diff --git a/Geometry/clash.py b/Geometry/clash.py index 1f74562..669faa1 100644 --- a/Geometry/clash.py +++ b/Geometry/clash.py @@ -83,6 +83,9 @@ def check_for_clash( continue intersection = pymesh.boolean(latest_pymesh, ref_pymesh, operation="intersection") + + print(f"intersection: {intersection}") + if intersection and intersection.volume > 0: severity = intersection.volume / min( ref_pymesh.volume, latest_pymesh.volume diff --git a/Geometry/mocks.py b/Geometry/mocks.py index 0c04f47..402aa6b 100644 --- a/Geometry/mocks.py +++ b/Geometry/mocks.py @@ -9,5 +9,9 @@ def volume(self): return 0 @staticmethod - def boolean(_other, _operation): + def boolean(mesh_a, mesh_b, operation): return mypymesh.Mesh([], []) + + @staticmethod + def form_mesh(vertices, faces): + return mypymesh.Mesh(vertices, faces) diff --git a/Rules/checks.py b/Rules/checks.py index 0a97f78..baf7e3c 100644 --- a/Rules/checks.py +++ b/Rules/checks.py @@ -30,12 +30,12 @@ def is_displayable_rule() -> Callable[[Base], bool]: """Rule: Check if a parameter is displayable.""" return ( lambda parameter: parameter.displayValue - and parameter.displayValue is not None + and parameter.displayValue is not None ) @staticmethod def speckle_type_rule( - desired_type: Union[str, List[str]] + desired_type: Union[str, List[str]] ) -> Callable[[Base], bool]: """Rule: Check if a parameter's speckle_type matches the desired type.""" @@ -43,9 +43,7 @@ def speckle_type_rule( if isinstance(desired_type, str): desired_type = [desired_type] - print(desired_type) - return ( lambda speckle_object: getattr(speckle_object, "speckle_type", None) - in desired_type + in desired_type ) diff --git a/main.py b/main.py index 2fe6c64..a2ccfea 100644 --- a/main.py +++ b/main.py @@ -41,14 +41,15 @@ class FunctionInputs(AutomateBase): title="Tolerance", description="Specify the tolerance value for the analysis. \ Negative values relaxes the test, positive values make it more strict.", - readonly=True, + json_schema_extra={ + "readOnly": True, + } ) tolerance_unit: str = Field( # Using the SpecklePy Units enum here default=Units.mm, - json_schema_extra={"examples": ["mm", "cm", "m"]}, + json_schema_extra={"examples": ["mm", "cm", "m"], "readOnly": True}, title="Tolerance Unit", description="Unit of the tolerance value.", - readonly=True, ) @@ -114,6 +115,7 @@ def automate_function( for base_obj, id, transform in reference_objects if visible_beams_rule(base_obj) ] + latest_displayable_objects = [ (base_obj, id, transform) for base_obj, id, transform in latest_objects @@ -148,6 +150,11 @@ def automate_function( all_objects_count = len(reference_mesh_elements) + len(latest_mesh_elements) all_clashes_count = len(clashes) + print(f"Clash detection report: {all_clashes_count} clashes found between {all_objects_count} objects.") + + print(f"Reference objects: {len([x for x in reference_objects])}.") + print(f"Latest objects: {len([x for x in latest_objects])}.") + clash_report_message = ( f"Clash detection report: {all_clashes_count} clashes found " f"between {all_objects_count} objects. " diff --git a/tests/test_main.py b/tests/test_main.py index 0850201..e1876c5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -23,12 +23,12 @@ def crypto_random_string(length: int) -> str: def register_new_automation( - project_id: str, - model_id: str, - speckle_client: SpeckleClient, - automation_id: str, - automation_name: str, - automation_revision_id: str, + project_id: str, + model_id: str, + speckle_client: SpeckleClient, + automation_id: str, + automation_name: str, + automation_revision_id: str, ): """Register a new automation in the speckle server.""" query = gql( @@ -97,8 +97,8 @@ def test_object() -> Base: # fixture to mock the AutomationRunData that would be generated by a full Automation Run def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationRunData: server_url = request.config.SPECKLE_SERVER_URL - project_id = "4f064f09e6" - model_id = "5a16cf52af" + project_id = "7d8e96669a" + model_id = "efeb71387b" function_name = "Clash Test" @@ -119,7 +119,7 @@ def fake_automation_run_data(request, test_client: SpeckleClient) -> AutomationR project_id=project_id, model_id=model_id, branch_name="main", - version_id="2b16327448", + version_id="3f13306ed2", speckle_server_url=server_url, # These ids would be available with a valid registered Automation definition. automation_id=automation_id, @@ -142,7 +142,7 @@ def test_function_run(fake_automation_run_data: AutomationRunData, speckle_token context, automate_function, FunctionInputs( - tolerance=0.1, tolerance_unit="mm", static_model_name="structural" + tolerance=0.1, tolerance_unit="mm", static_model_name="simple beams" ), ) @@ -156,26 +156,26 @@ def context(fake_automation_run_data: AutomationRunData, speckle_token: str): def test_non_existent_model(context, test_client: SpeckleClient): with pytest.raises( - Exception, match="The static model named does not exist, skipping the function." + Exception, match="The static model named does not exist, skipping the function." ): get_reference_model(context, "Fake Name") def test_model_with_no_versions(context, test_client: SpeckleClient): with pytest.raises( - Exception, match="The static model has no versions, skipping the function." + Exception, match="The static model has no versions, skipping the function." ): get_reference_model(context, "blank") def test_same_as_changed_model(context, test_client: SpeckleClient): with pytest.raises( - Exception, - match="The static model is the same as the changed model, skipping the function.", + Exception, + match="The static model is the same as the changed model, skipping the function.", ): - get_reference_model(context, "hvac") + get_reference_model(context, "clash simple") def test_valid_reference_model(context, test_client: SpeckleClient): - reference_model = get_reference_model(context, "structural") + reference_model = get_reference_model(context, "simple beams") assert reference_model is not None