2009-04-27 19:02:18 +08:00
|
|
|
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
|
|
|
*
|
|
|
|
* This software is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the GNU General Public License (GPL) version 2.0.
|
|
|
|
* The full license is in LICENSE.txt file included with this distribution,.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* include LICENSE.txt for more details.
|
|
|
|
*/
|
|
|
|
|
2009-06-25 00:03:49 +08:00
|
|
|
#include <osgPresentation/PickEventHandler>
|
|
|
|
#include <osgPresentation/SlideEventHandler>
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
#include <osg/Notify>
|
|
|
|
#include <osgDB/FileUtils>
|
|
|
|
|
2009-11-17 22:06:07 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-04-30 04:30:21 +08:00
|
|
|
using namespace osgPresentation;
|
|
|
|
|
|
|
|
PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum):
|
2009-04-27 19:02:18 +08:00
|
|
|
_operation(operation),
|
|
|
|
_relativeJump(relativeJump),
|
|
|
|
_slideNum(slideNum),
|
|
|
|
_layerNum(layerNum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-30 04:30:21 +08:00
|
|
|
PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum):
|
2009-04-27 19:02:18 +08:00
|
|
|
_command(str),
|
|
|
|
_operation(operation),
|
|
|
|
_relativeJump(relativeJump),
|
|
|
|
_slideNum(slideNum),
|
|
|
|
_layerNum(layerNum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-30 04:30:21 +08:00
|
|
|
PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum):
|
2009-04-27 19:02:18 +08:00
|
|
|
_keyPos(keyPos),
|
2009-04-30 04:30:21 +08:00
|
|
|
_operation(osgPresentation::EVENT),
|
2009-04-27 19:02:18 +08:00
|
|
|
_relativeJump(relativeJump),
|
|
|
|
_slideNum(slideNum),
|
|
|
|
_layerNum(layerNum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
switch(ea.getEventType())
|
|
|
|
{
|
|
|
|
case(osgGA::GUIEventAdapter::MOVE):
|
|
|
|
case(osgGA::GUIEventAdapter::PUSH):
|
|
|
|
case(osgGA::GUIEventAdapter::RELEASE):
|
|
|
|
{
|
|
|
|
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
|
|
|
|
osgUtil::LineSegmentIntersector::Intersections intersections;
|
|
|
|
if (viewer->computeIntersections(ea.getX(),ea.getY(), nv->getNodePath(), intersections))
|
|
|
|
{
|
|
|
|
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr=intersections.begin();
|
|
|
|
hitr!=intersections.end();
|
|
|
|
++hitr)
|
|
|
|
{
|
|
|
|
if (ea.getEventType()==osgGA::GUIEventAdapter::MOVE)
|
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_INFO<<"Tooltip..."<<std::endl;
|
2009-04-27 19:02:18 +08:00
|
|
|
}
|
|
|
|
else if (ea.getEventType()==osgGA::GUIEventAdapter::RELEASE)
|
|
|
|
{
|
|
|
|
doOperation();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(osgGA::GUIEventAdapter::KEYDOWN):
|
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
//OSG_NOTICE<<"PickEventHandler KEYDOWN "<<(char)ea.getKey()<<std::endl;
|
|
|
|
//if (object) OSG_NOTICE<<" "<<object->className()<<std::endl;
|
2009-04-27 19:02:18 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PickEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
|
|
|
|
{
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PickEventHandler::setRelativeJump(int slideNum, int layerNum)
|
|
|
|
{
|
|
|
|
_relativeJump = true;
|
|
|
|
_slideNum = slideNum;
|
|
|
|
_layerNum = layerNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PickEventHandler::setAbsoluteJump(int slideNum, int layerNum)
|
|
|
|
{
|
|
|
|
_relativeJump = false;
|
|
|
|
_slideNum = slideNum;
|
|
|
|
_layerNum = layerNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PickEventHandler::doOperation()
|
|
|
|
{
|
|
|
|
switch(_operation)
|
|
|
|
{
|
2009-04-30 04:30:21 +08:00
|
|
|
case(osgPresentation::RUN):
|
2009-04-27 19:02:18 +08:00
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_NOTICE<<"Run "<<_command<<std::endl;
|
2009-04-30 04:30:21 +08:00
|
|
|
|
|
|
|
#if 0
|
2009-04-27 19:02:18 +08:00
|
|
|
osgDB::FilePathList& paths = osgDB::getDataFilePathList();
|
|
|
|
if (!paths.empty())
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
std::string delimintor(";");
|
|
|
|
#else
|
|
|
|
std::string delimintor(":");
|
|
|
|
#endif
|
|
|
|
std::string filepath("OSG_FILE_PATH=");
|
2009-05-14 21:30:25 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
bool needDeliminator = false;
|
|
|
|
for(osgDB::FilePathList::iterator itr = paths.begin();
|
|
|
|
itr != paths.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (needDeliminator) filepath += delimintor;
|
|
|
|
filepath += *itr;
|
|
|
|
needDeliminator = true;
|
|
|
|
}
|
|
|
|
putenv( (char*) filepath.c_str());
|
|
|
|
|
|
|
|
std::string binpath("PATH=");
|
|
|
|
char* path = getenv("PATH");
|
|
|
|
if (path) binpath += path;
|
2009-05-14 21:30:25 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
needDeliminator = true;
|
|
|
|
for(osgDB::FilePathList::iterator itr = paths.begin();
|
|
|
|
itr != paths.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (needDeliminator) binpath += delimintor;
|
|
|
|
binpath += *itr;
|
|
|
|
needDeliminator = true;
|
|
|
|
}
|
|
|
|
putenv( (char*) binpath.c_str());
|
|
|
|
|
|
|
|
}
|
2009-05-14 21:30:25 +08:00
|
|
|
#endif
|
2009-04-27 19:02:18 +08:00
|
|
|
int result = system(_command.c_str());
|
2009-05-14 21:30:25 +08:00
|
|
|
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_INFO<<"system("<<_command<<") result "<<result<<std::endl;
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2009-04-30 04:30:21 +08:00
|
|
|
case(osgPresentation::LOAD):
|
2009-04-27 19:02:18 +08:00
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_NOTICE<<"Load "<<_command<<std::endl;
|
2009-04-27 19:02:18 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-04-30 04:30:21 +08:00
|
|
|
case(osgPresentation::EVENT):
|
2009-04-27 19:02:18 +08:00
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_INFO<<"Event "<<_keyPos._key<<" "<<_keyPos._x<<" "<<_keyPos._y<<std::endl;
|
2009-04-27 19:02:18 +08:00
|
|
|
if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_keyPos);
|
|
|
|
break;
|
|
|
|
}
|
2009-04-30 04:30:21 +08:00
|
|
|
case(osgPresentation::JUMP):
|
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_NOTICE<<"Requires jump "<<std::endl;
|
2009-04-30 04:30:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-04-27 19:02:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (requiresJump())
|
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_NOTICE<<"Requires jump "<<_relativeJump<<", "<<_slideNum<<", "<<_layerNum<<std::endl;
|
2009-05-14 21:30:25 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
if (_relativeJump)
|
|
|
|
{
|
|
|
|
int previousSlide = SlideEventHandler::instance()->getActiveSlide();
|
|
|
|
int previousLayer = SlideEventHandler::instance()->getActiveLayer();
|
|
|
|
int newSlide = previousSlide + _slideNum;
|
|
|
|
int newLayer = previousLayer + _layerNum;
|
|
|
|
if (newLayer<0)
|
|
|
|
{
|
|
|
|
newLayer = 0;
|
|
|
|
}
|
2009-05-14 21:30:25 +08:00
|
|
|
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_NOTICE<<" jump to "<<newSlide<<", "<<newLayer<<std::endl;
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
SlideEventHandler::instance()->selectSlide(newSlide, newLayer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SlideEventHandler::instance()->selectSlide(_slideNum,_layerNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 00:08:15 +08:00
|
|
|
OSG_NOTICE<<"No jump required."<<std::endl;
|
2009-04-27 19:02:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|