Skip to content

Commit

Permalink
Fixes complex import issue
Browse files Browse the repository at this point in the history
Fixes issue #17.
  • Loading branch information
pushkalkatara committed Jun 4, 2018
1 parent 0904186 commit 44a8fa4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
7 changes: 5 additions & 2 deletions core/state.py
Expand Up @@ -43,11 +43,14 @@ def setID(self, id):

def getID(self):
return self.id

def setPos(self, x, y):
self.x = x
self.y = y

def setParent(self, parent):
self.parent = parent

def addChild(self, child):
if child not in self.children:
self.children.append(child)
Expand Down Expand Up @@ -110,7 +113,7 @@ def parseElement(self, elementName, parentElement):
if len(elements[0].childNodes) > 0:
return elements[0].childNodes[0].nodeValue
return ''

def parse(self, stateElement):
# parse attributes of the state
for (name, value) in stateElement.attributes.items():
Expand Down
5 changes: 3 additions & 2 deletions gui/automata/automatascene.py
Expand Up @@ -196,6 +196,7 @@ def removeStateItem(self, stateItem):

self.stateRemoved.emit(stateItem)

"""
def importItems(self, stateItem):
transitions = []
for child in stateItem.getChildren():
Expand All @@ -204,6 +205,7 @@ def importItems(self, stateItem):
for tran in transitions:
self.addTransitionItem(tran.getGraphicsItem(),False)
"""

def mouseReleaseEvent(self, qGraphicsSceneMouseEvent):
# if we were editing the state text next mouse release should disable text editing
Expand Down Expand Up @@ -243,11 +245,10 @@ def mouseReleaseEvent(self, qGraphicsSceneMouseEvent):
else:
self.origin = None

# Feature to add? While clicking on the active state paste all the states
elif self.operationType == OpType.IMPORTSTATE and qGraphicsSceneMouseEvent.button() == Qt.LeftButton and self.operationData != None:
selectedItems = self.items(qGraphicsSceneMouseEvent.scenePos())
if len(selectedItems) == 0:
self.operationData.setPos(qGraphicsSceneMouseEvent.scenePos().x(),
qGraphicsSceneMouseEvent.scenePos().y())
self.importItems(self.operationData)
self.setLastIndexes(self.activeState)
self.operationData = None
Expand Down
7 changes: 5 additions & 2 deletions gui/tree/treemodel.py
Expand Up @@ -153,9 +153,12 @@ def removeAll(self):
self.rootNode.removeChildren()
self.layoutChanged.emit()

def loadFromRoot(self, rootState):
def loadFromRoot(self, rootState, parentState=None):
for child in rootState.getChildren():
self.insertStateData(child, QColor(Qt.white), self.getByDataId(rootState.id))
if parentState:
self.insertStateData(child, QColor(Qt.white), self.getByDataId(parentState.id))
else:
self.insertStateData(child, QColor(Qt.white), self.getByDataId(rootState.id))
self.loadFromRoot(child)

def setAllBackgroundByParentId(self, color, parentId):
Expand Down
19 changes: 16 additions & 3 deletions gui/visualstates.py
Expand Up @@ -249,6 +249,13 @@ def transitionAction(self):
self.automataScene.setOperationType(OpType.ADDTRANSITION)

def importAction(self):
"""
Step 1 - Get Updated IDs
Step 2 - Add imported root state as children of the activeState
Step 3 - Set parent of imported root states as activeState
Step 4 - Load Complex States into tree model to display all in tree model.
Step 5 - Update Indexs.
"""
fileDialog = QFileDialog(self)
fileDialog.setWindowTitle("Import VisualStates File")
fileDialog.setViewMode(QFileDialog.Detail)
Expand All @@ -258,8 +265,14 @@ def importAction(self):
if fileDialog.exec_():
file = self.fileManager.open(fileDialog.selectedFiles()[0])
#Verify Here configs and functions and aux vars
state = self.importManager.updateIDs(file[0], self.automataScene.getStateIndex())
self.automataScene.setOperationType(OpType.IMPORTSTATE, state)
importedState = self.importManager.updateIDs(file[0], self.automataScene.getStateIndex())
for state in importedState.getChildren():
self.activeState.addChild(state)
state.setParent(self.activeState)
self.treeModel.loadFromRoot(importedState, self.activeState)
self.automataScene.setActiveState(self.rootState)
self.automataScene.setLastIndexes(self.rootState)


def timerAction(self):
if self.activeState is not None:
Expand Down Expand Up @@ -409,7 +422,7 @@ def activeStateChanged(self):
def upButtonClicked(self):
if self.activeState != None:
if self.activeState.parent != None:
# print('parent name:' + self.activeState.parent.name)
#print(self.activeState.parent.id)
self.automataScene.setActiveState(self.activeState.parent)

def getStateById(self,state, id):
Expand Down

0 comments on commit 44a8fa4

Please sign in to comment.