diff --git a/src/Mod/FreeCADExchange/RoutingNetwork.py b/src/Mod/FreeCADExchange/RoutingNetwork.py index aabcf90..64216ce 100644 --- a/src/Mod/FreeCADExchange/RoutingNetwork.py +++ b/src/Mod/FreeCADExchange/RoutingNetwork.py @@ -423,7 +423,7 @@ def _ensure_integer_property(obj, prop_name, description, value): setattr(obj, prop_name, 0) -def _set_route_carrier_semantics(obj, project_uuid="", kind=ROUTE_CARRIER_KIND): +def _set_route_carrier_semantics(obj, project_uuid="", kind=ROUTE_CARRIER_KIND, capacity=1): TerminalObjects.ensure_string_property( obj, "QetRoutingRole", @@ -456,11 +456,22 @@ def _set_route_carrier_semantics(obj, project_uuid="", kind=ROUTE_CARRIER_KIND): obj, "QetRouteCarrierCapacity", "How many routed wires can reuse this carrier segment before detouring is preferred", - 1, + capacity, ) return obj +def _route_carrier_capacity_value(obj, default=1): + for property_name in ("QetRouteCarrierCapacity", "QetWireCapacity"): + try: + value = int(float(getattr(obj, property_name, 0) or 0)) + except Exception: + value = 0 + if value > 0: + return value + return int(default or 1) + + def _set_wire_duct_source_semantics(source): if source is None: return @@ -478,6 +489,12 @@ def _set_wire_duct_source_semantics(source): "How routing connection collision checks should treat this object", WIRE_DUCT_OBSTACLE_MODE, ) + _ensure_integer_property( + source, + "QetRouteCarrierCapacity", + "How many routed wires can reuse generated wire duct segments before detouring is preferred", + _route_carrier_capacity_value(source, default=1), + ) def _set_support_surface_source_semantics(source): @@ -571,7 +588,7 @@ def _create_carrier_geometry(doc, name, points): return obj -def create_route_carrier(doc, points, label="", project_uuid="", kind=ROUTE_CARRIER_KIND): +def create_route_carrier(doc, points, label="", project_uuid="", kind=ROUTE_CARRIER_KIND, capacity=1): """Create a routable carrier from ordered 3D points.""" if doc is None: raise RoutingNetworkError("No FreeCAD document is available.") @@ -596,7 +613,7 @@ def create_route_carrier(doc, points, label="", project_uuid="", kind=ROUTE_CARR "Ordered centerline points used by the 3D router", ) carrier.Points = list(normalized) - _set_route_carrier_semantics(carrier, project_uuid=project_uuid, kind=kind) + _set_route_carrier_semantics(carrier, project_uuid=project_uuid, kind=kind, capacity=capacity) group = WiringObjects.ensure_carrier_group(doc, project_uuid) if carrier not in getattr(group, "Group", []): @@ -1607,12 +1624,14 @@ def create_wire_duct_carriers_from_document( if len(points) < 2: continue label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Wire Duct" + capacity = _route_carrier_capacity_value(source, default=1) carrier = create_route_carrier( doc, points, label="QET Auto Wire Duct Centerline {0}".format(label), project_uuid=project_uuid, kind=ROUTE_CARRIER_KIND_WIRE_DUCT, + capacity=capacity, ) _mark_wire_duct_source(source, carrier) created.append(carrier) @@ -1626,6 +1645,7 @@ def create_wire_duct_carriers_from_document( label="QET Auto Wire Duct Open End {0} {1}".format(label, end_index), project_uuid=project_uuid, kind=ROUTE_CARRIER_KIND_WIRE_DUCT_OPEN_END, + capacity=capacity, ) ) return created @@ -1908,12 +1928,14 @@ def create_wire_duct_carriers_from_selection( if len(points) < 2: continue label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Wire Duct" + capacity = _route_carrier_capacity_value(source, default=1) carrier = create_route_carrier( doc, points, label="QET Wire Duct Centerline {0}".format(label), project_uuid=project_uuid, kind=ROUTE_CARRIER_KIND_WIRE_DUCT, + capacity=capacity, ) _mark_wire_duct_source(source, carrier) created.append(carrier) @@ -1927,6 +1949,7 @@ def create_wire_duct_carriers_from_selection( label="QET Wire Duct Open End {0} {1}".format(label, end_index), project_uuid=project_uuid, kind=ROUTE_CARRIER_KIND_WIRE_DUCT_OPEN_END, + capacity=capacity, ) ) return created diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index 7abd8f9..9205f12 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -1304,6 +1304,25 @@ class AutoRoutingTest(unittest.TestCase): self.assertEqual("PassThrough", duct.QetRoutingObstacleMode) self.assertEqual([(20.0, 0.0, 15.0), (100.0, 0.0, 15.0)], [(p.x, p.y, p.z) for p in carrier.Points]) + def test_wire_duct_source_capacity_is_copied_to_generated_carriers(self): + _install_fake_freecad() + terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules() + doc = FakeDocument() + terminal_objects.ensure_root_group(doc, "project-1") + duct = doc.addObject("Part::Feature", "WireDuct") + duct.Shape = FakeShape(FakeBoundBox(0, 120, -10, 10, 5, 25)) + duct.QetRouteCarrierCapacity = 4 + + created = routing_network.create_wire_duct_carriers_from_selection( + doc, + [FakeSelectionItem(obj=duct)], + project_uuid="project-1", + margin=20.0, + ) + + self.assertIn("QetRouteCarrierCapacity", duct.PropertiesList) + self.assertTrue(all(item.QetRouteCarrierCapacity == 4 for item in created)) + def test_auto_detect_wire_ducts_ignores_cabinet_models(self): _install_fake_freecad() terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules()