1/* -*-c++-*- */
2/* osgEarth - Geospatial SDK for OpenSceneGraph
3* Copyright 2019 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* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
16* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
17* IN THE SOFTWARE.
18*
19* You should have received a copy of the GNU Lesser General Public License
20* along with this program.  If not, see <http://www.gnu.org/licenses/>
21*/
22
23#ifndef OSGEARTHUTIL_WMS_H
24#define OSGEARTHUTIL_WMS_H 1
25
26#include <osgEarthUtil/Common>
27#include <osg/Referenced>
28#include <osg/ref_ptr>
29#include <osgEarth/Common>
30#include <osgEarth/URI>
31
32#include <osgDB/ReaderWriter>
33#include <osg/Version>
34#include <osgDB/Options>
35
36
37#include <string>
38#include <vector>
39
40namespace osgEarth { namespace Util
41{
42    /**
43    * A WMS Style
44    */
45    class OSGEARTHUTIL_EXPORT WMSStyle : public osg::Referenced
46    {
47    public:
48        WMSStyle();
49        WMSStyle(const std::string& name, const std::string& title);
50
51        /** dtor */
52        virtual ~WMSStyle() { }
53
54        /**
55        *Gets the name of the style
56        */
57	    const std::string& getName() const {return _name;}
58
59        /**
60        *Sets the name of the style
61        */
62        void setName(const std::string &name) {_name = name;}
63
64        /**
65        *Gets the title of the style
66        */
67	    const std::string& getTitle() const {return _title;}
68
69        /**
70        *Sets the title of the style
71        */
72        void setTitle(const std::string &title) {_title = title;}
73
74    protected:
75        std::string _name;
76        std::string _title;
77    };
78
79    /**
80    *A WMS layer
81    */
82    class OSGEARTHUTIL_EXPORT WMSLayer : public osg::Referenced
83    {
84    public:
85        WMSLayer();
86
87        /** dtor */
88        virtual ~WMSLayer() { }
89
90        /**
91        *Gets the name of the layer
92        */
93        const std::string& getName() {return _name;}
94
95        /**
96        *Sets the name of the layer
97        */
98        void setName(const std::string &name) {_name = name;}
99
100        /**
101        *Gets the title of the layer
102        */
103        const std::string& getTitle() {return _title;}
104
105        /**
106        *Sets the title of the layer
107        */
108        void setTitle(const std::string &title) {_title = title;}
109
110        /**
111        *Gets the abstract of the layer
112        */
113        const std::string& getAbstract() {return _abstract;}
114
115        /**
116        *Sets the abstract of the layer
117        */
118        void setAbstract(const std::string &abstract) {_abstract = abstract;}
119
120        /**
121        *Gets the lat lon extents of the layer
122        */
123        void getLatLonExtents(double &minLon, double &minLat, double &maxLon, double &maxLat);
124
125        /**
126        *Sets the lat lon extents of the layer
127        */
128        void setLatLonExtents(double minLon, double minLat, double maxLon, double maxLat);
129
130        /**
131        *Gets the extents of the layer
132        */
133        void getExtents(double &minX, double &minY, double &maxX, double &maxY);
134
135        /**
136        *Sets the extents of the layer
137        */
138        void setExtents(double minX, double minY, double maxX, double maxY);
139
140
141        /**A list of Styles*/
142        typedef std::vector<WMSStyle> StyleList;
143
144        /**
145        *Gets this Layer's list of defined Styles
146        */
147        StyleList& getStyles() {return _styles;}
148
149        /**A list of spatial references*/
150        typedef std::vector<std::string> SRSList;
151
152        /**
153        *Gets this Layer's list of spatial references
154        */
155        SRSList& getSpatialReferences() {return _spatialReferences;}
156
157        /**A list of Layers*/
158        typedef std::vector< osg::ref_ptr<WMSLayer> > LayerList;
159
160        /**
161        *Gets this Layer's list of child Layers
162        */
163        LayerList& getLayers() {return _layers;}
164
165        /**
166        *Gets this Layer's parent layer
167        */
168        WMSLayer* getParentLayer() {return _parentLayer;}
169
170        /**
171        *Sets this Layer's parent layer
172        */
173        void setParentLayer( WMSLayer* layer ) {_parentLayer = layer;}
174
175        /**
176        *Finds the child Layer with the given name.
177        *@returns
178        *       The Layer with the given name or NULL if not found.
179        */
180        WMSLayer* getLayerByName(const std::string &name);
181    protected:
182        std::string _name;
183        std::string _title;
184        std::string _abstract;
185        double _minLon, _minLat, _maxLon, _maxLat;
186        double _minX, _minY, _maxX, _maxY;
187        StyleList _styles;
188        SRSList _spatialReferences;
189
190        LayerList _layers;
191        WMSLayer* _parentLayer;
192    };
193
194    /**
195    *WMS Capabilities
196    */
197    class OSGEARTHUTIL_EXPORT WMSCapabilities : public osg::Referenced
198    {
199    public:
200        WMSCapabilities();
201
202        /** dtor */
203        virtual ~WMSCapabilities() { }
204
205        /**
206        *Gets the WMS capabilities version
207        */
208        const std::string& getVersion() {return _version;}
209
210        /**
211        *Sets the WMS capabilities version
212        */
213        void setVersion(const std::string& version) {_version = version;}
214
215        /**A list of supported formats*/
216        typedef std::vector<std::string> FormatList;
217
218        /**
219        *Gets the list of supported formats
220        */
221        FormatList& getFormats() {return _formats;}
222
223        /**
224        *Gets the Layer's for the Capabilities.
225        */
226        WMSLayer::LayerList& getLayers() {return _layers;}
227
228        /**
229        *Suggests an extension to use for WMS layers defined for the service.
230        *This function will analyze the list of formats contained in the Capabilities request
231        *and recommend the first format that has an OpenSceneGraph ReaderWriter that can support
232        *it's extension.
233        *@returns
234        *       The suggested extension.
235        */
236        std::string suggestExtension();
237
238        /**
239        *Finds the child Layer with the given name.
240        *@returns
241        *       The Layer with the given name or NULL if not found.
242        */
243        WMSLayer* getLayerByName(const std::string &name);
244
245    protected:
246        FormatList _formats;
247        WMSLayer::LayerList _layers;
248        std::string _version;
249    };
250
251    /*
252    * Reads Capabilities from a URL or file
253    */
254    class OSGEARTHUTIL_EXPORT WMSCapabilitiesReader
255    {
256    public:
257        static WMSCapabilities* read( const URI& location, const osgDB::Options *options );
258        static WMSCapabilities* read( std::istream &in );
259    private:
260        WMSCapabilitiesReader(){}
261        WMSCapabilitiesReader(const WMSCapabilitiesReader &cr){}
262
263        /** dtor */
264        virtual ~WMSCapabilitiesReader() { }
265    };
266
267} } // namespace osgEarth::Util
268
269#endif //OSGEARTHUTIL_WMS_H
270