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

Add connections in schedule

parent 0117c82a
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #74655 failed
...@@ -7,7 +7,6 @@ from b_asic.signal import Signal ...@@ -7,7 +7,6 @@ from b_asic.signal import Signal
from b_asic.port import SignalSourceProvider, InputPort, OutputPort from b_asic.port import SignalSourceProvider, InputPort, OutputPort
from b_asic.graph_component import GraphComponent, AbstractGraphComponent, Name from b_asic.graph_component import GraphComponent, AbstractGraphComponent, Name
import itertools as it import itertools as it
from math import trunc
import collections import collections
from abc import abstractmethod from abc import abstractmethod
......
...@@ -68,6 +68,11 @@ class GraphicsComponentItem(QGraphicsItemGroup): ...@@ -68,6 +68,11 @@ class GraphicsComponentItem(QGraphicsItemGroup):
"""Get the op-id.""" """Get the op-id."""
return self._operation.graph_id return self._operation.graph_id
@property
def operation(self) -> GraphComponent:
"""Get the operation."""
return self._operation
@property @property
def height(self) -> float: def height(self) -> float:
"""Get or set the current component height. Setting the height to a new """Get or set the current component height. Setting the height to a new
...@@ -86,12 +91,14 @@ class GraphicsComponentItem(QGraphicsItemGroup): ...@@ -86,12 +91,14 @@ class GraphicsComponentItem(QGraphicsItemGroup):
"""Get the relative end time.""" """Get the relative end time."""
return self._end_time return self._end_time
@property @property
def event_items(self) -> List[QGraphicsItem]: def event_items(self) -> List[QGraphicsItem]:
"""Returnes a list of objects, that receives events.""" """Returnes a list of objects, that receives events."""
return [self] return [self]
def get_port_location(self, key) -> QPointF:
return self.mapToParent(self._ports[key]['pos'])
def _make_component(self) -> None: def _make_component(self) -> None:
"""Makes a new component out of the stored attributes.""" """Makes a new component out of the stored attributes."""
brush1 = QBrush(Qt.lightGray) # used by component filling brush1 = QBrush(Qt.lightGray) # used by component filling
...@@ -170,10 +177,10 @@ class GraphicsComponentItem(QGraphicsItemGroup): ...@@ -170,10 +177,10 @@ class GraphicsComponentItem(QGraphicsItemGroup):
for port_dict in self._ports.values(): for port_dict in self._ports.values():
port_pos = self.mapToParent(port_dict['pos']) port_pos = self.mapToParent(port_dict['pos'])
port = QGraphicsEllipseItem(-port_size/2, -port_size/2, port_size, port_size) # center of circle is in origo port = QGraphicsEllipseItem(-port_size/2, -port_size/2, port_size, port_size) # center of circle is in origo
port.setPen(pen2)
port.setBrush(brush2)
port.setPos(port_pos.x(), port_pos.y())
self._port_items.append(port) self._port_items.append(port)
self._port_items[-1].setPen(pen2)
self._port_items[-1].setBrush(brush2)
self._port_items[-1].setPos(port_pos.x(), port_pos.y())
## op-id/label ## op-id/label
self._label_item = QGraphicsSimpleTextItem(self._operation.graph_id) self._label_item = QGraphicsSimpleTextItem(self._operation.graph_id)
......
...@@ -160,12 +160,14 @@ class GraphicsGraphEvent: # PyQt5 ...@@ -160,12 +160,14 @@ class GraphicsGraphEvent: # PyQt5
# self.prepareGeometryChange() # self.prepareGeometryChange()
item.setX(pos) item.setX(pos)
self._current_pos.setX(self._current_pos.x() + 1.0) self._current_pos.setX(self._current_pos.x() + 1.0)
self._redraw_lines(item)
elif dx < -0.505: elif dx < -0.505:
pos = item.x() - 1.0 pos = item.x() - 1.0
if self.is_component_valid_pos(item, pos): if self.is_component_valid_pos(item, pos):
# self.prepareGeometryChange() # self.prepareGeometryChange()
item.setX(pos) item.setX(pos)
self._current_pos.setX(self._current_pos.x() - 1.0) self._current_pos.setX(self._current_pos.x() - 1.0)
self._redraw_lines(item)
def comp_mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None: def comp_mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None:
"""Changes the cursor to ClosedHandCursor when grabbing an object and """Changes the cursor to ClosedHandCursor when grabbing an object and
......
...@@ -5,19 +5,22 @@ ...@@ -5,19 +5,22 @@
Contains the scheduler-gui GraphicsGraphItem class for drawing and Contains the scheduler-gui GraphicsGraphItem class for drawing and
maintain a component in a graph. maintain a component in a graph.
""" """
from collections import defaultdict
from math import floor from math import floor
from pprint import pprint from pprint import pprint
from typing import Optional, List from typing import Optional, List, Dict, Set
# QGraphics and QPainter imports # QGraphics and QPainter imports
from qtpy.QtWidgets import QGraphicsItem, QGraphicsItemGroup from qtpy.QtWidgets import QGraphicsItem, QGraphicsItemGroup
from qtpy.QtGui import QPen
from qtpy.QtCore import Qt
# B-ASIC # B-ASIC
from b_asic.schedule import Schedule from b_asic.schedule import Schedule
from b_asic.special_operations import Input, Output
from graphics_component_item import GraphicsComponentItem from graphics_component_item import GraphicsComponentItem
from graphics_axes_item import GraphicsAxesItem from graphics_axes_item import GraphicsAxesItem
from graphics_graph_event import GraphicsGraphEvent from graphics_graph_event import GraphicsGraphEvent
from graphics_signal import GraphicsSignal
class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / PyQt5 class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / PyQt5
...@@ -33,6 +36,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / ...@@ -33,6 +36,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
_components_height: float _components_height: float
_x_axis_indent: float _x_axis_indent: float
_event_items: List[QGraphicsItem] _event_items: List[QGraphicsItem]
_signal_dict: Dict[GraphicsComponentItem, Set[GraphicsSignal]]
def __init__(self, schedule: Schedule, parent: Optional[QGraphicsItem] = None): def __init__(self, schedule: Schedule, parent: Optional[QGraphicsItem] = None):
...@@ -50,7 +54,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / ...@@ -50,7 +54,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
self._components_height = 0.0 self._components_height = 0.0
self._x_axis_indent = 0.2 self._x_axis_indent = 0.2
self._event_items = [] self._event_items = []
self._signal_dict = defaultdict(set)
self._make_graph() self._make_graph()
def clear(self) -> None: def clear(self) -> None:
...@@ -82,6 +86,10 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / ...@@ -82,6 +86,10 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
return True return True
def _redraw_lines(self, item: GraphicsComponentItem):
for signal in self._signal_dict[item]:
signal.update_path()
def set_new_starttime(self, item: GraphicsComponentItem, pos: float) -> None: def set_new_starttime(self, item: GraphicsComponentItem, pos: float) -> None:
op_start_time = self.schedule.start_time_of_operation(item.op_id) op_start_time = self.schedule.start_time_of_operation(item.op_id)
new_start_time = floor(pos) - floor(self._x_axis_indent) new_start_time = floor(pos) - floor(self._x_axis_indent)
...@@ -89,7 +97,6 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / ...@@ -89,7 +97,6 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
if move_time: if move_time:
self.schedule.move_operation(item.op_id, move_time) self.schedule.move_operation(item.op_id, move_time)
def is_valid_delta_time(self, delta_time: int) -> bool: def is_valid_delta_time(self, delta_time: int) -> bool:
"""Takes in a delta time and returns true if the new schedule time is """Takes in a delta time and returns true if the new schedule time is
valid, false otherwise.""" valid, false otherwise."""
...@@ -127,6 +134,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / ...@@ -127,6 +134,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
"""Makes a new graph out of the stored attributes.""" """Makes a new graph out of the stored attributes."""
# build components # build components
spacing = 0.2 spacing = 0.2
_components_dict = {}
# print('Start times:') # print('Start times:')
for op_id, op_start_time in self.schedule.start_times.items(): for op_id, op_start_time in self.schedule.start_times.items():
op = self.schedule.sfg.find_by_id(op_id) op = self.schedule.sfg.find_by_id(op_id)
...@@ -136,6 +144,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / ...@@ -136,6 +144,7 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
component = GraphicsComponentItem(op) component = GraphicsComponentItem(op)
component.setPos(self._x_axis_indent + op_start_time, self._components_height) component.setPos(self._x_axis_indent + op_start_time, self._components_height)
self._components.append(component) self._components.append(component)
_components_dict[op] = component
self._components_height += component.height self._components_height += component.height
self._event_items += component.event_items self._event_items += component.event_items
# self._components_height += spacing # self._components_height += spacing
...@@ -154,4 +163,19 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 / ...@@ -154,4 +163,19 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
self.addToGroup(component) self.addToGroup(component)
# self.addToGroup(self._components) # self.addToGroup(self._components)
pen1 = QPen(Qt.black) # used by component outline
pen1.setWidthF(0.03)
# add signals
for component in self._components:
op = component.operation
for i, output_port in enumerate(op.outputs):
for signal in output_port.signals:
dest_component = _components_dict[signal.destination.operation]
gs = GraphicsSignal(component, dest_component, signal, pen=pen1)
self.addToGroup(gs)
self._signal_dict[component].add(gs)
self._signal_dict[dest_component].add(gs)
pprint(GraphicsGraphItem.__mro__) pprint(GraphicsGraphItem.__mro__)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment