def __init__(self, unit_operation, container, graphicsView): l = [ 'Splitter', 'Mixer', 'DistillationColumn', 'Flash', 'CompoundSeparator', 'ShortcutColumn' ] stm = ['MaterialStream', 'EnergyStream'] super(NodeItem, self).__init__() self.obj = unit_operation self.container = container self.graphicsView = graphicsView self.name = self.obj.name self.type = self.obj.type if (self.obj.modes_list): default_tooltip = f"{self.name}\n\n" default_tooltip_dict = self.obj.param_getter(self.obj.mode) 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.type == 'Mixer' and not self.obj.saved: text, ok = QInputDialog.getText(self.container.graphicsView, 'Mixer', 'Enter number of input:', echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs)) 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' and not self.obj.saved: # 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['No']['value'] = self.nop elif self.obj.type == 'DistillationColumn' and not self.obj.saved: text, ok = QInputDialog.getText(self.container.graphicsView, 'DistillationColumn', 'Enter number of input:', echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs)) if ok and text: self.nin = int(text) self.obj.no_of_inputs = self.nin self.obj.variables['Ni']['value'] = self.nin self.nin = self.obj.no_of_inputs self.nop = self.obj.no_of_outputs self.dock_widget = None lst.append(self) 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) elif self.obj.type == "AdiabaticCompressor" or self.obj.type == "AdiabaticExpander": self.dock_widget = eval("DockWidgetCompressorExpander")( 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) 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) # updating input values if self.dock_widget.obj.type != 'MaterialStream': print(self.dock_widget.obj.type) try: self.dock_widget.obj.param_setter( self.dock_widget.obj.param_getter( self.dock_widget.obj.mode)) except Exception as e: print(e) # self.dock_widget.param() self.dock_widget.hide() self.pic = QtGui.QPixmap("Icons/" + self.type + ".png") self.rect = QtCore.QRect(0, 0, self.pic.width(), self.pic.height()) self.text = QGraphicsTextItem(self) f = QFont() f.setPointSize(8) self.text.setFont(f) self.text.setDefaultTextColor(QtGui.QColor(0, 70, 70, 220)) self.text.setParentItem(self) 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) # Brush self.brush = QtGui.QBrush() self.brush.setStyle(QtCore.Qt.SolidPattern) self.brush.setColor(QtGui.QColor(80, 0, 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.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)) # initializing the node sockets self.input, self.output = self.initialize_sockets(self.type)
class NodeItem(QtWidgets.QGraphicsItem): @staticmethod def get_instances(namee): for i in lst: if i.name == namee: return i @staticmethod def get_dock_widget(): return dock_widget_lst def __init__(self, unit_operation, container, graphicsView): l = [ 'Splitter', 'Mixer', 'DistillationColumn', 'Flash', 'CompoundSeparator', 'ShortcutColumn' ] stm = ['MaterialStream', 'EnergyStream'] super(NodeItem, self).__init__() self.obj = unit_operation self.container = container self.graphicsView = graphicsView self.name = self.obj.name self.type = self.obj.type if (self.obj.modes_list): default_tooltip = f"{self.name}\n\n" default_tooltip_dict = self.obj.param_getter(self.obj.mode) 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.type == 'Mixer' and not self.obj.saved: text, ok = QInputDialog.getText(self.container.graphicsView, 'Mixer', 'Enter number of input:', echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs)) 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' and not self.obj.saved: # 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['No']['value'] = self.nop elif self.obj.type == 'DistillationColumn' and not self.obj.saved: text, ok = QInputDialog.getText(self.container.graphicsView, 'DistillationColumn', 'Enter number of input:', echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs)) if ok and text: self.nin = int(text) self.obj.no_of_inputs = self.nin self.obj.variables['Ni']['value'] = self.nin self.nin = self.obj.no_of_inputs self.nop = self.obj.no_of_outputs self.dock_widget = None lst.append(self) 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) elif self.obj.type == "AdiabaticCompressor" or self.obj.type == "AdiabaticExpander": self.dock_widget = eval("DockWidgetCompressorExpander")( 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) 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) # updating input values if self.dock_widget.obj.type != 'MaterialStream': print(self.dock_widget.obj.type) try: self.dock_widget.obj.param_setter( self.dock_widget.obj.param_getter( self.dock_widget.obj.mode)) except Exception as e: print(e) # self.dock_widget.param() self.dock_widget.hide() self.pic = QtGui.QPixmap("Icons/" + self.type + ".png") self.rect = QtCore.QRect(0, 0, self.pic.width(), self.pic.height()) self.text = QGraphicsTextItem(self) f = QFont() f.setPointSize(8) self.text.setFont(f) self.text.setDefaultTextColor(QtGui.QColor(0, 70, 70, 220)) self.text.setParentItem(self) 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) # Brush self.brush = QtGui.QBrush() self.brush.setStyle(QtCore.Qt.SolidPattern) self.brush.setColor(QtGui.QColor(80, 0, 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.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)) # initializing the node sockets self.input, self.output = self.initialize_sockets(self.type) def shape(self): path = QtGui.QPainterPath() path.addRect(self.boundingRect()) return path def boundingRect(self): return QtCore.QRectF(self.rect) def paint(self, painter, option, widget): if self.isSelected(): painter.setPen(self.sel_pen) painter.drawRect(QtCore.QRectF(self.rect)) else: painter.setPen(self.pen) painter.drawPixmap(self.rect, self.pic) def initialize_sockets(self, type): 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', x) 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', x) 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(-2.5, (self.rect.height() * x / (self.nin + 1)) - 2, 4, 4), self, 'in', x) 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', x) 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)) - 2, 4, 4), self, 'in', x) 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', x) for x in range(1, self.nop + 1) ] return input, output elif (self.type == "CentrifugalPump"): input = [ NodeSocket( QtCore.QRect(-2.5, (self.rect.height() * x / (self.nin + 1)) - 7, 4, 4), self, 'in', x) for x in range(1, self.nin + 1) ] output = [ NodeSocket(QtCore.QRect(self.rect.width() - 2.5, -1.5, 4, 4), self, 'op', x) 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', x) 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', x) 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) - 2), 4, 4), self, 'in', x) 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', x) for x in range(1, self.nop + 1) ] return input, output def mouseMoveEvent(self, event): super(NodeItem, self).mouseMoveEvent(event) 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.set_pos(self.pos) def mouseDoubleClickEvent(self, event): self.graphicsView.setInteractive(False) if len(stack): stack[-1].hide() self.dock_widget.show() stack.append(self.dock_widget) self.graphicsView.setInteractive(True) def update_tooltip(self): 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)