1 // Copyright 2008, Google Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 //  1. Redistributions of source code must retain the above copyright notice,
7 //     this list of conditions and the following disclaimer.
8 //  2. Redistributions in binary form must reproduce the above copyright notice,
9 //     this list of conditions and the following disclaimer in the documentation
10 //     and/or other materials provided with the distribution.
11 //  3. Neither the name of Google Inc. nor the names of its contributors may be
12 //     used to endorse or promote products derived from this software without
13 //     specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 // This file declares the Region, LatLonAltBox and Lod elements.
27 // LatLonAltBox and Lod are here because they are used only with Region.
28 
29 #ifndef KML_DOM_REGION_H__
30 #define KML_DOM_REGION_H__
31 
32 #include "kml/dom/abstractlatlonbox.h"
33 #include "kml/dom/kml22.h"
34 #include "kml/dom/kml_ptr.h"
35 #include "kml/dom/object.h"
36 #include "kml/base/util.h"
37 
38 namespace kmldom {
39 
40 class Visitor;
41 class VisitorDriver;
42 
43 // <LatLonAltBox>
44 class LatLonAltBox : public AbstractLatLonBox {
45  public:
46   virtual ~LatLonAltBox();
Type()47   virtual KmlDomType Type() const { return Type_LatLonAltBox; }
IsA(KmlDomType type)48   virtual bool IsA(KmlDomType type) const {
49     return type == Type_LatLonAltBox || AbstractLatLonBox::IsA(type);
50   }
51 
52   // <minAltitude>
get_minaltitude()53   double get_minaltitude() const {
54     return minaltitude_;
55   }
has_minaltitude()56   bool has_minaltitude() const {
57     return has_minaltitude_;
58   }
set_minaltitude(double minaltitude)59   void set_minaltitude(double minaltitude) {
60     minaltitude_ = minaltitude;
61     has_minaltitude_ = true;
62   }
clear_minaltitude()63   void clear_minaltitude() {
64     minaltitude_ = 0.0;
65     has_minaltitude_ = false;
66   }
67 
68   // <maxAltitude>
get_maxaltitude()69   double get_maxaltitude() const {
70     return maxaltitude_;
71   }
has_maxaltitude()72   bool has_maxaltitude() const {
73     return has_maxaltitude_;
74   }
set_maxaltitude(double maxaltitude)75   void set_maxaltitude(double maxaltitude) {
76     maxaltitude_ = maxaltitude;
77     has_maxaltitude_ = true;
78   }
clear_maxaltitude()79   void clear_maxaltitude() {
80     maxaltitude_ = 0.0;
81     has_maxaltitude_ = false;
82   }
83 
84   // <altitudeMode>
get_altitudemode()85   int get_altitudemode() const {
86     return altitudemode_;
87   }
has_altitudemode()88   bool has_altitudemode() const {
89     return has_altitudemode_;
90   }
set_altitudemode(int altitudemode)91   void set_altitudemode(int altitudemode) {
92     altitudemode_ = altitudemode;
93     has_altitudemode_ = true;
94   }
clear_altitudemode()95   void clear_altitudemode() {
96     altitudemode_ = ALTITUDEMODE_CLAMPTOGROUND;
97     has_altitudemode_ = false;
98   }
99 
100   // <gx:altitudeMode>
get_gx_altitudemode()101   int get_gx_altitudemode() const {
102     return gx_altitudemode_;
103   }
has_gx_altitudemode()104   bool has_gx_altitudemode() const {
105     return has_gx_altitudemode_;
106   }
set_gx_altitudemode(int gx_altitudemode)107   void set_gx_altitudemode(int gx_altitudemode) {
108     gx_altitudemode_ = gx_altitudemode;
109     has_gx_altitudemode_ = true;
110   }
clear_gx_altitudemode()111   void clear_gx_altitudemode() {
112     gx_altitudemode_ = GX_ALTITUDEMODE_CLAMPTOSEAFLOOR;
113     has_gx_altitudemode_ = false;
114   }
115 
116   // Visitor API methods, see visitor.h.
117   virtual void Accept(Visitor* visitor);
118 
119  private:
120   friend class KmlFactory;
121   LatLonAltBox();
122   friend class KmlHandler;
123   virtual void AddElement(const ElementPtr& element);
124   friend class Serializer;
125   virtual void Serialize(Serializer& serializer) const;
126   double minaltitude_;
127   bool has_minaltitude_;
128   double maxaltitude_;
129   bool has_maxaltitude_;
130   int altitudemode_;
131   bool has_altitudemode_;
132   int gx_altitudemode_;
133   bool has_gx_altitudemode_;
134   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(LatLonAltBox);
135 };
136 
137 // <Lod>
138 class Lod : public Object {
139  public:
140   virtual ~Lod();
Type()141   virtual KmlDomType Type() const { return Type_Lod; }
IsA(KmlDomType type)142   virtual bool IsA(KmlDomType type) const {
143     return type == Type_Lod || Object::IsA(type);
144   }
145 
146   // <minLodPixels>
get_minlodpixels()147   double get_minlodpixels() const {
148     return minlodpixels_;
149   }
has_minlodpixels()150   bool has_minlodpixels() const {
151     return has_minlodpixels_;
152   }
set_minlodpixels(double minlodpixels)153   void set_minlodpixels(double minlodpixels) {
154     minlodpixels_ = minlodpixels;
155     has_minlodpixels_ = true;
156   }
clear_minlodpixels()157   void clear_minlodpixels() {
158     minlodpixels_ = 0.0;
159     has_minlodpixels_ = false;
160   }
161 
162   // <maxLodPixels>
get_maxlodpixels()163   double get_maxlodpixels() const {
164     return maxlodpixels_;
165   }
has_maxlodpixels()166   bool has_maxlodpixels() const {
167     return has_maxlodpixels_;
168   }
set_maxlodpixels(double minlodpixels)169   void set_maxlodpixels(double minlodpixels) {
170     maxlodpixels_ = minlodpixels;
171     has_maxlodpixels_ = true;
172   }
clear_maxlodpixels()173   void clear_maxlodpixels() {
174     maxlodpixels_ = -1.0;
175     has_maxlodpixels_ = false;
176   }
177 
178   // <minFadeExtent>
get_minfadeextent()179   double get_minfadeextent() const {
180     return minfadeextent_;
181   }
has_minfadeextent()182   bool has_minfadeextent() const {
183     return has_minfadeextent_;
184   }
set_minfadeextent(double minlodpixels)185   void set_minfadeextent(double minlodpixels) {
186     minfadeextent_ = minlodpixels;
187     has_minfadeextent_ = true;
188   }
clear_minfadeextent()189   void clear_minfadeextent() {
190     minfadeextent_ = 0.0;
191     has_minfadeextent_ = false;
192   }
193 
194   // <maxFadeExtent>
get_maxfadeextent()195   double get_maxfadeextent() const {
196     return maxfadeextent_;
197   }
has_maxfadeextent()198   bool has_maxfadeextent() const {
199     return has_maxfadeextent_;
200   }
set_maxfadeextent(double maxlodpixels)201   void set_maxfadeextent(double maxlodpixels) {
202     maxfadeextent_ = maxlodpixels;
203     has_maxfadeextent_ = true;
204   }
clear_maxfadeextent()205   void clear_maxfadeextent() {
206     maxfadeextent_ = 0.0;
207     has_maxfadeextent_ = false;
208   }
209 
210   // Visitor API methods, see visitor.h.
211   virtual void Accept(Visitor* visitor);
212 
213  private:
214   friend class KmlFactory;
215   Lod();
216   friend class KmlHandler;
217   virtual void AddElement(const ElementPtr& element);
218   friend class Serializer;
219   virtual void Serialize(Serializer& serializer) const;
220   double minlodpixels_;
221   bool has_minlodpixels_;
222   double maxlodpixels_;
223   bool has_maxlodpixels_;
224   double minfadeextent_;
225   bool has_minfadeextent_;
226   double maxfadeextent_;
227   bool has_maxfadeextent_;
228   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Lod);
229 };
230 
231 // <Region>
232 class Region : public Object {
233  public:
234   virtual ~Region();
Type()235   virtual KmlDomType Type() const { return Type_Region; }
IsA(KmlDomType type)236   virtual bool IsA(KmlDomType type) const {
237     return type == Type_Region || Object::IsA(type);
238   }
239 
240   // <LatLonAltBox>
get_latlonaltbox()241   const LatLonAltBoxPtr& get_latlonaltbox() const { return latlonaltbox_; }
has_latlonaltbox()242   bool has_latlonaltbox() const { return latlonaltbox_ != NULL; }
set_latlonaltbox(const LatLonAltBoxPtr & latlonaltbox)243   void set_latlonaltbox(const LatLonAltBoxPtr& latlonaltbox) {
244     SetComplexChild(latlonaltbox, &latlonaltbox_);
245   }
clear_latlonaltbox()246   void clear_latlonaltbox() {
247     set_latlonaltbox(NULL);
248   }
249 
250   // <Lod>
get_lod()251   const LodPtr& get_lod() const { return lod_; }
has_lod()252   bool has_lod() const { return lod_ != NULL; }
set_lod(const LodPtr & lod)253   void set_lod(const LodPtr& lod) {
254     SetComplexChild(lod, &lod_);
255   }
clear_lod()256   void clear_lod() {
257     set_lod(NULL);
258   }
259 
260   // Visitor API methods, see visitor.h.
261   virtual void Accept(Visitor* visitor);
262   virtual void AcceptChildren(VisitorDriver* driver);
263 
264  private:
265   friend class KmlFactory;
266   Region();
267   friend class KmlHandler;
268   virtual void AddElement(const ElementPtr& element);
269   friend class Serializer;
270   virtual void Serialize(Serializer& serializer) const;
271   LatLonAltBoxPtr latlonaltbox_;
272   LodPtr lod_;
273   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Region);
274 };
275 
276 }  // end namespace kmldom
277 
278 #endif  // KML_DOM_REGION_H__
279