State.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2014
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include <QObject>
26 #include <QMap>
27 #include <QMetaType>
28 
29 #include <memory>
30 #include "StateParameter.h"
31 #include "Transition.h"
33 #include "stateinstance/EndState.h"
34 #include "SignalType.h"
35 #include "Event.h"
36 
39 #include <ArmarXCore/interface/statechart/StatechartIce.h>
40 
42 {
43 
44  class State;
45  class DynamicRemoteStateClass;
46  using StatePtr = std::shared_ptr<State>;
47  using DynamicRemoteStateClassPtr = std::shared_ptr<DynamicRemoteStateClass>;
48  using TransitionList = QList<TransitionPtr>;
49  using CTransitionList = QList<TransitionCPtr>;
50  using StateInstanceMap = QMap<QString, StateInstancePtr>;
51 
52  class State :
53  public QObject,
54  public Logging,
55  public std::enable_shared_from_this<State>
56  {
57  Q_OBJECT
58  public:
59  const QRectF margin;
60 
61  explicit State(const QString& uuid = "");
62  ~State() override;
63  /**
64  * Annotates the State object created by parseXml() before with references to other states.
65  */
66  void addReferences(const QMap<QString, armarx::statechartmodel::StatePtr>& uuidStateMap);
67 
68  QString getStateName() const
69  {
70  return stateName;
71  }
72  QString getUUID() const
73  {
74  return UUID;
75  }
76  const QString& getDescription() const
77  {
78  return description;
79  }
80  const QList<QString> getProxies() const
81  {
82  return proxies;
83  }
84  // QString getPath() const { return filePath;}
86  {
87  return inputParameters;
88  }
90  {
91  return localParameters;
92  }
95  {
96  return outputParameters;
97  }
98  CTransitionList getTransitions(bool withStartTransition = false) const;
100  {
101  return substates;
102  }
104  {
105  return activeSubstate;
106  }
110  {
111  return outgoingTransitions;
112  }
113  EventList getAllEvents() const;
114 
115  QSizeF getSize() const
116  {
117  return size;
118  }
119  virtual eStateType getType() const
120  {
121  return eNormalState;
122  }
123  bool getDirty() const
124  {
125  return dirty;
126  }
129  TransitionPtr findTransition(const QString& eventName, const QString& transitionSourceName, const QString& transitionDestinationName) const;
130  bool hasDescendant(statechartmodel::StatePtr state) const;
131 
132  static QString StateTypeToString(eStateType type);
133  void connectToSubclasses();
134 
135  bool isEditable() const;
136  signals:
137  /*
138  * @brief stateChanged
139  * name changed,
140  * parameters changed,
141  * promoted to endstate
142  * start substate changed
143  * @param state
144  * @param signalType
145  */
146  void stateChanged(statechartmodel::SignalType signalType);
147 
148  /*
149  * @brief substateChanged
150  * substate added
151  * substate removed
152  * substate moved
153  * substate resized
154  * substate instance name renamed
155  * substate
156  * @param substate
157  * @param signalType
158  */
160 
161  /*
162  * @brief transitionChanged
163  * transition added
164  * transition removed
165  * transition event changed
166  * mapping changed,
167  * target/source state changed
168  * support point changed/added/removed
169  * @param transition
170  * @param signalType
171  */
173  void outgoingTransitionChanged(const QString& eventName, statechartmodel::StatePtr stateClass, statechartmodel::SignalType signalType);
174 
175  void resized();
176  void dirtyStatusChanged(bool newStatus);
177 
178  /**
179  * @brief stateDeleted Signals that the destructor of this state was called.
180  */
181  void stateDeleted();
182 
183  public slots:
184  void setStateName(const QString& newName);
185  void setDescription(const QString& newDescription);
186  void setSize(const QSizeF& newSize);
187  void setSubstateAreaSize(const QSizeF& newSize);
188 
189  void setEditable(bool editable);
190 
191  // Substate slots
193  StateInstancePtr addSubstate(StatePtr newSubstate, QString instanceName = "", const QPointF& pos = QPointF());
194  StateInstancePtr addRemoteSubstate(StatePtr newRemoteSubstate, const QString& remoteStateOffererName, QString instanceName = "", const QPointF& pos = QPointF());
195  StateInstancePtr addDynamicRemoteSubstate(StatePtr state, QString instanceName, const QPointF& pos);
196  StateInstancePtr addEndSubstate(const QString& endstateName, const QString& eventName, const QPointF& pos = QPointF());
197 
198  bool renameSubstate(QString oldName, QString newName);
199  bool removeSubstate(StateInstancePtr substate);
200  bool removeSubstate(QString stateInstanceName);
201  StateInstancePtr replaceSubstate(QString stateInstanceName, StateInstancePtr newInstance);
202  void replaceSubstates(StateInstanceMap newSubstateList);
203 
204  void setActiveSubstate(StateInstancePtr newActiveState);
205  void clearActiveSubstates();
206  void setStartState(StateInstancePtr newStartState);
207  void setStartStateInputMapping(const ParameterMappingList& newStartStateInputMapping);
208 
209  // Parameter slots
210  void setInputParameters(const StateParameterMap& newInputParameters);
211  void setLocalParameters(const StateParameterMap& newLocalParameters);
212  void setOutputParameters(const StateParameterMap& newOutputParameters);
213 
214  // Transition slots
215  void addTransition(TransitionPtr newTransition);
216  void setTransitionMapping(TransitionCPtr transition, const ParameterMappingList& mappingToNextStateInput, const ParameterMappingList& mappingToParentLocal, const ParameterMappingList& mappingToParentOutput);
217  void setTransitionSupportPoints(statechartmodel::TransitionCPtr transition, const SupportPoints& points, const QPointPtr& labelCenterPosition = QPointPtr(), const FloatPtr& labelFontPointSize = FloatPtr());
218  void setTransitionActivated(TransitionCPtr transition);
219  void setTransitionUserCodeEnabled(TransitionCPtr transition, bool enabled = true);
220  void addDetachedTransition(const QString& eventName, StateInstancePtr sourceState);
221  void updateTransitionDestination(TransitionCPtr transition, StateInstancePtr newDest, QPointList newSupportPoints = QPointList());
222  void detachTransitionDestination(TransitionCPtr transition, QPointF floatingEndPoint);
224  void bendTransition(TransitionCPtr transition, int u, int v);
225  void replaceTransitions(TransitionList newTransitionList);
226  void addSupportPoint(TransitionCPtr transition, QPointF supportPoint);
227 
228  bool removeTransition(TransitionPtr transition);
229 
230 
231  void setOutgoingEvents(const EventList& outgoingEvents);
232  void updateTransition(const QString& eventName, statechartmodel::StatePtr stateClass, statechartmodel::SignalType signalType);
233 
234  private slots:
235  void setDirty(statechartmodel::SignalType signalType);
236  void setDirty(statechartmodel::StateInstancePtr substate, statechartmodel::SignalType signalType);
237  void setDirty(statechartmodel::TransitionCPtr transition, statechartmodel::SignalType signalType);
238  void setDirty(bool dirty);
239  protected:
240  QList<StateInstancePtr> getInstances(statechartmodel::StatePtr stateClass) const;
242  TransitionPtr getTransition(const QString& eventName, StateInstancePtr sourceInstance) const;
243  bool checkTransition(TransitionPtr transition) const;
244  bool checkSubstate(StatePtr newState) const;
246  QString stateName;
247  QString description;
248 
249  QList<QString> proxies;
250 
254 
257 
258  TransitionList transitions; /* Transition to start state has sourceState == 0 */
259  // QString filePath;?
260  QString UUID;
261  QString cppClassName;
262 
263  QSizeF size;
264  bool dirty;
265  bool editable;
266  private:
267  bool active;
268 
269  void addDetachedTransitions(StateInstancePtr instance);
270  QPointF calcDetachedTransitionLastControlPoint(StateInstancePtr instance) const;
271  QPointF calcDetachedTransitionEndPoint(StateInstancePtr instance, const QPointF& lastControlPoint) const;
272  friend class StateInstance;
273  };
274 }
275 Q_DECLARE_METATYPE(armarx::statechartmodel::StatePtr)
276 
EndState.h
armarx::statechartmodel::State::activeSubstate
StateInstancePtr activeSubstate
Definition: State.h:256
armarx::statechartmodel::DynamicRemoteStateClassPtr
std::shared_ptr< DynamicRemoteStateClass > DynamicRemoteStateClassPtr
Definition: DynamicRemoteStateClass.h:39
armarx::statechartmodel::State::stateDeleted
void stateDeleted()
stateDeleted Signals that the destructor of this state was called.
armarx::statechartmodel::StateInstance
Definition: StateInstance.h:44
armarx::statechartmodel::State::State
State(const QString &uuid="")
Definition: State.cpp:36
armarx::statechartmodel::State::addRemoteSubstate
StateInstancePtr addRemoteSubstate(StatePtr newRemoteSubstate, const QString &remoteStateOffererName, QString instanceName="", const QPointF &pos=QPointF())
Definition: State.cpp:279
armarx::QPointList
QList< QPointF > QPointList
Definition: Transition.h:39
armarx::statechartmodel::State::editable
bool editable
Definition: State.h:265
armarx::statechartmodel::State::transitionChanged
void transitionChanged(statechartmodel::TransitionCPtr transition, statechartmodel::SignalType signalType)
armarx::statechartmodel::State::replaceSubstate
StateInstancePtr replaceSubstate(QString stateInstanceName, StateInstancePtr newInstance)
Definition: State.cpp:544
armarx::statechartmodel::State::description
QString description
Definition: State.h:247
armarx::statechartmodel::State::bendTransition
void bendTransition(TransitionCPtr transition, int u, int v)
Definition: State.cpp:1268
armarx::statechartmodel::State::setTransitionMapping
void setTransitionMapping(TransitionCPtr transition, const ParameterMappingList &mappingToNextStateInput, const ParameterMappingList &mappingToParentLocal, const ParameterMappingList &mappingToParentOutput)
Definition: State.cpp:678
armarx::statechartmodel::State::getStartState
StateInstancePtr getStartState() const
Definition: State.cpp:116
armarx::statechartmodel::State::setStartState
void setStartState(StateInstancePtr newStartState)
Definition: State.cpp:397
armarx::statechartmodel::State::getDirty
bool getDirty() const
Definition: State.h:123
armarx::statechartmodel::State::setSize
void setSize(const QSizeF &newSize)
Definition: State.cpp:213
armarx::statechartmodel::State::clearActiveSubstates
void clearActiveSubstates()
Definition: State.cpp:607
armarx::statechartmodel::State::addReferences
void addReferences(const QMap< QString, armarx::statechartmodel::StatePtr > &uuidStateMap)
Annotates the State object created by parseXml() before with references to other states.
Definition: State.cpp:55
armarx::statechartmodel::State::localParameters
StateParameterMap localParameters
Definition: State.h:252
armarx::statechartmodel::TransitionPtr
std::shared_ptr< Transition > TransitionPtr
Definition: Transition.h:93
armarx::FloatPtr
std::shared_ptr< float > FloatPtr
Definition: Transition.h:40
SignalType.h
armarx::statechartmodel::State::getInputParameters
const StateParameterMap & getInputParameters() const
Definition: State.h:85
armarx::statechartmodel::State::addEndSubstate
StateInstancePtr addEndSubstate(const QString &endstateName, const QString &eventName, const QPointF &pos=QPointF())
Definition: State.cpp:353
armarx::statechartmodel::EventList
QList< EventPtr > EventList
Definition: XmlWriter.h:47
armarx::statechartmodel::State::resized
void resized()
armarx::statechartmodel::State::getOutputParameters
const StateParameterMap & getOutputParameters() const
Definition: State.h:94
armarx::statechartmodel::State::addDetachedTransition
void addDetachedTransition(const QString &eventName, StateInstancePtr sourceState)
Definition: State.cpp:753
armarx::statechartmodel::State::dirty
bool dirty
Definition: State.h:264
armarx::statechartmodel::State::StateTypeToString
static QString StateTypeToString(eStateType type)
Definition: State.cpp:1188
armarx::statechartmodel::State::updateTransitionDestination
void updateTransitionDestination(TransitionCPtr transition, StateInstancePtr newDest, QPointList newSupportPoints=QPointList())
Definition: State.cpp:770
armarx::statechartmodel::State::updateTransition
void updateTransition(const QString &eventName, statechartmodel::StatePtr stateClass, statechartmodel::SignalType signalType)
Definition: State.cpp:965
armarx::statechartmodel::State::getOutgoingEvents
const EventList & getOutgoingEvents() const
Definition: State.h:109
armarx::statechartmodel::State::removeTransition
bool removeTransition(TransitionPtr transition)
Definition: State.cpp:1069
armarx::statechartmodel::State::checkTransition
bool checkTransition(TransitionPtr transition) const
Definition: State.cpp:1086
armarx::statechartmodel::State::getTransition
TransitionPtr getTransition(const QString &eventName, StateInstancePtr sourceInstance) const
Definition: State.cpp:1055
armarx::statechartmodel::State::setLocalParameters
void setLocalParameters(const StateParameterMap &newLocalParameters)
Definition: State.cpp:642
armarx::statechartmodel::State::getTransitions
CTransitionList getTransitions(bool withStartTransition=false) const
Definition: State.cpp:90
armarx::statechartmodel::State::transitions
TransitionList transitions
Definition: State.h:258
armarx::statechartmodel::State::margin
const QRectF margin
Definition: State.h:59
armarx::statechartmodel::State::getDescription
const QString & getDescription() const
Definition: State.h:76
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::statechartmodel::State::getInputAndLocalParameters
const StateParameterMap getInputAndLocalParameters() const
Definition: State.cpp:78
armarx::QPointPtr
std::shared_ptr< QPointF > QPointPtr
Definition: Transition.h:41
armarx::statechartmodel::State::hasDescendant
bool hasDescendant(statechartmodel::StatePtr state) const
Definition: State.cpp:1155
armarx::statechartmodel::StateInstanceMap
QMap< QString, StateInstancePtr > StateInstanceMap
Definition: State.h:50
armarx::statechartmodel::State::checkSubstate
bool checkSubstate(StatePtr newState) const
Definition: State.cpp:1117
armarx::statechartmodel::State::outputParameters
StateParameterMap outputParameters
Definition: State.h:253
armarx::statechartmodel::State::detachTransitionDestination
void detachTransitionDestination(TransitionCPtr transition, QPointF floatingEndPoint)
Definition: State.cpp:813
armarx::statechartmodel::State::setStateName
void setStateName(const QString &newName)
Definition: State.cpp:103
armarx::statechartmodel::State::setDescription
void setDescription(const QString &newDescription)
Definition: State.cpp:200
armarx::statechartmodel::State::renameSubstate
bool renameSubstate(QString oldName, QString newName)
Definition: State.cpp:442
armarx::statechartmodel::State::dirtyStatusChanged
void dirtyStatusChanged(bool newStatus)
armarx::statechartmodel::State::outgoingTransitionChanged
void outgoingTransitionChanged(const QString &eventName, statechartmodel::StatePtr stateClass, statechartmodel::SignalType signalType)
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::statechartmodel
Definition: XmlWriter.h:36
armarx::statechartmodel::State::getInstances
QList< StateInstancePtr > getInstances(statechartmodel::StatePtr stateClass) const
Definition: State.cpp:1040
KITProsthesis::ProsthesisState::State
State
Definition: KITProstheticHandInterface.ice:32
StateParameter.h
armarx::statechartmodel::State::removeSubstate
bool removeSubstate(StateInstancePtr substate)
Definition: State.cpp:475
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::statechartmodel::State
Definition: State.h:52
armarx::statechartmodel::State::addDynamicRemoteSubstate
StateInstancePtr addDynamicRemoteSubstate(StatePtr state, QString instanceName, const QPointF &pos)
Definition: State.cpp:313
armarx::statechartmodel::State::getStartTransition
TransitionCPtr getStartTransition() const
Definition: State.cpp:155
armarx::statechartmodel::State::getProxies
const QList< QString > getProxies() const
Definition: State.h:80
armarx::statechartmodel::State::size
QSizeF size
Definition: State.h:263
armarx::statechartmodel::State::findTransition
TransitionPtr findTransition(TransitionCPtr t) const
Definition: State.cpp:1130
armarx::statechartmodel::State::setTransitionActivated
void setTransitionActivated(TransitionCPtr transition)
Definition: State.cpp:733
armarx::statechartmodel::State::setActiveSubstate
void setActiveSubstate(StateInstancePtr newActiveState)
Definition: State.cpp:584
armarx::statechartmodel::State::getSubstates
const StateInstanceMap & getSubstates() const
Definition: State.h:99
armarx::statechartmodel::State::addTransition
void addTransition(TransitionPtr newTransition)
Definition: State.cpp:667
armarx::statechartmodel::State::getActiveSubstate
const StateInstancePtr & getActiveSubstate() const
Definition: State.h:103
armarx::statechartmodel::State::setOutputParameters
void setOutputParameters(const StateParameterMap &newOutputParameters)
Definition: State.cpp:659
armarx::statechartmodel::State::outgoingTransitions
EventList outgoingTransitions
Definition: State.h:245
armarx::statechartmodel::State::getAllEvents
EventList getAllEvents() const
Definition: State.cpp:128
StateInstance.h
armarx::statechartmodel::CTransitionList
QList< TransitionCPtr > CTransitionList
Definition: State.h:49
armarx::statechartmodel::State::getType
virtual eStateType getType() const
Definition: State.h:119
Transition.h
ExpressionException.h
armarx::statechartmodel::TransitionList
QList< TransitionPtr > TransitionList
Definition: State.h:48
armarx::statechartmodel::State::getStateName
QString getStateName() const
Definition: State.h:68
Event.h
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::statechartmodel::State::setOutgoingEvents
void setOutgoingEvents(const EventList &outgoingEvents)
Definition: State.cpp:897
armarx::statechartmodel::State::replaceTransitions
void replaceTransitions(TransitionList newTransitionList)
Definition: State.cpp:842
armarx::statechartmodel::State::getLocalParameters
const StateParameterMap & getLocalParameters() const
Definition: State.h:89
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
ArmarXWidgetController.h
armarx::statechartmodel::State::addSubstate
StateInstancePtr addSubstate(StateInstancePtr stateInstance)
Definition: State.cpp:371
armarx::statechartmodel::State::getStartStateInputMapping
ParameterMappingList getStartStateInputMapping() const
Definition: State.cpp:122
armarx::statechartmodel::State::proxies
QList< QString > proxies
Definition: State.h:249
armarx::statechartmodel::State::UUID
QString UUID
Definition: State.h:260
armarx::statechartmodel::SignalType
SignalType
The SignalType enum.
Definition: SignalType.h:33
armarx::statechartmodel::State::connectToSubclasses
void connectToSubclasses()
Definition: State.cpp:183
armarx::statechartmodel::TransitionCPtr
std::shared_ptr< const Transition > TransitionCPtr
Definition: Transition.h:94
armarx::statechartmodel::State::setTransitionSupportPoints
void setTransitionSupportPoints(statechartmodel::TransitionCPtr transition, const SupportPoints &points, const QPointPtr &labelCenterPosition=QPointPtr(), const FloatPtr &labelFontPointSize=FloatPtr())
Definition: State.cpp:698
armarx::statechartmodel::State::cppClassName
QString cppClassName
Definition: State.h:261
armarx::statechartmodel::ParameterMappingList
QList< ParameterMappingPtr > ParameterMappingList
Definition: XmlWriter.h:49
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:46
armarx::statechartmodel::State::stateName
QString stateName
Definition: State.h:246
armarx::statechartmodel::State::setEditable
void setEditable(bool editable)
Definition: State.cpp:237
armarx::statechartmodel::State::inputParameters
StateParameterMap inputParameters
Definition: State.h:251
armarx::statechartmodel::State::addSupportPoint
void addSupportPoint(TransitionCPtr transition, QPointF supportPoint)
Definition: State.cpp:860
armarx::statechartmodel::State::stateChanged
void stateChanged(statechartmodel::SignalType signalType)
armarx::statechartmodel::State::setStartStateInputMapping
void setStartStateInputMapping(const ParameterMappingList &newStartStateInputMapping)
Definition: State.cpp:421
armarx::statechartmodel::State::~State
~State() override
Definition: State.cpp:50
armarx::statechartmodel::State::setTransitionUserCodeEnabled
void setTransitionUserCodeEnabled(TransitionCPtr transition, bool enabled=true)
Definition: State.cpp:738
armarx::SupportPoints
Definition: Transition.h:43
armarx::statechartmodel::State::isEditable
bool isEditable() const
Definition: State.cpp:195
armarx::statechartmodel::State::substateChanged
void substateChanged(statechartmodel::StateInstancePtr substate, statechartmodel::SignalType signalType)
armarx::statechartmodel::State::replaceSubstates
void replaceSubstates(StateInstanceMap newSubstateList)
Definition: State.cpp:563
armarx::statechartmodel::State::setInputParameters
void setInputParameters(const StateParameterMap &newInputParameters)
Definition: State.cpp:625
armarx::statechartmodel::State::substates
StateInstanceMap substates
Definition: State.h:255
armarx::statechartmodel::State::getUUID
QString getUUID() const
Definition: State.h:72
armarx::statechartmodel::State::getSize
QSizeF getSize() const
Definition: State.h:115
armarx::statechartmodel::State::setSubstateAreaSize
void setSubstateAreaSize(const QSizeF &newSize)
Definition: State.cpp:230