From Stephan Hunber, "attached you’ll find some changes to osg/p3d:

* a new command-line-option to present3d and a new option to the p3d-plugin to suppress any found <env> tags
* a new command-line-option to present3d to forward mouse-events via osgGA::Device (defaults to off) so we can test the interface-files with present3d better
* I added a new attribute forward_to_devices for click_to_event to forward the event to all attached devices instead of handling the event locally. This will fix the annoyance with the new interface-files when toggling polygon-mode or switching light on/off.

Here’s an example:

<click_to_event forward_to_devices="true">0x72</click_to_event>
"
This commit is contained in:
Robert Osfield
2013-12-19 13:49:27 +00:00
parent 02120e188e
commit f16f278fea
5 changed files with 119 additions and 27 deletions

View File

@@ -41,6 +41,8 @@ class ReaderWriterP3DXML : public osgDB::ReaderWriter
public:
ReaderWriterP3DXML()
{
supportsOption("suppressEnvTags", "if set to (true|1) all env-tags in the p3d-file will be suppressed");
_colorMap["WHITE"] .set(1.0f,1.0f,1.0f,1.0f);
_colorMap["BLACK"] .set(0.0f,0.0f,0.0f,1.0f);
_colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f);
@@ -112,6 +114,7 @@ public:
return osgDB::equalCaseInsensitive(extension,"p3d") ||
osgDB::equalCaseInsensitive(extension,"xml") ;
}
virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* options) const;
@@ -175,7 +178,8 @@ public:
inline bool read(const char* str, osg::Vec2& value) const;
inline bool read(const char* str, osg::Vec3& value) const;
inline bool read(const char* str, osg::Vec4& value) const;
inline bool read(const std::string& str, bool& value) const;
inline bool read(const std::string& str, int& value) const;
inline bool read(const std::string& str, float& value) const;
inline bool read(const std::string& str, double& value) const;
@@ -186,6 +190,7 @@ public:
bool getProperty(osgDB::XmlNode*cur, const char* token) const;
bool getKeyProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, bool& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const;
@@ -324,6 +329,17 @@ bool ReaderWriterP3DXML::read(const char* str, osg::Vec4& value) const
return !iss.fail();
}
bool ReaderWriterP3DXML::read(const std::string& str, bool& value) const
{
if ((str == "1") || (str == "0")) {
value = (str == "1");
return true;
}
std::string s(osgDB::convertToLowerCase(str));
value = (s == "true");
return true;
}
bool ReaderWriterP3DXML::read(const std::string& str, int& value) const
{
std::istringstream iss(str);
@@ -383,6 +399,13 @@ bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode* cur, const char* token) con
return cur->properties.count(token)!=0;
}
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, bool& value) const
{
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
if (itr==cur->properties.end()) return false;
return read(itr->second,value);
}
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int& value) const
{
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
@@ -1426,7 +1449,7 @@ bool ReaderWriterP3DXML::getKeyPosition(osgDB::XmlNode*cur, osgPresentation::Key
cur->name == "esc" ||
cur->name == "exit")
{
keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f);
keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f, false);
return true;
}
return false;
@@ -1455,7 +1478,9 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation
// v in range 0.0 to 1, from bottom to top
y = v*2.0f-1.0f;
}
bool forward_to_devices = false;
getProperty(cur, "forward_to_devices", forward_to_devices);
std::string key = cur->getTrimmedContents();
unsigned int keyValue = 0;
@@ -1494,7 +1519,7 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation
return false;
}
keyPosition.set(keyValue,x,y);
keyPosition.set(keyValue,x,y, forward_to_devices);
return true;
}
@@ -2855,13 +2880,15 @@ osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode* root, bool readOnly
osgDB::FilePathList previousPaths = osgDB::getDataFilePathList();
bool env_tag_suppressed = false || (options && ((options->getPluginStringData("suppressEnvTags") == "1") || (options->getPluginStringData("suppressEnvTags") == "true")));
for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
itr != root->children.end();
++itr)
{
osgDB::XmlNode* cur = itr->get();
if (cur->name=="env")
if (cur->name=="env" && !env_tag_suppressed)
{
char* str = strdup(cur->contents.c_str());
OSG_INFO<<"putenv("<<str<<")"<<std::endl;

View File

@@ -87,16 +87,7 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
// std::cout << transformed_x << "/" << transformed_x << " -> " << cloned_ea->getX() << "/" <<cloned_ea->getY() << std::endl;
// dispatch cloned event to devices
osgViewer::View::Devices& devices = viewer->getDevices();
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
{
if((*i)->getCapabilities() & osgGA::Device::SEND_EVENTS)
{
(*i)->sendEvent(*cloned_ea);
}
}
SlideEventHandler::instance()->forwardEventToDevices(cloned_ea);
}
else
{

View File

@@ -1550,8 +1550,39 @@ void SlideEventHandler::releaseSlide(unsigned int slideNum)
_presentationSwitch->getChild(slideNum)->accept(globjVisitor);
}
void SlideEventHandler::forwardEventToDevices(osgGA::Event* event)
{
// dispatch cloned event to devices
osgViewer::View::Devices& devices = _viewer->getDevices();
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
{
if((*i)->getCapabilities() & osgGA::Device::SEND_EVENTS)
{
(*i)->sendEvent(*event);
}
}
}
void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition)
{
if (keyPosition._forwardToDevices)
{
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter();
event->setKey(keyPosition._key);
event->setTime(_viewer->getEventQueue()->getTime());
// forward key-down
event->setEventType(osgGA::GUIEventAdapter::KEYDOWN);
forwardEventToDevices(event);
// forward key-up
event->setEventType(osgGA::GUIEventAdapter::KEYUP);
forwardEventToDevices(event);
// ignore local event-queue
return;
}
osgGA::EventQueue* eq = _viewer->getEventQueue();
// reset the time of the last key press to ensure that the event is disgarded as a key repeat.