osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthUtil/MeasureTool

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2010 Pelican Mapping
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00020 #ifndef OSGEARTHUTIL_MEASURETOOL_H
00021 #define OSGEARTHUTIL_MEASURETOOL_H 1
00022 
00023 #include <osgEarthUtil/Common>
00024 #include <osgEarth/MapNode>
00025 #include <osgEarthFeatures/FeatureNode>
00026 #include <osgEarthSymbology/Style>
00027 #include <osg/Group>
00028 #include <osgGA/GUIEventHandler>
00029 #include <osgViewer/View>
00030 
00031 namespace osgEarth { namespace Util
00032 {
00033     using namespace osgEarth::Symbology;
00034 
00035     struct OSGEARTHUTIL_EXPORT MeasureToolHandler : public osgGA::GUIEventHandler 
00036     {
00037     public:
00038 
00039         class MeasureToolEventHandler : public osg::Referenced
00040         {
00041         public:
00042             virtual void onDistanceChanged(MeasureToolHandler* sender, double distance) {}
00043         };
00044 
00045         typedef std::list< osg::ref_ptr< MeasureToolEventHandler > > MeasureToolEventHandlerList;
00046 
00047 
00048         MeasureToolHandler( osg::Group* group, MapNode* mapNode );        
00049         ~MeasureToolHandler();
00050 
00051         bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );        
00052 
00053         bool getLocationAt(osgViewer::View* view, double x, double y, double &lon, double &lat);
00054         
00055         void clear();
00056 
00057         void addEventHandler(MeasureToolEventHandler* handler );
00058 
00059         void setMouseButton(int mouseButton);
00060         int getMouseButton() const;
00061 
00062         GeoInterpolation getGeoInterpolation() const;
00063         void setGeoInterpolation( GeoInterpolation geoInterpolation );
00064 
00065         void setIsPath( bool path );
00066         bool getIsPath() const;
00067 
00069         void setLineStyle( const Style& style );
00070         const Style& getLineStyle() const { return _feature->style().value(); }
00071 
00072         void setIntersectionMask( osg::Node::NodeMask intersectionMask ) { _intersectionMask = intersectionMask; }
00073         osg::Node::NodeMask getIntersectionMask() const { return _intersectionMask;}
00074 
00075     protected:
00076         GeoInterpolation _geoInterpolation;
00077         void fireDistanceChanged();
00078         bool _lastPointTemporary;
00079         bool _gotFirstLocation;
00080         bool _finished;
00081         bool _mouseDown;
00082         float _mouseDownX, _mouseDownY;
00083         int _mouseButton;
00084         osg::ref_ptr< osg::Group > _group;
00085 
00086         osg::ref_ptr< osgEarth::Features::FeatureNode > _featureNode;
00087         osg::ref_ptr< osgEarth::Features::Feature >  _feature;
00088 
00089         MeasureToolEventHandlerList _eventHandlers;
00090         bool _isPath;        
00091         osg::ref_ptr< MapNode > _mapNode;
00092         osg::Node::NodeMask _intersectionMask;
00093     };
00094 }}
00095 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines