summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpravindalve2021-01-02 02:58:41 +0530
committerpravindalve2021-01-02 02:58:41 +0530
commitd5804aa7215191ab059435f23955cf7e36411d43 (patch)
treec49b0b321313259fbae23b449b02a011892540b2
parent60d80b1c9f32d9e742f1622eb2ec458fe79ba765 (diff)
downloadChemical-Simulator-GUI-d5804aa7215191ab059435f23955cf7e36411d43.tar.gz
Chemical-Simulator-GUI-d5804aa7215191ab059435f23955cf7e36411d43.tar.bz2
Chemical-Simulator-GUI-d5804aa7215191ab059435f23955cf7e36411d43.zip
Added functionality for labeling the ports
-rw-r--r--DockWidgets/DockWidget.txt636
-rw-r--r--Graphics.py80
-rw-r--r--Undo.datbin0 -> 20426 bytes
-rw-r--r--UnitOperations.py10
4 files changed, 47 insertions, 679 deletions
diff --git a/DockWidgets/DockWidget.txt b/DockWidgets/DockWidget.txt
deleted file mode 100644
index b14eef8..0000000
--- a/DockWidgets/DockWidget.txt
+++ /dev/null
@@ -1,636 +0,0 @@
-from PyQt5.QtCore import *
-from PyQt5.QtWidgets import *
-from PyQt5.QtGui import *
-from PyQt5.uic import loadUiType
-import pandas as pd
-from functools import partial
-from component_selector import *
-from collections import defaultdict
-from Graphics import *
-
-ui_dialog,_ = loadUiType('DockWidget.ui')
-
-class DockWidget(QDockWidget,ui_dialog):
-
- def __init__(self,name,comptype,obj,container,parent=None):
- QDockWidget.__init__(self,parent)
- self.setupUi(self)
- self.setWindowTitle(obj.name)
- self.name=name
- self.obj=obj
- self.type = comptype
- self.inputdict = {}
- self.x_pclist = []
- self.modes()
- self.comboBox.currentIndexChanged.connect(self.modeSelection)
-
- print("constructor ", self.inputdict)
- self.pushButton_2.clicked.connect(self.param)
- self.dict = {}
-
- self.nameType = None
- self.container = container
-
- header = QTreeWidgetItem(['Compound','Value','Unit'])
- self.mTreeWidget.setHeaderItem(header)
- self.lTreeWidget.setHeaderItem(header)
- self.vTreeWidget.setHeaderItem(header)
-
- self.mTreeWidget.itemClicked.connect(lambda : self.printer(self.mTreeWidget.currentItem()))
- self.lTreeWidget.itemClicked.connect(lambda : self.printer(self.lTreeWidget.currentItem()))
- self.vTreeWidget.itemClicked.connect(lambda : self.printer(self.vTreeWidget.currentItem()))
-
- def printer(self, treeItem ):
- foldername = treeItem.text(0)
- comment = treeItem.text(1)
- data = treeItem.text(2)
- print(foldername , ': ' , comment , ' (' + data + ')')
-
- # input data tab
- def modes(self):
- modesList = self.obj.modesList
- if(modesList):
- for j in modesList:
- self.comboBox.addItem(str(self.obj.variables[j]['name']))
- self.modeSelection()
- else:
- self.comboBox.setDisabled(True)
- self.inputdict= {}
- self.inputdict = self.obj.paramgetter()
- self.inputparamslist()
-
- def modeSelection(self):
- self.inputdict= {}
- for i in reversed(range(self.formLayout.count())):
- self.formLayout.removeRow(i)
- print(self.comboBox.currentText())
- for i in self.obj.variables:
- if self.obj.variables[i]['name'] == self.comboBox.currentText():
- currentText = i
- break
- self.inputdict = self.obj.paramgetter(currentText)
- print('mode selection ', self.inputdict)
- self.inputparamslist()
-
- def inputparamslist(self):
- try:
- print("inputparamslist ", self.inputdict)
- for c,i in enumerate(self.inputdict):
- if i == None:
- continue
- if(i=="thermoPackage"):
- print("thermo1")
- combo = QComboBox()
- self.lines = [line.rstrip('\n') for line in open('thermopackage.txt')]
- print("thermo2")
- for j in self.lines:
- combo.addItem(str(j))
- combo.setMinimumContentsLength(15)
- lay = QGridLayout()
- lay.addWidget(QLabel(i+":"), 0,0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, 0, 1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(''), 0, 2, alignment = Qt.AlignCenter)
- self.formLayout.addRow(lay)
- self.inputdict[i] = combo
- print("thermo")
- elif(i=="Ctype"):
- combo = QComboBox()
- self.lines = ["Total","Partial"]
- for j in self.lines:
- combo.addItem(str(j))
- combo.setMinimumContentsLength(15)
- lay = QGridLayout()
- lay.addWidget(QLabel("Condensor Type :"), 0, 0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, 0, 1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(''), 0, 2, alignment = Qt.AlignCenter)
- self.formLayout.addRow(lay)
- self.inputdict[i] = combo
- elif(i=="x_pc"):
- noc = len(compound_selected)
- print(noc)
- self.x_pclist.clear()
- gp = QGroupBox("Compounds")
- lay = QGridLayout()
- for j in range(noc):
- l = QLineEdit()
- self.inputdict[i] = "x_pc"
- lay.addWidget(QLabel(str(compound_selected[j])+":"),j,0, alignment=Qt.AlignLeft)
- lay.addWidget(l,j,1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables[i]['unit']),j,2, alignment=Qt.AlignCenter)
- self.x_pclist.append(l)
- gp.setLayout(lay)
- self.formLayout.addRow(gp)
- elif (self.obj.type == 'Mixer' and i == 'Pout'):
- combo = QComboBox()
- print("Mixer combo")
- for j in self.obj.Pout_modes:
- combo.addItem(str(j))
- combo.setMinimumContentsLength(15)
- lay = QGridLayout()
- lay.addWidget(QLabel(self.obj.variables[i]['name']+":"), 0,0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, 0, 1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables[i]['unit']),0,2, alignment=Qt.AlignCenter)
- self.formLayout.addRow(lay)
- self.inputdict[i] = combo
- elif (self.obj.type == 'Splitter' and i == 'CalcType'):
- combo = QComboBox()
- print("Splitter combo")
- for j in self.obj.CalcType_modes:
- combo.addItem(str(j))
- combo.setMinimumContentsLength(15)
- stream1 = QLineEdit()
- stream2 = QLineEdit()
- unit = QLabel('')
- lay = QGridLayout()
- lay.addWidget(QLabel(self.obj.variables[i]['name']+":"), 0,0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, 0, 1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables[i]['unit']),0,2, alignment=Qt.AlignCenter)
-
- lay.addWidget(QLabel("Stream 1 : "), 1,0, alignment = Qt.AlignLeft)
- lay.addWidget(stream1, 1,1, alignment = Qt.AlignCenter)
- lay.addWidget(unit, 1,2, alignment = Qt.AlignRight)
-
- lay.addWidget(QLabel("Stream 2 : "), 2,0, alignment = Qt.AlignLeft)
- lay.addWidget(stream2, 2,1, alignment = Qt.AlignCenter)
- lay.addWidget(unit, 2,2, alignment = Qt.AlignRight)
- self.formLayout.addRow(lay)
- print("daf ", self.formLayout)
- #combo.currentIndexChanged.connect(lambda:self.SplitterStreams(combo, lay, unit))
- lst = [combo, stream1, stream2]
- #lst = [combo.currentText(), stream1.text(), stream2.text()]
- self.inputdict[i] = lst
- # self.inputdict[i] = stream1
- # self.inputdict[i] = stream2
- print(self.inputdict[i])
- elif i == 'HKey' or i == 'LKey':
- combo = QComboBox()
- print("ShortcutColumn combo")
- for j in self.obj.compounds:
- combo.addItem(str(j))
- combo.setMinimumContentsLength(15)
- lay = QGridLayout()
- lay.addWidget(QLabel(self.obj.variables[i]['name']+":"), 0,0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, 0, 1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables[i]['unit']),0,2, alignment=Qt.AlignCenter)
- self.formLayout.addRow(lay)
- self.inputdict[i] = combo
- elif self.obj.type == 'CompoundSeparator' and i == 'SepStrm':
- print(i)
- rlay = QHBoxLayout()
- r1 = QRadioButton('Stream 1')
- r1.setChecked(True)
- r2 = QRadioButton('Stream 2')
- r2.setChecked(False)
- rlay.addWidget(r1)
- rlay.addWidget(r2)
- self.formLayout.addRow(rlay)
-
- lst = [r1, r2]
-
- lay = QGridLayout()
- for k,val in enumerate(self.obj.compounds):
- combo = QComboBox()
- print("CompoundSeparator combo")
- for j in self.obj.SepFact_modes:
- combo.addItem(str(j))
- l = QLineEdit()
- lay.addWidget(QLabel(val+" :"), k,0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, k, 1, alignment=Qt.AlignCenter)
- lay.addWidget(l,k,2, alignment=Qt.AlignCenter)
- lst.append(combo)
- lst.append(l)
- self.inputdict[i] = lst
- self.formLayout.addRow(lay)
- elif self.obj.type == 'Flash' and i == 'Bdef':
- print(i)
- # rlay = QHBoxLayout()
- r1 = QCheckBox()
- r1.setChecked(False)
- r2 = QCheckBox()
- r2.setChecked(False)
- # rlay.addWidget(r1)
- # rlay.addWidget(r2)
- # self.formLayout.addRow(rlay)
-
- l1 = QLineEdit()
- l1.setText(str(self.obj.variables['Tdef']['value']))
- l2 = QLineEdit()
- l2.setText(str(self.obj.variables['Pdef']['value']))
- lay = QGridLayout()
- lay.addWidget(r1, 0,0, alignment = Qt.AlignLeft)
- lay.addWidget(QLabel(self.obj.variables['Tdef']['name']+":"), 0,1, alignment=Qt.AlignLeft)
- lay.addWidget(l1, 0, 2, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables['Tdef']['unit']),0,3, alignment=Qt.AlignRight)
- l1.setDisabled(True)
-
- lay.addWidget(r2, 2,0, alignment = Qt.AlignLeft)
- lay.addWidget(QLabel(self.obj.variables['Pdef']['name']+":"), 2,1, alignment=Qt.AlignLeft)
- lay.addWidget(l2, 2, 2, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables['Pdef']['unit']),2,3, alignment=Qt.AlignRight)
- self.formLayout.addRow(lay)
- l2.setDisabled(True)
- r1.toggled.connect(lambda:l1.setDisabled(not r1.isChecked()))
- r2.toggled.connect(lambda:l2.setDisabled(not r2.isChecked()))
-
- self.inputdict[i] = [r1, r2, l1, l2]
- else:
- print("elseloop")
- print(i)
- if i == None:
- continue
- l = QLineEdit()
- if self.inputdict[i] != None:
- l.setText(str(self.inputdict[i]))
- print('before lay')
- lay = QGridLayout()
- lay.addWidget(QLabel(self.obj.variables[i]['name']+":"),0,0, alignment=Qt.AlignLeft) #self.obj.variables[i]['name']
- lay.addWidget(l,0,1, alignment=Qt.AlignCenter)
- print('after lay')
- if(i != 'MolFlow'):
- lay.addWidget(QLabel(self.obj.variables[i]['unit']),0,2, alignment=Qt.AlignCenter)
- else:
- lay.addWidget(QLabel('mol/s'),0,2, alignment=Qt.AlignCenter)
- print('after all')
- self.formLayout.addRow(lay)
- self.inputdict[i] = l
-
-
- except Exception as e:
- print(e)
-
- def Show_Error(self):
- QMessageBox.about(self, 'Important', "Please fill all fields with data")
-
- def param(self):
- try:
- self.dict={}
- print("param.inputdict ", self.inputdict)
- for i in self.inputdict:
- if (self.inputdict[i] == None):
- continue
-
- if(i=="thermoPackage"):
- if (self.inputdict[i].currentText()):
- self.dict[i] = self.inputdict[i].currentText()
- else:
- self.Show_Error()
- break
- elif(i=="Ctype"):
- if (self.inputdict[i].currentText()):
- self.dict[i] = self.inputdict[i].currentText()
- else:
- self.Show_Error()
- break
- elif(i =="x_pc"):
- l=[]
- mf = []
- total_moles = 0
- for mol_frac in self.x_pclist:
- if (mol_frac.text()):
- l.append(mol_frac.text())
- total_moles += float(l[-1])
- else:
- self.Show_Error()
- break
- for c in range(len(compound_selected)):
- mf.append(str(float(l[c])/total_moles))
- self.x_pclist[c].setText(mf[-1])
- self.dict[i] = ",".join(mf)
- elif(i == 'Pout' and self.obj.type == 'Mixer' or i == '' or i == 'HKey' or i == 'LKey'):
- self.dict[i] = self.inputdict[i].currentText()
- elif i == 'CalcType' and self.obj.type == 'Splitter':
- self.dict[i] = [self.inputdict[i][0].currentText(), self.inputdict[i][1].text(), self.inputdict[i][2].text()]
- elif self.obj.type == 'Flash' and i == 'Bdef':
- self.dict[i] = [self.inputdict[i][0].isChecked(), self.inputdict[i][1].isChecked(), self.inputdict[i][2].text(), self.inputdict[i][3].text()]
- elif self.obj.type == 'CompoundSeparator':
- self.dict[i] = [self.inputdict[i][0].isChecked(),self.inputdict[i][1].isChecked()]
- j = 2
- for comp in self.obj.compounds:
- self.dict[i].append(self.inputdict[i][j].currentText())
- self.dict[i].append(self.inputdict[i][j+1].text())
- j += 2
- else:
- print(self.inputdict[i], i, self.obj.type)
- if (self.inputdict[i].text()):
- self.dict[i] = self.inputdict[i].text()
- else:
- print(self.inputdict[i].text())
- self.Show_Error()
- break
-
- print("param ", self.dict)
- self.obj.paramsetter(self.dict)
- self.hide()
-
- except Exception as e:
- print(e)
-
-
- @staticmethod
- def showResult(lst):
- #DockWidget1.flag = True
- for i in lst:
- i.resultsCategory(i.name)
- #i.show()
-
- # result data tab
- def resultsCategory(self,name):
- flag = True
- try:
- print("Under result category name ", name)
- result=self.container.result
- obj = self.container.fetchObject(name)
-
- d = {"Mole Fraction":"x_pc", "Mass Fraction":"xm_pc", "Mole Flow":"F_pc", "Mass Flow":"Fm_pc"}
- lst = list(d.keys())
- klst = list(d.values())
-
- p = {"Pressure":"P", "Temperature":"T","Vapour Phase Mole Fraction":"xvap", "Phase Molar Enthalpy":"H_p",
- "Phase Molar Entropy":"S_p", "Molar Flow Rate":"F_p"}
-
- # Amounts Tab
- if obj.type == 'MaterialStream':
- l = [] # list for basis names
- for basis in d:
- propertyname = name + '.' + d[basis]
- print("basis ", basis, propertyname)
- for i in result[0]:
- if (propertyname in i):
- l.append(i)
- print(l)
-
- j = 0
- t = 0
- namee = klst[j]
- print("namee ", namee)
-
- for i,k in enumerate(l):
- ind = result[0].index(k)
- print("index ", ind)
- print("str ", k)
- resultval = str(result[-1][ind])
- print("######Resultsfetch####",resultval)
- print(k[k.find(".")+1:k.find("[")])
- obj.variables[k.split('.')[1]]['value'] = resultval
- if namee in k:
- if i%3 == 0:
- if(flag):
- mroot = QTreeWidgetItem(self.mTreeWidget, [lst[j]])
- child = QTreeWidgetItem(mroot, [compound_selected[t], str(resultval),obj.variables[k.split('.')[1]]['unit']])
- elif i%3 == 1:
- if(flag):
- lroot = QTreeWidgetItem(self.lTreeWidget, [lst[j]])
- child = QTreeWidgetItem(lroot, [compound_selected[t], str(resultval),obj.variables[k.split('.')[1]]['unit']])
- elif i%3 == 2:
- if (flag):
- vroot = QTreeWidgetItem(self.vTreeWidget, [lst[j]])
- child = QTreeWidgetItem(vroot, [compound_selected[t], str(resultval),obj.variables[k.split('.')[1]]['unit']])
- t += 1
- flag = False
- else:
- j += 1
- t = 0
- namee = klst[j]
- flag = True
- if i%3 == 0:
- if (flag):
- mroot = QTreeWidgetItem(self.mTreeWidget, [lst[j]])
- child = QTreeWidgetItem(mroot, [compound_selected[t], str(resultval),obj.variables[k.split('.')[1]]['unit']])
- elif i%3 == 1:
- if (flag):
- lroot = QTreeWidgetItem(self.lTreeWidget, [lst[j]])
- child = QTreeWidgetItem(lroot, [compound_selected[t], str(resultval),obj.variables[k.split('.')[1]]['unit']])
- elif i%3 == 2:
- if (flag):
- vroot = QTreeWidgetItem(self.vTreeWidget, [lst[j]])
- child = QTreeWidgetItem(vroot, [compound_selected[t], str(resultval),obj.variables[k.split('.')[1]]['unit']])
- t += 1
- flag = False
- #print(obj.variables)
-
- # Phase Properties Tab
- phaseResLst = []
- for phase in p:
- propertyname = name + '.' + p[phase]
- print("phase ", phase, propertyname)
- for i in result[0]:
- if i.find('['):
- if (propertyname == i[0:i.find('[')]):
- phaseResLst.append(i)
- if propertyname == i:
- phaseResLst.append(i)
- print(phaseResLst)
-
- self.mTableWidget.setRowCount(0)
- self.lTableWidget.setRowCount(0)
- self.vTableWidget.setRowCount(0)
-
- for i,val in enumerate(phaseResLst):
- ind = result[0].index(val)
- resultval = str(result[-1][ind])
- print(resultval, i, val)
- obj.variables[val.split('.')[1]]['value'] = resultval
- if '[' in val:
- print(val)
- temp = val[val.find('.')+1:val.find('[')]
- print(temp)
- if '1' in val.split('.')[1]:
- print(obj.variables[val.split('.')[1]]['name'])
- mrowPosition = self.mTableWidget.rowCount()
- self.mTableWidget.insertRow(mrowPosition)
- self.mTableWidget.setItem(mrowPosition , 0, QTableWidgetItem(obj.variables[val.split('.')[1]]['name']))
- self.mTableWidget.setItem(mrowPosition , 1, QTableWidgetItem(resultval))
- self.mTableWidget.setItem(mrowPosition , 2, QTableWidgetItem(obj.variables[val.split('.')[1]]['unit']))
- self.mTableWidget.resizeColumnsToContents()
-
- if '2' in val.split('.')[1]:
- lrowPosition = self.lTableWidget.rowCount()
- self.lTableWidget.insertRow(lrowPosition)
- self.lTableWidget.setItem(lrowPosition , 0, QTableWidgetItem(obj.variables[val.split('.')[1]]['name']))
- self.lTableWidget.setItem(lrowPosition , 1, QTableWidgetItem(resultval))
- self.lTableWidget.setItem(lrowPosition , 2, QTableWidgetItem(obj.variables[val.split('.')[1]]['unit']))
- self.lTableWidget.resizeColumnsToContents()
- if '3' in val.split('.')[1]:
- vrowPosition = self.vTableWidget.rowCount()
- self.vTableWidget.insertRow(vrowPosition)
- self.vTableWidget.setItem(vrowPosition , 0, QTableWidgetItem(obj.variables[val.split('.')[1]]['name']))
- self.vTableWidget.setItem(vrowPosition , 1, QTableWidgetItem(resultval))
- self.vTableWidget.setItem(vrowPosition , 2, QTableWidgetItem(obj.variables[val.split('.')[1]]['unit']))
- self.vTableWidget.resizeColumnsToContents()
- if not '[' in val:
- #print(p[val.split('.')[1]])
- print(obj.variables[val.split('.')[1]]['name'])
- mrowPosition = self.mTableWidget.rowCount()
- self.mTableWidget.insertRow(mrowPosition)
- self.mTableWidget.setItem(mrowPosition , 0, QTableWidgetItem(obj.variables[val.split('.')[1]]['name']))
- self.mTableWidget.setItem(mrowPosition , 1, QTableWidgetItem(resultval))
- self.mTableWidget.setItem(mrowPosition , 2, QTableWidgetItem(obj.variables[val.split('.')[1]]['unit']))
- self.mTableWidget.resizeColumnsToContents()
-
- print(obj.variables)
-
- except Exception as e:
- print(e)
-
-
-class DockWidgetFlash(DockWidget):
-
- def __init__(self,name,comptype,obj,container,parent=None):
- DockWidget.__init__(self,name,comptype,obj,container,parent=None)
-
- def inputparamslist(self):
- try:
- print("inputparamslist ", self.inputdict)
- for c,i in enumerate(self.inputdict):
- if i == None:
- continue
- if(i=="thermoPackage"):
- print("thermo1")
- combo = QComboBox()
- self.lines = [line.rstrip('\n') for line in open('thermopackage.txt')]
- print("thermo2")
- for j in self.lines:
- combo.addItem(str(j))
- combo.setMinimumContentsLength(15)
- lay = QGridLayout()
- lay.addWidget(QLabel(i+":"), 0,0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, 0, 1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(''), 0, 2, alignment = Qt.AlignCenter)
- self.formLayout.addRow(lay)
- self.inputdict[i] = combo
- print("thermo")
- elif self.obj.type == 'Flash' and i == 'Bdef':
- print(i)
- r1 = QCheckBox()
- r1.setChecked(False)
- r2 = QCheckBox()
- r2.setChecked(False)
-
- l1 = QLineEdit()
- l1.setText(str(self.obj.variables['Tdef']['value']))
- l2 = QLineEdit()
- l2.setText(str(self.obj.variables['Pdef']['value']))
- lay = QGridLayout()
- lay.addWidget(r1, 0,0, alignment = Qt.AlignLeft)
- lay.addWidget(QLabel(self.obj.variables['Tdef']['name']+":"), 0,1, alignment=Qt.AlignLeft)
- lay.addWidget(l1, 0, 2, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables['Tdef']['unit']),0,3, alignment=Qt.AlignRight)
- l1.setDisabled(True)
-
- lay.addWidget(r2, 2,0, alignment = Qt.AlignLeft)
- lay.addWidget(QLabel(self.obj.variables['Pdef']['name']+":"), 2,1, alignment=Qt.AlignLeft)
- lay.addWidget(l2, 2, 2, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables['Pdef']['unit']),2,3, alignment=Qt.AlignRight)
- self.formLayout.addRow(lay)
- l2.setDisabled(True)
- r1.toggled.connect(lambda:l1.setDisabled(not r1.isChecked()))
- r2.toggled.connect(lambda:l2.setDisabled(not r2.isChecked()))
-
- self.inputdict[i] = [r1, r2, l1, l2]
- except Exception as e:
- print(e)
-
- def param(self):
- try:
- self.dict={}
- print("param.inputdict ", self.inputdict)
- for i in self.inputdict:
- if (self.inputdict[i] == None):
- continue
-
- if(i=="thermoPackage"):
- if (self.inputdict[i].currentText()):
- self.dict[i] = self.inputdict[i].currentText()
- else:
- self.Show_Error()
- break
- elif self.obj.type == 'Flash' and i == 'Bdef':
- self.dict[i] = [self.inputdict[i][0].isChecked(), self.inputdict[i][1].isChecked(), self.inputdict[i][2].text(), self.inputdict[i][3].text()]
-
- print("param ", self.dict)
- self.obj.paramsetter(self.dict)
- self.hide()
-
- except Exception as e:
- print(e)
-
-class DockWidgetFlash(DockWidget):
-
- def __init__(self,name,comptype,obj,container,parent=None):
- DockWidget.__init__(self,name,comptype,obj,container,parent=None)
-
- def inputparamslist(self):
- try:
- print("inputparamslist ", self.inputdict)
- for c,i in enumerate(self.inputdict):
- if i == None:
- continue
- if(i=="thermoPackage"):
- print("thermo1")
- combo = QComboBox()
- self.lines = [line.rstrip('\n') for line in open('thermopackage.txt')]
- print("thermo2")
- for j in self.lines:
- combo.addItem(str(j))
- combo.setMinimumContentsLength(15)
- lay = QGridLayout()
- lay.addWidget(QLabel(i+":"), 0,0, alignment=Qt.AlignLeft)
- lay.addWidget(combo, 0, 1, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(''), 0, 2, alignment = Qt.AlignCenter)
- self.formLayout.addRow(lay)
- self.inputdict[i] = combo
- print("thermo")
- elif self.obj.type == 'Flash' and i == 'Bdef':
- print(i)
- r1 = QCheckBox()
- r1.setChecked(False)
- r2 = QCheckBox()
- r2.setChecked(False)
-
- l1 = QLineEdit()
- l1.setText(str(self.obj.variables['Tdef']['value']))
- l2 = QLineEdit()
- l2.setText(str(self.obj.variables['Pdef']['value']))
- lay = QGridLayout()
- lay.addWidget(r1, 0,0, alignment = Qt.AlignLeft)
- lay.addWidget(QLabel(self.obj.variables['Tdef']['name']+":"), 0,1, alignment=Qt.AlignLeft)
- lay.addWidget(l1, 0, 2, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables['Tdef']['unit']),0,3, alignment=Qt.AlignRight)
- l1.setDisabled(True)
-
- lay.addWidget(r2, 2,0, alignment = Qt.AlignLeft)
- lay.addWidget(QLabel(self.obj.variables['Pdef']['name']+":"), 2,1, alignment=Qt.AlignLeft)
- lay.addWidget(l2, 2, 2, alignment=Qt.AlignCenter)
- lay.addWidget(QLabel(self.obj.variables['Pdef']['unit']),2,3, alignment=Qt.AlignRight)
- self.formLayout.addRow(lay)
- l2.setDisabled(True)
- r1.toggled.connect(lambda:l1.setDisabled(not r1.isChecked()))
- r2.toggled.connect(lambda:l2.setDisabled(not r2.isChecked()))
-
- self.inputdict[i] = [r1, r2, l1, l2]
- except Exception as e:
- print(e)
-
- def param(self):
- try:
- self.dict={}
- print("param.inputdict ", self.inputdict)
- for i in self.inputdict:
- if (self.inputdict[i] == None):
- continue
-
- if(i=="thermoPackage"):
- if (self.inputdict[i].currentText()):
- self.dict[i] = self.inputdict[i].currentText()
- else:
- self.Show_Error()
- break
- elif self.obj.type == 'Flash' and i == 'Bdef':
- self.dict[i] = [self.inputdict[i][0].isChecked(), self.inputdict[i][1].isChecked(), self.inputdict[i][2].text(), self.inputdict[i][3].text()]
-
- print("param ", self.dict)
- self.obj.paramsetter(self.dict)
- self.hide()
-
- except Exception as e:
- print(e) \ No newline at end of file
diff --git a/Graphics.py b/Graphics.py
index da1954c..71d5b71 100644
--- a/Graphics.py
+++ b/Graphics.py
@@ -14,7 +14,6 @@ from DockWidgets.DockWidgetSplitter import *
from DockWidgets.DockWidgetFlash import *
from DockWidgets.DockWidgetCompoundSeparator import *
from DockWidgets.DockWidgetCompressorExpander import *
-
from Container import *
from Streams import *
from UnitOperations import *
@@ -55,41 +54,41 @@ class Graphics(QDialog, QtWidgets.QGraphicsItem):
elif i.type not in stm:
ip = i.input_stms
op = i.output_stms
- for j in ip:
- ip_index = ip.index(j)
- pointA = NodeItem.get_instances(j.name)
+ for k, v in ip.items():
+ pointA = NodeItem.get_instances(v.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[ip_index].boundingRect()
+ socketB = next((s for s in pointB.input if k == s.id))
+ rectB = socketB.boundingRect()
pointBB = QtCore.QPointF(rectB.x() + rectB.width()/2, rectB.y() + rectB.height()/2)
- pointBB = pointB.input[ip_index].mapToScene(pointBB)
+ pointBB = socketB.mapToScene(pointBB)
self.new_line = NodeLine(pointAA, pointBB, 'in')
self.new_line.source = pointA.output[0]
- self.new_line.target = pointB.input[0]
+ self.new_line.target = socketB
pointA.output[0].out_lines.append(self.new_line)
- pointB.input[ip_index].in_lines.append(self.new_line)
+ socketB.in_lines.append(self.new_line)
pointA.output[0].other_line = self.new_line
- pointB.input[ip_index].other_line = self.new_line
+ socketB.other_line = self.new_line
self.scene.addItem(self.new_line)
self.new_line.updatePath()
- for k in op:
- op_index = op.index(k)
+ for k, v in op.items():
pointA = NodeItem.get_instances(i.name)
- pointB = NodeItem.get_instances(k.name)
- rect = pointA.output[op_index].boundingRect()
+ pointB = NodeItem.get_instances(v.name)
+ socketA = next(s for s in pointA.output if k == s.id)
+ rect = socketA.boundingRect()
pointAA = QtCore.QPointF(rect.x() + rect.width()/2, rect.y() + rect.height()/2)
- pointAA = pointA.output[op_index].mapToScene(pointAA)
+ pointAA = socketA.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)
self.new_line = NodeLine(pointAA, pointBB, 'out')
- self.new_line.source = pointA.output[op.index(k)]
+ self.new_line.source = socketA
self.new_line.target = pointB.input[0]
- pointA.output[op_index].out_lines.append(self.new_line)
+ socketA.out_lines.append(self.new_line)
pointB.input[0].in_lines.append(self.new_line)
- pointA.output[op_index].other_line = self.new_line
+ socketA.other_line = self.new_line
pointB.input[0].other_line = self.new_line
self.scene.addItem(self.new_line)
self.new_line.updatePath()
@@ -245,11 +244,12 @@ class NodeLine(QtWidgets.QGraphicsPathItem):
del self._pointB
class NodeSocket(QtWidgets.QGraphicsItem):
- def __init__(self, rect, parent, socketType):
+ def __init__(self, rect, parent, socketType, id):
super(NodeSocket, self).__init__(parent)
self.rect = rect
self.type = socketType
self.parent=parent
+ self.id = id
self.setAcceptHoverEvents(True)
self.new_line=None
self.other_line=None
@@ -330,20 +330,22 @@ class NodeSocket(QtWidgets.QGraphicsItem):
self.new_line.target = item
item.in_lines.append(self.new_line)
self.new_line.pointB = item.get_center()
+ print(type(self.new_line.source))
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)
+ self.new_line.source.parent.obj.add_connection(0, self.new_line.source.id, 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
+ self.new_line.target.parent.obj.add_connection(1, self.new_line.target.id, self.new_line.source.parent.obj) # Input stream if flag is 1
elif (self.type =='in') and (item.type == 'op'):
self.new_line.source = item
self.new_line.target = self
item.out_lines.append(self.new_line)
self.new_line.pointA = item.get_center()
+ print(type(self.new_line.source))
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)
+ self.new_line.source.parent.obj.add_connection(0, self.new_line.source.id, 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)
+ self.new_line.target.parent.obj.add_connection(1, self.new_line.target.id, self.new_line.source.parent.obj)
else:
@@ -356,7 +358,7 @@ class NodeSocket(QtWidgets.QGraphicsItem):
super(NodeSocket, self).mouseReleaseEvent(event)
try:
- data = Container.get_last_list('Undo')
+ data = get_last_list('Undo')
comp_selected = data[-1]
data.remove(comp_selected)
for i in range(len(data)):
@@ -365,7 +367,7 @@ class NodeSocket(QtWidgets.QGraphicsItem):
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)
+ push('Undo', data)
except Exception as e:
print(e)
@@ -420,8 +422,7 @@ class NodeItem(QtWidgets.QGraphicsItem):
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
+
if self.obj.type == 'Mixer' and not self.obj.saved:
text, ok = QInputDialog.getText(self.container.graphicsView, 'Mixer', 'Enter number of input:')
if ok and text:
@@ -441,6 +442,9 @@ class NodeItem(QtWidgets.QGraphicsItem):
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:
@@ -519,28 +523,28 @@ class NodeItem(QtWidgets.QGraphicsItem):
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') 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)]
+ 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') 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)]
+ 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') 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)]
+ 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=="Pump"):
- 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)]
+ 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') 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)]
+ 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') 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)]
+ 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):
diff --git a/Undo.dat b/Undo.dat
index e69de29..6c9d56f 100644
--- a/Undo.dat
+++ b/Undo.dat
Binary files differ
diff --git a/UnitOperations.py b/UnitOperations.py
index 8a3f8db..ed2864c 100644
--- a/UnitOperations.py
+++ b/UnitOperations.py
@@ -9,8 +9,8 @@ class UnitOperation():
def __init__(self):
self.OM_data_eqn = ''
self.OM_data_init = ''
- self.input_stms = []
- self.output_stms = []
+ self.input_stms = {}
+ self.output_stms = {}
self.compounds = [c[:c.index('(')] for c in compound_selected]
self.name = ''
self.mode = None
@@ -56,11 +56,11 @@ class UnitOperation():
self.variables[k]['value'] = v
self.mode_val = params[self.mode]
- def add_connection(self,flag,UnitOpr):
+ def add_connection(self,flag,sourceId, UnitOpr):
if flag==1: # Input stream if flag is 1
- self.input_stms.append(UnitOpr)
+ self.input_stms[sourceId] = UnitOpr
else :
- self.output_stms.append(UnitOpr)
+ self.output_stms[sourceId] = UnitOpr
def set_pos(self,pos):
self.pos = pos