Skip to content

Commit

Permalink
changes made after addition of groups, some of action are implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
hrani committed Oct 18, 2017
1 parent 24cba7d commit 83be02e
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 45 deletions.
44 changes: 27 additions & 17 deletions plugins/kkit.py
Expand Up @@ -6,8 +6,10 @@
__maintainer__ = "HarshaRani"
__email__ = "hrani@ncbs.res.in"
__status__ = "Development"
__updated__ = "Sep 26 2017"
__updated__ = "Oct 18 2017"
'''
'''
import math
import sys
from PyQt4 import QtGui, QtCore, Qt
Expand Down Expand Up @@ -846,7 +848,7 @@ def positionChange(self,mooseObject):
self.updateArrow(j)
self.updateArrow(rectChilditem)
elif element(mooseObject).className == 'Neutral':
for k,v in self.qGraGrp.items():
for k,v in self.qGraGrp.items():
if k.path == element(mooseObject).path:
for grpChilditem in v.childItems():
if isinstance(grpChilditem, KineticsDisplayItem):
Expand All @@ -857,22 +859,28 @@ def positionChange(self,mooseObject):
x = grpChilditem.scenePos().x()/self.defaultScenewidth
y = grpChilditem.scenePos().y()/self.defaultSceneheight
else:
print "Check for other models "
x,y = 1,1
#print "Check for other models at grp level ",grpChilditem.scenePos()
x = grpChilditem.scenePos().x()
y = grpChilditem.scenePos().y()
#print " x and y at 863 ",grpChilditem.scenePos()
anno.x = x
anno.y = y
# if isinstance(moose.element(grpChilditem.mobj.path),PoolBase):
# t = moose.element(grpChilditem.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(grpChilditem)
#print " anno ",anno, anno.x, anno.y
if isinstance(moose.element(grpChilditem.mobj.path),PoolBase):
t = moose.element(grpChilditem.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(grpChilditem)
# grpcompt = self.qGraCompt[self.objPar[k]]
# rectcompt = calculateChildBoundingRect(grpcompt)
# rectcompt = calculateChildBoundingRect(grpcompt)
rectgrp = calculateChildBoundingRect(v)
v.setRect(rectgrp.x()-10,rectgrp.y()-10,(rectgrp.width()+20),(rectgrp.height()+20))

else:
mobj = self.mooseId_GObj[element(mooseObject)]
self.updateArrow(mobj)
Expand All @@ -886,8 +894,10 @@ def positionChange(self,mooseObject):
x = mobj.scenePos().x()/self.defaultScenewidth
y = mobj.scenePos().y()/self.defaultSceneheight
else:
print "Check for other models "
x,y = 1,1
#print "Check for other models ",mobj.scenePos()
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)
# grpBoundingRect = gv.boundingRect()
Expand Down
9 changes: 5 additions & 4 deletions plugins/kkitOrdinateUtil.py
Expand Up @@ -5,9 +5,10 @@
__maintainer__ = "HarshaRani"
__email__ = "hrani@ncbs.res.in"
__status__ = "Development"
__updated__ = "Sep 18 2017"
__updated__ = "Oct 18 2017"

'''
Oct 18: moved some function to kkitUtil
getxyCord, etc function are added
'''
import collections
Expand All @@ -17,7 +18,7 @@
from networkx.drawing.nx_agraph import graphviz_layout
import numpy as np
import networkx as nx
from kkitUtil import getRandColor,colorCheck
from kkitUtil import getRandColor,colorCheck,findCompartment, findGroup, findGroup_compt, mooseIsInstance
from PyQt4.QtGui import QColor

def getxyCord(xcord,ycord,list1):
Expand All @@ -36,7 +37,7 @@ def xyPosition(objInfo,xory):
return(float(element(objInfo).getField(xory)))
except ValueError:
return (float(0))

'''
def mooseIsInstance(melement, classNames):
return element(melement).__class__.__name__ in classNames
Expand All @@ -55,7 +56,7 @@ def findGroup_compt(melement):
while not (mooseIsInstance(melement, ["Neutral","CubeMesh", "CyclMesh"])):
melement = melement.parent
return melement

'''
def populateMeshEntry(meshEntry,parent,types,obj):
#print " parent ",parent, "types ",types, " obj ",obj
try:
Expand Down
32 changes: 31 additions & 1 deletion plugins/kkitUtil.py
@@ -1,4 +1,16 @@
from moose import Annotator
__author__ = "HarshaRani"
__credits__ = ["Upi Lab"]
__license__ = "GPL3"
__version__ = "1.0.0"
__maintainer__ = "HarshaRani"
__email__ = "hrani@ncbs.res.in"
__status__ = "Development"
__updated__ = "Oct 18 2017"

