~ubuntu-branches/ubuntu/trusty/openscenegraph/trusty

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgPlugins/OpenFlight/ExportOptions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-07-29 04:34:38 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080729043438-no1h9h0dpsrlzp1y
* Non-maintainer upload.
* No longer try to detect (using /proc/cpuinfo when available) how many
  CPUs are available, fixing the FTBFS (due to -j0) on various platforms
  (Closes: #477353). The right way to do it is to support parallel=n in
  DEB_BUILD_OPTIONS (see Debian Policy §4.9.1), and adequate support has
  been implemented.
* Add patch to fix FTBFS due to the build system now refusing to handle
  whitespaces (Policy CMP0004 say the logs), thanks to Andreas Putzo who
  provided it (Closes: #482239):
   - debian/patches/fix-cmp0004-build-failure.dpatch
* Remove myself from Uploaders, as requested a while ago, done by Luk in
  his 2.2.0-2.1 NMU, which was never acknowledged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
30
namespace 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
 */
 
44
std::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
 */
 
50
std::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
 */
 
56
std::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
 */
 
66
std::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
 */
 
74
std::string ExportOptions::_lightingOption( "lighting" );
 
75
/** Value: "stripTextureFilePath".
 
76
 *  If present in the Options string, the exporter strips the path from
 
77
 *  texture file names, and writes only the texure file name to the FLT
 
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
 */
 
82
std::string ExportOptions::_stripTextureFilePathOption( "stripTextureFilePath" );
 
83
//@}
 
84
 
 
85
 
 
86
using namespace osgDB;
 
87
 
 
88
 
 
89
const int ExportOptions::VERSION_15_7( 1570 );
 
90
const int ExportOptions::VERSION_15_8( 1580 );
 
91
const int ExportOptions::VERSION_16_1( 1610 );
 
92
 
 
93
 
 
94
 
 
95
ExportOptions::ExportOptions()
 
96
  : _version( VERSION_16_1 ),
 
97
    _units( METERS ),
 
98
    _validate( false ),
 
99
    _lightingDefault( true ),
 
100
    _stripTextureFilePath( false )
 
101
{
 
102
}
 
103
 
 
104
ExportOptions::ExportOptions( const osgDB::ReaderWriter::Options* opt )
 
105
  : _version( VERSION_16_1 ),
 
106
    _units( METERS ),
 
107
    _validate( false ),
 
108
    _lightingDefault( true )
 
109
{
 
110
    if (opt)
 
111
    {
 
112
        const ExportOptions* fltOpt = dynamic_cast<const ExportOptions*>( opt );
 
113
        if (fltOpt)
 
114
        {
 
115
            _version = fltOpt->_version;
 
116
            _units = fltOpt->_units;
 
117
            _validate = fltOpt->_validate;
 
118
            _tempDir = fltOpt->_tempDir;
 
119
            _lightingDefault = fltOpt->_lightingDefault;
 
120
        }
 
121
        setOptionString( opt->getOptionString() );
 
122
    }
 
123
}
 
124
 
 
125
void
 
126
ExportOptions::parseOptionsString()
 
127
{
 
128
    // Parse out the option string and store values directly in
 
129
    //   ExportOptions member variables.
 
130
 
 
131
    const std::string& str = getOptionString();
 
132
    if (str.empty())
 
133
        return;
 
134
 
 
135
    std::string::size_type pos( 0 );
 
136
    while (pos != str.npos)
 
137
    {
 
138
        // Skip leading spaces.
 
139
        while ( (pos < str.length()) &&
 
140
            (str[pos] == ' ') )
 
141
            pos++;
 
142
 
 
143
        // Get the next token
 
144
        std::string::size_type count = str.substr( pos ).find_first_of( " =" );
 
145
        std::string token = str.substr( pos, count );
 
146
        if (count == str.npos)
 
147
            pos = str.npos;
 
148
        else
 
149
            pos += (count+1);
 
150
 
 
151
        // See if it's a Boolen/toggle
 
152
        if ( token == _validateOption )
 
153
        {
 
154
            osg::notify( osg::INFO ) << "fltexp: Found: " << token << std::endl;
 
155
            setValidateOnly( true );
 
156
            continue;
 
157
        }
 
158
        if ( token == _stripTextureFilePathOption )
 
159
        {
 
160
            osg::notify( osg::INFO ) << "fltexp: Found: " << token << std::endl;
 
161
            setStripTextureFilePath( true );
 
162
            continue;
 
163
        }
 
164
 
 
165
        // Not a Boolean/toggle. Must have a value.
 
166
        // Get the value of the token, which could be double-quoted.
 
167
        if( str[pos] == '"' )
 
168
        {
 
169
            ++pos;
 
170
            count = str.substr( pos ).find_first_of( '"' );
 
171
        }
 
172
        else
 
173
            count = str.substr( pos ).find_first_of( ' ' );
 
174
        std::string value = str.substr( pos, count );
 
175
        if (count == str.npos)
 
176
            pos = str.npos;
 
177
        else
 
178
            pos += (count+1);
 
179
 
 
180
        if (token == _versionOption)
 
181
        {
 
182
            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
 
183
            int version( VERSION_16_1 );
 
184
            if( value == std::string( "15.7" ) )
 
185
                version = VERSION_15_7;
 
186
            else if( value == std::string( "15.8" ) )
 
187
                version = VERSION_15_8;
 
188
            else if( value != std::string( "16.1" ) )
 
189
                osg::notify( osg::WARN ) << "fltexp: Unsupported version: " << value << ". Defaulting to 16.1." << std::endl;
 
190
            setFlightFileVersionNumber( version );
 
191
        }
 
192
        else if (token == _unitsOption)
 
193
        {
 
194
            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
 
195
            FlightUnits units( METERS );
 
196
            if( value == std::string( "KILOMETERS" ) )
 
197
                units = KILOMETERS;
 
198
            else if( value == std::string( "FEET" ) )
 
199
                units = FEET;
 
200
            else if( value == std::string( "INCHES" ) )
 
201
                units = INCHES;
 
202
            else if( value == std::string( "NAUTICAL_MILES" ) )
 
203
                units = NAUTICAL_MILES;
 
204
            else if( value != std::string( "METERS" ) )
 
205
                osg::notify( osg::WARN ) << "fltexp: Unsupported units: " << value << ". Defaulting to METERS." << std::endl;
 
206
            setFlightUnits( units );
 
207
        }
 
208
        else if (token == _tempDirOption)
 
209
        {
 
210
            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
 
211
            setTempDir( value );
 
212
        }
 
213
        else if (token == _lightingOption)
 
214
        {
 
215
            osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
 
216
            bool lighting( true );
 
217
            if (value == std::string( "OFF" ) )
 
218
                lighting = false;
 
219
            else if (value != std::string( "ON" ) )
 
220
                osg::notify( osg::WARN ) << "fltexp: Unsupported lighting value: " << value << ". Defaulting to ON." << std::endl;
 
221
            setLightingDefault( lighting );
 
222
        }
 
223
        else
 
224
            osg::notify( osg::WARN ) << "fltexp: Bogus OptionString: " << token << std::endl;
 
225
    }
 
226
}
 
227
 
 
228
 
 
229
}