ArVizWidgetController.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 RobotAPI::gui-plugins::ArVizWidgetController
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 #pragma once
23 
24 #include <RobotAPI/gui-plugins/ArViz/ui_ArVizWidget.h>
25 
27 #include <RobotAPI/interface/ArViz/Component.h>
28 
32 
33 #include <ArmarXCore/interface/observers/ObserverInterface.h>
35 
36 #include "LayerInfoTree.h"
37 
38 
39 namespace armarx
40 {
41  enum class ArVizWidgetMode
42  {
44  Live,
45  Recording,
48  };
49 
50  struct ArVizWidgetBatchCallback;
51 
52 
53  /**
54  \page RobotAPI-GuiPlugins-ArViz ArViz
55  \brief The ArViz allows visualizing ...
56 
57  \image html ArViz.png
58  The user can
59 
60  API Documentation \ref ArVizWidgetController
61 
62  \see ArVizGuiPlugin
63  */
64 
65  /**
66  * \class ArVizWidgetController
67  * \brief ArVizWidgetController brief one line description
68  *
69  * Detailed description
70  */
73  : armarx::ArmarXComponentWidgetControllerTemplate < ArVizWidgetController >
74  {
75  Q_OBJECT
76 
77  public:
78 
79  /// Controller Constructor
80  explicit ArVizWidgetController();
81 
82  /// Controller destructor
83  virtual ~ArVizWidgetController() override;
84 
85  void loadSettings(QSettings* settings) override;
86  void saveSettings(QSettings* settings) override;
87 
88  QPointer<QDialog> getConfigDialog(QWidget* parent) override;
89  void configured() override;
90 
91  SoNode* getScene() override;
92 
93  /// Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
94  static QString GetWidgetName()
95  {
96  return "Visualization.ArViz";
97  }
98 
99  /// @see armarx::Component::onInitComponent()
100  void onInitComponent() override;
101  void onExitComponent() override;
102 
103  void onConnectComponent() override;
104  void onDisconnectComponent() override;
105 
106  void onGetBatchAsync(viz::data::RecordingBatch const& batch);
107 
108 
109  public slots:
110  /* QT slot declarations */
111 
112  signals:
113  /* QT signal declarations */
114 
115  void connectGui();
116  void disconnectGui();
117 
118 
119  private:
120 
121  void onConnectGui();
122  void onDisconnectGui();
123 
124  void layersChanged(std::vector<viz::CoinLayerID> const& layers);
125  void layerTreeChanged(QTreeWidgetItem* item, int column);
126  void updateSelectedLayer(QTreeWidgetItem* current, QTreeWidgetItem* previous);
127 
128  void onCollapseAll(bool);
129  void onExpandAll(bool);
130 
131  void onHideAll(bool);
132  void onShowAll(bool);
133  void onHideFiltered(bool);
134  void onShowFiltered(bool);
135 
136  void onFilterTextChanged(QString const& filter);
137 
138  void showAllLayers(bool visible);
139  void showFilteredLayers(bool visible);
140 
141  void onDeselectElement();
142  void onContextMenuClicked();
143  void onInteractiveElementSelected(QListWidgetItem* item);
144 
145  void onUpdate();
146  void onTimingObserverUpdate();
147 
148 
149  // Record & Replay
150 
151  void onStartRecording();
152  void onStopRecording();
153 
154  void onRefreshRecordings();
155  void onRecordingSelectionChanged(QListWidgetItem* current, QListWidgetItem* previous);
156 
157  void onReplaySpinChanged(int newValue);
158  void onReplaySliderChanged(int newValue);
159 
160  void selectRecording(viz::data::Recording const& recording);
161 
162  void onReplayStart(bool);
163  void onReplayStop(bool);
164  long replayToRevision(long revision);
165  long getRevisionForTimestamp(long timestamp);
166  void onReplayTimedStart(bool checked);
167  void onReplayTimerTick();
168  void exportToVRML();
169 
170  void changeMode(ArVizWidgetMode newMode);
171  void enableWidgetAccordingToMode();
172 
173 
174  private:
175 
176  Ui::ArVizWidget widget;
177 
178  QPointer<SimpleConfigDialog> configDialog;
179 
180  QTimer* updateTimer;
182  StringVariantBaseMap timingMap;
183 
184  QTimer* replayTimer;
185  long replayCurrentTimestamp = 0;
186  long lastReplayRealTime = 0;
187 
188  std::string storageName;
189  armarx::viz::StorageInterfacePrx storage;
190  std::string debugObserverName;
191  DebugObserverInterfacePrx debugObserver;
192 
193  armarx::viz::CoinVisualizer visualizer;
194  armarx::LayerInfoTree layerInfoTree;
195 
196  viz::data::RecordingSeq allRecordings;
197 
198  // Replay control
199  viz::data::Recording currentRecording;
200  long currentRevision = -1;
201  long currentTimestamp = -1;
202  bool currentRecordingSelected = false;
203 
204  // Recording batch cache
205  struct TimestampedRecordingBatch
206  {
207  IceUtil::Time lastUsed;
208  viz::data::RecordingBatch data;
209  };
210 
211  viz::data::RecordingBatch const& getRecordingBatch(long index);
212  void limitRecordingBatchCacheSize();
213 
214  std::size_t recordingBatchCacheMaxSize = 5;
215  std::mutex recordingBatchCacheMutex;
216  std::atomic<long> recordingWaitingForBatchIndex = -1;
217  std::map<long, TimestampedRecordingBatch> recordingBatchCache;
218 
220 
222  armarx::viz::Callback_StorageInterface_getRecordingBatchPtr callback;
223  Ice::AsyncResultPtr callbackResult;
224 
225  std::vector<double> timings;
226 
227  public:
228  static QIcon GetWidgetIcon()
229  {
230  return QIcon(":icons/ArViz.png");
231  }
232  };
233 }
234 
235 
armarx::ArVizWidgetMode::Recording
@ Recording
armarx::viz::coin::exportToVRML
void exportToVRML(SoNode *node, std::string const &exportFilePath)
Definition: ExportVRML.cpp:68
armarx::ArVizWidgetMode
ArVizWidgetMode
Definition: ArVizWidgetController.h:41
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::LayerInfoTree
Manages the layer info QTreeWidget.
Definition: LayerInfoTree.h:16
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
SimpleConfigDialog.h
armarx::ArVizWidgetController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: ArVizWidgetController.h:228
armarx::ArVizWidgetMode::ReplayingManual
@ ReplayingManual
armarx::ArVizWidgetController::GetWidgetName
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
Definition: ArVizWidgetController.h:94
armarx::viz::CoinVisualizer_UpdateTiming
Definition: Visualizer.h:170
ArmarXGuiPlugin.h
armarx::ArVizWidgetController
ArVizWidgetController brief one line description.
Definition: ArVizWidgetController.h:71
armarx::ArVizWidgetMode::NotConnected
@ NotConnected
LayerInfoTree.h
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
Visualizer.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::viz::CoinVisualizer
Definition: Visualizer.h:198
IceUtil::Handle
Definition: forward_declarations.h:29
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
armarx::ArVizWidgetMode::Live
@ Live
armarx::ArVizWidgetMode::ReplayingTimed
@ ReplayingTimed
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ImportExportComponent.h