]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/elements/CanvasMap.hxx
Fix #1783: repeated error message on console
[simgear.git] / simgear / canvas / elements / CanvasMap.hxx
1 // A group of 2D Canvas elements which get automatically transformed according
2 // to the map parameters.
3 //
4 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library 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 GNU
14 // Library General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
19
20 #ifndef CANVAS_MAP_HXX_
21 #define CANVAS_MAP_HXX_
22
23 #include "CanvasGroup.hxx"
24
25 #include <boost/shared_ptr.hpp>
26 #include <boost/unordered_map.hpp>
27 #include <boost/unordered_set.hpp>
28
29 namespace simgear
30 {
31 namespace canvas
32 {
33   class GeoNodePair;
34   class HorizontalProjection;
35   class Map:
36     public Group
37   {
38     public:
39       static const std::string TYPE_NAME;
40       static void staticInit();
41
42       Map( const CanvasWeakPtr& canvas,
43            const SGPropertyNode_ptr& node,
44            const Style& parent_style,
45            Element* parent = 0 );
46       virtual ~Map();
47
48       virtual void update(double dt);
49
50       virtual void childAdded( SGPropertyNode * parent,
51                                SGPropertyNode * child );
52       virtual void childRemoved( SGPropertyNode * parent,
53                                  SGPropertyNode * child );
54       virtual void valueChanged(SGPropertyNode * child);
55
56     protected:
57
58       virtual void childChanged(SGPropertyNode * child);
59
60       typedef boost::unordered_map< SGPropertyNode*,
61                                     boost::shared_ptr<GeoNodePair>
62                                   > GeoNodes;
63       typedef boost::unordered_set<SGPropertyNode*> NodeSet;
64
65       GeoNodes _geo_nodes;
66       NodeSet  _hdg_nodes;
67       boost::shared_ptr<HorizontalProjection> _projection;
68       bool _projection_dirty;
69
70       struct GeoCoord
71       {
72         GeoCoord():
73           type(INVALID),
74           value(0)
75         {}
76         enum
77         {
78           INVALID,
79           LATITUDE,
80           LONGITUDE
81         } type;
82         double value;
83       };
84
85       void geoNodeChanged(SGPropertyNode * child);
86       void hdgNodeChanged(SGPropertyNode * child);
87
88       GeoCoord parseGeoCoord(const std::string& val) const;
89   };
90
91 } // namespace canvas
92 } // namespace simgear
93
94 #endif /* CANVAS_MAP_HXX_ */