00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 # include <simgear_config.h>
00024 #endif
00025
00026 #include <osgDB/Registry>
00027 #include <osgDB/Input>
00028 #include <osgDB/ParameterOutput>
00029
00030 #include "SGSceneUserData.hxx"
00031
00032 SGSceneUserData*
00033 SGSceneUserData::getSceneUserData(osg::Node* node)
00034 {
00035 if (!node)
00036 return 0;
00037 osg::Referenced* referenced = node->getUserData();
00038 if (!referenced)
00039 return 0;
00040 return dynamic_cast<SGSceneUserData*>(referenced);
00041 }
00042
00043 const SGSceneUserData*
00044 SGSceneUserData::getSceneUserData(const osg::Node* node)
00045 {
00046 if (!node)
00047 return 0;
00048 const osg::Referenced* referenced = node->getUserData();
00049 if (!referenced)
00050 return 0;
00051 return dynamic_cast<const SGSceneUserData*>(referenced);
00052 }
00053
00054 SGSceneUserData*
00055 SGSceneUserData::getOrCreateSceneUserData(osg::Node* node)
00056 {
00057 SGSceneUserData* userData = getSceneUserData(node);
00058 if (userData)
00059 return userData;
00060 userData = new SGSceneUserData;
00061 node->setUserData(userData);
00062 return userData;
00063 }
00064
00065 unsigned
00066 SGSceneUserData::getNumPickCallbacks() const
00067 {
00068 return _pickCallbacks.size();
00069 }
00070
00071 SGPickCallback*
00072 SGSceneUserData::getPickCallback(unsigned i) const
00073 {
00074 if (_pickCallbacks.size() <= i)
00075 return 0;
00076 return _pickCallbacks[i];
00077 }
00078
00079 void
00080 SGSceneUserData::setPickCallback(SGPickCallback* pickCallback)
00081 {
00082 _pickCallbacks.clear();
00083 addPickCallback(pickCallback);
00084 }
00085
00086 void
00087 SGSceneUserData::addPickCallback(SGPickCallback* pickCallback)
00088 {
00089 if (!pickCallback)
00090 return;
00091 _pickCallbacks.push_back(pickCallback);
00092 }
00093
00094 bool SGSceneUserData_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
00095 {
00096 const SGSceneUserData& data = static_cast<const SGSceneUserData&>(obj);
00097
00098 unsigned numPickCallbacks = data.getNumPickCallbacks();
00099 if (numPickCallbacks > 0)
00100 fw.indent() << "num_pickCallbacks " << numPickCallbacks << "\n";
00101 if (data.getBVHNode())
00102 fw.indent() << "hasBVH true\n";
00103 const SGSceneUserData::Velocity* vel = data.getVelocity();
00104 if (vel) {
00105 fw.indent() << "velocity {\n";
00106 fw.moveIn();
00107 fw.indent() << "linear " << vel->linear << "\n";
00108 fw.indent() << "angular " << vel->angular << "\n";
00109 fw.indent() << "referenceTime " << vel->referenceTime << "\n";
00110 fw.indent() << "id " << static_cast<unsigned>(vel->id) << "\n";
00111 fw.moveOut();
00112 fw.indent() << "}\n";
00113 }
00114 return true;
00115 }
00116
00117 namespace
00118 {
00119 osgDB::RegisterDotOsgWrapperProxy SGSceneUserDataProxy
00120 (
00121 new SGSceneUserData,
00122 "simgear::SGSceneUserData",
00123 "Object simgear::SGSceneUserData",
00124 0,
00125 &SGSceneUserData_writeLocalData
00126 );
00127 }