SimulatorControlGuiPlugin.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::MemoryX::WorkingMemoryGuiPlugin
17* @author Nikolaus Vahrenkamp (vahrenkamp at kit dot edu)
18* @copyright 2012
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21
22*/
23
24#pragma once
25
26/** ArmarX headers **/
28
31
34
35#include <ArmarXSimulation/gui-plugins/SimulatorControlGuiPlugin/ui_SimulatorControlGuiPlugin.h>
36
37/** Qt headers **/
38#include <QCheckBox>
39#include <QMainWindow>
40#include <QSignalMapper>
41#include <QString>
42#include <QTableWidgetItem>
43#include <QTimer>
44#include <QToolBar>
45
46/** Coin3D/SoQt headers **/
47#include <Inventor/Qt/SoQt.h>
48#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
49#include <Inventor/nodes/SoEventCallback.h>
50#include <Inventor/nodes/SoMatrixTransform.h>
51#include <Inventor/nodes/SoNode.h>
52#include <Inventor/nodes/SoSeparator.h>
53#include <Inventor/sensors/SoTimerSensor.h>
54
55/** VirtualRobot headers **/
56#include <VirtualRobot/Nodes/RobotNode.h>
57#include <VirtualRobot/Robot.h>
58#include <VirtualRobot/RobotNodeSet.h>
59#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
60#include <VirtualRobot/Visualization/VisualizationFactory.h>
61
62#include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
63
64/** STD headers **/
65#include <memory>
66#include <unordered_map>
67
68namespace armarx
69{
70 /**
71 * \class SimulatorControlGuiPlugin
72 * \brief This plugin offers a widget to control a simulation.
73 * \see SimulatorControlController
74 * \ingroup ArmarXSimulatorComponents
75 */
76
78 {
79 Q_OBJECT
80 Q_INTERFACES(ArmarXGuiInterface)
81 Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
82 public:
84
85 QString
86 getPluginName() override
87 {
88 return "SimulatorControlGuiPlugin";
89 }
90 };
91
92 /**
93 \page ArmarXSimulation-GuiPlugins-SimulatorControl SimulatorControl Gui
94
95 \brief A widget to control a simulation.
96
97 This widget provides information and allows controlling the simulation.
98
99 \image html SimulatorControlGuiPlugin_Widget_800.png "The plugin's ui." width=300px
100 -# A table containing all visualization layers. The layers can be turned off and on, cleared and removed.
101 -# Whether the simulation window is visible.
102 -# Whether a coordinate system at (0,0,0) is shown.
103 -# Whether contacts are shown. @image html SimulatorControlGuiPlugin_Collision_mod.png "Left: The full model. Right: The collision model" width=300px
104 -# Whether the full model or collision model is rendered. @image html SimulatorControlGuiPlugin_Contacts.png "Left: Contacts visible. Right: Contacts invisible" width=300px
105 -# The level of anti aliasing
106 -# Some information about the simulation. (timings, number of robots, joints, objects and contacts, camera position and orientation)
107
108 SimulatorControl API Documenation \ref SimulatorControlController
109 \ingroup ArmarXSimulatorComponents
110 \see SimulatorControlGuiPlugin
111 */
112
113 /**
114 * \brief A widget to control a simulation.
115 *
116 * This widget provides information and allows controlling the simulation.
117 * \ingroup ArmarXSimulatorComponents
118 * \see SimulatorControlGuiPlugin
119 */
121 public ArmarXComponentWidgetControllerTemplate<SimulatorControlController>
122 {
123 Q_OBJECT
124 public:
126
128 {
129 }
130
131 // inherited from Component
132 void onInitComponent() override;
133 void onConnectComponent() override;
134 void onDisconnectComponent() override;
135 void onExitComponent() override;
136
137 // inherited of ArmarXWidget
138 static QString
140 {
141 return "SimulatorControlGuiPlugin";
142 }
143
144 static QIcon
146 {
147 return QIcon{"://icons/monitor_and_remote.svg"};
148 }
149
150 void loadSettings(QSettings* settings) override;
151 void saveSettings(QSettings* settings) override;
152
153 QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
154
155 signals:
157
158 public slots:
159 void showSimWindow(bool enable);
160 void showCoordSystem(bool enable);
161 void showContacts(bool enable);
162 void selectVisuType();
163 void playStopSim();
164 void stepSim();
165 /*!
166 * \brief reInit Re-loads all simulator content.
167 */
168 void reInit();
169 void antiAliasing(int steps);
170
171 /**
172 * @brief Removes a layer.
173 * @param layerName The layer to remove.
174 */
175 void layerRemove(QString layerName);
176 /**
177 * @brief Toggles a layer's visibility
178 * @param layerName The layer.
179 */
180 void layerToggleVisibility(QString layerName);
181 /**
182 * @brief Requests the current layer information from simulatorPrx and updates the table.
183 */
184 void layerPoll();
185 /**
186 * @brief Clears a layer.
187 * @param layerName The layer to clear.
188 */
189 void layerClear(QString layerName);
190
191 protected:
192 /**
193 * @brief timerEvent
194 * @param event
195 */
196 void timerEvent(QTimerEvent*) override;
197
198 void connectSlots();
199
200 Ui::SimulatorControlGuiPlugin ui;
201
203
204 SimulatorInterfacePrx simulatorPrx;
205 SimulatorViewerControlInterfacePrx simulatorViewerPrx;
206
207 private slots:
208 void on_pushButtonManipRobSetPose_clicked();
209
210 private slots:
211 void on_pushButtonManipRobotUpdate_clicked();
212
213 private slots:
214 void on_pushButtonAddRobot_clicked();
215
216 private:
217 std::string settings_simulatorPrxName;
218 std::string settings_simulatorViewerPrxName;
219
220 /**
221 * @brief Triggers the request for layer information
222 */
223 QTimer layerPollTimer;
224 /**
225 * @brief Maps events to toggle a layer's visibility from checkboxes contained in the table to layerToggleVisibility.
226 */
227 QSignalMapper layerSignalMapperVisible;
228 /**
229 * @brief Maps events to clear a layer from corresponding buttons contained in the table to layerClear
230 */
231 QSignalMapper layerSignalMapperClear;
232 /**
233 * @brief Maps events to remove a layer from corresponding buttons contained in the table to layerClear
234 */
235 QSignalMapper layerSignalMapperRemove;
236
237 using LayerVisibilityCheckBoxesType =
238 std::map<std::string, std::pair<QTableWidgetItem*, QPointer<QCheckBox>>>;
239 /**
240 * @brief Stores checkboxes to turn layers visible / invisible.
241 */
242 LayerVisibilityCheckBoxesType layerVisibilityCheckBoxes;
243
244 int timerId;
245
246 QPointer<QToolBar> customToolbar;
247 };
248
249 using SimulatorControlGuiPluginPtr = std::shared_ptr<SimulatorControlGuiPlugin>;
250} // namespace armarx
The main gui interface.
void onInitComponent() override
Pure virtual hook for the subclass.
SimulatorViewerControlInterfacePrx simulatorViewerPrx
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
void onDisconnectComponent() override
Hook for subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
void layerClear(QString layerName)
Clears a layer.
void layerPoll()
Requests the current layer information from simulatorPrx and updates the table.
void layerRemove(QString layerName)
Removes a layer.
void reInit()
reInit Re-loads all simulator content.
void timerEvent(QTimerEvent *) override
timerEvent
void onConnectComponent() override
Pure virtual hook for the subclass.
void layerToggleVisibility(QString layerName)
Toggles a layer's visibility.
void onExitComponent() override
Hook for subclass.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< SimulatorControlGuiPlugin > SimulatorControlGuiPluginPtr