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.
This commit is contained in:
parent
61cb0833b9
commit
965c72f5bd
@ -39,27 +39,15 @@ int main(int argc, char** argv)
|
|||||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
|
arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
|
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings.");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer.");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer.");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer.");
|
|
||||||
arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer.");
|
|
||||||
|
|
||||||
// if user request help write it out to cout.
|
osgViewer::Viewer viewer(arguments);
|
||||||
bool helpAll = arguments.read("--help-all");
|
|
||||||
unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) |
|
unsigned int helpType = 0;
|
||||||
((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) |
|
if ((helpType = arguments.readHelpType()))
|
||||||
((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 );
|
|
||||||
if (helpType)
|
|
||||||
{
|
{
|
||||||
arguments.getApplicationUsage()->write(std::cout, helpType);
|
arguments.getApplicationUsage()->write(std::cout, helpType);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
osgViewer::Viewer viewer(arguments);
|
|
||||||
|
|
||||||
// report any errors if they have occurred when parsing the program arguments.
|
// report any errors if they have occurred when parsing the program arguments.
|
||||||
if (arguments.errors())
|
if (arguments.errors())
|
||||||
|
@ -43,9 +43,11 @@ class OSG_EXPORT ApplicationUsage : public osg::Referenced
|
|||||||
|
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
|
NO_HELP = 0x0,
|
||||||
COMMAND_LINE_OPTION = 0x1,
|
COMMAND_LINE_OPTION = 0x1,
|
||||||
ENVIRONMENTAL_VARIABLE = 0x2,
|
ENVIRONMENTAL_VARIABLE = 0x2,
|
||||||
KEYBOARD_MOUSE_BINDING = 0x4
|
KEYBOARD_MOUSE_BINDING = 0x4,
|
||||||
|
HELP_ALL = KEYBOARD_MOUSE_BINDING|ENVIRONMENTAL_VARIABLE|COMMAND_LINE_OPTION
|
||||||
};
|
};
|
||||||
|
|
||||||
void addUsageExplanation(Type type,const std::string& option,const std::string& explanation);
|
void addUsageExplanation(Type type,const std::string& option,const std::string& explanation);
|
||||||
|
@ -190,6 +190,14 @@ class OSG_EXPORT ArgumentParser
|
|||||||
/** Write error messages to the given ostream, if at or above the given severity. */
|
/** Write error messages to the given ostream, if at or above the given severity. */
|
||||||
void writeErrorMessages(std::ostream& output,ErrorSeverity sevrity=BENIGN);
|
void writeErrorMessages(std::ostream& output,ErrorSeverity sevrity=BENIGN);
|
||||||
|
|
||||||
|
|
||||||
|
/** This convinience method handles help requests on the command line.
|
||||||
|
* Return the type(s) of help requested. The return value of this
|
||||||
|
* function is suitable for passing into getApplicationUsage()->write().
|
||||||
|
* If ApplicationUsage::NO_HELP is returned then no help commandline option
|
||||||
|
* was found on the command line. */
|
||||||
|
ApplicationUsage::Type readHelpType();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -630,3 +630,19 @@ void ArgumentParser::writeErrorMessages(std::ostream& output,ErrorSeverity sever
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApplicationUsage::Type ArgumentParser::readHelpType()
|
||||||
|
{
|
||||||
|
getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters");
|
||||||
|
getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
|
||||||
|
getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available");
|
||||||
|
getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings.");
|
||||||
|
|
||||||
|
// if user request help write it out to cout.
|
||||||
|
if (read("--help-all")) return ApplicationUsage::HELP_ALL;
|
||||||
|
if (read("-h") || read("--help")) return ApplicationUsage::COMMAND_LINE_OPTION;
|
||||||
|
if (read("--help-env")) return ApplicationUsage::ENVIRONMENTAL_VARIABLE;
|
||||||
|
if (read("--help-keys")) return ApplicationUsage::KEYBOARD_MOUSE_BINDING;
|
||||||
|
|
||||||
|
return ApplicationUsage::NO_HELP;
|
||||||
|
}
|
||||||
|
@ -43,6 +43,21 @@ Viewer::Viewer(osg::ArgumentParser& arguments)
|
|||||||
_viewerBase = this;
|
_viewerBase = this;
|
||||||
|
|
||||||
constructorInit();
|
constructorInit();
|
||||||
|
|
||||||
|
// Add help for command-line options read here
|
||||||
|
arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer.");
|
||||||
|
arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer.");
|
||||||
|
arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer.");
|
||||||
|
arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer.");
|
||||||
|
arguments.getApplicationUsage()->addCommandLineOption("--clear-color <color>","Set the background color of the viewer in the form \"r,g,b[,a]\".");
|
||||||
|
arguments.getApplicationUsage()->addCommandLineOption("--screen <num>","Set the screen to use when multiple screens are present.");
|
||||||
|
arguments.getApplicationUsage()->addCommandLineOption("--window <x y w h>","Set the position (x,y) and size (w,h) of the viewer window.");
|
||||||
|
// FIXME: Uncomment these lines when the options have been documented properly
|
||||||
|
//arguments.getApplicationUsage()->addCommandLineOption("--3d-sd","");
|
||||||
|
//arguments.getApplicationUsage()->addCommandLineOption("--panoramic-sd","");
|
||||||
|
//arguments.getApplicationUsage()->addCommandLineOption("--radius","");
|
||||||
|
//arguments.getApplicationUsage()->addCommandLineOption("--collar","");
|
||||||
|
//arguments.getApplicationUsage()->addCommandLineOption("--im","");
|
||||||
|
|
||||||
std::string filename;
|
std::string filename;
|
||||||
bool readConfig = false;
|
bool readConfig = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user