diff options
Diffstat (limited to 'Graphics.py')
-rw-r--r-- | Graphics.py | 437 |
1 files changed, 253 insertions, 184 deletions
diff --git a/Graphics.py b/Graphics.py index 467b628..0fa3306 100644 --- a/Graphics.py +++ b/Graphics.py @@ -10,101 +10,121 @@ from PyQt5.QtGui import QTextDocument ,QTextCursor ,QTextCharFormat ,QFont ,QPix from PyQt5.uic import loadUiType from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QGraphicsProxyWidget, QGraphicsObject, QGraphicsEllipseItem ,QGraphicsPixmapItem,QApplication, QGraphicsView, QGraphicsScene, QHBoxLayout, QWidget, QLabel -from PyQt5.QtGui import QBrush ,QTransform ,QMouseEvent +from PyQt5.QtGui import QBrush ,QTransform ,QMouseEvent, QIcon import PyQt5.QtGui as QtGui import PyQt5.QtCore as QtCore import PyQt5.QtWidgets as QtWidgets -from component_selector import * -from DockWidget import * -from DockWidgetMatStm import * - +from ComponentSelector import * +from DockWidgets.DockWidget import * +from DockWidgets.DockWidgetMaterialStream import * +from DockWidgets.DockWidgetDistillationColumn import * +from DockWidgets.DockWidgetShortcutColumn import * +from DockWidgets.DockWidgetMixer import * +from DockWidgets.DockWidgetSplitter import * +from DockWidgets.DockWidgetFlash import * +from DockWidgets.DockWidgetCompoundSeparator import * import datetime -from container import * -import container +from Container import * +import Container from Streams import * from UnitOperations import * class Graphics(QDialog, QtWidgets.QGraphicsItem): - def __init__(self, unitOp): + def __init__(self, unit_operations, graphicsView): QDialog.__init__(self) QtWidgets.QGraphicsItem.__init__(self) self.scene = QGraphicsScene() self.scene.setItemIndexMethod(QGraphicsScene.BspTreeIndex) + self.graphicsView = graphicsView self.pos = None - self.unitOp = unitOp + self.unit_operations = unit_operations - def getScene(self): + def get_scene(self): return self.scene - def getComponentSelector(self): - return componentSelector(self) + def get_component_selector(self): + return ComponentSelector(self) - def createNodeItem(self,unitOpr, container): - return NodeItem(unitOpr, container) + def create_node_item(self,unit_operation, container): + print("in create node item function") + return NodeItem(unit_operation, container, self.graphicsView) - def boundingRect(self): - return QtCore.QRectF(self.rect) + # def boundingRect(self): + # return QtCore.QRectF(self.rect) - def loadCanvas(self, obj): + def load_canvas(self, obj, container): stm = ['MaterialStream','EngStm'] - + print('in load canvas') compounds = obj[-1] obj.pop() - componentSelector.setCompounds(compounds) + ComponentSelector.set_compounds(compounds) for i in obj: - if(i in self.unitOp): + print("in for loop", i) + if(i in self.unit_operations): pass else: - self.unitOp.append(i) - new_box = self.createNodeItem(i, self) + self.unit_operations.append(i) + print(self.unit_operations) + new_box = self.create_node_item(i, container) + print('after createing node item') new_box.setPos(i.pos.toPoint().x(), i.pos.toPoint().y()) self.scene.addItem(new_box) for i in obj: + print('in i obj line') if i.type == "MaterialStream": - eval(i.type).counter += 1 + print('in i obj line in if') + # print(eval(i.type)) + # eval(i.type).counter += 1 + # print(eval(i.type).counter) elif i.type not in stm: - eval(i.type).counter += 1 - ip = i.InputStms - op = i.OutputStms + print('in i obj line in else') + ip = i.input_stms + op = i.output_stms + print(ip) + print(op) + # print(eval(i.type)) + # eval(i.type).counter += 1 + # print(eval(i.type).counter) for j in ip: - pointA = NodeItem.getInstances(j.name) - pointB = NodeItem.getInstances(i.name) - rect = pointA.Output[0].boundingRect() + print('in j in ip') + pointA = NodeItem.get_instances(j.name) + pointB = NodeItem.get_instances(i.name) + rect = pointA.output[0].boundingRect() pointAA = QtCore.QPointF(rect.x() + rect.width()/2, rect.y() + rect.height()/2) - pointAA = pointA.Output[0].mapToScene(pointAA) - rectB = pointB.Input[0].boundingRect() + pointAA = pointA.output[0].mapToScene(pointAA) + rectB = pointB.input[0].boundingRect() pointBB = QtCore.QPointF(rectB.x() + rectB.width()/2, rectB.y() + rectB.height()/2) - pointBB = pointB.Input[0].mapToScene(pointBB) + pointBB = pointB.input[0].mapToScene(pointBB) self.new_line = NodeLine(pointAA, pointBB, 'in') - self.new_line.source = pointA.Output[0] - self.new_line.target = pointB.Input[0] - pointA.Output[0].outLines.append(self.new_line) - pointB.Input[0].inLines.append(self.new_line) - pointA.Output[0].otherLine = self.new_line - pointB.Input[0].otherLine = self.new_line + self.new_line.source = pointA.output[0] + self.new_line.target = pointB.input[0] + pointA.output[0].out_lines.append(self.new_line) + pointB.input[0].in_lines.append(self.new_line) + pointA.output[0].other_line = self.new_line + pointB.input[0].other_line = self.new_line self.scene.addItem(self.new_line) self.new_line.updatePath() for k in op: - pointA = NodeItem.getInstances(i.name) - pointB = NodeItem.getInstances(k.name) - rect = pointA.Output[0].boundingRect() + pointA = NodeItem.get_instances(i.name) + pointB = NodeItem.get_instances(k.name) + rect = pointA.output[0].boundingRect() pointAA = QtCore.QPointF(rect.x() + rect.width()/2, rect.y() + rect.height()/2) - pointAA = pointA.Output[0].mapToScene(pointAA) - rectB = pointB.Input[0].boundingRect() + pointAA = pointA.output[0].mapToScene(pointAA) + rectB = pointB.input[0].boundingRect() pointBB = QtCore.QPointF(rectB.x() + rectB.width()/2, rectB.y() + rectB.height()/2) - pointBB = pointB.Input[0].mapToScene(pointBB) + pointBB = pointB.input[0].mapToScene(pointBB) self.new_line = NodeLine(pointAA, pointBB, 'out') - self.new_line.source = pointA.Output[0] - self.new_line.target = pointB.Input[0] - pointA.Output[0].outLines.append(self.new_line) - pointB.Input[0].inLines.append(self.new_line) - pointA.Output[0].otherLine = self.new_line - pointB.Input[0].otherLine = self.new_line + self.new_line.source = pointA.output[0] + self.new_line.target = pointB.input[0] + pointA.output[0].out_lines.append(self.new_line) + pointB.input[0].in_lines.append(self.new_line) + pointA.output[0].other_line = self.new_line + pointB.input[0].other_line = self.new_line self.scene.addItem(self.new_line) self.new_line.updatePath() @@ -118,11 +138,11 @@ class NodeLine(QtWidgets.QGraphicsPathItem): self._source = None self._target = None self.setZValue(-1) - self.setBrush(QtGui.QColor(0,0,255,255)) + self.setBrush(QtGui.QColor(0,70,70,120)) self.pen = QtGui.QPen() self.pen.setStyle(QtCore.Qt.SolidLine) - self.pen.setWidth(1) - self.pen.setColor(QtGui.QColor(0,0,255,255)) + self.pen.setWidth(2) + self.pen.setColor(QtGui.QColor(0,70,70,220)) self.setPen(self.pen) def updatePath(self): @@ -138,8 +158,8 @@ class NodeLine(QtWidgets.QGraphicsPathItem): path.cubicTo(ctrl1_1, ctrl2_1, pt1) if abs(self.pointB.x()-midptx) > 150: - ctrl1_2 = QtCore.QPointF(midptx, self.pointB.y()) - ctrl2_2 = QtCore.QPointF(midptx, self.pointB.y()) + ctrl1_2 = QtCore.QPointF(midptx, self.pointA.y()) + ctrl2_2 = QtCore.QPointF(midptx, self.pointA.y()) pt2 = QtCore.QPointF(midptx , self.pointA.y()+100) path.cubicTo(ctrl1_2, ctrl2_2, pt2) path.moveTo(pt2) @@ -150,8 +170,8 @@ class NodeLine(QtWidgets.QGraphicsPathItem): path.cubicTo(ctrl1_3, ctrl2_3, pt3) path.moveTo(pt3) - ctrl1_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2)) - ctrl2_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2)) + ctrl1_4 = QtCore.QPointF(self.pointB.x()-13, self.pointA.y()+100) + ctrl2_4 = QtCore.QPointF(self.pointB.x()-13, self.pointA.y()+100) pt4 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y()) path.cubicTo(ctrl1_4, ctrl2_4, pt4) path.moveTo(pt4) @@ -165,8 +185,8 @@ class NodeLine(QtWidgets.QGraphicsPathItem): self.setPath(path) return else: - ctrl1_2 = QtCore.QPointF(midptx, self.pointB.y()) - ctrl2_2 = QtCore.QPointF(midptx, self.pointB.y()) + ctrl1_2 = QtCore.QPointF(midptx, self.pointA.y()) + ctrl2_2 = QtCore.QPointF(midptx, self.pointA.y()) pt2 = QtCore.QPointF(midptx , max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2)) path.cubicTo(ctrl1_2, ctrl2_2, pt2) path.moveTo(pt2) @@ -202,8 +222,8 @@ class NodeLine(QtWidgets.QGraphicsPathItem): path.cubicTo(ctrl1_1, ctrl2_1, pt1) path.moveTo(pt1) - ctrl1_2 = QtCore.QPointF(midptx, self.pointB.y()) - ctrl2_2 = QtCore.QPointF(midptx, self.pointB.y()) + ctrl1_2 = QtCore.QPointF(midptx, self.pointA.y()) + ctrl2_2 = QtCore.QPointF(midptx, self.pointA.y()) pt2 = QtCore.QPointF(midptx , self.pointB.y()) path.cubicTo(ctrl1_2, ctrl2_2, pt2) path.moveTo(pt2) @@ -264,22 +284,23 @@ class NodeSocket(QtWidgets.QGraphicsItem): self.rect = rect self.type = socketType self.parent=parent - self.newLine=None - self.otherLine=None + self.setAcceptHoverEvents(True) + self.new_line=None + self.other_line=None # Brush. self.brush = QtGui.QBrush() self.brush.setStyle(QtCore.Qt.SolidPattern) - self.brush.setColor(QtGui.QColor(180,20,90,255)) + self.brush.setColor(QtGui.QColor(220,220,220,220)) #180,20,90,255 # Pen. self.pen = QtGui.QPen() self.pen.setStyle(QtCore.Qt.SolidLine) self.pen.setWidth(1) - self.pen.setColor(QtGui.QColor(20,20,20,255)) + self.pen.setColor(QtGui.QColor(0,70,70,255)) #20,20,20,255 # Lines. - self.outLines = [] - self.inLines = [] + self.out_lines = [] + self.in_lines = [] def shape(self): path = QtGui.QPainterPath() @@ -295,159 +316,199 @@ class NodeSocket(QtWidgets.QGraphicsItem): painter.drawEllipse(self.rect) def mousePressEvent(self, event): + cursor = QCursor( Qt.PointingHandCursor ) + QApplication.instance().setOverrideCursor(cursor) + if self.type == 'op': rect = self.boundingRect() pointA = QtCore.QPointF(rect.x() + rect.width()/2, rect.y() + rect.height()/2) pointA = self.mapToScene(pointA) pointB = self.mapToScene(event.pos()) - self.newLine = NodeLine(pointA, pointB ,'op') - self.outLines.append(self.newLine) - self.scene().addItem(self.newLine) + self.new_line = NodeLine(pointA, pointB ,'op') + self.out_lines.append(self.new_line) + self.scene().addItem(self.new_line) elif self.type == 'in': rect = self.boundingRect() pointA = self.mapToScene(event.pos()) pointB = QtCore.QPointF(rect.x() + rect.width()/2, rect.y() + rect.height()/2) pointB = self.mapToScene(pointB) - self.newLine = NodeLine(pointA, pointB, 'in') - self.inLines.append(self.newLine) - self.scene().addItem(self.newLine) + self.new_line = NodeLine(pointA, pointB, 'in') + self.in_lines.append(self.new_line) + self.scene().addItem(self.new_line) else: super(NodeSocket, self).mousePressEvent(event) def mouseMoveEvent(self, event): + if self.type == 'op': pointB = self.mapToScene(event.pos()) - self.newLine.pointB = pointB - if self.otherLine: - self.otherLine.pointB=pointB + self.new_line.pointB = pointB + if self.other_line: + self.other_line.pointB=pointB elif self.type == 'in': pointA = self.mapToScene(event.pos()) - self.newLine.pointA = pointA - if self.otherLine: - self.otherLine.pointA=pointA + self.new_line.pointA = pointA + if self.other_line: + self.other_line.pointA=pointA else: super(NodeSocket, self).mouseMoveEvent(event) def mouseReleaseEvent(self, event): + cursor = QCursor( Qt.ArrowCursor ) + QApplication.instance().setOverrideCursor(cursor) + item = self.scene().itemAt(event.scenePos().toPoint(),QtGui.QTransform()) stm = ['MaterialStream','EngStm'] - item.otherLine=self.newLine + item.other_line=self.new_line if (self.type == 'op') and (item.type == 'in'): - self.newLine.source = self - self.newLine.target = item - item.inLines.append(self.newLine) - self.newLine.pointB = item.getCenter() - if self.newLine.source.parent.obj.type not in stm: - self.newLine.source.parent.obj.add_connection(0,self.newLine.target.parent.obj) - if self.newLine.target.parent.obj.type not in stm: - self.newLine.target.parent.obj.add_connection(1,self.newLine.source.parent.obj) # Input stream if flag is 1 + self.new_line.source = self + self.new_line.target = item + item.in_lines.append(self.new_line) + self.new_line.pointB = item.get_center() + if self.new_line.source.parent.obj.type not in stm: + self.new_line.source.parent.obj.add_connection(0,self.new_line.target.parent.obj) + if self.new_line.target.parent.obj.type not in stm: + self.new_line.target.parent.obj.add_connection(1,self.new_line.source.parent.obj) # Input stream if flag is 1 + elif (self.type =='in') and (item.type == 'op'): - self.newLine.source = item - self.newLine.target = self - item.outLines.append(self.newLine) - self.newLine.pointA = item.getCenter() - if self.newLine.source.parent.obj.type not in stm: - self.newLine.source.parent.obj.add_connection(0,self.newLine.target.parent.obj) - if self.newLine.target.parent.obj.type not in stm: - self.newLine.target.parent.obj.add_connection(1,self.newLine.source.parent.obj) + self.new_line.source = item + self.new_line.target = self + item.out_lines.append(self.new_line) + self.new_line.pointA = item.get_center() + if self.new_line.source.parent.obj.type not in stm: + self.new_line.source.parent.obj.add_connection(0,self.new_line.target.parent.obj) + if self.new_line.target.parent.obj.type not in stm: + self.new_line.target.parent.obj.add_connection(1,self.new_line.source.parent.obj) + else: - self.scene().removeItem(self.newLine) - if(self.newLine in self.inLines): - self.inLines.remove(self.newLine) - if(self.newLine in self.outLines): - self.outLines.remove(self.newLine) - del self.newLine + self.scene().removeItem(self.new_line) + if(self.new_line in self.in_lines): + self.in_lines.remove(self.new_line) + if(self.new_line in self.out_lines): + self.out_lines.remove(self.new_line) + del self.new_line super(NodeSocket, self).mouseReleaseEvent(event) try: - data = container.get_last_list('Undo') + data = Container.get_last_list('Undo') comp_selected = data[-1] data.remove(comp_selected) for i in range(len(data)): - if data[i].name == self.newLine.source.parent.obj.name: - data[i] = self.newLine.source.parent.obj - elif data[i].name == self.newLine.target.parent.obj.name: - data[i] = self.newLine.target.parent.obj + if data[i].name == self.new_line.source.parent.obj.name: + data[i] = self.new_line.source.parent.obj + elif data[i].name == self.new_line.target.parent.obj.name: + data[i] = self.new_line.target.parent.obj data.append(comp_selected) - container.PUSH('Undo', data) + Container.push('Undo', data) except Exception as e: print(e) - def getCenter(self): + def get_center(self): rect = self.boundingRect() center = QtCore.QPointF(rect.x() + rect.width()/2, rect.y() + rect.height()/2) center = self.mapToScene(center) return center + + def hoverEnterEvent(self, event): + print("in hover enter") + cursor = QCursor( Qt.CrossCursor ) + QApplication.instance().setOverrideCursor(cursor) + + def hoverLeaveEvent(self, event): + cursor = QCursor( Qt.ArrowCursor ) + QApplication.instance().setOverrideCursor(cursor) # all created node items will be put inside this list # it is used for recreating the node lines by returning the node item object based on unit operation object's name lst = [] -dockWidgetLst = [] +dock_widget_lst = [] +stack = [] class NodeItem(QtWidgets.QGraphicsItem): @staticmethod - def getInstances(namee): + def get_instances(namee): for i in lst: if i.name == namee: return i @staticmethod - def getDockWidget(): - return dockWidgetLst + def get_dock_widget(): + return dock_widget_lst - def __init__(self,unitOpr, container): - l = ['Mixer','Splitter'] + def __init__(self,unit_operation, container, graphicsView): + l = ['Splitter','Mixer', 'DistillationColumn', 'Flash', 'CompoundSeparator', 'ShortcutColumn'] stm = ['MaterialStream', 'EnergyStream'] super(NodeItem, self).__init__() - - self.obj = unitOpr + print("in node item") + self.obj = unit_operation self.container = container + self.graphicsView = graphicsView self.name = self.obj.name self.type = self.obj.type + print('Before obj.modes_list') - default_tooltip = f"{self.name}\n\n" - default_tooltip_dict = self.obj.paramgetter(self.obj.modesList[0]) - for i, j in default_tooltip_dict.items(): - if j is not None: - default_tooltip = default_tooltip + f" {i} : {j}\n" - self.setToolTip(default_tooltip) + if (self.obj.modes_list): + default_tooltip = f"{self.name}\n\n" + default_tooltip_dict = self.obj.param_getter(self.obj.modes_list[0]) + for i, j in default_tooltip_dict.items(): + if j is not None: + default_tooltip = default_tooltip + f" {i} : {j}\n" + self.setToolTip(default_tooltip) self.nin = self.obj.no_of_inputs self.nop = self.obj.no_of_outputs - - self.dockWidget = None + print('Before mixer') + if self.obj.type == 'Mixer': + text, ok = QInputDialog.getText(self.container.graphicsView, 'Mixer', 'Enter number of input:') + if ok and text: + self.nin = int(text) + self.obj.no_of_inputs = self.nin + self.obj.variables['NI']['value'] = self.nin + elif self.obj.type == 'Splitter': + text, ok = QInputDialog.getText(self.container.graphicsView, 'Splitter', 'Enter number of output:') + if ok and text: + self.nop = int(text) + self.obj.no_of_outputs = self.nop + self.obj.variables['NOO']['value'] = self.nop + + self.dock_widget = None lst.append(self) + print("before DockWidget") + if self.obj.type in l: + self.dock_widget = eval("DockWidget"+self.obj.type)(self.obj.name,self.obj.type,self.obj,self.container) + elif self.obj.type in stm: + self.dock_widget = eval("DockWidget"+self.obj.type)(self.obj.name,self.obj.type,self.obj,self.container) + else: + self.dock_widget = DockWidget(self.obj.name,self.obj.type,self.obj,self.container) + print('in dockwidget') + dock_widget_lst.append(self.dock_widget) + self.main_window= findMainWindow(self) + self.dock_widget.setFixedWidth(360) + self.dock_widget.setFixedHeight(640) + self.dock_widget.DockWidgetFeature(QDockWidget.AllDockWidgetFeatures) + self.main_window.addDockWidget(Qt.LeftDockWidgetArea, self.dock_widget) + self.dock_widget.hide() + + print("after dockwidget") - if(self.obj.type not in l): - if (self.obj.type in stm): - self.dockWidget = DockWidgetMatStm(self.obj.name,self.obj.type,self.obj,self.container) - else: - self.dockWidget = DockWidget(self.obj.name,self.obj.type,self.obj,self.container) - dockWidgetLst.append(self.dockWidget) - self.mainwindow= findMainWindow(self) - self.dockWidget.setFixedWidth(360) - self.dockWidget.setFixedHeight(640) - self.dockWidget.DockWidgetFeature(QDockWidget.AllDockWidgetFeatures) - self.mainwindow.addDockWidget(Qt.LeftDockWidgetArea, self.dockWidget) - self.dockWidget.hide() - - self.pic=QtGui.QPixmap("icons/"+self.type+".png") + self.pic=QtGui.QPixmap("Icons/"+self.type+".png") + # self.pic = QIcon("svg/Cooler.svg") self.rect = QtCore.QRect(0,0,self.pic.width(),self.pic.height()) + # self.rect = QtCore.QRect(0,0,100,100) self.text = QGraphicsTextItem(self) f = QFont() f.setPointSize(8) self.text.setFont(f) - self.text.setDefaultTextColor(QtGui.QColor(73,36,73,255)) + self.text.setDefaultTextColor(QtGui.QColor(0,70,70,220)) self.text.setParentItem(self) - self.text.setPos(-2.5, self.rect.height()-15) + self.text.setPos(self.rect.width()-(self.rect.width()*0.9), self.rect.height()) self.text.setPlainText(self.name) self.setFlag(QtWidgets.QGraphicsPixmapItem.ItemIsMovable) self.setFlag(QtWidgets.QGraphicsPixmapItem.ItemIsSelectable) - self.initUi() # Brush self.brush = QtGui.QBrush() @@ -459,13 +520,15 @@ class NodeItem(QtWidgets.QGraphicsItem): self.pen.setWidth(1) self.pen.setColor(QtGui.QColor(20,20,20,255)) - self.selPen = QtGui.QPen() - self.selPen.setStyle(QtCore.Qt.SolidLine) - self.selPen.setWidth(2) - self.selPen.setColor(QtGui.QColor(222,192,222)) + self.sel_pen = QtGui.QPen() + self.sel_pen.setStyle(QtCore.Qt.SolidLine) + self.sel_pen.setWidth(1) + self.sel_pen.setColor(QtGui.QColor(220,220,220,255)) - def initUi(self): - self.Input , self.Output = self.initializeSockets(self.type) + # initializing the node sockets + self.input , self.output = self.initialize_sockets(self.type) + + print('after ndoe item') def shape(self): path = QtGui.QPainterPath() @@ -477,57 +540,63 @@ class NodeItem(QtWidgets.QGraphicsItem): def paint(self, painter, option, widget): if self.isSelected(): - painter.setPen(self.selPen) + painter.setPen(self.sel_pen) painter.drawRect(QtCore.QRectF(self.rect)) else: painter.setPen(self.pen) painter.drawPixmap(self.rect,self.pic) - - def initializeSockets(self,type): - if(self.type=="Flash" or self.type=="CompSep"): - Input = [NodeSocket(QtCore.QRect(-2.5+5.5,(self.rect.height()*x/(self.nin+1))-8,4,4), self, 'in') for x in range(1,self.nin+1) ] - Output = [NodeSocket(QtCore.QRect(self.rect.width()-7.5,(self.rect.height()*x*0.90/(self.nop+1))-4,4,4), self, 'op') for x in range(1,self.nop+1)] - return Input,Output + # painter.drawPixmap(self.rect, self.pic.pixmap(QSize(1000,1000))) + + def initialize_sockets(self,type): + print("inside initialization") + if(self.type=="Flash" or self.type=="CompoundSeparator"): + input = [NodeSocket(QtCore.QRect(5,(self.rect.height()*x/(self.nin+1)-2),4,4), self, 'in') for x in range(1,self.nin+1) ] + output = [NodeSocket(QtCore.QRect(self.rect.width()-9,(self.rect.height()*x*1/(self.nop+1)),4,4), self, 'op') for x in range(1,self.nop+1)] + return input,output elif(self.type=="AdiabaticCompressor" or self.type=="AdiabaticExpander" or self.type =="Mixer" or self.type =="Splitter" or self.type =="Valve" ): - Input = [NodeSocket(QtCore.QRect(-3.5,(self.rect.height()*x/(self.nin+1))-6,4,4), self, 'in') for x in range(1,self.nin+1) ] - Output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,(self.rect.height()*x/(self.nop+1))-6,4,4), self, 'op') for x in range(1,self.nop+1)] - return Input,Output + input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-2,4,4), self, 'in') for x in range(1,self.nin+1) ] + output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,(self.rect.height()*x/(self.nop+1))-2,4,4), self, 'op') for x in range(1,self.nop+1)] + return input,output elif(self.type=="Cooler" or self.type=="Heater"): - Input = [NodeSocket(QtCore.QRect(3.5,(self.rect.height()*x/(self.nin+1))-4,4,4), self, 'in') for x in range(1,self.nin+1) ] - Output = [NodeSocket(QtCore.QRect(self.rect.width()-8.0,(self.rect.height()*x/(self.nop+1))-4,4,4), self, 'op') for x in range(1,self.nop+1)] - return Input,Output + input = [NodeSocket(QtCore.QRect(3.5,(self.rect.height()*x/(self.nin+1))-2,4,4), self, 'in') for x in range(1,self.nin+1) ] + output = [NodeSocket(QtCore.QRect(self.rect.width()-8.0,(self.rect.height()*x/(self.nop+1))-2,4,4), self, 'op') for x in range(1,self.nop+1)] + return input,output elif(self.type=="Pump"): - Input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-10,4,4), self, 'in') for x in range(1,self.nin+1) ] - Output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,-2.5,4,4), self, 'op') for x in range(1,self.nop+1)] - return Input,Output - elif(self.type=="DistCol" or self.type=="ShortCol"): - Input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-12,5,5), self, 'in') for x in range(1,self.nin+1) ] - Output = [NodeSocket(QtCore.QRect(self.rect.width()-5.5,(self.rect.height()*1.44*x/(self.nop+1))-67,5,5), self, 'op') for x in range(1,self.nop+1)] - return Input,Output + input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-7, 4,4), self, 'in') for x in range(1,self.nin+1) ] + output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,-1.5,4,4), self, 'op') for x in range(1,self.nop+1)] + return input,output + elif(self.type=="DistillationColumn" or self.type=="ShortcutColumn"): + input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1)),5,5), self, 'in') for x in range(1,self.nin+1) ] + output = [NodeSocket(QtCore.QRect(self.rect.width()-5.5,(self.rect.height()*1.44*x/(self.nop+1))-55,5,5), self, 'op') for x in range(1,self.nop+1)] + return input,output elif(self.type=="MaterialStream"): - Input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-1,4,4), self, 'in') for x in range(1,self.nin+1) ] - Output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,(self.rect.height()*x/(self.nin+1))-1,4,4), self, 'op') for x in range(1,self.nop+1)] - return Input,Output + input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1)-2),4,4), self, 'in') for x in range(1,self.nin+1) ] + output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,(self.rect.height()*x/(self.nin+1)-2),4,4), self, 'op') for x in range(1,self.nop+1)] + return input,output def mouseMoveEvent(self, event): super(NodeItem, self).mouseMoveEvent(event) - for output in self.Output: - for line in output.outLines: - line.pointA = line.source.getCenter() - line.pointB = line.target.getCenter() - for input in self.Input: - for line in input.inLines: - line.pointA = line.source.getCenter() - line.pointB = line.target.getCenter() + for op in self.output: + for line in op.out_lines: + line.pointA = line.source.get_center() + line.pointB = line.target.get_center() + for ip in self.input: + for line in ip.in_lines: + line.pointA = line.source.get_center() + line.pointB = line.target.get_center() self.pos = event.scenePos() - self.obj.setPos(self.pos) + self.obj.set_pos(self.pos) #print(self.name, self.pos) def mouseDoubleClickEvent(self, event): - self.setPos(event.scenePos().x()-250,event.scenePos().y()) - temp = self.obj.pos - self.dockWidget.show() - self.setPos(temp) + + self.graphicsView.setInteractive(False) + if len(stack): + print(stack) + stack[-1].hide() + self.dock_widget.show() + stack.append(self.dock_widget) + self.graphicsView.setInteractive(True) def findMainWindow(self): |