source: geovis/trunk/Placard.h @ 6274

Last change on this file since 6274 was 6274, checked in by ldelgass, 6 years ago

fix includes

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2015  HUBzero Foundation, LLC
4 *
5 * Author: Leif Delgass <ldelgass@purdue.edu>
6 */
7
8#ifndef GEOVIS_PLACARD_H
9#define GEOVIS_PLACARD_H
10
11#include <string>
12#include <vector>
13#include <algorithm>
14
15#ifdef NEW_ANNOTATION_API
16#include <osgEarth/ScreenSpaceLayout>
17#include <osgEarthAnnotation/GeoPositionNode>
18#else
19#include <osgEarthAnnotation/Decoration>
20#include <osgEarthAnnotation/OrthoNode>
21#endif
22#include <osgEarthAnnotation/LabelNode>
23#include <osgEarthFeatures/Feature>
24
25namespace GeoVis {
26
27class Placard {
28public:
29    Placard();
30    virtual ~Placard()
31    {}
32    void addAllAttributes(const osgEarth::Features::AttributeTable& attrs)
33    {
34        for (osgEarth::Features::AttributeTable::const_iterator itr = attrs.begin();
35             itr != attrs.end(); ++itr) {
36            std::string label = itr->first;
37            std::replace(label.begin(), label.end(), '_', ' ');
38            addEntry(itr->first, label);
39        }
40    }
41    void addEntry(const std::string& name)
42    {
43        addEntry(name, name);
44    }
45    void addEntry(const std::string& name, const std::string& label)
46    {
47        _attrNames.push_back(name);
48        _attrLabels.push_back(label);
49    }
50    void getEntry(int i, std::string& name, std::string& label) const
51    {
52        name = _attrNames[i];
53        label = _attrLabels[i];
54    }
55    size_t getNumEntries() const
56    {
57        return _attrNames.size();
58    }
59    void setStyle(const osgEarth::Symbology::Style& style)
60    {
61        _textStyle = style;
62    }
63    const osgEarth::Symbology::Style& getStyle() const
64    {
65        return _textStyle;
66    }
67    void setPadding(float padding)
68    {
69        _padding = padding;
70    }
71    float getPadding() const
72    {
73        return _padding;
74    }
75    bool enabled()
76    {
77        return _enabled;
78    }
79    void setEnabled(bool state)
80    {
81        _enabled = state;
82    }
83
84private:
85    std::vector<std::string> _attrNames;
86    std::vector<std::string> _attrLabels;
87    float _padding;
88    osgEarth::Symbology::Style _textStyle;
89    bool _enabled;
90};
91
92class PlacardLabelNode : public osgEarth::Annotation::LabelNode {
93public:
94    META_Node(osgEarthAnnotation, PlacardLabelNode);
95#ifndef NEW_ANNOTATION_API
96    virtual bool accept(osgEarth::Annotation::Decoration* ds, bool enable)
97    { return ds->apply(*this, enable); }
98#endif
99    PlacardLabelNode() :
100        osgEarth::Annotation::LabelNode()
101    {}
102    PlacardLabelNode(const PlacardLabelNode& other, const osg::CopyOp& op = osg::CopyOp::DEEP_COPY_ALL) :
103        osgEarth::Annotation::LabelNode(other, op),
104        _placardConf(other._placardConf)
105    {
106    }
107    PlacardLabelNode(osgEarth::MapNode *mapNode,
108                     const osgEarth::GeoPoint& position,
109                     const Placard& placardConf,
110                     const osgEarth::Features::AttributeTable &attrs);
111
112    virtual ~PlacardLabelNode()
113    {}
114
115    void setConfig(const Placard& placardConf);
116
117private:
118    Placard _placardConf;
119    osgEarth::Features::AttributeTable _attrs;
120};
121
122class PlacardNode :
123#ifdef NEW_ANNOTATION_API
124public osgEarth::Annotation::GeoPositionNode
125#else
126public osgEarth::Annotation::OrthoNode
127#endif
128{
129public:
130    META_Node(osgEarthAnnotation, PlacardNode);
131#ifndef NEW_ANNOTATION_API
132    virtual bool accept(osgEarth::Annotation::Decoration* ds, bool enable)
133    { return ds->apply(*this, enable); }
134#endif
135    PlacardNode() :
136#ifdef NEW_ANNOTATION_API
137        osgEarth::Annotation::GeoPositionNode()
138#else
139        osgEarth::Annotation::OrthoNode()
140#endif
141    {}
142    PlacardNode(const PlacardNode& other, const osg::CopyOp& op = osg::CopyOp::DEEP_COPY_ALL) :
143#ifdef NEW_ANNOTATION_API
144        osgEarth::Annotation::GeoPositionNode(other, op),
145#else
146        osgEarth::Annotation::OrthoNode(other, op),
147#endif
148        _placardConf(other._placardConf)
149    {
150    }
151    PlacardNode(osgEarth::MapNode *mapNode,
152                const osgEarth::GeoPoint& position,
153                const Placard& placardConf,
154                const osgEarth::Features::AttributeTable &attrs);
155
156    virtual ~PlacardNode()
157    {}
158
159    void setConfig(const Placard& placardConf);
160
161    /**
162     * Sets the text content.
163     */
164    void setText( const std::string& text );
165    const std::string& text() const { return _text; }
166    virtual const std::string& getText() const { return text(); }
167
168    /**
169     * Gets a copy of the text style.
170     */
171    const osgEarth::Symbology::Style& getStyle() const { return _style; }
172
173    /**
174     * Sets a new text style
175     */
176    void setStyle( const osgEarth::Symbology::Style& style );
177
178public: // Ortho|GeoPositionNode override
179#ifdef NEW_ANNOTATION_API
180    virtual void setPriority(float value);
181#else
182    virtual void setAnnotationData( osgEarth::Annotation::AnnotationData* data );
183#endif
184    virtual void setDynamic( bool value );
185
186    virtual osgEarth::Config getConfig() const;
187
188protected:
189    void init(const osgEarth::Symbology::Style& style);
190#ifdef NEW_ANNOTATION_API
191    void updateLayoutData();
192#endif
193
194    std::string                _text;
195    osgEarth::Symbology::Style _style;
196    osg::ref_ptr<osg::Geode>   _geode;
197    osg::ref_ptr<osg::Geode>   _backdropGeode;
198#ifdef NEW_ANNOTATION_API
199    osg::ref_ptr<osgEarth::ScreenSpaceLayoutData> _dataLayout;
200#endif
201
202    Placard _placardConf;
203    osgEarth::Features::AttributeTable _attrs;
204};
205
206}
207
208#endif
Note: See TracBrowser for help on using the repository browser.