ADTF Display Toolbox
Loading...
Searching...
No Matches
mixin.h
Go to the documentation of this file.
1
7#pragma once
8
9#include "mixin_types.h"
11#include "scene_graph_intf.h"
12#include "viewer_intf.h"
13#include "font.h"
14
15#include <adtf_filtersdk.h>
16#include <a_utils.h>
17#include <adtf_base.h>
18#include <adtf_ucom3.h>
19#include <adtf_streaming3.h>
20#include <osg/Switch>
21
22#include <vector>
23
24// Undefine macro from "windows.h" for this file, which would cause name clash.
25#ifdef GetObject
26 #undef GetObject
27#endif
28
29#ifdef GetCurrentTime
30 #undef GetCurrentTime
31#endif
32
33namespace osgText
34{
35class Font;
36}
37namespace osg
38{
39class Node;
40}
41namespace osg
42{
43class Group;
44}
45
46namespace adtf
47{
48
49namespace disptb
50{
51
52namespace mixinlib
53{
54
55namespace endor
56{
57
62{
63protected:
66
67public:
72 virtual osg::Group* GetRoot() = 0;
73
78 virtual tVoid SetPosition(const osg::Vec3d& oPos) = 0;
79
84 virtual tVoid SetAttitude(const osg::Quat& oQuat) = 0;
85
90 virtual tVoid SetScale(const osg::Vec3d& oScale) = 0;
91
96 virtual tVoid SetPivotPoint(const osg::Vec3d& oPivot) = 0;
97};
98
99namespace detail
100{
101
102class cChildCoordinateSystem : public IChildCoordinateSystem
103{
104public:
105 cChildCoordinateSystem(const tChar* strName,
106 filter::interface_client<ISceneGraph> pSceneGraph,
107 INodeHandler* pHandler):
108 m_strName(strName), m_pSceneGraph(pSceneGraph), m_pRoot(new osg::Group), m_pPickHandler(pHandler)
109 {
110 }
111
112 osg::Group* GetRoot() override
113 {
114 return m_pRoot;
115 }
116
117 tVoid SetPosition(const osg::Vec3d& oPos) override
118 {
119 m_oPos = oPos;
120
121 if (m_pCoordinateSystem)
122 {
123 m_pCoordinateSystem->SetPosition(oPos);
124 }
125 }
126 tVoid SetAttitude(const osg::Quat& oQuat) override
127 {
128 m_oAttitude = oQuat;
129
130 if (m_pCoordinateSystem)
131 {
132 m_pCoordinateSystem->SetAttitude(oQuat);
133 }
134 }
135 tVoid SetScale(const osg::Vec3d& oScale) override
136 {
137 m_oScale = oScale;
138
139 if (m_pCoordinateSystem)
140 {
141 m_pCoordinateSystem->SetScale(oScale);
142 }
143 }
144 tVoid SetPivotPoint(const osg::Vec3d& oPivot) override
145 {
146 m_oPivotPoint = oPivot;
147
148 if (m_pCoordinateSystem)
149 {
150 m_pCoordinateSystem->SetPivotPoint(oPivot);
151 }
152 }
153
154 ucom::object_ptr<ICoordinateSystem> GetCoordinateSystem()
155 {
156 Create();
157 return m_pCoordinateSystem;
158 }
159
160 tVoid Create()
161 {
162 if (!m_pCoordinateSystem)
163 {
164 ucom::object_ptr<ICoordinateSystem> pParent;
165 THROW_IF_FAILED(m_pSceneGraph->GetObject(pParent));
166 THROW_IF_FAILED(pParent->CreateChild(m_strName.c_str(), m_pCoordinateSystem));
167 m_pCoordinateSystem->SetPosition(m_oPos);
168 m_pCoordinateSystem->SetAttitude(m_oAttitude);
169 m_pCoordinateSystem->SetScale(m_oScale);
170 m_pCoordinateSystem->SetPivotPoint(m_oPivotPoint);
171 m_pCoordinateSystem->AddNode(m_pRoot, m_pPickHandler);
172 }
173 }
174
175public:
176 std::string m_strName;
177 filter::interface_client<ISceneGraph> m_pSceneGraph;
178 osg::ref_ptr<osg::Group> m_pRoot;
179 ucom::object_ptr<ICoordinateSystem> m_pCoordinateSystem;
180 INodeHandler* m_pPickHandler;
181
182 osg::Vec3d m_oPos;
183 osg::Quat m_oAttitude;
184 osg::Vec3d m_oScale = {1.0, 1.0, 1.0};
185 osg::Vec3d m_oPivotPoint;
186};
187
188class cSceneGraphProxy : public ucom::object<ISceneGraph>
189{
190public:
191 cSceneGraphProxy(const tChar* strName, filter::interface_client<ISceneGraph> pSceneGraph, INodeHandler* pHandler):
192 m_pSceneGraph(pSceneGraph), m_oChildCoordinateSystem(strName, pSceneGraph, pHandler)
193 {
194 }
195
196 tResult GetObject(ucom::ant::iobject_ptr<ucom::ant::IObject>& pObject, const tChar* strObjectName = "")
197 {
198 std::string strNameHelper = strObjectName ? strObjectName : "";
199
200 if (strNameHelper.empty() ||
201 strNameHelper == adtf::disptb::mixinlib::endor::tSceneGraphObjectNames::CoordinateSystem)
202 {
203 if (IS_OK(pObject.Reset(m_oChildCoordinateSystem.GetCoordinateSystem())))
204 {
205 RETURN_NOERROR;
206 }
207 }
208
209 return m_pSceneGraph->GetObject(pObject, strObjectName);
210 }
211
212 cChildCoordinateSystem* GetCoordinateSystem()
213 {
214 return &m_oChildCoordinateSystem;
215 }
216
217private:
218 filter::interface_client<ISceneGraph> m_pSceneGraph;
219 cChildCoordinateSystem m_oChildCoordinateSystem;
220};
221
222} // namespace detail
223
237class cMixin :
238 public ucom::catwo::object<filter::cFilter, INodeHandler, IMenuEventSink>,
239 public ucom::ant::enable_object_ptr_from_this<cMixin>
240{
241public:
246 {
247 m_pSceneGraph = CreateInterfaceClient<ISceneGraph>("scene_graph");
248 SetDescription("scene_graph", "ISceneGraph interface for use with Openscenegraph 3.5.6");
249 }
250
254 ~cMixin() override
255 {
256 }
257
268 {
269 auto pSceneGraph = ucom::make_object_ptr<detail::cSceneGraphProxy>(strName, m_pSceneGraph, this);
270 CreateInterfaceServer<ISceneGraph>(strName, ucom::ucom_object_ptr_cast<ISceneGraph>(pSceneGraph));
271 m_oCoordinateSystemSceneGraphProxys.push_back(pSceneGraph);
272 return pSceneGraph->GetCoordinateSystem();
273 }
274
279 osg::Group* GetRoot()
280 {
281 if (!m_pRootNode)
282 {
283 osg::ref_ptr<osg::Switch> pRootNode = new osg::Switch;
284 ucom::object_ptr<ICoordinateSystem> pCoordinateSystem;
285 THROW_IF_FAILED(GetSceneGraph().GetObject(pCoordinateSystem));
286 THROW_IF_FAILED(pCoordinateSystem->AddNode(pRootNode, this));
287 m_pRootNode = pRootNode;
288 }
289
290 return m_pRootNode;
291 }
292
298 {
299 return m_pSceneGraph.Get();
300 }
301
307 osgText::Font* GetFont()
308 {
309 return m_pFont;
310 }
311
313 tResult HandleMenuEvent(const tChar* /*strMenuText*/, tVoid* /*pvEventData*/) override
314 {
315 RETURN_NOERROR;
316 }
318
333 virtual tResult OnPick(tInt32 /*nPosX*/, tInt32 /*nPosY*/, tUInt32 /*nFlags*/, const tNodePath& /*sNodePath*/)
334 {
335 RETURN_NOERROR;
336 }
337
345 virtual tResult AddMenuItemForPick(chewbacca::IMenu& /*oMenu*/, const tNodePath& /*sNodePath*/)
346 {
347 RETURN_NOERROR;
348 }
349
355 virtual tResult AddGlobalMenuItem(chewbacca::IMenu& /*oMenu*/)
356 {
357 RETURN_NOERROR;
358 }
359
363 std::vector<const osg::Node*> GetLastMenuPath()
364 {
365 return m_oLastPick;
366 }
367
369 tResult Init(tInitStage eStage) override
370 {
371 RETURN_IF_FAILED(cFilter::Init(eStage));
372
373 if (eStage == tInitStage::StageGraphReady)
374 {
375 RETURN_IF_FAILED(GetSceneGraph().GetObject(m_pViewer));
376 m_pViewer->MakeCurrent();
377 CreateCoordinateSystems();
378 RETURN_IF_FAILED(InitScene());
379 }
380
381 RETURN_NOERROR;
382 }
383
384 tResult Shutdown(tInitStage eStage) override
385 {
386 if (eStage == tInitStage::StageGraphReady)
387 {
388 ClearScene();
389 }
390 return cFilter::Shutdown(eStage);
391 }
392
393 tResult GetName(base::ant::IString&& strName) const override
394 {
395 return cFilter::GetName(std::move(strName));
396 }
397
398 tResult
399 OnPick(tInt32 nPosX, tInt32 nPosY, tUInt32 nFlags, const tNodePath& sNodePath, chewbacca::IMenu& oMenu) override
400 {
401 if (sNodePath.nCount == 0)
402 {
403 RETURN_IF_FAILED(AddGlobalMenuItem(oMenu));
404 }
405 else
406 {
407 if (nFlags & INodeHandler::CM_RIGHT_MB)
408 {
409 m_oLastPick.clear();
410 m_oLastPick.insert(m_oLastPick.end(), sNodePath.ppNodePath, sNodePath.ppNodePath + sNodePath.nCount);
411 RETURN_IF_FAILED(AddMenuItemForPick(oMenu, sNodePath));
412 }
413 else
414 {
415 RETURN_IF_FAILED(OnPick(nPosX, nPosY, nFlags, sNodePath));
416 }
417 }
418 RETURN_NOERROR;
419 }
420
421 tResult Process(base::flash::tNanoSeconds tmTrigger, streaming::ant::IRunner* pRunner) override
422 {
423 m_pViewer->Lock();
424 auto oResult = cFilter::Process(tmTrigger, pRunner);
425 m_pViewer->Unlock();
426 return oResult;
427 }
428
429 tResult ProcessInput(base::flash::tNanoSeconds tmTrigger, streaming::flash::ISampleReader* pReader) override
430 {
431 m_pViewer->Lock();
432 auto oResult = cFilter::ProcessInput(tmTrigger, pReader);
433 m_pViewer->Unlock();
434 return oResult;
435 }
437
438protected:
443 virtual tResult InitScene()
444 {
445 RETURN_NOERROR;
446 }
447
451 virtual tVoid ClearScene()
452 {
453 }
454
455protected:
456 tVoid CreateCoordinateSystems()
457 {
458 for (auto& pProxy : m_oCoordinateSystemSceneGraphProxys)
459 {
460 pProxy->GetCoordinateSystem()->Create();
461 }
462 }
463
464 osg::ref_ptr<osg::Switch> m_pRootNode;
465 filter::interface_client<ISceneGraph> m_pSceneGraph;
466 std::vector<ucom::object_ptr<detail::cSceneGraphProxy>> m_oCoordinateSystemSceneGraphProxys;
467 osg::ref_ptr<osgText::Font> m_pFont = new cInstanceFont;
468 ucom::object_ptr<IViewer> m_pViewer;
469 std::vector<const osg::Node*> m_oLastPick;
470};
471
472} // namespace endor
473
474using endor::cMixin;
475using endor::IChildCoordinateSystem;
476
477} // namespace mixinlib
478
479} // namespace disptb
480
481} // namespace adtf
Interface for managing a (context) menu.
Definition menu_intf.h:161
Interface for accessing and manipulating a coordinate system created with cMixin::CreateCoordinateSys...
Definition mixin.h:62
virtual tVoid SetAttitude(const osg::Quat &oQuat)=0
Set the attitude of the coordinate system.
virtual tVoid SetPosition(const osg::Vec3d &oPos)=0
Set the position of the coordinate system.
virtual tVoid SetScale(const osg::Vec3d &oScale)=0
Set the scale of the coordinate system.
virtual osg::Group * GetRoot()=0
Use this to add nodes within the coordinate system.
virtual tVoid SetPivotPoint(const osg::Vec3d &oPivot)=0
Set the pivot point of the coordinate system.
Interface for a handler that is responsible for a node and all its children.
Interface for the scene graph of a 3D Scene Display.
virtual tResult AddMenuItemForPick(chewbacca::IMenu &, const tNodePath &)
Return context menu entries for one of your nodes.
Definition mixin.h:345
ISceneGraph & GetSceneGraph()
Access the ISceneGraph interface.
Definition mixin.h:297
virtual tResult OnPick(tInt32, tInt32, tUInt32, const tNodePath &)
Handle a left click on one of your nodes.
Definition mixin.h:333
virtual tResult InitScene()
Impelement this to add your graph elements.
Definition mixin.h:443
IChildCoordinateSystem * CreateCoordinateSystem(const tChar *strName)
Creates a new coordinate system.
Definition mixin.h:267
virtual tVoid ClearScene()
Use this to clean up your graph elements.
Definition mixin.h:451
osgText::Font * GetFont()
Returns a pointer to a valid Font, use this for your osgText nodes.
Definition mixin.h:307
~cMixin() override
Destructor.
Definition mixin.h:254
virtual tResult AddGlobalMenuItem(chewbacca::IMenu &)
Add global menu entries not related to a specific one of your nodes.
Definition mixin.h:355
std::vector< const osg::Node * > GetLastMenuPath()
Definition mixin.h:363
osg::Group * GetRoot()
Add your nodes to this group.
Definition mixin.h:279
tVoid SetPivotPoint(const osg::Vec3d &oPivot) override
Set the pivot point of the coordinate system.
Definition mixin.h:144
tVoid SetScale(const osg::Vec3d &oScale) override
Set the scale of the coordinate system.
Definition mixin.h:135
osg::Group * GetRoot() override
Use this to add nodes within the coordinate system.
Definition mixin.h:112
tVoid SetAttitude(const osg::Quat &oQuat) override
Set the attitude of the coordinate system.
Definition mixin.h:126
tVoid SetPosition(const osg::Vec3d &oPos) override
Set the position of the coordinate system.
Definition mixin.h:117
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
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.
Copyright © Audi Electronics Venture GmbH.