Skip to content
Snippets Groups Projects
Commit 0f8c05de authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Improve signal drawing

parent 9b136a14
No related branches found
No related tags found
1 merge request!81Improve signal drawing
Pipeline #74828 passed
......@@ -34,7 +34,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
_components_height: float
_x_axis_indent: float
_event_items: List[QGraphicsItem]
_signal_dict: Dict[GraphicsComponentItem, Set[GraphicsSignal]]
_signal_dict: Dict[GraphicsComponentItem, Set[GraphicsSignal]]
def __init__(self, schedule: Schedule, parent: Optional[QGraphicsItem] = None):
......@@ -152,7 +152,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
# if not isinstance(op, (Input, Output)):
self._components_height += spacing
component = GraphicsComponentItem(operation)
component = GraphicsComponentItem(operation, parent=self)
component.setPos(self._x_axis_indent + op_start_time, self._components_height)
self._components.append(component)
_components_dict[operation] = component
......@@ -179,7 +179,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
for output_port in component.operation.outputs:
for signal in output_port.signals:
dest_component = _components_dict[signal.destination.operation]
gui_signal = GraphicsSignal(component, dest_component, signal)
gui_signal = GraphicsSignal(component, dest_component, signal, parent=self)
self.addToGroup(gui_signal)
self._signal_dict[component].add(gui_signal)
self._signal_dict[dest_component].add(gui_signal)
......
......@@ -7,7 +7,8 @@ from qtpy.QtCore import QPointF
# B-ASIC
from b_asic.signal import Signal
from b_asic.scheduler_gui.graphics_component_item import GraphicsComponentItem
from b_asic.scheduler_gui._preferences import SIGNAL_ACTIVE, SIGNAL_INACTIVE, SIGNAL_WIDTH
from b_asic.scheduler_gui._preferences import (SIGNAL_ACTIVE, SIGNAL_INACTIVE,
SIGNAL_WIDTH)
class GraphicsSignal(QGraphicsPathItem):
_path: Optional[QPainterPath] = None
......@@ -44,15 +45,24 @@ class GraphicsSignal(QGraphicsPathItem):
source_y = source_point.y()
dest_x = dest_point.x()
dest_y = dest_point.y()
if abs(source_x - dest_x) <= 0.1:
ctrl_point1 = QPointF(source_x + 0.5, source_y)
ctrl_point2 = QPointF(source_x - 0.5, dest_y)
if (dest_x - source_x <= -0.1 or
self.parentItem().schedule._laps[self._signal.graph_id]):
offset = 0.2 # TODO: Get from parent/axes...
laps = self.parentItem().schedule._laps[self._signal.graph_id]
path.lineTo(self.parentItem().schedule.schedule_time + offset,
source_y)
path.moveTo(0 + offset, dest_y)
path.lineTo(dest_x, dest_y)
else:
mid_x = (source_x + dest_x)/2
ctrl_point1 = QPointF(mid_x, source_y)
ctrl_point2 = QPointF(mid_x, dest_y)
if abs(source_x - dest_x) <= 0.1: # "== 0"
ctrl_point1 = QPointF(source_x + 0.5, source_y)
ctrl_point2 = QPointF(source_x - 0.5, dest_y)
else:
mid_x = (source_x + dest_x)/2
ctrl_point1 = QPointF(mid_x, source_y)
ctrl_point2 = QPointF(mid_x, dest_y)
path.cubicTo(ctrl_point1, ctrl_point2, dest_point)
path.cubicTo(ctrl_point1, ctrl_point2, dest_point)
self.setPath(path)
def refresh_pens(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment