diff --git a/moose-gui/mgui.py b/moose-gui/mgui.py index d5a900abe4b3df5e4b6e3ffccfbc847ce342c84f..0ecb96fe2ca97b62136fd0cebccb8a15470c41b2 100644 --- a/moose-gui/mgui.py +++ b/moose-gui/mgui.py @@ -6,7 +6,7 @@ # Maintainer: HarshaRani # Created: Mon Nov 12 09:38:09 2012 (+0530) # Version: -# Last-Updated: Fri Sep 7 14:54:33 2017 (+0530) +# Last-Updated: Fri Sep 20 00:54:33 2018 (+0530) # By: Harsha # Update #: # URL: @@ -45,13 +45,18 @@ '''' 2018 -Sep 7: popup is closed if exist +Sep 20 : Lot of duplicate code removed + Function call made when filename or filepath is passed in command line +Sep 19 : From the cmd line if a directory is passed, then Gui opens up the dialog file for the folder, + window is resized to maximum width, clean warning message if filename or path is wrong + Added model info QmessageBox +Sep 7 : popup is closed if exist 2017 -Aug 31: Pass file from the command to load into gui - : added dsolver in disableModel function is used to unset the solver for the model - into moose-gui which are not to be run. +Aug 31 : Pass file from the command to load into gui + : added dsolver in disableModel function is used to unset the solver for the model + into moose-gui which are not to be run. -Oct 5: clean up with round trip of dialog_exe +Oct 5 : clean up with round trip of dialog_exe ''' # Code: @@ -196,6 +201,7 @@ class MWindow(QtGui.QMainWindow): pass else: cmdfilepath = os.path.abspath(sys.argv[1]) + try: sys.argv[2] except: @@ -207,6 +213,7 @@ class MWindow(QtGui.QMainWindow): filepath,fileName = os.path.split(cmdfilepath) modelRoot,extension = os.path.splitext(fileName) if extension == '.py': + self.setWindowState(QtCore.Qt.WindowMaximized) self.show() self.createPopup() freeCursor() @@ -215,16 +222,23 @@ class MWindow(QtGui.QMainWindow): QtGui.QApplication.restoreOverrideCursor() return if not os.path.exists(cmdfilepath): + self.setWindowState(QtCore.Qt.WindowMaximized) self.show() self.createPopup() - reply = QtGui.QMessageBox.information(self,"Model file can not open","Check filename or filepath ",QtGui.QMessageBox.Ok) + reply = QtGui.QMessageBox.information(self,"Model file can not open","File Not Found \n \nCheck filename or filepath\n ",QtGui.QMessageBox.Ok) if reply == QtGui.QMessageBox.Ok: QtGui.QApplication.restoreOverrideCursor() return + if os.path.isdir(cmdfilepath): + self.setWindowState(QtCore.Qt.WindowMaximized) + self.show() + self.loadModelDialogFunc(cmdfilepath) + else: filePath = filepath+'/'+fileName ret = loadFile(str(filePath), '%s' % (modelRoot), solver, merge=False) - self.objectEditSlot('/',False) + #self.objectEditSlot('/',False) + self.objectEditSlot(ret['model'].path,False) pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype']) try: pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])] @@ -249,26 +263,10 @@ class MWindow(QtGui.QMainWindow): modelAnno.dirpath = str(filepath) self.setPlugin(pluginName, ret['model'].path) + self.setWindowState(QtCore.Qt.WindowMaximized) self.show() - # if pluginName == 'kkit': - # QtCore.QCoreApplication.sendEvent(self.plugin.getEditorView().getCentralWidget().view, QtGui.QKeyEvent(QtCore.QEvent.KeyPress, Qt.Qt.Key_A, Qt.Qt.NoModifier)) - - # noOfCompt = len(moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]')) - # grp = 0 - # for c in moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]'): - # noOfGrp = moose.wildcardFind(moose.element(c).path+'/#[TYPE=Neutral]') - # grp = grp+len(noOfGrp) - - # noOfPool = len(moose.wildcardFind(ret['model'].path+'/##[ISA=PoolBase]')) - # noOfFunc = len(moose.wildcardFind(ret['model'].path+'/##[ISA=Function]')) - # noOfReac = len(moose.wildcardFind(ret['model'].path+'/##[ISA=ReacBase]')) - # noOfEnz = len(moose.wildcardFind(ret['model'].path+'/##[ISA=EnzBase]')) - # noOfStimtab = len(moose.wildcardFind(ret['model'].path+'/##[ISA=StimulusTable]')) - - # reply = QtGui.QMessageBox.information(self,"Model Info","Model has : \n %s Compartment \t \n %s Group \t \n %s Pool \t \n %s Function \t \n %s reaction \t \n %s Enzyme \t \n %s StimulusTable" %(noOfCompt, grp, noOfPool, noOfFunc, noOfReac, noOfEnz, noOfStimtab)) - # if reply == QtGui.QMessageBox.Ok: - # QtGui.QApplication.restoreOverrideCursor() - # return + if pluginName == 'kkit': + self.displaymodelInfo(ret) else: self.createPopup() @@ -571,7 +569,6 @@ class MWindow(QtGui.QMainWindow): if name == 'kkit': self.objectEditDockWidget.objectNameChanged.connect(self.plugin.getEditorView().getCentralWidget().updateItemSlot) self.objectEditDockWidget.colorChanged.connect(self.plugin.getEditorView().getCentralWidget().updateColorSlot) - self.setCurrentView('editor') freeCursor() return self.plugin @@ -646,7 +643,8 @@ class MWindow(QtGui.QMainWindow): self.plugin.setCurrentView(view) if view =='run': #Harsha: This will clear out object editor's objectpath and make it invisible - self.objectEditSlot('/',False) + #self.objectEditSlot('/',False) + self.objectEditDockWidget.setVisible(False) targetView = None newSubWindow = True @@ -1222,6 +1220,15 @@ class MWindow(QtGui.QMainWindow): for table in moose.wildcardFind( modelPath+'/data/graph#/#' ): table.tick = -1 + def loadModelDialogFunc(self,directorypassed): + """ This is from command line the filepath and file name is passed + """ + dialog = LoaderDialog(self, + self.tr('Load model from file'),directorypassed) + + if dialog.exec_(): + self.passtoPluginCheck(dialog) + def loadModelDialogSlot(self): """Start a file dialog to choose a model file. @@ -1245,66 +1252,48 @@ class MWindow(QtGui.QMainWindow): activeWindow = None # This to be used later to refresh the current widget with newly loaded model dialog = LoaderDialog(self, self.tr('Load model from file')) - if dialog.exec_(): - valid = False - ret = [] - ret,pluginName = self.checkPlugin(dialog) + self.passtoPluginCheck(dialog) + + def passtoPluginCheck(self, dialog): + valid = False + ret = [] + ret,pluginName = self.checkPlugin(dialog) + valid,ret = self.dialog_check(ret) + + if valid == True: + modelAnno = moose.Annotator(ret['model'].path+'/info') + if ret['subtype']: + modelAnno.modeltype = ret['subtype'] + else: + modelAnno.modeltype = ret['modeltype'] + modelAnno.dirpath = str(dialog.directory().absolutePath()) + self.loadedModelsAction(ret['model'].path,pluginName) + self.setPlugin(pluginName, ret['model'].path) + if pluginName == 'kkit': - if (ret['subtype'] == 'sbml' and ret['foundlib'] == False): - reply = QtGui.QMessageBox.question(self, "python-libsbml is not found.","\n Read SBML is not possible.\n This can be installed using \n \n pip python-libsbml or \n apt-get install python-libsbml", - QtGui.QMessageBox.Ok) - if reply == QtGui.QMessageBox.Ok: - QtGui.QApplication.restoreOverrideCursor() - return - else: - if ret['loaderror'] != "": - reply = QtGui.QMessageBox.question(self, "Model can't be loaded", ret['loaderror']+" \n \n Do you want another file", - QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) - if reply == QtGui.QMessageBox.Yes: - dialog = LoaderDialog(self,self.tr('Load model from file')) - if dialog.exec_(): - valid = False - ret = [] - pluginName = None - ret,pluginName = self.checkPlugin(dialog) - - valid, ret = self.dialog_check(ret) - else: - QtGui.QApplication.restoreOverrideCursor() - return valid - else: + self.displaymodelInfo(ret) + + def displaymodelInfo(self,ret): + QtCore.QCoreApplication.sendEvent(self.plugin.getEditorView().getCentralWidget().view, QtGui.QKeyEvent(QtCore.QEvent.KeyPress, Qt.Qt.Key_A, Qt.Qt.NoModifier)) + + noOfCompt = len(moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]')) + grp = 0 + for c in moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]'): + noOfGrp = moose.wildcardFind(moose.element(c).path+'/#[TYPE=Neutral]') + grp = grp+len(noOfGrp) + + noOfPool = len(moose.wildcardFind(ret['model'].path+'/##[ISA=PoolBase]')) + noOfFunc = len(moose.wildcardFind(ret['model'].path+'/##[ISA=Function]')) + noOfReac = len(moose.wildcardFind(ret['model'].path+'/##[ISA=ReacBase]')) + noOfEnz = len(moose.wildcardFind(ret['model'].path+'/##[ISA=EnzBase]')) + noOfStimtab = len(moose.wildcardFind(ret['model'].path+'/##[ISA=StimulusTable]')) + + reply = QtGui.QMessageBox.information(self,"Model Info","Model has : \n %s Compartment \t \n %s Group \t \n %s Pool \t \n %s Function \t \n %s reaction \t \n %s Enzyme \t \n %s StimulusTable" %(noOfCompt, grp, noOfPool, noOfFunc, noOfReac, noOfEnz, noOfStimtab)) + if reply == QtGui.QMessageBox.Ok: + QtGui.QApplication.restoreOverrideCursor() + return - valid = True - if valid == True: - modelAnno = moose.Annotator(ret['model'].path+'/info') - if ret['subtype']: - modelAnno.modeltype = ret['subtype'] - else: - modelAnno.modeltype = ret['modeltype'] - modelAnno.dirpath = str(dialog.directory().absolutePath()) - self.loadedModelsAction(ret['model'].path,pluginName) - self.setPlugin(pluginName, ret['model'].path) - if pluginName == 'kkit': - QtCore.QCoreApplication.sendEvent(self.plugin.getEditorView().getCentralWidget().view, QtGui.QKeyEvent(QtCore.QEvent.KeyPress, Qt.Qt.Key_A, Qt.Qt.NoModifier)) - - noOfCompt = len(moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]')) - grp = 0 - for c in moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]'): - noOfGrp = moose.wildcardFind(moose.element(c).path+'/#[TYPE=Neutral]') - grp = grp+len(noOfGrp) - - noOfPool = len(moose.wildcardFind(ret['model'].path+'/##[ISA=PoolBase]')) - noOfFunc = len(moose.wildcardFind(ret['model'].path+'/##[ISA=Function]')) - noOfReac = len(moose.wildcardFind(ret['model'].path+'/##[ISA=ReacBase]')) - noOfEnz = len(moose.wildcardFind(ret['model'].path+'/##[ISA=EnzBase]')) - noOfStimtab = len(moose.wildcardFind(ret['model'].path+'/##[ISA=StimulusTable]')) - - reply = QtGui.QMessageBox.information(self,"Model Info","Model has : \n %s Compartment \t \n %s Group \t \n %s Pool \t \n %s Function \t \n %s reaction \t \n %s Enzyme \t \n %s StimulusTable" %(noOfCompt, grp, noOfPool, noOfFunc, noOfReac, noOfEnz, noOfStimtab)) - if reply == QtGui.QMessageBox.Ok: - QtGui.QApplication.restoreOverrideCursor() - return - def checkPlugin(self,dialog): fileNames = dialog.selectedFiles() for fileName in fileNames: @@ -1360,7 +1349,7 @@ class MWindow(QtGui.QMainWindow): def newModelDialogSlot(self): #Harsha: Create a new dialog widget for model building - if popup: + if self.popup: self.popup.close() newModelDialog = DialogWidget() if newModelDialog.exec_(): diff --git a/moose-gui/mload.py b/moose-gui/mload.py index 9fc753e64551b388f7b605d0fe326fc75738e930..3b9783282db59afed47d012d15d0069f2bf83d75 100644 --- a/moose-gui/mload.py +++ b/moose-gui/mload.py @@ -61,7 +61,8 @@ from PyQt4 import QtGui, QtCore, Qt from plugins.setsolver import * from moose.SBML import * from plugins.kkitOrdinateUtil import * - +import moose._moose as moose +import moose.utils as mutils def loadGenCsp(target,filename,solver="gsl"): target = target.replace(" ", "") path = '/'+target @@ -72,7 +73,7 @@ def loadGenCsp(target,filename,solver="gsl"): moose.delete(mpath) modelpath1 = moose.Neutral('%s' %(target)) modelpath = moose.Neutral('%s/%s' %(modelpath1.path,"model")) - model = moose.loadModel(filename, modelpath.path,solver) + model = mutils.loadModel(filename, modelpath.path,solver) if not moose.exists(modelpath1.path+'/data'): graphspath = moose.Neutral('%s/%s' %(modelpath1.path,"data")) @@ -189,7 +190,7 @@ def loadFile(filename, target, solver="gsl", merge=True): moose.Annotator(moose.element(modelpath).path+'/info').modeltype = "kkit" else: print (" path doesn't exists") - moose.le(modelpath) + #moose.le(modelpath) else: print ('Only kkit and prototype files can be loaded.') diff --git a/moose-gui/objectedit.py b/moose-gui/objectedit.py index d5d66b60c96fa506af50e620260a109f5deb8e29..11a35b66948262d60c12cdd528ab421e7b5aa873 100644 --- a/moose-gui/objectedit.py +++ b/moose-gui/objectedit.py @@ -6,7 +6,7 @@ # Maintainer: # Created: Wed Jun 30 11:18:34 2010 (+0530) # Version: -# Last-Updated: Mon Sep 10 11:05:59 2017 (+0530) +# Last-Updated: Fri Feb 01 11:05:59 2017 (+0530) # By: Harsha # Update #: # URL: @@ -77,11 +77,13 @@ import sys from collections import deque import traceback -sys.path.append('../python') +#sys.path.append('../python') import moose import defaults import config -from plugins.kkitUtil import getColor +#from plugins.kkitUtil import getColor +from moose.chemUtil.chemConnectUtil import getColor + #these fields will be ignored extra_fields = ['this', 'me', @@ -437,7 +439,7 @@ class ObjectEditView(QtGui.QTableView): def setColor(self, color): self.colorButton.setStyleSheet( "QPushButton {" - + "background-color: {0}; color: {0};".format(color.name()) + + "background-color: {0}; color: {0};".format(color) + "}" ) self.colorDialog.setCurrentColor(color) diff --git a/moose-gui/plugins/kkit.py b/moose-gui/plugins/kkit.py index 3cd531bb4498af9fc86fc75bc11a9a4376f602d0..c375e06905103bff17f50aaeaea810589327399b 100644 --- a/moose-gui/plugins/kkit.py +++ b/moose-gui/plugins/kkit.py @@ -6,11 +6,17 @@ __version__ = "1.0.0" __maintainer__ = "HarshaRani" __email__ = "hrani@ncbs.res.in" __status__ = "Development" -__updated__ = "Sep 11 2018" +__updated__ = "Feb 22 2019" #Change log: +#2019 +#Feb 22: cross compartment molecules are checked for destination # 2018 -#sep 11: comparment size is calculated based on group sceneBoundingRect size +#Oct 26: xfer cross compartment molecules are hidden and for cross compartment reaction's +# connection are now dotted line +#Oct 10: filedialog default is sbml +# layout co-ordainates are updated with scenepos +#Sep 11: comparment size is calculated based on group sceneBoundingRect size #Sep 07: in positionChange all the group's boundingRect is calculated # and when group is moved the children's position are stored #Jun 18: update the color of the group from objecteditor @@ -38,6 +44,7 @@ import RunWidget from os.path import expanduser #from setsolver import * from moose.chemUtil.add_Delete_ChemicalSolver import * +import re class KkitPlugin(MoosePlugin): """Default plugin for MOOSE GUI""" @@ -62,41 +69,25 @@ class KkitPlugin(MoosePlugin): self.getEditorView() def SaveModelDialogSlot(self): - type_sbml = 'SBML' - type_genesis = 'Genesis' + dirpath = "" - # if moose.Annotator(self.modelRoot+'/model/info'): - # moose.Annotator(self.modelRoot+'/model/info') - # mooseAnno = moose.Annotator(self.modelRoot+'/model/info') - #dirpath = mooseAnno.dirpath if not dirpath: dirpath = expanduser("~") - filters = {'SBML(*.xml)': type_sbml,'Genesis(*.g)':type_genesis} - - filename,filter_ = QtGui.QFileDialog.getSaveFileNameAndFilter(None,'Save File',dirpath,';;'.join(filters)) + filters = {'SBML(*.xml)': 'SBML','Genesis(*.g)':'Genesis'} + #filename,filter_ = QtGui.QFileDialog.getSaveFileNameAndFilter(None,'Save File',dirpath,';;'.join(filters)) + filename,filter_ = QtGui.QFileDialog.getSaveFileNameAndFilter(None,'Save File',dirpath,"SBML(*.xml);;Genesis(*.g)") extension = "" if str(filename).rfind('.') != -1: filename = filename[:str(filename).rfind('.')] if str(filter_).rfind('.') != -1: extension = filter_[str(filter_).rfind('.'):len(filter_)-1] + if filename: filename = filename if filters[str(filter_)] == 'SBML': - self.sceneObj = KkitEditorView(self).getCentralWidget().mooseId_GObj self.coOrdinates = {} self.plugin = KkitEditorView(self).getCentralWidget().plugin - self.defaultScenewidth = KkitEditorView(self).getCentralWidget().defaultScenewidth - self.defaultSceneheight = KkitEditorView(self).getCentralWidget().defaultSceneheight self.coOrdinates = KkitEditorView(self).getCentralWidget().getsceneCord() - ''' - for k,v in self.sceneObj.items(): - if moose.exists(moose.element(k).path+'/info'): - annoInfo = Annotator(k.path+'/info') - if moose.element(self.plugin.modelRoot+'/info').modeltype == 'kkit': - self.coOrdinates[k] = {'x':annoInfo.x*self.defaultScenewidth, 'y':annoInfo.y*self.defaultSceneheight} - else: - self.coOrdinates[k] = {'x':annoInfo.x, 'y':annoInfo.y} - ''' #writeerror = moose.writeSBML(self.modelRoot,str(filename),self.coOrdinates) writeerror = -2 conisitencyMessages = "" @@ -344,8 +335,8 @@ class KineticsWidget(EditorWidgetBase): self.arrowsize = 2 self.reset() - self.defaultSceneheight = 800#1000 - self.defaultScenewidth = 1000#2400 + self.defaultSceneheight = 1#800#1000 + self.defaultScenewidth = 1#000#2400 self.positionInfoExist = True self.defaultComptsize = 5 self.srcdesConnection = {} @@ -376,13 +367,10 @@ class KineticsWidget(EditorWidgetBase): def getsceneCord(self): self.cord = {} + self.view.setRefWidget("runView") for item in self.sceneContainer.items(): if isinstance(item,KineticsDisplayItem): - #item.refresh(scale) - #self.update() - xpos = item.scenePos().x() - ypos = item.scenePos().y() - self.cord[item.mobj] = {'x':xpos,'y':ypos} + self.cord[item.mobj] = {'x':item.scenePos().x(),'y':item.scenePos().y()} return self.cord def updateModelView(self): @@ -459,18 +447,15 @@ class KineticsWidget(EditorWidgetBase): self.srcdesConnection = {} setupItem(self.modelRoot,self.srcdesConnection) - - # if not self.positionInfoExist: - # autoCoordinates(self.meshEntry,self.srcdesConnection) + #self.noPositionInfo = False if not self.noPositionInfo: self.autocoordinates = True #self.xmin,self.xmax,self.ymin,self.ymax,self.autoCordinatepos = autoCoordinates(self.meshEntry,self.srcdesConnection) - #print " after ",self.xmin,self.xmax, self.ymin, self.ymax,self.autoCordinatepos autoCoordinates(self.meshEntry,self.srcdesConnection) self.size = QtCore.QSize(1000 ,550) - ''' + ''' if self.xmax-self.xmin != 0: self.xratio = (self.size.width()-10)/(self.xmax-self.xmin) else: self.xratio = self.size.width()-10 @@ -485,7 +470,7 @@ class KineticsWidget(EditorWidgetBase): self.xratio = 1 if self.yratio == 0: self.yratio = 1 - ''' + ''' def sizeHint(self): return QtCore.QSize(800,400) @@ -503,6 +488,7 @@ class KineticsWidget(EditorWidgetBase): self.positionChange(mooseObject) self.view.removeConnector() self.view.showConnector(item) + def updateColorSlot(self,mooseObject, colour): #Color slot for changing background color for Pool,Enz and group from objecteditor anninfo = moose.Annotator(mooseObject.path+'/info') @@ -631,6 +617,7 @@ class KineticsWidget(EditorWidgetBase): elif isinstance(moose.element(v), moose.Neutral): group_parent = self.qGraGrp[v] self.createGroup(k,group_parent) + for cmpt_grp,memb in self.meshEntry.items(): if len(memb): if isinstance(moose.element(cmpt_grp),moose.ChemCompt): @@ -643,6 +630,7 @@ class KineticsWidget(EditorWidgetBase): self.groupChildrenBoundingRect() # compartment's rectangle size is calculated depending on children self.comptChildrenBoundingRect() + def mObjontoscene(self,memb,mclass,qtGrpparent): try: value = memb[mclass] @@ -651,7 +639,6 @@ class KineticsWidget(EditorWidgetBase): else: for mObj in memb[mclass]: minfo = mObj.path+'/info' - if mObj.className in['Enz',"ZombieEnz"]: mItem = EnzItem(mObj,qtGrpparent) @@ -669,18 +656,20 @@ class KineticsWidget(EditorWidgetBase): minfo = (mObj.parent).path+'/info' mItem = CplxItem(mObj,self.mooseId_GObj[element(mObj).parent]) self.mooseId_GObj[element(mObj.getId())] = mItem + elif mclass == "function": if isinstance(moose.element(mObj.parent),moose.PoolBase): minfo = moose.element(mObj).path+'/info' Af = Annotator(minfo) qtGrpparent = self.mooseId_GObj[element(mObj.parent)] mItem = FuncItem(mObj,qtGrpparent) + elif mclass == "stimTab": minfo = mObj.path+'/info' mItem = TableItem(mObj,qtGrpparent) self.mooseId_GObj[element(mObj.getId())] = mItem self.setupDisplay(minfo,mItem,mclass) - + def createGroup(self,key,parent): self.new_GRP = GRPItem(parent,0,0,0,0,key) self.qGraGrp[key] = self.new_GRP @@ -696,12 +685,13 @@ class KineticsWidget(EditorWidgetBase): v.setPen(QtGui.QPen(Qt.QColor(grpcolor), self.comptPen, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin)) def comptChildrenBoundingRect(self): + comptlist = [] for k, v in self.qGraCompt.items(): # compartment's rectangle size is calculated depending on children rectcompt = calculateChildBoundingRect(v) v.setRect(rectcompt.x()-10,rectcompt.y()-10,(rectcompt.width()+20),(rectcompt.height()+20)) v.setPen(QtGui.QPen(Qt.QColor(66,66,66,100), self.comptPen, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin)) - + def createCompt(self,key): self.new_Compt = ComptItem(self,0,0,0,0,key) self.qGraCompt[key] = self.new_Compt @@ -738,34 +728,34 @@ class KineticsWidget(EditorWidgetBase): else: xpos,ypos = self.positioninfo(info) - self.xylist = [xpos,ypos] - self.xyCord[moose.element(info).parent] = [xpos,ypos] - elif isinstance(self,kineticRunWidget): self.editormooseId_GObj = self.editor.getCentralWidget().mooseId_GObj editorItem = self.editormooseId_GObj[moose.element(info).parent] xpos = editorItem.scenePos().x() - ypos = editorItem.scenePos().y() - #Annoinfo.x = xpos - #Annoinfo.y = -ypos + ypos = editorItem.scenePos().y() graphicalObj.setDisplayProperties(xpos,ypos,textcolor,bgcolor) - #Annoinfo.x = xpos - #Annoinfo.y = ypos + def positioninfo(self,iteminfo): '''By this time, model loaded from kkit,cspace,SBML would have info field created and co-ordinates are added either by autocoordinates (for cspace,SBML(unless it is not saved from moose)) or from kkit ''' - if moose.Annotator(self.plugin.modelRoot+'/info').modeltype == 'kkit': - x = self.defaultScenewidth * float(element(iteminfo).getField('x')) - y = self.defaultSceneheight * float(element(iteminfo).getField('y')) - #x = x /self.defaultScenewidth - #y = y /self.defaultSceneheight - else: - x = float(element(iteminfo).getField('x')) - y = float(element(iteminfo).getField('y')) - self.defaultScenewidth = 1 - self.defaultSceneheight = 1 + + x = float(element(iteminfo).getField('x')) + y = float(element(iteminfo).getField('y')) + #print " positioninfo", iteminfo,x,y + # if moose.Annotator(self.plugin.modelRoot+'/info').modeltype == 'kkit': + # x = self.defaultScenewidth * float(element(iteminfo).getField('x')) + # y = self.defaultSceneheight * float(element(iteminfo).getField('y')) + # print " positioninfo ",iteminfo, element(iteminfo).getField('x'), element(iteminfo).getField('y'), x, y + + # #x = x /self.defaultScenewidth + # #y = y /self.defaultSceneheight + # else: + # x = float(element(iteminfo).getField('x')) + # y = float(element(iteminfo).getField('y')) + # self.defaultScenewidth = 1 + # self.defaultSceneheight = 1 return(x,y) def drawLine_arrow(self, itemignoreZooming=False): @@ -776,20 +766,39 @@ class KineticsWidget(EditorWidgetBase): # key is Function and value is [list of pool] (list) #src = self.mooseId_GObj[inn] + linetype = "regular" if isinstance(out,tuple): src = self.mooseId_GObj[inn] if len(out[0])== 0: print (inn.className + ' : ' +inn.name+ " doesn't output message") else: for items in (items for items in out[0] ): + if re.search("xfer",element(items[0]).name): + xrefPool = items[0].name[:items[0].name.index("_xfer_")] + xrefCompt = items[0].name[items[0].name.index("_xfer_") + len("_xfer_"):] + orgCompt = moose.wildcardFind(self.modelRoot+'/##[FIELD(name)='+xrefCompt+']')[0] + orgPool = moose.wildcardFind(orgCompt.path+'/##[FIELD(name)='+xrefPool+']')[0] + itemslist = list(items) + itemslist[0] = orgPool + items = tuple(itemslist) + linetype = "crosscompt" des = self.mooseId_GObj[element(items[0])] - self.lineCord(src,des,items,itemignoreZooming) + self.lineCord(src,des,items,itemignoreZooming,linetype) if len(out[1]) == 0: print (inn.className + ' : ' +inn.name+ " doesn't output message") else: for items in (items for items in out[1] ): + if re.search("xfer",element(items[0]).name): + xrefPool = items[0].name[:items[0].name.index("_xfer_")] + xrefCompt = items[0].name[items[0].name.index("_xfer_") + len("_xfer_"):] + orgCompt = moose.wildcardFind(self.modelRoot+'/##[FIELD(name)='+xrefCompt+']')[0] + orgPool = moose.wildcardFind(orgCompt.path+'/##[FIELD(name)='+xrefPool+']')[0] + itemslist = list(items) + itemslist[0] = orgPool + items = tuple(itemslist) + linetype = "crosscompt" des = self.mooseId_GObj[element(items[0])] - self.lineCord(src,des,items,itemignoreZooming) + self.lineCord(src,des,items,itemignoreZooming,linetype) elif isinstance(out,list): if len(out) == 0: if inn.className == "StimulusTable": @@ -799,9 +808,19 @@ class KineticsWidget(EditorWidgetBase): else: src = self.mooseId_GObj[inn] for items in (items for items in out ): + if re.search("xfer",element(items[0]).name): + xrefPool = items[0].name[:items[0].name.index("_xfer_")] + xrefCompt = items[0].name[items[0].name.index("_xfer_") + len("_xfer_"):] + orgCompt = moose.wildcardFind(self.modelRoot+'/##[FIELD(name)='+xrefCompt+']')[0] + orgPool = moose.wildcardFind(orgCompt.path+'/##[FIELD(name)='+xrefPool+']')[0] + itemslist = list(items) + itemslist[0] = orgPool + items = tuple(itemslist) + linetype = "crosscompt" des = self.mooseId_GObj[element(items[0])] - self.lineCord(src,des,items,itemignoreZooming) - def lineCord(self,src,des,type_no,itemignoreZooming): + self.lineCord(src,des,items,itemignoreZooming,linetype) + + def lineCord(self,src,des,type_no,itemignoreZooming,linetype): srcdes_list = [] endtype = type_no[1] line = 0 @@ -810,18 +829,18 @@ class KineticsWidget(EditorWidgetBase): return srcdes_list = [src,des,endtype,line] arrow = calcArrow(srcdes_list,itemignoreZooming,self.iconScale) - self.drawLine(srcdes_list,arrow) + self.drawLine(srcdes_list,arrow,linetype) while(type_no[2] > 1 and line <= (type_no[2]-1)): srcdes_list =[src,des,endtype,line] arrow = calcArrow(srcdes_list,itemignoreZooming,self.iconScale) - self.drawLine(srcdes_list,arrow) + self.drawLine(srcdes_list,arrow,linetype) line = line +1 if type_no[2] > 5: print ("Higher order reaction will not be displayed") - def drawLine(self,srcdes_list,arrow): + def drawLine(self,srcdes_list,arrow,linetype="solid"): src = srcdes_list[0] des = srcdes_list[1] endtype = srcdes_list[2] @@ -839,7 +858,12 @@ class KineticsWidget(EditorWidgetBase): qgLineitem = self.sceneContainer.addPolygon(arrow) qgLineitem.setParentItem(src.parentItem()) pen = QtGui.QPen(QtCore.Qt.green, 0, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin) + if linetype == "crosscompt": + pen.setStyle(Qt.Qt.CustomDashLine) + pen.setDashPattern([1, 5, 1, 5]) + pen.setWidth(self.arrowsize) + # Green is default color moose.ReacBase and derivatives - already set above if isinstance(source, EnzBase): if ( (endtype == 's') or (endtype == 'p')): @@ -859,8 +883,37 @@ class KineticsWidget(EditorWidgetBase): self.object2line[ src ].append( ( qgLineitem, des,endtype,line) ) self.object2line[ des ].append( ( qgLineitem, src,endtype,line ) ) qgLineitem.setPen(pen) - + def positionChange(self,mooseObject): + #If the item position changes, the corresponding arrow's are calculated + print mooseObject + for k, v in self.qGraCompt.items(): + for rectChilditem in v.childItems(): + self.updateArrow(rectChilditem) + if isinstance(rectChilditem,GRPItem): + for grpChilditem in rectChilditem.childItems(): + self.updateArrow(grpChilditem) + if isinstance(grpChilditem,KineticsDisplayItem): + if moose.exists(grpChilditem.mobj.path+'/info'): + #print grpChilditem.mobj.name, grpChilditem.scenePos() + moose.element(grpChilditem.mobj.path+'/info').x = grpChilditem.scenePos().x() + moose.element(grpChilditem.mobj.path+'/info').y = grpChilditem.scenePos().y() + #self.updateGrpSize(rectChilditem) + if isinstance(rectChilditem,KineticsDisplayItem): + if moose.exists(rectChilditem.mobj.path+'/info'): + #print rectChilditem.mobj.name, rectChilditem.scenePos() + moose.element(rectChilditem.mobj.path+'/info').x = rectChilditem.scenePos().x() + moose.element(rectChilditem.mobj.path+'/info').y = rectChilditem.scenePos().y() + + rectcompt = calculateChildBoundingRect(v) + comptBoundingRect = v.boundingRect() + if not comptBoundingRect.contains(rectcompt): + self.updateCompartmentSize(v) + else: + rectcompt = calculateChildBoundingRect(v) + v.setRect(rectcompt.x()-10,rectcompt.y()-10,(rectcompt.width()+20),(rectcompt.height()+20)) + + def positionChange_old(self,mooseObject): #If the item position changes, the corresponding arrow's are calculated if isinstance(element(mooseObject),ChemCompt): for k, v in self.qGraCompt.items(): @@ -868,15 +921,23 @@ class KineticsWidget(EditorWidgetBase): if k.path == mesh: for rectChilditem in v.childItems(): if isinstance(rectChilditem, KineticsDisplayItem): - if isinstance(moose.element(rectChilditem.mobj.path),PoolBase): - t = moose.element(rectChilditem.mobj.path) - moose.element(t).children - for items in moose.element(t).children: - if isinstance(moose.element(items),Function): - test = moose.element(items.path+'/x') - for i in moose.element(test).neighbors['input']: - j = self.mooseId_GObj[moose.element(i)] - self.updateArrow(j) + if moose.exists(rectChilditem.mobj.path): + iInfo = rectChilditem.mobj.path+'/info' + anno = moose.Annotator(iInfo) + #storing scenePos back to annotator file for further use + x = rectChilditem.scenePos().x() + y = rectChilditem.scenePos().y() + #anno.x = x + #anno.y = y + if isinstance(moose.element(rectChilditem.mobj.path),PoolBase): + t = moose.element(rectChilditem.mobj.path) + moose.element(t).children + for items in moose.element(t).children: + if isinstance(moose.element(items),Function): + test = moose.element(items.path+'/x') + for i in moose.element(test).neighbors['input']: + j = self.mooseId_GObj[moose.element(i)] + self.updateArrow(j) self.updateArrow(rectChilditem) elif element(mooseObject).className == 'Neutral': for k,v in self.qGraGrp.items(): @@ -886,14 +947,10 @@ class KineticsWidget(EditorWidgetBase): iInfo = grpChilditem.mobj.path+'/info' anno = moose.Annotator(iInfo) #storing scenePos back to annotator file for further use - if moose.Annotator(self.plugin.modelRoot+'/info').modeltype == 'kkit': - x = grpChilditem.scenePos().x()/self.defaultScenewidth - y = grpChilditem.scenePos().y()/self.defaultSceneheight - else: - x = grpChilditem.scenePos().x() - y = grpChilditem.scenePos().y() - anno.x = x - anno.y = y + x = grpChilditem.scenePos().x() + y = grpChilditem.scenePos().y() + #anno.x = x + #anno.y = y if isinstance(moose.element(grpChilditem.mobj.path),PoolBase): t = moose.element(grpChilditem.mobj.path) @@ -922,18 +979,20 @@ class KineticsWidget(EditorWidgetBase): else: mobj = self.mooseId_GObj[element(mooseObject)] self.updateArrow(mobj) - elePath = moose.element(mooseObject).path - pos = elePath.find('/',1) - l = elePath[0:pos] - linfo = moose.Annotator(l+'/info') - if moose.exists(l): - #anno = moose.Annotator(linfo) - if moose.Annotator(self.plugin.modelRoot+'/info').modeltype == 'kkit': - x = mobj.scenePos().x()/self.defaultScenewidth - y = mobj.scenePos().y()/self.defaultSceneheight - else: - x = mobj.scenePos().x() - y = mobj.scenePos().y() + # elePath = moose.element(mooseObject).path + # pos = elePath.find('/',1) + # l = elePath[0:pos] + # linfo = moose.Annotator(l+'/info') + # if moose.exists(l): + # #anno = moose.Annotator(linfo) + # # if moose.Annotator(self.plugin.modelRoot+'/info').modeltype == 'kkit': + # # x = mobj.scenePos().x()/self.defaultScenewidth + # # y = mobj.scenePos().y()/self.defaultSceneheight + # # else: + # # x = mobj.scenePos().x() + # # y = mobj.scenePos().y() + # x = mobj.scenePos().x() + # y = mobj.scenePos().y() #print " x and y at 863 ",mobj.scenePos() # for gk,gv in self.qGraGrp.items(): # rectgrp = calculateChildBoundingRect(gv) @@ -952,7 +1011,11 @@ class KineticsWidget(EditorWidgetBase): else: rectcompt = calculateChildBoundingRect(v) v.setRect(rectcompt.x()-10,rectcompt.y()-10,(rectcompt.width()+20),(rectcompt.height()+20)) - + # print " position change " + # for item in self.sceneContainer.items(): + # if isinstance(item,KineticsDisplayItem): + # print item.mobj.name, moose.element(item.mobj.path+'/info').x,moose.element(item.mobj.path+'/info').y + def updateGrpSize(self,grp): compartmentBoundary = grp.rect() diff --git a/moose-gui/plugins/kkitOrdinateUtil.py b/moose-gui/plugins/kkitOrdinateUtil.py index dd3b967d4b17c4fa94a9ad0e8130b724ed876c6c..4d27c9ad5f6909056ea8311642c41694810652cb 100644 --- a/moose-gui/plugins/kkitOrdinateUtil.py +++ b/moose-gui/plugins/kkitOrdinateUtil.py @@ -5,9 +5,13 @@ __version__ = "1.0.0" __maintainer__ = "HarshaRani" __email__ = "hrani@ncbs.res.in" __status__ = "Development" -__updated__ = "Oct 18 2017" +__updated__ = "Oct 26 2018" ''' +2018 +Oct 26: xfer molecules are not put into screen +Sep 28: to zoom the kkit co-ordinates a factor of w=1000 and h=800 is multipled here +2017 Oct 18: moved some function to kkitUtil getxyCord, etc function are added ''' @@ -20,6 +24,8 @@ import numpy as np import networkx as nx from kkitUtil import getRandColor,colorCheck,findCompartment, findGroup, findGroup_compt, mooseIsInstance from PyQt4.QtGui import QColor +import re +import moose._moose as moose def getxyCord(xcord,ycord,list1): for item in list1: @@ -198,20 +204,20 @@ def setupMeshObj(modelRoot): # n =n +1 for compt in wildcardFind(modelRoot+'/##[ISA=ChemCompt]'): for m in wildcardFind(compt.path+'/##[ISA=PoolBase]'): - grp_cmpt = findGroup_compt(m) - - xcord.append(xyPosition(m.path+'/info','x')) - ycord.append(xyPosition(m.path+'/info','y')) - if isinstance(element(grp_cmpt),Neutral): - if isinstance(element(m.parent),EnzBase): - populateMeshEntry(meshEntry,grp_cmpt,"cplx",m) - else: - populateMeshEntry(meshEntry,grp_cmpt,"pool",m) - else: - if isinstance(element(m.parent),EnzBase): - populateMeshEntry(meshEntry,compt,"cplx",m) + if not re.search("xfer",m.name): + grp_cmpt = findGroup_compt(m) + xcord.append(xyPosition(m.path+'/info','x')) + ycord.append(xyPosition(m.path+'/info','y')) + if isinstance(element(grp_cmpt),Neutral): + if isinstance(element(m.parent),EnzBase): + populateMeshEntry(meshEntry,grp_cmpt,"cplx",m) + else: + populateMeshEntry(meshEntry,grp_cmpt,"pool",m) else: - populateMeshEntry(meshEntry,compt,"pool",m) + if isinstance(element(m.parent),EnzBase): + populateMeshEntry(meshEntry,compt,"cplx",m) + else: + populateMeshEntry(meshEntry,compt,"pool",m) for r in wildcardFind(compt.path+'/##[ISA=ReacBase]'): rgrp_cmpt = findGroup_compt(r) @@ -384,7 +390,6 @@ def countitems(mitems,objtype): return(uniqItems,countuniqItems) def recalculatecoordinatesforKkit(mObjlist,xcord,ycord): - positionInfoExist = not(len(np.nonzero(xcord)[0]) == 0 \ and len(np.nonzero(ycord)[0]) == 0) @@ -399,8 +404,8 @@ def recalculatecoordinatesforKkit(mObjlist,xcord,ycord): if moose.exists(objInfo): Ix = (xyPosition(objInfo,'x')-xmin)/(xmax-xmin) Iy = (ymin-xyPosition(objInfo,'y'))/(ymax-ymin) - element(objInfo).x = Ix - element(objInfo).y = Iy + element(objInfo).x = Ix*1000 + element(objInfo).y = Iy*800 def xyPosition(objInfo,xory): try: diff --git a/moose-gui/plugins/kkitUtil.py b/moose-gui/plugins/kkitUtil.py index b7dde1b7cc061f53c9075db806ac4fce9ba32117..8aee47ee97d7df30766ad58b3694a3c40706c4fe 100644 --- a/moose-gui/plugins/kkitUtil.py +++ b/moose-gui/plugins/kkitUtil.py @@ -5,10 +5,12 @@ __version__ = "1.0.0" __maintainer__ = "HarshaRani" __email__ = "hrani@ncbs.res.in" __status__ = "Development" -__updated__ = "Sep 17 2018" +__updated__ = "Oct 11 2018" ''' 2018 +Oct 11: when collision is handled an update of position is done +Sep 28: spell corrected cyclMesh to cylMesh Sep 17: when vertical or horizontal layout is applied for group, compartment size is recalculated Sep 11: group size is calculated based on sceneBoundingRect for compartment size 2017 @@ -131,7 +133,6 @@ def moveX(reference, collider, layoutPt, margin): layoutPt.drawLine_arrow(itemignoreZooming=False) def handleCollisions(compartments, moveCallback, layoutPt,margin = 5.0): - print " handelCollision" if len(compartments) is 0 : return compartments = sorted(compartments, key = lambda c: c.sceneBoundingRect().center().x()) print " compartment ",compartments @@ -155,6 +156,7 @@ def handleCollisions(compartments, moveCallback, layoutPt,margin = 5.0): else: rectcompt = calculateChildBoundingRect(v) v.setRect(rectcompt.x()-10,rectcompt.y()-10,(rectcompt.width()+20),(rectcompt.height()+20)) + layoutPt.positionChange(compartments) return handleCollisions(compartments, moveCallback, layoutPt,margin) def calculateChildBoundingRect(compt): @@ -208,7 +210,7 @@ def mooseIsInstance(melement, classNames): return element(melement).__class__.__name__ in classNames def findCompartment(melement): - while not mooseIsInstance(melement, ["CubeMesh", "CyclMesh"]): + while not mooseIsInstance(melement, ["CubeMesh", "CylMesh"]): melement = melement.parent return melement @@ -218,6 +220,6 @@ def findGroup(melement): return melement def findGroup_compt(melement): - while not (mooseIsInstance(melement, ["Neutral","CubeMesh", "CyclMesh"])): + while not (mooseIsInstance(melement, ["Neutral","CubeMesh", "CylMesh"])): melement = melement.parent - return melement \ No newline at end of file + return melement diff --git a/moose-gui/plugins/kkitViewcontrol.py b/moose-gui/plugins/kkitViewcontrol.py index 06fa8b7f9cca58f97379d0af03360736abe6e311..877f305e4a61cc2d3774365f7c8e5351149491c6 100644 --- a/moose-gui/plugins/kkitViewcontrol.py +++ b/moose-gui/plugins/kkitViewcontrol.py @@ -5,11 +5,15 @@ __version__ = "1.0.0" __maintainer__ = "HarshaRani" __email__ = "hrani@ncbs.res.in" __status__ = "Development" -__updated__ = "Sep 7 2018" +__updated__ = "Oct 27 2018" ''' 2018 - +Oct 27 : When group is moved within another group, outer group is resize inturn compartmet is also resized +Oct 10 : Groups are handled with collision detection, + messagebox when object moved from one group to another + layout updated when object moved etc +Sep 18 : one can close the messagebox if doesn't want to plot Sep 07 : when object qgraphicalparent is changed then connecting arrow's parent also need to be changed Jun 08 : If object is moved from one group or compartment to another group or with in same Compartment, then both at moose level (group or compartment path is updated ) and qt level the setParentItem is set @@ -34,6 +38,8 @@ from kkitUtil import * #from setsolver import * from PyQt4 import QtSvg from moose import utils +from functools import partial + class GraphicalView(QtGui.QGraphicsView): @@ -191,6 +197,18 @@ class GraphicalView(QtGui.QGraphicsView): else: #If right button clicked self.resetState() + # if itemType == GROUP_INTERIOR: + # print " self.layoutPt.qGraGrp ",item, item.childItems() + # grouplist = [] + # for i in item.childItems(): + # if isinstance(i,KineticsDisplayItem): + # grouplist.append(i) + # popupmenu = QtGui.QMenu('PopupMenu', self) + # popupmenu.addAction("LinearLayout", lambda : handleCollisions(list(grouplist), moveX, self.layoutPt)) + # popupmenu.addAction("VerticalLayout" ,lambda : handleCollisions(list(grouplist), moveMin, self.layoutPt )) + # popupmenu.exec_(self.mapToGlobal(event.pos())) + # self.layoutPt.updateGrpSize(item) + if itemType == GROUP_BOUNDARY: popupmenu = QtGui.QMenu('PopupMenu', self) popupmenu.addAction("DeleteGroup", lambda : self.deleteGroup(item,self.layoutPt)) @@ -267,6 +285,9 @@ class GraphicalView(QtGui.QGraphicsView): final = self.mapToScene(event.pos()) displacement = final - initial item.moveBy(displacement.x(), displacement.y()) + if isinstance(item.parentItem(),GRPItem): + self.layoutPt.updateGrpSize(item.parentItem()) + self.layoutPt.positionChange(item.mobj.path) self.state["press"]["pos"] = event.pos() @@ -333,7 +354,6 @@ class GraphicalView(QtGui.QGraphicsView): #if already built model then compartment size depends on max and min objects rectcompt = calculateChildBoundingRect(v) v.setRect(rectcompt.x()-10,rectcompt.y()-10,(rectcompt.width()+20),(rectcompt.height()+20)) - else: #When group is moved then compartment need to be update which is done here if isinstance(self.state["release"]["item"], KineticsDisplayItem): @@ -356,7 +376,6 @@ class GraphicalView(QtGui.QGraphicsView): movedGraphObj = self.state["press"]["item"].parent() if actionType == "move": - if itemType == EMPTY: self.objectpullback("Empty",item,movedGraphObj,xx,yy) @@ -377,7 +396,14 @@ class GraphicalView(QtGui.QGraphicsView): if moose.exists(grpCmpt.mobj.path+'/'+parentPool.name+'/'+movedGraphObj.name): self.objectpullback("Enzyme",grpCmpt,movedGraphObj,xx,yy) else: - self.moveObjSceneParent(grpCmpt,movedGraphObj,item.pos(),self.mapToScene(event.pos())) + reply = QtGui.QMessageBox.question(self, "Moving the Object",'Do want to move \'{movedGraphObj}\' \n from \'{parent}\' to \'{grpCmpt}\''.format(movedGraphObj=movedGraphObj.mobj.name,parent= movedGraphObj.parentItem().mobj.name,grpCmpt=grpCmpt.mobj.name), + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) + if reply == QtGui.QMessageBox.No: + movedGraphObj.moveBy(-xx,-yy) + self.layoutPt.updateArrow(movedGraphObj) + + else: + self.moveObjSceneParent(grpCmpt,movedGraphObj,item.pos(),self.mapToScene(event.pos())) else: self.objectpullback("Enzymeparent",grpCmpt,movedGraphObj,xx,yy) else: @@ -385,9 +411,32 @@ class GraphicalView(QtGui.QGraphicsView): if moose.exists(grpCmpt.mobj.path+'/'+movedGraphObj.mobj.name): self.objectpullback("All",grpCmpt,movedGraphObj,xx,yy) else: - self.moveObjSceneParent(grpCmpt,movedGraphObj,item.pos(),self.mapToScene(event.pos())) + reply = QtGui.QMessageBox.question(self, "Moving the Object",'Do want to move \'{movedGraphObj}\' \n from \'{parent}\' to \'{grpCmpt}\''.format(movedGraphObj=movedGraphObj.mobj.name,parent= movedGraphObj.parentItem().mobj.name,grpCmpt=grpCmpt.mobj.name), + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) + if reply == QtGui.QMessageBox.No: + movedGraphObj.moveBy(-xx,-yy) + self.layoutPt.updateArrow(movedGraphObj) + else: + self.moveObjSceneParent(grpCmpt,movedGraphObj,item.pos(),self.mapToScene(event.pos())) else: '''Same compt/grp to which it was belong to ''' + if isinstance(movedGraphObj,KineticsDisplayItem): + itemPath = movedGraphObj.mobj.path + if moose.exists(itemPath): + iInfo = itemPath+'/info' + anno = moose.Annotator(iInfo) + eventpos = self.mapToScene(event.pos()) + itempos = item.pos() + x = eventpos.x()+(15/2)#-itempos.x() + y = eventpos.y()+(2/2)#-itempos.y() + anno.x = x + anno.y = y + self.layoutPt.updateArrow(itemPath) + QtGui.QApplication.setOverrideCursor(QtGui.QCursor(Qt.Qt.ArrowCursor)) + self.layoutPt.updateGrpSize(movedGraphObj.parentItem()) + self.layoutPt.positionChange(movedGraphObj.mobj) + self.updateScale(self.iconScale) + if isinstance(grpCmpt,GRPItem): self.layoutPt.updateGrpSize(movedGraphObj.parentItem()) elif isinstance(grpCmpt,ComptItem): @@ -420,29 +469,18 @@ class GraphicalView(QtGui.QGraphicsView): elif actionType == "plot": element = moose.element(item.parent().mobj.path) if isinstance (element,moose.PoolBase): - if moose.exists(self.modelRoot+'/data/graph_0'): - self.graph = moose.element(self.modelRoot+'/data/graph_0') - else: - moose.Neutral(self.modelRoot+'/data') - moose.Neutral(self.modelRoot+'/data/graph_0') - self.graph = moose.element(self.modelRoot+'/data/graph_0') - plotType = "Conc" msgBox = QtGui.QMessageBox() msgBox.setText('What to plot?') - msgBox.addButton(QtGui.QPushButton('Number'), QtGui.QMessageBox.YesRole) - msgBox.addButton(QtGui.QPushButton('Concentration'), QtGui.QMessageBox.NoRole) - ret = msgBox.exec_() - if ret == 0: - plotType = "N" - tablePath = moose.utils.create_table_path(moose.element(self.modelRoot), self.graph, element, plotType) - table = moose.utils.create_table(tablePath, element, plotType,"Table2") - ''' - tablePath = utils.create_table_path(moose.element(self.modelRoot), self.graph, element, "Conc") - table = utils.create_table(tablePath, element, "Conc","Table2") - ''' - self.layoutPt.plugin.view.getCentralWidget().plotWidgetContainer.plotAllData() - reply = QtGui.QMessageBox.information(self, "plot Object","Plot is added to Graph1", - QtGui.QMessageBox.Ok) + self.pushButtonNumber = QtGui.QPushButton(('Number'))#, QtGui.QMessageBox.YesRole) + self.pushButtonConc = QtGui.QPushButton('Concentration')#, QtGui.QMessageBox.NoRole + self.pushButtonConc.setAutoDefault(False) + self.pushButtonNumber.setAutoDefault(False) + msgBox.addButton(self.pushButtonNumber,QtGui.QMessageBox.YesRole) + msgBox.addButton(self.pushButtonConc,QtGui.QMessageBox.NoRole) + msgBox.buttonClicked.connect(partial(self.onClicked, str(self.modelRoot),element)) + msgBox.exec_() + self.removeConnector() + elif actionType == "clone": if self.state["move"]["happened"]: QtGui.QApplication.setOverrideCursor(QtGui.QCursor(Qt.Qt.ArrowCursor)) @@ -552,7 +590,33 @@ class GraphicalView(QtGui.QGraphicsView): popupmenu.addAction("Move", lambda: self.moveSelections()) popupmenu.exec_(self.mapToGlobal(event.pos())) self.resetState() - + + def onClicked(self,modelRoot,element, btn): + self.modelRoot = modelRoot + if moose.exists(self.modelRoot+'/data/graph_0'): + self.graph = moose.element(self.modelRoot+'/data/graph_0') + else: + moose.Neutral(self.modelRoot+'/data') + moose.Neutral(self.modelRoot+'/data/graph_0') + self.graph = moose.element(self.modelRoot+'/data/graph_0') + + plotType = "Conc" + if btn.text() == "Number": + plotType = "N" + else: + plotType = "Conc" + + tablePath = moose.utils.create_table_path(moose.element(self.modelRoot), self.graph, element, plotType) + table = moose.utils.create_table(tablePath, element, plotType,"Table2") + ''' + tablePath = utils.create_table_path(moose.element(self.modelRoot), self.graph, element, "Conc") + table = utils.create_table(tablePath, element, "Conc","Table2") + ''' + self.layoutPt.plugin.view.getCentralWidget().plotWidgetContainer.plotAllData() + reply = QtGui.QMessageBox.information(self, "plot Object","Plot is added to Graph1", + QtGui.QMessageBox.Ok) + self.removeConnector() + def objectpullback(self,messgtype,item,movedGraphObj,xx,yy): if messgtype.lower() != "empty": desObj = item.mobj.className @@ -601,43 +665,33 @@ class GraphicalView(QtGui.QGraphicsView): if isinstance(moose.element(es), EnzBase): if moose.element(moose.element(es).neighbors['enzDest'][0]) == movedGraphObj.mobj: enzGrapObj = self.layoutPt.mooseId_GObj[moose.element(es)] - testx = enzGrapObj.scenePos().x() - testy = enzGrapObj.scenePos().y() + enzXpos = enzGrapObj.scenePos().x() + enzYpos = enzGrapObj.scenePos().y() enzGrapObj.setParentItem(item) - enzGrapObj.setGeometry(testx,testy, + enzGrapObj.setGeometry(enzXpos,enzYpos, enzGrapObj.gobj.boundingRect().width(), enzGrapObj.gobj.boundingRect().height()) for ll in self.layoutPt.object2line[enzGrapObj]: ll[0].setParentItem(item) self.layoutPt.updateArrow(enzGrapObj) - #enzGrapObj.setGeometry(testx,testy, - # enzGrapObj.gobj.boundingRect().width(), - # enzGrapObj.gobj.boundingRect().height()) ''' Re-calculting the group size after the movement ''' + self.setnewPostion(movedGraphObj,itempos,eventpos) + self.layoutPt.updateArrow(movedGraphObj) + self.layoutPt.positionChange(movedGraphObj.mobj) if isinstance(prevPar,GRPItem): if item != prevPar: + self.layoutPt.updateGrpSize(prevPar) self.layoutPt.updateGrpSize(item) - self.setnewPostion(movedGraphObj,itempos,eventpos) - self.layoutPt.updateArrow(movedGraphObj) - + def setnewPostion(self,movedGraphObj,itempos,eventpos): if isinstance(movedGraphObj,KineticsDisplayItem): itemPath = movedGraphObj.mobj.path if moose.exists(itemPath): iInfo = itemPath+'/info' anno = moose.Annotator(iInfo) - # eventpos = self.mapToScene(event.pos()) - # itempos = item.pos() x = eventpos.x()+(15/2)-itempos.x() y = eventpos.y()+(2/2)-itempos.y() - if moose.Annotator(self.layoutPt.plugin.modelRoot+'/info').modeltype == 'kkit': - anno.x = x/self.layoutPt.defaultScenewidth - anno.y = y/self.layoutPt.defaultSceneheight - else: - anno.x = x - anno.y = y - #item = movedGraphObj if isinstance(movedGraphObj,ReacItem) or isinstance(movedGraphObj,EnzItem) or isinstance(movedGraphObj,MMEnzItem): movedGraphObj.setGeometry(x,y, movedGraphObj.gobj.boundingRect().width(), @@ -865,6 +919,7 @@ class GraphicalView(QtGui.QGraphicsView): #if ( isinstance(v, PoolItem) or isinstance(v, ReacItem) or isinstance(v, EnzItem) or isinstance(v, CplxItem) ): if isinstance(v,KineticsDisplayItem): v.setFlag(QtGui.QGraphicsItem.ItemIgnoresTransformations, on) + def keyPressEvent(self,event): key = event.key() self.removeConnector() @@ -899,20 +954,6 @@ class GraphicalView(QtGui.QGraphicsView): item.refresh(scale) xpos = item.pos().x() ypos = item.pos().y() - if isinstance(item,ReacItem) or isinstance(item,EnzItem) or isinstance(item,MMEnzItem): - item.setGeometry(xpos,ypos, - item.gobj.boundingRect().width(), - item.gobj.boundingRect().height()) - elif isinstance(item,CplxItem): - item.setGeometry(item.gobj.boundingRect().width()/2,item.gobj.boundingRect().height(), - item.gobj.boundingRect().width(), - item.gobj.boundingRect().height()) - elif isinstance(item,PoolItem) or isinstance(item, PoolItemCircle): - item.setGeometry(xpos, ypos,item.gobj.boundingRect().width() - +PoolItem.fontMetrics.width(' '), - item.gobj.boundingRect().height()) - item.bg.setRect(0, 0, item.gobj.boundingRect().width()+PoolItem.fontMetrics.width(' '), item.gobj.boundingRect().height()) - self.layoutPt.drawLine_arrow(itemignoreZooming=False) self.layoutPt.comptChildrenBoundingRect()