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