From 5cf6177cb339d7db1c06fc4c459b9126c29ed186 Mon Sep 17 00:00:00 2001
From: Dilawar Singh <dilawars@ncbs.res.in>
Date: Mon, 27 Jun 2016 16:13:14 +0530
Subject: [PATCH] Squashed 'moose-gui/' changes from bc510df..c21a557

c21a557 line color for enzparent and enz is the color of enzparent's bgcolor
c99de1b model saved to Genesis formate with co-ordinates, with addition pool obj added to existing gensis model and also once can save newly built model to Genesis format

git-subtree-dir: moose-gui
git-subtree-split: c21a557870de4402a7d4118c3e09507d2f9bdece
---
 plugins/kkit.py            | 31 +++++++++++++++++++++----------
 plugins/kkitViewcontrol.py | 15 +++++++++++----
 plugins/modelBuild.py      | 35 +++++++++++++++++++----------------
 3 files changed, 51 insertions(+), 30 deletions(-)

diff --git a/plugins/kkit.py b/plugins/kkit.py
index 44b5f27e..c25936f2 100644
--- a/plugins/kkit.py
+++ b/plugins/kkit.py
@@ -40,6 +40,7 @@ class KkitPlugin(MoosePlugin):
             self.fileinsertMenu.addAction(self.saveModelAction)
         self._menus.append(self.fileinsertMenu)
         self.getEditorView()
+        
     def SaveModelDialogSlot(self):
         type_sbml = 'SBML'
         type_genesis = 'Genesis'
@@ -71,10 +72,15 @@ class KkitPlugin(MoosePlugin):
                 elif writeerror == 0:
                      QtGui.QMessageBox.information(None,'Could not save the Model','\nThe filename could not be opened for writing')
             elif filters[str(filter_)] == 'Genesis':
-                #self.test = KkitEditorView(self).getCentralWidget().mooseId_GObj
+                self.sceneObj = KkitEditorView(self).getCentralWidget().mooseId_GObj
+                self.coOrdinates = {}
+                for k,v in self.sceneObj.items():
+                    if moose.exists(moose.element(k).path+'/info'):
+                        annoInfo = Annotator(k.path+'/info')
+                        self.coOrdinates[k] = {'x':annoInfo.x, 'y':annoInfo.y}
+
                 filename = filename
-                self.test = None
-                writeerror = write(self.modelRoot,str(filename),self.test)
+                writeerror = write(self.modelRoot,str(filename),self.coOrdinates)
                 if writeerror == False:
                     QtGui.QMessageBox.information(None,'Could not save the Model','\nCheck the file')
                 else:
@@ -305,7 +311,6 @@ class  KineticsWidget(EditorWidgetBase):
         self.editor             = None
 
     def reset(self):
-        #print "reset "
         self.createdItem = {}
         #This are created at drawLine
         self.lineItem_dict = {}
@@ -315,6 +320,7 @@ class  KineticsWidget(EditorWidgetBase):
         if hasattr(self,'sceneContainer'):
                 self.sceneContainer.clear()
         self.sceneContainer = QtGui.QGraphicsScene(self)
+        self.sceneContainer.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
         sceneDim = self.sceneContainer.itemsBoundingRect()
         # if (sceneDim.width() == 0 and sceneDim.height() == 0):
         #     self.sceneContainer.setSceneRect(0,0,30,30)
@@ -332,6 +338,7 @@ class  KineticsWidget(EditorWidgetBase):
                 self.layout().removeWidget(self.view)
            #self.sceneContainer.setSceneRect(-self.width()/2,-self.height()/2,self.width(),self.height())
             self.view = GraphicalView(self.modelRoot,self.sceneContainer,self.border,self,self.createdItem)
+
             if isinstance(self,kineticEditorWidget):
                 self.view.setRefWidget("editorView")
                 self.view.setAcceptDrops(True)
@@ -540,6 +547,8 @@ class  KineticsWidget(EditorWidgetBase):
             #Annoinfo.x = xpos
             #Annoinfo.y = -ypos 
         graphicalObj.setDisplayProperties(xpos,ypos,textcolor,bgcolor)
+        Annoinfo.x = xpos
+        Annoinfo.y = ypos
 
     def positioninfo(self,iteminfo):
         Anno = moose.Annotator(self.modelRoot+'/info')
@@ -559,10 +568,11 @@ class  KineticsWidget(EditorWidgetBase):
             y = float(element(iteminfo).getField('y'))
             #Qt origin is at the top-left corner. The x values increase to the right and the y values increase downwards \
             #as compared to Genesis codinates where origin is center and y value is upwards, that is why ypos is negated
