source: geovis/branches/rex/Placard.h @ 6570

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

First pass at porting to new Map layer API

  • Property svn:eol-style set to native
File size: 4.4 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#include <osgEarth/ScreenSpaceLayout>
16#include <osgEarthAnnotation/GeoPositionNode>
17#include <osgEarthAnnotation/LabelNode>
18#include <osgEarthFeatures/Feature>
19
20namespace GeoVis {
21
22class Placard {
23public:
24    Placard();
25    virtual ~Placard()
26    {}
27    void addAllAttributes(const osgEarth::Features::AttributeTable& attrs)
28    {
29        for (osgEarth::Features::AttributeTable::const_iterator itr = attrs.begin();
30             itr != attrs.end(); ++itr) {
31            std::string label = itr->first;
32            std::replace(label.begin(), label.end(), '_', ' ');
33            addEntry(itr->first, label);
34        }
35    }
36    void addEntry(const std::string& name)
37    {
38        addEntry(name, name);
39    }
40    void addEntry(const std::string& name, const std::string& label)
41    {
42        _attrNames.push_back(name);
43        _attrLabels.push_back(label);
44    }
45    void getEntry(int i, std::string& name, std::string& label) const
46    {
47        name = _attrNames[i];
48        label = _attrLabels[i];
49    }
50    size_t getNumEntries() const
51    {
52        return _attrNames.size();
53    }
54    void setStyle(const osgEarth::Symbology::Style& style)
55    {
56        _textStyle = style;
57    }
58    const osgEarth::Symbology::Style& getStyle() const
59    {
60        return _textStyle;
61    }
62    void setPadding(float padding)
63    {
64        _padding = padding;
65    }
66    float getPadding() const
67    {
68        return _padding;
69    }
70    bool enabled()
71    {
72        return _enabled;
73    }
74    void setEnabled(bool state)
75    {
76        _enabled = state;
77    }
78
79private:
80    std::vector<std::string> _attrNames;
81    std::vector<std::string> _attrLabels;
82    float _padding;
83    osgEarth::Symbology::Style _textStyle;
84    bool _enabled;
85};
86
87class PlacardLabelNode : public osgEarth::Annotation::LabelNode {
88public:
89    META_Node(osgEarthAnnotation, PlacardLabelNode);
90
91    PlacardLabelNode() :
92        osgEarth::Annotation::LabelNode()
93    {}
94    PlacardLabelNode(const PlacardLabelNode& other, const osg::CopyOp& op = osg::CopyOp::DEEP_COPY_ALL) :
95        osgEarth::Annotation::LabelNode(other, op),
96        _placardConf(other._placardConf)
97    {
98    }
99    PlacardLabelNode(osgEarth::MapNode *mapNode,
100                     const osgEarth::GeoPoint& position,
101                     const Placard& placardConf,
102                     const osgEarth::Features::AttributeTable &attrs);
103
104    virtual ~PlacardLabelNode()
105    {}
106
107    void setConfig(const Placard& placardConf);
108
109private:
110    Placard _placardConf;
111    osgEarth::Features::AttributeTable _attrs;
112};
113
114class PlacardNode :
115public osgEarth::Annotation::GeoPositionNode
116{
117public:
118    META_Node(osgEarthAnnotation, PlacardNode);
119
120    PlacardNode() :
121        osgEarth::Annotation::GeoPositionNode()
122    {}
123    PlacardNode(const PlacardNode& other, const osg::CopyOp& op = osg::CopyOp::DEEP_COPY_ALL) :
124        osgEarth::Annotation::GeoPositionNode(other, op),
125        _placardConf(other._placardConf)
126    {
127    }
128    PlacardNode(osgEarth::MapNode *mapNode,
129                const osgEarth::GeoPoint& position,
130                const Placard& placardConf,
131                const osgEarth::Features::AttributeTable &attrs);
132
133    virtual ~PlacardNode()
134    {}
135
136    void setConfig(const Placard& placardConf);
137
138    /**
139     * Sets the text content.
140     */
141    void setText( const std::string& text );
142    const std::string& text() const { return _text; }
143    virtual const std::string& getText() const { return text(); }
144
145    /**
146     * Gets a copy of the text style.
147     */
148    const osgEarth::Symbology::Style& getStyle() const { return _style; }
149
150    /**
151     * Sets a new text style
152     */
153    void setStyle( const osgEarth::Symbology::Style& style );
154
155public: // Ortho|GeoPositionNode override
156    virtual void setPriority(float value);
157
158    virtual void setDynamic( bool value );
159
160    virtual osgEarth::Config getConfig() const;
161
162protected:
163    void init(const osgEarth::Symbology::Style& style);
164
165    void updateLayoutData();
166
167    std::string                _text;
168    osgEarth::Symbology::Style _style;
169    osg::ref_ptr<osg::Geode>   _geode;
170    osg::ref_ptr<osg::Geode>   _backdropGeode;
171    osg::ref_ptr<osgEarth::ScreenSpaceLayoutData> _dataLayout;
172
173    Placard _placardConf;
174    osgEarth::Features::AttributeTable _attrs;
175};
176
177}
178
179#endif
Note: See TracBrowser for help on using the repository browser.