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 <unordered_set>
25
26// Qt includes
27#include <QListWidgetItem>
28
30#include <ArmarXCore/interface/observers/ObserverInterface.h>
31
35
37#include <RobotAPI/interface/ArViz/Component.h>
38
40#include "LayerInfoTree.h"
41
42// C++ includes
43#include <memory>
44
45// ui_ArVizWidget.h is included by the .cpp, not here: moc textually inlines every
46// #include it can resolve, and parsing the uic-generated header alongside this one
47// makes moc mis-qualify this class as Ui::armarx::*.
48namespace Ui
49{
50 class ArVizWidget;
51}
52
53namespace armarx
54{
63
64 struct ArVizWidgetBatchCallback;
65
66 /**
67 \page RobotAPI-GuiPlugins-ArViz ArViz
68 \brief The ArViz allows visualizing ...
69
70 \image html ArViz.png
71 The user can
72
73 API Documentation \ref ArVizWidgetController
74
75 \see ArVizGuiPlugin
76 */
77
78 /**
79 * \class ArVizWidgetController
80 * \brief ArVizWidgetController brief one line description
81 *
82 * Detailed description
83 */
86 {
87 Q_OBJECT
88
89 public:
90 /// Controller Constructor
91 explicit ArVizWidgetController();
92
93 /// Controller destructor
94 virtual ~ArVizWidgetController() override;
95
96 void loadSettings(QSettings* settings) override;
97 void saveSettings(QSettings* settings) override;
98
99 QPointer<QDialog> getConfigDialog(QWidget* parent) override;
100 void configured() override;
101
102 SoNode* getScene() override;
103
104 /// Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
105 static QString
107 {
108 return "Visualization.ArViz";
109 }
110
111 /// @see armarx::Component::onInitComponent()
112 void onInitComponent() override;
113 void onExitComponent() override;
114
115 void onConnectComponent() override;
116 void onDisconnectComponent() override;
117
118 void onGetBatchAsync(viz::data::RecordingBatch const& batch);
119
120 private slots:
121 /* QT slot declarations */
122 void updateLayers();
123 void updateLayersFromProfile();
124
125 signals:
126 /* QT signal declarations */
127
130
131
132 private:
133 void onConnectGui();
134 void onDisconnectGui();
135
136 void layersChanged(std::vector<viz::CoinLayerID> const& layers);
137 void layerTreeChanged(QTreeWidgetItem* item, int column);
138 void updateSelectedLayer(QTreeWidgetItem* current, QTreeWidgetItem* previous);
139
140 void onCollapseAll(bool);
141 void onExpandAll(bool);
142
143 void onHideAll(bool);
144 void onShowAll(bool);
145 void onHideFiltered(bool);
146 void onShowFiltered(bool);
147
148 void onFilterTextChanged(QString const& filter);
149
150 void showAllLayers(bool visible);
151 void showFilteredLayers(bool visible);
152
153 void onDeselectElement();
154 void onContextMenuClicked();
155 void onInteractiveElementSelected(QListWidgetItem* item);
156
157 void onUpdate();
158 void onTimingObserverUpdate();
159
160
161 // Record & Replay
162
163 void onStartRecording();
164 void onStopRecording();
165
166 void onRefreshRecordings();
167 void onRecordingSelectionChanged(QListWidgetItem* current, QListWidgetItem* previous);
168
169 void onReplaySpinChanged(int newValue);
170 void onReplaySliderChanged(int newValue);
171
172 void selectRecording(viz::data::Recording const& recording);
173
174 void onReplayStart(bool);
175 void onReplayStop(bool);
176 long replayToRevision(long revision);
177 long getRevisionForTimestamp(long timestamp);
178 void onReplayTimedStart(bool checked);
179 void onReplayTimerTick();
180 void exportToVRML();
181
182 void changeMode(ArVizWidgetMode newMode);
183 void enableWidgetAccordingToMode();
184
185
186 private:
187 std::unique_ptr<Ui::ArVizWidget> widget;
188
189 QPointer<SimpleConfigDialog> configDialog;
190
191 QTimer* updateTimer;
193 StringVariantBaseMap timingMap;
194
195 QTimer* replayTimer;
196 long replayCurrentTimestamp = 0;
197 long lastReplayRealTime = 0;
198
199 std::string storageName;
200 armarx::viz::StorageInterfacePrx storage;
201 std::string debugObserverName;
202 DebugObserverInterfacePrx debugObserver;
203
205 armarx::LayerInfoTree layerInfoTree;
206
207 viz::data::RecordingSeq allRecordings;
208
209 // Replay control
210 viz::data::Recording currentRecording;
211 long currentRevision = -1;
212 long currentTimestamp = -1;
213 bool currentRecordingSelected = false;
214
215 // Recording batch cache
216 struct TimestampedRecordingBatch
217 {
218 IceUtil::Time lastUsed;
219 viz::data::RecordingBatch data;
220 };
221
222 viz::data::RecordingBatch const& getRecordingBatch(long index);
223 void limitRecordingBatchCacheSize();
224
225 std::size_t recordingBatchCacheMaxSize = 5;
226 std::mutex recordingBatchCacheMutex;
227 std::atomic<long> recordingWaitingForBatchIndex = -1;
228 std::map<long, TimestampedRecordingBatch> recordingBatchCache;
229
231
233 armarx::viz::Callback_StorageInterface_getRecordingBatchPtr callback;
234 Ice::AsyncResultPtr callbackResult;
235
236 std::vector<double> timings;
237
238 ArvizProfileManagerWidget* arvizeProfileLayerWidget;
239
240 public:
241 static QIcon
243 {
244 return QIcon(":icons/ArViz.png");
245 }
246 };
247} // namespace armarx
std::string timestamp()
uint8_t index
#define ARMARXCOMPONENT_IMPORT_EXPORT
Manages the layer info QTreeWidget.
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
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.
SoNode * getScene() override
Reimplementing this function and returning a SoNode* will show this SoNode in the 3DViewerWidget,...
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
ArVizWidgetController()
Controller Constructor.
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.