-            if Anno.modeltype == "kkit":
-                ypos = 1.0-(y-self.ymin)*self.yratio
-            else:
-                ypos = (y-self.ymin)*self.yratio
+            # if Anno.modeltype == "kkit":
+            #     ypos = 1.0-(y-self.ymin)*self.yratio
+            # else:
+            #     ypos = (y-self.ymin)*self.yratio
+            ypos = (y-self.ymin)*self.yratio
         xpos = (x-self.xmin)*self.xratio
 
         return(xpos,ypos)
@@ -642,10 +652,11 @@ class  KineticsWidget(EditorWidgetBase):
                 pen.setColor(QtCore.Qt.red)
             elif(endtype != 'cplx'):
                 p1 = (next((k for k,v in self.mooseId_GObj.items() if v == src), None))
-                pinfo = p1.path+'/info'
+                pinfo = p1.parent.path+'/info'
                 color,bgcolor = getColor(pinfo)
                 #color = QColor(color[0],color[1],color[2])
-                pen.setColor(color)
+                pen.setColor(bgcolor)
+
         elif isinstance(source, moose.PoolBase) or isinstance(source,moose.Function):
             pen.setColor(QtCore.Qt.blue)
         elif isinstance(source,moose.StimulusTable):
diff --git a/plugins/kkitViewcontrol.py b/plugins/kkitViewcontrol.py
index 404e8934..91bcef43 100644
--- a/plugins/kkitViewcontrol.py
+++ b/plugins/kkitViewcontrol.py
@@ -27,6 +27,7 @@ class GraphicalView(QtGui.QGraphicsView):
         self.setScene(parent)
         self.modelRoot = modelRoot
         self.sceneContainerPt = parent
+        self.sceneContainerPt.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
         self.setDragMode(QtGui.QGraphicsView.RubberBandDrag)
         self.itemSelected = False
         self.customrubberBand = None
@@ -144,7 +145,6 @@ class GraphicalView(QtGui.QGraphicsView):
             initial = self.mapToScene(self.state["press"]["pos"])
             final = self.mapToScene(event.pos())
             displacement = final - initial
-            #print("Displacement", displacement)
             for item in self.selectedItems:
                 if isinstance(item, KineticsDisplayItem) and not isinstance(item,ComptItem) and not isinstance(item,CplxItem):
                     item.moveBy(displacement.x(), displacement.y())
@@ -164,6 +164,14 @@ class GraphicalView(QtGui.QGraphicsView):
                 initial = item.parent().pos()
                 final = self.mapToScene(event.pos())
                 displacement = final-initial
+                if isinstance(item.parent(),KineticsDisplayItem):
+                    itemPath = item.parent().mobj.path
+                    if moose.exists(itemPath):
+                        iInfo = itemPath+'/info'
+                        anno = moose.Annotator(iInfo)
+                        anno.x = self.mapToScene(event.pos()).x()
+                        anno.y = self.mapToScene(event.pos()).y()
+                
                 if not isinstance(item.parent(),FuncItem) and not isinstance(item.parent(),CplxItem):
                     self.removeConnector()
                     item.parent().moveBy(displacement.x(), displacement.y())
@@ -245,7 +253,6 @@ class GraphicalView(QtGui.QGraphicsView):
         self.state["release"]["mode"] = VALID
         self.state["release"]["item"] = item
         self.state["release"]["type"] = itemType
-
         clickedItemType = self.state["press"]["type"]
         if clickedItemType == ITEM:
             if not self.state["move"]["happened"]:
@@ -285,6 +292,7 @@ class GraphicalView(QtGui.QGraphicsView):
         if clickedItemType  == CONNECTOR:
             actionType = str(self.state["press"]["item"].data(0).toString())
             
+            
             if actionType == "move":
                 QtGui.QApplication.setOverrideCursor(QtGui.QCursor(Qt.Qt.ArrowCursor))
 
@@ -1127,5 +1135,4 @@ class GraphicalView(QtGui.QGraphicsView):
         if callsetupItem:
             self.layoutPt.getMooseObj()
             setupItem(self.modelRoot,self.layoutPt.srcdesConnection)
