~ubuntu-branches/debian/sid/osgearth/sid

« back to all changes in this revision

Viewing changes to src/osgEarth/ModelLayer

  • Committer: Bazaar Package Importer
  • Author(s): Pirmin Kalberer
  • Date: 2011-07-14 22:13:36 UTC
  • Revision ID: james.westby@ubuntu.com-20110714221336-94igk9rskxveh794
Tags: upstream-2.0+dfsg
ImportĀ upstreamĀ versionĀ 2.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-c++-*- */
 
2
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 
3
 * Copyright 2008-2010 Pelican Mapping
 
4
 * http://osgearth.org
 
5
 *
 
6
 * osgEarth is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 
18
 */
 
19
 
 
20
#ifndef OSGEARTH_MODEL_LAYER_H
 
21
#define OSGEARTH_MODEL_LAYER_H 1
 
22
 
 
23
#include <osgEarth/Common>
 
24
#include <osgEarth/Layer>
 
25
#include <osgEarth/Config>
 
26
#include <osgEarth/ModelSource>
 
27
#include <osg/Node>
 
28
#include <vector>
 
29
 
 
30
namespace osgEarth
 
31
{
 
32
    class Map;
 
33
 
 
34
    /**
 
35
     * Configuration options for a ModelLayer.
 
36
     */
 
37
    class OSGEARTH_EXPORT ModelLayerOptions : public ConfigOptions
 
38
    {
 
39
    public:        
 
40
        ModelLayerOptions( const ConfigOptions& options =ConfigOptions() );
 
41
 
 
42
        ModelLayerOptions( const std::string& name, const ModelSourceOptions& driverOptions =ModelSourceOptions() );
 
43
 
 
44
        /**
 
45
         * The readable name of the layer.
 
46
         */
 
47
        optional<std::string>& name() { return _name; }
 
48
        const optional<std::string>& name() const { return _name; }
 
49
 
 
50
        /**
 
51
         * Options for the underlying model source driver.
 
52
         */
 
53
        optional<ModelSourceOptions>& driver() { return _driver; }
 
54
        const optional<ModelSourceOptions>& driver() const { return _driver; }
 
55
 
 
56
        /**
 
57
         * Whether to enable OpenGL lighting on the model node.
 
58
         */
 
59
        optional<bool>& lightingEnabled() { return _lighting; }
 
60
        const optional<bool>& lightingEnabled() const { return _lighting; }
 
61
 
 
62
        /**
 
63
         * Whether this layer will be drawn.
 
64
         */
 
65
        optional<bool>& enabled() { return _enabled; }
 
66
        const optional<bool>& enabled() const { return _enabled; }
 
67
 
 
68
        /**
 
69
         * Whether to drape the model geometry over the terrain as a projected overlay.
 
70
         * Defaults to false
 
71
         */
 
72
        optional<bool>& overlay() { return _overlay; }
 
73
        const optional<bool>& overlay() const { return _overlay; }
 
74
 
 
75
    public:
 
76
        virtual Config getConfig() const;
 
77
        virtual void mergeConfig( const Config& conf );
 
78
 
 
79
    private:
 
80
        void fromConfig( const Config& conf );
 
81
        void setDefaults();
 
82
 
 
83
        optional<std::string> _name;
 
84
        optional<bool> _overlay;
 
85
        optional<ModelSourceOptions> _driver;
 
86
        optional<bool> _enabled;
 
87
        optional<bool> _lighting;
 
88
    };
 
89
 
 
90
    /**
 
91
    * Callback for receiving notification of property changes on a ModelLayer.
 
92
    */
 
93
    struct ModelLayerCallback : public osg::Referenced
 
94
    {
 
95
        virtual void onOverlayChanged( class ModelLayer* layer ) { }
 
96
    };
 
97
 
 
98
    typedef void (ModelLayerCallback::*ModelLayerCallbackMethodPtr)(ModelLayer* layer);
 
99
 
 
100
    typedef std::list< osg::ref_ptr<ModelLayerCallback> > ModelLayerCallbackList;
 
101
 
 
102
 
 
103
    class OSGEARTH_EXPORT ModelLayer : public Layer
 
104
    {
 
105
    public:
 
106
        /**
 
107
         * Constructs a new model layer.
 
108
         */
 
109
        ModelLayer( const ModelLayerOptions& options );
 
110
 
 
111
        /**
 
112
         * Constructs a new model layer with a user-provided driver options.
 
113
         */
 
114
        ModelLayer( const std::string& name, const ModelSourceOptions& options );
 
115
        
 
116
        /**
 
117
         * Constructs a new model layer with a user-provided model source.
 
118
         */
 
119
        ModelLayer(const ModelLayerOptions& options, ModelSource* source );
 
120
 
 
121
        /**
 
122
         * Constructs a new model layer with a user provided name and an existing node
 
123
         */
 
124
        ModelLayer(const std::string& name, osg::Node* node);
 
125
 
 
126
    public:
 
127
        /** 
 
128
         * Gets the name of this model layer
 
129
         */
 
130
        const std::string& getName() const { return _options.name().value(); }
 
131
 
 
132
        /**
 
133
         * Gets the initialization options for this layer.
 
134
         */
 
135
        const ModelLayerOptions& getModelLayerOptions() const { return _options; }
 
136
 
 
137
        /**
 
138
         * Gets the reference URI (for resolving relative paths)
 
139
         */
 
140
        const std::string& getReferenceURI() const { return _referenceURI; }
 
141
 
 
142
        /**
 
143
         * Access the underlying model source.
 
144
         */
 
145
        ModelSource* getModelSource() const { return _modelSource.get(); }
 
146
 
 
147
    public:
 
148
 
 
149
        osg::Node* getOrCreateNode( ProgressCallback* progress =0L );
 
150
 
 
151
    public: // properties
 
152
 
 
153
        /** Whether this layer is rendered. */
 
154
        bool getEnabled() const;
 
155
        void setEnabled(bool enabled);
 
156
 
 
157
        /** Whether this layer is drawn as normal geometry or as a draped overlay. */
 
158
        bool getOverlay() const;
 
159
        void setOverlay( bool overlay );
 
160
 
 
161
        // whether to apply lighting to the model layer's root node
 
162
        void setLightingEnabled( bool value );
 
163
        const optional<bool>& lightingEnabled() const { return _enabled; }
 
164
 
 
165
    public:
 
166
 
 
167
        /** Adds a property notification callback to this layer */
 
168
        void addCallback( ModelLayerCallback* cb );
 
169
 
 
170
        /** Removes a property notification callback from this layer */
 
171
        void removeCallback( ModelLayerCallback* cb );
 
172
 
 
173
    public:
 
174
 
 
175
        // internal function
 
176
        void initialize( const std::string& referenceURI, const Map* map );
 
177
 
 
178
    private:
 
179
        std::string _referenceURI;
 
180
        osg::ref_ptr<ModelSource> _modelSource;
 
181
        const ModelLayerOptions _options;
 
182
 
 
183
        osg::ref_ptr< osg::Node > _node;
 
184
 
 
185
        optional<bool> _enabled;
 
186
        optional<bool> _lighting;
 
187
        optional<bool>  _overlay;
 
188
 
 
189
        Revision _modelSourceRev;
 
190
 
 
191
        ModelLayerCallbackList _callbacks;
 
192
        virtual void fireCallback( ModelLayerCallbackMethodPtr method );
 
193
 
 
194
    };
 
195
 
 
196
    typedef std::vector< osg::ref_ptr<ModelLayer> > ModelLayerVector;
 
197
}
 
198
 
 
199
#endif // OSGEARTH_MODEL_LAYER_H