ADTF Display Toolbox
Loading...
Searching...
No Matches
baseobjectselectionmixin.h
Go to the documentation of this file.
1
7
8/*
9 * This file depends on Qt which is licensed under LGPLv3.
10 * See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
11 */
12
13#pragma once
14
16#include <adtfui/adtf_ui.h>
17#include <adtfucom3/adtf_ucom3.h>
19
20#include <QObject>
21#include <QGroupBox>
22#include <QLabel>
23
24namespace adtf
25{
26
27namespace disptb
28{
29
30namespace mixinlib
31{
32
33namespace endor
34{
35
47class cBaseObjectSelectionMixin : public QObject, public adtf::ui::qt_ui_filter<cBaseObjectMixin>
48{
49 // Removed Q_OBJECT for switch to interface library
50public:
55
57 {
58 }
59
60public: // overwrite cMixin
66 QWidget* CreateView() override
67 {
68 // create the base widget
69 QWidget* pWidget = new QWidget;
70 pWidget->setLayout(new QVBoxLayout);
71
72 AttachItemsToWidget(pWidget);
73
74 return pWidget;
75 }
76
78 tVoid ReleaseView() override
79 {
80 }
81
87 tResult InitScene() override
88 {
89 RETURN_IF_FAILED(cBaseObjectMixin::InitScene());
90 RETURN_IF_FAILED(GetSceneGraph().GetObject(m_pViewer));
91
92 RETURN_NOERROR;
93 }
94
102 tResult ProcessInput(adtf::streaming::flash::ISampleReader* pReader,
103 const adtf::ucom::ant::iobject_ptr<const adtf::streaming::ant::ISample>& pSample) override
104 {
105 cBaseObjectScene* pScene = nullptr;
106 if (IS_OK(GetScene(pReader, &pScene)))
107 {
108 RETURN_IF_FAILED(UpdateScene(pScene, pSample));
109
110 // check if our selected object still exists in the scene
111 if (m_pSelectedObject && m_pSelectedScene == pScene)
112 {
113 cBaseObject* pBaseObj = nullptr;
114 if (IS_FAILED(m_pSelectedScene->GetObject(m_pSelectedObject->GetId(), &pBaseObj)))
115 {
116 m_pSelectedObject = nullptr; // delete it (ref ptr)
117 m_pSelectedScene = nullptr;
118 }
119 }
120 }
121
122 RETURN_NOERROR;
123 }
124
130 tResult OnIdle() override
131 {
132 if (!m_pViewer)
133 {
134 // if viewer is not initialized, there is nothing to do.
135 RETURN_NOERROR;
136 }
137
138 // We lock the viewer to access m_pSelectedObject.
139 // See the documentation of cMixin for more information on locking the viewer.
140 m_pViewer->Lock();
141
142 // update all widgets
144
145 // release the viewer lock
146 m_pViewer->Unlock();
147
148 return nResult;
149 }
150
151public: // overwrite cBaseObjectMixin
154 tResult OnObjectPick(cBaseObjectScene* pScene,
155 cBaseObject* pObj,
156 tInt /*nPosX*/,
157 tInt /*nPosY*/,
158 tUInt32 /*nFlags*/,
159 const tNodePath& /*sNodePath*/) override
160 {
161 // we do not call the base method since it always toggles the selection state of the picked object.
162
163 // unselect a previously selected object
165 {
166 m_pSelectedObject->SetSelected(tFalse);
167 }
168
169 if (m_pSelectedObject != pObj)
170 {
171 // select this object
172 pObj->SetSelected(tTrue);
173 // and store a reference
174 m_pSelectedObject = pObj;
175 m_pSelectedScene = pScene;
176 }
177 else
178 {
179 m_pSelectedObject = nullptr;
180 m_pSelectedScene = nullptr;
181 }
182 RETURN_NOERROR;
183 }
185
186protected:
192 virtual void AttachItemsToWidget(QWidget* pWidget)
193 {
194 QGroupBox* pSelectedGroup = new QGroupBox("Selected Object");
195 pWidget->layout()->addWidget(pSelectedGroup);
196 pWidget->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));
197 QGridLayout* pGrid = new QGridLayout;
198 pSelectedGroup->setLayout(pGrid);
199
200 // and add all our labels.
201 tInt nRow = 0;
202 pGrid->addWidget(new QLabel("Scene:"), nRow, 0);
203 m_pSceneLabel = new QLabel("<na>");
204 pGrid->addWidget(m_pSceneLabel, nRow, 1);
205
206 ++nRow;
207 pGrid->addWidget(new QLabel("Id:"), nRow, 0);
208 m_pIdLabel = new QLabel("<na>");
209 pGrid->addWidget(m_pIdLabel, nRow, 1);
210
211 ++nRow;
212 pGrid->addWidget(new QLabel("Position:"), nRow, 0);
213 m_pPositionLabel = new QLabel("<na>");
214 pGrid->addWidget(m_pPositionLabel, nRow, 1);
215
216 ++nRow;
217 pGrid->addWidget(new QLabel("Rotation:"), nRow, 0);
218 m_pRotationLabel = new QLabel("<na>");
219 pGrid->addWidget(m_pRotationLabel, nRow, 1);
220
221 ++nRow;
222 pGrid->addWidget(new QLabel("Dimensions:"), nRow, 0);
223 m_pDimLabel = new QLabel("<na>");
224 pGrid->addWidget(m_pDimLabel, nRow, 1);
225
226 ++nRow;
227 pGrid->addWidget(new QLabel("Motion Vector:"), nRow, 0);
228 m_pMotionLabel = new QLabel("<na>");
229 pGrid->addWidget(m_pMotionLabel, nRow, 1);
230 }
231
239 virtual tResult UpdateWidgets(cBaseObjectScene* pScene, cBaseObject* pObj)
240 {
241 if (pObj)
242 {
243 // if we have a selected object we update the labels.
244 m_pSceneLabel->setText(pScene->GetName());
245 m_pIdLabel->setText(QString::number(pObj->GetId()));
246
247 const tChar* strFormat = "%.3f / %.3f / %.3f";
248 osg::Vec3d vTmp = pObj->GetPosition();
249 m_pPositionLabel->setText(adtf_util::cString::Format(strFormat, vTmp.x(), vTmp.y(), vTmp.z()).GetPtr());
250 vTmp = pObj->GetRotation();
251 m_pRotationLabel->setText(adtf_util::cString::Format(strFormat, vTmp.x(), vTmp.y(), vTmp.z()).GetPtr());
252 vTmp = pObj->GetSize();
253 m_pDimLabel->setText(adtf_util::cString::Format(strFormat, vTmp.x(), vTmp.y(), vTmp.z()).GetPtr());
254 vTmp = pObj->GetMotion();
255 m_pMotionLabel->setText(adtf_util::cString::Format(strFormat, vTmp.x(), vTmp.y(), vTmp.z()).GetPtr());
256 m_bHadSelection = tTrue;
257 }
258 else
259 {
260 if (m_bHadSelection)
261 {
262 // reset all labels
263 m_pSceneLabel->setText("<na>");
264 m_pIdLabel->setText("<na>");
265 m_pPositionLabel->setText("<na>");
266 m_pRotationLabel->setText("<na>");
267 m_pDimLabel->setText("<na>");
268 m_pMotionLabel->setText("<na>");
269 }
270 m_bHadSelection = tFalse;
271 }
272
273 RETURN_NOERROR;
274 }
275
276protected:
278 adtf::ucom::ant::object_ptr<IViewer> m_pViewer;
279
283 QLabel* m_pIdLabel;
289 QLabel* m_pDimLabel;
292
294 tBool m_bHadSelection = false;
295
297 osg::ref_ptr<cBaseObject> m_pSelectedObject;
299 osg::ref_ptr<cBaseObjectScene> m_pSelectedScene;
300};
301
302} // namespace endor
303
306
307} // namespace mixinlib
308
309} // namespace disptb
310
311} // namespace adtf
Copyright © Audi Electronics Venture GmbH.
Base class for objects that can be managed with cBaseObjectScene.
Definition baseobject.h:42
osg::Vec3d GetMotion()
Returns the current motion vector.
Definition baseobject.h:425
osg::Vec3d GetRotation()
Returns the current rotation.
Definition baseobject.h:333
tUInt32 GetId()
Returns the id of the object.
Definition baseobject.h:199
osg::Vec3d GetSize()
Returns the current size.
Definition baseobject.h:367
virtual tResult SetSelected(tBool bSelected)
Gives the object a chance to change its appearance when being selected or unselected.
Definition baseobject.h:435
osg::Vec3d GetPosition()
Returns the current position.
Definition baseobject.h:312
Base class for managing a scene of objects.
virtual const tChar * GetName()
Returns the name of the scene.
tResult ProcessInput(adtf::streaming::flash::ISampleReader *pReader, const adtf::ucom::ant::iobject_ptr< const adtf::streaming::ant::ISample > &pSample) override
Process input override.
tBool m_bHadSelection
Used to remember whether we had a selection during the last idle call.
QWidget * CreateView() override
Creates the view with the XService.
adtf::ucom::ant::object_ptr< IViewer > m_pViewer
pointer to the viewer (used for locking)
osg::ref_ptr< cBaseObject > m_pSelectedObject
Remembers the selected object.
tVoid ReleaseView() override
Releases the view with the XService.
virtual tResult UpdateWidgets(cBaseObjectScene *pScene, cBaseObject *pObj)
Updates the Qt widgets based on the currently selected object.
QLabel * m_pMotionLabel
Pointer to the motion vector label.
tResult InitScene() override
Init the scene of this mixin.
virtual void AttachItemsToWidget(QWidget *pWidget)
Creates Qt widgets for displaying data.
osg::ref_ptr< cBaseObjectScene > m_pSelectedScene
remembers the scene that the selected object belongs to.
virtual tResult InitScene()
Impelement this to add your graph elements.
Definition mixin.h:443
Namespace for functionality provided by the Mixin Library.
Definition baseobject.h:26
Namespace for functionality provided by the Display Toolbox.
Main namespace.
Copyright © Audi Electronics Venture GmbH.