osgEarth 2.1.1
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

osgEarth::Util::MeasureToolHandler Struct Reference

List of all members.

Classes

class  MeasureToolEventHandler

Public Types

typedef std::list
< osg::ref_ptr
< MeasureToolEventHandler > > 
MeasureToolEventHandlerList

Public Member Functions

 MeasureToolHandler (osg::Group *group, MapNode *mapNode)
 ~MeasureToolHandler ()
bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
bool getLocationAt (osgViewer::View *view, double x, double y, double &lon, double &lat)
void clear ()
void addEventHandler (MeasureToolEventHandler *handler)
void setMouseButton (int mouseButton)
int getMouseButton () const
GeoInterpolation getGeoInterpolation () const
void setGeoInterpolation (GeoInterpolation geoInterpolation)
void setIsPath (bool path)
bool getIsPath () const
void setLineStyle (const Style &style)
const StylegetLineStyle () const
void setIntersectionMask (osg::Node::NodeMask intersectionMask)
osg::Node::NodeMask getIntersectionMask () const

Protected Member Functions

void fireDistanceChanged ()

Protected Attributes

GeoInterpolation _geoInterpolation
bool _lastPointTemporary
bool _gotFirstLocation
bool _finished
bool _mouseDown
float _mouseDownX
float _mouseDownY
int _mouseButton
osg::ref_ptr< osg::Group > _group
osg::ref_ptr
< osgEarth::Features::FeatureNode
_featureNode
osg::ref_ptr
< osgEarth::Features::Feature
_feature
MeasureToolEventHandlerList _eventHandlers
bool _isPath
osg::ref_ptr< MapNode_mapNode
osg::Node::NodeMask _intersectionMask

Detailed Description

Definition at line 35 of file MeasureTool.


Member Typedef Documentation

Definition at line 45 of file MeasureTool.


Constructor & Destructor Documentation

MeasureToolHandler::MeasureToolHandler ( osg::Group *  group,
osgEarth::MapNode mapNode 
)

Definition at line 33 of file MeasureTool.cpp.

                                                                                 :
_mouseDown(false),
_group(group),
_gotFirstLocation(false),
_lastPointTemporary(false),
_finished(false),
_geoInterpolation( GEOINTERP_GREAT_CIRCLE ),
_mouseButton( osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON),
_isPath( false ),
_mapNode( mapNode ),
_intersectionMask(0xffffffff)
{
    LineString* line = new LineString();
    _feature = new Feature();
    _feature->setGeometry( line );
    _feature->geoInterp() = _geoInterpolation;    

    //Define a style for the line
    Style style;
    LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
    ls->stroke()->color() = osg::Vec4f( 1,0,0,1 );
    ls->stroke()->width() = 2.0f;   

    _feature->style() = style;

    _featureNode = new FeatureNode( _mapNode.get(), _feature.get(), false);
    

    //Disable lighting and depth testing for the feature graph
    _featureNode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    _featureNode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

    _group->addChild (_featureNode.get() );
}

Here is the call graph for this function:

MeasureToolHandler::~MeasureToolHandler ( )

Definition at line 68 of file MeasureTool.cpp.

{
    if (_group.valid()) _group->removeChild( _featureNode.get() );
}

Member Function Documentation

void MeasureToolHandler::addEventHandler ( MeasureToolEventHandler handler)

Definition at line 246 of file MeasureTool.cpp.

{
    _eventHandlers.push_back( handler );
}

Here is the caller graph for this function:

void MeasureToolHandler::clear ( )

Definition at line 221 of file MeasureTool.cpp.

