Changeset 153


Ignore:
Timestamp:
Nov 11, 2010, 9:03:48 PM (13 years ago)
Author:
Torben Dannhauer
Message:

visual2D enhanced to use XML config file.
todo: test

Location:
osgVisual
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/bin/osgVisualConfig.xml

    r151 r153  
    1818  <module name="sky_silverlining" enabled="yes"></module>
    1919  <module name="vista2d" enabled="yes">
    20     <vista2d filename="hud.view"></vista2d>
     20    <vista2d filename="hud.view" paintBackground="no" position_x="800" position_y="450" zoom="0.5"></vista2d>
    2121  </module>
    2222 
  • osgVisual/include/vista2D/visual_vista2D.h

    r32 r153  
    1717
    1818#include "VistaView.h"
     19
     20#include <string>
    1921
    2022#include <osg/Drawable>
     
    7072         * @return : True if successful.
    7173         */
    72         static bool createVistaOverlay( std::string vista2DFilename_, osg::CoordinateSystemNode *sceneGraphRoot_ );
     74        static bool init( osg::CoordinateSystemNode *sceneGraphRoot_, std::string configFileName );
    7375
    7476        /**
     
    8890
    8991private:
     92
     93        bool processXMLConfiguration();
     94
    9095        /**
    9196         * \brief This function initialized the visual_vista2D object after instantiation by createVistaOverlay()
    92          *
    93          * @param vista2DFilename_ : Vista2D project file to instantiate.
    9497         */
    95         void init(std::string vista2DFilename_);
     98        void startVista2D();
    9699
    97100        /**
     
    109112         */
    110113        Vista2D::VistaView* view;
     114
     115        /**
     116         * XML config filename
     117         */
     118        std::string configFileName;
     119
     120        /**
     121         * Filename of the Vista2D project file.
     122         */
     123        std::string filename;
     124
     125        /**
     126         * Should the background of the Vista2D project be painted?
     127         */
     128        bool paintBackground;
     129
     130        /**
     131         * X-Position to draw.
     132         */
     133        int position_x;
     134
     135        /**
     136         * Y-Position to draw.
     137         */
     138        int position_y;
     139
     140        /**
     141         * Zoom factor to draw the project.
     142         */
     143        double zoom;
    111144};
    112145
  • osgVisual/src/distortion/visual_distortion.cpp

    r152 r153  
    175175        }
    176176
    177 
    178 
    179177        return true;
    180178}
  • osgVisual/src/vista2D/visual_vista2D.cpp

    r145 r153  
    2424   // Create a Vista2D View
    2525   view = new Vista2D::VistaView();
     26
     27        filename = "";
     28        paintBackground = false;;
     29        position_x = 600;
     30        position_y = 400;
     31        zoom = 0.5;
    2632}
    2733
     
    3036}
    3137
    32 void visual_vista2D::init(std::string vista2DFilename_)
    33 {       
     38void visual_vista2D::startVista2D(std::string vista2DFilename_)
     39{
    3440    /***************
    3541    load view
    3642    ***************/
    37         view->load( vista2DFilename_ );
    38     view->setBackgroundMode(false);     // don't paint background
    39         view->setPosition(800,450);
    40         view->setZoom( 0.5 );
     43        view->load( filename );
     44    view->setBackgroundMode(paintBackground);   // don't paint background
     45        view->setPosition( position_x,position_y);
     46        view->setZoom( zoom );
    4147
    4248    /***************
     
    4854}
    4955
    50 bool visual_vista2D::createVistaOverlay( std::string vista2DFilename_, osg::CoordinateSystemNode *sceneGraphRoot_ )
    51 {
     56bool visual_vista2D::processXMLConfiguration()
     57{
     58        // Init XML
     59        xmlDoc* tmpDoc;
     60        bool disabled;
     61        xmlNode* config = util::getModuleXMLConfig( configFileName, "vista2D", tmpDoc, disabled );
     62
     63        if( disabled)
     64        {
     65                OSG_NOTIFY( osg::ALWAYS ) << "..disabled by XML configuration file." << std::endl;
     66                return false;
     67        }
     68       
     69        // extract configuration values
     70        if(config)
     71        {
     72                xmlNode* a_node = config->children;
     73
     74                for (xmlNode *cur_node = a_node; cur_node; cur_node = cur_node->next)
     75                {
     76                std::string node_name=reinterpret_cast<const char*>(cur_node->name);
     77                        //OSG_ALWAYS << "----visual_vista2D::processXMLConfiguration() - node type="<< cur_node->type <<", name=" << cur_node->name << std::endl;
     78
     79                        // Check for vista2d node
     80                        if(cur_node->type == XML_ELEMENT_NODE && node_name == "vista2d")
     81                        {
     82                                // Check attributes
     83                                xmlAttr  *attr = cur_node->properties;
     84                                while ( attr )
     85                                {
     86                                        std::string attr_name=reinterpret_cast<const char*>(attr->name);
     87                                        std::string attr_value=reinterpret_cast<const char*>(attr->children->content);
     88
     89                                        if( attr_name == "filename" )
     90                                        {
     91                                                filename=attr_value
     92                                        }
     93
     94                                        if( attr_name == "paintBackground" )
     95                                        {
     96                                                paintBackground = (attr_value == "yes") ? true : false;
     97                                        }
     98
     99                                        if( attr_name == "position_x" )
     100                                        {
     101                                                std::stringstream sstr(attr_value);
     102                                                sstr >> position_x;
     103                                        }
     104
     105                                        if( attr_name == "position_y" )
     106                                        {
     107                                                std::stringstream sstr(attr_value);
     108                                                sstr >> position_y;
     109                                        }
     110
     111                                        if( attr_name == "zoom" )
     112                                        {
     113                                                std::stringstream sstr(attr_value);
     114                                                sstr >> zoom;
     115                                        }
     116
     117                                        attr = attr->next;
     118                                }       // WHILE attr END
     119                        }       // IF node == vista2d END
     120                }       // FOR end
     121       
     122                // clean up
     123                xmlFreeDoc(tmpDoc); xmlCleanupParser();
     124                return true;
     125        }       // IF Config valid END
     126        else
     127        {
     128                OSG_WARN << "ERROR: visual_vista2D::processXMLConfiguration() - Module configuration not found" << std::endl;
     129                return false;
     130        }
     131
     132        return true;
     133}
     134
     135bool visual_vista2D::init( osg::CoordinateSystemNode *sceneGraphRoot_, std::string configFileName )
     136{
     137        OSG_NOTIFY (osg::ALWAYS ) << "visual_vista2D initialize..";  // The sentence is finished by the init result...
     138
     139        this->configFileName = configFileName;
     140
     141        // Analyse XML configuration file
     142                // Process XML configuration
     143        if(!processXMLConfiguration())
     144                return false;   // Abort vista2D initialization.
     145
    52146        // Check if Vista2D file exist
    53         if (! osgDB::fileExists( vista2DFilename_ ) )
    54         {
    55                 osg::notify( osg::WARN ) << "WARNING: Could not find specified Vista2D projectfile. Skip adding Vista2D project." << std::endl;
     147        if (! osgDB::fileExists( filename ) )
     148        {
     149                osg::notify( osg::WARN ) << "WARNING: visual_vista2D::createVistaOverlay - Could not find specified Vista2D projectfile. Skip adding Vista2D project." << std::endl;
    56150                return false;
    57151        }
     
    92186        // Add Payload: Vista2D                 
    93187        osg::ref_ptr<visual_vista2D> vista2D = new visual_vista2D();
    94         vista2D->init( vista2DFilename_ );
     188        vista2D->startVista2D( vista2DFilename_ );
    95189
    96190        vista2D.get()->setUseDisplayList( false );
Note: See TracChangeset for help on using the changeset viewer.