You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.7 KiB
Python
97 lines
2.7 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
|
|
import FreeCAD as App
|
|
|
|
|
|
REPO_ROOT = r"D:\LightWork3D"
|
|
MODULE_DIR = os.path.join(REPO_ROOT, "src", "Mod", "FreeCADExchange")
|
|
OUT_DIR = os.path.join(REPO_ROOT, "tests", "out")
|
|
OUT_FCSTD = os.path.join(OUT_DIR, "auto_routing_smoke.FCStd")
|
|
OUT_JSON = os.path.join(OUT_DIR, "auto_routing_smoke_result.json")
|
|
|
|
if MODULE_DIR not in sys.path:
|
|
sys.path.insert(0, MODULE_DIR)
|
|
|
|
import AutoRouting
|
|
import RoutingNetwork
|
|
import TerminalObjects
|
|
import WiringObjects
|
|
|
|
|
|
def _make_terminal(doc, name, terminal_uuid, point):
|
|
terminal = TerminalObjects.create_lcs_object(
|
|
doc,
|
|
name,
|
|
placement=App.Placement(point, App.Rotation()),
|
|
label=terminal_uuid,
|
|
)
|
|
TerminalObjects.set_terminal_semantics(
|
|
terminal,
|
|
"project-smoke",
|
|
"element-" + terminal_uuid,
|
|
terminal_uuid,
|
|
"instance-" + terminal_uuid,
|
|
label=terminal_uuid,
|
|
)
|
|
return terminal
|
|
|
|
|
|
def _point_payload(point):
|
|
return {
|
|
"x": float(point.x),
|
|
"y": float(point.y),
|
|
"z": float(point.z),
|
|
}
|
|
|
|
|
|
def main():
|
|
os.makedirs(OUT_DIR, exist_ok=True)
|
|
doc = App.newDocument("AutoRoutingSmoke")
|
|
App.setActiveDocument(doc.Name)
|
|
TerminalObjects.ensure_root_group(doc, "project-smoke")
|
|
WiringObjects.initialize_wiring_scene(doc, "project-smoke")
|
|
|
|
start = _make_terminal(doc, "SmokeTerminalStart", "terminal-start", App.Vector(0, 0, 0))
|
|
end = _make_terminal(doc, "SmokeTerminalEnd", "terminal-end", App.Vector(160, 0, 0))
|
|
|
|
RoutingNetwork.create_route_carrier(
|
|
doc,
|
|
[
|
|
App.Vector(0, 0, 20),
|
|
App.Vector(0, 60, 20),
|
|
App.Vector(160, 60, 20),
|
|
App.Vector(160, 0, 20),
|
|
],
|
|
label="Smoke Route Carrier",
|
|
project_uuid="project-smoke",
|
|
)
|
|
|
|
obstacle = doc.addObject("Part::Box", "SmokeObstacle")
|
|
obstacle.Label = "Smoke Obstacle"
|
|
obstacle.Length = 40
|
|
obstacle.Width = 40
|
|
obstacle.Height = 60
|
|
obstacle.Placement = App.Placement(App.Vector(60, -20, -10), App.Rotation())
|
|
doc.recompute()
|
|
|
|
result = AutoRouting.route_between_terminals(doc, start, end)
|
|
payload = {
|
|
"algorithm": result["algorithm"],
|
|
"route_status": result["route_status"],
|
|
"collision_count": result["collision_count"],
|
|
"points": [_point_payload(point) for point in result["points"]],
|
|
"network": RoutingNetwork.network_summary(doc),
|
|
"scene": OUT_FCSTD,
|
|
}
|
|
|
|
doc.saveAs(OUT_FCSTD)
|
|
with open(OUT_JSON, "w", encoding="utf-8") as handle:
|
|
json.dump(payload, handle, ensure_ascii=False, indent=2)
|
|
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|