'''
Oct 18 some of the function moved to this file from kkitOrdinateUtils
'''
from moose import Annotator,element
from kkitQGraphics import PoolItem, ReacItem,EnzItem,CplxItem,GRPItem,ComptItem
from PyQt4 import QtCore,QtGui,QtSvg
from PyQt4.QtGui import QColor
Expand Down Expand Up @@ -168,3 +180,21 @@ def calculateChildBoundingRect(compt):
calculateRectcompt = compt.rect()

return calculateRectcompt

def mooseIsInstance(melement, classNames):
return element(melement).__class__.__name__ in classNames

def findCompartment(melement):
while not mooseIsInstance(melement, ["CubeMesh", "CyclMesh"]):
melement = melement.parent
return melement

def findGroup(melement):
while not mooseIsInstance(melement, ["Neutral"]):
melement = melement.parent
return melement

def findGroup_compt(melement):
while not (mooseIsInstance(melement, ["Neutral","CubeMesh", "CyclMesh"])):
melement = melement.parent
return melement
107 changes: 84 additions & 23 deletions plugins/kkitViewcontrol.py
Expand Up @@ -5,9 +5,14 @@
__maintainer__ = "HarshaRani"
__email__ = "hrani@ncbs.res.in"
__status__ = "Development"
__updated__ = "Oct 3 2017"
__updated__ = "Oct 17 2017"

