TransitionController.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 RobotTrajectoryDesigner::gui-plugins::Controller::TransitionController
17 * \author Max Beddies
18 * \date 2018
19 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 #ifndef TRANSITIONCONTROLLER_H
23 #define TRANSITIONCONTROLLER_H
24 #include <QDoubleValidator>
25 #include <QListWidget>
26 #include <QMetaType>
27 #include <QVariant>
28 
29 #include "../Util/WheelEventFilter.h"
30 #include "../View/TransitionTab.h"
31 #include "AbstractController.h"
32 
33 namespace armarx
34 {
35  /**
36  * @brief Struct defining a transition which can be stored as QVariant
37  * in a QListWidgetItem
38  */
39  typedef struct GuiTransition
40  {
41  double duration;
42  double start;
43  int it;
44 
45  /**
46  * @brief Overload '==' operator for GuiTransition struct
47  * @param transition GuiTransition to compare with
48  * @return true, iff all values of both GuiTransitions are equal, otherwise false
49  */
50  bool
52  {
53  return (duration == transition.duration) && (start == transition.start) &&
54  (it == transition.it);
55  }
56 
57  /**
58  * @brief Checks whether all values of a transition
59  * are greater than or equal to zero
60  * @return true iff the transition is valid
61  */
62  bool
64  {
65  return (duration >= 0) && (start >= 0) && (it >= 0);
66  }
67  } GuiTransition;
68 
69  /**
70  * @class TransitionController
71  * @brief Subcontroller which handles all user interaction with the transition
72  * tab in the GUI, communicates with other controllers via signals
73  * and slots
74  */
76  {
77  Q_OBJECT
78 
79  public:
80  /**
81  * @brief @see AbstractController
82  */
83  void onInitComponent() override;
84 
85  /**
86  * @brief @see AbstractController
87  */
88  void onConnectComponent() override;
89 
90  /**
91  * @brief @see AbstractController
92  */
93  void onDisconnectComponent() override;
94 
95  /**
96  * @brief @see AbstractController
97  */
98  void onExitComponent() override;
99 
100  /**
101  * @brief Creates a new TransitionController and assigns a TransitionTab to handle
102  * @param guiTransitionTab Pointer to the TransitionTab whose user interaction
103  * is handled by the TransitionController
104  */
105  TransitionController(TransitionTabPtr guiTransitionTab);
106 
107  /**
108  * @brief Getter for the TransitionTab pointer to guiTransitionTab
109  * @return A Pointer to the guiTransitionTab
110  */
112 
113  /**
114  * @brief Setter for the TransitionTab pointer to guiTransitionTab
115  * @param guiTransitionTab Pointer to the TransitionTab whose user interaction
116  * is handled by the TransitionController
117  */
118  void setGuiTransitionTab(TransitionTabPtr guiTransitionTab);
119 
120  public slots:
121  /*
122  * Changed parameters from QString name, QVariant userData
123  * to int start, int end, double duration
124  * to set the QVariant data within this method
125  */
126  /**
127  * @brief Adds a new transition to the list widget
128  * @param index Index of the transition
129  * @param duration Duration of the transition
130  * @param start Start time of the transition
131  * @param interpolation Index of the interpolation
132  */
133  void addTransition(int index, double duration, double start, int interpolation);
134 
135  /**
136  * @brief Removes the transition at a given index from the list widget
137  * @param index Index of the transition
138  */
139  void removeTransition(int index);
140 
141  /**
142  * @brief Updates the currently selected transition
143  * @param index Index of the currently selected transition in the list widget
144  */
146 
147  /**
148  * @brief Connected with signals from other controllers, sets all
149  * values of the transition at a given index
150  * @param transition Index of the transition
151  * @param duration Duration of the transition
152  * @param start Start time of the transition
153  * @param it Index of the interpolation of the transition
154  */
155  void setTransitionData(int index, double duration, double start, int it);
156 
157  /**
158  * @brief Retranslates the guiTransitionTab
159  */
160  void retranslateGui();
161 
162  /**
163  * @brief Removes all items of the transition list
164  */
165  void clearTransitionList();
166 
167  private slots:
168  /**
169  * @brief Updates the currently selected transition
170  * @param item Currently selected transition in the list widget
171  */
172  void updateSelectedTransition(QListWidgetItem* item);
173 
174  /**
175  * @brief Sets the duration of the currently selected transition
176  */
177  void setDurationValue();
178 
179  /**
180  * @brief Sets the interpolation of the currently selected transition
181  * @param index Index of the interpolation
182  */
183  void setInterpolation(int index);
184 
185  /**
186  * @brief Enables or disables the duration, interpolation and list widget
187  * @param enable Determines whether to enable or disable the duration, interpolation and list widget
188  */
189  void enableAll(bool enable);
190 
191  signals:
192  /**
193  * @brief Notifies other controllers about changes of the duration of
194  * the given transition
195  * @param index Index of the transition
196  * @param duration New duration value of the transition
197  */
198  void changedDuration(int transition, double duration);
199 
200  /**
201  * @brief Notifies other controllers about changes of the interpolation
202  * type of the given transition
203  * @param index Index of the transition
204  * @param it New interpolation index of the transition
205  */
206  void changedInterpolation(int index, int it);
207 
208 
210 
211  private:
212  TransitionTabPtr guiTransitionTab;
213 
214  /**
215  * @brief Auxiliary method checking whether a list widget contains certain data,
216  * namely a certain GuiTransition
217  * @param list QListWidget to check
218  * @param transition GuiTransition to check for
219  * @return true, if the list contains the data otherwise return false
220  */
221  bool contains(QListWidget* list, GuiTransition transition);
222 
223  /**
224  * @brief Initializes the interpolation combo box
225  */
226  void initInterpolationComboBox();
227 
228  //@Max eingefügt von @Tim dadurch: Reihenfolge Item == Text Item
229  void changeTextListWidgetItems();
230  };
231 
232  using TransitionControllerPtr = std::shared_ptr<TransitionController>;
233 } // namespace armarx
234 
235 Q_DECLARE_METATYPE(armarx::GuiTransition)
236 
237 #endif // TRANSITIONCONTROLLER_H
armarx::GuiTransition::start
double start
Definition: TransitionController.h:42
armarx::GuiTransition
Struct defining a transition which can be stored as QVariant in a QListWidgetItem.
Definition: TransitionController.h:39
index
uint8_t index
Definition: EtherCATFrame.h:59
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
armarx::GuiTransition::isValid
bool isValid()
Checks whether all values of a transition are greater than or equal to zero.
Definition: TransitionController.h:63
armarx::TransitionController::getGuiTransitionTab
TransitionTabPtr getGuiTransitionTab()
Getter for the TransitionTab pointer to guiTransitionTab.
Definition: TransitionController.cpp:95
armarx::TransitionController::addTransition
void addTransition(int index, double duration, double start, int interpolation)
Adds a new transition to the list widget.
Definition: TransitionController.cpp:110
armarx::TransitionController
Subcontroller which handles all user interaction with the transition tab in the GUI,...
Definition: TransitionController.h:75
armarx::TransitionController::onDisconnectComponent
void onDisconnectComponent() override
Definition: TransitionController.cpp:76
armarx::TransitionController::onExitComponent
void onExitComponent() override
Definition: TransitionController.cpp:82
armarx::TransitionControllerPtr
std::shared_ptr< TransitionController > TransitionControllerPtr
Definition: TransitionController.h:232
armarx::TransitionController::retranslateGui
void retranslateGui()
Retranslates the guiTransitionTab.
Definition: TransitionController.cpp:271
AbstractController.h
armarx::TransitionController::selectedTransitionChanged
void selectedTransitionChanged(int index)
TransitionTabPtr
std::shared_ptr< TransitionTab > TransitionTabPtr
Definition: TransitionTab.h:52
armarx::TransitionController::setGuiTransitionTab
void setGuiTransitionTab(TransitionTabPtr guiTransitionTab)
Setter for the TransitionTab pointer to guiTransitionTab.
Definition: TransitionController.cpp:101
armarx::TransitionController::clearTransitionList
void clearTransitionList()
Removes all items of the transition list.
Definition: TransitionController.cpp:277
armarx::TransitionController::TransitionController
TransitionController(TransitionTabPtr guiTransitionTab)
Creates a new TransitionController and assigns a TransitionTab to handle.
Definition: TransitionController.cpp:87
armarx::TransitionController::updateSelectedTransition
void updateSelectedTransition(int index)
Updates the currently selected transition.
Definition: TransitionController.cpp:172
armarx::TransitionController::onInitComponent
void onInitComponent() override
Definition: TransitionController.cpp:32
armarx::GuiTransition::duration
double duration
Definition: TransitionController.h:41
armarx::TransitionController::removeTransition
void removeTransition(int index)
Removes the transition at a given index from the list widget.
Definition: TransitionController.cpp:137
armarx::TransitionController::changedInterpolation
void changedInterpolation(int index, int it)
Notifies other controllers about changes of the interpolation type of the given transition.
armarx::TransitionController::setTransitionData
void setTransitionData(int index, double duration, double start, int it)
Connected with signals from other controllers, sets all values of the transition at a given index.
Definition: TransitionController.cpp:243
armarx::GuiTransition
struct armarx::GuiTransition GuiTransition
Struct defining a transition which can be stored as QVariant in a QListWidgetItem.
armarx::TransitionController::onConnectComponent
void onConnectComponent() override
Definition: TransitionController.cpp:52
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::GuiTransition::operator==
bool operator==(GuiTransition transition)
Overload '==' operator for GuiTransition struct.
Definition: TransitionController.h:51
armarx::GuiTransition::it
int it
Definition: TransitionController.h:43
armarx::AbstractController
Abstract controller providing a set of methods which must be implemented by every controller.
Definition: AbstractController.h:37
armarx::TransitionController::changedDuration
void changedDuration(int transition, double duration)
Notifies other controllers about changes of the duration of the given transition.