2 Copyright (C) 1997-2017 JDERobot Developers Team 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Library General Public License for more details. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. 17 Authors : Okan Asik (asik.okan@gmail.com) 18 Pushkal Katara (katarapushkal@gmail.com) 21 from visualstates.gui.state.guistate
import StateGraphicsItem
22 from visualstates.core.transition
import Transition
23 from visualstates.core.namespace
import Namespace
24 from xml.dom.minidom
import Node
27 def __init__(self, id, name, initial, namespace, parent=None):
58 return self.parent.namespace
78 self.children.append(child)
82 self.children.remove(child)
92 self.originTransitions.append(tran)
96 self.originTransitions.remove(tran)
103 self.destTransitions.append(tran)
107 self.destTransitions.remove(tran)
112 self.graphicsItem.posChanged.connect(self.
posChanged)
113 self.graphicsItem.setRunning(self.
isRunning)
120 scenePos = stateItem.scenePos()
121 self.
x = scenePos.x()
122 self.
y = scenePos.y()
127 copy.code = self.
code 133 elements = parentElement.getElementsByTagName(elementName)
134 if len(elements) > 0:
135 if len(elements[0].childNodes) > 0:
136 return elements[0].childNodes[0].nodeValue
141 for (name, value)
in stateElement.attributes.items():
144 elif name ==
'initial':
145 self.
initial = (value ==
'True')
147 self.
name = stateElement.getElementsByTagName(
'name')[0].childNodes[0].nodeValue
149 self.
x = float(stateElement.getElementsByTagName(
'posx')[0].childNodes[0].nodeValue)
150 self.
y = float(stateElement.getElementsByTagName(
'posy')[0].childNodes[0].nodeValue)
155 namespace = Namespace(
'',
'')
156 namespace.parse(stateElement.getElementsByTagName(
'namespace')[0])
159 allChildTransitions = []
161 stateTransitions = []
163 for childNode
in stateElement.childNodes:
164 if childNode.nodeType == Node.ELEMENT_NODE:
165 if childNode.tagName ==
'state':
167 transitionNodes = childState.parse(childNode)
171 statesById[childState.id] = childState
172 allChildTransitions = allChildTransitions + transitionNodes
173 elif childNode.tagName ==
'transition':
174 stateTransitions.append(childNode)
177 for tranNode
in allChildTransitions:
178 transition = Transition(0,
'transition')
179 transition.parse(tranNode, statesById)
182 return stateTransitions
185 stateElement = doc.createElement(
'state')
186 stateElement.setAttribute(
'initial', str(self.
initial))
187 stateElement.setAttribute(
'id', str(self.
id))
188 posxElement = doc.createElement(
'posx')
189 posxElement.appendChild(doc.createTextNode(str(self.
x)))
190 posyElement = doc.createElement(
'posy')
191 posyElement.appendChild(doc.createTextNode(str(self.
y)))
192 stateElement.appendChild(posxElement)
193 stateElement.appendChild(posyElement)
194 nameElement = doc.createElement(
'name')
195 nameElement.appendChild(doc.createTextNode(self.
name))
196 stateElement.appendChild(nameElement)
197 codeElement = doc.createElement(
'code')
198 codeElement.appendChild(doc.createTextNode(self.
code))
199 stateElement.appendChild(codeElement)
200 timeElement = doc.createElement(
'timestep')
202 stateElement.appendChild(timeElement)
204 stateElement.appendChild(self.namespace.createNode(doc))
208 tranElement = tran.createElement(doc)
209 stateElement.appendChild(tranElement)
212 child.createElement(doc, stateElement)
214 if parentElement
is not None:
215 parentElement.appendChild(stateElement)
241 childTransitions = []
243 childTransitions += child.getOriginTransitions()
244 return childTransitions
249 self.graphicsItem.setRunning(self.
isRunning)
def removeChild(self, child)
def addChild(self, child)
def setParent(self, parent)
def removeDestTransition(self, tran)
def setTimeStep(self, timestep)
def removeOriginTransition(self, tran)
def __init__(self, id, name, initial, namespace, parent=None)
def posChanged(self, stateItem)
def getChildrenTransitions(self)
def getDestTransitions(self)
def resetGraphicsItem(self)
def parseElement(self, elementName, parentElement)
def createElement(self, doc, parentElement=None)
def getParentNamespace(self)
def parse(self, stateElement)
def addDestTransition(self, tran)
def setInitial(self, initial)
def getInitialChild(self)
def getGraphicsItem(self)
def setRunning(self, status)
def getOriginTransitions(self)
def addOriginTransition(self, tran)
def setNamespace(self, namespace)