1 // Copyright (C) 2009 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "HLAView.hxx"
24 #include <simgear/hla/HLAArrayDataElement.hxx>
25 #include "HLAViewClass.hxx"
26 #include "HLAViewerFederate.hxx"
30 HLAView::HLAView(HLAViewClass* objectClass, const SGWeakPtr<simgear::HLAFederate>& federate) :
31 HLAObjectInstance(objectClass),
32 _sceneObject(federate)
41 HLAView::createAttributeDataElements()
43 /// FIXME at some point we should not need that anymore
44 HLAObjectInstance::createAttributeDataElements();
46 assert(dynamic_cast<HLAViewClass*>(getObjectClass().get()));
47 HLAViewClass& objectClass = static_cast<HLAViewClass&>(*getObjectClass());
49 setAttributeDataElement(objectClass.getNameIndex(), _name.getDataElement());
50 setAttributeDataElement(objectClass.getPositionIndex(), _position.getDataElement());
51 setAttributeDataElement(objectClass.getOrientationIndex(), _orientation.getDataElement());
52 setAttributeDataElement(objectClass.getSceneObjectNameIndex(), _sceneObject.getDataElement());
56 HLAView::discoverInstance(const simgear::RTIData& tag)
58 HLAObjectInstance::discoverInstance(tag);
60 SGSharedPtr<simgear::HLAFederate> federate = getFederate().lock();
61 if (federate.valid()) {
62 assert(dynamic_cast<HLAViewerFederate*>(federate.get()));
63 static_cast<HLAViewerFederate*>(federate.get())->insertView(this);
68 HLAView::removeInstance(const simgear::RTIData& tag)
70 HLAObjectInstance::removeInstance(tag);
72 SGSharedPtr<simgear::HLAFederate> federate = getFederate().lock();
73 if (federate.valid()) {
74 assert(dynamic_cast<HLAViewerFederate*>(federate.get()));
75 static_cast<HLAViewerFederate*>(federate.get())->eraseView(this);
80 HLAView::registerInstance(simgear::HLAObjectClass* objectClass)
82 HLAObjectInstance::registerInstance(objectClass);
84 SGSharedPtr<simgear::HLAFederate> federate = getFederate().lock();
85 if (federate.valid()) {
86 assert(dynamic_cast<HLAViewerFederate*>(federate.get()));
87 static_cast<HLAViewerFederate*>(federate.get())->insertView(this);
92 HLAView::deleteInstance(const simgear::RTIData& tag)
94 SGSharedPtr<simgear::HLAFederate> federate = getFederate().lock();
95 if (federate.valid()) {
96 assert(dynamic_cast<HLAViewerFederate*>(federate.get()));
97 static_cast<HLAViewerFederate*>(federate.get())->eraseView(this);
100 HLAObjectInstance::deleteInstance(tag);
103 const HLASceneObject*
104 HLAView::getSceneObject() const
106 /// FIXME!!! The federate should track unresolved object references
107 _sceneObject.recheckObject();
108 return _sceneObject.getObject();
112 HLAView::getSceneObject()
114 /// FIXME!!! The federate should track unresolved object references
115 _sceneObject.recheckObject();
116 return _sceneObject.getObject();
120 HLAView::setSceneObject(HLASceneObject* sceneObject)
122 _sceneObject.setObject(sceneObject);
126 HLAView::getLocation(const SGTimeStamp& timeStamp) const
128 const HLASceneObject* sceneObject = getSceneObject();
129 SGLocationd location(getPosition(), getOrientation());
132 return sceneObject->getLocation(timeStamp).getAbsoluteLocation(location);
135 } // namespace fgviewer