root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/ExportOptions.cpp @ 8888

Revision 8888, 7.8 kB (checked in by robert, 6 years ago)

From John Argentieri, added missing _stripTextureFilePath( false ) initializer.

RevLine 
[8003]1/*
2 * This library is open source and may be redistributed and/or modified under
3 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or (at
4 * your option) any later version. The full license is in the LICENSE file
5 * included with this distribution, and on the openscenegraph.org website.
6 *
7 * This library is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * OpenSceneGraph Public License for more details.
11*/
12
13//
14// Copyright(c) 2008 Skew Matrix Software LLC.
15//
16
17#include <osg/Notify>
18#include <osg/ProxyNode>
19
20#include <osgDB/FileNameUtils>
21#include <osgDB/FileUtils>
22#include <osgDB/Registry>
23#include <osgDB/ReadFile>
24
25#include "ExportOptions.h"
26
27#include <fstream>
28#include <sstream>
29
30namespace flt
31{
32
33
34
35/** @name Valid Option Strings
36 *  This plugin supports the following \c Option string values.
37 */
38//@{
39/** Value: "version".
40 *  Specifies the version of the output OpenFlight file. Supported values
41 *  include 15.7, 15.8, and 16.1. Default is 16.1. Example:
42 *  "version=15.8".
43 */
44std::string ExportOptions::_versionOption( "version" );
45/** Value: "units".
46 *  Specifies the contents of the \c Units field of the OpenFliht header record.
47 *  Valid values include INCHES, FEET, METERS, KILOMETERS, and NATICAL_MILES.
48 *  Default is METERS. Example: "units=METERS".
49 */
50std::string ExportOptions::_unitsOption( "units" );
51/** Value: "validate".
52 *  If present in the Options string, the plugin does not write an OpenFlight file.
53 *  Instead, it returns an indication of the scene graph's suitability for
54 *  OpenFlight export.
55 */
56std::string ExportOptions::_validateOption( "validate" );
57/** Value: "tempDir".
58 *  Specifies the directory to use for creation of temporary files. If not
59 *  specified, the directory is taken from the file name. If the file doesn't
60 *  contain a path, the current working directory is used. Applications should
61 *  set this to the name of their app-specific temp directory. If the path
62 *  contains spaces, use double quotes to ensure correct parsing. Examples:
63 *  "tempDir=/tmp".
64 *  "tempDir=\"C:\\My Temp Dir\"".
65 */
66std::string ExportOptions::_tempDirOption( "tempDir" );
67/** Value: "lighting".
68 *  Specifies a default enable/disable state for lighting, for Nodes in the
69 *  exported scene graph that don't set it explicitly. By default, the
70 *  exporter assumes lighting is enabled (GL_LIGHTING ON). Set this to
71 *  either ON or OFF. Example:
72 *  "lighting=OFF".
73 */
74std::string ExportOptions::_lightingOption( "lighting" );
75/** Value: "stripTextureFilePath".
76 *  If present in the Options string, the exporter strips the path from
[8563]77 *  texture file names, and writes only the texture file name to the FLT
[8003]78 *  Texture Palette. By default, the exporter doesn't strip the path,
79 *  and the name written to the Texture Palette is taken directly from
80 *  the osg::Image object referenced by the osg::Texture2D StateAttribute.
81 */
82std::string ExportOptions::_stripTextureFilePathOption( "stripTextureFilePath" );
83//@}
84
85
86using namespace osgDB;
87
88
89const int ExportOptions::VERSION_15_7( 1570 );
90const int ExportOptions::VERSION_15_8( 1580 );
91const int ExportOptions::VERSION_16_1( 1610 );
92
93
94
95ExportOptions::ExportOptions()
96  : _version( VERSION_16_1 ),
97    _units( METERS ),
98    _validate( false ),
99    _lightingDefault( true ),
100    _stripTextureFilePath( false )
101{
102}
103
104ExportOptions::ExportOptions( const osgDB::ReaderWriter::Options* opt )
105  : _version( VERSION_16_1 ),
106    _units( METERS ),
107    _validate( false ),
[8888]108    _lightingDefault( true ),
109    _stripTextureFilePath( false )
110   
[8003]111{
112    if (opt)
113    {
114        const ExportOptions* fltOpt = dynamic_cast<const ExportOptions*>( opt );
115        if (fltOpt)
116        {
117            _version = fltOpt->_version;
118            _units = fltOpt->_units;
119            _validate = fltOpt->_validate;
120            _tempDir = fltOpt->_tempDir;
121            _lightingDefault = fltOpt->_lightingDefault;
122        }
123        setOptionString( opt->getOptionString() );
124    }
125}
126
127void
128ExportOptions::parseOptionsString()
129{
130    // Parse out the option string and store values directly in
131    //   ExportOptions member variables.
132
133    const std::string& str = getOptionString();
134    if (str.empty())
135        return;
136
137    std::string::size_type pos( 0 );
138    while (pos != str.npos)
139    {
140        // Skip leading spaces.
141        while ( (pos < str.length()) &&
142            (str[pos] == ' ') )
143            pos++;
144
145        // Get the next token
146        std::string::size_type count = str.substr( pos ).find_first_of( " =" );
147        std::string token = str.substr( pos, count );
148        if (count == str.npos)
149            pos = str.npos;
150        else
151            pos += (count+1);
152
153        // See if it's a Boolen/toggle
154        if ( token == _validateOption )
155        {
156            osg::notify( osg::INFO ) << "fltexp: Found: " << token << std::endl;
157            setValidateOnly( true );
158            continue;
159        }
160        if ( token == _stripTextureFilePathOption )
161        {
162            osg::notify( osg::INFO ) << "fltexp: Found: " << token << std::endl;
163            setStripTextureFilePath( true );
164            continue;
165        }
166
167        // Not a Boolean/toggle. Must have a value.
168        // Get the value of the token, which could be double-quoted.
169        if( str[pos] == '"' )
170        {
171            ++pos;
172            count = str.substr( pos ).find_first_of( '"' );
173        }
174        else
175            count = str.substr( pos ).find_first_of( ' ' );
176        std::string value = str.substr( pos, count );
177        if (count == str.npos)
178            pos = str.npos;
179        else
180            pos += (count+1);
181
182        if (token == _versionOption)
183        {
184            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
185            int version( VERSION_16_1 );
186            if( value == std::string( "15.7" ) )
187                version = VERSION_15_7;
188            else if( value == std::string( "15.8" ) )
189                version = VERSION_15_8;
190            else if( value != std::string( "16.1" ) )
191                osg::notify( osg::WARN ) << "fltexp: Unsupported version: " << value << ". Defaulting to 16.1." << std::endl;
192            setFlightFileVersionNumber( version );
193        }
194        else if (token == _unitsOption)
195        {
196            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
197            FlightUnits units( METERS );
198            if( value == std::string( "KILOMETERS" ) )
199                units = KILOMETERS;
200            else if( value == std::string( "FEET" ) )
201                units = FEET;
202            else if( value == std::string( "INCHES" ) )
203                units = INCHES;
204            else if( value == std::string( "NAUTICAL_MILES" ) )
205                units = NAUTICAL_MILES;
206            else if( value != std::string( "METERS" ) )
207                osg::notify( osg::WARN ) << "fltexp: Unsupported units: " << value << ". Defaulting to METERS." << std::endl;
208            setFlightUnits( units );
209        }
210        else if (token == _tempDirOption)
211        {
212            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
213            setTempDir( value );
214        }
215        else if (token == _lightingOption)
216        {
217            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
218            bool lighting( true );
219            if (value == std::string( "OFF" ) )
220                lighting = false;
221            else if (value != std::string( "ON" ) )
222                osg::notify( osg::WARN ) << "fltexp: Unsupported lighting value: " << value << ". Defaulting to ON." << std::endl;
223            setLightingDefault( lighting );
224        }
225        else
226            osg::notify( osg::WARN ) << "fltexp: Bogus OptionString: " << token << std::endl;
227    }
228}
229
230
231}
Note: See TracBrowser for help on using the browser.