|
|
|
@ -367,6 +367,7 @@ class AutoRoutingTest(unittest.TestCase):
|
|
|
|
terminal_objects, wiring_objects, routing_network, auto_routing = _reload_modules()
|
|
|
|
terminal_objects, wiring_objects, routing_network, auto_routing = _reload_modules()
|
|
|
|
app = sys.modules["FreeCAD"]
|
|
|
|
app = sys.modules["FreeCAD"]
|
|
|
|
doc = FakeDocument()
|
|
|
|
doc = FakeDocument()
|
|
|
|
|
|
|
|
app.ActiveDocument = doc
|
|
|
|
terminal_objects.ensure_root_group(doc, "project-1")
|
|
|
|
terminal_objects.ensure_root_group(doc, "project-1")
|
|
|
|
start = _terminal(doc, terminal_objects, "TerminalStart", "terminal-start", app.Vector(0, 0, 0))
|
|
|
|
start = _terminal(doc, terminal_objects, "TerminalStart", "terminal-start", app.Vector(0, 0, 0))
|
|
|
|
end = _terminal(doc, terminal_objects, "TerminalEnd", "terminal-end", app.Vector(100, 0, 0))
|
|
|
|
end = _terminal(doc, terminal_objects, "TerminalEnd", "terminal-end", app.Vector(100, 0, 0))
|
|
|
|
@ -396,6 +397,113 @@ class AutoRoutingTest(unittest.TestCase):
|
|
|
|
self.assertEqual([first], routed_wires)
|
|
|
|
self.assertEqual([first], routed_wires)
|
|
|
|
self.assertIsNotNone(doc.getObject(first.Name))
|
|
|
|
self.assertIsNotNone(doc.getObject(first.Name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_eplan_connection_route_keeps_existing_wire_when_new_geometry_creation_fails(self):
|
|
|
|
|
|
|
|
_install_fake_freecad()
|
|
|
|
|
|
|
|
terminal_objects, wiring_objects, routing_network, auto_routing = _reload_modules()
|
|
|
|
|
|
|
|
app = sys.modules["FreeCAD"]
|
|
|
|
|
|
|
|
doc = FakeDocument()
|
|
|
|
|
|
|
|
terminal_objects.ensure_root_group(doc, "project-1")
|
|
|
|
|
|
|
|
start = _terminal(doc, terminal_objects, "TerminalStart", "terminal-start", app.Vector(0, 0, 0))
|
|
|
|
|
|
|
|
end = _terminal(doc, terminal_objects, "TerminalEnd", "terminal-end", app.Vector(100, 0, 0))
|
|
|
|
|
|
|
|
routing_network.create_route_carrier(
|
|
|
|
|
|
|
|
doc,
|
|
|
|
|
|
|
|
[app.Vector(0, 0, 20), app.Vector(100, 0, 20)],
|
|
|
|
|
|
|
|
project_uuid="project-1",
|
|
|
|
|
|
|
|
kind="WireDuct",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
first = auto_routing.route_eplan_connection_between_terminals(
|
|
|
|
|
|
|
|
doc,
|
|
|
|
|
|
|
|
start,
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
wire_uuid="wire-1",
|
|
|
|
|
|
|
|
)["wire"]
|
|
|
|
|
|
|
|
original_create_wire_geometry = auto_routing._create_wire_geometry
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def failing_create_wire_geometry(_doc, _name, _points):
|
|
|
|
|
|
|
|
raise RuntimeError("create failed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto_routing._create_wire_geometry = failing_create_wire_geometry
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
|
|
|
|
auto_routing.route_eplan_connection_between_terminals(
|
|
|
|
|
|
|
|
doc,
|
|
|
|
|
|
|
|
start,
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
wire_uuid="wire-1",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
auto_routing._create_wire_geometry = original_create_wire_geometry
|
|
|
|
|
|
|
|
routed_wires = list(wiring_objects.iter_routed_wire_objects(doc))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual([first], routed_wires)
|
|
|
|
|
|
|
|
self.assertIsNotNone(doc.getObject(first.Name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_eplan_connection_route_cleans_up_half_created_wire_when_draft_fallback_fails(self):
|
|
|
|
|
|
|
|
_install_fake_freecad()
|
|
|
|
|
|
|
|
terminal_objects, wiring_objects, routing_network, auto_routing = _reload_modules()
|
|
|
|
|
|
|
|
app = sys.modules["FreeCAD"]
|
|
|
|
|
|
|
|
doc = FakeDocument()
|
|
|
|
|
|
|
|
terminal_objects.ensure_root_group(doc, "project-1")
|
|
|
|
|
|
|
|
start = _terminal(doc, terminal_objects, "TerminalStart", "terminal-start", app.Vector(0, 0, 0))
|
|
|
|
|
|
|
|
end = _terminal(doc, terminal_objects, "TerminalEnd", "terminal-end", app.Vector(100, 0, 0))
|
|
|
|
|
|
|
|
routing_network.create_route_carrier(
|
|
|
|
|
|
|
|
doc,
|
|
|
|
|
|
|
|
[app.Vector(0, 0, 20), app.Vector(100, 0, 20)],
|
|
|
|
|
|
|
|
project_uuid="project-1",
|
|
|
|
|
|
|
|
kind="WireDuct",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
first = auto_routing.route_eplan_connection_between_terminals(
|
|
|
|
|
|
|
|
doc,
|
|
|
|
|
|
|
|
start,
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
wire_uuid="wire-1",
|
|
|
|
|
|
|
|
)["wire"]
|
|
|
|
|
|
|
|
part_module = sys.modules["Part"]
|
|
|
|
|
|
|
|
draft_module = sys.modules.get("Draft")
|
|
|
|
|
|
|
|
if draft_module is None:
|
|
|
|
|
|
|
|
draft_module = types.ModuleType("Draft")
|
|
|
|
|
|
|
|
sys.modules["Draft"] = draft_module
|
|
|
|
|
|
|
|
original_make_polygon = part_module.makePolygon
|
|
|
|
|
|
|
|
original_make_wire = getattr(draft_module, "make_wire", None)
|
|
|
|
|
|
|
|
original_add_object = doc.addObject
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def failing_make_polygon(*args, **kwargs):
|
|
|
|
|
|
|
|
raise RuntimeError("part unavailable")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def half_created_make_wire(points, closed=False, placement=None, face=None, support=None, bs2wire=False):
|
|
|
|
|
|
|
|
obj = doc.addObject("Part::FeaturePython", "Wire")
|
|
|
|
|
|
|
|
obj.Points = list(points)
|
|
|
|
|
|
|
|
raise RuntimeError("draft failed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def failing_add_object(type_name, name):
|
|
|
|
|
|
|
|
if type_name == "App::FeaturePython":
|
|
|
|
|
|
|
|
raise RuntimeError("fallback failed")
|
|
|
|
|
|
|
|
return original_add_object(type_name, name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
part_module.makePolygon = failing_make_polygon
|
|
|
|
|
|
|
|
draft_module.make_wire = half_created_make_wire
|
|
|
|
|
|
|
|
doc.addObject = failing_add_object
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
|
|
|
|
auto_routing.route_eplan_connection_between_terminals(
|
|
|
|
|
|
|
|
doc,
|
|
|
|
|
|
|
|
start,
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
wire_uuid="wire-1",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
part_module.makePolygon = original_make_polygon
|
|
|
|
|
|
|
|
if original_make_wire is None:
|
|
|
|
|
|
|
|
delattr(draft_module, "make_wire")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
draft_module.make_wire = original_make_wire
|
|
|
|
|
|
|
|
doc.addObject = original_add_object
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
routed_wires = list(wiring_objects.iter_routed_wire_objects(doc))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual([first], routed_wires)
|
|
|
|
|
|
|
|
self.assertEqual(0, len([obj for obj in doc.Objects if obj.Name == "Wire"]))
|
|
|
|
|
|
|
|
|
|
|
|
def test_route_carrier_styles_make_generated_objects_distinguishable(self):
|
|
|
|
def test_route_carrier_styles_make_generated_objects_distinguishable(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()
|
|
|
|
|