Bond graph ports and drawing added
This commit is contained in:
@@ -285,7 +285,12 @@ class DocumentController(QObject):
|
||||
target_port = self._port_for_endpoint(target, "target")
|
||||
if source_port is None or target_port is None:
|
||||
raise ValueError("A connection endpoint no longer exists")
|
||||
if not PortTypeRegistry.compatible(source_port.type, target_port.type):
|
||||
if not PortTypeRegistry.compatible(
|
||||
source_port.type,
|
||||
target_port.type,
|
||||
source_port.domain,
|
||||
target_port.domain,
|
||||
):
|
||||
raise ValueError(f"Cannot connect {source_port.type!r} to {target_port.type!r}")
|
||||
if not self.endpoint_accepts_connection(source, "source"):
|
||||
raise ValueError(
|
||||
@@ -573,11 +578,24 @@ class DocumentController(QObject):
|
||||
)
|
||||
if endpoint.interface is not None:
|
||||
ports = owner.inputs if role == "source" else owner.outputs
|
||||
ports = [
|
||||
*ports,
|
||||
*(
|
||||
port
|
||||
for port in owner.inputs
|
||||
if port.orientation == "indifferent" and port not in ports
|
||||
),
|
||||
]
|
||||
else:
|
||||
component = owner.graph.blocks.get(endpoint.block or "")
|
||||
if component is None:
|
||||
return None
|
||||
ports = component.outputs if role == "source" else component.inputs
|
||||
if role == "source":
|
||||
ports = [
|
||||
*ports,
|
||||
*(port for port in component.inputs if port.orientation == "indifferent"),
|
||||
]
|
||||
return next(
|
||||
(port for port in ports if port.id == (endpoint.interface or endpoint.port)), None
|
||||
)
|
||||
@@ -664,6 +682,9 @@ class DocumentController(QObject):
|
||||
raise ValueError("Only text-defined components can be edited here")
|
||||
input_ids = [port.id for port in inputs]
|
||||
output_ids = [port.id for port in outputs]
|
||||
source_ids = output_ids + [
|
||||
port.id for port in inputs if port.orientation == "indifferent"
|
||||
]
|
||||
if len(set(input_ids)) != len(input_ids) or len(set(output_ids)) != len(output_ids):
|
||||
raise ValueError("Input and output IDs must be unique")
|
||||
if any(not port.name.strip() for port in (*inputs, *outputs)):
|
||||
@@ -686,7 +707,7 @@ class DocumentController(QObject):
|
||||
)
|
||||
if (
|
||||
connection.source.block == component.id
|
||||
and connection.source.port not in output_ids
|
||||
and connection.source.port not in source_ids
|
||||
):
|
||||
raise ValueError(
|
||||
f"Output {connection.source.port!r} is still connected in the containing graph"
|
||||
@@ -842,6 +863,9 @@ class DocumentController(QObject):
|
||||
return
|
||||
input_ids = {port.id for port in inputs}
|
||||
output_ids = {port.id for port in outputs}
|
||||
source_ids = output_ids | {
|
||||
port.id for port in inputs if port.orientation == "indifferent"
|
||||
}
|
||||
parent = self.document.find_parent(component_id)
|
||||
if parent is not None:
|
||||
for connection in parent.graph.connections.values():
|
||||
@@ -852,7 +876,7 @@ class DocumentController(QObject):
|
||||
raise ValueError("An input cannot be removed or reoriented while connected")
|
||||
if (
|
||||
connection.source.block == component_id
|
||||
and connection.source.port not in output_ids
|
||||
and connection.source.port not in source_ids
|
||||
):
|
||||
raise ValueError("An output cannot be removed or reoriented while connected")
|
||||
for connection in component.graph.connections.values():
|
||||
|
||||
Reference in New Issue
Block a user