| [8003] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 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 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | std::string ExportOptions::_versionOption( "version" ); |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | std::string ExportOptions::_unitsOption( "units" ); |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | std::string ExportOptions::_validateOption( "validate" ); |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | std::string ExportOptions::_tempDirOption( "tempDir" ); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | std::string ExportOptions::_lightingOption( "lighting" ); |
|---|
| 75 | |
|---|
| 76 | |
|---|
| [8563] | 77 | |
|---|
| [8003] | 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 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 ), |
|---|
| [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 | |
|---|
| 127 | void |
|---|
| 128 | ExportOptions::parseOptionsString() |
|---|
| 129 | { |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 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 | |
|---|
| 141 | while ( (pos < str.length()) && |
|---|
| 142 | (str[pos] == ' ') ) |
|---|
| 143 | pos++; |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 168 | |
|---|
| 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 | } |
|---|