Added new connection styles
This commit is contained in:
@@ -225,7 +225,14 @@ class DocumentController(QObject):
|
||||
RotateComponentsCommand(self, self.active_component_id, rotations)
|
||||
)
|
||||
|
||||
def connect(self, source: Endpoint, target: Endpoint) -> str:
|
||||
def connect(
|
||||
self,
|
||||
source: Endpoint,
|
||||
target: Endpoint,
|
||||
*,
|
||||
routing: str = "spline",
|
||||
waypoints: list[QPointF] | None = None,
|
||||
) -> str:
|
||||
if self.active_component_id is None:
|
||||
raise ValueError("There is no active graph")
|
||||
source_port = self._port_for_endpoint(source, "source")
|
||||
@@ -236,7 +243,19 @@ class DocumentController(QObject):
|
||||
raise ValueError(
|
||||
f"Cannot connect {source_port.type!r} to {target_port.type!r}"
|
||||
)
|
||||
connection = Connection(str(uuid4()), source, target)
|
||||
if routing not in {"direct", "angled", "spline"}:
|
||||
raise ValueError(f"Unknown connection routing: {routing}")
|
||||
connection = Connection(
|
||||
str(uuid4()),
|
||||
source,
|
||||
target,
|
||||
properties={
|
||||
"routing": routing,
|
||||
"waypoints": [
|
||||
{"x": point.x(), "y": point.y()} for point in (waypoints or [])
|
||||
],
|
||||
},
|
||||
)
|
||||
self.undo_stack.push(
|
||||
AddConnectionCommand(self, self.active_component_id, connection)
|
||||
)
|
||||
@@ -255,6 +274,10 @@ class DocumentController(QObject):
|
||||
ports = component.outputs if role == "source" else component.inputs
|
||||
return next((port for port in ports if port.id == (endpoint.interface or endpoint.port)), None)
|
||||
|
||||
def connection_port_type(self, connection: Connection) -> str:
|
||||
port = self._port_for_endpoint(connection.source, "source")
|
||||
return port.type if port is not None else "signal"
|
||||
|
||||
def add_interface_port(self, direction: str, position: QPointF) -> str:
|
||||
component = self.active_component
|
||||
if component is None or component.implementation_kind != "graph":
|
||||
@@ -489,10 +512,17 @@ class DocumentController(QObject):
|
||||
for source in source_connections:
|
||||
if source.source.block not in id_map or source.target.block not in id_map:
|
||||
continue
|
||||
properties = deepcopy(source.properties)
|
||||
for point in properties.get("waypoints", []):
|
||||
if isinstance(point, dict):
|
||||
point["x"] = float(point.get("x", 0)) + offset.x()
|
||||
point["y"] = float(point.get("y", 0)) + offset.y()
|
||||
connection = Connection(
|
||||
id=str(uuid4()),
|
||||
source=Endpoint(block=id_map[source.source.block], port=source.source.port),
|
||||
target=Endpoint(block=id_map[source.target.block], port=source.target.port),
|
||||
name=source.name,
|
||||
properties=properties,
|
||||
)
|
||||
connections[connection.id] = connection
|
||||
if blocks:
|
||||
|
||||
Reference in New Issue
Block a user