| [10113] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| [10396] | 13 | #include <osgPresentation/PickEventHandler> |
|---|
| 14 | #include <osgPresentation/SlideEventHandler> |
|---|
| [10113] | 15 | |
|---|
| 16 | #include <osgViewer/Viewer> |
|---|
| 17 | #include <osg/Notify> |
|---|
| 18 | #include <osgDB/FileUtils> |
|---|
| 19 | |
|---|
| [10117] | 20 | using namespace osgPresentation; |
|---|
| 21 | |
|---|
| 22 | PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): |
|---|
| [10113] | 23 | _operation(operation), |
|---|
| 24 | _relativeJump(relativeJump), |
|---|
| 25 | _slideNum(slideNum), |
|---|
| 26 | _layerNum(layerNum) |
|---|
| 27 | { |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| [10117] | 30 | PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): |
|---|
| [10113] | 31 | _command(str), |
|---|
| 32 | _operation(operation), |
|---|
| 33 | _relativeJump(relativeJump), |
|---|
| 34 | _slideNum(slideNum), |
|---|
| 35 | _layerNum(layerNum) |
|---|
| 36 | { |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| [10117] | 39 | PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum): |
|---|
| [10113] | 40 | _keyPos(keyPos), |
|---|
| [10117] | 41 | _operation(osgPresentation::EVENT), |
|---|
| [10113] | 42 | _relativeJump(relativeJump), |
|---|
| 43 | _slideNum(slideNum), |
|---|
| 44 | _layerNum(layerNum) |
|---|
| 45 | { |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv) |
|---|
| 50 | { |
|---|
| 51 | switch(ea.getEventType()) |
|---|
| 52 | { |
|---|
| 53 | case(osgGA::GUIEventAdapter::MOVE): |
|---|
| 54 | case(osgGA::GUIEventAdapter::PUSH): |
|---|
| 55 | case(osgGA::GUIEventAdapter::RELEASE): |
|---|
| 56 | { |
|---|
| 57 | osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); |
|---|
| 58 | osgUtil::LineSegmentIntersector::Intersections intersections; |
|---|
| 59 | if (viewer->computeIntersections(ea.getX(),ea.getY(), nv->getNodePath(), intersections)) |
|---|
| 60 | { |
|---|
| 61 | for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr=intersections.begin(); |
|---|
| 62 | hitr!=intersections.end(); |
|---|
| 63 | ++hitr) |
|---|
| 64 | { |
|---|
| 65 | if (ea.getEventType()==osgGA::GUIEventAdapter::MOVE) |
|---|
| 66 | { |
|---|
| 67 | osg::notify(osg::INFO)<<"Tooltip..."<<std::endl; |
|---|
| 68 | } |
|---|
| 69 | else if (ea.getEventType()==osgGA::GUIEventAdapter::RELEASE) |
|---|
| 70 | { |
|---|
| 71 | doOperation(); |
|---|
| 72 | return true; |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | break; |
|---|
| 77 | } |
|---|
| 78 | case(osgGA::GUIEventAdapter::KEYDOWN): |
|---|
| 79 | { |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | break; |
|---|
| 83 | } |
|---|
| 84 | default: |
|---|
| 85 | break; |
|---|
| 86 | } |
|---|
| 87 | return false; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | void PickEventHandler::accept(osgGA::GUIEventHandlerVisitor& v) |
|---|
| 92 | { |
|---|
| 93 | v.visit(*this); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | void PickEventHandler::getUsage(osg::ApplicationUsage& ) const |
|---|
| 97 | { |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | void PickEventHandler::setRelativeJump(int slideNum, int layerNum) |
|---|
| 101 | { |
|---|
| 102 | _relativeJump = true; |
|---|
| 103 | _slideNum = slideNum; |
|---|
| 104 | _layerNum = layerNum; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | void PickEventHandler::setAbsoluteJump(int slideNum, int layerNum) |
|---|
| 108 | { |
|---|
| 109 | _relativeJump = false; |
|---|
| 110 | _slideNum = slideNum; |
|---|
| 111 | _layerNum = layerNum; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | void PickEventHandler::doOperation() |
|---|
| 116 | { |
|---|
| 117 | switch(_operation) |
|---|
| 118 | { |
|---|
| [10117] | 119 | case(osgPresentation::RUN): |
|---|
| [10113] | 120 | { |
|---|
| 121 | osg::notify(osg::NOTICE)<<"Run "<<_command<<std::endl; |
|---|
| [10117] | 122 | |
|---|
| 123 | #if 0 |
|---|
| [10113] | 124 | osgDB::FilePathList& paths = osgDB::getDataFilePathList(); |
|---|
| 125 | if (!paths.empty()) |
|---|
| 126 | { |
|---|
| 127 | #ifdef _WIN32 |
|---|
| 128 | std::string delimintor(";"); |
|---|
| 129 | #else |
|---|
| 130 | std::string delimintor(":"); |
|---|
| 131 | #endif |
|---|
| 132 | std::string filepath("OSG_FILE_PATH="); |
|---|
| [10207] | 133 | |
|---|
| [10113] | 134 | bool needDeliminator = false; |
|---|
| 135 | for(osgDB::FilePathList::iterator itr = paths.begin(); |
|---|
| 136 | itr != paths.end(); |
|---|
| 137 | ++itr) |
|---|
| 138 | { |
|---|
| 139 | if (needDeliminator) filepath += delimintor; |
|---|
| 140 | filepath += *itr; |
|---|
| 141 | needDeliminator = true; |
|---|
| 142 | } |
|---|
| 143 | putenv( (char*) filepath.c_str()); |
|---|
| 144 | |
|---|
| 145 | std::string binpath("PATH="); |
|---|
| 146 | char* path = getenv("PATH"); |
|---|
| 147 | if (path) binpath += path; |
|---|
| [10207] | 148 | |
|---|
| [10113] | 149 | needDeliminator = true; |
|---|
| 150 | for(osgDB::FilePathList::iterator itr = paths.begin(); |
|---|
| 151 | itr != paths.end(); |
|---|
| 152 | ++itr) |
|---|
| 153 | { |
|---|
| 154 | if (needDeliminator) binpath += delimintor; |
|---|
| 155 | binpath += *itr; |
|---|
| 156 | needDeliminator = true; |
|---|
| 157 | } |
|---|
| 158 | putenv( (char*) binpath.c_str()); |
|---|
| 159 | |
|---|
| 160 | } |
|---|
| [10207] | 161 | #endif |
|---|
| [10113] | 162 | int result = system(_command.c_str()); |
|---|
| 163 | |
|---|
| [10207] | 164 | osg::notify(osg::INFO)<<"system("<<_command<<") result "<<result<<std::endl; |
|---|
| 165 | |
|---|
| [10113] | 166 | break; |
|---|
| 167 | } |
|---|
| [10117] | 168 | case(osgPresentation::LOAD): |
|---|
| [10113] | 169 | { |
|---|
| 170 | osg::notify(osg::NOTICE)<<"Load "<<_command<<std::endl; |
|---|
| 171 | break; |
|---|
| 172 | } |
|---|
| [10117] | 173 | case(osgPresentation::EVENT): |
|---|
| [10113] | 174 | { |
|---|
| 175 | osg::notify(osg::INFO)<<"Event "<<_keyPos._key<<" "<<_keyPos._x<<" "<<_keyPos._y<<std::endl; |
|---|
| 176 | if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_keyPos); |
|---|
| 177 | break; |
|---|
| 178 | } |
|---|
| [10117] | 179 | case(osgPresentation::JUMP): |
|---|
| 180 | { |
|---|
| 181 | osg::notify(osg::NOTICE)<<"Requires jump "<<std::endl; |
|---|
| 182 | break; |
|---|
| 183 | } |
|---|
| [10113] | 184 | } |
|---|
| 185 | |
|---|
| 186 | if (requiresJump()) |
|---|
| 187 | { |
|---|
| 188 | osg::notify(osg::NOTICE)<<"Requires jump "<<_relativeJump<<", "<<_slideNum<<", "<<_layerNum<<std::endl; |
|---|
| [10207] | 189 | |
|---|
| [10113] | 190 | if (_relativeJump) |
|---|
| 191 | { |
|---|
| 192 | int previousSlide = SlideEventHandler::instance()->getActiveSlide(); |
|---|
| 193 | int previousLayer = SlideEventHandler::instance()->getActiveLayer(); |
|---|
| 194 | int newSlide = previousSlide + _slideNum; |
|---|
| 195 | int newLayer = previousLayer + _layerNum; |
|---|
| 196 | if (newLayer<0) |
|---|
| 197 | { |
|---|
| 198 | newLayer = 0; |
|---|
| 199 | } |
|---|
| [10207] | 200 | |
|---|
| [10113] | 201 | osg::notify(osg::NOTICE)<<" jump to "<<newSlide<<", "<<newLayer<<std::endl; |
|---|
| 202 | |
|---|
| 203 | SlideEventHandler::instance()->selectSlide(newSlide, newLayer); |
|---|
| 204 | } |
|---|
| 205 | else |
|---|
| 206 | { |
|---|
| 207 | SlideEventHandler::instance()->selectSlide(_slideNum,_layerNum); |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | else |
|---|
| 211 | { |
|---|
| 212 | osg::notify(osg::NOTICE)<<"No jump required."<<std::endl; |
|---|
| 213 | } |
|---|
| 214 | } |
|---|