|
| 1 | +/* -*-c++-*- */ |
| 2 | +/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph |
| 3 | + * Copyright 2016 Pelican Mapping |
| 4 | + * http://osgearth.org |
| 5 | + * |
| 6 | + * osgEarth is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 18 | + */ |
| 19 | +#ifndef OSGEARTH_DRIVER_GRATICULE_OPTIONS |
| 20 | +#define OSGEARTH_DRIVER_GRATICULE_OPTIONS 1 |
| 21 | + |
| 22 | +#include <osgEarth/Common> |
| 23 | +#include <osgEarth/URI> |
| 24 | +#include <osgEarthSymbology/Color> |
| 25 | + |
| 26 | +namespace osgEarth { namespace Util |
| 27 | +{ |
| 28 | + using namespace osgEarth; |
| 29 | + using namespace osgEarth::Symbology; |
| 30 | + |
| 31 | + /** |
| 32 | + * Options governing normal mapping of the terrain. |
| 33 | + */ |
| 34 | + class GraticuleOptions : public DriverConfigOptions // NO EXPORT; header only |
| 35 | + { |
| 36 | + public: |
| 37 | + /** Grid line color */ |
| 38 | + optional<Color>& color() { return _color; } |
| 39 | + const optional<Color>& color() const { return _color; } |
| 40 | + |
| 41 | + /** Label color */ |
| 42 | + optional<Color>& labelColor() { return _labelColor; } |
| 43 | + const optional<Color>& labelColor() const { return _labelColor; } |
| 44 | + |
| 45 | + /** Label size */ |
| 46 | + optional<int>& labelSize() { return _labelSize; } |
| 47 | + const optional<int>& labelSize() const { return _labelSize; } |
| 48 | + |
| 49 | + /** Grid line width in pixels */ |
| 50 | + optional<float>& lineWidth() { return _lineWidth; } |
| 51 | + const optional<float>& lineWidth() const { return _lineWidth; } |
| 52 | + |
| 53 | + /** A target number of grid lines to view on screen at once. */ |
| 54 | + optional<int>& gridLines() { return _gridLines; } |
| 55 | + const optional<int>& gridLines() const { return _gridLines; } |
| 56 | + |
| 57 | + /** Resolutions for the graticule separated by spaces |
| 58 | + * Resolutions are in degrees listed from lowest to highest resolution |
| 59 | + * For example: 10 5 2.5 1.25 |
| 60 | + */ |
| 61 | + optional<std::string>& resolutions() { return _resolutions; } |
| 62 | + const optional<std::string>& resolutions() const { return _resolutions; } |
| 63 | + |
| 64 | + public: // uniform names |
| 65 | + static const char* resolutionUniformName() { return "oe_graticule_resolution"; } |
| 66 | + static const char* colorUniformName() { return "oe_graticule_color"; } |
| 67 | + static const char* lineWidthUniformName() { return "oe_graticule_lineWidth"; } |
| 68 | + |
| 69 | + public: |
| 70 | + GraticuleOptions( const ConfigOptions& opt =ConfigOptions() ) : DriverConfigOptions( opt ) |
| 71 | + { |
| 72 | + setDriver( "graticule" ); |
| 73 | + _lineWidth.init ( 2.0f ); |
| 74 | + _color.init ( Color(Color::Yellow, 0.5f) ); |
| 75 | + _labelColor.init ( Color::White ); |
| 76 | + _labelSize.init(10); |
| 77 | + _gridLines.init(10); |
| 78 | + fromConfig( _conf ); |
| 79 | + } |
| 80 | + |
| 81 | + virtual ~GraticuleOptions() { } |
| 82 | + |
| 83 | + public: |
| 84 | + Config getConfig() const { |
| 85 | + Config conf = DriverConfigOptions::getConfig(); |
| 86 | + conf.addIfSet("line_width", _lineWidth); |
| 87 | + conf.addIfSet("color", _color); |
| 88 | + conf.addIfSet("label_color", _labelColor ); |
| 89 | + conf.addIfSet("label_size", _labelSize ); |
| 90 | + conf.addIfSet("grid_lines", _gridLines); |
| 91 | + conf.addIfSet("resolutions", _resolutions); |
| 92 | + return conf; |
| 93 | + } |
| 94 | + |
| 95 | + protected: |
| 96 | + void mergeConfig( const Config& conf ) { |
| 97 | + DriverConfigOptions::mergeConfig( conf ); |
| 98 | + fromConfig( conf ); |
| 99 | + } |
| 100 | + |
| 101 | + private: |
| 102 | + void fromConfig( const Config& conf ) { |
| 103 | + conf.getIfSet("line_width", _lineWidth); |
| 104 | + conf.getIfSet("color", _color); |
| 105 | + conf.getIfSet("label_color", _labelColor); |
| 106 | + conf.getIfSet("label_size", _labelSize ); |
| 107 | + conf.getIfSet("grid_lines", _gridLines); |
| 108 | + conf.getIfSet("resolutions", _resolutions); |
| 109 | + } |
| 110 | + |
| 111 | + optional<float> _lineWidth; |
| 112 | + optional<Color> _color; |
| 113 | + optional<Color> _labelColor; |
| 114 | + optional<int> _labelSize; |
| 115 | + optional<int> _gridLines; |
| 116 | + optional<std::string> _resolutions; |
| 117 | + }; |
| 118 | + |
| 119 | +} } // namespace osgEarth::Util |
| 120 | + |
| 121 | +#endif // OSGEARTH_DRIVER_GRATICULE_OPTIONS |
| 122 | + |
0 commit comments