def open(self, fullPath): self.setFullPath(fullPath) doc = minidom.parse(fullPath) rootNode = doc.getElementsByTagName('VisualStates')[0].getElementsByTagName('state')[0] rootState = State(0, 'root', True) rootState.parse(rootNode) # parse configs config = None configElement = doc.getElementsByTagName('VisualStates')[0].getElementsByTagName('config')[0] if configElement.getAttribute('type') == str(ROS): config = RosConfig() config.loadNode(configElement) config.type = ROS elif configElement.getAttribute('type') == str(JDEROBOTCOMM): config = JdeRobotConfig() config.loadNode(configElement) config.type = JDEROBOTCOMM libraries = [] # parse libraries libraryElements = doc.getElementsByTagName('VisualStates')[0].getElementsByTagName('libraries') if len(libraryElements) > 0: libraryElements = libraryElements[0].getElementsByTagName('library') for libElement in libraryElements: libraries.append(libElement.childNodes[0].nodeValue) return (rootState, config, libraries)
def open(self, fullPath): self.setFullPath(fullPath) doc = minidom.parse(fullPath) rootNode = doc.getElementsByTagName('VisualStates')[0].getElementsByTagName('state')[0] rootState = State(0, 'root', True) rootState.parse(rootNode) # parse configs config = None if len(doc.getElementsByTagName('VisualStates')[0].getElementsByTagName('config')) > 0: configElement = doc.getElementsByTagName('VisualStates')[0].getElementsByTagName('config')[0] if configElement.getAttribute('type') == str(ROS): config = RosConfig() config.loadNode(configElement) config.type = ROS elif configElement.getAttribute('type') == str(JDEROBOTCOMM): config = JdeRobotConfig() config.loadNode(configElement) config.type = JDEROBOTCOMM libraries = [] # parse libraries libraryElements = doc.getElementsByTagName('VisualStates')[0].getElementsByTagName('libraries') if len(libraryElements) > 0: libraryElements = libraryElements[0].getElementsByTagName('library') for libElement in libraryElements: libraries.append(libElement.childNodes[0].nodeValue) return (rootState, config, libraries)
def addState(self, id, name, initial, x, y, parentId): if parentId is not None: self.states[id] = State(id, name, initial, self.states[parentId]) self.states[parentId].addChild(self.states[id]) parentItem = self.treeModel.getByDataId(parentId) # print('parent:' + str(parentItem)) else: self.states[id] = State(id, name, initial, None) if id == 0: self.rootState = self.states[id] self.states[id].setPos(x, y)
def __init__(self, parent=None): super(QMainWindow, self).__init__() self.setWindowTitle("VisualStates") self.configDialog = None # root state self.rootState = State(0, "root", True) self.activeState = self.rootState # create status bar self.statusBar() self.createMenu() self.createTreeView() self.createStateCanvas() self.setGeometry(0, 0, 800, 600) self.show() self.fileManager = FileManager() self.libraries = [] self.config = None self.interfaceHeaderMap = Interfaces.getInterfaces()
def mouseReleaseEvent(self, qGraphicsSceneMouseEvent): # if we were editing the state text next mouse release should disable text editing # and should not add a new state or transition if self.stateTextEditingStarted: self.stateTextEditingStarted = False QGraphicsScene.mouseReleaseEvent(self, qGraphicsSceneMouseEvent) return if self.operationType == OpType.ADDSTATE and qGraphicsSceneMouseEvent.button( ) == Qt.LeftButton: selectedItems = self.items(qGraphicsSceneMouseEvent.scenePos()) if len(selectedItems) == 0: sIndex = self.getStateIndex() state = State(sIndex, 'state ' + str(sIndex), False, self.activeState) state.setPos(qGraphicsSceneMouseEvent.scenePos().x(), qGraphicsSceneMouseEvent.scenePos().y()) self.addStateItem(state.getGraphicsItem()) self.origin = None elif self.operationType == OpType.ADDTRANSITION and qGraphicsSceneMouseEvent.button( ) == Qt.LeftButton: selectedItems = self.items(qGraphicsSceneMouseEvent.scenePos()) if len(selectedItems) > 0: # get the parent item = self.getParentItem(selectedItems[0]) if isinstance(item, StateGraphicsItem): if self.origin != None: self.destination = item tIndex = self.getTransitionIndex() tran = Transition(tIndex, 'transition ' + str(tIndex), self.origin.stateData, self.destination.stateData) self.addTransitionItem(tran.getGraphicsItem()) self.origin = None else: self.origin = item else: self.origin = None else: self.origin = None else: if self.operationType == OpType.OPENAUTOMATA: self.operationType = self.prevOperationType QGraphicsScene.mouseReleaseEvent(self, qGraphicsSceneMouseEvent)
def newAction(self): self.automataScene.clearScene() self.treeModel.removeAll() # create new root state self.rootState = State(0, 'root', True) self.automataScene.setActiveState(self.rootState) self.automataScene.resetIndexes()
def mouseReleaseEvent(self, qGraphicsSceneMouseEvent): # if we were editing the state text next mouse release should disable text editing # and should not add a new state or transition if self.stateTextEditingStarted: self.stateTextEditingStarted = False QGraphicsScene.mouseReleaseEvent(self, qGraphicsSceneMouseEvent) return if self.operationType == OpType.ADDSTATE and qGraphicsSceneMouseEvent.button() == Qt.LeftButton: selectedItems = self.items(qGraphicsSceneMouseEvent.scenePos()) if len(selectedItems) == 0: sIndex = self.getStateIndex() state = State(sIndex, 'state ' + str(sIndex), False, self.activeState) state.setPos(qGraphicsSceneMouseEvent.scenePos().x(), qGraphicsSceneMouseEvent.scenePos().y()) self.addStateItem(state.getGraphicsItem()) self.origin = None elif self.operationType == OpType.ADDTRANSITION and qGraphicsSceneMouseEvent.button() == Qt.LeftButton: selectedItems = self.items(qGraphicsSceneMouseEvent.scenePos()) if len(selectedItems) > 0: # get the parent item = self.getParentItem(selectedItems[0]) if isinstance(item, StateGraphicsItem): if self.origin != None: self.destination = item tIndex = self.getTransitionIndex() tran = Transition(tIndex, 'transition ' + str(tIndex), self.origin.stateData, self.destination.stateData) self.addTransitionItem(tran.getGraphicsItem()) self.origin = None else: self.origin = item else: self.origin = None else: self.origin = None else: if self.operationType == OpType.OPENAUTOMATA: self.operationType = self.prevOperationType QGraphicsScene.mouseReleaseEvent(self, qGraphicsSceneMouseEvent)
def newAction(self): self.automataScene.clearScene() self.treeModel.removeAll() # create new root state self.rootState = State(0, 'root', True) self.automataScene.setActiveState(self.rootState) self.automataScene.resetIndexes() self.libraries = [] self.config = None self.functions = '' self.variables = ''