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

Fix schedule range

parent a518bcc2
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #74627 failed
......@@ -22,10 +22,9 @@ class GraphicsComponentItem(QGraphicsItemGroup):
"""A class to represent an component in a graph."""
_scale: float = 1.0
"""Static, changed from MainWindow."""
_op_id: str
_operation: GraphComponent
_height: float
_ports: Dict[str, Dict[str, Union[float, QPointF]]] # ['port-id']['latency/pos']
_execution_time: Union[int, None]
_end_time: int
_component_item: QGraphicsPathItem
_execution_time_item: QGraphicsRectItem
......
......@@ -38,7 +38,7 @@ class GraphicsGraphEvent: # PyQt5
#@overload
def is_component_valid_pos(self, pos: float, end_time: int) -> bool: ...
def is_component_valid_pos(self, item: GraphicsComponentItem, pos: float) -> bool: ...
#@overload
def is_valid_delta_time(self, delta_time: int) -> bool: ...
#@overload
......@@ -156,13 +156,13 @@ class GraphicsGraphEvent: # PyQt5
dx = (item.mapToParent(event.pos()) - self._current_pos).x()
if dx > 0.505:
pos = item.x() + 1.0
if self.is_component_valid_pos(pos, item.end_time):
if self.is_component_valid_pos(item, pos):
# self.prepareGeometryChange()
item.setX(pos)
self._current_pos.setX(self._current_pos.x() + 1.0)
elif dx < -0.505:
pos = item.x() - 1.0
if self.is_component_valid_pos(pos, item.end_time):
if self.is_component_valid_pos(item, pos):
# self.prepareGeometryChange()
item.setX(pos)
self._current_pos.setX(self._current_pos.x() - 1.0)
......@@ -183,6 +183,9 @@ class GraphicsGraphEvent: # PyQt5
"""Changes the cursor to OpenHandCursor when releasing an object."""
item: GraphicsComponentItem = self.scene().mouseGrabberItem()
item.setCursor(QCursor(Qt.OpenHandCursor))
dx = (item.mapToParent(event.pos()) - self._current_pos).x()
pos = item.x()
self.set_new_starttime(item, pos)
def comp_mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent) -> None: ...
def comp_wheelEvent(self, event: QGraphicsSceneWheelEvent) -> None: ...
......
......@@ -60,23 +60,36 @@ class GraphicsGraphItem(GraphicsGraphEvent, QGraphicsItemGroup): # PySide2 /
item.setParentItem(None)
del item
def is_component_valid_pos(self, pos: float, end_time: int) -> bool:
def is_component_valid_pos(self, item: GraphicsComponentItem, pos: float) -> bool:
"""Takes in a component position and returns true if the component's new
position is valid, false otherwise."""
# TODO: implement
assert self.schedule is not None , "No schedule installed."
start_time = floor(pos) - floor(self._x_axis_indent)
end_time = item.end_time
new_start_time = floor(pos) - floor(self._x_axis_indent)
slacks = self.schedule.slacks(item.op_id)
op_start_time = self.schedule.start_time_of_operation(item.op_id)
if not -slacks[0] <= new_start_time - op_start_time <= slacks[1]:
return False
if pos < 0:
return False
elif (self.schedule.cyclic
and start_time > self.schedule.schedule_time):
and new_start_time > self.schedule.schedule_time):
return False
elif (not self.schedule.cyclic
and start_time + end_time > self.schedule.schedule_time):
and new_start_time + end_time > self.schedule.schedule_time):
return False
return True
def set_new_starttime(self, item: GraphicsComponentItem, pos: float) -> None:
op_start_time = self.schedule.start_time_of_operation(item.op_id)
new_start_time = floor(pos) - floor(self._x_axis_indent)
move_time = new_start_time - op_start_time
if move_time:
self.schedule.move_operation(item.op_id, move_time)
def is_valid_delta_time(self, delta_time: int) -> bool:
"""Takes in a delta time and returns true if the new schedule time is
valid, false otherwise."""
......
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