Skip to content
Snippets Groups Projects
Commit adb9740d authored by Andreas Bolin's avatar Andreas Bolin
Browse files

workspace dump

parent 2a9c4ca9
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #73084 passed
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
Graphical user interface for B-ASIC scheduler. Graphical user interface for B-ASIC scheduler.
""" """
from logger import * from logger import *
from main_window import * from main_window import *
from graphics_graph import * from graphics_graph import *
from graphics_axis import *
from component_item import *
#__all__ = ['main_window', 'scheduler'] # __all__ = ['main_window', 'graphics_graph', 'graphics_axis', 'component_item']
__version__ = '0.1' __version__ = '0.1'
__author__ = 'Andreas Bolin' __author__ = 'Andreas Bolin'
...@@ -39,7 +39,7 @@ class ComponentItem(QGraphicsItemGroup): ...@@ -39,7 +39,7 @@ class ComponentItem(QGraphicsItemGroup):
_item_group: QGraphicsItemGroup _item_group: QGraphicsItemGroup
def __init__(self, height: float = 1.0, parent: QGraphicsItem = None): def __init__(self, height: float = 10.0, parent: QGraphicsItem = None):
super().__init__(parent) super().__init__(parent)
self._height = height self._height = height
...@@ -48,6 +48,7 @@ class ComponentItem(QGraphicsItemGroup): ...@@ -48,6 +48,7 @@ class ComponentItem(QGraphicsItemGroup):
self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable) self.setFlag(QGraphicsItem.ItemIsSelectable)
# self.setHandlesChildEvents(False)
self._populate() self._populate()
...@@ -57,11 +58,8 @@ class ComponentItem(QGraphicsItemGroup): ...@@ -57,11 +58,8 @@ class ComponentItem(QGraphicsItemGroup):
return self._height return self._height
def _populate(self) -> None: def _populate(self) -> None:
# brush = QBrush(Qt.lightGray, bs=Qt.SolidPattern)
brush = QBrush(Qt.lightGray) brush = QBrush(Qt.lightGray)
# brush.setStyle(Qt.SolidPattern) pen = QPen(Qt.SolidPattern, 2/self._scale)
pen = QPen(Qt.SolidLine)
pen.setWidthF(1/self._scale)
pen.setBrush(Qt.darkGray) pen.setBrush(Qt.darkGray)
# pen.setCapStyle(Qt.RoundCap) # Qt.FlatCap, Qt.SquareCap (default), Qt.RoundCap # pen.setCapStyle(Qt.RoundCap) # Qt.FlatCap, Qt.SquareCap (default), Qt.RoundCap
pen.setJoinStyle(Qt.RoundJoin) # Qt.MiterJoin, Qt.BevelJoin (default), Qt.RoundJoin, Qt.SvgMiterJoin pen.setJoinStyle(Qt.RoundJoin) # Qt.MiterJoin, Qt.BevelJoin (default), Qt.RoundJoin, Qt.SvgMiterJoin
...@@ -69,21 +67,21 @@ class ComponentItem(QGraphicsItemGroup): ...@@ -69,21 +67,21 @@ class ComponentItem(QGraphicsItemGroup):
# component path # component path
component_path = QPainterPath(QPoint(0,0)) component_path = QPainterPath(QPoint(0,0))
component_path.lineTo(0, self._height/2) component_path.lineTo(0, self._height/2)
component_path.lineTo(0.2, self._height/2) component_path.lineTo(2, self._height/2)
component_path.lineTo(0.2, self._height) component_path.lineTo(2, self._height)
component_path.lineTo(4, self._height) component_path.lineTo(40, self._height)
component_path.lineTo(4, 0) component_path.lineTo(40, 0)
component_path.closeSubpath() component_path.closeSubpath()
# component item # component item
self._component_item.setPath(component_path) self._component_item.setPath(component_path)
self._component_item.setPen(pen) self._component_item.setPen(pen)
self._component_item.setBrush(brush) self._component_item.setBrush(brush)
self._component_item.setPos(1, 0) # in parent (i.e. self) coordinates self._component_item.setPos(10, 0) # in parent (i.e. self) coordinates
# execution time square # execution time square
execution_time_path = QPainterPath(QPoint(0,0)) execution_time_path = QPainterPath(QPoint(0,0))
execution_time_path.addRect(0, 0, 2.0, self._height) execution_time_path.addRect(0, 0, 20, self._height)
# execution time item # execution time item
green_color = QColor(Qt.magenta) green_color = QColor(Qt.magenta)
......
from operator import contains
import os import os
import sys import sys
from typing import Any, Optional from typing import Any, Optional
...@@ -6,7 +7,7 @@ from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union, Optional, ...@@ -6,7 +7,7 @@ from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union, Optional,
# from typing_extensions import Self, Final, Literal, LiteralString, TypeAlias, final # from typing_extensions import Self, Final, Literal, LiteralString, TypeAlias, final
import numpy as np import numpy as np
from copy import deepcopy from copy import deepcopy
from itertools import combinations from math import cos, sin, pi
import qtpy import qtpy
from qtpy import QtCore from qtpy import QtCore
...@@ -18,12 +19,12 @@ from qtpy.QtCore import ( ...@@ -18,12 +19,12 @@ from qtpy.QtCore import (
Qt, QObject, QRect, QRectF, QPoint, QSize, QSizeF, QByteArray) Qt, QObject, QRect, QRectF, QPoint, QSize, QSizeF, QByteArray)
from qtpy.QtGui import ( from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap, QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap,
QLinearGradient, QTransform) QLinearGradient, QTransform, QPolygonF)
from qtpy.QtWidgets import ( from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget, QGraphicsView, QGraphicsScene, QGraphicsWidget,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout, QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem, QGraphicsTextItem, QGraphicsRectItem, QGraphicsItem, QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLineItem, QGraphicsTextItem, QGraphicsRectItem,
QStyleOptionGraphicsItem, QWidget, QGraphicsObject, QGraphicsSimpleTextItem) QStyleOptionGraphicsItem, QWidget, QGraphicsObject, QGraphicsSimpleTextItem, QGraphicsPolygonItem)
from qtpy.QtCore import ( from qtpy.QtCore import (
QPoint, QPointF) QPoint, QPointF)
...@@ -37,20 +38,21 @@ class GraphicsAxis(QGraphicsItemGroup): ...@@ -37,20 +38,21 @@ class GraphicsAxis(QGraphicsItemGroup):
_scale: float = 1.0 _scale: float = 1.0
_width: float _width: float
_height: float _height: float
_x_indent: float
_axis: dict[str: Any] _axis: dict[str: Any]
Type: int
def __init__(self, width: float = 10.0, height: float = 10.0, x_indent: float = 2.0, parent: QGraphicsItem = None):
def __init__(self, width: float = 1.0, height: float = 1.0, parent: QGraphicsItem = None):
super().__init__(parent) super().__init__(parent)
self._width = width
self._height = height
self._axis = {} self._axis = {}
# self._axis['x'] = QGraphicsItemGroup() self.Type = 10 # QGraphicsItemGroup.Type == 10
# self._axis['y'] = QGraphicsLineItem()
self._make_axis() self.update(width, height, x_indent)
def type(self) -> int:
return self.Type
@property @property
def width(self) -> float: def width(self) -> float:
...@@ -76,10 +78,18 @@ class GraphicsAxis(QGraphicsItemGroup): ...@@ -76,10 +78,18 @@ class GraphicsAxis(QGraphicsItemGroup):
# for child in self._axis.values(): # for child in self._axis.values():
# del child # del child
def _make_axis(self) -> None: def update(self, width, height, x_indent) -> None:
self._width = width
self._height = height
self._x_indent = x_indent
pen = QPen() # make sure the group is empty
pen.setWidthF(2/self._scale) keys = list(self._axis.keys())
for key in keys:
self._axis[key].setParentItem(None)
del self._axis[key]
pen = QPen(Qt.SolidPattern, 2/self._scale, j = Qt.MiterJoin)
# x-axis # x-axis
self._axis['x'] = QGraphicsItemGroup() self._axis['x'] = QGraphicsItemGroup()
...@@ -87,37 +97,37 @@ class GraphicsAxis(QGraphicsItemGroup): ...@@ -87,37 +97,37 @@ class GraphicsAxis(QGraphicsItemGroup):
line.setPen(pen) line.setPen(pen)
self._axis['x'].addToGroup(line) self._axis['x'].addToGroup(line)
# x-axis arrow # x-axis arrow
arrow_line1 = QGraphicsLineItem(0, 0, -0.05, -0.05) arrow_size = 8/self._scale
arrow_line1.setPen(pen) p0 = QPointF(0, sin(pi/6) * arrow_size)
arrow_line1.setPos(self._width, 0) p1 = QPointF(arrow_size, 0)
self._axis['x'].addToGroup(arrow_line1) p2 = QPointF(0, -sin(pi/6) * arrow_size)
arrow_line2 = QGraphicsLineItem(0, 0, -0.05, 0.05) polygon = QPolygonF([p0, p1, p2])
arrow_line2.setPen(pen) arrow = QGraphicsPolygonItem(polygon)
arrow_line2.setPos(self._width, 0) arrow.setPen(pen)
self._axis['x'].addToGroup(arrow_line2) arrow.setBrush(Qt.SolidPattern)
arrow.setPos(self._width, 0)
self._axis['x'].addToGroup(arrow)
# x-axis scale # x-axis scale
# ticks = [x for x in range(int(self._width) + 1)]
# print(f'{range(int(self._width) + 1)}')
# print('xxxxxxxxxxxxxxxxxxxxxxx', x)
x_scale = [] x_scale = []
x_scale_labels = [] x_scale_labels = []
for i in range(int(self._width) + 1): for i in range(int(self._width/10) + 1):
# vertical x-scale # vertical x-scale
x_scale.append(QGraphicsLineItem(0, -0.05, 0, 0.05)) x_scale.append(QGraphicsLineItem(0, -0.5, 0, 0.5))
x_scale[i].setPen(pen) x_scale[i].setPen(pen)
x_scale[i].setPos(0.2 + i, 0) x_scale[i].setPos(self._x_indent + i*10, 0)
self._axis['x'].addToGroup(x_scale[i]) self._axis['x'].addToGroup(x_scale[i])
# numbers # numbers
x_scale_labels.append(QGraphicsSimpleTextItem(str(i))) x_scale_labels.append(QGraphicsSimpleTextItem(str(i)))
x_scale_labels[i].setScale(x_scale_labels[i].scale() / self._scale) x_scale_labels[i].setScale(x_scale_labels[i].scale() / self._scale)
x_scale_labels[i].setPen(pen) half_width = x_scale_labels[i].boundingRect().width()/(2*self._scale)
x_scale_labels[i].setPos(0.16 + i, 0.08) x_scale_labels[i].setPos(self._x_indent + i*10 - half_width, 0.8)
self._axis['x'].addToGroup(x_scale_labels[i]) self._axis['x'].addToGroup(x_scale_labels[i])
# x-axis label # x-axis label
label = QGraphicsSimpleTextItem('time') label = QGraphicsSimpleTextItem('time')
label.setScale(label.scale() / self._scale) label.setScale(label.scale() / self._scale)
label.setPos(self._width - 0.18, 0.08) half_width = label.boundingRect().width()/(2*self._scale)
arrow_half_width = arrow_size/2
label.setPos(self._width - half_width + arrow_half_width, 0.8)
self._axis['x'].addToGroup(label) self._axis['x'].addToGroup(label)
self._axis['x'].boundingRect() self._axis['x'].boundingRect()
# add x-axis # add x-axis
...@@ -127,7 +137,6 @@ class GraphicsAxis(QGraphicsItemGroup): ...@@ -127,7 +137,6 @@ class GraphicsAxis(QGraphicsItemGroup):
# y-axis # y-axis
self._axis['y'] = QGraphicsLineItem(0, 0, 0, self._height) self._axis['y'] = QGraphicsLineItem(0, 0, 0, self._height)
self._axis['y'].setPen(pen) self._axis['y'].setPen(pen)
self._axis['y'].setPos(0, 0)
# add y-axis # add y-axis
self.addToGroup(self._axis['y']) self.addToGroup(self._axis['y'])
\ No newline at end of file
...@@ -40,34 +40,45 @@ class GraphicsGraph(QGraphicsItemGroup): ...@@ -40,34 +40,45 @@ class GraphicsGraph(QGraphicsItemGroup):
_axis: GraphicsAxis _axis: GraphicsAxis
_component_group: QGraphicsItemGroup _component_group: QGraphicsItemGroup
_axis_group: QGraphicsItemGroup _axis_group: QGraphicsItemGroup
_components_height: float
_x_axis_indent: float
def __init__(self, schedule: Schedule, parent: QGraphicsItem = None): def __init__(self, schedule: Schedule, parent: QGraphicsItem = None):
super().__init__(parent) super().__init__(parent)
self.setHandlesChildEvents(False)
self._schedule = deepcopy(schedule) self._schedule = deepcopy(schedule)
self._axis = None self._axis = None
self._component_group = QGraphicsItemGroup() self._component_group = QGraphicsItemGroup()
self._axis_group = QGraphicsItemGroup() self._axis_group = QGraphicsItemGroup()
# add components # add components
y: float = 0.0 self._x_axis_indent = 2.0
self._components_height = 0.0
for i in range(5): for i in range(5):
component = ComponentItem() component = ComponentItem()
component.setPos(0, y) component.setPos(0, self._components_height)
self._component_group.addToGroup(component) self._component_group.addToGroup(component)
y += component.height + 0.2 self._components_height += component.height + 2
self._component_group.setPos(0.2, 0.1) self._component_group.setPos(self._x_axis_indent, 1)
self.addToGroup(self._component_group) self.addToGroup(self._component_group)
y += 0.1 self._components_height += 1.5
# add axis # add axis
self._axis = GraphicsAxis(5 + 0.6, y) self._axis = GraphicsAxis(50 + 6, self._components_height, self._x_axis_indent)
self.addToGroup(self._axis) self.addToGroup(self._axis)
def update(self) -> None:
# self.prepareGeometryChange()
self.removeFromGroup(self._axis)
self._axis.update(40 + 6, self._components_height, self._x_axis_indent)
self.addToGroup(self._axis)
# @property # @property
......
...@@ -33,14 +33,14 @@ from qtpy.QtWidgets import ( ...@@ -33,14 +33,14 @@ from qtpy.QtWidgets import (
# QGraphics and QPainter imports # QGraphics and QPainter imports
from qtpy.QtCore import ( from qtpy.QtCore import (
QRect, QRectF, QPoint, QSize, QByteArray) QRect, QRectF, QPoint, QSize, QByteArray, QMarginsF)
from qtpy.QtGui import ( from qtpy.QtGui import (
QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap, QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap,
QLinearGradient) QLinearGradient)
from qtpy.QtWidgets import ( from qtpy.QtWidgets import (
QGraphicsView, QGraphicsScene, QGraphicsWidget, QGraphicsScale, QGraphicsView, QGraphicsScene, QGraphicsWidget, QGraphicsScale,
QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout, QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsLayoutItem, QGraphicsAnchorLayout,
QGraphicsItem, QGraphicsItemGroup) QGraphicsItem, QGraphicsItemGroup, QGraphicsRectItem)
# B-ASIC # B-ASIC
import logger import logger
...@@ -117,6 +117,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -117,6 +117,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
_scene_count: int _scene_count: int
_open_file_dialog_opened: bool _open_file_dialog_opened: bool
_scale: float _scale: float
_debug_rects: QGraphicsItemGroup
def __init__(self): def __init__(self):
...@@ -127,7 +128,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -127,7 +128,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._scene_count = 0 self._scene_count = 0
self._graph_count = 0 self._graph_count = 0
self._open_file_dialog_opened = False self._open_file_dialog_opened = False
self._scale = 75.0 self._scale = 10.0
self._debug_rects = None
QIcon.setThemeName('breeze') QIcon.setThemeName('breeze')
log.debug('themeName: \'{}\''.format(QIcon.themeName())) log.debug('themeName: \'{}\''.format(QIcon.themeName()))
...@@ -275,21 +277,29 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -275,21 +277,29 @@ class MainWindow(QMainWindow, Ui_MainWindow):
graph = GraphicsGraph(schedule) graph = GraphicsGraph(schedule)
# graph.setPos(200, 20)
self._scene.addItem(graph) self._scene.addItem(graph)
# graph.prepareGeometryChange()
# graph.setPos(200, 20)
# Debug rectangles # self._scene.setSceneRect(self._scene.itemsBoundingRect()) # Forces the scene to it's minimum size
# # Debug rectangles
# if __debug__: # if __debug__:
# self._scene.setSceneRect(self._scene.itemsBoundingRect()) # Forces the scene to it's minimum size # # self._scene.setSceneRect(self._scene.itemsBoundingRect()) # Forces the scene to it's minimum size
# m = QMarginsF(1/self._scale, 1/self._scale, 0, 0)
# m2 = QMarginsF(1, 1, 1, 1)
# pen = QPen(Qt.red) # pen = QPen(Qt.red)
# pen.setStyle(Qt.DashLine) # pen.setStyle(Qt.DotLine)
# pen.setCosmetic(True) # pen.setCosmetic(True)
# for component in graph.items: # for component in graph.items:
# self._scene.addRect(component.mapRectToScene(component.boundingRect()), pen) # self._scene.addRect(component.mapRectToScene(component.boundingRect() - m), pen)
# pen.setColor(Qt.red)
# for axis in graph.axis.childItems(): # for axis in graph.axis.childItems():
# self._scene.addRect(axis.mapRectToScene(axis.boundingRect()), pen) # self._scene.addRect(axis.mapRectToScene(axis.boundingRect() - m), pen)
# pen.setColor(Qt.green) # pen.setColor(Qt.green)
# self._scene.addRect(self._scene.itemsBoundingRect(), pen) # # self._scene.addRect(self._scene.itemsBoundingRect() - m, pen)
......
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