fix(translator): restore product contracts and SolidWorks assembly evaluation
Preserve public connectors and solved placements without mutating upstream products, and retain SolidWorks 2023/2025 compatibility. Validation: 10 reported regressions fixed; affected tests 75 passed, 9 shared failures, 52 skipped; 36 version checks passed. Native 2023/2025 assembly save, reopen, placement, and dimension-edit checks passed.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
"""FreeCAD translator backend for SimpleCAD models."""
|
||||
|
||||
from .api import (
|
||||
translate_model_json_to_fcstd,
|
||||
translate_model_json_to_freecad_script,
|
||||
translate_product_package_to_fcstd,
|
||||
translate_product_package_to_freecad_script,
|
||||
)
|
||||
@@ -12,8 +10,6 @@ from .translator import FreeCADTranslator
|
||||
__all__ = [
|
||||
"CAPABILITIES",
|
||||
"FreeCADTranslator",
|
||||
"translate_model_json_to_fcstd",
|
||||
"translate_model_json_to_freecad_script",
|
||||
"translate_product_package_to_fcstd",
|
||||
"translate_product_package_to_freecad_script",
|
||||
]
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
"""SolidWorks translator backend for SimpleCAD model JSON."""
|
||||
"""SolidWorks translator backend for SimpleCAD product packages."""
|
||||
|
||||
from .api import (
|
||||
SUPPORTED_SOLIDWORKS_VERSIONS,
|
||||
export_model_json_to_solidworks_step,
|
||||
translate_model_json_to_solidworks_script,
|
||||
translate_model_json_to_solidworks_step,
|
||||
translate_product_package_to_solidworks_script,
|
||||
)
|
||||
from .capabilities import CAPABILITIES
|
||||
from .compiler_compat import SolidWorksScriptTranslator # noqa: F401
|
||||
from .translator import SolidWorksTranslator
|
||||
|
||||
__all__ = [
|
||||
"CAPABILITIES",
|
||||
"SUPPORTED_SOLIDWORKS_VERSIONS",
|
||||
"SolidWorksTranslator",
|
||||
"export_model_json_to_solidworks_step",
|
||||
"translate_model_json_to_solidworks_script",
|
||||
"translate_model_json_to_solidworks_step",
|
||||
"translate_product_package_to_solidworks_script",
|
||||
]
|
||||
|
||||
@@ -100,8 +100,5 @@ def translate_product_package_to_solidworks_script(
|
||||
|
||||
__all__ = [
|
||||
"SUPPORTED_SOLIDWORKS_VERSIONS",
|
||||
"export_model_json_to_solidworks_step",
|
||||
"translate_model_json_to_solidworks_script",
|
||||
"translate_model_json_to_solidworks_step",
|
||||
"translate_product_package_to_solidworks_script",
|
||||
]
|
||||
|
||||
@@ -65,7 +65,8 @@ _PRODUCT_OPS = {
|
||||
"make_vertex_connector_rconnector",
|
||||
"make_placement_connector_rconnector",
|
||||
"make_add_connector_rpart",
|
||||
"make_add_connector_rassembly",
|
||||
"make_set_public_connector_rassembly",
|
||||
"evaluate_assembly_definition",
|
||||
"make_connector_ref_rconnectorref",
|
||||
"make_scalar_limit_rscalarlimit",
|
||||
"make_ground_component_rassembly",
|
||||
@@ -103,7 +104,7 @@ for _op in _PRODUCT_OPS:
|
||||
CAPABILITIES = BackendCapabilities(
|
||||
backend_id=BACKEND_NAME,
|
||||
display_name="SolidWorks",
|
||||
input_schema_versions=("2.0",),
|
||||
input_schema_versions=("product-package-2.0",),
|
||||
targets=(
|
||||
TranslationTarget(
|
||||
target_id="solidworks_script",
|
||||
|
||||
@@ -4,10 +4,23 @@ from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
|
||||
from ....product.placement import placement_frame_mm
|
||||
from ....topology import OperationNode
|
||||
from ..codegen import _emit_node_lines
|
||||
|
||||
|
||||
def evaluated_assembly_params(params):
|
||||
"""Convert durable evaluation ticks for both payload and emitted calls."""
|
||||
# The older make_solve operation already carries millimetre frames.
|
||||
return {
|
||||
**params,
|
||||
"component_placements": [
|
||||
{**record, "placement": placement_frame_mm(record["placement"])}
|
||||
for record in params.get("component_placements", [])
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class ProductEmitterMixin:
|
||||
def _emit_products(self, node: OperationNode) -> List[str]:
|
||||
return _emit_node_lines(
|
||||
|
||||
@@ -57,7 +57,7 @@ EMITTER_METHOD_BY_OP: Dict[str, str] = {
|
||||
"make_vertex_connector_rconnector": "_emit_products",
|
||||
"make_placement_connector_rconnector": "_emit_products",
|
||||
"make_add_connector_rpart": "_emit_products",
|
||||
"make_add_connector_rassembly": "_emit_products",
|
||||
"evaluate_assembly_definition": "_emit_products",
|
||||
"make_set_public_connector_rassembly": "_emit_products",
|
||||
"make_connector_ref_rconnectorref": "_emit_products",
|
||||
"make_scalar_limit_rscalarlimit": "_emit_products",
|
||||
|
||||
@@ -2,6 +2,51 @@
|
||||
|
||||
|
||||
class AssemblyRuntimeMixin:
|
||||
def _assembly_with_placements(self, assembly, placements):
|
||||
value = dict(assembly)
|
||||
known = {str(c.get('component_id')) for c in assembly.get('components', [])}
|
||||
if set(placements) - known:
|
||||
raise RuntimeError('Solved placement references a missing component')
|
||||
components = []
|
||||
for source in assembly.get('components', []):
|
||||
component = dict(source)
|
||||
component_id = str(component.get('component_id'))
|
||||
if component_id in placements:
|
||||
component['placement'] = {
|
||||
'kind': 'placement', 'params': dict(placements[component_id]),
|
||||
}
|
||||
components.append(component)
|
||||
value['components'] = components
|
||||
return value
|
||||
|
||||
def _assembly_with_public_connector(self, assembly, params):
|
||||
public_id = str(params.get('public_connector_id') or '')
|
||||
component_id = str(params.get('source_component_id') or '')
|
||||
connector_id = str(params.get('source_connector_id') or '')
|
||||
if not all((public_id, component_id, connector_id)):
|
||||
raise RuntimeError('Public connector requires non-empty IDs')
|
||||
public = list(assembly.get('public_connectors') or [])
|
||||
if any(c['public_connector_id'] == public_id for c in public):
|
||||
raise RuntimeError(f'duplicate public_connector_id in assembly: {public_id}')
|
||||
component = next((c for c in assembly.get('components', [])
|
||||
if str(c.get('component_id')) == component_id), None)
|
||||
if component is None:
|
||||
raise RuntimeError(f'Public connector references missing component: {component_id}')
|
||||
item = component['item']
|
||||
if item.get('kind') == 'assembly':
|
||||
connector_ids = {c['public_connector_id'] for c in item.get('public_connectors', [])}
|
||||
else:
|
||||
connector_ids = {c['params']['connector_id'] for c in item.get('connectors', [])}
|
||||
if connector_id not in connector_ids:
|
||||
raise RuntimeError(f'Public connector references missing connector: {connector_id}')
|
||||
public.append({
|
||||
'public_connector_id': public_id, 'name': params.get('name'),
|
||||
'component_id': component_id, 'connector_id': connector_id,
|
||||
})
|
||||
value = dict(assembly)
|
||||
value['public_connectors'] = public
|
||||
return value
|
||||
|
||||
def _save_native_assembly(self, step_path, assembly_path):
|
||||
master_model = self.model
|
||||
master_title = str(_maybe_call(master_model.GetTitle))
|
||||
|
||||
@@ -878,19 +878,25 @@ class SimpleCADSolidWorksRuntime(
|
||||
self.product_values[node_id] = assembly
|
||||
return self._set_output(node, assembly)
|
||||
if op == 'make_solve_assembly_constraints_rassembly':
|
||||
assembly = dict(self._first_output(inputs[0]))
|
||||
solved_placements = dict(params.get('component_placements') or {})
|
||||
components = []
|
||||
for component in assembly.get('components') or []:
|
||||
component = dict(component)
|
||||
component_id = str(component.get('component_id') or '')
|
||||
if component_id in solved_placements:
|
||||
component['placement'] = {
|
||||
'kind': 'placement',
|
||||
'params': dict(solved_placements[component_id]),
|
||||
}
|
||||
components.append(component)
|
||||
assembly['components'] = components
|
||||
assembly = self._assembly_with_placements(
|
||||
self._first_output(inputs[0]),
|
||||
dict(params.get('component_placements') or {}),
|
||||
)
|
||||
self.product_values[node_id] = assembly
|
||||
return self._set_output(node, assembly)
|
||||
if op == 'evaluate_assembly_definition':
|
||||
placements = {}
|
||||
for record in params.get('component_placements') or []:
|
||||
component_id = str(record['instance_id'])
|
||||
if component_id in placements:
|
||||
raise RuntimeError(f'Duplicate solved component: {component_id}')
|
||||
placements[component_id] = record['placement']
|
||||
assembly = self._assembly_with_placements(self._first_output(inputs[0]), placements)
|
||||
assembly['constraint_report'] = dict(params.get('constraint_report') or {})
|
||||
self.product_values[node_id] = assembly
|
||||
return self._set_output(node, assembly)
|
||||
if op == 'make_set_public_connector_rassembly':
|
||||
assembly = self._assembly_with_public_connector(self._first_output(inputs[0]), params)
|
||||
self.product_values[node_id] = assembly
|
||||
return self._set_output(node, assembly)
|
||||
if op == 'make_compound_from_assembly_rcompound':
|
||||
@@ -903,8 +909,12 @@ class SimpleCADSolidWorksRuntime(
|
||||
return self._set_output(node, {'kind': 'compound', 'bodies': bodies})
|
||||
if op.startswith('make_') and op.endswith('_rconnector'):
|
||||
return self._set_output(node, {'kind': 'connector', 'params': params})
|
||||
if op == 'make_add_connector_rpart':
|
||||
part = dict(self._first_output(inputs[0]))
|
||||
part['connectors'] = list(part.get('connectors') or []) + [self._first_output(inputs[1])]
|
||||
self.product_values[node_id] = part
|
||||
return self._set_output(node, part)
|
||||
if op in {
|
||||
'make_add_connector_rpart', 'make_add_connector_rassembly',
|
||||
'make_connector_ref_rconnectorref', 'make_scalar_limit_rscalarlimit',
|
||||
'make_ground_component_rassembly', 'make_unground_component_rassembly',
|
||||
'make_fixed_constraint_rassembly', 'make_revolute_constraint_rassembly',
|
||||
|
||||
@@ -49,6 +49,8 @@ _OPERATION_LABELS: Dict[str, str] = {
|
||||
"apply_tag_rselection": "Tag",
|
||||
"make_part_rpart": "Part",
|
||||
"make_assembly_rassembly": "Assembly",
|
||||
"make_set_public_connector_rassembly": "Public Connector",
|
||||
"evaluate_assembly_definition": "Assembly Evaluation",
|
||||
"make_add_component_rassembly": "Component",
|
||||
"make_place_component_rassembly": "Component Placement",
|
||||
"make_material_rmaterial": "Material",
|
||||
|
||||
@@ -48,6 +48,7 @@ from .emitters import (
|
||||
emit_native_node,
|
||||
)
|
||||
from .runtime import assemble_runtime_source
|
||||
from .emitters.products import evaluated_assembly_params
|
||||
from .versions import normalize_solidworks_version
|
||||
|
||||
|
||||
@@ -291,6 +292,8 @@ class _SolidWorksCompiler(
|
||||
)
|
||||
elif op == "make_spline_redge":
|
||||
params = _clamped_spline_params(params)
|
||||
elif op == "evaluate_assembly_definition":
|
||||
params = evaluated_assembly_params(params)
|
||||
return params
|
||||
|
||||
def translate_model_json_to_script(
|
||||
@@ -619,6 +622,7 @@ class SolidWorksTranslator(BaseTranslator):
|
||||
"root_definition_id": view.root_definition_id,
|
||||
"root_definition_kind": view.root_definition_kind,
|
||||
"definition_ids": view.definition_ids,
|
||||
"target_runtime_validated": False,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -5398,21 +5398,15 @@ class TestGeoSelectorStabilityCriterion(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
import math as math_module
|
||||
from pathlib import Path
|
||||
from simplecadapi.translator.freecad_translator.runtime import (
|
||||
assemble_runtime_source,
|
||||
)
|
||||
|
||||
import simplecadapi
|
||||
|
||||
source = (
|
||||
Path(simplecadapi.__file__).parent
|
||||
/ "translator"
|
||||
/ "freecad_translator"
|
||||
/ "runtime"
|
||||
/ "selections.py"
|
||||
).read_text()
|
||||
source = assemble_runtime_source()
|
||||
# One namespace dict so runtime snippet functions share globals,
|
||||
# mirroring how the emitter concatenates them into one script scope.
|
||||
cls.runtime = {"math": math_module}
|
||||
exec(compile(source, "selections.py", "exec"), cls.runtime)
|
||||
exec(compile(source, "<freecad-runtime>", "exec"), cls.runtime)
|
||||
|
||||
@staticmethod
|
||||
def _edge(length, start, end, center=None):
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
"""Execute emitted product operations without starting a COM application."""
|
||||
|
||||
import copy
|
||||
import math
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from simplecadapi.product.placement import Placement, placement_ticks
|
||||
from simplecadapi.topology import OperationGraph
|
||||
from simplecadapi.translator.solidworks_translator import (
|
||||
CAPABILITIES,
|
||||
SolidWorksTranslator,
|
||||
)
|
||||
from simplecadapi.translator.solidworks_translator.emitters import emit_native_node
|
||||
from simplecadapi.translator.solidworks_translator.runtime import (
|
||||
assemble_runtime_source,
|
||||
)
|
||||
from simplecadapi.translator.solidworks_translator.translator import _SolidWorksCompiler
|
||||
from simplecadapi.translator.types import SupportLevel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def runtime():
|
||||
namespace = {"math": math}
|
||||
exec(assemble_runtime_source(), namespace)
|
||||
cls = namespace["SimpleCADSolidWorksRuntime"]
|
||||
value = cls.__new__(cls)
|
||||
value.outputs = {}
|
||||
value.product_values = {}
|
||||
return value
|
||||
|
||||
|
||||
def emit(runtime, op, params, inputs=(), node_id="result"):
|
||||
return runtime.emit_node(
|
||||
{
|
||||
"node_id": node_id,
|
||||
"op": op,
|
||||
"params": params,
|
||||
"inputs": [{"node_id": key} for key in inputs],
|
||||
}
|
||||
)[0]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def assembly(runtime):
|
||||
# Part connector registration is essential for resolving public aliases.
|
||||
runtime.outputs["part"] = [
|
||||
{"kind": "part", "body": object(), "material": {"name": "steel"}}
|
||||
]
|
||||
emit(
|
||||
runtime,
|
||||
"make_placement_connector_rconnector",
|
||||
{"connector_id": "mount"},
|
||||
node_id="connector",
|
||||
)
|
||||
part = emit(
|
||||
runtime, "make_add_connector_rpart", {}, ["part", "connector"], "connected"
|
||||
)
|
||||
source = {
|
||||
"kind": "assembly",
|
||||
"components": [
|
||||
{
|
||||
"component_id": "a",
|
||||
"item": part,
|
||||
"placement": {
|
||||
"kind": "placement",
|
||||
"params": {"origin": [1.0, 2.0, 3.0]},
|
||||
},
|
||||
},
|
||||
{
|
||||
"component_id": "b",
|
||||
"item": {
|
||||
"kind": "assembly",
|
||||
"components": [],
|
||||
"public_connectors": [
|
||||
{
|
||||
"public_connector_id": "nested",
|
||||
"component_id": "child",
|
||||
"connector_id": "mount",
|
||||
},
|
||||
],
|
||||
},
|
||||
"placement": {
|
||||
"kind": "placement",
|
||||
"params": {"origin": [7.0, 8.0, 9.0]},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
runtime.outputs["assembly"] = [source]
|
||||
return source
|
||||
|
||||
|
||||
def test_public_connector_preserves_source_and_nested_alias(runtime, assembly):
|
||||
params = {
|
||||
"public_connector_id": "interface",
|
||||
"source_component_id": "a",
|
||||
"source_connector_id": "mount",
|
||||
"name": "Mount",
|
||||
}
|
||||
result = emit(runtime, "make_set_public_connector_rassembly", params, ["assembly"])
|
||||
assert result["public_connectors"] == [
|
||||
{
|
||||
"public_connector_id": "interface",
|
||||
"component_id": "a",
|
||||
"connector_id": "mount",
|
||||
"name": "Mount",
|
||||
}
|
||||
]
|
||||
assert "public_connectors" not in assembly
|
||||
assert result["components"] is assembly["components"]
|
||||
assert runtime.product_values["result"] is result
|
||||
assert assembly["components"][0]["item"]["material"] == {"name": "steel"}
|
||||
assert "connectors" not in runtime.outputs["part"][0]
|
||||
nested = emit(
|
||||
runtime,
|
||||
"make_set_public_connector_rassembly",
|
||||
{**params, "source_component_id": "b", "source_connector_id": "nested"},
|
||||
["assembly"],
|
||||
)
|
||||
assert nested["public_connectors"][0]["component_id"] == "b"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"changes,match",
|
||||
[
|
||||
({"source_component_id": "missing"}, "missing component"),
|
||||
({"source_connector_id": "missing"}, "missing connector"),
|
||||
({"public_connector_id": ""}, "non-empty"),
|
||||
],
|
||||
)
|
||||
def test_invalid_public_connector_rejected(runtime, assembly, changes, match):
|
||||
params = {
|
||||
"public_connector_id": "interface",
|
||||
"source_component_id": "a",
|
||||
"source_connector_id": "mount",
|
||||
}
|
||||
with pytest.raises(RuntimeError, match=match):
|
||||
emit(
|
||||
runtime,
|
||||
"make_set_public_connector_rassembly",
|
||||
{**params, **changes},
|
||||
["assembly"],
|
||||
)
|
||||
assert "result" not in runtime.outputs
|
||||
assert "public_connectors" not in assembly
|
||||
|
||||
|
||||
def test_duplicate_public_connector_rejected(runtime, assembly):
|
||||
params = {
|
||||
"public_connector_id": "interface",
|
||||
"source_component_id": "a",
|
||||
"source_connector_id": "mount",
|
||||
}
|
||||
first = emit(runtime, "make_set_public_connector_rassembly", params, ["assembly"])
|
||||
with pytest.raises(RuntimeError, match="duplicate public_connector_id"):
|
||||
emit(
|
||||
runtime,
|
||||
"make_set_public_connector_rassembly",
|
||||
params,
|
||||
["result"],
|
||||
"duplicate",
|
||||
)
|
||||
assert len(first["public_connectors"]) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"op", ["evaluate_assembly_definition", "make_solve_assembly_constraints_rassembly"]
|
||||
)
|
||||
def test_emitted_solved_frames_replace_placement_without_mutation(
|
||||
runtime, assembly, op
|
||||
):
|
||||
original_placements = copy.deepcopy(
|
||||
[c["placement"] for c in assembly["components"]]
|
||||
)
|
||||
frame = Placement(
|
||||
origin=(20.0, -5.0, 3.0), x_axis=(0.0, 1.0, 0.0), y_axis=(-1.0, 0.0, 0.0)
|
||||
)
|
||||
ticks = placement_ticks(frame)
|
||||
placements = (
|
||||
[{"instance_id": "a", "placement": ticks}]
|
||||
if op == "evaluate_assembly_definition"
|
||||
else {"a": frame.to_dict()}
|
||||
)
|
||||
graph = OperationGraph()
|
||||
source = graph.add_node("make_assembly_rassembly", node_id="assembly")
|
||||
public = graph.add_node(
|
||||
"make_set_public_connector_rassembly",
|
||||
params={
|
||||
"public_connector_id": "interface",
|
||||
"source_component_id": "a",
|
||||
"source_connector_id": "mount",
|
||||
},
|
||||
inputs=[source],
|
||||
node_id="public",
|
||||
)
|
||||
evaluated = graph.add_node(
|
||||
op,
|
||||
params={
|
||||
"component_placements": placements,
|
||||
"constraint_report": {"solved": True},
|
||||
},
|
||||
inputs=[public],
|
||||
node_id="solved",
|
||||
)
|
||||
SolidWorksTranslator()._preflight(graph, evaluated.node_id)
|
||||
compiler = _SolidWorksCompiler()
|
||||
for node in (public, evaluated):
|
||||
source = (
|
||||
"def execute():\n if True:\n"
|
||||
+ "\n".join(emit_native_node(compiler, node))
|
||||
+ "\nexecute()"
|
||||
)
|
||||
exec(source, {"runtime": runtime})
|
||||
result = runtime.outputs["solved"][0]
|
||||
assert result["components"][0]["placement"]["params"] == frame.to_dict()
|
||||
assert [c["placement"] for c in assembly["components"]] == original_placements
|
||||
assert result["components"] is not assembly["components"]
|
||||
assert result["components"][1] == assembly["components"][1]
|
||||
for index in (0, 1):
|
||||
assert (
|
||||
result["components"][index]["item"] is assembly["components"][index]["item"]
|
||||
)
|
||||
assert (
|
||||
result["public_connectors"] == runtime.outputs["public"][0]["public_connectors"]
|
||||
)
|
||||
assert runtime.product_values["solved"] is result
|
||||
assert evaluated.params["component_placements"] == placements
|
||||
payload = compiler._payload_to_jsonable({}, graph, [evaluated])
|
||||
assert payload["graph"]["nodes"][0]["params"] == compiler._solidworks_params(
|
||||
evaluated
|
||||
)
|
||||
runtime.emit_node(payload["graph"]["nodes"][0])
|
||||
assert (
|
||||
runtime.outputs["solved"][0]["components"][0]["placement"]
|
||||
== result["components"][0]["placement"]
|
||||
)
|
||||
if op == "evaluate_assembly_definition":
|
||||
assert result["constraint_report"] == {"solved": True}
|
||||
matrix = runtime._assembly_with_placements.__globals__["_placement_matrix"](
|
||||
result["components"][0]["placement"]
|
||||
)
|
||||
assert matrix[:9] == [0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
|
||||
assert matrix[9:12] == pytest.approx([0.020, -0.005, 0.003])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"records,match",
|
||||
[
|
||||
([{"instance_id": "unknown", "placement": {}}], "missing component"),
|
||||
([{"instance_id": "a", "placement": {}}] * 2, "Duplicate solved component"),
|
||||
],
|
||||
)
|
||||
def test_invalid_evaluation_rejected(runtime, assembly, records, match):
|
||||
with pytest.raises(RuntimeError, match=match):
|
||||
emit(
|
||||
runtime,
|
||||
"evaluate_assembly_definition",
|
||||
{"component_placements": records},
|
||||
["assembly"],
|
||||
)
|
||||
assert "result" not in runtime.product_values
|
||||
|
||||
|
||||
def test_current_assembly_operations_have_emitters_and_metadata_support():
|
||||
from simplecadapi.recording.serializer import CANONICAL_OP_SET
|
||||
from simplecadapi.translator.solidworks_translator.emitters.registry import (
|
||||
EMITTER_METHOD_BY_OP,
|
||||
)
|
||||
|
||||
assert set(CAPABILITIES.operations) == set(CANONICAL_OP_SET)
|
||||
assert "make_add_connector_rassembly" not in EMITTER_METHOD_BY_OP
|
||||
for op in ("evaluate_assembly_definition", "make_set_public_connector_rassembly"):
|
||||
assert CAPABILITIES.operations[op].level is SupportLevel.METADATA_ONLY
|
||||
assert EMITTER_METHOD_BY_OP[op] == "_emit_products"
|
||||
|
||||
|
||||
def test_legacy_solve_integer_coordinates_are_not_ticks(runtime, assembly):
|
||||
graph = OperationGraph()
|
||||
source = graph.add_node("make_assembly_rassembly", node_id="assembly")
|
||||
frame = {
|
||||
"origin": [10, 0, 0],
|
||||
"x_axis": [1, 0, 0],
|
||||
"y_axis": [0, 1, 0],
|
||||
"z_axis": [0, 0, 1],
|
||||
}
|
||||
node = graph.add_node(
|
||||
"make_solve_assembly_constraints_rassembly",
|
||||
params={"component_placements": {"a": frame}},
|
||||
inputs=[source],
|
||||
)
|
||||
lines = emit_native_node(_SolidWorksCompiler(), node)
|
||||
exec(
|
||||
"def execute():\n if True:\n" + "\n".join(lines) + "\nexecute()",
|
||||
{"runtime": runtime},
|
||||
)
|
||||
assert (
|
||||
runtime.outputs[node.node_id][0]["components"][0]["placement"]["params"]
|
||||
== frame
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("owned", [True, False])
|
||||
@pytest.mark.parametrize("visible", [True, False])
|
||||
def test_cleanup_only_closes_owned_application(runtime, owned, visible):
|
||||
calls = []
|
||||
runtime.sw = SimpleNamespace(
|
||||
CloseAllDocuments=lambda discard: calls.append(("close", discard)),
|
||||
ExitApp=lambda: calls.append(("exit",)),
|
||||
)
|
||||
runtime.model = object() # Cleanup must not call a possibly stale model proxy.
|
||||
runtime._owns_solidworks = owned
|
||||
runtime.visible = visible
|
||||
runtime._stop_solidworks()
|
||||
assert calls == ([("close", True), ("exit",)] if owned else [])
|
||||
assert runtime.sw is None and runtime.model is None
|
||||
assert runtime._owns_solidworks is False
|
||||
runtime._stop_solidworks()
|
||||
assert calls == ([("close", True), ("exit",)] if owned else [])
|
||||
@@ -89,9 +89,8 @@ def test_script_owns_com_and_contains_native_product_paths(tmp_path: Path) -> No
|
||||
)
|
||||
assert coinit_offset < runtime_offset
|
||||
assert script.count("pythoncom.CoInitialize()") == 1
|
||||
assert "self.sw.CloseDoc(str(_maybe_call(self.model.GetTitle)))" in script
|
||||
assert "if not self.visible:" in script
|
||||
assert "self.sw.ExitApp()" in script
|
||||
assert "runtime.finish()" in script
|
||||
assert "self._stop_solidworks()" in script
|
||||
assert "if op == 'make_box_rsolid':" in script
|
||||
assert "self._extrude_profile(" in script
|
||||
assert "if op == 'evaluate_assembly_definition':" in script
|
||||
|
||||
Reference in New Issue
Block a user