-            self.layoutPt.drawLine_arrow(False)
-
+            self.layoutPt.drawLine_arrow(False)
\ No newline at end of file
diff --git a/plugins/modelBuild.py b/plugins/modelBuild.py
index 80b77e0d..8a174efb 100644
--- a/plugins/modelBuild.py
+++ b/plugins/modelBuild.py
@@ -63,7 +63,6 @@ def checkCreate(scene,view,modelpath,mobj,string,ret_string,num,event_pos,layout
         
         poolinfo = moose.Annotator(poolObj.path+'/info')
         #Compartment's one Pool object is picked to get the font size
-
         
         qGItem = PoolItem(poolObj,itemAtView)
         layoutPt.mooseId_GObj[poolObj] = qGItem
@@ -71,12 +70,15 @@ def checkCreate(scene,view,modelpath,mobj,string,ret_string,num,event_pos,layout
         bgcolor = getRandColor()
         qGItem.setDisplayProperties(posWrtComp.x(),posWrtComp.y(),QtGui.QColor('green'),bgcolor)
         poolinfo.color = str(bgcolor.getRgb())
-        if mType == "new_kkit":
-            poolinfo.x = posWrtComp.x()
-            poolinfo.y = posWrtComp.y()
+        #if mType == "new_kkit":
+        poolinfo.x = posWrtComp.x()
+        poolinfo.y = posWrtComp.y()
         view.emit(QtCore.SIGNAL("dropped"),poolObj)
         setupItem(modelpath.path,layoutPt.srcdesConnection)
         layoutPt.drawLine_arrow(False)
+        poolinfo.x = posWrtComp.x()
+        poolinfo.y = posWrtComp.y()
+        
         #Dropping is on compartment then update Compart size
         if isinstance(mobj,moose.ChemCompt):
             compt = layoutPt.qGraCompt[moose.element(mobj)]
@@ -88,9 +90,9 @@ def checkCreate(scene,view,modelpath,mobj,string,ret_string,num,event_pos,layout
         reacinfo = moose.Annotator(reacObj.path+'/info')
         qGItem = ReacItem(reacObj,itemAtView)
         qGItem.setDisplayProperties(posWrtComp.x(),posWrtComp.y(),"white", "white")
-        if mType == "new_kkit":
-            reacinfo.x = posWrtComp.x()
-            reacinfo.y = posWrtComp.y()
+        #if mType == "new_kkit":
+        reacinfo.x = posWrtComp.x()
+        reacinfo.y = posWrtComp.y()
         layoutPt.mooseId_GObj[reacObj] = qGItem
         view.emit(QtCore.SIGNAL("dropped"),reacObj)
         setupItem(modelpath.path,layoutPt.srcdesConnection)
@@ -106,9 +108,9 @@ def checkCreate(scene,view,modelpath,mobj,string,ret_string,num,event_pos,layout
         tabinfo = moose.Annotator(tabObj.path+'/info')
         qGItem = TableItem(tabObj,itemAtView)
         qGItem.setDisplayProperties(posWrtComp.x(),posWrtComp.y(),QtGui.QColor('white'),QtGui.QColor('white'))
-        if mType == "new_kkit":
-            tabinfo.x = posWrtComp.x()
-            tabinfo.y = posWrtComp.y()
+        #if mType == "new_kkit":
+        tabinfo.x = posWrtComp.x()
+        tabinfo.y = posWrtComp.y()
         layoutPt.mooseId_GObj[tabObj] = qGItem
         view.emit(QtCore.SIGNAL("dropped"),tabObj)
         setupItem(modelpath.path,layoutPt.srcdesConnection)
@@ -128,9 +130,9 @@ def checkCreate(scene,view,modelpath,mobj,string,ret_string,num,event_pos,layout
         #print " function ", posWrtComp.x(),posWrtComp.y()
         qGItem.setDisplayProperties(posWrtComp.x(),posWrtComp.y(),QtGui.QColor('red'),QtGui.QColor('green'))
         layoutPt.mooseId_GObj[funcObj] = qGItem
-        if mType == "new_kkit":
-            funcinfo.x = posWrtComp.x()
-            funcinfo.y = posWrtComp.y()
+        #if mType == "new_kkit":
+        funcinfo.x = posWrtComp.x()
+        funcinfo.y = posWrtComp.y()
         view.emit(QtCore.SIGNAL("dropped"),funcObj)
         setupItem(modelpath.path,layoutPt.srcdesConnection)
         layoutPt.drawLine_arrow(False)
@@ -159,9 +161,10 @@ def checkCreate(scene,view,modelpath,mobj,string,ret_string,num,event_pos,layout
             posWrtComp = pos
             bgcolor = getRandColor()
             qGItem.setDisplayProperties(posWrtComp.x(),posWrtComp.y()-40,QtGui.QColor('green'),bgcolor)
-            if mType == "new_kkit":
-                enzinfo.x = posWrtComp.x()
-                enzinfo.y = posWrtComp.y()
+            #if mType == "new_kkit":
+            enzinfo.x = posWrtComp.x()
+            enzinfo.y = posWrtComp.y()
+        
             enzinfo.color = str(bgcolor.name())
             e = moose.Annotator(enzinfo)
             #e.x = posWrtComp.x()
-- 
GitLab