Changeset 8306

Show
Ignore:
Timestamp:
05/12/08 12:55:55
Author:
robert
Message:

From Eric Sokolowski and Robert Osfield, moved command line option usage setup
from osgviewer example into osg::ArgumentParser? and osgViewer::Viewer to make
them more universally available.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/applications/osgviewer/osgviewer.cpp

    r7895 r8306  
    4040    arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); 
    4141    arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); 
    42     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); 
    43     arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); 
    44     arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); 
    45     arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings."); 
    46     arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer."); 
    47     arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer."); 
    48     arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer."); 
    49     arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer."); 
    5042 
    51     // if user request help write it out to cout. 
    52     bool helpAll = arguments.read("--help-all"); 
    53     unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | 
    54                             ((helpAll ||  arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | 
    55                             ((helpAll ||  arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); 
    56     if (helpType) 
     43    osgViewer::Viewer viewer(arguments); 
     44 
     45    unsigned int helpType = 0; 
     46    if ((helpType = arguments.readHelpType())) 
    5747    { 
    5848        arguments.getApplicationUsage()->write(std::cout, helpType); 
    5949        return 1; 
    6050    } 
    61  
    62     osgViewer::Viewer viewer(arguments); 
    6351     
    6452    // report any errors if they have occurred when parsing the program arguments. 
  • OpenSceneGraph/trunk/include/osg/ApplicationUsage

    r7648 r8306  
    4444        enum Type 
    4545        { 
     46            NO_HELP = 0x0, 
    4647            COMMAND_LINE_OPTION = 0x1, 
    4748            ENVIRONMENTAL_VARIABLE = 0x2, 
    48             KEYBOARD_MOUSE_BINDING = 0x4 
     49            KEYBOARD_MOUSE_BINDING = 0x4, 
     50            HELP_ALL = KEYBOARD_MOUSE_BINDING|ENVIRONMENTAL_VARIABLE|COMMAND_LINE_OPTION 
    4951        }; 
    5052         
  • OpenSceneGraph/trunk/include/osg/ArgumentParser

    r7648 r8306  
    191191        void writeErrorMessages(std::ostream& output,ErrorSeverity sevrity=BENIGN); 
    192192 
     193         
     194        /** This convinience method handles help requests on the command line. 
     195          * Return the type(s) of help requested. The return value of this 
     196          * function is suitable for passing into getApplicationUsage()->write(). 
     197          * If ApplicationUsage::NO_HELP is returned then no help commandline option  
     198          * was found on the command line. */ 
     199        ApplicationUsage::Type readHelpType(); 
     200 
    193201   
    194202  protected: 
  • OpenSceneGraph/trunk/src/osg/ArgumentParser.cpp

    r7442 r8306  
    631631    } 
    632632} 
     633 
     634ApplicationUsage::Type ArgumentParser::readHelpType()  
     635{ 
     636    getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); 
     637    getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); 
     638    getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); 
     639    getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings."); 
     640 
     641    // if user request help write it out to cout. 
     642    if (read("--help-all"))             return ApplicationUsage::HELP_ALL; 
     643    if (read("-h") || read("--help"))   return ApplicationUsage::COMMAND_LINE_OPTION; 
     644    if (read("--help-env"))             return ApplicationUsage::ENVIRONMENTAL_VARIABLE; 
     645    if (read("--help-keys"))            return ApplicationUsage::KEYBOARD_MOUSE_BINDING; 
     646 
     647    return ApplicationUsage::NO_HELP; 
     648} 
  • OpenSceneGraph/trunk/src/osgViewer/Viewer.cpp

    r8276 r8306  
    4444 
    4545    constructorInit(); 
     46 
     47    // Add help for command-line options read here 
     48    arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer."); 
     49    arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer."); 
     50    arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer."); 
     51    arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer."); 
     52    arguments.getApplicationUsage()->addCommandLineOption("--clear-color <color>","Set the background color of the viewer in the form \"r,g,b[,a]\"."); 
     53    arguments.getApplicationUsage()->addCommandLineOption("--screen <num>","Set the screen to use when multiple screens are present."); 
     54    arguments.getApplicationUsage()->addCommandLineOption("--window <x y w h>","Set the position (x,y) and size (w,h) of the viewer window."); 
     55    // FIXME: Uncomment these lines when the options have been documented properly 
     56    //arguments.getApplicationUsage()->addCommandLineOption("--3d-sd",""); 
     57    //arguments.getApplicationUsage()->addCommandLineOption("--panoramic-sd",""); 
     58    //arguments.getApplicationUsage()->addCommandLineOption("--radius",""); 
     59    //arguments.getApplicationUsage()->addCommandLineOption("--collar",""); 
     60    //arguments.getApplicationUsage()->addCommandLineOption("--im",""); 
    4661     
    4762    std::string filename;