Commit 08718bb6 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[widgets][toolchaineditor] implemented connection edition

parent eb83d495
......@@ -90,61 +90,61 @@ class BasePin(QGraphicsItem):
painter.drawEllipse(self.boundingRect())
def mousePressEvent(self, event):
"""Painting connection process"""
"""Painting connection initiated"""
self.new_connection = Connection(self.block_object.connection_style)
self.block_object.scene().addItem(self.new_connection)
def mouseMoveEvent(self, event):
"""Painting connection process"""
"""Painting connection in progress"""
mouse_position = self.mapToScene(event.pos())
self.new_connection.set_new_connection_pins_coordinates(self, mouse_position)
def mouseReleaseEvent(self, event):
"""Painting connection process"""
"""Painting connection ended - validation required"""
self.block_object.scene().removeItem(self.new_connection)
target = self.block_object.scene().itemAt(
event.scenePos().toPoint(), QTransform()
)
if isinstance(target, BasePin) and target.is_valid(self):
# This needs to be refactored and worked on!
connection_settings = {}
connection_settings["channel"] = "train"
if isinstance(target, BasePin):
if isinstance(target, InputPin) and isinstance(self, OutputPin):
connection_settings["from"] = self.block + "." + self.pin
connection_settings["to"] = target.block + "." + target.pin
if isinstance(self, OutputPin):
start = self
end = target
else:
connection_settings["from"] = target.block + "." + target.pin
connection_settings["to"] = self.block + "." + self.pin
channel_colors = self.block_object.toolchain.json_object["representation"][
"channel_colors"
]
connection = Connection(self.block_object.connection_style)
connection.load(
self.block_object.toolchain, connection_settings, channel_colors
)
self.block_object.toolchain.connections.append(connection)
self.block_object.toolchain.scene.addItem(connection)
self.block_object.scene().addItem(connection)
else:
self.block_object.scene().removeItem(self.new_connection)
def is_valid(self, source):
# remove input-input and output-output connection
if type(source) == type(self):
return False
# remove connection to same block object
if source.block_object == self.block_object:
return False
return True
start = target
end = self
if Connection(self.block_object.connection_style).check_validity(
start, end
):
# Find the corresponding channel
connection_settings = {}
if start.block_object.type == BlockType.DATASETS.name:
connection_settings["channel"] = start.block_object.name
else:
connection_settings[
"channel"
] = start.block_object.synchronized_channel
# Create the connection
connection_settings["from"] = start.block + "." + start.pin
connection_settings["to"] = end.block + "." + end.pin
channel_colors = self.block_object.toolchain.json_object[
"representation"
]["channel_colors"]
connection = Connection(self.block_object.connection_style)
connection.load(
self.block_object.toolchain, connection_settings, channel_colors
)
self.block_object.toolchain.connections.append(connection)
self.block_object.toolchain.scene.addItem(connection)
def get_center_point(self):
"""Get the center coordinates of the Pin(x,y)"""
......@@ -277,6 +277,25 @@ class Connection(QGraphicsPathItem):
self.drawCubicBezierCurve()
def check_validity(self, start, end):
# remove input-input and output-output connection
if type(start) == type(end):
return False
# remove connection to same block object
if start.block_object == end.block_object:
return False
# check if end block pin is free
toolchain = end.block_object.toolchain
for connection in toolchain.connections:
if connection.end_block == end.block_object:
if connection.end_pin == end:
return False
return True
def load(self, toolchain, connection_details, channel_colors):
self.start_block_name = connection_details["from"].split(".")[0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment