diff options
author | Blaine | 2020-06-09 12:39:52 +0530 |
---|---|---|
committer | Blaine | 2020-06-10 11:29:49 +0530 |
commit | 2cdd1b40a2cf410ea1970afeb692649e7cd07b29 (patch) | |
tree | ea2a9490f767d644c3241e1ab18674af831d98a1 /src/main/python | |
parent | 0d33ceda3262494437fe022466e4368db62c8849 (diff) | |
download | Chemical-PFD-2cdd1b40a2cf410ea1970afeb692649e7cd07b29.tar.gz Chemical-PFD-2cdd1b40a2cf410ea1970afeb692649e7cd07b29.tar.bz2 Chemical-PFD-2cdd1b40a2cf410ea1970afeb692649e7cd07b29.zip |
implement id logic
Diffstat (limited to 'src/main/python')
-rw-r--r-- | src/main/python/shapes/line.py | 8 | ||||
-rw-r--r-- | src/main/python/shapes/shapes.py | 7 | ||||
-rw-r--r-- | src/main/python/utils/app.py | 5 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 21 |
4 files changed, 31 insertions, 10 deletions
diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 92c5b1d..85c5753 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -919,8 +919,12 @@ class Line(QGraphicsPathItem): "_classname_": self.__class__.__name__, "startPoint": (self.startPoint.x(), self.startPoint.y()), "endPoint": (self.endPoint.x(), self.endPoint.y()), - "points": [(point.x(), point.y()) for point in self.points] + "points": [(point.x(), point.y()) for point in self.points], + "startGripItem": hex(id(self.startGripItem)), + "endGripItem": hex(id(self.endGripItem)) if self.endGripItem else 0, + "refLine": hex(id(self.refLine)) if self.refLine else 0, + "refIndex": self.refIndex, + "id": hex(id(self)) } - def __setstate__(self, dict): self.points = [QPointF(x, y) for x, y in dict["points"]] diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 0358898..774951d 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -12,7 +12,6 @@ from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, from .line import Line, findIndex from utils.app import fileImporter -from utils.app import fileImporter class ItemLabel(QGraphicsTextItem): def __init__(self, pos, parent=None): @@ -498,7 +497,8 @@ class NodeItem(QGraphicsSvgItem): "_classname_": self.__class__.__name__, "width": self.width, "height": self.height, - "pos": (self.pos().x(), self.pos().y()) + "pos": (self.pos().x(), self.pos().y()), + "lineGripItems": [(hex(id(i)), i.m_index) for i in self.lineGripItems] } def __setstate__(self, dict): @@ -506,9 +506,6 @@ class NodeItem(QGraphicsSvgItem): self.width = dict['width'] self.height = dict['height'] self.rect = QRectF(-self.width / 2, -self.height / 2, self.width, self.height) - transform = QTransform() - transform.translate(self.width / 2, self.height / 2) - self.setTransform(transform, True) self.updateSizeGripItem() # classes of pfd-symbols diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py index 5d85cb7..92c403c 100644 --- a/src/main/python/utils/app.py +++ b/src/main/python/utils/app.py @@ -49,4 +49,7 @@ class JSON_Typer(JSONEncoder): return JSON_Encoder._encode(obj) def encode(self, obj): - return super(JSON_Typer, self).encode(self._encode(obj))
\ No newline at end of file + return super(JSON_Typer, self).encode(self._encode(obj)) + +shapeGrips = {} +lines = {}
\ No newline at end of file diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index a83aeb2..2b029e0 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -6,7 +6,7 @@ from PyQt5.QtWidgets import (QFileDialog, QApplication, QHBoxLayout, QMenu, from . import dialogs from .graphics import customView, customScene from .data import paperSizes, ppiList, sheetDimensionList -from .app import dumps, loads, JSON_Typer +from .app import dumps, loads, JSON_Typer, shapeGrips, lines import shapes @@ -129,7 +129,7 @@ class canvas(QWidget): "canvasSize": self._canvasSize, "ObjectName": self.objectName(), "symbols": [i for i in self.painter.items() if isinstance(i, shapes.NodeItem)], - "lines": [i for i in self.painter.items() if isinstance(i, shapes.Line)], + "lines": sorted([i for i in self.painter.items() if isinstance(i, shapes.Line)], key = lambda x: 1 if x.refLine else 0), # "lineLabels": [i.__getstate__() for i in self.painter.items() if isinstance(i, shapes.LineLabel)], # "itemLabels": [i.__getstate__() for i in self.painter.items() if isinstance(i, shapes.itemLabel)] } @@ -144,12 +144,29 @@ class canvas(QWidget): graphic.__setstate__(dict = item) self.painter.addItem(graphic) graphic.setPos(*item['pos']) + for gripitem in item['lineGripItems']: + shapeGrips[gripitem[0]] = (graphic, gripitem[1]) for item in dict['lines']: line = shapes.Line(QPointF(*item['startPoint']), QPointF(*item['endPoint'])) + lines[item['id']] = line line.__setstate__(dict = item) + graphic, index = shapeGrips[item['startGripItem']] + line.setStartGripItem = graphic.lineGripItems[index] + graphic.lineGripItems[index].line = line + print("hello2") + if item['endGripItem']: + graphic, index = shapeGrips[item['endGripItem']] + line.setEndGripItem = graphic.lineGripItems[index] + graphic.lineGripItems[index].line = line + else: + line.refLine = lines[item['refLine']] + line.refIndex = item['refIndex'] self.painter.addItem(line) + # line.addGrabber() + shapeGrips.clear() + lines.clear() self.painter.advance() # for item in dict['lineLabels']: |