diff --git a/b_asic/scheduler_gui/_preferences.py b/b_asic/scheduler_gui/_preferences.py index 72d117d193a1c9f50c20b7d3f84912b2de232cca..6529b24efbe661439c94ab6c28ba80d8ce67ceed 100644 --- a/b_asic/scheduler_gui/_preferences.py +++ b/b_asic/scheduler_gui/_preferences.py @@ -1,14 +1,11 @@ from qtpy.QtGui import QColor -from b_asic._preferences import ( - EXECUTION_TIME_COLOR, - LATENCY_COLOR, - SIGNAL_COLOR, -) +from b_asic._preferences import EXECUTION_TIME_COLOR, LATENCY_COLOR, SIGNAL_COLOR SIGNAL_INACTIVE = QColor(*SIGNAL_COLOR) SIGNAL_ACTIVE = QColor(0, 207, 181) SIGNAL_WIDTH = 0.03 +SIGNAL_WIDTH_ACTIVE = 0.05 OPERATION_LATENCY_INACTIVE = QColor(*LATENCY_COLOR) OPERATION_LATENCY_ACTIVE = QColor(0, 207, 181) @@ -16,8 +13,6 @@ OPERATION_EXECUTION_TIME_INACTIVE = QColor(*EXECUTION_TIME_COLOR) OPERATION_EXECUTION_TIME_ACTIVE = QColor(*EXECUTION_TIME_COLOR) OPERATION_HEIGHT = 0.75 -OPERATION_GAP = ( - 1 - OPERATION_HEIGHT -) # TODO: For now, should really fix the bug +OPERATION_GAP = 1 - OPERATION_HEIGHT # TODO: For now, should really fix the bug SCHEDULE_INDENT = 0.2 diff --git a/b_asic/scheduler_gui/operation_item.py b/b_asic/scheduler_gui/operation_item.py index b687a01633edb8b71ad861d3b2ae0aae59827682..eb6687c9c38fdbfca8e5130db577c408ed350510 100644 --- a/b_asic/scheduler_gui/operation_item.py +++ b/b_asic/scheduler_gui/operation_item.py @@ -89,6 +89,14 @@ class OperationItem(QGraphicsItemGroup): QCursor(Qt.CursorShape.OpenHandCursor) ) # default cursor when hovering over object + self._port_filling_brush = QBrush(Qt.GlobalColor.black) + self._port_outline_pen = QPen(Qt.GlobalColor.black) + self._port_outline_pen.setWidthF(0) + + self._port_filling_brush_active = QBrush(OPERATION_LATENCY_ACTIVE) + self._port_outline_pen_active = QPen(OPERATION_LATENCY_ACTIVE) + self._port_outline_pen_active.setWidthF(0) + self._make_component() # def sceneEvent(self, event: QEvent) -> bool: @@ -171,6 +179,16 @@ class OperationItem(QGraphicsItemGroup): self._set_background(OPERATION_LATENCY_INACTIVE) self.setCursor(QCursor(Qt.CursorShape.OpenHandCursor)) + def set_port_active(self, key: str): + item = self._ports[key]["item"] + item.setBrush(self._port_filling_brush_active) + item.setPen(self._port_outline_pen_active) + + def set_port_inactive(self, key: str): + item = self._ports[key]["item"] + item.setBrush(self._port_filling_brush) + item.setPen(self._port_outline_pen) + def _set_background(self, color: QColor) -> None: brush = QBrush(color) self._latency_item.setBrush(brush) @@ -185,10 +203,6 @@ class OperationItem(QGraphicsItemGroup): Qt.RoundJoin ) # Qt.MiterJoin, Qt.BevelJoin (default), Qt.RoundJoin, Qt.SvgMiterJoin - port_filling_brush = QBrush(Qt.GlobalColor.black) # used by port filling - port_outline_pen = QPen(Qt.GlobalColor.black) # used by port outline - port_outline_pen.setWidthF(0) - # port_outline_pen.setCosmetic(True) port_size = 7 / self._scale # the diameter of a port execution_time_color = QColor(OPERATION_EXECUTION_TIME_INACTIVE) @@ -230,10 +244,10 @@ class OperationItem(QGraphicsItemGroup): new_port = QGraphicsEllipseItem( -port_size / 2, -port_size / 2, port_size, port_size ) - new_port.setPen(port_outline_pen) - new_port.setBrush(port_filling_brush) + new_port.setPen(self._port_outline_pen) + new_port.setBrush(self._port_filling_brush) new_port.setPos(port_pos.x(), port_pos.y()) - self._port_items.append(new_port) + self._ports[key]["item"] = new_port create_ports(self._operation.get_input_coordinates(), "in") create_ports(self._operation.get_output_coordinates(), "out") @@ -247,8 +261,8 @@ class OperationItem(QGraphicsItemGroup): # item group, consist of component_item, port_items and execution_time_item self.addToGroup(self._latency_item) - for port in self._port_items: - self.addToGroup(port) + for port in self._ports.values(): + self.addToGroup(port["item"]) self.addToGroup(self._label_item) if execution_time: self.addToGroup(self._execution_time_item) diff --git a/b_asic/scheduler_gui/signal_item.py b/b_asic/scheduler_gui/signal_item.py index 267ab08e8368714bf956a48a6bf1fe864d4fba72..0f28b0c50c67ff88cff247a136803f3bbec9c48f 100644 --- a/b_asic/scheduler_gui/signal_item.py +++ b/b_asic/scheduler_gui/signal_item.py @@ -18,6 +18,7 @@ from b_asic.scheduler_gui._preferences import ( SIGNAL_ACTIVE, SIGNAL_INACTIVE, SIGNAL_WIDTH, + SIGNAL_WIDTH_ACTIVE, ) from b_asic.scheduler_gui.operation_item import OperationItem from b_asic.signal import Signal @@ -59,6 +60,8 @@ class SignalItem(QGraphicsPathItem): self._src_operation = src_operation self._dest_operation = dest_operation self._signal = signal + self._src_key = f"out{self._signal.source.index}" + self._dest_key = f"in{self._signal.destination.index}" self._refresh_pens() self.set_inactive() self.update_path() @@ -67,12 +70,8 @@ class SignalItem(QGraphicsPathItem): """ Create a new path after moving connected operations. """ - source_point = self._src_operation.get_port_location( - f"out{self._signal.source.index}" - ) - dest_point = self._dest_operation.get_port_location( - f"in{self._signal.destination.index}" - ) + source_point = self._src_operation.get_port_location(self._src_key) + dest_point = self._dest_operation.get_port_location(self._dest_key) path = QPainterPath() path.moveTo(source_point) source_x = source_point.x() @@ -100,7 +99,7 @@ class SignalItem(QGraphicsPathItem): def _refresh_pens(self) -> None: """Create pens.""" pen = QPen(SIGNAL_ACTIVE) - pen.setWidthF(SIGNAL_WIDTH) + pen.setWidthF(SIGNAL_WIDTH_ACTIVE) self._active_pen = pen pen = QPen(SIGNAL_INACTIVE) pen.setWidthF(SIGNAL_WIDTH) @@ -111,7 +110,11 @@ class SignalItem(QGraphicsPathItem): Set the signal color to represent that a connected operation is selected. """ self.setPen(self._active_pen) + self._src_operation.set_port_active(self._src_key) + self._dest_operation.set_port_active(self._dest_key) def set_inactive(self) -> None: """Set the signal color to the default color.""" self.setPen(self._inactive_pen) + self._src_operation.set_port_inactive(self._src_key) + self._dest_operation.set_port_inactive(self._dest_key)