From 20560bd927e479a434004afc58e0b0da8d6f51c4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 21 Jul 2014 12:21:42 +0000 Subject: [PATCH] Initial work on integtasting osgUI into Present3D git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14370 16af8721-9629-0410-8352-f15c8da7e697 --- src/osgPresentation/CMakeLists.txt | 2 + .../deprecated/SlideShowConstructor.cpp | 110 +++++++++++++++--- 2 files changed, 95 insertions(+), 17 deletions(-) diff --git a/src/osgPresentation/CMakeLists.txt b/src/osgPresentation/CMakeLists.txt index 31c638802..b634a1db2 100644 --- a/src/osgPresentation/CMakeLists.txt +++ b/src/osgPresentation/CMakeLists.txt @@ -74,6 +74,8 @@ SET(TARGET_SRC SET(TARGET_LIBRARIES osgViewer + osgUI + osgWidget osgManipulator osgVolume osgFX diff --git a/src/osgPresentation/deprecated/SlideShowConstructor.cpp b/src/osgPresentation/deprecated/SlideShowConstructor.cpp index 72326d2a5..6c20b6034 100644 --- a/src/osgPresentation/deprecated/SlideShowConstructor.cpp +++ b/src/osgPresentation/deprecated/SlideShowConstructor.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -42,6 +43,8 @@ #include +#include + #include #include @@ -2115,7 +2118,7 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD subgraph = group; - osgDB::writeNodeFile(*subgraph, "output.osgt"); + // osgDB::writeNodeFile(*subgraph, "output.osgt"); } @@ -2510,11 +2513,33 @@ protected: std::string _source; }; -struct CollectVolumeSettingsVisitor : public osgVolume::PropertyVisitor +struct CollectVolumeSettingsVisitor : public osgVolume::PropertyVisitor, public osg::NodeVisitor { CollectVolumeSettingsVisitor(): osgVolume::PropertyVisitor(false) {} + virtual void apply(osg::Node& node) + { + osgVolume::VolumeTile* tile = dynamic_cast(&node); + if (tile) + { + OSG_NOTICE<<"Found Tile "<getLayer()->getProperty()->accept(*this); + return; + } + + osgUI::Widget* widget = dynamic_cast(&node); + if (widget) + { + OSG_NOTICE<<"Found Widget "< > VolumeSettingsList; VolumeSettingsList _vsList; + + typedef std::vector< osg::ref_ptr > WidgetList; + WidgetList _widgets; }; struct VolumeSettingsCallback : public osgGA::GUIEventHandler { VolumeSettingsCallback(): - _saveKey(19), // Ctril-S - _editKey(05) // Ctrl-E + //_saveKey(19), // Ctril-S + //_editKey(05) // Ctrl-E + _saveKey('W'), + _editKey('E') { } @@ -2540,8 +2570,8 @@ struct VolumeSettingsCallback : public osgGA::GUIEventHandler { if (ea.getHandled()) return false; - osgVolume::VolumeTile* tile = dynamic_cast(object); - if (!tile) + osg::Node* node = dynamic_cast(object); + if (!node) { OSG_NOTICE<<"Warning: VolumeSettingsCallback assigned to a node other than VolumeTile, cannot operate edit/save."<getLayer()->getProperty()->accept(cvsv); + node->accept(cvsv); for(CollectVolumeSettingsVisitor::VolumeSettingsList::iterator itr = cvsv._vsList.begin(); itr != cvsv._vsList.end(); @@ -2578,6 +2608,19 @@ struct VolumeSettingsCallback : public osgGA::GUIEventHandler if (ea.getKey()==_editKey) { OSG_NOTICE<<"Need to edit VolumeSettings "<accept(cvsv); + + for(CollectVolumeSettingsVisitor::WidgetList::iterator itr = cvsv._widgets.begin(); + itr != cvsv._widgets.end(); + ++itr) + { + osgUI::Widget* widget = itr->get(); + OSG_NOTICE<<"Toggling visibility of Widget "<setVisible(!widget->getVisible()); + } return true; } } @@ -2748,6 +2791,8 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position volume->addChild(tile.get()); } + osg::ref_ptr vs = volumeData.volumeSettings; + if (!layer) { if (!image) return; @@ -2809,8 +2854,6 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position groupPropetry->addProperty(sp.get()); - osg::ref_ptr vs = volumeData.volumeSettings; - osg::ref_ptr ap = vs.valid() ? vs->getCutoffProperty() : new osgVolume::AlphaFuncProperty(0.1f); setUpVolumeScalarProperty(tile.get(), ap.get(), volumeData.cutoffValue); @@ -3016,10 +3059,16 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position osg::ref_ptr model = volume.get(); + osg::ref_ptr group = dynamic_cast(model.get()); if (volumeData.useTabbedDragger || volumeData.useTrackballDragger) { - osg::ref_ptr group = new osg::Group; + if (!group) + { + group = new osg::Group; + group->addChild(volume.get()); + model = group.get(); + } osg::ref_ptr dragger; if (volumeData.useTabbedDragger) @@ -3038,20 +3087,47 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position dragger->addDraggerCallback(new DraggerVolumeTileCallback(tile.get(), tile->getLocator())); dragger->setMatrix(osg::Matrix::translate(0.5,0.5,0.5)*tile->getLocator()->getTransform()); - group->addChild(dragger.get()); - //dragger->addChild(volume.get()); - - group->addChild(volume.get()); - - model = group.get(); } - tile->addEventCallback(new VolumeSettingsCallback()); + + + model->addEventCallback(new VolumeSettingsCallback()); ModelData modelData; addModel(model.get(), positionData, modelData, scriptData); + +#if 0 + osgUI::Widget* widget = vs.valid() ? osgDB::readFile("VolumeSettings.lua") : 0; + if (widget) + { + OSG_NOTICE<<"Addig widget"<setVisible(true); + vs->setName("VolumeSettings"); + widget->getOrCreateUserDataContainer()->addUserObject(vs.get()); + + osg::Vec3 pos = convertSlideToModel(osg::Vec3(0.0f,0.0f,0.0f)); + + const osg::BoundingBox& bb = widget->getExtents(); + float slide_scale = 0.5f*_slideWidth/(bb.xMax()-bb.xMin()); + + osg::MatrixTransform* transform = new osg::MatrixTransform; + transform->setDataVariance(osg::Object::DYNAMIC); + transform->setMatrix(osg::Matrix::rotate(osg::inDegrees(90.0f),osg::Vec3(1.0f,0.0f,0.0f)) * osg::Matrix::scale(slide_scale,slide_scale,slide_scale)*osg::Matrix::translate(pos)); + transform->addChild(widget); + +#if 1 + HUDTransform* hudTransform = new HUDTransform(_hudSettings.get()); + hudTransform->addChild(transform); + + addToCurrentLayer(hudTransform); +#else + addToCurrentLayer(transform); +#endif + } +#endif } bool SlideShowConstructor::attachTexMat(osg::StateSet* stateset, const ImageData& imageData, float s, float t, bool textureRectangle)