'''
Oct 17: 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
-If object is moved to Empty place or not allowed place in the GUI its moved back to origin position
-also some clean up when object is just clicked in QsvgItem and v/s clicked and some action done
-with Rubber selection if object are moved then group size is updated
Oct 3 : At mousePressEvent, a clean way of checking on what object mouse press Event happened is checked.
This is after group is added where Group Interior and Boundary is checked, with in groupInterior if click in
on COMPARTMENT BOUNDARY is clicked then COMPARTMENT_BOUNDARY is return, else top most group object is returned.
Expand Down Expand Up @@ -110,15 +115,18 @@ def resolveItem(self, items, position):
groupList = []
comptInteriorfound = False
comptBoundary = []


# If clicked , moved and dropped then drop object should not take polygonItem it shd take Goup or compartment
#(this is checked is self.state["move"]), else qpolygonItem then deleting the connection b/w 2 objects
#move is True the
for item in items:
# if isinstance(item, QtGui.QGraphicsPixmapItem):
# return (item, CONNECTOR)
if isinstance(item, QtSvg.QGraphicsSvgItem):
return (item, CONNECTOR)

if isinstance(item, QtGui.QGraphicsPolygonItem):
return (item, CONNECTION)

if not self.state["move"]["happened"]:
for item in items:
if isinstance(item, QtGui.QGraphicsPolygonItem):
return (item, CONNECTION)

for item in items:
if hasattr(item, "name"):
Expand Down Expand Up @@ -197,13 +205,14 @@ def editorMouseMoveEvent(self,event):
self.state["move"]["happened"] = False
return
if self.move:
#This part of the code is when rubberband selection is done and move option is selected
initial = self.mapToScene(self.state["press"]["pos"])
# final = self.mapToScene(event.pos())
# displacement = final - initial
# 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())
# self.layoutPt.positionChange(item.mobj.path)
final = self.mapToScene(event.pos())
displacement = final - initial
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())
self.layoutPt.positionChange(item.mobj.path)
self.state["press"]["pos"] = event.pos()
return

Expand Down Expand Up @@ -300,6 +309,9 @@ def editorMouseReleaseEvent(self,event):
if self.modelRoot.find('/',1) > 0:
l = self.modelRoot[0:self.modelRoot.find('/',1)]
linfo = moose.Annotator(l+'/info')
for k,v in self.layoutPt.qGraGrp.items():
rectgrp = calculateChildBoundingRect(v)
v.setRect(rectgrp.x()-10,rectgrp.y()-10,(rectgrp.width()+20),(rectgrp.height()+20))
for k, v in self.layoutPt.qGraCompt.items():
rectcompt = v.childrenBoundingRect()
if linfo.modeltype == "new_kkit":
Expand All @@ -313,6 +325,7 @@ def editorMouseReleaseEvent(self,event):
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):
if not moose.element(self.state["press"]["item"].mobj) == moose.element(self.state["release"]["item"].mobj):
self.populate_srcdes( self.state["press"]["item"].mobj
Expand All @@ -328,18 +341,61 @@ def editorMouseReleaseEvent(self,event):
pressItem = self.state["press"]["item"]

if actionType == "move":

QtGui.QApplication.setOverrideCursor(QtGui.QCursor(Qt.Qt.ArrowCursor))
#If any case, move is not valide need to move back the object to original position is store and calculation
initscenepos = self.state["press"]["scenepos"]
finialscenepos = pressItem.parent().scenePos()
xx = finialscenepos.x()-initscenepos.x()
yy = finialscenepos.y()-initscenepos.y()

if itemType == EMPTY:
initscenepos = self.state["press"]["scenepos"]
finialscenepos = pressItem.parent().scenePos()
xx = finialscenepos.x()-initscenepos.x()
yy = finialscenepos.y()-initscenepos.y()
pressItem.parent().moveBy(-xx,-yy)
self.layoutPt.updateArrow(pressItem.parent())
QtGui.QMessageBox.warning(None,'Could not move the object', "The object can't be moved to empty space")
else:
pressItem = self.state["press"]["item"]
if isinstance(self.state["press"]["item"], Qt.QGraphicsSvgItem):
pressedItem = self.state["press"]["item"]
releaseItem = self.state["release"]["item"]
sgrp = findGroup(pressItem.parent().mobj)
scmpt = findCompartment(pressItem.parent().mobj)
dgrp = findGroup(releaseItem.mobj)
dcmpt = findCompartment(releaseItem.mobj)
if isinstance(dgrp,Neutral):
# This is obj moved from group to
# - another group
# - into compartment
if sgrp.path != dgrp.path:
if scmpt.volume == dcmpt.volume:
#With in same compartment but different group
moose.move(pressItem.parent().mobj,dgrp)
lKey = self.layoutPt.qGraGrp[dgrp]
pressItem.parent().setParentItem(lKey)
self.layoutPt.positionChange(sgrp)
self.layoutPt.positionChange(dgrp)
else:
#If object is tried to move to diff compartment,
# then object will be pulled back to origin position which it was moved from
pressItem.parent().moveBy(-xx,-yy)
self.layoutPt.updateArrow(pressItem.parent())
QtGui.QMessageBox.warning(None,'Could not move the object', "The object can't be moved to empty space")
elif isinstance(dcmpt,CubeMesh):
# This is obj moved from group into compartment
if scmpt.path != dcmpt.path:
if scmpt.volume == dcmpt.volume:
moose.move(pressItem.parent().mobj,dcmpt)
lKey = self.layoutPt.qGraCompt[dcmpt]
pressItem.parent().setParentItem(lKey)
self.layoutPt.positionChange(sgrp)
self.layoutPt.positionChange(dgrp)
else:
#If object is tried to move to diff compartment,
# then object will be pulled back to origin position which it was moved from
pressItem.parent().moveBy(-xx,-yy)
self.layoutPt.updateArrow(pressItem.parent())
QtGui.QMessageBox.warning(None,'Could not move the object', "The object can't be moved to empty space")
else:
print " Check what moved when! does it reaches this condition"

self.layoutPt.positionChange(item.mobj)
self.updateScale(self.iconScale)

Expand Down Expand Up @@ -389,12 +445,16 @@ def editorMouseReleaseEvent(self,event):
posWrtComp = self.mapToScene(event.pos())
itemAtView = self.sceneContainerPt.itemAt(self.mapToScene(event.pos()))
self.removeConnector()
if isinstance(itemAtView,ComptItem):
if isinstance(itemAtView,ComptItem) or isinstance(itemAtView, GRPItem):
#Solver should be deleted
## if there is change in 'Topology' of the model
## or if copy has to made then oject should be in unZombify mode
deleteSolver(self.modelRoot)
lKey = [key for key, value in self.layoutPt.qGraCompt.iteritems() if value == itemAtView][0]
#As name is suggesting, if item is Compartment, then search in qGraCompt and if group then qGraGrp
if isinstance(itemAtView,ComptItem):
lKey = [key for key, value in self.layoutPt.qGraCompt.iteritems() if value == itemAtView][0]
if isinstance (itemAtView, GRPItem):
lKey = [key for key, value in self.layoutPt.qGraGrp.iteritems() if value == itemAtView][0]
iR = 0
iP = 0
t = moose.element(cloneObj.parent().mobj)
Expand Down Expand Up @@ -476,8 +536,9 @@ def editorMouseReleaseEvent(self,event):
for item in selectedItems:
if isinstance(item, KineticsDisplayItem) and not isinstance(item,ComptItem):
item.setSelected(True)
self.customrubberBand.hide()
self.customrubberBand = None
if self.customrubberBand != None:
self.customrubberBand.hide()
self.customrubberBand = None
popupmenu = QtGui.QMenu('PopupMenu', self)

popupmenu.addAction("Delete", lambda: self.deleteSelections(x0,y0,x1,y1))
Expand Down

0 comments on commit 83be02e

Please sign in to comment.