feat: 继承线槽源容量到布线路径

dev
Zhaowenlong 3 weeks ago
parent 26d227240b
commit 6e71be95ac

@ -423,7 +423,7 @@ def _ensure_integer_property(obj, prop_name, description, value):
setattr(obj, prop_name, 0) 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( TerminalObjects.ensure_string_property(
obj, obj,
"QetRoutingRole", "QetRoutingRole",
@ -456,11 +456,22 @@ def _set_route_carrier_semantics(obj, project_uuid="", kind=ROUTE_CARRIER_KIND):
obj, obj,
"QetRouteCarrierCapacity", "QetRouteCarrierCapacity",
"How many routed wires can reuse this carrier segment before detouring is preferred", "How many routed wires can reuse this carrier segment before detouring is preferred",
1, capacity,
) )
return obj 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): def _set_wire_duct_source_semantics(source):
if source is None: if source is None:
return return
@ -478,6 +489,12 @@ def _set_wire_duct_source_semantics(source):
"How routing connection collision checks should treat this object", "How routing connection collision checks should treat this object",
WIRE_DUCT_OBSTACLE_MODE, 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): def _set_support_surface_source_semantics(source):
@ -571,7 +588,7 @@ def _create_carrier_geometry(doc, name, points):
return obj 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.""" """Create a routable carrier from ordered 3D points."""
if doc is None: if doc is None:
raise RoutingNetworkError("No FreeCAD document is available.") 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", "Ordered centerline points used by the 3D router",
) )
carrier.Points = list(normalized) 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) group = WiringObjects.ensure_carrier_group(doc, project_uuid)
if carrier not in getattr(group, "Group", []): if carrier not in getattr(group, "Group", []):
@ -1607,12 +1624,14 @@ def create_wire_duct_carriers_from_document(
if len(points) < 2: if len(points) < 2:
continue continue
label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Wire Duct" label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Wire Duct"
capacity = _route_carrier_capacity_value(source, default=1)
carrier = create_route_carrier( carrier = create_route_carrier(
doc, doc,
points, points,
label="QET Auto Wire Duct Centerline {0}".format(label), label="QET Auto Wire Duct Centerline {0}".format(label),
project_uuid=project_uuid, project_uuid=project_uuid,
kind=ROUTE_CARRIER_KIND_WIRE_DUCT, kind=ROUTE_CARRIER_KIND_WIRE_DUCT,
capacity=capacity,
) )
_mark_wire_duct_source(source, carrier) _mark_wire_duct_source(source, carrier)
created.append(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), label="QET Auto Wire Duct Open End {0} {1}".format(label, end_index),
project_uuid=project_uuid, project_uuid=project_uuid,
kind=ROUTE_CARRIER_KIND_WIRE_DUCT_OPEN_END, kind=ROUTE_CARRIER_KIND_WIRE_DUCT_OPEN_END,
capacity=capacity,
) )
) )
return created return created
@ -1908,12 +1928,14 @@ def create_wire_duct_carriers_from_selection(
if len(points) < 2: if len(points) < 2:
continue continue
label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Wire Duct" label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Wire Duct"
capacity = _route_carrier_capacity_value(source, default=1)
carrier = create_route_carrier( carrier = create_route_carrier(
doc, doc,
points, points,
label="QET Wire Duct Centerline {0}".format(label), label="QET Wire Duct Centerline {0}".format(label),
project_uuid=project_uuid, project_uuid=project_uuid,
kind=ROUTE_CARRIER_KIND_WIRE_DUCT, kind=ROUTE_CARRIER_KIND_WIRE_DUCT,
capacity=capacity,
) )
_mark_wire_duct_source(source, carrier) _mark_wire_duct_source(source, carrier)
created.append(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), label="QET Wire Duct Open End {0} {1}".format(label, end_index),
project_uuid=project_uuid, project_uuid=project_uuid,
kind=ROUTE_CARRIER_KIND_WIRE_DUCT_OPEN_END, kind=ROUTE_CARRIER_KIND_WIRE_DUCT_OPEN_END,
capacity=capacity,
) )
) )
return created return created

@ -1304,6 +1304,25 @@ class AutoRoutingTest(unittest.TestCase):
self.assertEqual("PassThrough", duct.QetRoutingObstacleMode) 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]) 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): def test_auto_detect_wire_ducts_ignores_cabinet_models(self):
_install_fake_freecad() _install_fake_freecad()
terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules() terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules()

Loading…
Cancel
Save