00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef SCENE_EVENT_HANDLER
00014 #define SCENE_EVENT_HANDLER
00015
00016 #include "SimulatedIAUV.h"
00017 #include "ROSInterface.h"
00018 #include "ConfigXMLParser.h"
00019
00020 class SceneEventHandler : public osgGA::GUIEventHandler
00021 {
00022 private:
00023 osg::ref_ptr<osgOceanScene> _scene;
00024 osg::ref_ptr<TextHUD> _textHUD;
00025 std::vector<osg::ref_ptr<osgWidget::Window> > _windows;
00026 std::vector<boost::shared_ptr<ROSInterface> > _ROSInterfaces;
00027 ConfigFile *_config;
00028
00029 bool draw_frames_;
00030 public:
00031
00032 SceneEventHandler(std::vector<osg::ref_ptr<osgWidget::Window> > &windows, TextHUD* textHUD,
00033 osg::ref_ptr<osgOceanScene> scene, std::vector<boost::shared_ptr<ROSInterface> > &ROSInterfaces,
00034 ConfigFile *config) :
00035 _scene(scene), _textHUD(textHUD), _windows(windows), _ROSInterfaces(ROSInterfaces), draw_frames_(false)
00036 {
00037 _textHUD->setSceneText("Clear Blue Sky");
00038 _config = config;
00039 }
00040
00041 virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&)
00042 {
00043 switch (ea.getEventType())
00044 {
00045 case (osgGA::GUIEventAdapter::KEYUP):
00046 {
00047
00048 if (ea.getKey() == '1')
00049 {
00050 ROS_INFO("Switch to Clear Blue Sky");
00051 _scene->changeScene(osgOceanScene::CLEAR);
00052 _scene->getOceanScene()->setUnderwaterFog(
00053 _config->fogDensity, osg::Vec4f(_config->fogColor[0], _config->fogColor[1], _config->fogColor[2], 1));
00054 _scene->getOceanScene()->setUnderwaterDiffuse(
00055 osg::Vec4f(_config->color[0], _config->color[1], _config->color[2], 1));
00056 _scene->getOceanScene()->setUnderwaterAttenuation(
00057 osg::Vec3f(_config->attenuation[0], _config->attenuation[1], _config->attenuation[2]));
00058
00059 _textHUD->setSceneText("Clear Blue Sky");
00060 return false;
00061 }
00062 else if (ea.getKey() == '2')
00063 {
00064 _scene->changeScene(osgOceanScene::DUSK);
00065 _textHUD->setSceneText("Dusk");
00066 _scene->getOceanScene()->setUnderwaterFog(
00067 _config->fogDensity, osg::Vec4f(_config->fogColor[0], _config->fogColor[1], _config->fogColor[2], 1));
00068 _scene->getOceanScene()->setUnderwaterDiffuse(
00069 osg::Vec4f(_config->color[0], _config->color[1], _config->color[2], 1));
00070 _scene->getOceanScene()->setUnderwaterAttenuation(
00071 osg::Vec3f(_config->attenuation[0], _config->attenuation[1], _config->attenuation[2]));
00072 return false;
00073 }
00074 else if (ea.getKey() == '3')
00075 {
00076 _scene->changeScene(osgOceanScene::CLOUDY);
00077 _textHUD->setSceneText("Pacific Cloudy");
00078 _scene->getOceanScene()->setUnderwaterFog(
00079 _config->fogDensity, osg::Vec4f(_config->fogColor[0], _config->fogColor[1], _config->fogColor[2], 1));
00080 _scene->getOceanScene()->setUnderwaterDiffuse(
00081 osg::Vec4f(_config->color[0], _config->color[1], _config->color[2], 1));
00082 _scene->getOceanScene()->setUnderwaterAttenuation(
00083 osg::Vec3f(_config->attenuation[0], _config->attenuation[1], _config->attenuation[2]));
00084 return false;
00085 }
00086 else if (ea.getKey() == 'c')
00087 {
00088 for (unsigned int i = 0; i < _windows.size(); i++)
00089 if (_windows[i]->isVisible())
00090 _windows[i]->hide();
00091 else
00092 _windows[i]->show();
00093 return false;
00094 }
00095 else if (ea.getKey() == 'f')
00096 {
00097
00098 findNodeVisitor finder("switch_frames");
00099 _scene->localizedWorld->accept(finder);
00100 std::vector<osg::Node*> node_list = finder.getNodeList();
00101 (draw_frames_) ? draw_frames_ = false : draw_frames_ = true;
00102 for (unsigned int i = 0; i < node_list.size(); i++)
00103 (draw_frames_) ? node_list[i]->asSwitch()->setAllChildrenOn() :
00104 node_list[i]->asSwitch()->setAllChildrenOff();
00105 }
00106 else if (ea.getKey() == 't')
00107 {
00108
00109 findNodeVisitor finder("switch_trajectory");
00110 _scene->localizedWorld->accept(finder);
00111 std::vector<osg::Node*> node_list = finder.getNodeList();
00112 (draw_frames_) ? draw_frames_ = false : draw_frames_ = true;
00113 for (unsigned int i = 0; i < node_list.size(); i++)
00114 (draw_frames_) ? node_list[i]->asSwitch()->setAllChildrenOn() :
00115 node_list[i]->asSwitch()->setAllChildrenOff();
00116 }
00117 else if (ea.getKey() == 'r')
00118 {
00119
00120 GetCatchableObjects finder;
00121 _scene->getScene()->accept(finder);
00122 std::vector<osg::Node*> node_list = finder.getNodeList();
00123 for (unsigned int i = 0; i < node_list.size(); i++)
00124 {
00125 osg::ref_ptr<NodeDataType> data = dynamic_cast<NodeDataType*>(node_list[i]->getUserData());
00126 osg::Matrixd matrix;
00127 matrix.makeRotate(
00128 osg::Quat(data->originalRotation[0], osg::Vec3d(1, 0, 0), data->originalRotation[1],
00129 osg::Vec3d(0, 1, 0), data->originalRotation[2], osg::Vec3d(0, 0, 1)));
00130 matrix.setTrans(data->originalPosition[0], data->originalPosition[1], data->originalPosition[2]);
00131 node_list[i]->asTransform()->asMatrixTransform()->setMatrix(matrix);
00132 _scene->localizedWorld->addChild(node_list[i]);
00133 node_list[i]->getParent(0)->removeChild(node_list[i]);
00134 }
00135
00136
00137 findNodeVisitor finder2("ObjectPickerNode");
00138 _scene->localizedWorld->accept(finder2);
00139 node_list = finder2.getNodeList();
00140
00141 for (unsigned int i = 0; i < node_list.size(); i++)
00142 {
00143 osg::ref_ptr<ObjectPickerUpdateCallback> callback =
00144 dynamic_cast<ObjectPickerUpdateCallback*>(node_list[i]->getUpdateCallback());
00145 callback->picked = false;
00146 }
00147
00148
00149 }
00150
00151 }
00152 default:
00153 return false;
00154 }
00155 }
00156
00157 void getUsage(osg::ApplicationUsage& usage) const
00158 {
00159 }
00160
00161 };
00162
00163 #endif