]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/elements/map/geo_node_pair.hxx
Fix a Clang warning in Shiva.
[flightgear.git] / src / Canvas / elements / map / geo_node_pair.hxx
1 /*
2  * geo_node_pair.hxx
3  *
4  *  Created on: 11.07.2012
5  *      Author: tom
6  */
7
8 #ifndef CANVAS_GEO_NODE_PAIR_HXX_
9 #define CANVAS_GEO_NODE_PAIR_HXX_
10
11 namespace canvas
12 {
13   class GeoNodePair
14   {
15     public:
16       enum StatusFlags
17       {
18         LAT_MISSING = 1,
19         LON_MISSING = LAT_MISSING << 1,
20         INCOMPLETE = LAT_MISSING | LON_MISSING,
21         DIRTY = LON_MISSING << 1
22       };
23
24       GeoNodePair():
25         _status(INCOMPLETE),
26         _node_lat(0),
27         _node_lon(0)
28       {}
29
30       uint8_t getStatus() const
31       {
32         return _status;
33       }
34
35       void setDirty(bool flag = true)
36       {
37         if( flag )
38           _status |= DIRTY;
39         else
40           _status &= ~DIRTY;
41       }
42
43       bool isDirty() const
44       {
45         return _status & DIRTY;
46       }
47
48       bool isComplete() const
49       {
50         return !(_status & INCOMPLETE);
51       }
52
53       void setNodeLat(SGPropertyNode* node)
54       {
55         _node_lat = node;
56         _status &= ~LAT_MISSING;
57
58         if( node == _node_lon )
59         {
60           _node_lon = 0;
61           _status |= LON_MISSING;
62         }
63       }
64
65       void setNodeLon(SGPropertyNode* node)
66       {
67         _node_lon = node;
68         _status &= ~LON_MISSING;
69
70         if( node == _node_lat )
71         {
72           _node_lat = 0;
73           _status |= LAT_MISSING;
74         }
75       }
76
77       const char* getLat() const
78       {
79         return _node_lat ? _node_lat->getStringValue() : "";
80       }
81
82       const char* getLon() const
83       {
84         return _node_lon ? _node_lon->getStringValue() : "";
85       }
86
87       void setTargetName(const std::string& name)
88       {
89         _target_name = name;
90       }
91
92       void setScreenPos(float x, float y)
93       {
94         assert( isComplete() );
95         SGPropertyNode *parent = _node_lat->getParent();
96         parent->getChild(_target_name, _node_lat->getIndex(), true)
97               ->setDoubleValue(x);
98         parent->getChild(_target_name, _node_lon->getIndex(), true)
99               ->setDoubleValue(y);
100       }
101
102       void print()
103       {
104         std::cout << "lat=" << (_node_lat ? _node_lat->getPath() : "")
105                   << ", lon=" << (_node_lon ? _node_lon->getPath() : "")
106                   << std::endl;
107       }
108
109     private:
110
111       uint8_t _status;
112       SGPropertyNode *_node_lat,
113                      *_node_lon;
114       std::string   _target_name;
115
116   };
117
118 } // namespace canvas
119
120 #endif /* CANVAS_GEO_NODE_PAIR_HXX_ */