|
|
|
|
@ -102,6 +102,14 @@ def _point_payload(point):
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _route_length(points):
|
|
|
|
|
total = 0.0
|
|
|
|
|
normalized = [_vector(point) for point in points or []]
|
|
|
|
|
for index in range(len(normalized) - 1):
|
|
|
|
|
total += _distance(normalized[index], normalized[index + 1])
|
|
|
|
|
return total
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _is_finite_point(point):
|
|
|
|
|
try:
|
|
|
|
|
return all(
|
|
|
|
|
@ -514,26 +522,43 @@ def _set_string(obj, name, value, description="Auto-routing property"):
|
|
|
|
|
TerminalObjects.ensure_string_property(obj, name, "QET Routing", description, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _route_payload(route_data, collisions):
|
|
|
|
|
def _route_payload(route_data, collisions, wire_style_id=""):
|
|
|
|
|
points = route_data.get("points", [])
|
|
|
|
|
return {
|
|
|
|
|
"algorithm": route_data.get("algorithm", ""),
|
|
|
|
|
"points": [_point_payload(point) for point in route_data.get("points", [])],
|
|
|
|
|
"length_mm": _route_length(points),
|
|
|
|
|
"wire_style_id": str(wire_style_id or "").strip(),
|
|
|
|
|
"points": [_point_payload(point) for point in points],
|
|
|
|
|
"collision_count": len(collisions),
|
|
|
|
|
"collisions": collisions,
|
|
|
|
|
"network": route_data.get("network", {}),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _set_auto_metadata(wire, route_data, collisions):
|
|
|
|
|
def _set_auto_metadata(wire, route_data, collisions, wire_style_id=""):
|
|
|
|
|
length_mm = _route_length(route_data.get("points", []))
|
|
|
|
|
_set_string(
|
|
|
|
|
wire,
|
|
|
|
|
"QetAutoRouteAlgorithm",
|
|
|
|
|
route_data.get("algorithm", ""),
|
|
|
|
|
"Auto-routing algorithm used for this wire",
|
|
|
|
|
)
|
|
|
|
|
_set_string(
|
|
|
|
|
wire,
|
|
|
|
|
"QetAutoRouteLengthMm",
|
|
|
|
|
"{0:.3f}".format(length_mm),
|
|
|
|
|
"Auto route length in millimeters",
|
|
|
|
|
)
|
|
|
|
|
_set_string(
|
|
|
|
|
wire,
|
|
|
|
|
"QetWireStyleId",
|
|
|
|
|
str(wire_style_id or "").strip(),
|
|
|
|
|
"QET wire style ID",
|
|
|
|
|
)
|
|
|
|
|
_set_string(
|
|
|
|
|
wire,
|
|
|
|
|
"QetAutoRouteDiagnosticsJson",
|
|
|
|
|
json.dumps(_route_payload(route_data, collisions), ensure_ascii=False),
|
|
|
|
|
json.dumps(_route_payload(route_data, collisions, wire_style_id=wire_style_id), ensure_ascii=False),
|
|
|
|
|
"Auto-routing diagnostics",
|
|
|
|
|
)
|
|
|
|
|
if route_data.get("network"):
|
|
|
|
|
@ -870,6 +895,7 @@ def route_between_terminals(
|
|
|
|
|
group_uuid="",
|
|
|
|
|
wire_mark="",
|
|
|
|
|
wire_mark_is_manual=False,
|
|
|
|
|
wire_style_id="",
|
|
|
|
|
):
|
|
|
|
|
if doc is None:
|
|
|
|
|
raise AutoRoutingError("No FreeCAD document is available.")
|
|
|
|
|
@ -881,6 +907,7 @@ def route_between_terminals(
|
|
|
|
|
raise AutoRoutingError("Start and end terminal must be different.")
|
|
|
|
|
|
|
|
|
|
opts = _merged_options(options)
|
|
|
|
|
effective_wire_style_id = str(wire_style_id or opts.get("wire_style_id", "") or "").strip()
|
|
|
|
|
start_uuid = (getattr(start_terminal, "QetTerminalUuid", "") or "").strip()
|
|
|
|
|
end_uuid = (getattr(end_terminal, "QetTerminalUuid", "") or "").strip()
|
|
|
|
|
project_uuid = _project_uuid(doc, start_terminal, end_terminal)
|
|
|
|
|
@ -937,7 +964,7 @@ def route_between_terminals(
|
|
|
|
|
wire_mark=wire_mark,
|
|
|
|
|
wire_mark_is_manual=wire_mark_is_manual,
|
|
|
|
|
)
|
|
|
|
|
_set_auto_metadata(wire, route_data, collisions)
|
|
|
|
|
_set_auto_metadata(wire, route_data, collisions, wire_style_id=effective_wire_style_id)
|
|
|
|
|
|
|
|
|
|
routed_group = WiringObjects.ensure_routed_group(doc, project_uuid)
|
|
|
|
|
if wire not in getattr(routed_group, "Group", []):
|
|
|
|
|
@ -1094,6 +1121,7 @@ def route_all_from_payload(doc, payload, options=None):
|
|
|
|
|
group_uuid=_wire_item_value(item, "group_uuid"),
|
|
|
|
|
wire_mark=_wire_item_value(item, "wire_mark"),
|
|
|
|
|
wire_mark_is_manual=bool(item.get("wire_mark_is_manual", False)),
|
|
|
|
|
wire_style_id=_wire_item_value(item, "wire_style_id"),
|
|
|
|
|
)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
report["errors"].append(str(exc))
|
|
|
|
|
@ -1175,6 +1203,7 @@ def _wire_tasks_payload(doc):
|
|
|
|
|
"wire_label": (getattr(task, "QetWireLabel", "") or "").strip(),
|
|
|
|
|
"wire_mark": (getattr(task, "QetWireMark", "") or "").strip(),
|
|
|
|
|
"wire_mark_is_manual": bool(getattr(task, "QetWireMarkIsManual", False)),
|
|
|
|
|
"wire_style_id": (getattr(task, "QetWireStyleId", "") or "").strip(),
|
|
|
|
|
"net_uuid": (getattr(task, "QetNetUuid", "") or "").strip(),
|
|
|
|
|
"group_uuid": (getattr(task, "QetGroupUuid", "") or "").strip(),
|
|
|
|
|
"start_element_uuid": (getattr(task, "QetStartElementUuid", "") or "").strip(),
|
|
|
|
|
|