summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaurabhAgarwala2019-12-16 07:58:03 +0530
committerSaurabhAgarwala2019-12-16 07:58:03 +0530
commit68e33f34e454c6cea16db04ff7b1a73a9c670de1 (patch)
treeceb14ba6b06942e1998f6fdc0e9dd427945bd286
parentd77a48ced21b2c5f8293148379f061897c50d4f4 (diff)
downloadChemical-Simulator-GUI-68e33f34e454c6cea16db04ff7b1a73a9c670de1.tar.gz
Chemical-Simulator-GUI-68e33f34e454c6cea16db04ff7b1a73a9c670de1.tar.bz2
Chemical-Simulator-GUI-68e33f34e454c6cea16db04ff7b1a73a9c670de1.zip
Added normailizing feature, and enhanced readability
-rw-r--r--.gitignore5
-rw-r--r--OMChem/Flowsheet.py14
-rw-r--r--OMChem/MatStm.py1
-rw-r--r--component_selector.py4
-rw-r--r--container.py2
-rw-r--r--dockWidget.py23
-rw-r--r--main.ui23
-rw-r--r--mainApp.py76
-rw-r--r--resDockWidget.py3
9 files changed, 114 insertions, 37 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b0a2e7b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+OMChem/__pycache__/*
+__pycache__/*
+Simulator/Flowsheet*
+Simulator/simulateEQN.mos
+.vscode/settings.json
diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py
index 35c6d0a..cfd9bae 100644
--- a/OMChem/Flowsheet.py
+++ b/OMChem/Flowsheet.py
@@ -14,9 +14,9 @@ class Flowsheet():
self.compounds = []
self.interface = ''
self.omc_path = None
- self.curr_path = os.getcwd()
- self.sim_dir_path = os.path.join(self.curr_path, self.sim_name)
- self.Flomo_path = os.path.join(self.sim_dir_path,'Flowsheet.mo')
+ self.curr_path = os.getcwd() # Chemical-Simulator-GUI
+ self.sim_dir_path = os.path.join(self.curr_path, self.sim_name) # Chemical-Simulator-GUI/Simulator
+ self.Flomo_path = os.path.join(self.sim_dir_path,'Flowsheet.mo')
self.eqn_mos_path = os.path.join(self.sim_dir_path,'simulateEQN.mos')
self.sm_mos_path = os.path.join(self.sim_dir_path,'simulateSM.mos')
self.resdata = []
@@ -37,15 +37,15 @@ class Flowsheet():
raise
def add_UnitOpn(self,unitop,flag):
- f=(unitop,flag)
- self.UnitOpn.append(f)
+ f=(unitop,flag)
+ self.UnitOpn.append(f)
+
def remove_UnitOpn(self,unitop):
self.UnitOpn.remove(unitop)
def add_comp_list(self,comp):
self.compounds = comp
-
def send_for_simulationEqn(self):
self.resdata = []
self.omc_path = self.get_omc_path()
@@ -263,8 +263,6 @@ class Flowsheet():
self.send_for_simulationEqn()
-
-
def simulateSM(self,ip,op):
self.sim_method = 'SM'
self.data = []
diff --git a/OMChem/MatStm.py b/OMChem/MatStm.py
index 6a3d814..f27b3da 100644
--- a/OMChem/MatStm.py
+++ b/OMChem/MatStm.py
@@ -111,6 +111,7 @@ class MatStm():
def modesList(self):
return ["PT","PH","PVF","TVF","PS"]
+
def paramgetter(self,mode):
dict = {}
if(mode=="PT"):
diff --git a/component_selector.py b/component_selector.py
index 3be0f0f..03c0863 100644
--- a/component_selector.py
+++ b/component_selector.py
@@ -70,7 +70,7 @@ class componentSelector(QDialog,ui_dialog):
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
- def addCompToList(self,comp):
+ def addCompToList(self,comp): # which list?
self.item = QListWidgetItem()
self.item.setText(comp)
self.listWidget.addItem(self.item)
@@ -80,8 +80,10 @@ class componentSelector(QDialog,ui_dialog):
self.tableWidget.removeRow(self.tableWidget.currentRow())
compound_selected.remove(item)
+
def Show_Error(self):
QMessageBox.about(self, 'Important', "Selected Compound is not Available")
+
def cancel(self):
compound_selected.clear()
self.tableWidget.setRowCount(0)
diff --git a/container.py b/container.py
index 91d4833..89fb897 100644
--- a/container.py
+++ b/container.py
@@ -30,6 +30,7 @@ class Container():
def updateConn(self,key,value):
self.conn[key].append(value)
self.msg.append("<span style=\"color:blue\">["+str(self.currentTime())+"]<b> "+key.name+" </b> output is connected to input of<b> "+value.name +" </b></span>")
+
def addUnitOp(self,obj):
if(obj in self.unitOp):
pass
@@ -41,6 +42,7 @@ class Container():
for i in self.unitOp:
if(i.name==name):
return i
+
def addCompounds(self,comp):
self.compounds = comp
diff --git a/dockWidget.py b/dockWidget.py
index a4956c5..a7325e4 100644
--- a/dockWidget.py
+++ b/dockWidget.py
@@ -31,7 +31,7 @@ class dockWidget(QDockWidget,ui_dialog):
modesList = self.obj.modesList()
if(modesList):
for j in modesList:
- self.comboBox.addItem(str(j))
+ self.comboBox.addItem(str(j))
self.modeSelection()
else:
self.inputdict= {}
@@ -64,29 +64,29 @@ class dockWidget(QDockWidget,ui_dialog):
self.lines = ["Total","Partial"]
for j in self.lines:
combo.addItem(str(j))
- self.formLayout.addRow(QLabel("Condensor Type :"+":"),combo )
+ self.formLayout.addRow(QLabel("Condensor Type :"+":"),combo)
self.inputdict[i] = combo
elif(i=="CompMolFrac"):
- print("cmfnjkmnjkmnjkm")
noc = len(compound_selected)
print(noc)
self.compmolfraclist.clear()
for j in range(noc):
l = QLineEdit()
self.inputdict[i] = "compmolfrac"
- self.formLayout.addRow(QLabel(str(compound_selected[j])+" Fraction"+":"),l )
-
+ self.formLayout.addRow(QLabel(str(compound_selected[j])+":"),l )
self.compmolfraclist.append(l)
else:
- print("elseloopo")
+ print("elseloop")
l = QLineEdit()
self.formLayout.addRow(QLabel(i+":"),l )
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={}
@@ -105,13 +105,21 @@ class dockWidget(QDockWidget,ui_dialog):
break
elif(i =="CompMolFrac"):
l=[]
+ mf = []
+ total_moles = 0
for mol_frac in self.compmolfraclist:
if (mol_frac.text()):
l.append(mol_frac.text())
+ total_moles += float(l[-1])
else:
self.Show_Error()
break
- self.dict[i] = ",".join(l)
+ for c in range(len(compound_selected)):
+ mf.append(str(float(l[c])/total_moles))
+ self.compmolfraclist[c].setText(mf[-1])
+ # self.formLayout.addRow(QLabel(str(compound_selected[c])+" Mole Fraction: "+str(float(l[c])/total_moles)))
+ self.dict[i] = ",".join(mf)
+ # self.update()
else:
if (self.inputdict[i].text()):
self.dict[i] = self.inputdict[i].text()
@@ -122,6 +130,7 @@ class dockWidget(QDockWidget,ui_dialog):
self.obj.paramsetter(self.dict)
print(self.dict)
self.hide()
+
except Exception as e:
print(e)
diff --git a/main.ui b/main.ui
index 24d25d6..378d376 100644
--- a/main.ui
+++ b/main.ui
@@ -148,7 +148,7 @@
<x>0</x>
<y>0</y>
<width>1068</width>
- <height>21</height>
+ <height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -161,6 +161,8 @@
<property name="title">
<string>Edit</string>
</property>
+ <addaction name="actionUndo_2"/>
+ <addaction name="actionRedo"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
@@ -254,8 +256,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>221</width>
- <height>956</height>
+ <width>222</width>
+ <height>978</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -1182,6 +1184,21 @@
<string>save</string>
</property>
</action>
+ <action name="actionUndo">
+ <property name="text">
+ <string>Undo</string>
+ </property>
+ </action>
+ <action name="actionUndo_2">
+ <property name="text">
+ <string>Undo</string>
+ </property>
+ </action>
+ <action name="actionRedo">
+ <property name="text">
+ <string>Redo</string>
+ </property>
+ </action>
</widget>
<resources/>
<connections/>
diff --git a/mainApp.py b/mainApp.py
index 9869621..97578c8 100644
--- a/mainApp.py
+++ b/mainApp.py
@@ -13,7 +13,7 @@ from PyQt5.QtWidgets import *
from PyQt5.QtGui import QTextDocument ,QTextCursor ,QTextCharFormat ,QFont ,QPixmap
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.QtWidgets import QGraphicsProxyWidget, QGraphicsObject, QGraphicsEllipseItem ,QGraphicsPixmapItem,QApplication, QGraphicsView, QGraphicsScene, QHBoxLayout, QWidget, QLabel, QUndoStack
from PyQt5.QtGui import QBrush ,QTransform ,QMouseEvent
import PyQt5.QtGui as QtGui
import PyQt5.QtCore as QtCore
@@ -25,41 +25,58 @@ from resDockWidget import resdockWidget
from helper import helperFunc
import datetime
from container import Container
+
ui,_ = loadUiType('main.ui')
-#comp_dict is a dictionary in which keys are the type of component and value is a list [counter_of_that_particular_type ,Number of ip,Number of op]
+
+# comp_dict is a dictionary in which keys are the type of component and value is a list [counter_of_that_particular_type ,Number of ip,Number of op]
comp_dict ={'MatStm':[1,1,1],'EngStm':[1,1,1],'Mixer':[1,4,1],'Splitter':[1,1,4],'Flash':[1,1,2],'Heater':[1,1,1],'Valve':[1,1,1],'Cooler':[1,1,1],'CompSep':[1,1,2],'Pump':[1,1,1],'AdiaComp':[1,1,1],'AdiaExp':[1,1,1],'DistCol':[1,2,2],'ShortCol':[1,1,2]}
'''
MainApp class is responsible for all the main App Ui operations
'''
class MainApp(QMainWindow,ui):
+ '''
+ Initializing the application
+ '''
def __init__(self):
QMainWindow.__init__(self)
+
+ # Loading and setting up style sheet
self.setupUi(self)
style = open('light.css','r')
style = style.read()
+ self.setStyleSheet(style)
+ # Initializing attributes
self.zoomcount = 0
- self.Container = Container(self.textBrowser)
- self.setStyleSheet(style)
- self.comp =componentSelector(self)
+
+ # Creating instances of classes for the main app
+ self.Container = Container(self.textBrowser)
+ self.comp = componentSelector(self)
+
+ # Setting up interactive canvas
self.scene = QGraphicsScene()
self.scene.setItemIndexMethod(QGraphicsScene.BspTreeIndex)
self.graphicsView.setScene(self.scene)
self.graphicsView.setMouseTracking(True)
- self.comp.show()
+ self.graphicsView.keyPressEvent=self.deleteCall
self.setDockNestingEnabled(True)
self.setCorner(Qt.BottomRightCorner, Qt.RightDockWidgetArea)
self.setCorner(Qt.BottomLeftCorner, Qt.LeftDockWidgetArea)
self.addDockWidget(Qt.BottomDockWidgetArea,self.dockWidget_2)
+
+ # Setting up undo stack
+ # self.undoStack = QUndoStack(self)
+
+ # Calling initialisation functions
self.buttonHandler()
self.menuBar()
- self.graphicsView.keyPressEvent=self.deleteCall
+ self.comp.show()
'''
MenuBar function handels all the all the operations of
- menu bar like,new,zoom,comounds selector,Simulation options.
+ menu bar like new,zoom,comounds selector, simulation options.
'''
def menuBar(self):
self.actionSelect_compouns.triggered.connect(self.selectCompounds)
@@ -70,6 +87,8 @@ class MainApp(QMainWindow,ui):
self.actionHelp.triggered.connect(self.help)
self.actionSequential_mode.triggered.connect(partial(self.simulate,'SM'))
self.actionEquation_oriented.triggered.connect(partial(self.simulate,'EQN'))
+ # self.actionUndo_2.triggered.connect(self.undoStack.undo)
+ # self.actionRedo.triggered.connect(self.undoStack.redo)
'''
Handles all the buttons of different components.
@@ -115,7 +134,7 @@ class MainApp(QMainWindow,ui):
return time
'''
- Simulate function is responsible forthe simulation
+ Simulate function is responsible for the simulation
of the designed flowsheet in a particular mode
selected by the user.
'''
@@ -127,7 +146,7 @@ class MainApp(QMainWindow,ui):
self.res.show()
'''
- Resets the zoom level to default scalling
+ Resets the zoom level to default scaling
'''
def zoomReset(self):
if(self.zoomcount>0):
@@ -152,14 +171,16 @@ class MainApp(QMainWindow,ui):
self.zoomcount +=1
'''
- Instanciate a NodeItem object for selected type of
+ Instantiate a NodeItem object for selected type of
component and added that on canvas/flowsheeting area.
'''
def component(self,conntype):
if(self.comp.isCompSelected()):
- box=None
- box = NodeItem(conntype,self.Container)
- print(box)
+ # box=None
+ box = NodeItem(conntype,self.Container) # Returns the unit operation with NodeItem, NodeSocket initialized
+ # print(box)
+ # addNodeItem = AddNodeItemCommand(self,box)
+ # self.undoStack.push(addNodeItem)
self.scene.addItem(box)
box.setPos(2500-30, 2500-30)
else:
@@ -177,7 +198,7 @@ class MainApp(QMainWindow,ui):
self.comp.show()
'''
- handels all the operations which will happen when delete button is called.
+ Handels all the operations which will happen when delete button is pressed.
'''
def deleteCall(self,event):
try:
@@ -188,14 +209,17 @@ class MainApp(QMainWindow,ui):
print(e)
'''
- deletes the selected item from the canvas and also the objects
+ Deletes the selected item from the canvas and also the objects
created for that type.
'''
def delete(self,l):
+ # if isinstance(l,NodeItem):
+ # l = [l]
for item in l:
self.scene.removeItem(item)
if hasattr(item,'Input'):
for x in item.Input:
+
if x.newLine:
self.scene.removeItem(x.newLine)
@@ -227,6 +251,20 @@ class MainApp(QMainWindow,ui):
self.textBrowser.append("<span style=\"color:blue\">["+str(self.currentTime())+"]<b> "+item.obj.name+" </b>is deleted .""</span>")
del item.obj
del item
+
+# class AddNodeItemCommand(QUndoCommand):
+
+# def __init__(self,mainApp,box):
+# super(AddNodeItemCommand, self).__init__()
+# self.mainApp = mainApp
+# self.box = box
+
+# def redo(self):
+# self.mainApp.scene.addItem(self.box)
+# self.box.setPos(2500-30, 2500-30)
+
+# def undo(self):
+# self.mainApp.delete(self.box)
'''
@@ -274,6 +312,7 @@ class NodeLine(QtWidgets.QGraphicsPathItem):
ctrl2_3 = QtCore.QPointF(midptx, self.pointB.y())
path.cubicTo(ctrl1_3, ctrl2_3, self.pointB)
self.setPath(path)
+
def paint(self, painter, option, widget):
painter.setPen(self.pen)
painter.drawPath(self.path())
@@ -340,6 +379,7 @@ class NodeSocket(QtWidgets.QGraphicsItem):
self.brush = QtGui.QBrush()
self.brush.setStyle(QtCore.Qt.SolidPattern)
self.brush.setColor(QtGui.QColor(180,20,90,255))
+
# Pen.
self.pen = QtGui.QPen()
self.pen.setStyle(QtCore.Qt.SolidLine)
@@ -480,7 +520,7 @@ class NodeItem(QtWidgets.QGraphicsItem):
self.selPen.setWidth(2)
self.selPen.setColor(QtGui.QColor(222,192,222))
- def initUi(self):
+ def initUi(self): # Should be rather named as initialize sockets
self.Input , self.Output = self.initializeSockets(self.type)
def shape(self):
@@ -526,6 +566,7 @@ class NodeItem(QtWidgets.QGraphicsItem):
Input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-1,4,4), self, 'in',self.container) 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',self.container) 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:
@@ -536,6 +577,7 @@ class NodeItem(QtWidgets.QGraphicsItem):
for line in input.inLines:
line.pointA = line.source.getCenter()
line.pointB = line.target.getCenter()
+
def mouseDoubleClickEvent(self, event):
self.setPos(event.scenePos().x()-250,event.scenePos().y())
self.dockWidget.show()
diff --git a/resDockWidget.py b/resDockWidget.py
index 5575cbd..df3e271 100644
--- a/resDockWidget.py
+++ b/resDockWidget.py
@@ -81,7 +81,8 @@ class resdockWidget(QDockWidget,ui_dialog):
def resultTree(self):
self.resultsCategory(self.comboBox.currentText())
- def results(self):
+
+ def results(self): # Should be named as selecting object whose result is to be displayed
self.nameType={}
for i in self.Container.unitOp:
#nameslist.append(i.name)