{
    //Clear the locations    
    _feature->getGeometry()->clear();
    //_features->dirty();
    _featureNode->init();
    fireDistanceChanged();

    _gotFirstLocation = false; 
    _lastPointTemporary = false; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MeasureToolHandler::fireDistanceChanged ( ) [protected]

Definition at line 252 of file MeasureTool.cpp.

{
    double distance = 0;
    if (_geoInterpolation == GEOINTERP_GREAT_CIRCLE)
    {
        distance = GeoMath::distance(_feature->getGeometry()->asVector());
    }
    else if (_geoInterpolation == GEOINTERP_RHUMB_LINE) 
    {
        distance = GeoMath::rhumbDistance(_feature->getGeometry()->asVector());
    }
    for (MeasureToolEventHandlerList::const_iterator i = _eventHandlers.begin(); i != _eventHandlers.end(); ++i)
    {
        i->get()->onDistanceChanged( this, distance );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

GeoInterpolation MeasureToolHandler::getGeoInterpolation ( ) const

Definition at line 93 of file MeasureTool.cpp.

{
    return _geoInterpolation;
}
osg::Node::NodeMask osgEarth::Util::MeasureToolHandler::getIntersectionMask ( ) const [inline]

Definition at line 73 of file MeasureTool.

{ return _intersectionMask;}
bool MeasureToolHandler::getIsPath ( ) const

Definition at line 74 of file MeasureTool.cpp.

{
    return _isPath;
}
const Style& osgEarth::Util::MeasureToolHandler::getLineStyle ( ) const [inline]

Definition at line 70 of file MeasureTool.

{ return _feature->style().value(); }
bool MeasureToolHandler::getLocationAt ( osgViewer::View *  view,
double  x,
double  y,
double &  lon,
double &  lat 
)

Definition at line 203 of file MeasureTool.cpp.

{
    osgUtil::LineSegmentIntersector::Intersections results;            
    if ( view->computeIntersections( x, y, results, _intersectionMask ) )
    {
        // find the first hit under the mouse:
        osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
        osg::Vec3d point = first.getWorldIntersectPoint();

        double lat_rad, lon_rad, height;       
        _mapNode->getMap()->getProfile()->getSRS()->getEllipsoid()->convertXYZToLatLongHeight( point.x(), point.y(), point.z(), lat_rad, lon_rad, height );
        lat = osg::RadiansToDegrees( lat_rad );
        lon = osg::RadiansToDegrees( lon_rad );
        return true;
    }
    return false;
}

Here is the caller graph for this function:

int MeasureToolHandler::getMouseButton ( ) const

Definition at line 240 of file MeasureTool.cpp.

{
    return _mouseButton;
}
bool MeasureToolHandler::handle ( const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &  aa 
)

Definition at line 118 of file MeasureTool.cpp.

{    
    if ( ea.getHandled() )
    {
        return false;
    }

    
    osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());                
    if (ea.getEventType() == osgGA::GUIEventAdapter::PUSH && ea.getButton() == _mouseButton)
    {        
        _mouseDown = true;
        _mouseDownX = ea.getX();
        _mouseDownY = ea.getY();
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == _mouseButton)
    {        
        float eps = 1.0f;
        _mouseDown = false;
        if (osg::equivalent(ea.getX(), _mouseDownX) && osg::equivalent(ea.getY(), _mouseDownY))
        {
            double lon, lat;
            if (getLocationAt(view, ea.getX(), ea.getY(), lon, lat))
            {
                if (!_gotFirstLocation)
                {
                    _finished = false;
                    clear();                    
                    _gotFirstLocation = true;
                    _feature->getGeometry()->push_back( osg::Vec3d( lon, lat, 0 ) );
                }
                else
                {
                    if (_lastPointTemporary)
                    {
                        _feature->getGeometry()->back() = osg::Vec3d( lon, lat, 0 );
                        _lastPointTemporary = false;
                    }
                    else
                    {                     
                        _feature->getGeometry()->push_back( osg::Vec3d( lon, lat, 0 ) );
                    }
                    _featureNode->init();
                    //_gotFirstLocation = false;
                    //_finished = true;
                    if (_finished || !_isPath) {
                        _gotFirstLocation = false;
                    }
                    fireDistanceChanged();
                }
            }
        }
    }  
    else if (ea.getEventType() == osgGA::GUIEventAdapter::DOUBLECLICK) {        
        if (_gotFirstLocation)
        {
            //_gotFirstLocation = false;
            _finished = true;     
            return true;
        }
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE)
    {
        if (_gotFirstLocation)
        {
            double lon, lat;
            if (getLocationAt(view, ea.getX(), ea.getY(), lon, lat))
            {
                if (!_lastPointTemporary)
                {
                    _feature->getGeometry()->push_back( osg::Vec3d( lon, lat, 0 ) );                 
                    _lastPointTemporary = true;
                }                        
                else
                {
                    _feature->getGeometry()->back() = osg::Vec3d( lon, lat, 0 );
                }
                _featureNode->init();
                fireDistanceChanged();
            }
        }
    }    
    return false;
}

Here is the call graph for this function:

void MeasureToolHandler::setGeoInterpolation ( GeoInterpolation  geoInterpolation)

Definition at line 99 of file MeasureTool.cpp.

{
    if (_geoInterpolation != geoInterpolation)
    {
        _geoInterpolation = geoInterpolation;
        _feature->geoInterp() = _geoInterpolation;
        _featureNode->init();
        fireDistanceChanged();
    }
}

Here is the call graph for this function:

void osgEarth::Util::MeasureToolHandler::setIntersectionMask ( osg::Node::NodeMask  intersectionMask) [inline]

Definition at line 72 of file MeasureTool.

{ _intersectionMask = intersectionMask; }

Here is the caller graph for this function:

void MeasureToolHandler::setIsPath ( bool  path)

Definition at line 80 of file MeasureTool.cpp.

{
    if (_isPath != path)
    {
        _isPath = path;
        _finished = true;
        clear();                    
        _gotFirstLocation = false;
    }
}

Here is the call graph for this function:

void MeasureToolHandler::setLineStyle ( const Style style)

Sets the style of the measurment line (to something other than the default)

Definition at line 111 of file MeasureTool.cpp.

{
     _feature->style() = style;
     _featureNode->init();
}

Here is the caller graph for this function:

void MeasureToolHandler::setMouseButton ( int  mouseButton)

Definition at line 234 of file MeasureTool.cpp.

{
    _mouseButton = mouseButton;
}

Member Data Documentation

Definition at line 89 of file MeasureTool.

Definition at line 87 of file MeasureTool.

Definition at line 86 of file MeasureTool.

Definition at line 80 of file MeasureTool.

Definition at line 76 of file MeasureTool.

Definition at line 79 of file MeasureTool.

osg::ref_ptr< osg::Group > osgEarth::Util::MeasureToolHandler::_group [protected]

Definition at line 84 of file MeasureTool.

Definition at line 92 of file MeasureTool.

Definition at line 90 of file MeasureTool.

Definition at line 78 of file MeasureTool.

Definition at line 91 of file MeasureTool.

Definition at line 83 of file MeasureTool.

Definition at line 81 of file MeasureTool.

Definition at line 82 of file MeasureTool.

Definition at line 82 of file MeasureTool.


The documentation for this struct was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines