]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/SGReaderWriterOptions.hxx
Centralize osgDB::Option handling in SGReaderWriterOptions.
[simgear.git] / simgear / scene / util / SGReaderWriterOptions.hxx
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 <osgDB/Registry>
25 #include <simgear/scene/model/modellib.hxx>
26 #include <simgear/props/props.hxx>
27
28 class SGPropertyNode;
29 class SGMaterialLib;
30
31 namespace simgear
32 {
33
34 class SGReaderWriterOptions : public osgDB::Options {
35 public:
36     SGReaderWriterOptions() :
37         _materialLib(0),
38         _load_panel(0),
39         _model_data(0),
40         _instantiateEffects(false)
41     { }
42     SGReaderWriterOptions(const std::string& str) :
43         osgDB::Options(str),
44         _materialLib(0),
45         _load_panel(0),
46         _model_data(0),
47         _instantiateEffects(false)
48     { }
49     SGReaderWriterOptions(const osgDB::Options& options,
50                           const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) :
51         osgDB::Options(options, copyop),
52         _materialLib(0),
53         _load_panel(0),
54         _model_data(0),
55         _instantiateEffects(false)
56     { }
57     SGReaderWriterOptions(const SGReaderWriterOptions& options,
58                           const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) :
59         osgDB::Options(options, copyop),
60         _propertyNode(options._propertyNode),
61         _materialLib(options._materialLib),
62         _load_panel(options._load_panel),
63         _model_data(options._model_data),
64         _instantiateEffects(options._instantiateEffects)
65     { }
66
67     META_Object(simgear, SGReaderWriterOptions);
68
69     const SGSharedPtr<SGPropertyNode>& getPropertyNode() const
70     { return _propertyNode; }
71     void setPropertyNode(const SGSharedPtr<SGPropertyNode>& propertyNode)
72     { _propertyNode = propertyNode; }
73
74     SGMaterialLib* getMaterialLib() const
75     { return _materialLib; }
76     void setMaterialLib(SGMaterialLib* materialLib)
77     { _materialLib = materialLib; }
78
79     typedef osg::Node *(*panel_func)(SGPropertyNode *);
80
81     panel_func getLoadPanel() const
82     { return _load_panel; }
83     void setLoadPanel(panel_func pf)
84     { _load_panel=pf; }
85
86     SGModelData *getModelData() const
87     { return _model_data.get(); }
88     void setModelData(SGModelData *modelData)
89     { _model_data=modelData; }
90
91     bool getInstantiateEffects() const
92     { return _instantiateEffects; }
93     void setInstantiateEffects(bool instantiateEffects)
94     { _instantiateEffects = instantiateEffects; }
95
96     static SGReaderWriterOptions* copyOrCreate(const osgDB::Options* options)
97     {
98         if (!options)
99             options = osgDB::Registry::instance()->getOptions();
100         if (!options)
101             return new SGReaderWriterOptions;
102         if (!dynamic_cast<const SGReaderWriterOptions*>(options))
103             return new SGReaderWriterOptions(*options);
104         return new SGReaderWriterOptions(*static_cast<const SGReaderWriterOptions*>(options));
105     }
106
107     static SGReaderWriterOptions* fromPath(const std::string& path)
108     {
109         SGReaderWriterOptions* options = copyOrCreate(0);
110         options->setDatabasePath(path);
111         return options;
112     }
113
114 protected:
115     virtual ~SGReaderWriterOptions() {}
116
117 private:
118     SGSharedPtr<SGPropertyNode> _propertyNode;
119     SGMaterialLib* _materialLib;
120     osg::Node *(*_load_panel)(SGPropertyNode *);
121     osg::ref_ptr<SGModelData> _model_data;
122     bool _instantiateEffects;
123 };
124
125 }
126
127 #endif