From 02363abb603af1d696cc3dd44a4535b6f16f9730 Mon Sep 17 00:00:00 2001 From: sumit Date: Thu, 28 May 2020 10:07:54 +0530 Subject: change final shape of line --- src/main/python/shapes/line.py | 336 +++++++++++++++++++++++++++++++++++---- src/main/python/shapes/shapes.py | 17 +- 2 files changed, 320 insertions(+), 33 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 310b496..fa10936 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -20,6 +20,8 @@ class Grabber(QGraphicsPathItem): self.setFlag(QGraphicsItem.ItemIsMovable, True) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) self.setAcceptHoverEvents(True) + self.pen = QPen(Qt.white, -1, Qt.SolidLine) + self.brush = QBrush(Qt.transparent) def itemChange(self, change, value): """ move position of grabber after resize""" @@ -37,13 +39,11 @@ class Grabber(QGraphicsPathItem): def paint(self, painter, option, widget): """paints the path of grabber only if it is selected """ - if self.isSelected(): - # show line of grabber + if self.isSelected() and not self.m_annotation_item.isSelected() : + # show parent line of grabber self.m_annotation_item.setSelected(True) - painter.setBrush(QBrush(Qt.cyan)) - color = Qt.black if self.isSelected() else Qt.white - width = 2 if self.isSelected() else -1 - painter.setPen(QPen(color, width, Qt.SolidLine)) + painter.setBrush(self.brush) + painter.setPen(self.pen) painter.drawPath(self.path()) # To paint path of shape @@ -90,6 +90,14 @@ class Grabber(QGraphicsPathItem): self.setCursor(QCursor(Qt.ArrowCursor)) super(Grabber, self).hoverLeaveEvent(event) + def show(self): + self.pen = QPen(Qt.black, 2, Qt.SolidLine) + self.brush = QBrush(Qt.cyan) + + def hide(self): + self.pen = QPen(Qt.white, -1, Qt.SolidLine) + self.brush = QBrush(Qt.transparent) + class Line(QGraphicsPathItem): """ @@ -125,18 +133,284 @@ class Line(QGraphicsPathItem): offset = 30 x0, y0 = self.startPoint.x(), self.startPoint.y() x1, y1 = self.endPoint.x(), self.endPoint.y() + # create line is in process self.points = [self.startPoint, QPointF((x0 + x1) / 2, y0), QPointF((x0 + x1) / 2, y1), self.endPoint] - if self.startGripItem and self.startGripItem.m_location in ["left", "right"]: - if self.endGripItem and self.endGripItem.m_location in ["top", "bottom"]: - if self.endGripItem.m_location == "top": offset = -offset - self.points = [self.startPoint, QPointF((x0 + x1) / 2, y0), QPointF((x0 + x1) / 2, y1 + offset), - QPointF(self.endPoint.x(), y1 + offset), self.endPoint] - - if self.startGripItem and self.startGripItem.m_location in ["top", "bottom"]: - self.points = [self.startPoint, QPointF(x0, (y0 + y1) / 2), QPointF(x1, (y0 + y1) / 2), self.endPoint] - if self.endGripItem and self.endGripItem.m_location in ["left", "right"]: - self.points = [self.startPoint, QPointF(x0, (y0 + y1) / 2), QPointF(x1 - offset, (y0 + y1) / 2), - QPointF(x1 - offset, self.endPoint.y()), self.endPoint] + # final path of line + if self.startGripItem and self.endGripItem: + # determine ns (point next to start) + item = self.startGripItem + self.startPoint = item.parentItem().mapToScene(item.pos()) + if item.m_location == "top": + ns = QPointF(self.startPoint.x(), self.startPoint.y() - offset) + elif item.m_location == "left": + ns = QPointF(self.startPoint.x() - offset, self.startPoint.y()) + elif item.m_location == "bottom": + ns = QPointF(self.startPoint.x(), self.startPoint.y() + offset) + else: + ns = QPointF(self.startPoint.x() + offset, self.startPoint.y()) + # pe (point previous to end) + item = self.endGripItem + self.endPoint = item.parentItem().mapToScene(item.pos()) + if item.m_location == "top": + pe = QPointF(self.endPoint.x(), self.endPoint.y() - offset) + elif item.m_location == "left": + pe = QPointF(self.endPoint.x() - offset, self.endPoint.y()) + elif item.m_location == "bottom": + pe = QPointF(self.endPoint.x(), self.endPoint.y() + offset) + else: + pe = QPointF(self.endPoint.x() + offset, self.endPoint.y()) + + start = self.startPoint + end = self.endPoint + sheight = self.startGripItem.m_annotation_item.boundingRect().height() / 2 + swidth = self.startGripItem.m_annotation_item.boundingRect().width() / 2 + eheight = self.endGripItem.m_annotation_item.boundingRect().height() / 2 + ewidth = self.endGripItem.m_annotation_item.boundingRect().width() / 2 + + if self.startGripItem.m_location in ["right"]: + if self.endGripItem.m_location in ["top"]: + if start.x() + offset < end.x() - ewidth: + if start.y() + offset < end.y(): + self.points = [start, QPointF(end.x(), start.y()), end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + elif start.x() - 2 * swidth > end.x(): + if start.y() + sheight + offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + elif start.y() - sheight - offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight - offset), + QPointF(pe.x(), ns.y() - sheight - offset), end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + if start.y() > end.y(): + x = max(end.x() + ewidth + offset, ns.x()) + self.points = [start, QPointF(x, start.y()), QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + if start.x() + offset < end.x() - ewidth: + if start.y() + offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + else: + self.points = [start, QPointF(end.x(), start.y()), end] + + elif start.x() - 2 * swidth > end.x(): + if start.y() + sheight + offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + elif start.y() - sheight - offset < end.y(): + y = max(pe.y(), start.y() + sheight + offset) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + if start.y() < end.y(): + x = max(end.x() + ewidth + offset, ns.x()) + self.points = [start, QPointF(x, start.y()), QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + x = max(start.x() + offset, pe.x()) + self.points = [start, QPointF(x, start.y()), QPointF(x, end.y()), end] + if start.x() + offset < end.x() - ewidth: + if start.y() + offset > end.y() - eheight and end.y() >= start.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y() - eheight), + QPointF(pe.x(), pe.y() - eheight), pe, end] + elif start.y() - offset < end.y() + eheight and end.y() <= start.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y() + eheight), + QPointF(pe.x(), pe.y() + eheight), pe, end] + elif start.y() - sheight - offset < end.y() < start.y() + sheight + offset: + if end.y() < start.y(): + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), pe, end] + + elif self.endGripItem.m_location in ["left"]: + self.points = [start, QPointF((start.x() + end.x()) / 2, start.y()), + QPointF((start.x() + end.x()) / 2, end.y()), end] + if end.x() < start.x() + offset: + if end.y() + eheight <= start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + elif end.y() - eheight >= start.y() + sheight + offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), pe, end] + elif end.y() <= start.y(): + y = min(end.y() - eheight, start.y() - sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + else: + y = max(end.y() + eheight, start.y() + sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + + + elif self.startGripItem.m_location in ["left"]: + if self.endGripItem.m_location in ["top"]: + if start.x() + offset < end.x() - ewidth: + if end.y() > start.y() + sheight + offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), end] + else: + y = min(start.y() - sheight, pe.y()) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), end] + elif end.x() + ewidth >= start.x() - offset: + x = min(ns.x(), end.x() - ewidth) + self.points = [start, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + else: + if end.y() >= start.y() + offset: + self.points = [start, QPointF(end.x(), start.y()), end] + else: + x = (start.x() + end.x()) / 2 + self.points = [start, QPointF(x, start.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + if start.x() + offset < end.x() - ewidth: + if end.y() < start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), end] + else: + y = max(start.y() + sheight, pe.y()) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), end] + elif end.x() + ewidth >= start.x() - offset: + x = min(ns.x(), end.x() - ewidth) + self.points = [start, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + else: + if end.y() <= start.y() - offset: + self.points = [start, QPointF(end.x(), start.y()), end] + else: + x = (start.x() + end.x()) / 2 + self.points = [start, QPointF(x, start.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + self.points = [start, QPointF((start.x() + end.x()) / 2, start.y()), + QPointF((start.x() + end.x()) / 2, end.y()), end] + if end.x() > start.x() + offset: + if end.y() + eheight <= start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + elif end.y() - eheight >= start.y() + sheight + offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), pe, end] + elif end.y() <= start.y(): + y = min(end.y() - eheight, start.y() - sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + else: + y = max(end.y() + eheight, start.y() + sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + + elif self.endGripItem.m_location in ["left"]: + self.points = [start, QPointF(pe.x(), start.y()), pe, end] + if start.x() + offset < end.x(): + self.points = [start, ns, QPointF(ns.x(), end.y()), end] + if start.y() + sheight + offset > end.y() > start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + elif end.y() - eheight - offset < start.y() < end.y() + eheight + offset: + if end.y() > start.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y() - eheight), + QPointF(pe.x(), pe.y() - eheight), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y() + eheight), + QPointF(pe.x(), pe.y() + eheight), pe, end] + + + elif self.startGripItem.m_location in ["top"]: + if self.endGripItem.m_location in ["top"]: + self.points = [self.startPoint, QPointF(start.x(), pe.y()), + pe, self.endPoint] + if start.y() < end.y(): + self.points = [self.startPoint, ns, QPointF(pe.x(), ns.y()), self.endPoint] + if start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + if start.x() > end.x(): + x = min(start.x() - swidth, end.x() - ewidth) + x -= offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + self.points = [self.startPoint, ns, QPointF((x0 + x1) / 2, ns.y()), QPointF((x0 + x1) / 2, pe.y()), + pe, self.endPoint] + if start.y() - offset > end.y(): + self.points = [start, QPointF(start.x(), (y0 + y1) / 2), QPointF(end.x(), (y0 + y1) / 2), + self.endPoint] + elif start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + if start.x() > end.x(): + x = min(start.x() - swidth, end.x() - ewidth) + x -= offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + y = min(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset and end.y() > start.y() + offset: + self.points = [start, ns, QPointF(ns.x() + swidth + offset, ns.y()), + QPointF(ns.x() + swidth + offset, pe.y()), end] + elif end.y() - eheight < start.y() - offset < end.y() + eheight: + self.points = [start, ns, QPointF(start.x(), end.y() - eheight), + QPointF(pe.x(), end.y() - eheight), pe, end] + + elif self.endGripItem.m_location in ["left"]: + y = min(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset and end.y() > start.y() + offset: + self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), + QPointF(ns.x() - swidth - offset, pe.y()), end] + elif end.y() - eheight < start.y() - offset < end.y() + eheight: + self.points = [start, ns, QPointF(start.x(), end.y() - eheight), + QPointF(pe.x(), end.y() - eheight), pe, end] + + elif self.startGripItem.m_location in ["bottom"]: + if self.endGripItem.m_location in ["top"]: + self.points = [self.startPoint, ns, QPointF((x0 + x1) / 2, ns.y()), QPointF((x0 + x1) / 2, pe.y()), + pe, self.endPoint] + if start.y() < end.y(): + self.points = [self.startPoint, ns, QPointF(pe.x(), ns.y()), self.endPoint] + if start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + self.points = [self.startPoint, ns, QPointF((x0 + x1) / 2, ns.y()), QPointF((x0 + x1) / 2, pe.y()), + pe, self.endPoint] + if start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + y = max(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset: + self.points = [start, ns, QPointF(ns.x() + swidth + offset, ns.y()), + QPointF(ns.x() + swidth + offset, pe.y()), end] + + elif self.endGripItem.m_location in ["left"]: + y = max(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset: + self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), + QPointF(ns.x() - swidth - offset, pe.y()), end] + # draw line path = QPainterPath(self.startPoint) for i in range(1, len(self.points)): @@ -197,12 +471,12 @@ class Line(QGraphicsPathItem): # To paint path of shape # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) # painter.drawPath(self.shape()) - if self.isSelected(): - self.showGripItem() - self._selected = True - elif self._selected: - self.hideGripItem() - self._selected = False + # if self.isSelected(): + # self.showGripItem() + # self._selected = True + # elif self._selected: + # self.hideGripItem() + # self._selected = False def movePoints(self, index, movement): """move points of line @@ -222,7 +496,7 @@ class Line(QGraphicsPathItem): else: direction = [Qt.Vertical, Qt.Horizontal] for i in range(1, len(self.points) - 2): - item = Grabber(self, i, direction[i - 1]) + item = Grabber(self, i, direction[(i - 1)%2]) item.setParentItem(self) item.setPos(self.pos()) self.scene().addItem(item) @@ -243,6 +517,12 @@ class Line(QGraphicsPathItem): grabber.setEnabled(True) def itemChange(self, change, value): + if change == QGraphicsItem.ItemSelectedHasChanged: + if value == 1: + self.showGripItem() + else: + self.hideGripItem() + return if change == QGraphicsItem.ItemSceneHasChanged and self.scene(): # self.addGrabber() # self.updateGrabber() @@ -280,18 +560,20 @@ class Line(QGraphicsPathItem): self.scene().removeItem(self) def showGripItem(self): - """hides grip items which contains line + """shows grip items which contains line """ if self.startGripItem: self.startGripItem.show() if self.endGripItem: self.endGripItem.show() - # for grabber in self.m_grabber: - # grabber.setSelected(True) + for grabber in self.m_grabbers: + grabber.show() def hideGripItem(self): """hides grip items which contains line """ if self.startGripItem: self.startGripItem.hide() if self.endGripItem: self.endGripItem.hide() + for grabber in self.m_grabbers: + grabber.hide() def setStartGripItem(self, item): self.startGripItem = item diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 210d68e..0807e96 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -66,7 +66,7 @@ class SizeGripItem(GripItem): self.width = annotation_item.boundingRect().width() path = QPainterPath() - path.addRect(QRectF(-self.width/2, -self.height/2, self.width, self.height)) + path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) super(SizeGripItem, self).__init__(annotation_item, path=path, parent=parent) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setFlag(QGraphicsItem.ItemIsMovable, True) @@ -97,7 +97,7 @@ class SizeGripItem(GripItem): else: self.width = self.parentItem().boundingRect().width() path = QPainterPath() - path.addRect(QRectF(-self.width/2, -self.height/2, self.width, self.height)) + path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) self.setPath(path) def updatePosition(self): @@ -225,7 +225,6 @@ class LineGripItem(GripItem): # initialize a line and add on scene startPoint = endPoint = self.parentItem().mapToScene(self.pos()) self.tempLine = Line(startPoint, endPoint) - self.tempLine.setStartGripItem(self) self.scene().addItem(self.tempLine) super().mousePressEvent(mouseEvent) @@ -258,6 +257,7 @@ class LineGripItem(GripItem): self.transform()) if type(item) == LineGripItem and item != self: + self.tempLine.setStartGripItem(self) self.tempLine.setEndGripItem(item) endPoint = item.parentItem().mapToScene(item.pos()) self.tempLine.updateLine(endPoint=endPoint) @@ -294,11 +294,13 @@ class NodeItem(QGraphicsSvgItem): """ Extends PyQt5's QGraphicsSvgItem to create the basic structure of shapes with given unit operation type """ + renderer = QSvgRenderer("For sample svg_2.svg") def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) - self.m_type = unitOperationType - self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") + self.id = unitOperationType + self.m_renderer = NodeItem.renderer + # self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") # self.m_renderer = QSvgRenderer(resourceManager.get_resource(f'toolbar/{unitOperationType}.svg')) self.setSharedRenderer(self.m_renderer) # set initial size of item @@ -330,7 +332,10 @@ class NodeItem(QGraphicsSvgItem): """ if not self.m_renderer: QGraphicsSvgItem.paint(self, painter, option, widget) - self.m_renderer.render(painter, self.boundingRect()) + elif self.id: + self.m_renderer.render(painter,self.id, self.boundingRect()) + else: + self.m_renderer.render(painter, self.boundingRect()) if self.isSelected(): self.showGripItem() -- cgit From 237a19e87df926c2d66be49a1aa5c26edaf9add4 Mon Sep 17 00:00:00 2001 From: sumit Date: Thu, 28 May 2020 19:11:52 +0530 Subject: open svg from resources --- src/main/python/shapes/shapes.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 0807e96..7db759c 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -1,4 +1,3 @@ -# from fbs_runtime.application_context.PyQt5 import ApplicationContext from PyQt5 import QtCore, QtWidgets from PyQt5.QtSvg import QGraphicsSvgItem, QSvgRenderer from PyQt5.QtWidgets import QLineEdit, QGraphicsItem, QGraphicsEllipseItem, QGraphicsProxyWidget, QGraphicsPathItem, \ @@ -6,11 +5,10 @@ from PyQt5.QtWidgets import QLineEdit, QGraphicsItem, QGraphicsEllipseItem, QGra from PyQt5.QtGui import QPen, QColor, QFont, QCursor, QPainterPath, QPainter, QDrag, QBrush, QImage, QTransform from PyQt5.QtCore import Qt, QRectF, QPointF, QSizeF, QEvent, QMimeData, QFile, QIODevice, QRect -from line import Line +from .line import Line +from utils.app import fileImporter -# resourceManager = ApplicationContext() - class GripItem(QGraphicsPathItem): """ @@ -294,14 +292,15 @@ class NodeItem(QGraphicsSvgItem): """ Extends PyQt5's QGraphicsSvgItem to create the basic structure of shapes with given unit operation type """ - renderer = QSvgRenderer("For sample svg_2.svg") + # set a common renderer for all svg + renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) - self.id = unitOperationType + self.id = None self.m_renderer = NodeItem.renderer - # self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") - # self.m_renderer = QSvgRenderer(resourceManager.get_resource(f'toolbar/{unitOperationType}.svg')) + # if each svg is seperate file + # self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) self.setSharedRenderer(self.m_renderer) # set initial size of item self.width = 100 -- cgit From 5e0015b53c72d59e34376f6a48597c1420f7dedf Mon Sep 17 00:00:00 2001 From: sumit Date: Sat, 30 May 2020 16:58:46 +0530 Subject: remove extra point of line --- src/main/python/shapes/line.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index fa10936..8bba5be 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -2,6 +2,7 @@ from PyQt5.QtGui import QPen, QPainterPath, QBrush, QPainterPathStroker, QPainte from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem from PyQt5.QtCore import Qt, QPointF, QRectF + class Grabber(QGraphicsPathItem): """ Extends QGraphicsPathItem to create grabber for line for moving a particular segment @@ -373,7 +374,7 @@ class Line(QGraphicsPathItem): self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), QPointF(ns.x() - swidth - offset, pe.y()), end] elif end.y() - eheight < start.y() - offset < end.y() + eheight: - self.points = [start, ns, QPointF(start.x(), end.y() - eheight), + self.points = [start, QPointF(start.x(), end.y() - eheight), QPointF(pe.x(), end.y() - eheight), pe, end] elif self.startGripItem.m_location in ["bottom"]: -- cgit From 25341b4f0c95f404b2acbeb4d23c3decb2a8f346 Mon Sep 17 00:00:00 2001 From: sumit Date: Sat, 30 May 2020 17:08:18 +0530 Subject: change add line for undo --- src/main/python/shapes/shapes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 7db759c..19c0298 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -223,7 +223,7 @@ class LineGripItem(GripItem): # initialize a line and add on scene startPoint = endPoint = self.parentItem().mapToScene(self.pos()) self.tempLine = Line(startPoint, endPoint) - self.scene().addItem(self.tempLine) + self.scene().addItemPlus(self.tempLine) super().mousePressEvent(mouseEvent) def mouseMoveEvent(self, mouseEvent): @@ -297,6 +297,7 @@ class NodeItem(QGraphicsSvgItem): def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) + self.m_type = unitOperationType self.id = None self.m_renderer = NodeItem.renderer # if each svg is seperate file @@ -616,9 +617,9 @@ class InducedDraftCooling(NodeItem): super(InducedDraftCooling, self).__init__("InducedDraftCooling", parent=None) -class jacketedMixingVessel(NodeItem): +class JacketedMixingVessel(NodeItem): def __init__(self): - super(jacketedMixingVessel, self).__init__("jacketedMixingVessel", parent=None) + super(JacketedMixingVessel, self).__init__("JacketedMixingVessel", parent=None) class LiquidRingCompressor(NodeItem): -- cgit From 3d48ad1d1884aacb74e569f60b213aa2be64d539 Mon Sep 17 00:00:00 2001 From: sumit Date: Sun, 31 May 2020 21:31:43 +0530 Subject: common path of lines --- src/main/python/shapes/line.py | 58 ++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 8bba5be..2c5a527 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -126,6 +126,46 @@ class Line(QGraphicsPathItem): # initiates path self.createPath() + def advance(self, phase): + # items = self.collidingItems(Qt.IntersectsItemShape) + items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.DescendingOrder) + self.commonPaths = [] + for item in items: + if type(item) in [type(self)]: + if item == self: + break + # origin = self.mapFromItem(item, 0, 0) + shape = item.shape() + shape = self.mapFromItem(item, item.shape()) + commonPath = self.shape().intersected(shape) + self.commonPaths.append(commonPath) + + def paint(self, painter, option, widget): + color = Qt.red if self.isSelected() else Qt.black + painter.setPen(QPen(color, 2, self.penStyle)) + path = self.path() + painter.drawPath(path) + for p in self.commonPaths: + print("length = ",p.length(),"element = ",p.elementCount()) + for i in range(p.elementCount()): + print(p.elementAt(i).x,p.elementAt(i).y) + # if p.elementAt(0).x == p.elementAt(1).x: + # pass + painter.save() + painter.setPen(Qt.darkYellow) + painter.setBrush(Qt.darkYellow) + painter.drawPath(p) + painter.restore() + # painter.setPen(QPen(QBrush(Qt.black),-1)) + # painter.setBrush(QBrush(Qt.red)) + # print(painter.pen().width()) + # painter.drawPath(path) + + # To paint path of shape + # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) + # painter.drawPath(self.shape()) + + def createPath(self): """ creates initial path and stores it's points @@ -412,7 +452,7 @@ class Line(QGraphicsPathItem): self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), QPointF(ns.x() - swidth - offset, pe.y()), end] - # draw line + # path of line path = QPainterPath(self.startPoint) for i in range(1, len(self.points)): path.lineTo(self.points[i]) @@ -464,21 +504,6 @@ class Line(QGraphicsPathItem): path = qp.createStroke(self.path()) return path - def paint(self, painter, option, widget): - color = Qt.red if self.isSelected() else Qt.black - painter.setPen(QPen(color, 2, self.penStyle)) - painter.drawPath(self.path()) - - # To paint path of shape - # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) - # painter.drawPath(self.shape()) - # if self.isSelected(): - # self.showGripItem() - # self._selected = True - # elif self._selected: - # self.hideGripItem() - # self._selected = False - def movePoints(self, index, movement): """move points of line """ @@ -543,6 +568,7 @@ class Line(QGraphicsPathItem): self.endPoint = endPoint self.createPath() self.updateGrabber() + self.scene().update() return if self.startGripItem and self.endGripItem: -- cgit From df2e93d76688cdfe5620184d45bd0ec78daa706a Mon Sep 17 00:00:00 2001 From: sumit Date: Sun, 31 May 2020 21:41:45 +0530 Subject: add variable commonPaths --- src/main/python/shapes/line.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 2c5a527..9f3bfaf 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -125,6 +125,7 @@ class Line(QGraphicsPathItem): self.setAcceptHoverEvents(True) # initiates path self.createPath() + self.commonPaths=[] def advance(self, phase): # items = self.collidingItems(Qt.IntersectsItemShape) -- cgit From 8296841405bb3dc3fd6414bdb3f2da5c76e43895 Mon Sep 17 00:00:00 2001 From: sumit Date: Tue, 2 Jun 2020 11:50:35 +0530 Subject: add text label to line --- src/main/python/shapes/line.py | 87 +++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 23 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 9f3bfaf..e6b1dd9 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -1,5 +1,6 @@ +import math from PyQt5.QtGui import QPen, QPainterPath, QBrush, QPainterPathStroker, QPainter, QCursor -from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem +from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem, QGraphicsTextItem from PyQt5.QtCore import Qt, QPointF, QRectF @@ -99,6 +100,50 @@ class Grabber(QGraphicsPathItem): self.pen = QPen(Qt.white, -1, Qt.SolidLine) self.brush = QBrush(Qt.transparent) +class LineLabel(QGraphicsTextItem): + def __init__(self, parent=None): + super(LineLabel, self).__init__(parent=parent) + self.setTextInteractionFlags(Qt.TextEditorInteraction) + self.setFlags(QGraphicsItem.ItemIsMovable | + QGraphicsItem.ItemIsSelectable | + QGraphicsItem.ItemIsFocusable) + self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) + self.setPlainText("abc") + + def paint(self, painter, option, widget): + super(LineLabel, self).paint(painter,option,widget) + painter.drawEllipse(self.boundingRect()) + + def updateLabel(self): + points = self.parentItem().points + # min_A = QPointF() + # min_B =QPointF() + # min_dis =math.inf + # for i in range(1, len(points)): + # A = points[i - 1] + # B = points[i] + # C = self.pos() + # BAx = B.x() - A.x() + # BAy = B.y() - A.y() + # CAx = C.x() - A.x() + # CAy = C.y() - A.y() + # length = math.sqrt(BAx * BAx + BAy * BAy) + # if length >0: + # dis = (BAx*CAy - CAx*BAy)/length + # if abs(dis) < abs(min_dis): + # min_dis=dis + # min_A=A + # min_B=B + # + # self.setPos(self.parentItem().mapFromScene(QPointF(min_A))) + # print(self.pos()) + + def itemChange(self, change, value): + print("label change",change,value) + # if change == QGraphicsItem.ItemPositionChange: + # print("label change", change, value) + return super(LineLabel, self).itemChange(change,value) + class Line(QGraphicsPathItem): """ @@ -126,45 +171,41 @@ class Line(QGraphicsPathItem): # initiates path self.createPath() self.commonPaths=[] + self.label = LineLabel(self) def advance(self, phase): # items = self.collidingItems(Qt.IntersectsItemShape) - items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.DescendingOrder) + items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.AscendingOrder) self.commonPaths = [] for item in items: if type(item) in [type(self)]: if item == self: break - # origin = self.mapFromItem(item, 0, 0) shape = item.shape() shape = self.mapFromItem(item, item.shape()) commonPath = self.shape().intersected(shape) - self.commonPaths.append(commonPath) + polygons = commonPath.toSubpathPolygons() + for polygon in polygons: + center = polygon.boundingRect().center() + self.commonPaths.append(center) + # self.commonPaths[commonPath] = item + self.update() def paint(self, painter, option, widget): color = Qt.red if self.isSelected() else Qt.black painter.setPen(QPen(color, 2, self.penStyle)) - path = self.path() - painter.drawPath(path) - for p in self.commonPaths: - print("length = ",p.length(),"element = ",p.elementCount()) - for i in range(p.elementCount()): - print(p.elementAt(i).x,p.elementAt(i).y) - # if p.elementAt(0).x == p.elementAt(1).x: - # pass - painter.save() - painter.setPen(Qt.darkYellow) - painter.setBrush(Qt.darkYellow) - painter.drawPath(p) - painter.restore() - # painter.setPen(QPen(QBrush(Qt.black),-1)) - # painter.setBrush(QBrush(Qt.red)) - # print(painter.pen().width()) + # path = self.path() # painter.drawPath(path) + path = QPainterPath(self.startPoint) + # iterating over all points of line + for i in range(1, len(self.points)): + for point in self.commonPaths: + # point is center of common path + pass + path.lineTo(self.points[i]) + painter.drawPath(path) + - # To paint path of shape - # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) - # painter.drawPath(self.shape()) def createPath(self): -- cgit From 375b02f7857c410a0ebbb55bdffd37726cc6faf3 Mon Sep 17 00:00:00 2001 From: Sumit-Sahu Date: Tue, 2 Jun 2020 12:12:11 +0530 Subject: remove shapes.py from pull request --- src/main/python/shapes/shapes.py | 747 --------------------------------------- 1 file changed, 747 deletions(-) delete mode 100644 src/main/python/shapes/shapes.py (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py deleted file mode 100644 index 19c0298..0000000 --- a/src/main/python/shapes/shapes.py +++ /dev/null @@ -1,747 +0,0 @@ -from PyQt5 import QtCore, QtWidgets -from PyQt5.QtSvg import QGraphicsSvgItem, QSvgRenderer -from PyQt5.QtWidgets import QLineEdit, QGraphicsItem, QGraphicsEllipseItem, QGraphicsProxyWidget, QGraphicsPathItem, \ - QGraphicsSceneHoverEvent, QGraphicsColorizeEffect -from PyQt5.QtGui import QPen, QColor, QFont, QCursor, QPainterPath, QPainter, QDrag, QBrush, QImage, QTransform -from PyQt5.QtCore import Qt, QRectF, QPointF, QSizeF, QEvent, QMimeData, QFile, QIODevice, QRect - -from .line import Line -from utils.app import fileImporter - - - -class GripItem(QGraphicsPathItem): - """ - Extends QGraphicsPathItem to create the structure of the Grabbable points for resizing shapes and connecting lines. - Takes two parameters, reference item (On which the grip items are to appear) and the path of the item - """ - - def __init__(self, annotation_item, path, parent=None): - """ - Extends PyQt5's QGraphicsPathItem to create the general structure of the Grabbable points for resizing shapes. - """ - QGraphicsPathItem.__init__(self, parent) - self.m_annotation_item = annotation_item - # set path of item - self.setPath(path) - self.setAcceptHoverEvents(True) - self.setCursor(QCursor(Qt.PointingHandCursor)) - - # def hoverEnterEvent(self, event): - # """ - # defines shape highlighting on Mouse Over - # """ - # self.setPen(QPen(QColor("black"), 2)) - # self.setBrush(QColor("red")) - # super(GripItem, self).hoverEnterEvent(event) - # - # def hoverLeaveEvent(self, event): - # """ - # defines shape highlighting on Mouse Leave - # """ - # self.setPen(QPen(Qt.transparent)) - # self.setBrush(Qt.transparent) - # super(GripItem, self).hoverLeaveEvent(event) - - def mouseReleaseEvent(self, event): - """ - Automatically deselects grip item on mouse release - """ - self.setSelected(False) - super(GripItem, self).mouseReleaseEvent(event) - - -class SizeGripItem(GripItem): - """ - Extends grip items for vertical and horizontal directions, with hover events and directional changes - """ - - def __init__(self, annotation_item, index, direction=Qt.Horizontal, parent=None): - self.width = self.height = 0 - if direction is Qt.Horizontal: - self.height = annotation_item.boundingRect().height() - else: - self.width = annotation_item.boundingRect().width() - - path = QPainterPath() - path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) - super(SizeGripItem, self).__init__(annotation_item, path=path, parent=parent) - self.setFlag(QGraphicsItem.ItemIsSelectable, True) - self.setFlag(QGraphicsItem.ItemIsMovable, True) - self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) - self.setPen(QPen(QColor("black"), -1)) - self.setZValue(2) - self._direction = direction - self.m_index = index - - @property - def direction(self): - """ - property that returns the current intended resize direction of the grip item object - """ - return self._direction - - def paint(self, painter, option, widget): - if self.isSelected() and not self.parentItem().isSelected(): - self.parentItem().setSelected(True) - self.parentItem().setFlag(QGraphicsSvgItem.ItemIsMovable, False) - super().paint(painter, option, widget) - - def updatePath(self): - """updates path of size grip item - """ - if self._direction is Qt.Horizontal: - self.height = self.parentItem().boundingRect().height() - else: - self.width = self.parentItem().boundingRect().width() - path = QPainterPath() - path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) - self.setPath(path) - - def updatePosition(self): - """updates position of grip items - """ - self.updatePath() - pos = self.point(self.m_index) - self.setEnabled(False) - self.setPos(pos) - self.setEnabled(True) - - def point(self, index): - """ - yields a list of positions of grip items in a node item - """ - width = self.parentItem().boundingRect().width() - height = self.parentItem().boundingRect().height() - if 0 <= index < 4: - return [ - QPointF(0, -height / 2), - QPointF(-width / 2, 0), - QPointF(0, height / 2), - QPointF(width / 2, 0) - ][index] - - def hoverEnterEvent(self, event): - """ - Changes cursor to horizontal resize or vertical resize depending on the direction of the grip item on mouse enter - """ - # self.setPen(QPen(QColor("black"), 2)) - # self.setBrush(QColor("red")) - if self._direction == Qt.Horizontal: - self.setCursor(QCursor(Qt.SizeHorCursor)) - else: - self.setCursor(QCursor(Qt.SizeVerCursor)) - super(SizeGripItem, self).hoverEnterEvent(event) - - def hoverLeaveEvent(self, event): - """ - reverts cursor to default on mouse leave - """ - # self.setPen(QPen(Qt.transparent)) - # self.setBrush(Qt.transparent) - self.setCursor(QCursor(Qt.ArrowCursor)) - super(SizeGripItem, self).hoverLeaveEvent(event) - - def itemChange(self, change, value): - """ - Moves position of grip item on resize - """ - if change == QGraphicsItem.ItemPositionChange and self.isEnabled(): - p = QPointF(self.pos()) - if self.direction == Qt.Horizontal: - p.setX(value.x()) - elif self.direction == Qt.Vertical: - p.setY(value.y()) - # Find change in positions - movement = p - self.pos() - # Set transform to oppose change in transformation due to parent - transform = QTransform() - transform.translate(-movement.x() / 2, -movement.y() / 2) - self.setTransform(transform, True) - self.parentItem().resize(self.m_index, movement) - return p - return super(SizeGripItem, self).itemChange(change, value) - - def mouseReleaseEvent(self, event): - super(SizeGripItem, self).mouseReleaseEvent(event) - # Reset transform and update position - self.resetTransform() - self.updatePosition() - # Make parent item move able - self.parentItem().setFlag(QGraphicsSvgItem.ItemIsMovable, True) - # If needed to reset transform of parent set it's position accordingly - # self.parentItem().setPos(self.parentItem().x() + self.parentItem().transform().dx(), self.parentItem().y() + self.parentItem().transform().dy()) - # self.parentItem().resetTransform() - - -class LineGripItem(GripItem): - """Extends grip items for connecting lines , with hover events and mouse events - """ - circle = QPainterPath() - circle.addEllipse(QRectF(-10, -10, 20, 20)) - - def __init__(self, annotation_item, index, location, parent=None): - self.path = LineGripItem.circle - super(LineGripItem, self).__init__(annotation_item, path=self.path, parent=parent) - self.m_index = index - self.m_location = location - self.connectedLines = [] - # stores current line which is in process - self.tempLine = None - # keep previous hovered item when line drawing in process - self.previousHoveredItem = None - self.setFlag(QGraphicsItem.ItemIsSelectable, True) - self.setPen(QPen(QColor("black"), -1)) - - def point(self, index): - """ - yields a list of positions of grip items in a node item - """ - width = self.parentItem().boundingRect().width() - height = self.parentItem().boundingRect().height() - if 0 <= index < 4: - return [ - QPointF(0, -height / 2), - QPointF(-width / 2, 0), - QPointF(0, height / 2), - QPointF(width / 2, 0) - ][index] - - def updatePosition(self): - pos = self.point(self.m_index) - self.setEnabled(False) - self.setPos(pos) - self.setEnabled(True) - for line in self.connectedLines: - line.updateLine() - - def mousePressEvent(self, mouseEvent): - """Handle all mouse press for this item - """ - if mouseEvent.button() != Qt.LeftButton: - return - # initialize a line and add on scene - startPoint = endPoint = self.parentItem().mapToScene(self.pos()) - self.tempLine = Line(startPoint, endPoint) - self.scene().addItemPlus(self.tempLine) - super().mousePressEvent(mouseEvent) - - def mouseMoveEvent(self, mouseEvent): - """Handle all mouse move for this item - """ - # if line get started then update it's end point - if self.tempLine: - endPoint = mouseEvent.scenePos() - self.tempLine.updateLine(endPoint=endPoint) - - item = self.scene().itemAt(mouseEvent.scenePos().x(), mouseEvent.scenePos().y(), - self.parentItem().transform()) - - if self.previousHoveredItem and item != self.previousHoveredItem and \ - item not in self.previousHoveredItem.lineGripItems: - self.previousHoveredItem.hideGripItem() - super().mouseMoveEvent(mouseEvent) - - if type(item) == NodeItem: - self.previousHoveredItem = item - item.showGripItem() - - def mouseReleaseEvent(self, mouseEvent): - """Handle all mouse release for this item""" - super().mouseReleaseEvent(mouseEvent) - # set final position of line - if self.tempLine: - item = self.scene().itemAt(mouseEvent.scenePos().x(), mouseEvent.scenePos().y(), - self.transform()) - - if type(item) == LineGripItem and item != self: - self.tempLine.setStartGripItem(self) - self.tempLine.setEndGripItem(item) - endPoint = item.parentItem().mapToScene(item.pos()) - self.tempLine.updateLine(endPoint=endPoint) - self.connectedLines.append(self.tempLine) - item.connectedLines.append(self.tempLine) - - - - elif self.tempLine and self.scene(): - self.scene().removeItem(self.tempLine) - self.tempLine = None - self.previousHoveredItem = None - - def removeConnectedLines(self): - """removes all connected line to grip""" - for line in self.connectedLines: - line.removeFromCanvas() - - def show(self): - """ shows line grip item - """ - self.setPen(QPen(QColor("black"), 2)) - self.setBrush(QColor("red")) - - def hide(self): - """ hides line grip item - """ - if (self.parentItem().isSelected() or self.isSelected()) is False: - self.setPen(QPen(Qt.transparent)) - self.setBrush(Qt.transparent) - - -class NodeItem(QGraphicsSvgItem): - """ - Extends PyQt5's QGraphicsSvgItem to create the basic structure of shapes with given unit operation type - """ - # set a common renderer for all svg - renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) - - def __init__(self, unitOperationType, parent=None): - QGraphicsSvgItem.__init__(self, parent) - self.m_type = unitOperationType - self.id = None - self.m_renderer = NodeItem.renderer - # if each svg is seperate file - # self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) - self.setSharedRenderer(self.m_renderer) - # set initial size of item - self.width = 100 - self.height = 150 - self.rect = QRectF(-self.width / 2, -self.height / 2, self.width, self.height) - # set graphical settings for this item - self.setFlags(QGraphicsSvgItem.ItemIsMovable | - QGraphicsSvgItem.ItemIsSelectable | - QGraphicsSvgItem.ItemSendsGeometryChanges) - self.setAcceptHoverEvents(True) - self.setZValue(2) - # grip items connected to this item - self.lineGripItems = [] - self.sizeGripItems = [] - - def boundingRect(self): - """Overrides QGraphicsSvgItem's boundingRect() virtual public function and - returns a valid bounding - """ - return self.rect - - def paint(self, painter, option, widget): - """ - Paints the contents of an item in local coordinates. - :param painter: QPainter instance - :param option: QStyleOptionGraphicsItem instance - :param widget: QWidget instance - """ - if not self.m_renderer: - QGraphicsSvgItem.paint(self, painter, option, widget) - elif self.id: - self.m_renderer.render(painter,self.id, self.boundingRect()) - else: - self.m_renderer.render(painter, self.boundingRect()) - if self.isSelected(): - self.showGripItem() - - def resize(self, index, movement): - """Move grip item with changing rect of node item - """ - self.prepareGeometryChange() - if index in [0, 1]: - self.width -= movement.x() - self.height -= movement.y() - else: - self.width += movement.x() - self.height += movement.y() - - self.rect = QRectF(-self.width / 2, -self.height / 2, self.width, self.height) - transform = QTransform() - transform.translate(movement.x() / 2, movement.y() / 2) - self.setTransform(transform, True) - self.updateSizeGripItem([index]) - - def addGripItem(self): - """adds grip items - """ - if self.scene(): - # add grip items for connecting lines - for i, (location) in enumerate( - ( - "top", - "left", - "bottom", - "right" - ) - ): - item = LineGripItem(self, i, location, parent=self) - self.lineGripItems.append(item) - # add grip for resize it - for i, (direction) in enumerate( - ( - Qt.Vertical, - Qt.Horizontal, - Qt.Vertical, - Qt.Horizontal, - ) - ): - item = SizeGripItem(self, i, direction, parent=self) - self.sizeGripItems.append(item) - - def updateLineGripItem(self, index_no_updates=None): - """ - updates line grip items - """ - # index_no_updates = index_no_updates or [] - for item in self.lineGripItems: - item.updatePosition() - - def updateSizeGripItem(self, index_no_updates=None): - """ - updates size grip items - """ - index_no_updates = index_no_updates or [] - for i, item in zip(range(len(self.sizeGripItems)), self.sizeGripItems): - if i not in index_no_updates: - item.updatePosition() - - def itemChange(self, change, value): - """Overloads and extends QGraphicsSvgItem to also update grip items - """ - if change == QGraphicsItem.ItemSelectedHasChanged: - if value is True: - self.showGripItem() - else: - self.hideGripItem() - return - if change == QGraphicsItem.ItemTransformHasChanged: - self.updateLineGripItem() - return - if change == QGraphicsItem.ItemPositionHasChanged: - self.updateLineGripItem() - self.updateSizeGripItem() - return - if change == QGraphicsItem.ItemSceneHasChanged: - self.addGripItem() - self.updateLineGripItem() - self.updateSizeGripItem() - return - return super(NodeItem, self).itemChange(change, value) - - def removeFromCanvas(self): - """This function is used to remove item from canvas - :return: - """ - for item in self.lineGripItems: - item.removeConnectedLines() - for item in self.sizeGripItems: - item.removeFromCanvas() - self.scene().removeItem(self) - - def hoverEnterEvent(self, event): - """defines shape highlighting on Mouse Over - """ - self.showGripItem() - super(NodeItem, self).hoverEnterEvent(event) - - def hoverLeaveEvent(self, event): - """defines shape highlighting on Mouse Leave - """ - self.hideGripItem() - super(NodeItem, self).hoverLeaveEvent(event) - - def showGripItem(self): - """shows grip items of svg item - """ - for item in self.lineGripItems: - item.setPen(QPen(QColor("black"), 2)) - item.setBrush(QColor("red")) - for item in self.sizeGripItems: - item.setPen(QPen(QColor("black"), 2)) - - def hideGripItem(self): - """hide grip items of svg item - """ - for item in self.lineGripItems: - if item.isSelected() is False: - item.setPen(QPen(Qt.transparent)) - item.setBrush(Qt.transparent) - for item in self.sizeGripItems: - item.setPen(QPen(Qt.transparent)) - item.setBrush(Qt.transparent) - - -# classes of pfd-symbols -class AirBlownCooler(NodeItem): - def __init__(self): - super(AirBlownCooler, self).__init__("AirBlownCooler", parent=None) - - -class Bag(NodeItem): - def __init__(self): - super(Bag, self).__init__("Bag", parent=None) - - -class Boiler(NodeItem): - def __init__(self): - super(Boiler, self).__init__("Boiler", parent=None) - - -class Breaker(NodeItem): - def __init__(self): - super(Breaker, self).__init__("Breaker", parent=None) - - -class BriquettingMachine(NodeItem): - def __init__(self): - super(BriquettingMachine, self).__init__("BriquettingMachine", parent=None) - - -class Centrifugal(NodeItem): - def __init__(self): - super(Centrifugal, self).__init__("Centrifugal", parent=None) - - -class CentrifugalCompressor(NodeItem): - def __init__(self): - super(CentrifugalCompressor, self).__init__("CentrifugalCompressor", parent=None) - - -class Centrifugalpump(NodeItem): - def __init__(self): - super(Centrifugalpump, self).__init__("Centrifugalpump", parent=None) - - -class CentrifugalPump2(NodeItem): - def __init__(self): - super(CentrifugalPump2, self).__init__("CentrifugalPump2", parent=None) - - -class CentrifugalPump3(NodeItem): - def __init__(self): - super(CentrifugalPump3, self).__init__("CentrifugalPump3", parent=None) - - -class Column(NodeItem): - def __init__(self): - super(Column, self).__init__("Column", parent=None) - - -class Compressor(NodeItem): - def __init__(self): - super(Compressor, self).__init__("Compressor", parent=None) - - -class CompressorSilencers(NodeItem): - def __init__(self): - super(CompressorSilencers, self).__init__("CompressorSilencers", parent=None) - - -class Condenser(NodeItem): - def __init__(self): - super(Condenser, self).__init__("Condenser", parent=None) - - -class Cooler(NodeItem): - def __init__(self): - super(Cooler, self).__init__("Cooler", parent=None) - - -class CoolingTower3(NodeItem): - def __init__(self): - super(CoolingTower3, self).__init__("CoolingTower3", parent=None) - - -class CoolingTwoer2(NodeItem): - def __init__(self): - super(CoolingTwoer2, self).__init__("CoolingTwoer2", parent=None) - - -class Crusher(NodeItem): - def __init__(self): - super(Crusher, self).__init__("Crusher", parent=None) - - -class DoublePipeHeat(NodeItem): - def __init__(self): - super(DoublePipeHeat, self).__init__("DoublePipeHeat", parent=None) - - -class ExtractorHood(NodeItem): - def __init__(self): - super(ExtractorHood, self).__init__("ExtractorHood", parent=None) - - -class FiredHeater(NodeItem): - def __init__(self): - super(FiredHeater, self).__init__("FiredHeater", parent=None) - - -class ForcedDraftCooling(NodeItem): - def __init__(self): - super(ForcedDraftCooling, self).__init__("ForcedDraftCooling", parent=None) - - -class Furnace(NodeItem): - def __init__(self): - super(Furnace, self).__init__("Furnace", parent=None) - - -class GasBottle(NodeItem): - def __init__(self): - super(GasBottle, self).__init__("GasBottle", parent=None) - - -class HalfPipeMixingVessel(NodeItem): - def __init__(self): - super(HalfPipeMixingVessel, self).__init__("HalfPipeMixingVessel", parent=None) - - -class Heater(NodeItem): - def __init__(self): - super(Heater, self).__init__("Heater", parent=None) - - -class HeatExchanger(NodeItem): - def __init__(self): - super(HeatExchanger, self).__init__("HeatExchanger", parent=None) - - -class HeatExchanger2(NodeItem): - def __init__(self): - super(HeatExchanger2, self).__init__("HeatExchanger2", parent=None) - - -class HorizontalVessel(NodeItem): - def __init__(self): - super(HorizontalVessel, self).__init__("HorizontalVessel", parent=None) - - -class InducedDraftCooling(NodeItem): - def __init__(self): - super(InducedDraftCooling, self).__init__("InducedDraftCooling", parent=None) - - -class JacketedMixingVessel(NodeItem): - def __init__(self): - super(JacketedMixingVessel, self).__init__("JacketedMixingVessel", parent=None) - - -class LiquidRingCompressor(NodeItem): - def __init__(self): - super(LiquidRingCompressor, self).__init__("LiquidRingCompressor", parent=None) - - -class Mixing(NodeItem): - def __init__(self): - super(Mixing, self).__init__("Mixing", parent=None) - - -class MixingReactor(NodeItem): - def __init__(self): - super(MixingReactor, self).__init__("MixingReactor", parent=None) - - -class OilBurner(NodeItem): - def __init__(self): - super(OilBurner, self).__init__("OilBurner", parent=None) - - -class OpenTank(NodeItem): - def __init__(self): - super(OpenTank, self).__init__("OpenTank", parent=None) - - -class ProportionalPump(NodeItem): - def __init__(self): - super(ProportionalPump, self).__init__("ProportionalPump", parent=None) - - -class Pump(NodeItem): - def __init__(self): - super(Pump, self).__init__("Pump", parent=None) - - -class Pump2(NodeItem): - def __init__(self): - super(Pump2, self).__init__("Pump2", parent=None) - - -class ReboilerHeatExchange(NodeItem): - def __init__(self): - super(ReboilerHeatExchange, self).__init__("ReboilerHeatExchange", parent=None) - - -class ReciprocatingCompressor(NodeItem): - def __init__(self): - super(ReciprocatingCompressor, self).__init__("ReciprocatingCompressor", parent=None) - - -class RotaryCompresor(NodeItem): - def __init__(self): - super(RotaryCompresor, self).__init__("RotaryCompresor", parent=None) - - -class RotaryGearPump(NodeItem): - def __init__(self): - super(RotaryGearPump, self).__init__("RotaryGearPump", parent=None) - - -class ScrewPump(NodeItem): - def __init__(self): - super(ScrewPump, self).__init__("ScrewPump", parent=None) - - -class SelectableCompressor(NodeItem): - def __init__(self): - super(SelectableCompressor, self).__init__("SelectableCompressor", parent=None) - - -class SelectableFan(NodeItem): - def __init__(self): - super(SelectableFan, self).__init__("SelectableFan", parent=None) - - -class SinglePassHeat(NodeItem): - def __init__(self): - super(SinglePassHeat, self).__init__("SinglePassHeat", parent=None) - - -class SpiralHeatExchanger(NodeItem): - def __init__(self): - super(SpiralHeatExchanger, self).__init__("SpiralHeatExchanger", parent=None) - - -class StraightTubersHeat(NodeItem): - def __init__(self): - super(StraightTubersHeat, self).__init__("StraightTubersHeat", parent=None) - - -class Tank(NodeItem): - def __init__(self): - super(Tank, self).__init__("Tank", parent=None) - - -class TurbinePump(NodeItem): - def __init__(self): - super(TurbinePump, self).__init__("TurbinePump", parent=None) - - -class UTubeHeatExchanger(NodeItem): - def __init__(self): - super(UTubeHeatExchanger, self).__init__("UTubeHeatExchanger", parent=None) - - -class VaccumPump(NodeItem): - def __init__(self): - super(VaccumPump, self).__init__("VaccumPump", parent=None) - - -class VerticalPump(NodeItem): - def __init__(self): - super(VerticalPump, self).__init__("VerticalPump", parent=None) - - -class VerticalVessel(NodeItem): - def __init__(self): - super(VerticalVessel, self).__init__("VerticalVessel", parent=None) - - -class WastewaterTreatment(NodeItem): - def __init__(self): - super(WastewaterTreatment, self).__init__("WastewaterTreatment", parent=None) -- cgit From 1a61fee7bd6038489a14fadc268dec663c50eb42 Mon Sep 17 00:00:00 2001 From: sumit Date: Tue, 2 Jun 2020 12:33:41 +0530 Subject: undo delete shapes.py --- src/main/python/shapes/shapes.py | 747 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 747 insertions(+) create mode 100644 src/main/python/shapes/shapes.py (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py new file mode 100644 index 0000000..19c0298 --- /dev/null +++ b/src/main/python/shapes/shapes.py @@ -0,0 +1,747 @@ +from PyQt5 import QtCore, QtWidgets +from PyQt5.QtSvg import QGraphicsSvgItem, QSvgRenderer +from PyQt5.QtWidgets import QLineEdit, QGraphicsItem, QGraphicsEllipseItem, QGraphicsProxyWidget, QGraphicsPathItem, \ + QGraphicsSceneHoverEvent, QGraphicsColorizeEffect +from PyQt5.QtGui import QPen, QColor, QFont, QCursor, QPainterPath, QPainter, QDrag, QBrush, QImage, QTransform +from PyQt5.QtCore import Qt, QRectF, QPointF, QSizeF, QEvent, QMimeData, QFile, QIODevice, QRect + +from .line import Line +from utils.app import fileImporter + + + +class GripItem(QGraphicsPathItem): + """ + Extends QGraphicsPathItem to create the structure of the Grabbable points for resizing shapes and connecting lines. + Takes two parameters, reference item (On which the grip items are to appear) and the path of the item + """ + + def __init__(self, annotation_item, path, parent=None): + """ + Extends PyQt5's QGraphicsPathItem to create the general structure of the Grabbable points for resizing shapes. + """ + QGraphicsPathItem.__init__(self, parent) + self.m_annotation_item = annotation_item + # set path of item + self.setPath(path) + self.setAcceptHoverEvents(True) + self.setCursor(QCursor(Qt.PointingHandCursor)) + + # def hoverEnterEvent(self, event): + # """ + # defines shape highlighting on Mouse Over + # """ + # self.setPen(QPen(QColor("black"), 2)) + # self.setBrush(QColor("red")) + # super(GripItem, self).hoverEnterEvent(event) + # + # def hoverLeaveEvent(self, event): + # """ + # defines shape highlighting on Mouse Leave + # """ + # self.setPen(QPen(Qt.transparent)) + # self.setBrush(Qt.transparent) + # super(GripItem, self).hoverLeaveEvent(event) + + def mouseReleaseEvent(self, event): + """ + Automatically deselects grip item on mouse release + """ + self.setSelected(False) + super(GripItem, self).mouseReleaseEvent(event) + + +class SizeGripItem(GripItem): + """ + Extends grip items for vertical and horizontal directions, with hover events and directional changes + """ + + def __init__(self, annotation_item, index, direction=Qt.Horizontal, parent=None): + self.width = self.height = 0 + if direction is Qt.Horizontal: + self.height = annotation_item.boundingRect().height() + else: + self.width = annotation_item.boundingRect().width() + + path = QPainterPath() + path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) + super(SizeGripItem, self).__init__(annotation_item, path=path, parent=parent) + self.setFlag(QGraphicsItem.ItemIsSelectable, True) + self.setFlag(QGraphicsItem.ItemIsMovable, True) + self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) + self.setPen(QPen(QColor("black"), -1)) + self.setZValue(2) + self._direction = direction + self.m_index = index + + @property + def direction(self): + """ + property that returns the current intended resize direction of the grip item object + """ + return self._direction + + def paint(self, painter, option, widget): + if self.isSelected() and not self.parentItem().isSelected(): + self.parentItem().setSelected(True) + self.parentItem().setFlag(QGraphicsSvgItem.ItemIsMovable, False) + super().paint(painter, option, widget) + + def updatePath(self): + """updates path of size grip item + """ + if self._direction is Qt.Horizontal: + self.height = self.parentItem().boundingRect().height() + else: + self.width = self.parentItem().boundingRect().width() + path = QPainterPath() + path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) + self.setPath(path) + + def updatePosition(self): + """updates position of grip items + """ + self.updatePath() + pos = self.point(self.m_index) + self.setEnabled(False) + self.setPos(pos) + self.setEnabled(True) + + def point(self, index): + """ + yields a list of positions of grip items in a node item + """ + width = self.parentItem().boundingRect().width() + height = self.parentItem().boundingRect().height() + if 0 <= index < 4: + return [ + QPointF(0, -height / 2), + QPointF(-width / 2, 0), + QPointF(0, height / 2), + QPointF(width / 2, 0) + ][index] + + def hoverEnterEvent(self, event): + """ + Changes cursor to horizontal resize or vertical resize depending on the direction of the grip item on mouse enter + """ + # self.setPen(QPen(QColor("black"), 2)) + # self.setBrush(QColor("red")) + if self._direction == Qt.Horizontal: + self.setCursor(QCursor(Qt.SizeHorCursor)) + else: + self.setCursor(QCursor(Qt.SizeVerCursor)) + super(SizeGripItem, self).hoverEnterEvent(event) + + def hoverLeaveEvent(self, event): + """ + reverts cursor to default on mouse leave + """ + # self.setPen(QPen(Qt.transparent)) + # self.setBrush(Qt.transparent) + self.setCursor(QCursor(Qt.ArrowCursor)) + super(SizeGripItem, self).hoverLeaveEvent(event) + + def itemChange(self, change, value): + """ + Moves position of grip item on resize + """ + if change == QGraphicsItem.ItemPositionChange and self.isEnabled(): + p = QPointF(self.pos()) + if self.direction == Qt.Horizontal: + p.setX(value.x()) + elif self.direction == Qt.Vertical: + p.setY(value.y()) + # Find change in positions + movement = p - self.pos() + # Set transform to oppose change in transformation due to parent + transform = QTransform() + transform.translate(-movement.x() / 2, -movement.y() / 2) + self.setTransform(transform, True) + self.parentItem().resize(self.m_index, movement) + return p + return super(SizeGripItem, self).itemChange(change, value) + + def mouseReleaseEvent(self, event): + super(SizeGripItem, self).mouseReleaseEvent(event) + # Reset transform and update position + self.resetTransform() + self.updatePosition() + # Make parent item move able + self.parentItem().setFlag(QGraphicsSvgItem.ItemIsMovable, True) + # If needed to reset transform of parent set it's position accordingly + # self.parentItem().setPos(self.parentItem().x() + self.parentItem().transform().dx(), self.parentItem().y() + self.parentItem().transform().dy()) + # self.parentItem().resetTransform() + + +class LineGripItem(GripItem): + """Extends grip items for connecting lines , with hover events and mouse events + """ + circle = QPainterPath() + circle.addEllipse(QRectF(-10, -10, 20, 20)) + + def __init__(self, annotation_item, index, location, parent=None): + self.path = LineGripItem.circle + super(LineGripItem, self).__init__(annotation_item, path=self.path, parent=parent) + self.m_index = index + self.m_location = location + self.connectedLines = [] + # stores current line which is in process + self.tempLine = None + # keep previous hovered item when line drawing in process + self.previousHoveredItem = None + self.setFlag(QGraphicsItem.ItemIsSelectable, True) + self.setPen(QPen(QColor("black"), -1)) + + def point(self, index): + """ + yields a list of positions of grip items in a node item + """ + width = self.parentItem().boundingRect().width() + height = self.parentItem().boundingRect().height() + if 0 <= index < 4: + return [ + QPointF(0, -height / 2), + QPointF(-width / 2, 0), + QPointF(0, height / 2), + QPointF(width / 2, 0) + ][index] + + def updatePosition(self): + pos = self.point(self.m_index) + self.setEnabled(False) + self.setPos(pos) + self.setEnabled(True) + for line in self.connectedLines: + line.updateLine() + + def mousePressEvent(self, mouseEvent): + """Handle all mouse press for this item + """ + if mouseEvent.button() != Qt.LeftButton: + return + # initialize a line and add on scene + startPoint = endPoint = self.parentItem().mapToScene(self.pos()) + self.tempLine = Line(startPoint, endPoint) + self.scene().addItemPlus(self.tempLine) + super().mousePressEvent(mouseEvent) + + def mouseMoveEvent(self, mouseEvent): + """Handle all mouse move for this item + """ + # if line get started then update it's end point + if self.tempLine: + endPoint = mouseEvent.scenePos() + self.tempLine.updateLine(endPoint=endPoint) + + item = self.scene().itemAt(mouseEvent.scenePos().x(), mouseEvent.scenePos().y(), + self.parentItem().transform()) + + if self.previousHoveredItem and item != self.previousHoveredItem and \ + item not in self.previousHoveredItem.lineGripItems: + self.previousHoveredItem.hideGripItem() + super().mouseMoveEvent(mouseEvent) + + if type(item) == NodeItem: + self.previousHoveredItem = item + item.showGripItem() + + def mouseReleaseEvent(self, mouseEvent): + """Handle all mouse release for this item""" + super().mouseReleaseEvent(mouseEvent) + # set final position of line + if self.tempLine: + item = self.scene().itemAt(mouseEvent.scenePos().x(), mouseEvent.scenePos().y(), + self.transform()) + + if type(item) == LineGripItem and item != self: + self.tempLine.setStartGripItem(self) + self.tempLine.setEndGripItem(item) + endPoint = item.parentItem().mapToScene(item.pos()) + self.tempLine.updateLine(endPoint=endPoint) + self.connectedLines.append(self.tempLine) + item.connectedLines.append(self.tempLine) + + + + elif self.tempLine and self.scene(): + self.scene().removeItem(self.tempLine) + self.tempLine = None + self.previousHoveredItem = None + + def removeConnectedLines(self): + """removes all connected line to grip""" + for line in self.connectedLines: + line.removeFromCanvas() + + def show(self): + """ shows line grip item + """ + self.setPen(QPen(QColor("black"), 2)) + self.setBrush(QColor("red")) + + def hide(self): + """ hides line grip item + """ + if (self.parentItem().isSelected() or self.isSelected()) is False: + self.setPen(QPen(Qt.transparent)) + self.setBrush(Qt.transparent) + + +class NodeItem(QGraphicsSvgItem): + """ + Extends PyQt5's QGraphicsSvgItem to create the basic structure of shapes with given unit operation type + """ + # set a common renderer for all svg + renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) + + def __init__(self, unitOperationType, parent=None): + QGraphicsSvgItem.__init__(self, parent) + self.m_type = unitOperationType + self.id = None + self.m_renderer = NodeItem.renderer + # if each svg is seperate file + # self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) + self.setSharedRenderer(self.m_renderer) + # set initial size of item + self.width = 100 + self.height = 150 + self.rect = QRectF(-self.width / 2, -self.height / 2, self.width, self.height) + # set graphical settings for this item + self.setFlags(QGraphicsSvgItem.ItemIsMovable | + QGraphicsSvgItem.ItemIsSelectable | + QGraphicsSvgItem.ItemSendsGeometryChanges) + self.setAcceptHoverEvents(True) + self.setZValue(2) + # grip items connected to this item + self.lineGripItems = [] + self.sizeGripItems = [] + + def boundingRect(self): + """Overrides QGraphicsSvgItem's boundingRect() virtual public function and + returns a valid bounding + """ + return self.rect + + def paint(self, painter, option, widget): + """ + Paints the contents of an item in local coordinates. + :param painter: QPainter instance + :param option: QStyleOptionGraphicsItem instance + :param widget: QWidget instance + """ + if not self.m_renderer: + QGraphicsSvgItem.paint(self, painter, option, widget) + elif self.id: + self.m_renderer.render(painter,self.id, self.boundingRect()) + else: + self.m_renderer.render(painter, self.boundingRect()) + if self.isSelected(): + self.showGripItem() + + def resize(self, index, movement): + """Move grip item with changing rect of node item + """ + self.prepareGeometryChange() + if index in [0, 1]: + self.width -= movement.x() + self.height -= movement.y() + else: + self.width += movement.x() + self.height += movement.y() + + self.rect = QRectF(-self.width / 2, -self.height / 2, self.width, self.height) + transform = QTransform() + transform.translate(movement.x() / 2, movement.y() / 2) + self.setTransform(transform, True) + self.updateSizeGripItem([index]) + + def addGripItem(self): + """adds grip items + """ + if self.scene(): + # add grip items for connecting lines + for i, (location) in enumerate( + ( + "top", + "left", + "bottom", + "right" + ) + ): + item = LineGripItem(self, i, location, parent=self) + self.lineGripItems.append(item) + # add grip for resize it + for i, (direction) in enumerate( + ( + Qt.Vertical, + Qt.Horizontal, + Qt.Vertical, + Qt.Horizontal, + ) + ): + item = SizeGripItem(self, i, direction, parent=self) + self.sizeGripItems.append(item) + + def updateLineGripItem(self, index_no_updates=None): + """ + updates line grip items + """ + # index_no_updates = index_no_updates or [] + for item in self.lineGripItems: + item.updatePosition() + + def updateSizeGripItem(self, index_no_updates=None): + """ + updates size grip items + """ + index_no_updates = index_no_updates or [] + for i, item in zip(range(len(self.sizeGripItems)), self.sizeGripItems): + if i not in index_no_updates: + item.updatePosition() + + def itemChange(self, change, value): + """Overloads and extends QGraphicsSvgItem to also update grip items + """ + if change == QGraphicsItem.ItemSelectedHasChanged: + if value is True: + self.showGripItem() + else: + self.hideGripItem() + return + if change == QGraphicsItem.ItemTransformHasChanged: + self.updateLineGripItem() + return + if change == QGraphicsItem.ItemPositionHasChanged: + self.updateLineGripItem() + self.updateSizeGripItem() + return + if change == QGraphicsItem.ItemSceneHasChanged: + self.addGripItem() + self.updateLineGripItem() + self.updateSizeGripItem() + return + return super(NodeItem, self).itemChange(change, value) + + def removeFromCanvas(self): + """This function is used to remove item from canvas + :return: + """ + for item in self.lineGripItems: + item.removeConnectedLines() + for item in self.sizeGripItems: + item.removeFromCanvas() + self.scene().removeItem(self) + + def hoverEnterEvent(self, event): + """defines shape highlighting on Mouse Over + """ + self.showGripItem() + super(NodeItem, self).hoverEnterEvent(event) + + def hoverLeaveEvent(self, event): + """defines shape highlighting on Mouse Leave + """ + self.hideGripItem() + super(NodeItem, self).hoverLeaveEvent(event) + + def showGripItem(self): + """shows grip items of svg item + """ + for item in self.lineGripItems: + item.setPen(QPen(QColor("black"), 2)) + item.setBrush(QColor("red")) + for item in self.sizeGripItems: + item.setPen(QPen(QColor("black"), 2)) + + def hideGripItem(self): + """hide grip items of svg item + """ + for item in self.lineGripItems: + if item.isSelected() is False: + item.setPen(QPen(Qt.transparent)) + item.setBrush(Qt.transparent) + for item in self.sizeGripItems: + item.setPen(QPen(Qt.transparent)) + item.setBrush(Qt.transparent) + + +# classes of pfd-symbols +class AirBlownCooler(NodeItem): + def __init__(self): + super(AirBlownCooler, self).__init__("AirBlownCooler", parent=None) + + +class Bag(NodeItem): + def __init__(self): + super(Bag, self).__init__("Bag", parent=None) + + +class Boiler(NodeItem): + def __init__(self): + super(Boiler, self).__init__("Boiler", parent=None) + + +class Breaker(NodeItem): + def __init__(self): + super(Breaker, self).__init__("Breaker", parent=None) + + +class BriquettingMachine(NodeItem): + def __init__(self): + super(BriquettingMachine, self).__init__("BriquettingMachine", parent=None) + + +class Centrifugal(NodeItem): + def __init__(self): + super(Centrifugal, self).__init__("Centrifugal", parent=None) + + +class CentrifugalCompressor(NodeItem): + def __init__(self): + super(CentrifugalCompressor, self).__init__("CentrifugalCompressor", parent=None) + + +class Centrifugalpump(NodeItem): + def __init__(self): + super(Centrifugalpump, self).__init__("Centrifugalpump", parent=None) + + +class CentrifugalPump2(NodeItem): + def __init__(self): + super(CentrifugalPump2, self).__init__("CentrifugalPump2", parent=None) + + +class CentrifugalPump3(NodeItem): + def __init__(self): + super(CentrifugalPump3, self).__init__("CentrifugalPump3", parent=None) + + +class Column(NodeItem): + def __init__(self): + super(Column, self).__init__("Column", parent=None) + + +class Compressor(NodeItem): + def __init__(self): + super(Compressor, self).__init__("Compressor", parent=None) + + +class CompressorSilencers(NodeItem): + def __init__(self): + super(CompressorSilencers, self).__init__("CompressorSilencers", parent=None) + + +class Condenser(NodeItem): + def __init__(self): + super(Condenser, self).__init__("Condenser", parent=None) + + +class Cooler(NodeItem): + def __init__(self): + super(Cooler, self).__init__("Cooler", parent=None) + + +class CoolingTower3(NodeItem): + def __init__(self): + super(CoolingTower3, self).__init__("CoolingTower3", parent=None) + + +class CoolingTwoer2(NodeItem): + def __init__(self): + super(CoolingTwoer2, self).__init__("CoolingTwoer2", parent=None) + + +class Crusher(NodeItem): + def __init__(self): + super(Crusher, self).__init__("Crusher", parent=None) + + +class DoublePipeHeat(NodeItem): + def __init__(self): + super(DoublePipeHeat, self).__init__("DoublePipeHeat", parent=None) + + +class ExtractorHood(NodeItem): + def __init__(self): + super(ExtractorHood, self).__init__("ExtractorHood", parent=None) + + +class FiredHeater(NodeItem): + def __init__(self): + super(FiredHeater, self).__init__("FiredHeater", parent=None) + + +class ForcedDraftCooling(NodeItem): + def __init__(self): + super(ForcedDraftCooling, self).__init__("ForcedDraftCooling", parent=None) + + +class Furnace(NodeItem): + def __init__(self): + super(Furnace, self).__init__("Furnace", parent=None) + + +class GasBottle(NodeItem): + def __init__(self): + super(GasBottle, self).__init__("GasBottle", parent=None) + + +class HalfPipeMixingVessel(NodeItem): + def __init__(self): + super(HalfPipeMixingVessel, self).__init__("HalfPipeMixingVessel", parent=None) + + +class Heater(NodeItem): + def __init__(self): + super(Heater, self).__init__("Heater", parent=None) + + +class HeatExchanger(NodeItem): + def __init__(self): + super(HeatExchanger, self).__init__("HeatExchanger", parent=None) + + +class HeatExchanger2(NodeItem): + def __init__(self): + super(HeatExchanger2, self).__init__("HeatExchanger2", parent=None) + + +class HorizontalVessel(NodeItem): + def __init__(self): + super(HorizontalVessel, self).__init__("HorizontalVessel", parent=None) + + +class InducedDraftCooling(NodeItem): + def __init__(self): + super(InducedDraftCooling, self).__init__("InducedDraftCooling", parent=None) + + +class JacketedMixingVessel(NodeItem): + def __init__(self): + super(JacketedMixingVessel, self).__init__("JacketedMixingVessel", parent=None) + + +class LiquidRingCompressor(NodeItem): + def __init__(self): + super(LiquidRingCompressor, self).__init__("LiquidRingCompressor", parent=None) + + +class Mixing(NodeItem): + def __init__(self): + super(Mixing, self).__init__("Mixing", parent=None) + + +class MixingReactor(NodeItem): + def __init__(self): + super(MixingReactor, self).__init__("MixingReactor", parent=None) + + +class OilBurner(NodeItem): + def __init__(self): + super(OilBurner, self).__init__("OilBurner", parent=None) + + +class OpenTank(NodeItem): + def __init__(self): + super(OpenTank, self).__init__("OpenTank", parent=None) + + +class ProportionalPump(NodeItem): + def __init__(self): + super(ProportionalPump, self).__init__("ProportionalPump", parent=None) + + +class Pump(NodeItem): + def __init__(self): + super(Pump, self).__init__("Pump", parent=None) + + +class Pump2(NodeItem): + def __init__(self): + super(Pump2, self).__init__("Pump2", parent=None) + + +class ReboilerHeatExchange(NodeItem): + def __init__(self): + super(ReboilerHeatExchange, self).__init__("ReboilerHeatExchange", parent=None) + + +class ReciprocatingCompressor(NodeItem): + def __init__(self): + super(ReciprocatingCompressor, self).__init__("ReciprocatingCompressor", parent=None) + + +class RotaryCompresor(NodeItem): + def __init__(self): + super(RotaryCompresor, self).__init__("RotaryCompresor", parent=None) + + +class RotaryGearPump(NodeItem): + def __init__(self): + super(RotaryGearPump, self).__init__("RotaryGearPump", parent=None) + + +class ScrewPump(NodeItem): + def __init__(self): + super(ScrewPump, self).__init__("ScrewPump", parent=None) + + +class SelectableCompressor(NodeItem): + def __init__(self): + super(SelectableCompressor, self).__init__("SelectableCompressor", parent=None) + + +class SelectableFan(NodeItem): + def __init__(self): + super(SelectableFan, self).__init__("SelectableFan", parent=None) + + +class SinglePassHeat(NodeItem): + def __init__(self): + super(SinglePassHeat, self).__init__("SinglePassHeat", parent=None) + + +class SpiralHeatExchanger(NodeItem): + def __init__(self): + super(SpiralHeatExchanger, self).__init__("SpiralHeatExchanger", parent=None) + + +class StraightTubersHeat(NodeItem): + def __init__(self): + super(StraightTubersHeat, self).__init__("StraightTubersHeat", parent=None) + + +class Tank(NodeItem): + def __init__(self): + super(Tank, self).__init__("Tank", parent=None) + + +class TurbinePump(NodeItem): + def __init__(self): + super(TurbinePump, self).__init__("TurbinePump", parent=None) + + +class UTubeHeatExchanger(NodeItem): + def __init__(self): + super(UTubeHeatExchanger, self).__init__("UTubeHeatExchanger", parent=None) + + +class VaccumPump(NodeItem): + def __init__(self): + super(VaccumPump, self).__init__("VaccumPump", parent=None) + + +class VerticalPump(NodeItem): + def __init__(self): + super(VerticalPump, self).__init__("VerticalPump", parent=None) + + +class VerticalVessel(NodeItem): + def __init__(self): + super(VerticalVessel, self).__init__("VerticalVessel", parent=None) + + +class WastewaterTreatment(NodeItem): + def __init__(self): + super(WastewaterTreatment, self).__init__("WastewaterTreatment", parent=None) -- cgit From 482455785986a00f66ccd764f2c4e3732ef30529 Mon Sep 17 00:00:00 2001 From: sumit Date: Tue, 2 Jun 2020 13:12:03 +0530 Subject: update end point of line --- src/main/python/shapes/line.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index e6b1dd9..8c5149f 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -518,6 +518,10 @@ class Line(QGraphicsPathItem): updates points of line when grabber is moved :return: """ + if self.startGripItem: + self.points[0]= self.startPoint + if self.endGripItem: + self.points[len(self.points) - 1] = self.endPoint if self.startGripItem.m_location in ["left", "right"]: point = self.points[1] self.points[1] = QPointF(point.x(), self.startPoint.y()) @@ -527,7 +531,6 @@ class Line(QGraphicsPathItem): else: point = self.points[len(self.points) - 2] self.points[len(self.points) - 2] = QPointF(self.endPoint.x(), point.y()) - else: point = self.points[1] self.points[1] = QPointF(self.startPoint.x(), point.y()) @@ -538,6 +541,7 @@ class Line(QGraphicsPathItem): point = self.points[len(self.points) - 2] self.points[len(self.points) - 2] = QPointF(self.endPoint.x(), point.y()) + def shape(self): """generates outline for path """ -- cgit From 2d97300ede188139fb8234a34c7475d5158ee77d Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 14:53:37 +0530 Subject: line working --- src/main/python/shapes/line.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 8c5149f..d1e3124 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -71,7 +71,6 @@ class Grabber(QGraphicsPathItem): return self.shape().boundingRect() def mousePressEvent(self, event): - print('grabber clicked', self) super(Grabber, self).mousePressEvent(event) def hoverEnterEvent(self, event): @@ -139,7 +138,6 @@ class LineLabel(QGraphicsTextItem): # print(self.pos()) def itemChange(self, change, value): - print("label change",change,value) # if change == QGraphicsItem.ItemPositionChange: # print("label change", change, value) return super(LineLabel, self).itemChange(change,value) @@ -188,7 +186,9 @@ class Line(QGraphicsPathItem): for polygon in polygons: center = polygon.boundingRect().center() self.commonPaths.append(center) + # self.commonPaths[commonPath] = item + print(self.commonPaths) self.update() def paint(self, painter, option, widget): @@ -198,11 +198,29 @@ class Line(QGraphicsPathItem): # painter.drawPath(path) path = QPainterPath(self.startPoint) # iterating over all points of line - for i in range(1, len(self.points)): + for i in range(len(self.points) - 1): + # for point in self.commonPaths: + # # point is center of common path + # pass for point in self.commonPaths: - # point is center of common path - pass - path.lineTo(self.points[i]) + x1, y1 = self.points[i].x(), self.points[i].y() + x2, y2 = self.points[i+1].x(), self.points[i+1].y() + x, y = point.x(), point.y() + # if not x1 * (y - y2) + x * (y2 - y1) + x2 * (y1 - y) : + if x == x1 == x2: + #vertical + if min(y1, y2) <= y < max(y1, y2): + path.lineTo(point - QPointF(0, 8)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) + path.moveTo(point + QPointF(0, 8)) + elif y == y1 == y2: + #horizontal + if min(x1, x2) <= x < max(x1, x2): + path.lineTo(point - QPointF(8, 0)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) + path.moveTo(point + QPointF(8, 0)) + path.lineTo(self.points[i+1]) + painter.drawPath(path) -- cgit From 3b9e4207dfb1429c8ee5df1265f88707492a1fa3 Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 18:02:03 +0530 Subject: reverse dir fix --- src/main/python/shapes/line.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index d1e3124..e0e3fae 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -210,15 +210,29 @@ class Line(QGraphicsPathItem): if x == x1 == x2: #vertical if min(y1, y2) <= y < max(y1, y2): - path.lineTo(point - QPointF(0, 8)) + bool = y2>y1 + if bool: + path.lineTo(point - QPointF(0, 8)) + else: + path.lineTo(point + QPointF(0, 8)) path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) - path.moveTo(point + QPointF(0, 8)) + if bool: + path.moveTo(point + QPointF(0, 8)) + else: + path.moveTo(point - QPointF(0, 8)) elif y == y1 == y2: #horizontal if min(x1, x2) <= x < max(x1, x2): - path.lineTo(point - QPointF(8, 0)) + bool = x2>x1 + if bool: + path.lineTo(point - QPointF(8, 0)) + else: + path.lineTo(point - QPointF(8, 0)) path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) - path.moveTo(point + QPointF(8, 0)) + if bool: + path.moveTo(point + QPointF(8, 0)) + else: + path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From ab89c224340e9341bfcb79f125c10b6d2d757077 Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 21:28:30 +0530 Subject: loop 2nd fix --- src/main/python/shapes/line.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index e0e3fae..1c30cd9 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -213,12 +213,11 @@ class Line(QGraphicsPathItem): bool = y2>y1 if bool: path.lineTo(point - QPointF(0, 8)) - else: - path.lineTo(point + QPointF(0, 8)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) - if bool: + path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) path.moveTo(point + QPointF(0, 8)) else: + path.lineTo(point + QPointF(0, 8)) + path.arcTo(QRectF(x-8, y-8, 16, 16), -90, 180) path.moveTo(point - QPointF(0, 8)) elif y == y1 == y2: #horizontal @@ -226,13 +225,12 @@ class Line(QGraphicsPathItem): bool = x2>x1 if bool: path.lineTo(point - QPointF(8, 0)) - else: - path.lineTo(point - QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) - if bool: + path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) path.moveTo(point + QPointF(8, 0)) else: path.lineTo(point - QPointF(8, 0)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 0, -180) + path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From b24e45566f0e627e3a87ec6e30109f4a061fa838 Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 23:24:34 +0530 Subject: minor typo --- src/main/python/shapes/line.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 1c30cd9..5ad61a7 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -210,8 +210,7 @@ class Line(QGraphicsPathItem): if x == x1 == x2: #vertical if min(y1, y2) <= y < max(y1, y2): - bool = y2>y1 - if bool: + if y2>y1: path.lineTo(point - QPointF(0, 8)) path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) path.moveTo(point + QPointF(0, 8)) @@ -222,14 +221,13 @@ class Line(QGraphicsPathItem): elif y == y1 == y2: #horizontal if min(x1, x2) <= x < max(x1, x2): - bool = x2>x1 - if bool: + if x2>x1: path.lineTo(point - QPointF(8, 0)) path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) path.moveTo(point + QPointF(8, 0)) else: path.lineTo(point - QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 0, -180) + path.arcTo(QRectF(x-8, y-8, 16, 16), 0, 180) path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) -- cgit From 53f4698ef5e5c7f7c388c73b9a657e1a4cf44497 Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 23:27:48 +0530 Subject: checkkk --- src/main/python/shapes/line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 5ad61a7..c5d5b57 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -228,7 +228,7 @@ class Line(QGraphicsPathItem): else: path.lineTo(point - QPointF(8, 0)) path.arcTo(QRectF(x-8, y-8, 16, 16), 0, 180) - path.lineTo(point - QPointF(8, 0)) + path.lineTo(point + QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From ab3e2c1eb31473ed651b6ab4535fcb8bd64504c6 Mon Sep 17 00:00:00 2001 From: sumit Date: Wed, 3 Jun 2020 05:32:55 +0530 Subject: curve fix for line from right to left --- src/main/python/shapes/line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index c5d5b57..1a54284 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -226,9 +226,9 @@ class Line(QGraphicsPathItem): path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) path.moveTo(point + QPointF(8, 0)) else: - path.lineTo(point - QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 0, 180) path.lineTo(point + QPointF(8, 0)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 0, -180) + path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From 6d002432a2234180e447114de67a522ad58372d3 Mon Sep 17 00:00:00 2001 From: sumit Date: Wed, 3 Jun 2020 13:17:33 +0530 Subject: Merge remote-tracking branch 'upstream/master' --- src/main/resources/base/svg/ellipse.svg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/resources/base/svg/ellipse.svg b/src/main/resources/base/svg/ellipse.svg index 8802667..c455408 100644 --- a/src/main/resources/base/svg/ellipse.svg +++ b/src/main/resources/base/svg/ellipse.svg @@ -1,8 +1,8 @@ - + - + - + \ No newline at end of file -- cgit From 56d830cb025a1b7dd99ac2c0292c0eed27aebb9b Mon Sep 17 00:00:00 2001 From: Blaine Date: Wed, 3 Jun 2020 14:12:43 +0530 Subject: fix shapes --- src/main/python/shapes/shapes.py | 44 ---------------------------------------- 1 file changed, 44 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 582215e..19c0298 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -5,24 +5,10 @@ from PyQt5.QtWidgets import QLineEdit, QGraphicsItem, QGraphicsEllipseItem, QGra from PyQt5.QtGui import QPen, QColor, QFont, QCursor, QPainterPath, QPainter, QDrag, QBrush, QImage, QTransform from PyQt5.QtCore import Qt, QRectF, QPointF, QSizeF, QEvent, QMimeData, QFile, QIODevice, QRect -<<<<<<< HEAD from .line import Line from utils.app import fileImporter -======= -<<<<<<< HEAD -from line import Line - - -======= -from .line import Line - -from utils.app import fileImporter ->>>>>>> merge -# resourceManager = ApplicationContext() - ->>>>>>> upstream/master class GripItem(QGraphicsPathItem): """ @@ -237,16 +223,7 @@ class LineGripItem(GripItem): # initialize a line and add on scene startPoint = endPoint = self.parentItem().mapToScene(self.pos()) self.tempLine = Line(startPoint, endPoint) -<<<<<<< HEAD - self.scene().addItemPlus(self.tempLine) -======= - self.tempLine.setStartGripItem(self) -<<<<<<< HEAD - self.scene().addItem(self.tempLine) -======= self.scene().addItemPlus(self.tempLine) ->>>>>>> merge ->>>>>>> upstream/master super().mousePressEvent(mouseEvent) def mouseMoveEvent(self, mouseEvent): @@ -321,29 +298,14 @@ class NodeItem(QGraphicsSvgItem): def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) self.m_type = unitOperationType -<<<<<<< HEAD self.id = None self.m_renderer = NodeItem.renderer # if each svg is seperate file # self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) -======= -<<<<<<< HEAD - self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") -======= - # self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") - # self.m_renderer = QSvgRenderer(fileImporter(f'svg/{unitOperationType}.svg')) - self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) ->>>>>>> merge - # self.m_renderer = QSvgRenderer(resourceManager.get_resource(f'toolbar/{unitOperationType}.svg')) ->>>>>>> upstream/master self.setSharedRenderer(self.m_renderer) # set initial size of item self.width = 100 -<<<<<<< HEAD self.height = 150 -======= - self.height = 100 ->>>>>>> merge self.rect = QRectF(-self.width / 2, -self.height / 2, self.width, self.height) # set graphical settings for this item self.setFlags(QGraphicsSvgItem.ItemIsMovable | @@ -355,12 +317,6 @@ class NodeItem(QGraphicsSvgItem): self.lineGripItems = [] self.sizeGripItems = [] -<<<<<<< HEAD -======= - def advance(self, int): - print (int) - ->>>>>>> merge def boundingRect(self): """Overrides QGraphicsSvgItem's boundingRect() virtual public function and returns a valid bounding -- cgit From d5745628dec09c909d162eaea722303e604b04e0 Mon Sep 17 00:00:00 2001 From: Blaine Date: Wed, 3 Jun 2020 14:19:08 +0530 Subject: fix2 --- src/main/python/shapes/shapes.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index c2d79e4..3237e72 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -14,10 +14,6 @@ from utils.app import fileImporter from .line import Line from utils.app import fileImporter -<<<<<<< HEAD - -======= ->>>>>>> upstream/master class GripItem(QGraphicsPathItem): """ -- cgit From 7980ef69a7c4b3b02c5edd4ecb8c765c99d44d18 Mon Sep 17 00:00:00 2001 From: Blaine Date: Wed, 3 Jun 2020 14:20:43 +0530 Subject: sort col points --- src/main/python/shapes/line.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 1a54284..2d7eba8 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -199,12 +199,9 @@ class Line(QGraphicsPathItem): path = QPainterPath(self.startPoint) # iterating over all points of line for i in range(len(self.points) - 1): - # for point in self.commonPaths: - # # point is center of common path - # pass - for point in self.commonPaths: - x1, y1 = self.points[i].x(), self.points[i].y() - x2, y2 = self.points[i+1].x(), self.points[i+1].y() + x1, y1 = self.points[i].x(), self.points[i].y() + x2, y2 = self.points[i+1].x(), self.points[i+1].y() + for point in self.commonPaths.sort(key = lambda x: x.x() + x.y(), reverse=x2 end.x(): + if start.y() + sheight + offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + elif start.y() - sheight - offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight - offset), + QPointF(pe.x(), ns.y() - sheight - offset), end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + if start.y() > end.y(): + x = max(end.x() + ewidth + offset, ns.x()) + self.points = [start, QPointF(x, start.y()), QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + if start.x() + offset < end.x() - ewidth: + if start.y() + offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + else: + self.points = [start, QPointF(end.x(), start.y()), end] + + elif start.x() - 2 * swidth > end.x(): + if start.y() + sheight + offset < end.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + elif start.y() - sheight - offset < end.y(): + y = max(pe.y(), start.y() + sheight + offset) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y()), pe, end] + if start.y() < end.y(): + x = max(end.x() + ewidth + offset, ns.x()) + self.points = [start, QPointF(x, start.y()), QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + x = max(start.x() + offset, pe.x()) + self.points = [start, QPointF(x, start.y()), QPointF(x, end.y()), end] + if start.x() + offset < end.x() - ewidth: + if start.y() + offset > end.y() - eheight and end.y() >= start.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y() - eheight), + QPointF(pe.x(), pe.y() - eheight), pe, end] + elif start.y() - offset < end.y() + eheight and end.y() <= start.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y() + eheight), + QPointF(pe.x(), pe.y() + eheight), pe, end] + elif start.y() - sheight - offset < end.y() < start.y() + sheight + offset: + if end.y() < start.y(): + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), pe, end] + + elif self.endGripItem.m_location in ["left"]: + self.points = [start, QPointF((start.x() + end.x()) / 2, start.y()), + QPointF((start.x() + end.x()) / 2, end.y()), end] + if end.x() < start.x() + offset: + if end.y() + eheight <= start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + elif end.y() - eheight >= start.y() + sheight + offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), pe, end] + elif end.y() <= start.y(): + y = min(end.y() - eheight, start.y() - sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + else: + y = max(end.y() + eheight, start.y() + sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + + + elif self.startGripItem.m_location in ["left"]: + if self.endGripItem.m_location in ["top"]: + if start.x() + offset < end.x() - ewidth: + if end.y() > start.y() + sheight + offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), end] + else: + y = min(start.y() - sheight, pe.y()) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), end] + elif end.x() + ewidth >= start.x() - offset: + x = min(ns.x(), end.x() - ewidth) + self.points = [start, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + else: + if end.y() >= start.y() + offset: + self.points = [start, QPointF(end.x(), start.y()), end] + else: + x = (start.x() + end.x()) / 2 + self.points = [start, QPointF(x, start.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + if start.x() + offset < end.x() - ewidth: + if end.y() < start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), end] + else: + y = max(start.y() + sheight, pe.y()) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), end] + elif end.x() + ewidth >= start.x() - offset: + x = min(ns.x(), end.x() - ewidth) + self.points = [start, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + else: + if end.y() <= start.y() - offset: + self.points = [start, QPointF(end.x(), start.y()), end] + else: + x = (start.x() + end.x()) / 2 + self.points = [start, QPointF(x, start.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + self.points = [start, QPointF((start.x() + end.x()) / 2, start.y()), + QPointF((start.x() + end.x()) / 2, end.y()), end] + if end.x() > start.x() + offset: + if end.y() + eheight <= start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + elif end.y() - eheight >= start.y() + sheight + offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() + sheight), + QPointF(pe.x(), ns.y() + sheight), pe, end] + elif end.y() <= start.y(): + y = min(end.y() - eheight, start.y() - sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + else: + y = max(end.y() + eheight, start.y() + sheight) + self.points = [start, ns, QPointF(ns.x(), y), + QPointF(pe.x(), y), pe, end] + + elif self.endGripItem.m_location in ["left"]: + self.points = [start, QPointF(pe.x(), start.y()), pe, end] + if start.x() + offset < end.x(): + self.points = [start, ns, QPointF(ns.x(), end.y()), end] + if start.y() + sheight + offset > end.y() > start.y() - sheight - offset: + self.points = [start, ns, QPointF(ns.x(), ns.y() - sheight), + QPointF(pe.x(), ns.y() - sheight), pe, end] + elif end.y() - eheight - offset < start.y() < end.y() + eheight + offset: + if end.y() > start.y(): + self.points = [start, ns, QPointF(ns.x(), pe.y() - eheight), + QPointF(pe.x(), pe.y() - eheight), pe, end] + else: + self.points = [start, ns, QPointF(ns.x(), pe.y() + eheight), + QPointF(pe.x(), pe.y() + eheight), pe, end] + + + elif self.startGripItem.m_location in ["top"]: + if self.endGripItem.m_location in ["top"]: + self.points = [self.startPoint, QPointF(start.x(), pe.y()), + pe, self.endPoint] + if start.y() < end.y(): + self.points = [self.startPoint, ns, QPointF(pe.x(), ns.y()), self.endPoint] + if start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + if start.x() > end.x(): + x = min(start.x() - swidth, end.x() - ewidth) + x -= offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + self.points = [self.startPoint, ns, QPointF((x0 + x1) / 2, ns.y()), QPointF((x0 + x1) / 2, pe.y()), + pe, self.endPoint] + if start.y() - offset > end.y(): + self.points = [start, QPointF(start.x(), (y0 + y1) / 2), QPointF(end.x(), (y0 + y1) / 2), + self.endPoint] + elif start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + if start.x() > end.x(): + x = min(start.x() - swidth, end.x() - ewidth) + x -= offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + y = min(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset and end.y() > start.y() + offset: + self.points = [start, ns, QPointF(ns.x() + swidth + offset, ns.y()), + QPointF(ns.x() + swidth + offset, pe.y()), end] + elif end.y() - eheight < start.y() - offset < end.y() + eheight: + self.points = [start, ns, QPointF(start.x(), end.y() - eheight), + QPointF(pe.x(), end.y() - eheight), pe, end] + + elif self.endGripItem.m_location in ["left"]: + y = min(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset and end.y() > start.y() + offset: + self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), + QPointF(ns.x() - swidth - offset, pe.y()), end] + elif end.y() - eheight < start.y() - offset < end.y() + eheight: + self.points = [start, ns, QPointF(start.x(), end.y() - eheight), + QPointF(pe.x(), end.y() - eheight), pe, end] + + elif self.startGripItem.m_location in ["bottom"]: + if self.endGripItem.m_location in ["top"]: + self.points = [self.startPoint, ns, QPointF((x0 + x1) / 2, ns.y()), QPointF((x0 + x1) / 2, pe.y()), + pe, self.endPoint] + if start.y() < end.y(): + self.points = [self.startPoint, ns, QPointF(pe.x(), ns.y()), self.endPoint] + if start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["bottom"]: + self.points = [self.startPoint, ns, QPointF((x0 + x1) / 2, ns.y()), QPointF((x0 + x1) / 2, pe.y()), + pe, self.endPoint] + if start.x() + swidth > end.x() > start.x() - swidth or end.x() + ewidth > start.x() > end.x() - ewidth: + x = max(start.x() + swidth, end.x() + ewidth) + x += offset + self.points = [start, ns, QPointF(x, ns.y()), + QPointF(x, pe.y()), pe, end] + + elif self.endGripItem.m_location in ["right"]: + y = max(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset: + self.points = [start, ns, QPointF(ns.x() + swidth + offset, ns.y()), + QPointF(ns.x() + swidth + offset, pe.y()), end] + + elif self.endGripItem.m_location in ["left"]: + y = max(ns.y(), end.y() + eheight + offset) + self.points = [start, QPointF(ns.x(), y), QPointF(pe.x(), y), pe, end] + if start.x() - swidth - offset < end.x() < start.x() + swidth + offset: + self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), + QPointF(ns.x() - swidth - offset, pe.y()), end] + # draw line path = QPainterPath(self.startPoint) for i in range(1, len(self.points)): @@ -197,12 +471,12 @@ class Line(QGraphicsPathItem): # To paint path of shape # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) # painter.drawPath(self.shape()) - if self.isSelected(): - self.showGripItem() - self._selected = True - elif self._selected: - self.hideGripItem() - self._selected = False + # if self.isSelected(): + # self.showGripItem() + # self._selected = True + # elif self._selected: + # self.hideGripItem() + # self._selected = False def movePoints(self, index, movement): """move points of line @@ -222,7 +496,7 @@ class Line(QGraphicsPathItem): else: direction = [Qt.Vertical, Qt.Horizontal] for i in range(1, len(self.points) - 2): - item = Grabber(self, i, direction[i - 1]) + item = Grabber(self, i, direction[(i - 1)%2]) item.setParentItem(self) item.setPos(self.pos()) self.scene().addItem(item) @@ -243,6 +517,12 @@ class Line(QGraphicsPathItem): grabber.setEnabled(True) def itemChange(self, change, value): + if change == QGraphicsItem.ItemSelectedHasChanged: + if value == 1: + self.showGripItem() + else: + self.hideGripItem() + return if change == QGraphicsItem.ItemSceneHasChanged and self.scene(): # self.addGrabber() # self.updateGrabber() @@ -280,18 +560,20 @@ class Line(QGraphicsPathItem): self.scene().removeItem(self) def showGripItem(self): - """hides grip items which contains line + """shows grip items which contains line """ if self.startGripItem: self.startGripItem.show() if self.endGripItem: self.endGripItem.show() - # for grabber in self.m_grabber: - # grabber.setSelected(True) + for grabber in self.m_grabbers: + grabber.show() def hideGripItem(self): """hides grip items which contains line """ if self.startGripItem: self.startGripItem.hide() if self.endGripItem: self.endGripItem.hide() + for grabber in self.m_grabbers: + grabber.hide() def setStartGripItem(self, item): self.startGripItem = item diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index e79ddb7..5c39125 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -53,7 +53,7 @@ class SizeGripItem(GripItem): self.width = annotation_item.boundingRect().width() path = QPainterPath() - path.addRect(QRectF(-self.width/2, -self.height/2, self.width, self.height)) + path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) super(SizeGripItem, self).__init__(annotation_item, path=path, parent=parent) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setFlag(QGraphicsItem.ItemIsMovable, True) @@ -84,7 +84,7 @@ class SizeGripItem(GripItem): else: self.width = self.parentItem().boundingRect().width() path = QPainterPath() - path.addRect(QRectF(-self.width/2, -self.height/2, self.width, self.height)) + path.addRect(QRectF(-self.width / 2, -self.height / 2, self.width, self.height)) self.setPath(path) def updatePosition(self): @@ -212,8 +212,7 @@ class LineGripItem(GripItem): # initialize a line and add on scene startPoint = endPoint = self.parentItem().mapToScene(self.pos()) self.tempLine = Line(startPoint, endPoint) - self.tempLine.setStartGripItem(self) - self.scene().addItemPlus(self.tempLine) + self.scene().addItem(self.tempLine) super().mousePressEvent(mouseEvent) def mouseMoveEvent(self, mouseEvent): @@ -245,6 +244,7 @@ class LineGripItem(GripItem): self.transform()) if type(item) == LineGripItem and item != self: + self.tempLine.setStartGripItem(self) self.tempLine.setEndGripItem(item) endPoint = item.parentItem().mapToScene(item.pos()) self.tempLine.updateLine(endPoint=endPoint) @@ -281,6 +281,7 @@ class NodeItem(QGraphicsSvgItem): """ Extends PyQt5's QGraphicsSvgItem to create the basic structure of shapes with given unit operation type """ + renderer = QSvgRenderer("For sample svg_2.svg") def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) @@ -319,7 +320,10 @@ class NodeItem(QGraphicsSvgItem): """ if not self.m_renderer: QGraphicsSvgItem.paint(self, painter, option, widget) - self.m_renderer.render(painter, self.boundingRect()) + elif self.id: + self.m_renderer.render(painter,self.id, self.boundingRect()) + else: + self.m_renderer.render(painter, self.boundingRect()) if self.isSelected(): self.showGripItem() -- cgit From 34b798e22ef468878176ee45c146290839f1afbc Mon Sep 17 00:00:00 2001 From: sumit Date: Thu, 28 May 2020 19:11:52 +0530 Subject: open svg from resources --- src/main/python/shapes/shapes.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 5c39125..4615ab1 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -9,9 +9,9 @@ from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, QGraphicsProxyWidget, QGraphicsSceneHoverEvent, QLineEdit) -from utils.app import fileImporter - from .line import Line +from utils.app import fileImporter + class GripItem(QGraphicsPathItem): @@ -281,15 +281,15 @@ class NodeItem(QGraphicsSvgItem): """ Extends PyQt5's QGraphicsSvgItem to create the basic structure of shapes with given unit operation type """ - renderer = QSvgRenderer("For sample svg_2.svg") + # set a common renderer for all svg + renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) - self.m_type = unitOperationType - # self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") - # self.m_renderer = QSvgRenderer(fileImporter(f'svg/{unitOperationType}.svg')) - self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) - # self.m_renderer = QSvgRenderer(resourceManager.get_resource(f'toolbar/{unitOperationType}.svg')) + self.id = None + self.m_renderer = NodeItem.renderer + # if each svg is seperate file + # self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) self.setSharedRenderer(self.m_renderer) # set initial size of item self.width = 100 -- cgit From 8f9295322a545e4b9ab070c2534ddc2d31a952c7 Mon Sep 17 00:00:00 2001 From: sumit Date: Sat, 30 May 2020 16:58:46 +0530 Subject: remove extra point of line --- src/main/python/shapes/line.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index fa10936..8bba5be 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -2,6 +2,7 @@ from PyQt5.QtGui import QPen, QPainterPath, QBrush, QPainterPathStroker, QPainte from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem from PyQt5.QtCore import Qt, QPointF, QRectF + class Grabber(QGraphicsPathItem): """ Extends QGraphicsPathItem to create grabber for line for moving a particular segment @@ -373,7 +374,7 @@ class Line(QGraphicsPathItem): self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), QPointF(ns.x() - swidth - offset, pe.y()), end] elif end.y() - eheight < start.y() - offset < end.y() + eheight: - self.points = [start, ns, QPointF(start.x(), end.y() - eheight), + self.points = [start, QPointF(start.x(), end.y() - eheight), QPointF(pe.x(), end.y() - eheight), pe, end] elif self.startGripItem.m_location in ["bottom"]: -- cgit From 634fde62599f92bd41dbce0adfedd1ae6af52ca4 Mon Sep 17 00:00:00 2001 From: sumit Date: Sat, 30 May 2020 17:08:18 +0530 Subject: change add line for undo --- src/main/python/shapes/shapes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 4615ab1..a0aca48 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -212,7 +212,7 @@ class LineGripItem(GripItem): # initialize a line and add on scene startPoint = endPoint = self.parentItem().mapToScene(self.pos()) self.tempLine = Line(startPoint, endPoint) - self.scene().addItem(self.tempLine) + self.scene().addItemPlus(self.tempLine) super().mousePressEvent(mouseEvent) def mouseMoveEvent(self, mouseEvent): @@ -286,6 +286,7 @@ class NodeItem(QGraphicsSvgItem): def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) + self.m_type = unitOperationType self.id = None self.m_renderer = NodeItem.renderer # if each svg is seperate file @@ -605,9 +606,9 @@ class InducedDraftCooling(NodeItem): super(InducedDraftCooling, self).__init__("InducedDraftCooling", parent=None) -class jacketedMixingVessel(NodeItem): +class JacketedMixingVessel(NodeItem): def __init__(self): - super(jacketedMixingVessel, self).__init__("jacketedMixingVessel", parent=None) + super(JacketedMixingVessel, self).__init__("JacketedMixingVessel", parent=None) class LiquidRingCompressor(NodeItem): -- cgit From 76a8d691c267a5e65074ee99468800c1d3e3d930 Mon Sep 17 00:00:00 2001 From: sumit Date: Sun, 31 May 2020 21:31:43 +0530 Subject: common path of lines --- src/main/python/shapes/line.py | 58 ++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 8bba5be..2c5a527 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -126,6 +126,46 @@ class Line(QGraphicsPathItem): # initiates path self.createPath() + def advance(self, phase): + # items = self.collidingItems(Qt.IntersectsItemShape) + items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.DescendingOrder) + self.commonPaths = [] + for item in items: + if type(item) in [type(self)]: + if item == self: + break + # origin = self.mapFromItem(item, 0, 0) + shape = item.shape() + shape = self.mapFromItem(item, item.shape()) + commonPath = self.shape().intersected(shape) + self.commonPaths.append(commonPath) + + def paint(self, painter, option, widget): + color = Qt.red if self.isSelected() else Qt.black + painter.setPen(QPen(color, 2, self.penStyle)) + path = self.path() + painter.drawPath(path) + for p in self.commonPaths: + print("length = ",p.length(),"element = ",p.elementCount()) + for i in range(p.elementCount()): + print(p.elementAt(i).x,p.elementAt(i).y) + # if p.elementAt(0).x == p.elementAt(1).x: + # pass + painter.save() + painter.setPen(Qt.darkYellow) + painter.setBrush(Qt.darkYellow) + painter.drawPath(p) + painter.restore() + # painter.setPen(QPen(QBrush(Qt.black),-1)) + # painter.setBrush(QBrush(Qt.red)) + # print(painter.pen().width()) + # painter.drawPath(path) + + # To paint path of shape + # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) + # painter.drawPath(self.shape()) + + def createPath(self): """ creates initial path and stores it's points @@ -412,7 +452,7 @@ class Line(QGraphicsPathItem): self.points = [start, ns, QPointF(ns.x() - swidth - offset, ns.y()), QPointF(ns.x() - swidth - offset, pe.y()), end] - # draw line + # path of line path = QPainterPath(self.startPoint) for i in range(1, len(self.points)): path.lineTo(self.points[i]) @@ -464,21 +504,6 @@ class Line(QGraphicsPathItem): path = qp.createStroke(self.path()) return path - def paint(self, painter, option, widget): - color = Qt.red if self.isSelected() else Qt.black - painter.setPen(QPen(color, 2, self.penStyle)) - painter.drawPath(self.path()) - - # To paint path of shape - # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) - # painter.drawPath(self.shape()) - # if self.isSelected(): - # self.showGripItem() - # self._selected = True - # elif self._selected: - # self.hideGripItem() - # self._selected = False - def movePoints(self, index, movement): """move points of line """ @@ -543,6 +568,7 @@ class Line(QGraphicsPathItem): self.endPoint = endPoint self.createPath() self.updateGrabber() + self.scene().update() return if self.startGripItem and self.endGripItem: -- cgit From f98bb44ef77d7f6d42e6f112ad8978fc5ef2c9eb Mon Sep 17 00:00:00 2001 From: sumit Date: Sun, 31 May 2020 21:41:45 +0530 Subject: add variable commonPaths --- src/main/python/shapes/line.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 2c5a527..9f3bfaf 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -125,6 +125,7 @@ class Line(QGraphicsPathItem): self.setAcceptHoverEvents(True) # initiates path self.createPath() + self.commonPaths=[] def advance(self, phase): # items = self.collidingItems(Qt.IntersectsItemShape) -- cgit From 41a1fd32e6dc812c6ef4e8c369686f5096663890 Mon Sep 17 00:00:00 2001 From: sumit Date: Tue, 2 Jun 2020 11:50:35 +0530 Subject: add text label to line --- src/main/python/shapes/line.py | 87 +++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 23 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 9f3bfaf..e6b1dd9 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -1,5 +1,6 @@ +import math from PyQt5.QtGui import QPen, QPainterPath, QBrush, QPainterPathStroker, QPainter, QCursor -from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem +from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem, QGraphicsTextItem from PyQt5.QtCore import Qt, QPointF, QRectF @@ -99,6 +100,50 @@ class Grabber(QGraphicsPathItem): self.pen = QPen(Qt.white, -1, Qt.SolidLine) self.brush = QBrush(Qt.transparent) +class LineLabel(QGraphicsTextItem): + def __init__(self, parent=None): + super(LineLabel, self).__init__(parent=parent) + self.setTextInteractionFlags(Qt.TextEditorInteraction) + self.setFlags(QGraphicsItem.ItemIsMovable | + QGraphicsItem.ItemIsSelectable | + QGraphicsItem.ItemIsFocusable) + self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) + self.setPlainText("abc") + + def paint(self, painter, option, widget): + super(LineLabel, self).paint(painter,option,widget) + painter.drawEllipse(self.boundingRect()) + + def updateLabel(self): + points = self.parentItem().points + # min_A = QPointF() + # min_B =QPointF() + # min_dis =math.inf + # for i in range(1, len(points)): + # A = points[i - 1] + # B = points[i] + # C = self.pos() + # BAx = B.x() - A.x() + # BAy = B.y() - A.y() + # CAx = C.x() - A.x() + # CAy = C.y() - A.y() + # length = math.sqrt(BAx * BAx + BAy * BAy) + # if length >0: + # dis = (BAx*CAy - CAx*BAy)/length + # if abs(dis) < abs(min_dis): + # min_dis=dis + # min_A=A + # min_B=B + # + # self.setPos(self.parentItem().mapFromScene(QPointF(min_A))) + # print(self.pos()) + + def itemChange(self, change, value): + print("label change",change,value) + # if change == QGraphicsItem.ItemPositionChange: + # print("label change", change, value) + return super(LineLabel, self).itemChange(change,value) + class Line(QGraphicsPathItem): """ @@ -126,45 +171,41 @@ class Line(QGraphicsPathItem): # initiates path self.createPath() self.commonPaths=[] + self.label = LineLabel(self) def advance(self, phase): # items = self.collidingItems(Qt.IntersectsItemShape) - items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.DescendingOrder) + items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.AscendingOrder) self.commonPaths = [] for item in items: if type(item) in [type(self)]: if item == self: break - # origin = self.mapFromItem(item, 0, 0) shape = item.shape() shape = self.mapFromItem(item, item.shape()) commonPath = self.shape().intersected(shape) - self.commonPaths.append(commonPath) + polygons = commonPath.toSubpathPolygons() + for polygon in polygons: + center = polygon.boundingRect().center() + self.commonPaths.append(center) + # self.commonPaths[commonPath] = item + self.update() def paint(self, painter, option, widget): color = Qt.red if self.isSelected() else Qt.black painter.setPen(QPen(color, 2, self.penStyle)) - path = self.path() - painter.drawPath(path) - for p in self.commonPaths: - print("length = ",p.length(),"element = ",p.elementCount()) - for i in range(p.elementCount()): - print(p.elementAt(i).x,p.elementAt(i).y) - # if p.elementAt(0).x == p.elementAt(1).x: - # pass - painter.save() - painter.setPen(Qt.darkYellow) - painter.setBrush(Qt.darkYellow) - painter.drawPath(p) - painter.restore() - # painter.setPen(QPen(QBrush(Qt.black),-1)) - # painter.setBrush(QBrush(Qt.red)) - # print(painter.pen().width()) + # path = self.path() # painter.drawPath(path) + path = QPainterPath(self.startPoint) + # iterating over all points of line + for i in range(1, len(self.points)): + for point in self.commonPaths: + # point is center of common path + pass + path.lineTo(self.points[i]) + painter.drawPath(path) + - # To paint path of shape - # painter.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) - # painter.drawPath(self.shape()) def createPath(self): -- cgit From c0e2880ec1a91adbaa449b0b97d852616336e2a6 Mon Sep 17 00:00:00 2001 From: Sumit-Sahu Date: Tue, 2 Jun 2020 12:12:11 +0530 Subject: remove shapes.py from pull request --- src/main/python/shapes/shapes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index a0aca48..9fb7428 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -10,9 +10,7 @@ from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, QLineEdit) from .line import Line -from utils.app import fileImporter - - +from utils.app import fileImporter class GripItem(QGraphicsPathItem): """ -- cgit From 166376901be1006dee9ce96fd12f6b910b2e860c Mon Sep 17 00:00:00 2001 From: sumit Date: Tue, 2 Jun 2020 12:33:41 +0530 Subject: undo delete shapes.py --- src/main/python/shapes/shapes.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 9fb7428..5abb6a4 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -10,6 +10,7 @@ from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, QLineEdit) from .line import Line + from utils.app import fileImporter class GripItem(QGraphicsPathItem): -- cgit From 172e96a0068d257986962f32ab67273bfa0200cd Mon Sep 17 00:00:00 2001 From: sumit Date: Tue, 2 Jun 2020 13:12:03 +0530 Subject: update end point of line --- src/main/python/shapes/line.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index e6b1dd9..8c5149f 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -518,6 +518,10 @@ class Line(QGraphicsPathItem): updates points of line when grabber is moved :return: """ + if self.startGripItem: + self.points[0]= self.startPoint + if self.endGripItem: + self.points[len(self.points) - 1] = self.endPoint if self.startGripItem.m_location in ["left", "right"]: point = self.points[1] self.points[1] = QPointF(point.x(), self.startPoint.y()) @@ -527,7 +531,6 @@ class Line(QGraphicsPathItem): else: point = self.points[len(self.points) - 2] self.points[len(self.points) - 2] = QPointF(self.endPoint.x(), point.y()) - else: point = self.points[1] self.points[1] = QPointF(self.startPoint.x(), point.y()) @@ -538,6 +541,7 @@ class Line(QGraphicsPathItem): point = self.points[len(self.points) - 2] self.points[len(self.points) - 2] = QPointF(self.endPoint.x(), point.y()) + def shape(self): """generates outline for path """ -- cgit From 5bf8f7e70f49e0af4939e5bf6ef71053726cc970 Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 14:53:37 +0530 Subject: line working --- src/main/python/shapes/line.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 8c5149f..d1e3124 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -71,7 +71,6 @@ class Grabber(QGraphicsPathItem): return self.shape().boundingRect() def mousePressEvent(self, event): - print('grabber clicked', self) super(Grabber, self).mousePressEvent(event) def hoverEnterEvent(self, event): @@ -139,7 +138,6 @@ class LineLabel(QGraphicsTextItem): # print(self.pos()) def itemChange(self, change, value): - print("label change",change,value) # if change == QGraphicsItem.ItemPositionChange: # print("label change", change, value) return super(LineLabel, self).itemChange(change,value) @@ -188,7 +186,9 @@ class Line(QGraphicsPathItem): for polygon in polygons: center = polygon.boundingRect().center() self.commonPaths.append(center) + # self.commonPaths[commonPath] = item + print(self.commonPaths) self.update() def paint(self, painter, option, widget): @@ -198,11 +198,29 @@ class Line(QGraphicsPathItem): # painter.drawPath(path) path = QPainterPath(self.startPoint) # iterating over all points of line - for i in range(1, len(self.points)): + for i in range(len(self.points) - 1): + # for point in self.commonPaths: + # # point is center of common path + # pass for point in self.commonPaths: - # point is center of common path - pass - path.lineTo(self.points[i]) + x1, y1 = self.points[i].x(), self.points[i].y() + x2, y2 = self.points[i+1].x(), self.points[i+1].y() + x, y = point.x(), point.y() + # if not x1 * (y - y2) + x * (y2 - y1) + x2 * (y1 - y) : + if x == x1 == x2: + #vertical + if min(y1, y2) <= y < max(y1, y2): + path.lineTo(point - QPointF(0, 8)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) + path.moveTo(point + QPointF(0, 8)) + elif y == y1 == y2: + #horizontal + if min(x1, x2) <= x < max(x1, x2): + path.lineTo(point - QPointF(8, 0)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) + path.moveTo(point + QPointF(8, 0)) + path.lineTo(self.points[i+1]) + painter.drawPath(path) -- cgit From bfda61462a7c993efc8ed5bf3583f68601c6c074 Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 18:02:03 +0530 Subject: reverse dir fix --- src/main/python/shapes/line.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index d1e3124..e0e3fae 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -210,15 +210,29 @@ class Line(QGraphicsPathItem): if x == x1 == x2: #vertical if min(y1, y2) <= y < max(y1, y2): - path.lineTo(point - QPointF(0, 8)) + bool = y2>y1 + if bool: + path.lineTo(point - QPointF(0, 8)) + else: + path.lineTo(point + QPointF(0, 8)) path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) - path.moveTo(point + QPointF(0, 8)) + if bool: + path.moveTo(point + QPointF(0, 8)) + else: + path.moveTo(point - QPointF(0, 8)) elif y == y1 == y2: #horizontal if min(x1, x2) <= x < max(x1, x2): - path.lineTo(point - QPointF(8, 0)) + bool = x2>x1 + if bool: + path.lineTo(point - QPointF(8, 0)) + else: + path.lineTo(point - QPointF(8, 0)) path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) - path.moveTo(point + QPointF(8, 0)) + if bool: + path.moveTo(point + QPointF(8, 0)) + else: + path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From 0d93a4bacf0693af87a9b4bc67156e6ce8ef414d Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 21:28:30 +0530 Subject: loop 2nd fix --- src/main/python/shapes/line.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index e0e3fae..1c30cd9 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -213,12 +213,11 @@ class Line(QGraphicsPathItem): bool = y2>y1 if bool: path.lineTo(point - QPointF(0, 8)) - else: - path.lineTo(point + QPointF(0, 8)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) - if bool: + path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) path.moveTo(point + QPointF(0, 8)) else: + path.lineTo(point + QPointF(0, 8)) + path.arcTo(QRectF(x-8, y-8, 16, 16), -90, 180) path.moveTo(point - QPointF(0, 8)) elif y == y1 == y2: #horizontal @@ -226,13 +225,12 @@ class Line(QGraphicsPathItem): bool = x2>x1 if bool: path.lineTo(point - QPointF(8, 0)) - else: - path.lineTo(point - QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) - if bool: + path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) path.moveTo(point + QPointF(8, 0)) else: path.lineTo(point - QPointF(8, 0)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 0, -180) + path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From 4bfb3b09971d5e4c1d03469d82fb3b6e884c1aaf Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 23:24:34 +0530 Subject: minor typo --- src/main/python/shapes/line.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 1c30cd9..5ad61a7 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -210,8 +210,7 @@ class Line(QGraphicsPathItem): if x == x1 == x2: #vertical if min(y1, y2) <= y < max(y1, y2): - bool = y2>y1 - if bool: + if y2>y1: path.lineTo(point - QPointF(0, 8)) path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) path.moveTo(point + QPointF(0, 8)) @@ -222,14 +221,13 @@ class Line(QGraphicsPathItem): elif y == y1 == y2: #horizontal if min(x1, x2) <= x < max(x1, x2): - bool = x2>x1 - if bool: + if x2>x1: path.lineTo(point - QPointF(8, 0)) path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) path.moveTo(point + QPointF(8, 0)) else: path.lineTo(point - QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 0, -180) + path.arcTo(QRectF(x-8, y-8, 16, 16), 0, 180) path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) -- cgit From fa77d7e77334d1df269564ee0919a7b917d00676 Mon Sep 17 00:00:00 2001 From: Blaine Date: Tue, 2 Jun 2020 23:27:48 +0530 Subject: checkkk --- src/main/python/shapes/line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 5ad61a7..c5d5b57 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -228,7 +228,7 @@ class Line(QGraphicsPathItem): else: path.lineTo(point - QPointF(8, 0)) path.arcTo(QRectF(x-8, y-8, 16, 16), 0, 180) - path.lineTo(point - QPointF(8, 0)) + path.lineTo(point + QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From d8955687ae3a35a4cb40ee5deca43bc6f605d133 Mon Sep 17 00:00:00 2001 From: sumit Date: Wed, 3 Jun 2020 05:32:55 +0530 Subject: curve fix for line from right to left --- src/main/python/shapes/line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index c5d5b57..1a54284 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -226,9 +226,9 @@ class Line(QGraphicsPathItem): path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) path.moveTo(point + QPointF(8, 0)) else: - path.lineTo(point - QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 0, 180) path.lineTo(point + QPointF(8, 0)) + path.arcTo(QRectF(x-8, y-8, 16, 16), 0, -180) + path.lineTo(point - QPointF(8, 0)) path.lineTo(self.points[i+1]) painter.drawPath(path) -- cgit From e1cde189d5eeec7c13c7d3b65b54a9579730d34a Mon Sep 17 00:00:00 2001 From: Blaine Date: Wed, 3 Jun 2020 14:20:43 +0530 Subject: sort col points --- src/main/python/shapes/line.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 1a54284..2d7eba8 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -199,12 +199,9 @@ class Line(QGraphicsPathItem): path = QPainterPath(self.startPoint) # iterating over all points of line for i in range(len(self.points) - 1): - # for point in self.commonPaths: - # # point is center of common path - # pass - for point in self.commonPaths: - x1, y1 = self.points[i].x(), self.points[i].y() - x2, y2 = self.points[i+1].x(), self.points[i+1].y() + x1, y1 = self.points[i].x(), self.points[i].y() + x2, y2 = self.points[i+1].x(), self.points[i+1].y() + for point in self.commonPaths.sort(key = lambda x: x.x() + x.y(), reverse=x2>>>>>> changes self.setSharedRenderer(self.m_renderer) # set initial size of item self.width = 100 -- cgit From 01e0a1e191a550ad1cbed717d768a9257d10f462 Mon Sep 17 00:00:00 2001 From: Blaine Date: Wed, 3 Jun 2020 15:29:59 +0530 Subject: upstream --- src/main/python/shapes/shapes.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 5bd68e2..4f2294d 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -287,16 +287,10 @@ class NodeItem(QGraphicsSvgItem): QGraphicsSvgItem.__init__(self, parent) self.m_type = unitOperationType self.id = None -<<<<<<< HEAD - self.m_renderer = NodeItem.renderer - # if each svg is seperate file - # self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) -======= # self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") # self.m_renderer = QSvgRenderer(fileImporter(f'svg/{unitOperationType}.svg')) self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) # self.m_renderer = QSvgRenderer(resourceManager.get_resource(f'toolbar/{unitOperationType}.svg')) ->>>>>>> changes self.setSharedRenderer(self.m_renderer) # set initial size of item self.width = 100 -- cgit From 4c2133fdff296922fe6fc1a03462d8258564bd82 Mon Sep 17 00:00:00 2001 From: sumit Date: Wed, 3 Jun 2020 16:25:49 +0530 Subject: added id for svg item --- src/main/python/shapes/shapes.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 3237e72..94b9eb1 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -289,6 +289,7 @@ class NodeItem(QGraphicsSvgItem): def __init__(self, unitOperationType, parent=None): QGraphicsSvgItem.__init__(self, parent) self.m_type = unitOperationType + self.id =None # self.m_renderer = QSvgRenderer("svg/" + unitOperationType + ".svg") # self.m_renderer = QSvgRenderer(fileImporter(f'svg/{unitOperationType}.svg')) self.m_renderer = QSvgRenderer(fileImporter(f'svg/ellipse.svg')) -- cgit From 3685cf35417bb90b01824a07c8c6d4d8721a97a5 Mon Sep 17 00:00:00 2001 From: sumit Date: Fri, 5 Jun 2020 08:57:47 +0530 Subject: add text label to line with pop up menu --- src/main/python/shapes/line.py | 169 ++++++++++++++++++++++++++++++++--------- 1 file changed, 134 insertions(+), 35 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index f5eb92a..d968ace 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -1,6 +1,6 @@ import math from PyQt5.QtGui import QPen, QPainterPath, QBrush, QPainterPathStroker, QPainter, QCursor -from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem, QGraphicsTextItem +from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem, QGraphicsTextItem, QMenu, QGraphicsLineItem from PyQt5.QtCore import Qt, QPointF, QRectF @@ -100,47 +100,135 @@ class Grabber(QGraphicsPathItem): self.brush = QBrush(Qt.transparent) class LineLabel(QGraphicsTextItem): - def __init__(self, parent=None): - super(LineLabel, self).__init__(parent=parent) + def __init__(self, pos, parent=None): + super(LineLabel, self).__init__() + self.setPlainText("abc") + self.index = None + self.gap = None self.setTextInteractionFlags(Qt.TextEditorInteraction) self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) - self.setPlainText("abc") + self.line = QGraphicsLineItem() + self.setPos(pos-self.boundingRect().center()) + self.setParentItem(parent) + self.line.setParentItem(self) + self.resetPos() + # self.line.setFlag(QGraphicsItem.ItemStacksBehindParent) def paint(self, painter, option, widget): - super(LineLabel, self).paint(painter,option,widget) + # painter.save() + # painter.setBrush(QBrush(Qt.white)) painter.drawEllipse(self.boundingRect()) + # painter.restore() + super(LineLabel, self).paint(painter, option, widget) def updateLabel(self): + offset = self.gap points = self.parentItem().points - # min_A = QPointF() - # min_B =QPointF() - # min_dis =math.inf - # for i in range(1, len(points)): - # A = points[i - 1] - # B = points[i] - # C = self.pos() - # BAx = B.x() - A.x() - # BAy = B.y() - A.y() - # CAx = C.x() - A.x() - # CAy = C.y() - A.y() - # length = math.sqrt(BAx * BAx + BAy * BAy) - # if length >0: - # dis = (BAx*CAy - CAx*BAy)/length - # if abs(dis) < abs(min_dis): - # min_dis=dis - # min_A=A - # min_B=B - # - # self.setPos(self.parentItem().mapFromScene(QPointF(min_A))) - # print(self.pos()) + firstPoint = points[self.index] + endPoint = points[self.index + 1] + center = self.mapToParent(self.boundingRect().center()) + newPos = center + if firstPoint.x() == endPoint.x(): + newPos.setX(firstPoint.x() + self.gap) + if min(firstPoint.y(), endPoint.y()) > newPos.y(): + newPos.setY(min(firstPoint.y(), endPoint.y())) + elif newPos.y() > max(firstPoint.y(), endPoint.y()): + newPos.setY(max(firstPoint.y(), endPoint.y())) + + elif firstPoint.y() == endPoint.y(): + newPos.setY(firstPoint.y() + self.gap) + if min(firstPoint.x(), endPoint.x()) > newPos.x(): + newPos.setX(min(firstPoint.x(), endPoint.x())) + elif newPos.x() > max(firstPoint.x(), endPoint.x()): + newPos.setX(max(firstPoint.x(), endPoint.x())) + newPos -= QPointF(self.boundingRect().width() / 2, self.boundingRect().height() / 2) + self.setPos(newPos) + + def resetPos(self): + points = self.parentItem().points + min_A = QPointF() + min_B = QPointF() + min_dis = math.inf + for i in range(len(points) - 1): + A = points[i] + B = points[i + 1] + C = QPointF(self.pos()+self.boundingRect().center()) + BAx = B.x() - A.x() + BAy = B.y() - A.y() + CAx = C.x() - A.x() + CAy = C.y() - A.y() + length = math.sqrt(BAx * BAx + BAy * BAy) + if BAx == 0: + if not min(A.y(), B.y()) <= C.y() <= max(A.y(), B.y()): + continue + if BAy == 0: + if not min(A.x(), B.x()) <= C.x() <= max(A.x(), B.x()): + continue + if length > 0: + dis = (BAx * CAy - CAx * BAy) / length + if abs(dis) < abs(min_dis): + min_dis = dis + min_A = A + min_B = B + self.index = i + point = self.mapFromScene(min_A) + if min_A.x() == min_B.x(): + self.setPos(self.parentItem().mapFromScene(QPointF(min_A.x() + 10, self.y()))) + self.gap = 10+self.boundingRect().width()/2 + else: + self.setPos(self.parentItem().mapFromScene(QPointF(self.x(), min_A.y() - 30))) + self.gap = -30+self.boundingRect().height()/2 def itemChange(self, change, value): - # if change == QGraphicsItem.ItemPositionChange: - # print("label change", change, value) - return super(LineLabel, self).itemChange(change,value) + if change == QGraphicsItem.ItemPositionChange and self.scene(): + newPos = QPointF(value) + newPos += QPointF(self.boundingRect().width() / 2, self.boundingRect().height() / 2) + points = self.parentItem().points + firstPoint = points[self.index] + endPoint = points[self.index + 1] + if firstPoint.x() == endPoint.x(): + if min(firstPoint.y(), endPoint.y()) > newPos.y(): + newPos.setY(min(firstPoint.y(), endPoint.y())) + elif newPos.y() > max(firstPoint.y(), endPoint.y()): + newPos.setY(max(firstPoint.y(), endPoint.y())) + elif firstPoint.y() == endPoint.y(): + if min(firstPoint.x(), endPoint.x()) > newPos.x(): + newPos.setX(min(firstPoint.x(), endPoint.x())) + elif newPos.x() > max(firstPoint.x(), endPoint.x()): + newPos.setX(max(firstPoint.x(), endPoint.x())) + newPos -= QPointF(self.boundingRect().width() / 2, self.boundingRect().height() / 2) + return newPos + if change == QGraphicsItem.ItemPositionHasChanged and self.scene(): + self.updateGap() + self.updateLine() + return + return super(LineLabel, self).itemChange(change, value) + + def updateGap(self): + points = self.parentItem().points + firstPoint = points[self.index] + endPoint = points[self.index + 1] + firstPoint = self.mapFromParent(firstPoint) + endPoint = self.mapFromParent(endPoint) + center = self.boundingRect().center() + if firstPoint.x() == endPoint.x(): + self.gap = center.x() - firstPoint.x() + else: + self.gap = center.y() - firstPoint.y() + + def updateLine(self): + points = self.parentItem().points + firstPoint = points[self.index] + endPoint = points[self.index + 1] + point = self.mapFromParent(firstPoint) + center = self.boundingRect().center() + if firstPoint.x() == endPoint.x(): + self.line.setLine(center.x(), center.y(), point.x(), center.y()) + else: + self.line.setLine(center.x(), center.y(), center.x(), point.y()) class Line(QGraphicsPathItem): @@ -169,14 +257,15 @@ class Line(QGraphicsPathItem): # initiates path self.createPath() self.commonPaths=[] - self.label = LineLabel(self) + self.label = None def advance(self, phase): - # items = self.collidingItems(Qt.IntersectsItemShape) + # items colliding with line items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.AscendingOrder) self.commonPaths = [] + # if item is line and stacked above self for item in items: - if type(item) in [type(self)]: + if type(item) in [type(self)]: if item == self: break shape = item.shape() @@ -186,9 +275,6 @@ class Line(QGraphicsPathItem): for polygon in polygons: center = polygon.boundingRect().center() self.commonPaths.append(center) - - # self.commonPaths[commonPath] = item - print(self.commonPaths) self.update() def paint(self, painter, option, widget): @@ -537,6 +623,8 @@ class Line(QGraphicsPathItem): path.lineTo(self.points[i]) path.lineTo(self.endPoint) self.setPath(path) + if self.label: + self.label.updateLabel() def updatePoints(self): """ @@ -682,3 +770,14 @@ class Line(QGraphicsPathItem): def setPenStyle(self, style): """change current pen style for line""" self.penStyle = style + + def contextMenuEvent(self, event): + """Pop up menu + :return: + """ + contextMenu = QMenu() + addLableAction = contextMenu.addAction("add Label") + # addLableAction.triggered.connect(self.addLabel) + action = contextMenu.exec_(event.screenPos()) + if action == addLableAction: + self.label = LineLabel(event.scenePos(), self) \ No newline at end of file -- cgit From 8b3337c29d33cd4fe9fb4d3f1796daa4b623616a Mon Sep 17 00:00:00 2001 From: sumit Date: Fri, 5 Jun 2020 10:42:05 +0530 Subject: add text label for svg item --- src/main/python/shapes/shapes.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 47d9a52..722b836 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -7,13 +7,23 @@ from PyQt5.QtSvg import QGraphicsSvgItem, QSvgRenderer from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, QGraphicsItem, QGraphicsPathItem, QGraphicsProxyWidget, QGraphicsSceneHoverEvent, - QLineEdit) + QLineEdit, QMenu, QGraphicsTextItem) from .line import Line from utils.app import fileImporter from utils.app import fileImporter +class ItemLabel(QGraphicsTextItem): + def __init__(self, pos, parent=None): + super().__init__(parent=parent) + self.setPlainText("abc") + self.setTextInteractionFlags(Qt.TextEditorInteraction) + self.setFlags(QGraphicsItem.ItemIsMovable | + QGraphicsItem.ItemIsSelectable | + QGraphicsItem.ItemIsFocusable) + self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) + class GripItem(QGraphicsPathItem): """ Extends QGraphicsPathItem to create the structure of the Grabbable points for resizing shapes and connecting lines. @@ -306,6 +316,7 @@ class NodeItem(QGraphicsSvgItem): # grip items connected to this item self.lineGripItems = [] self.sizeGripItems = [] + self.label =None def boundingRect(self): """Overrides QGraphicsSvgItem's boundingRect() virtual public function and @@ -455,6 +466,16 @@ class NodeItem(QGraphicsSvgItem): item.setPen(QPen(Qt.transparent)) item.setBrush(Qt.transparent) + def contextMenuEvent(self, event): + """Pop up menu + :return: + """ + contextMenu = QMenu() + addLableAction = contextMenu.addAction("add Label") + # addLableAction.triggered.connect(self.addLabel) + action = contextMenu.exec_(event.screenPos()) + if action == addLableAction: + self.label = ItemLabel(event.scenePos(), self) # classes of pfd-symbols class AirBlownCooler(NodeItem): -- cgit From 6679f42a74e0ca9556c260f4c9d710c0e83e13d0 Mon Sep 17 00:00:00 2001 From: sumit Date: Mon, 8 Jun 2020 17:17:41 +0530 Subject: make line connect able another line --- src/main/python/shapes/line.py | 293 ++++++++++++++++++++++++++++------------- 1 file changed, 203 insertions(+), 90 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index d968ace..dc0a09c 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -31,8 +31,29 @@ class Grabber(QGraphicsPathItem): p = QPointF(self.pos()) if self._direction == Qt.Horizontal: p.setX(value.x()) + if self.parentItem().refLine and self.m_index == len(self.parentItem().points) - 2: + points = self.parentItem().refLine.points + point1 = points[self.parentItem().refIndex] + point2 = points[self.parentItem().refIndex + 1] + point1 = self.parentItem().mapFromItem(self.parentItem().refLine, point1) + point2 = self.parentItem().mapFromItem(self.parentItem().refLine, point2) + if p.x() < min(point1.x(), point2.x()): + p.setX(min(point1.x(), point2.x())) + elif p.x() > max(point1.x(), point2.x()): + p.setX(max(point1.x(), point2.x())) elif self._direction == Qt.Vertical: p.setY(value.y()) + if self.parentItem().refLine and self.m_index == len(self.parentItem().points) - 2: + points = self.parentItem().refLine.points + point1 = points[self.parentItem().refIndex] + point2 = points[self.parentItem().refIndex + 1] + point1 = self.parentItem().mapFromItem(self.parentItem().refLine, point1) + point2 = self.parentItem().mapFromItem(self.parentItem().refLine, point2) + if p.y() < min(point1.y(), point2.y()): + p.setY(min(point1.y(), point2.y())) + elif p.y() > max(point1.y(), point2.y()): + p.setY(max(point1.y(), point2.y())) + movement = p - self.pos() self.m_annotation_item.movePoints(self.m_index, movement) return p @@ -105,23 +126,23 @@ class LineLabel(QGraphicsTextItem): self.setPlainText("abc") self.index = None self.gap = None - self.setTextInteractionFlags(Qt.TextEditorInteraction) self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable) + self.setTextInteractionFlags(Qt.NoTextInteraction) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) - self.line = QGraphicsLineItem() - self.setPos(pos-self.boundingRect().center()) + self.setPos(pos - self.boundingRect().center()) self.setParentItem(parent) + self.line = QGraphicsLineItem() self.line.setParentItem(self) + self.line.setFlag(QGraphicsItem.ItemStacksBehindParent) self.resetPos() - # self.line.setFlag(QGraphicsItem.ItemStacksBehindParent) def paint(self, painter, option, widget): - # painter.save() - # painter.setBrush(QBrush(Qt.white)) + painter.save() + painter.setBrush(QBrush(Qt.white)) painter.drawEllipse(self.boundingRect()) - # painter.restore() + painter.restore() super(LineLabel, self).paint(painter, option, widget) def updateLabel(self): @@ -155,7 +176,7 @@ class LineLabel(QGraphicsTextItem): for i in range(len(points) - 1): A = points[i] B = points[i + 1] - C = QPointF(self.pos()+self.boundingRect().center()) + C = QPointF(self.pos() + self.boundingRect().center()) BAx = B.x() - A.x() BAy = B.y() - A.y() CAx = C.x() - A.x() @@ -177,10 +198,10 @@ class LineLabel(QGraphicsTextItem): point = self.mapFromScene(min_A) if min_A.x() == min_B.x(): self.setPos(self.parentItem().mapFromScene(QPointF(min_A.x() + 10, self.y()))) - self.gap = 10+self.boundingRect().width()/2 + self.gap = 10 + self.boundingRect().width() / 2 else: self.setPos(self.parentItem().mapFromScene(QPointF(self.x(), min_A.y() - 30))) - self.gap = -30+self.boundingRect().height()/2 + self.gap = -30 + self.boundingRect().height() / 2 def itemChange(self, change, value): if change == QGraphicsItem.ItemPositionChange and self.scene(): @@ -230,42 +251,81 @@ class LineLabel(QGraphicsTextItem): else: self.line.setLine(center.x(), center.y(), center.x(), point.y()) + def mouseDoubleClickEvent(self, event): + self.setTextInteractionFlags(Qt.TextEditorInteraction) + self.setFocus() + super(LineLabel, self).mouseDoubleClickEvent(event) + + def focusOutEvent(self, event): + super(LineLabel, self).focusOutEvent(event) + self.setTextInteractionFlags(Qt.NoTextInteraction) + + +def findIndex(line, pos): + points = line.points + min_A = QPointF() + min_B = QPointF() + min_dis = math.inf + index = -1 + for i in range(len(points) - 1): + A = points[i] + B = points[i + 1] + C = pos + BAx = B.x() - A.x() + BAy = B.y() - A.y() + CAx = C.x() - A.x() + CAy = C.y() - A.y() + length = math.sqrt(BAx * BAx + BAy * BAy) + if BAx == 0: + if not min(A.y(), B.y()) <= C.y() <= max(A.y(), B.y()): + continue + if BAy == 0: + if not min(A.x(), B.x()) <= C.x() <= max(A.x(), B.x()): + continue + if length > 0: + dis = (BAx * CAy - CAx * BAy) / length + if abs(dis) < abs(min_dis): + min_dis = dis + min_A = A + min_B = B + index = i + return index + class Line(QGraphicsPathItem): """ Extends QGraphicsPathItem to draw zig-zag line consisting of multiple points """ - penStyle = Qt.SolidLine - def __init__(self, startPoint, endPoint, **args): QGraphicsItem.__init__(self, **args) self.startPoint = startPoint self.endPoint = endPoint - #stores all points of line + # stores all points of line self.points = [] - self.points.extend([startPoint, endPoint]) self.startGripItem = None self.endGripItem = None - self._selected = False self.m_grabbers = [] - # stores current pen style of line - self.penStyle = Line.penStyle - # set graphical settings for this item + # set graphical settings for line self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) self.setAcceptHoverEvents(True) - # initiates path - self.createPath() - self.commonPaths=[] - self.label = None + # store reference if line connect another line + self.refLine = None # reference line + self.refIndex = None # start index of segment to which it connects + self.commonPathsCenters = [] + self.midLines = [] + self.label = [] def advance(self, phase): + if not phase: + return # items colliding with line - items = self.scene().items(self.shape(),Qt.IntersectsItemShape,Qt.AscendingOrder) - self.commonPaths = [] - # if item is line and stacked above self + # items = self.collidingItems(Qt.IntersectsItemShape) + items = self.scene().items(self.shape(), Qt.IntersectsItemShape, Qt.AscendingOrder) + self.commonPathsCenters = [] + # if item is line and stacked above for item in items: - if type(item) in [type(self)]: + if type(item) in [type(self)]: if item == self: break shape = item.shape() @@ -274,50 +334,57 @@ class Line(QGraphicsPathItem): polygons = commonPath.toSubpathPolygons() for polygon in polygons: center = polygon.boundingRect().center() - self.commonPaths.append(center) + if polygon.size() == 5: + if item.refLine: + i = len(item.points) - 2 + x1, y1 = item.points[i].x(), item.points[i].y() + x2, y2 = item.points[i+1].x(), item.points[i+1].y() + x, y = center.x(), center.y() + if x == x1 == x2 and not min(y1, y2) + 8 <= y < max(y1, y2) - 8: + continue + elif y == y1 == y2 and not min(x1, x2) + 8 <= x < max(x1, x2) - 8: + continue + else: + self.commonPathsCenters.append(center) + else: + self.commonPathsCenters.append(center) self.update() - + def paint(self, painter, option, widget): color = Qt.red if self.isSelected() else Qt.black - painter.setPen(QPen(color, 2, self.penStyle)) - # path = self.path() - # painter.drawPath(path) + painter.setPen(QPen(color, 2, Qt.SolidLine)) path = QPainterPath(self.startPoint) # iterating over all points of line for i in range(len(self.points) - 1): x1, y1 = self.points[i].x(), self.points[i].y() - x2, y2 = self.points[i+1].x(), self.points[i+1].y() - for point in sorted(self.commonPaths, key = lambda x: x.x() + x.y(), reverse=x2y1: + # vertical + if min(y1, y2) + 8 <= y < max(y1, y2) - 8: + if y2 > y1: path.lineTo(point - QPointF(0, 8)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 90, -180) + path.arcTo(QRectF(x - 8, y - 8, 16, 16), 90, -180) path.moveTo(point + QPointF(0, 8)) else: path.lineTo(point + QPointF(0, 8)) - path.arcTo(QRectF(x-8, y-8, 16, 16), -90, 180) + path.arcTo(QRectF(x - 8, y - 8, 16, 16), -90, 180) path.moveTo(point - QPointF(0, 8)) elif y == y1 == y2: - #horizontal - if min(x1, x2) <= x < max(x1, x2): - if x2>x1: + # horizontal + if min(x1, x2) + 8 <= x < max(x1, x2) - 8: + if x2 > x1: path.lineTo(point - QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 180, 180) + path.arcTo(QRectF(x - 8, y - 8, 16, 16), 180, 180) path.moveTo(point + QPointF(8, 0)) else: path.lineTo(point + QPointF(8, 0)) - path.arcTo(QRectF(x-8, y-8, 16, 16), 0, -180) + path.arcTo(QRectF(x - 8, y - 8, 16, 16), 0, -180) path.lineTo(point - QPointF(8, 0)) - path.lineTo(self.points[i+1]) - - painter.drawPath(path) - - + path.lineTo(self.points[i + 1]) + painter.drawPath(path) def createPath(self): """ @@ -327,9 +394,28 @@ class Line(QGraphicsPathItem): offset = 30 x0, y0 = self.startPoint.x(), self.startPoint.y() x1, y1 = self.endPoint.x(), self.endPoint.y() - # create line is in process + # create path for line in process self.points = [self.startPoint, QPointF((x0 + x1) / 2, y0), QPointF((x0 + x1) / 2, y1), self.endPoint] # final path of line + if self.refLine: + from .shapes import LineGripItem + direction = "left" + points = self.refLine.points + point1 = points[self.refIndex] + point2 = points[self.refIndex + 1] + if point1.x() == point2.x(): + if point1.x() < self.startPoint.x(): + direction = "right" + else: + direction = "left" + elif point1.y() == point2.y(): + if point1.y() > self.startPoint.y(): + direction = "top" + else: + direction = "bottom" + + self.endGripItem = LineGripItem(self, -1, direction, self) + self.endGripItem.setPos(self.endPoint) if self.startGripItem and self.endGripItem: # determine ns (point next to start) item = self.startGripItem @@ -342,7 +428,7 @@ class Line(QGraphicsPathItem): ns = QPointF(self.startPoint.x(), self.startPoint.y() + offset) else: ns = QPointF(self.startPoint.x() + offset, self.startPoint.y()) - # pe (point previous to end) + # determine pe (point previous to end) item = self.endGripItem self.endPoint = item.parentItem().mapToScene(item.pos()) if item.m_location == "top": @@ -610,6 +696,11 @@ class Line(QGraphicsPathItem): for i in range(1, len(self.points)): path.lineTo(self.points[i]) self.setPath(path) + + if self.refLine: + self.scene().removeItem(self.endGripItem) + self.endGripItem = None + self.addGrabber() if self.endGripItem: self.addGrabber() @@ -623,8 +714,10 @@ class Line(QGraphicsPathItem): path.lineTo(self.points[i]) path.lineTo(self.endPoint) self.setPath(path) - if self.label: - self.label.updateLabel() + self.updateGrabber() + for label in self.label: + label.updateLabel() + self.updateMidLines() def updatePoints(self): """ @@ -632,29 +725,21 @@ class Line(QGraphicsPathItem): :return: """ if self.startGripItem: - self.points[0]= self.startPoint - if self.endGripItem: - self.points[len(self.points) - 1] = self.endPoint - if self.startGripItem.m_location in ["left", "right"]: + self.points[0] = self.startPoint point = self.points[1] - self.points[1] = QPointF(point.x(), self.startPoint.y()) - if self.endGripItem.m_location in ["left", "right"]: - point = self.points[len(self.points) - 2] - self.points[len(self.points) - 2] = QPointF(point.x(), self.endPoint.y()) + if self.startGripItem.m_location in ["left", "right"]: + self.points[1] = QPointF(point.x(), self.startPoint.y()) else: - point = self.points[len(self.points) - 2] - self.points[len(self.points) - 2] = QPointF(self.endPoint.x(), point.y()) - else: - point = self.points[1] - self.points[1] = QPointF(self.startPoint.x(), point.y()) + self.points[1] = QPointF(self.startPoint.x(), point.y()) + + if self.endGripItem: + self.points[len(self.points) - 1] = self.endPoint + point = self.points[len(self.points) - 2] if self.endGripItem.m_location in ["left", "right"]: - point = self.points[len(self.points) - 2] self.points[len(self.points) - 2] = QPointF(point.x(), self.endPoint.y()) else: - point = self.points[len(self.points) - 2] self.points[len(self.points) - 2] = QPointF(self.endPoint.x(), point.y()) - def shape(self): """generates outline for path """ @@ -670,21 +755,25 @@ class Line(QGraphicsPathItem): point = self.points[i] point += movement self.points[i] = point - self.updatePath() - self.updateGrabber([index]) + self.updatePath() def addGrabber(self): """adds grabber when line is moved """ - if self.startGripItem.m_location in ["left", "right"]: - direction = [Qt.Horizontal, Qt.Vertical] + for grabber in self.m_grabbers: + self.scene().removeItem(grabber) + if self.endGripItem: + count = range(1, len(self.points) - 2) else: - direction = [Qt.Vertical, Qt.Horizontal] - for i in range(1, len(self.points) - 2): - item = Grabber(self, i, direction[(i - 1)%2]) + count = range(1, len(self.points) - 1) + for i in count: + if self.points[i].x() == self.points[i + 1].x(): + direction = Qt.Horizontal + else: + direction = Qt.Vertical + item = Grabber(self, i, direction) item.setParentItem(self) item.setPos(self.pos()) - self.scene().addItem(item) self.m_grabbers.append(item) def updateGrabber(self, index_no_updates=None): @@ -692,7 +781,7 @@ class Line(QGraphicsPathItem): """ index_no_updates = index_no_updates or [] for grabber in self.m_grabbers: - if grabber.m_index in index_no_updates: continue + if grabber.m_index in index_no_updates or grabber.isSelected(): continue index = grabber.m_index startPoint = self.points[index] endPoint = self.points[index + 1] @@ -705,13 +794,15 @@ class Line(QGraphicsPathItem): if change == QGraphicsItem.ItemSelectedHasChanged: if value == 1: self.showGripItem() + items = self.collidingItems(Qt.IntersectsItemShape) + for item in items: + if type(item) == type(self): + item.stackBefore(self) + self.scene().update() else: self.hideGripItem() return - if change == QGraphicsItem.ItemSceneHasChanged and self.scene(): - # self.addGrabber() - # self.updateGrabber() - return + return super(Line, self).itemChange(change, value) def updateLine(self, startPoint=None, endPoint=None): @@ -727,7 +818,6 @@ class Line(QGraphicsPathItem): self.endPoint = endPoint self.createPath() self.updateGrabber() - self.scene().update() return if self.startGripItem and self.endGripItem: @@ -736,7 +826,35 @@ class Line(QGraphicsPathItem): item = self.endGripItem self.endPoint = item.parentItem().mapToScene(item.pos()) self.updatePath() - self.updateGrabber() + + if self.startGripItem and self.refLine: + item = self.startGripItem + self.startPoint = item.parentItem().mapToScene(item.pos()) + self.updatePath() + + def updateMidLines(self): + for line in self.midLines: + points = line.refLine.points + point1 = points[line.refIndex] + point2 = points[line.refIndex + 1] + i = len(line.points) - 1 + if point1.x() == point2.x(): + line.points[i].setX(point1.x()) + if line.points[i].y() < min(point1.y(), point2.y()): + line.points[i].setY(min(point1.y(), point2.y())) + line.points[i-1].setY(min(point1.y(), point2.y())) + elif line.points[i].y() > max(point1.y(), point2.y()): + line.points[i].setY(max(point1.y(), point2.y())) + line.points[i-1].setY(max(point1.y(), point2.y())) + elif point1.y() == point2.y(): + line.points[i].setY(point1.y()) + if line.points[i].x() < min(point1.x(), point2.x()): + line.points[i].setX(min(point1.x(), point2.x())) + line.points[i-1].setX(min(point1.x(), point2.x())) + elif line.points[i].x() > max(point1.x(), point2.x()): + line.points[i].setX(max(point1.x(), point2.x())) + line.points[i-1].setX(max(point1.x(), point2.x())) + line.updatePath() def removeFromCanvas(self): """This function is used to remove connecting line from canvas @@ -767,17 +885,12 @@ class Line(QGraphicsPathItem): def setEndGripItem(self, item): self.endGripItem = item - def setPenStyle(self, style): - """change current pen style for line""" - self.penStyle = style - def contextMenuEvent(self, event): """Pop up menu :return: """ contextMenu = QMenu() addLableAction = contextMenu.addAction("add Label") - # addLableAction.triggered.connect(self.addLabel) action = contextMenu.exec_(event.screenPos()) if action == addLableAction: - self.label = LineLabel(event.scenePos(), self) \ No newline at end of file + self.label.append(LineLabel(event.scenePos(), self)) \ No newline at end of file -- cgit From 0acf5ce903c3ce76eba9232ce914a3a5d5e5acb0 Mon Sep 17 00:00:00 2001 From: sumit Date: Mon, 8 Jun 2020 17:18:28 +0530 Subject: change text with double click text label --- src/main/python/shapes/shapes.py | 84 +++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 31 deletions(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 722b836..bd8273b 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -2,15 +2,15 @@ from PyQt5 import QtCore, QtWidgets from PyQt5.QtCore import (QEvent, QFile, QIODevice, QMimeData, QPointF, QRect, QRectF, QSizeF, Qt) from PyQt5.QtGui import (QBrush, QColor, QCursor, QDrag, QFont, QImage, - QPainter, QPainterPath, QPen, QTransform) + QPainter, QPainterPath, QPen, QTransform, QTextCursor) from PyQt5.QtSvg import QGraphicsSvgItem, QSvgRenderer from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, QGraphicsItem, QGraphicsPathItem, QGraphicsProxyWidget, QGraphicsSceneHoverEvent, QLineEdit, QMenu, QGraphicsTextItem) -from .line import Line -from utils.app import fileImporter +from .line import Line, findIndex +from utils.app import fileImporter from utils.app import fileImporter @@ -18,11 +18,22 @@ class ItemLabel(QGraphicsTextItem): def __init__(self, pos, parent=None): super().__init__(parent=parent) self.setPlainText("abc") - self.setTextInteractionFlags(Qt.TextEditorInteraction) self.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) + self.setTextInteractionFlags(Qt.NoTextInteraction) + self.setPos(self.parentItem().boundingRect().bottomLeft()) + + def mouseDoubleClickEvent(self, event): + self.setTextInteractionFlags(Qt.TextEditorInteraction) + self.setFocus() + super(ItemLabel, self).mouseDoubleClickEvent(event) + + def focusOutEvent(self, event): + super(ItemLabel, self).focusOutEvent(event) + self.setTextInteractionFlags(Qt.NoTextInteraction) + class GripItem(QGraphicsPathItem): """ @@ -184,7 +195,7 @@ class LineGripItem(GripItem): super(LineGripItem, self).__init__(annotation_item, path=self.path, parent=parent) self.m_index = index self.m_location = location - self.connectedLines = [] + self.line = None # stores current line which is in process self.tempLine = None # keep previous hovered item when line drawing in process @@ -211,8 +222,8 @@ class LineGripItem(GripItem): self.setEnabled(False) self.setPos(pos) self.setEnabled(True) - for line in self.connectedLines: - line.updateLine() + if self.line: + self.line.updateLine() def mousePressEvent(self, mouseEvent): """Handle all mouse press for this item @@ -220,9 +231,13 @@ class LineGripItem(GripItem): if mouseEvent.button() != Qt.LeftButton: return # initialize a line and add on scene - startPoint = endPoint = self.parentItem().mapToScene(self.pos()) - self.tempLine = Line(startPoint, endPoint) - self.scene().addItemPlus(self.tempLine) + if self.line and not self.line.scene(): + self.line = None + + if not self.line: + startPoint = endPoint = self.parentItem().mapToScene(self.pos()) + self.tempLine = Line(startPoint, endPoint) + self.scene().addItem(self.tempLine) super().mousePressEvent(mouseEvent) def mouseMoveEvent(self, mouseEvent): @@ -250,29 +265,36 @@ class LineGripItem(GripItem): super().mouseReleaseEvent(mouseEvent) # set final position of line if self.tempLine: - item = self.scene().itemAt(mouseEvent.scenePos().x(), mouseEvent.scenePos().y(), - self.transform()) - - if type(item) == LineGripItem and item != self: - self.tempLine.setStartGripItem(self) - self.tempLine.setEndGripItem(item) - endPoint = item.parentItem().mapToScene(item.pos()) - self.tempLine.updateLine(endPoint=endPoint) - self.connectedLines.append(self.tempLine) - item.connectedLines.append(self.tempLine) - + items = self.scene().items(QPointF(mouseEvent.scenePos().x(), mouseEvent.scenePos().y())) + for item in items: + if type(item) == LineGripItem and item != self: + if item.line and not item.line.scene(): + item.line = None + if item.line: + break + self.tempLine.setStartGripItem(self) + self.tempLine.setEndGripItem(item) + endPoint = item.parentItem().mapToScene(item.pos()) + self.tempLine.updateLine(endPoint=endPoint) + self.line = self.tempLine + item.line = self.tempLine + break + elif type(item) == Line and item != self.tempLine: + self.tempLine.setStartGripItem(self) + endPoint = mouseEvent.scenePos() + self.tempLine.refLine = item + self.tempLine.refIndex = findIndex(item, endPoint) + self.tempLine.updateLine(endPoint=endPoint) + item.midLines.append(self.tempLine) + self.line = self.tempLine + break + self.scene().removeItem(self.tempLine) + if self.line: + self.scene().addItemPlus(self.line) - - elif self.tempLine and self.scene(): - self.scene().removeItem(self.tempLine) self.tempLine = None self.previousHoveredItem = None - def removeConnectedLines(self): - """removes all connected line to grip""" - for line in self.connectedLines: - line.removeFromCanvas() - def show(self): """ shows line grip item """ @@ -316,8 +338,8 @@ class NodeItem(QGraphicsSvgItem): # grip items connected to this item self.lineGripItems = [] self.sizeGripItems = [] - self.label =None - + self.label = None + def boundingRect(self): """Overrides QGraphicsSvgItem's boundingRect() virtual public function and returns a valid bounding -- cgit From 7f7aa6afd060714d77ab1c38b8f53d56eaef29ca Mon Sep 17 00:00:00 2001 From: sumit Date: Mon, 8 Jun 2020 18:41:35 +0530 Subject: change in update size grip method --- src/main/python/shapes/shapes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index bd8273b..3e5cbb2 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -419,7 +419,7 @@ class NodeItem(QGraphicsSvgItem): updates size grip items """ index_no_updates = index_no_updates or [] - for i, item in zip(range(len(self.sizeGripItems)), self.sizeGripItems): + for i, item in enumerate(self.sizeGripItems): if i not in index_no_updates: item.updatePosition() -- cgit From 6b815b95236a28d585ad48799cc689e595110a94 Mon Sep 17 00:00:00 2001 From: sumit Date: Mon, 8 Jun 2020 18:56:12 +0530 Subject: add ellipse.svg --- src/main/resources/base/svg/ellipse.svg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/resources/base/svg/ellipse.svg b/src/main/resources/base/svg/ellipse.svg index c455408..7da0ae6 100644 --- a/src/main/resources/base/svg/ellipse.svg +++ b/src/main/resources/base/svg/ellipse.svg @@ -1,8 +1,8 @@ - + - + - + - \ No newline at end of file + \ No newline at end of file -- cgit