1 // Copyright (C) 2007 Tim Moore timoore@redhat.com 2 // Copyright (C) 2008 Till Busch buti@bux.at 3 // Copyright (C) 2011 Mathias Froehlich 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License as 7 // published by the Free Software Foundation; either version 2 of the 8 // License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, but 11 // WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 // 19 20 #ifndef SGREADERWRITEROPTIONS_HXX 21 #define SGREADERWRITEROPTIONS_HXX 1 22 23 #include <osgDB/Options> 24 #include <simgear/scene/model/modellib.hxx> 25 #include <simgear/scene/material/matlib.hxx> 26 27 #include <simgear/props/props.hxx> 28 29 #ifdef ENABLE_GDAL 30 #include <simgear/scene/dem/SGDem.hxx> 31 #endif 32 33 class SGPropertyNode; 34 class SGPath; 35 36 typedef std::vector < std::string > string_list; 37 38 namespace simgear 39 { 40 41 class SGReaderWriterOptions : public osgDB::Options { 42 public: 43 enum LoadOriginHint 44 { 45 ORIGIN_MODEL, 46 ORIGIN_EFFECTS, 47 ORIGIN_EFFECTS_NORMALIZED, 48 ORIGIN_SPLASH_SCREEN, 49 ORIGIN_CANVAS, 50 }; 51 52 //SGReaderWriterOptions* cloneOptions(const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) const { return static_cast<SGReaderWriterOptions*>(clone(copyop)); } 53 SGReaderWriterOptions()54 SGReaderWriterOptions() : 55 _materialLib(0), 56 _load_panel(0), 57 _instantiateEffects(false), 58 _instantiateMaterialEffects(false), 59 _LoadOriginHint(ORIGIN_MODEL) 60 { } SGReaderWriterOptions(const std::string & str)61 SGReaderWriterOptions(const std::string& str) : 62 osgDB::Options(str), 63 _materialLib(0), 64 _load_panel(0), 65 _instantiateEffects(false), 66 _instantiateMaterialEffects(false), 67 _LoadOriginHint(ORIGIN_MODEL) 68 { } SGReaderWriterOptions(const osgDB::Options & options,const osg::CopyOp & copyop=osg::CopyOp::SHALLOW_COPY)69 SGReaderWriterOptions(const osgDB::Options& options, 70 const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) : 71 osgDB::Options(options, copyop), 72 _materialLib(0), 73 _load_panel(0), 74 _instantiateEffects(false), 75 _instantiateMaterialEffects(false), 76 _LoadOriginHint(ORIGIN_MODEL) 77 { } SGReaderWriterOptions(const SGReaderWriterOptions & options,const osg::CopyOp & copyop=osg::CopyOp::SHALLOW_COPY)78 SGReaderWriterOptions(const SGReaderWriterOptions& options, 79 const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) : osgDB::Options(options, copyop), 80 _propertyNode(options._propertyNode), 81 _materialLib(options._materialLib), 82 #ifdef ENABLE_GDAL 83 _dem(options._dem), 84 #endif 85 _load_panel(options._load_panel), 86 _model_data(options._model_data), 87 _instantiateEffects(options._instantiateEffects), 88 _instantiateMaterialEffects(options._instantiateMaterialEffects), 89 _materialName(options._materialName), 90 _sceneryPathSuffixes(options._sceneryPathSuffixes), 91 _LoadOriginHint(ORIGIN_MODEL), 92 _errorContext(options._errorContext) 93 { } 94 95 META_Object(simgear, SGReaderWriterOptions); 96 getPropertyNode() const97 const SGSharedPtr<SGPropertyNode>& getPropertyNode() const 98 { return _propertyNode; } setPropertyNode(const SGSharedPtr<SGPropertyNode> & propertyNode)99 void setPropertyNode(const SGSharedPtr<SGPropertyNode>& propertyNode) 100 { _propertyNode = propertyNode; } 101 getMaterialLib() const102 SGMaterialLibPtr getMaterialLib() const 103 { return _materialLib; } setMaterialLib(SGMaterialLib * materialLib)104 void setMaterialLib(SGMaterialLib* materialLib) 105 { _materialLib = materialLib; } 106 107 #ifdef ENABLE_GDAL getDem() const108 SGDemPtr getDem() const 109 { return _dem; } setDem(SGDem * dem)110 void setDem(SGDem* dem) 111 { _dem = dem; } 112 #endif 113 114 typedef osg::Node *(*panel_func)(SGPropertyNode *); 115 getLoadPanel() const116 panel_func getLoadPanel() const 117 { return _load_panel; } setLoadPanel(panel_func pf)118 void setLoadPanel(panel_func pf) 119 { _load_panel=pf; } 120 getModelData() const121 SGModelData *getModelData() const 122 { return _model_data.get(); } setModelData(SGModelData * modelData)123 void setModelData(SGModelData *modelData) 124 { _model_data=modelData; } 125 getInstantiateEffects() const126 bool getInstantiateEffects() const 127 { return _instantiateEffects; } setInstantiateEffects(bool instantiateEffects)128 void setInstantiateEffects(bool instantiateEffects) 129 { _instantiateEffects = instantiateEffects; } 130 getInstantiateMaterialEffects() const131 bool getInstantiateMaterialEffects() const 132 { return _instantiateMaterialEffects; } setInstantiateMaterialEffects(bool instantiateMaterialEffects)133 void setInstantiateMaterialEffects(bool instantiateMaterialEffects) 134 { _instantiateMaterialEffects = instantiateMaterialEffects; } 135 getMaterialName() const136 string getMaterialName() const 137 { return _materialName; } setMaterialName(string materialName)138 void setMaterialName(string materialName) 139 { _materialName = materialName; } 140 getSceneryPathSuffixes() const141 const string_list& getSceneryPathSuffixes() const 142 { return _sceneryPathSuffixes; } 143 setSceneryPathSuffixes(const string_list & suffixes)144 void setSceneryPathSuffixes(const string_list& suffixes) 145 { _sceneryPathSuffixes = suffixes; } 146 147 static SGReaderWriterOptions* copyOrCreate(const osgDB::Options* options); 148 static SGReaderWriterOptions* fromPath(const SGPath& path); 149 setLocation(double lon,double lat)150 void setLocation(double lon, double lat) 151 { _geod = SGGeod::fromDeg(lon, lat); } 152 getLocation() const153 const SGGeod& getLocation() const 154 { return _geod; } 155 156 // the load origin defines where the load request has come from. 157 // example usage; to allow the DDS Texture Cache (DTC) to ignore 158 // any texture that is used in a shader, as these often have special values 159 // encoded into the channels that aren't suitable for conversion. setLoadOriginHint(LoadOriginHint _v) const160 void setLoadOriginHint(LoadOriginHint _v) const { _LoadOriginHint = _v; } getLoadOriginHint() const161 LoadOriginHint getLoadOriginHint() const { return _LoadOriginHint; } 162 163 using ErrorContext = std::map<std::string, std::string>; 164 165 void addErrorContext(const std::string& key, const std::string& value); 166 getErrorContext() const167 ErrorContext getErrorContext() const 168 { 169 return _errorContext; 170 } 171 172 protected: 173 virtual ~SGReaderWriterOptions(); 174 175 private: 176 SGSharedPtr<SGPropertyNode> _propertyNode; 177 SGSharedPtr<SGMaterialLib> _materialLib; 178 #ifdef ENABLE_GDAL 179 SGSharedPtr<SGDem> _dem; 180 #endif 181 182 osg::Node *(*_load_panel)(SGPropertyNode *); 183 osg::ref_ptr<SGModelData> _model_data; 184 185 bool _instantiateEffects; 186 bool _instantiateMaterialEffects; 187 string _materialName; 188 string_list _sceneryPathSuffixes; 189 SGGeod _geod; 190 mutable LoadOriginHint _LoadOriginHint; 191 ErrorContext _errorContext; 192 }; 193 194 } 195 196 #endif 197