source: geovis/trunk/Placard.h @ 5972

Last change on this file since 5972 was 5969, checked in by ldelgass, 8 years ago

Add style settings for placard

  • Property svn:eol-style set to native
File size: 4.7 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 <osgEarthAnnotation/Decoration>
16#include <osgEarthAnnotation/OrthoNode>
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    void setBackdropColor(const osg::Vec4& color)
71    {
72        _backdropColor = color;
73    }
74    const osg::Vec4& getBackdropColor() const
75    {
76        return _backdropColor;
77    }
78private:
79    std::vector<std::string> _attrNames;
80    std::vector<std::string> _attrLabels;
81    float _padding;
82    osg::Vec4 _backdropColor;
83    osgEarth::Symbology::Style _textStyle;
84};
85
86class PlacardLabelNode : public osgEarth::Annotation::LabelNode {
87public:
88    META_Node(osgEarthAnnotation, PlacardLabelNode);
89    virtual bool accept(osgEarth::Annotation::Decoration* ds, bool enable)
90    { return ds->apply(*this, enable); }
91
92    PlacardLabelNode() :
93        osgEarth::Annotation::LabelNode()
94    {}
95    PlacardLabelNode(const PlacardLabelNode& other, const osg::CopyOp& op = osg::CopyOp::DEEP_COPY_ALL) :
96        osgEarth::Annotation::LabelNode(other, op),
97        _placardConf(other._placardConf)
98    {
99    }
100    PlacardLabelNode(osgEarth::MapNode *mapNode,
101                     const osgEarth::GeoPoint& position,
102                     const Placard& placardConf,
103                     const osgEarth::Features::AttributeTable &attrs);
104
105    virtual ~PlacardLabelNode()
106    {}
107
108    void setConfig(const Placard& placardConf);
109
110private:
111    Placard _placardConf;
112    osgEarth::Features::AttributeTable _attrs;
113};
114
115class PlacardNode : public osgEarth::Annotation::OrthoNode {
116public:
117    META_Node(osgEarthAnnotation, PlacardNode);
118    virtual bool accept(osgEarth::Annotation::Decoration* ds, bool enable)
119    { return ds->apply(*this, enable); }
120
121    PlacardNode() :
122        osgEarth::Annotation::OrthoNode()
123    {}
124    PlacardNode(const PlacardNode& other, const osg::CopyOp& op = osg::CopyOp::DEEP_COPY_ALL) :
125        osgEarth::Annotation::OrthoNode(other, op),
126        _placardConf(other._placardConf)
127    {
128    }
129    PlacardNode(osgEarth::MapNode *mapNode,
130                const osgEarth::GeoPoint& position,
131                const Placard& placardConf,
132                const osgEarth::Features::AttributeTable &attrs);
133
134    virtual ~PlacardNode()
135    {}
136
137    void setConfig(const Placard& placardConf);
138
139    /**
140     * Sets the text content.
141     */
142    void setText( const std::string& text );
143    const std::string& text() const { return _text; }
144    virtual const std::string& getText() const { return text(); }
145
146    /**
147     * Gets a copy of the text style.
148     */
149    const osgEarth::Symbology::Style& getStyle() const { return _style; }
150
151    /**
152     * Sets a new text style
153     */
154    void setStyle( const osgEarth::Symbology::Style& style );
155
156public: // OrthoNode override
157
158    virtual void setAnnotationData( osgEarth::Annotation::AnnotationData* data );
159
160    virtual void setDynamic( bool value );
161
162    virtual osgEarth::Config getConfig() const;
163
164protected:
165    void init(const osgEarth::Symbology::Style& style);
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::Vec4 _backdropColor;
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.