[5944] | 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 | |
---|
[6274] | 15 | #include <osgEarth/ScreenSpaceLayout> |
---|
[6245] | 16 | #include <osgEarthAnnotation/GeoPositionNode> |
---|
[5944] | 17 | #include <osgEarthAnnotation/LabelNode> |
---|
| 18 | #include <osgEarthFeatures/Feature> |
---|
| 19 | |
---|
| 20 | namespace GeoVis { |
---|
| 21 | |
---|
| 22 | class Placard { |
---|
| 23 | public: |
---|
[5969] | 24 | Placard(); |
---|
[5944] | 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 | } |
---|
[5969] | 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 | } |
---|
[6254] | 70 | bool enabled() |
---|
| 71 | { |
---|
| 72 | return _enabled; |
---|
| 73 | } |
---|
| 74 | void setEnabled(bool state) |
---|
| 75 | { |
---|
| 76 | _enabled = state; |
---|
| 77 | } |
---|
[5974] | 78 | |
---|
[5944] | 79 | private: |
---|
| 80 | std::vector<std::string> _attrNames; |
---|
| 81 | std::vector<std::string> _attrLabels; |
---|
[5969] | 82 | float _padding; |
---|
| 83 | osgEarth::Symbology::Style _textStyle; |
---|
[6254] | 84 | bool _enabled; |
---|
[5944] | 85 | }; |
---|
| 86 | |
---|
[5961] | 87 | class PlacardLabelNode : public osgEarth::Annotation::LabelNode { |
---|
[5944] | 88 | public: |
---|
[5961] | 89 | META_Node(osgEarthAnnotation, PlacardLabelNode); |
---|
[6570] | 90 | |
---|
[5961] | 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, |
---|
[5969] | 102 | const osgEarth::Features::AttributeTable &attrs); |
---|
[5961] | 103 | |
---|
| 104 | virtual ~PlacardLabelNode() |
---|
| 105 | {} |
---|
| 106 | |
---|
| 107 | void setConfig(const Placard& placardConf); |
---|
| 108 | |
---|
| 109 | private: |
---|
| 110 | Placard _placardConf; |
---|
| 111 | osgEarth::Features::AttributeTable _attrs; |
---|
| 112 | }; |
---|
| 113 | |
---|
[6245] | 114 | class PlacardNode : |
---|
| 115 | public osgEarth::Annotation::GeoPositionNode |
---|
| 116 | { |
---|
[5961] | 117 | public: |
---|
[5944] | 118 | META_Node(osgEarthAnnotation, PlacardNode); |
---|
[6570] | 119 | |
---|
[5944] | 120 | PlacardNode() : |
---|
[6245] | 121 | osgEarth::Annotation::GeoPositionNode() |
---|
[5944] | 122 | {} |
---|
| 123 | PlacardNode(const PlacardNode& other, const osg::CopyOp& op = osg::CopyOp::DEEP_COPY_ALL) : |
---|
[6245] | 124 | osgEarth::Annotation::GeoPositionNode(other, op), |
---|
[5944] | 125 | _placardConf(other._placardConf) |
---|
| 126 | { |
---|
| 127 | } |
---|
| 128 | PlacardNode(osgEarth::MapNode *mapNode, |
---|
| 129 | const osgEarth::GeoPoint& position, |
---|
| 130 | const Placard& placardConf, |
---|
[5969] | 131 | const osgEarth::Features::AttributeTable &attrs); |
---|
[5944] | 132 | |
---|
| 133 | virtual ~PlacardNode() |
---|
| 134 | {} |
---|
| 135 | |
---|
| 136 | void setConfig(const Placard& placardConf); |
---|
| 137 | |
---|
[5961] | 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 | |
---|
[6245] | 155 | public: // Ortho|GeoPositionNode override |
---|
| 156 | virtual void setPriority(float value); |
---|
[6570] | 157 | |
---|
[5961] | 158 | virtual void setDynamic( bool value ); |
---|
| 159 | |
---|
| 160 | virtual osgEarth::Config getConfig() const; |
---|
| 161 | |
---|
| 162 | protected: |
---|
| 163 | void init(const osgEarth::Symbology::Style& style); |
---|
[6570] | 164 | |
---|
[6245] | 165 | void updateLayoutData(); |
---|
[5961] | 166 | |
---|
| 167 | std::string _text; |
---|
| 168 | osgEarth::Symbology::Style _style; |
---|
| 169 | osg::ref_ptr<osg::Geode> _geode; |
---|
| 170 | osg::ref_ptr<osg::Geode> _backdropGeode; |
---|
[6273] | 171 | osg::ref_ptr<osgEarth::ScreenSpaceLayoutData> _dataLayout; |
---|
[5961] | 172 | |
---|
[5944] | 173 | Placard _placardConf; |
---|
| 174 | osgEarth::Features::AttributeTable _attrs; |
---|
| 175 | }; |
---|
| 176 | |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | #endif |
---|