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) 20 from visualstates.gui.transition.transitiontype
import TransitionType
21 from visualstates.gui.transition.guitransition
import TransitionGraphicsItem
22 from PyQt5.QtCore
import QPointF
25 def __init__(self, id, name, origin=None, dest=None):
42 self.origin.addOriginTransition(self)
45 self.destination.addDestTransition(self)
59 self.origin.addOriginTransition(self)
64 self.destination.addDestTransition(self)
69 self.graphicsItem.posChanged.connect(self.
posChanged)
72 self.graphicsItem.updateMiddlePoints(QPointF(self.
x, self.
y))
73 self.graphicsItem.createMiddleHandle()
86 return self.origin.getNamespace()
101 if type == TransitionType.TEMPORAL
or type == TransitionType.CONDITIONAL:
112 self.
x = tranItem.midPointX
113 self.
y = tranItem.midPointY
117 self.
x = (self.origin.x + self.destination.x)/2
118 self.
y = (self.origin.y + self.destination.y)/2
121 tranElement = doc.createElement(
'transition')
122 tranElement.setAttribute(
'id', str(self.
id))
123 typeElement = doc.createElement(
'type')
124 typeElement.appendChild(doc.createTextNode(str(self.
getType())))
125 tranElement.appendChild(typeElement)
126 if self.
getType() == TransitionType.CONDITIONAL:
127 condElement = doc.createElement(
'condition')
128 condElement.appendChild(doc.createTextNode(self.
getCondition()))
129 tranElement.appendChild(condElement)
130 elif self.
getType() == TransitionType.TEMPORAL:
131 timeElement = doc.createElement(
'time')
132 timeElement.appendChild(doc.createTextNode(str(self.
getTemporalTime())))
133 tranElement.appendChild(timeElement)
134 tposxElement = doc.createElement(
'posx')
135 tposxElement.appendChild(doc.createTextNode(str(self.
x)))
136 tranElement.appendChild(tposxElement)
137 tposyElement = doc.createElement(
'posy')
138 tposyElement.appendChild(doc.createTextNode(str(self.
y)))
139 tranElement.appendChild(tposyElement)
140 nameElement = doc.createElement(
'name')
141 nameElement.appendChild(doc.createTextNode(self.
name))
142 tranElement.appendChild(nameElement)
143 originElement = doc.createElement(
'originid')
144 originElement.appendChild(doc.createTextNode(str(self.origin.id)))
145 tranElement.appendChild(originElement)
146 destinElement = doc.createElement(
'destinationid')
147 destinElement.appendChild(doc.createTextNode(str(self.destination.id)))
148 tranElement.appendChild(destinElement)
149 codeElement = doc.createElement(
'code')
150 codeElement.appendChild(doc.createTextNode(self.
getCode()))
151 tranElement.appendChild(codeElement)
154 def parse(self, transitionElement, statesById):
155 for (name, value)
in transitionElement.attributes.items():
158 self.
transitionType = int(transitionElement.getElementsByTagName(
'type')[0].childNodes[0].nodeValue)
160 self.
setTemporalTime(int(transitionElement.getElementsByTagName(
'time')[0].childNodes[0].nodeValue))
162 self.
setCondition(transitionElement.getElementsByTagName(
'condition')[0].childNodes[0].nodeValue)
163 if len(transitionElement.getElementsByTagName(
'name')[0].childNodes) > 0:
164 self.
name = transitionElement.getElementsByTagName(
'name')[0].childNodes[0].nodeValue
167 self.
x = float(transitionElement.getElementsByTagName(
'posx')[0].childNodes[0].nodeValue)
168 self.
y = float(transitionElement.getElementsByTagName(
'posy')[0].childNodes[0].nodeValue)
170 if len(transitionElement.getElementsByTagName(
'code')[0].childNodes) > 0:
171 self.
setCode(transitionElement.getElementsByTagName(
'code')[0].childNodes[0].nodeValue)
172 originId = int(transitionElement.getElementsByTagName(
'originid')[0].childNodes[0].nodeValue)
174 destinationId = int(transitionElement.getElementsByTagName(
'destinationid')[0].childNodes[0].nodeValue)
def addDestinationState(self, dest)
def parse(self, transitionElement, statesById)
def setTemporalTime(self, time)
def createElement(self, doc)
def setPosFromOriginAndDestination(self)
def resetGraphicsItem(self)
def addOriginState(self, origin)
def posChanged(self, tranItem)
def getGraphicsItem(self)
def __init__(self, id, name, origin=None, dest=None)
def setCondition(self, cond)
def getTemporalTime(self)