IceStateConverter.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 Clara Scherer
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 <string>
26#include <vector>
27
28#include <ArmarXCore/interface/statechart/StatechartIce.h>
29
30#include "StateWatcher.h"
31#include "model/State.h"
32#include "model/Transition.h"
33
34namespace armarx
35{
37 {
38 public:
39 /**
40 * @brief IceStateConverter Creates a converter whose model's top state is state.
41 * @param state The top state of the internal model
42 */
46
47 /**
48 * @brief Converts the given ice model into a statechartmodel. This is then accesible via
49 * getTopState().
50 * @param iceBase The StateIceBase that is the top state of the ice model that shall be converted
51 */
52 void convert(StateIceBasePtr iceBase);
53
54 /**
55 * @brief getTopState Returns the top state of the internal model that was converted from an ice model.
56 * @return The top state of the internal model.
57 */
59
60 void setStateWatcher(StateWatcherPtr watcher);
61
62 std::map<std::string, std::pair<statechartmodel::StateInstancePtr, StateIceBasePtr>>
63 getCompleteStateMap() const;
64
65 private:
66 /**
67 * @brief topState The top state of the model.
68 */
70
71 /**
72 * @brief Map with all states with their global state id, for quick access
73 */
74 std::map<std::string,
75 std::pair<armarx::statechartmodel::StateInstancePtr, armarx::StateIceBasePtr>>
76 completeStateMap;
77
78 /**
79 * @brief convert Converts iceBase into a statechartmodel state and saves the conversion result in modelState.
80 * @param iceBase A state from the ice model
81 * @param modelState The corresponding state from the statechartmodel
82 */
83 void convert(StateIceBasePtr iceBase, statechartmodel::StateInstancePtr modelState);
84
85 /**
86 * @brief updateState Updates the state in the model (incrementally if possible). Requires both states to be equal.
87 * @param iceBase The state maintained by ice.
88 * @param modelState The state contained by the model.
89 */
90 void updateState(StateIceBasePtr iceBase, statechartmodel::StateInstancePtr modelState);
91
92 /**
93 * @brief resetState Completely resets modelState to fit iceBase.
94 * @param iceBase The state maintained by ice.
95 * @param modelState The state contained by the model.
96 */
97 void resetState(StateIceBasePtr iceBase, statechartmodel::StateInstancePtr modelState);
98
99 /**
100 * @brief stateEqual Checks whether the states are equal. Two states are equal if they have
101 * the same name or, if not, have the same transitions
102 * @param iceBase The state maintained by ice.
103 * @param modelState The state contained by the model.
104 * @return Returns true if both states are equal.
105 */
106 bool stateEqual(StateIceBasePtr iceBase, statechartmodel::StateInstancePtr modelState);
107
108
109 /**
110 * @brief transitionEqual Tests whether two transitions are equal. Two transitions are considered
111 * considered equal if the are triggered by the same event.
112 * @param iceTransition The transition delivered by ice.
113 * @param modelTransition The transition contained in the statechartmodel.
114 * @return true if both transitions are equal.
115 */
116 bool transitionEqual(TransitionIceBase iceTransition,
117 statechartmodel::TransitionPtr modelTransition);
118 /**
119 * @brief sameTransitions Checks whether the ice transitions are the same as the model transitions, even if they are in
120 * a different order.
121 * @param iceTransitions The vector of transitions belonging to the iceBaseState.
122 * @param modelTransitions The list of transitions belonging to the state in the model.
123 * @return
124 */
125 bool sameTransitions(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
126
127
128 /**
129 * @brief updateTransitions (Incrementally) updates the model state's transitions to match those of the iceBase.
130 */
131 void updateTransitions(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
132 /**
133 * @brief updateSubstates (Incrementally) updates modelState's substates to match those of iceBase.
134 */
135 void updateSubstates(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
136 /**
137 * @brief updateStartState (Incrementally) updates modelState's start state to match the one of iceBase.
138 */
139 void updateStartState(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
140 /**
141 * @brief updateActiveSubstate (Incrementally) updates the modelState's active substate to match the one of iceBase.
142 */
143 void updateActiveSubstate(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
144 /**
145 * @brief updateStateName (Incrementally) updates modelState's state name to match the one of iceBase.
146 */
147 void updateStateAttributes(StateIceBasePtr iceBase,
149
150 void updateTransitionFromAll(TransitionIceBase newTrans,
151 statechartmodel::StatePtr modelState);
152 void updateSingleTransition(TransitionIceBase newTrans,
153 statechartmodel::StatePtr modelState);
154 //evtl. (bei allen/manchen) update Funktionen bool zurückgeben um anzuzeigen,
155 //ob das einfach so geändert werden kann oder alles neu übergeben werden muss?
156
157 /**
158 * @brief resetTransitions Resets modelState's transitions to match those of iceBase.
159 */
160 void resetTransitions(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
161 /**
162 * @brief resetSubstates Resets modelState's substates to match those of iceBase.
163 */
164 void resetSubstates(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
165 /**
166 * @brief resetParameters Resets modelState's parameters to match those of iceBase.
167 */
168 void resetParameters(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
169 /**
170 * @brief resetStartState Resets modelState's start state to match the one of iceBase.
171 */
172 void resetStartState(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
173 /**
174 * @brief resetActiveSubstate Resets modelState's active substate to match the one of iceBase.
175 */
176 void resetActiveSubstate(StateIceBasePtr iceBase, statechartmodel::StatePtr modelState);
177 /**
178 * @brief resetStateName Resets modelState's state name to match the one of iceBase.
179 */
180 void resetStateAttributes(StateIceBasePtr iceBase,
182
183
185 convertToModelParameterMap(armarx::StateParameterMap iceMap);
186 using stringVector = std::vector<std::string>;
187 /**
188 * @brief sortTransitionNames Sorts the names of ice and statechartmodel transitions alphabetically.
189 * @param iceTransitions A List of ice transitions
190 * @param modelTransitions A List of statechartmodel transitions
191 * @return A pair of string vectors.
192 * The first Component are the names of the ice transitions sorted alphabetically.
193 * The second component are the names of the statechartmodel transitions sorted alphabetically.
194 */
195 std::pair<stringVector, stringVector>
196 sortTransitionNames(TransitionTable iceTransitions,
197 statechartmodel::CTransitionList modelTransitions);
198 /**
199 * @brief compareIceStates Operator '<' on the states' names.
200 * @param l A statechartmodel state
201 * @param r Another statechartmodel state
202 * @return l->stateName < r->stateName
203 */
204 static bool compareIceStates(armarx::AbstractStateIceBasePtr l,
205 armarx::AbstractStateIceBasePtr r);
206
207 /**
208 * @brief findSubstateByName Finds the substate of state with name 'name'.
209 * @param state The parent of the sought substate
210 * @param name The name of the sought substate
211 * @return The InstantancePtr to the corresponding substate.
212 */
214 QString name);
215
216 private:
217 StateWatcherPtr watcher;
218 };
219
220 using IceStateConverterPtr = std::shared_ptr<IceStateConverter>;
221
222} // namespace armarx
statechartmodel::StateInstancePtr getTopState()
getTopState Returns the top state of the internal model that was converted from an ice model.
void convert(StateIceBasePtr iceBase)
Converts the given ice model into a statechartmodel.
void setStateWatcher(StateWatcherPtr watcher)
std::map< std::string, std::pair< statechartmodel::StateInstancePtr, StateIceBasePtr > > getCompleteStateMap() const
IceStateConverter(statechartmodel::StatePtr state=statechartmodel::StatePtr(new statechartmodel::State()))
IceStateConverter Creates a converter whose model's top state is state.
std::shared_ptr< State > StatePtr
Definition State.h:48
QMap< QString, StateParameterPtr > StateParameterMap
std::shared_ptr< StateInstance > StateInstancePtr
QList< TransitionCPtr > CTransitionList
Definition State.h:51
std::shared_ptr< Transition > TransitionPtr
Definition Transition.h:90
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< IceStateConverter > IceStateConverterPtr
IceInternal::Handle< StateWatcher > StateWatcherPtr