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