From 5cc855cd9a145012382031a5a1e731e297632107 Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Mon, 23 Dec 2019 17:36:31 +0530 Subject: Terminate function UI created and flowsheet made attribute of class --- container.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'container.py') diff --git a/container.py b/container.py index 89fb897..4211ed9 100644 --- a/container.py +++ b/container.py @@ -13,6 +13,7 @@ class Container(): self.unitOp = [] self.thermoPackage = None self.compounds = None + self.flowsheet = None self.conn = defaultdict(list) self.op=defaultdict(list) self.ip=defaultdict(list) @@ -71,14 +72,14 @@ class Container(): except Exception as e: print(e) - def msgBrowser(self,f): - std = f.stdout.decode("utf-8") + def msgBrowser(self): + std = self.flowsheet.stdout.decode("utf-8") if(std): stdout = str(std) stdout = stdout.replace("\n","
") self.msg.append(""+stdout+"") - stde = f.stderr.decode("utf-8") + stde = self.flowsheet.stderr.decode("utf-8") if(stde): stdout = str(stde) stdout = stdout.replace("\n","
") @@ -88,26 +89,26 @@ class Container(): print(mode) self.compounds = compound_selected self.connection() - f = Flowsheet() - f.add_comp_list(self.compounds) + self.flowsheet = Flowsheet() + self.flowsheet.add_comp_list(self.compounds) print("######## connection master#########\n",self.conn) for i in self.unitOp : if i in self.opl: print("here",i) - f.add_UnitOpn(i,1) + self.flowsheet.add_UnitOpn(i,1) else: - f.add_UnitOpn(i,0) + self.flowsheet.add_UnitOpn(i,0) if mode=='SM': self.msg.append("["+str(self.currentTime())+"] Simulating in Sequential mode ... ") - f.simulateSM(self.ip,self.op) - self.msgBrowser(f) - self.result=f.resdata + self.flowsheet.simulateSM(self.ip,self.op) + self.msgBrowser() + self.result=self.flowsheet.resdata print("under SEQ mode simulation") elif mode=='EQN': self.msg.append("["+str(self.currentTime())+"] Simulating in equation mode ... ") - f.simulateEQN() - self.msgBrowser(f) - self.result=f.resdata + self.flowsheet.simulateEQN() + self.msgBrowser() + self.result=self.flowsheet.resdata print("under Eqn mode simulation") def flatlist(lst): -- cgit From 7df9dbb0e57f2eeb03ab7fbf7de0b9f4cd658048 Mon Sep 17 00:00:00 2001 From: Ayush Agrawal Date: Tue, 24 Dec 2019 16:27:14 +0530 Subject: Restructured the API, and the front-end --- container.py | 76 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 24 deletions(-) (limited to 'container.py') diff --git a/container.py b/container.py index 89fb897..dd3cf89 100644 --- a/container.py +++ b/container.py @@ -5,9 +5,22 @@ from OMChem.Heater import Heater from component_selector import * from collections import defaultdict from PyQt5.QtCore import * +from PyQt5.QtWidgets import * from PyQt5.QtGui import * +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 +import PyQt5.QtCore as QtCore +import PyQt5.QtWidgets as QtWidgets +from dockWidget import dockWidget import datetime import itertools +import json +import pickle +import os +import sys + class Container(): def __init__(self,msgbrowser): self.unitOp = [] @@ -20,35 +33,20 @@ class Container(): self.msg.setText("") self.opl=[] self.result=[] + def currentTime(self): now = datetime.datetime.now() time = str(now.hour) + ":" + str(now.minute) + ":" +str(now.second) return time + + def updateConn(self,key,value): self.conn[key].append(value) self.msg.append("["+str(self.currentTime())+"] "+key.name+" output is connected to input of "+value.name +" ") - - def addUnitOp(self,obj): - if(obj in self.unitOp): - pass - else: - self.unitOp.append(obj) - self.msg.append("["+str(self.currentTime())+"] "+obj.name+" is instantiated .""") - - def fetchObject(self,name): - for i in self.unitOp: - if(i.name==name): - return i - - def addCompounds(self,comp): - self.compounds = comp - - def add_thermoPackage(self,thermo): - self.thermoPackage = thermo - + def connection(self): try: self.op.clear() @@ -71,6 +69,36 @@ class Container(): except Exception as e: print(e) + + def addUnitOp(self,obj,scene,graphics): + box = None + self.obj = obj + self.scene = scene + self.graphics = graphics + box = self.graphics.createNodeItem(self.obj) + self.scene.addItem(box) + box.setPos(2500-30, 2500-30) + + + if(obj in self.unitOp): + pass + else: + self.unitOp.append(obj) + + self.msg.append("["+str(self.currentTime())+"] "+obj.name+" is instantiated .""") + + def fetchObject(self,name): + for i in self.unitOp: + if(i.name==name): + return i + def addCompounds(self,comp): + self.compounds = comp + + def add_thermoPackage(self,thermo): + self.thermoPackage = thermo + + + def msgBrowser(self,f): std = f.stdout.decode("utf-8") if(std): @@ -85,18 +113,18 @@ class Container(): self.msg.append(""+stdout+"") def simulate(self,mode): + print("SIMULATE") print(mode) self.compounds = compound_selected - self.connection() + #self.connection() f = Flowsheet() f.add_comp_list(self.compounds) print("######## connection master#########\n",self.conn) for i in self.unitOp : - if i in self.opl: print("here",i) - f.add_UnitOpn(i,1) - else: - f.add_UnitOpn(i,0) + f.add_UnitOpn(i) + + if mode=='SM': self.msg.append("["+str(self.currentTime())+"] Simulating in Sequential mode ... ") f.simulateSM(self.ip,self.op) -- cgit From c350054473ffb5bd7275f2ed939ec2aff6e2afab Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Tue, 31 Dec 2019 19:57:01 +0530 Subject: Flowsheet functions clubbed together, merged UnitOprns.py with UnitOperations.py --- container.py | 1 + 1 file changed, 1 insertion(+) (limited to 'container.py') diff --git a/container.py b/container.py index 3652031..ba67be0 100644 --- a/container.py +++ b/container.py @@ -92,6 +92,7 @@ class Container(): for i in self.unitOp: if(i.name==name): return i + def addCompounds(self,comp): self.compounds = comp -- cgit From 8dfb7d836e438035be2284e49554dac36d0af7bf Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Fri, 3 Jan 2020 15:54:24 +0530 Subject: Made GUI compatible with the new Simulator, abbreviations updated to new convention and few bugs eliminated with code clean up at places --- container.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'container.py') diff --git a/container.py b/container.py index ba67be0..f9106ee 100644 --- a/container.py +++ b/container.py @@ -1,7 +1,4 @@ from OMChem.Flowsheet import Flowsheet -from OMChem.MatStm import MatStm -from OMChem.Mixer import Mixer -from OMChem.Heater import Heater from component_selector import * from collections import defaultdict from PyQt5.QtCore import * @@ -53,7 +50,7 @@ class Container(): self.op.clear() self.ip.clear() self.opl.clear() - stm = ['MatStm','EngStm'] + stm = ['MaterialStream','EngStm'] for i in self.conn: if i.type not in stm: self.op[i]=self.conn[i] -- cgit From 39ecc236c572ae17343b9afb39997233e7eb28f0 Mon Sep 17 00:00:00 2001 From: lucaszhao19 Date: Fri, 3 Jan 2020 17:09:38 +0530 Subject: Merged changes, load implemented (WIP) --- container.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'container.py') diff --git a/container.py b/container.py index f9106ee..8b47c05 100644 --- a/container.py +++ b/container.py @@ -17,10 +17,12 @@ import json import pickle import os import sys - +unitOp = [] class Container(): + + def __init__(self,msgbrowser): - self.unitOp = [] + #self.unitOp = [] self.thermoPackage = None self.compounds = None self.flowsheet = None @@ -31,15 +33,11 @@ class Container(): self.msg.setText("") self.opl=[] self.result=[] - - def currentTime(self): now = datetime.datetime.now() time = str(now.hour) + ":" + str(now.minute) + ":" +str(now.second) return time - - def updateConn(self,key,value): self.conn[key].append(value) @@ -67,7 +65,6 @@ class Container(): except Exception as e: print(e) - def addUnitOp(self,obj,scene,graphics): box = None self.obj = obj @@ -76,17 +73,16 @@ class Container(): box = self.graphics.createNodeItem(self.obj) self.scene.addItem(box) box.setPos(2500-30, 2500-30) - - if(obj in self.unitOp): + if(obj in unitOp): pass else: - self.unitOp.append(obj) - + #self.unitOp.append(obj) + unitOp.append(obj) self.msg.append("["+str(self.currentTime())+"] "+obj.name+" is instantiated .""") def fetchObject(self,name): - for i in self.unitOp: + for i in unitOp: if(i.name==name): return i @@ -95,8 +91,6 @@ class Container(): def add_thermoPackage(self,thermo): self.thermoPackage = thermo - - def msgBrowser(self): std = self.flowsheet.stdout.decode("utf-8") @@ -119,7 +113,7 @@ class Container(): self.flowsheet = Flowsheet() self.flowsheet.add_comp_list(self.compounds) print("######## connection master#########\n",self.conn) - for i in self.unitOp : + for i in unitOp : print("here",i) self.flowsheet.add_UnitOpn(i) -- cgit From db1e22fcf2aa9fd38a10867cc24813f8c4c9f079 Mon Sep 17 00:00:00 2001 From: lucaszhao19 Date: Wed, 8 Jan 2020 17:04:01 +0530 Subject: Creating, deleting, saving and loading graphics related parts fully completed --- container.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'container.py') diff --git a/container.py b/container.py index 8b47c05..6cfc689 100644 --- a/container.py +++ b/container.py @@ -10,19 +10,18 @@ from PyQt5.QtWidgets import QGraphicsProxyWidget, QGraphicsObject, QGraphicsElli from PyQt5.QtGui import QBrush ,QTransform ,QMouseEvent import PyQt5.QtCore as QtCore import PyQt5.QtWidgets as QtWidgets -from dockWidget import dockWidget import datetime import itertools import json import pickle import os import sys -unitOp = [] +from Graphics import * + class Container(): - def __init__(self,msgbrowser): - #self.unitOp = [] + self.unitOp = [] self.thermoPackage = None self.compounds = None self.flowsheet = None @@ -33,6 +32,7 @@ class Container(): self.msg.setText("") self.opl=[] self.result=[] + self.graphics = Graphics(self.unitOp) def currentTime(self): now = datetime.datetime.now() @@ -65,24 +65,26 @@ class Container(): except Exception as e: print(e) - def addUnitOp(self,obj,scene,graphics): + @staticmethod + def addUnitOpObj(obj): + self.unitOp.append(obj) + + def addUnitOp(self,obj): box = None self.obj = obj - self.scene = scene - self.graphics = graphics + self.scene = self.graphics.getScene() box = self.graphics.createNodeItem(self.obj) self.scene.addItem(box) box.setPos(2500-30, 2500-30) - if(obj in unitOp): + if(obj in self.unitOp): pass else: - #self.unitOp.append(obj) - unitOp.append(obj) + self.unitOp.append(obj) self.msg.append("["+str(self.currentTime())+"] "+obj.name+" is instantiated .""") def fetchObject(self,name): - for i in unitOp: + for i in self.unitOp: if(i.name==name): return i @@ -109,11 +111,10 @@ class Container(): print("SIMULATE") print(mode) self.compounds = compound_selected - #self.connection() self.flowsheet = Flowsheet() self.flowsheet.add_comp_list(self.compounds) print("######## connection master#########\n",self.conn) - for i in unitOp : + for i in self.unitOp : print("here",i) self.flowsheet.add_UnitOpn(i) -- cgit From 190966e010e321e4df56d40104ec80467a870e53 Mon Sep 17 00:00:00 2001 From: Sann Yay Aye Date: Thu, 30 Jan 2020 12:57:51 +0530 Subject: undo&redo_implementation --- container.py | 147 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 117 insertions(+), 30 deletions(-) (limited to 'container.py') diff --git a/container.py b/container.py index 6cfc689..7212cc4 100644 --- a/container.py +++ b/container.py @@ -19,7 +19,6 @@ import sys from Graphics import * class Container(): - def __init__(self,msgbrowser): self.unitOp = [] self.thermoPackage = None @@ -33,46 +32,47 @@ class Container(): self.opl=[] self.result=[] self.graphics = Graphics(self.unitOp) + self.scene = self.graphics.getScene() def currentTime(self): now = datetime.datetime.now() time = str(now.hour) + ":" + str(now.minute) + ":" +str(now.second) return time - def updateConn(self,key,value): - self.conn[key].append(value) - self.msg.append("["+str(self.currentTime())+"] "+key.name+" output is connected to input of "+value.name +" ") - - def connection(self): - try: - self.op.clear() - self.ip.clear() - self.opl.clear() - stm = ['MaterialStream','EngStm'] - for i in self.conn: - if i.type not in stm: - self.op[i]=self.conn[i] - - for j in range(len(self.conn[i])): - if self.conn[i][j].type not in stm: - self.ip[self.conn[i][j]].append(i) - - for i in self.op: - i.connect(InputStms=self.ip[i],OutputStms=self.op[i]) - - self.opl.append([self.op[i] for i in self.op]) - self.opl=flatlist(flatlist(self.opl)) - except Exception as e: - print(e) + # def updateConn(self,key,value): + # self.conn[key].append(value) + # self.msg.append("["+str(self.currentTime())+"] "+key.name+" output is connected to input of "+value.name +" ") + # + # def connection(self): + # try: + # self.op.clear() + # self.ip.clear() + # self.opl.clear() + # stm = ['MaterialStream','EngStm'] + # for i in self.conn: + # if i.type not in stm: + # self.op[i]=self.conn[i] + # + # for j in range(len(self.conn[i])): + # if self.conn[i][j].type not in stm: + # self.ip[self.conn[i][j]].append(i) + # + # for i in self.op: + # i.connect(InputStms=self.ip[i],OutputStms=self.op[i]) + # + # self.opl.append([self.op[i] for i in self.op]) + # self.opl=flatlist(flatlist(self.opl)) + # except Exception as e: + # print(e) - @staticmethod - def addUnitOpObj(obj): - self.unitOp.append(obj) + # @staticmethod + # def addUnitOpObj(obj): + # self.unitOp.append(obj) def addUnitOp(self,obj): box = None self.obj = obj - self.scene = self.graphics.getScene() + # self.scene = self.graphics.getScene() box = self.graphics.createNodeItem(self.obj) self.scene.addItem(box) box.setPos(2500-30, 2500-30) @@ -81,8 +81,49 @@ class Container(): pass else: self.unitOp.append(obj) + data = self.unitOp[:] + data.append(compound_selected) + PUSH('Undo', data) self.msg.append("["+str(self.currentTime())+"] "+obj.name+" is instantiated .""") + ''' + Deletes the selected item from the canvas and also the objects created for that type. + ''' + def delete(self,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) + del x.newLine + if x.otherLine: + self.scene.removeItem(x.otherLine) + del x.otherLine + if hasattr(item,'Output'): + for x in item.Output: + if x.newLine: + self.scene.removeItem(x.newLine) + del x.newLine + if x.otherLine: + self.scene.removeItem(x.otherLine) + del x.otherLine + if hasattr(item,'obj'): + self.unitOp.remove(item.obj) + for k in list(self.conn): + if item.obj==k: + del self.conn[k] + elif item.obj in self.conn[k]: + self.conn[k].remove(item.obj) + self.msg.append("["+str(self.currentTime())+"] "+item.obj.name+" is deleted .""") + del item.obj + del item + + CLEAN_FILE('Redo') + data = self.unitOp[:] + data.append(compound_selected) + PUSH('Undo', data) + def fetchObject(self,name): for i in self.unitOp: if(i.name==name): @@ -137,3 +178,49 @@ def flatlist(lst): for item in sublist: flat_list.append(item) return flat_list + +def PUSH(fileName, data): + with open(f"{fileName}.dat", "ab") as obj: + pickle.dump(data, obj) + +def CLEAN_FILE(fileName): + with open(f"{fileName}.dat", "wb") as clean: + pass + +def POP(fileName): + last_command = None + if os.stat(f"{fileName}.dat").st_size != 0: + commands = [] + with open(f"{fileName}.dat", "rb") as objs: + while True: + try: + command = pickle.load(objs) + commands.append(command) + except EOFError: + break + + last_command = commands[-1] + commands.remove(commands[-1]) + if len(commands) != 0: + with open(f"{fileName}.dat", "wb") as updated_data: + for i in range(len(commands)): + pickle.dump(commands[i], updated_data) + else: + CLEAN_FILE(fileName) + + return last_command + +def get_last_list(fileName): + commands = [] + if os.stat(f"{fileName}.dat").st_size != 0: + with open(f"{fileName}.dat", "rb") as objs: + while True: + try: + command = pickle.load(objs) + commands.append(command) + except EOFError: + break + if len(commands) is not 0: + return commands[-1] + else: + return None \ No newline at end of file -- cgit From 38dbff48f57c403abdc575a9cd9d0bbf512bfef6 Mon Sep 17 00:00:00 2001 From: lucaszhao19 Date: Wed, 5 Feb 2020 17:58:00 +0530 Subject: Input/Results DockWidgets, Newly implemented variables for MaterialStream and four UnitOps --- container.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'container.py') diff --git a/container.py b/container.py index 6cfc689..cc10c38 100644 --- a/container.py +++ b/container.py @@ -73,7 +73,7 @@ class Container(): box = None self.obj = obj self.scene = self.graphics.getScene() - box = self.graphics.createNodeItem(self.obj) + box = self.graphics.createNodeItem(self.obj, self) self.scene.addItem(box) box.setPos(2500-30, 2500-30) @@ -131,6 +131,8 @@ class Container(): self.result=self.flowsheet.resdata print("under Eqn mode simulation") + DockWidget.showResult(NodeItem.getDockWidget()) + def flatlist(lst): flat_list=[] for sublist in lst: -- cgit From df141f35dccc6b21fcfa575707c6435a39d0002f Mon Sep 17 00:00:00 2001 From: lucaszhao19 Date: Wed, 5 Feb 2020 18:20:17 +0530 Subject: Revamped and merged Input/Results DockWidgets, Added new "variables" dictionary for each object --- container.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'container.py') diff --git a/container.py b/container.py index 17f1b87..6b4bcbe 100644 --- a/container.py +++ b/container.py @@ -72,13 +72,8 @@ class Container(): def addUnitOp(self,obj): box = None self.obj = obj -<<<<<<< HEAD self.scene = self.graphics.getScene() box = self.graphics.createNodeItem(self.obj, self) -======= - # self.scene = self.graphics.getScene() - box = self.graphics.createNodeItem(self.obj) ->>>>>>> 190966e010e321e4df56d40104ec80467a870e53 self.scene.addItem(box) box.setPos(2500-30, 2500-30) -- cgit