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