osgEarth 2.1.1
Public Member Functions | Private Member Functions | Private Attributes

osgEarth::Util::AddPointHandler Struct Reference

List of all members.

Public Member Functions

 AddPointHandler (osgEarth::Features::Feature *feature, osgEarth::Features::FeatureListSource *source, const osgEarth::SpatialReference *mapSRS)
bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
void setMouseButton (osgGA::GUIEventAdapter::MouseButtonMask mouseButton)
osgGA::GUIEventAdapter::MouseButtonMask getMouseButton () const
void setIntersectionMask (osg::Node::NodeMask intersectionMask)
osg::Node::NodeMask getIntersectionMask () const

Private Member Functions

bool addPoint (float x, float y, osgViewer::View *view)

Private Attributes

osgGA::GUIEventAdapter::MouseButtonMask _mouseButton
bool _mouseDown
bool _firstMove
osg::ref_ptr
< osgEarth::Features::FeatureListSource
_source
osg::ref_ptr
< osgEarth::Features::Feature
_feature
osg::ref_ptr< const
SpatialReference
_mapSRS
osg::Node::NodeMask _intersectionMask

Detailed Description

AddPointHandler is a GUIEventHandler that allows you to append points to a Feature's Geometry

Definition at line 34 of file FeatureEditing.


Constructor & Destructor Documentation

AddPointHandler::AddPointHandler ( osgEarth::Features::Feature feature,
osgEarth::Features::FeatureListSource source,
const osgEarth::SpatialReference mapSRS 
)

Constructs a new AddPointHandler

Parameters:
featureThe Feature to edit
sourceThe FeatureSource that the Feature belongs to
mapSRSThe srs of the Map

Definition at line 28 of file FeatureEditing.cpp.

                                                                                                                   :
_feature(feature),
_source( source ),
_mapSRS( mapSRS ),
_mouseDown( false ),
_firstMove( false ),
_mouseButton( osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ),
_intersectionMask( 0xffffffff )
{
}

Member Function Documentation

bool AddPointHandler::addPoint ( float  x,
float  y,
osgViewer::View *  view 
) [private]

Definition at line 52 of file FeatureEditing.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();

        // transform it to map coordinates:
        double lat_rad, lon_rad, dummy;
        _mapSRS->getEllipsoid()->convertXYZToLatLongHeight( point.x(), point.y(), point.z(), lat_rad, lon_rad, dummy );

        double lat_deg = osg::RadiansToDegrees( lat_rad );
        double lon_deg = osg::RadiansToDegrees( lon_rad );

        if (_feature.valid())            
        {
            _feature->getGeometry()->push_back( osg::Vec3d(lon_deg, lat_deg, 0) );
            _source->dirty();
        }
        return true;
    }
    return false;
}

Here is the caller graph for this function:

osg::Node::NodeMask osgEarth::Util::AddPointHandler::getIntersectionMask ( ) const [inline]

Definition at line 61 of file FeatureEditing.

{ return _intersectionMask;}
osgGA::GUIEventAdapter::MouseButtonMask AddPointHandler::getMouseButton ( ) const

Gets the mouse button used for adding new points

Definition at line 46 of file FeatureEditing.cpp.

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

Definition at line 79 of file FeatureEditing.cpp.

{
    osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
    if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH )
    {
        if (ea.getButton() == _mouseButton)
        {
            _mouseDown = true;
            _firstMove = true;
            return addPoint( ea.getX(), ea.getY(), view );
        }
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
    {
        if (ea.getButton() == _mouseButton)
        {
            _mouseDown = false;
        }
    }
    else if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE || ea.getEventType() == osgGA::GUIEventAdapter::DRAG)
    {
        if (_mouseDown)
        {
            if (!_firstMove)
            {
                return addPoint( ea.getX(), ea.getY(), view );
            }
            _firstMove = false;
        }
        return true;
    }

    return false;
}

Here is the call graph for this function:

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

Definition at line 60 of file FeatureEditing.

{ _intersectionMask = intersectionMask; }
void AddPointHandler::setMouseButton ( osgGA::GUIEventAdapter::MouseButtonMask  mouseButton)

Sets the mouse button used for adding new points

Definition at line 40 of file FeatureEditing.cpp.

{
    _mouseButton = mouseButton;
}

Member Data Documentation

Definition at line 71 of file FeatureEditing.

Definition at line 69 of file FeatureEditing.

Definition at line 73 of file FeatureEditing.

Definition at line 72 of file FeatureEditing.

osgGA::GUIEventAdapter::MouseButtonMask osgEarth::Util::AddPointHandler::_mouseButton [private]

Definition at line 67 of file FeatureEditing.

Definition at line 68 of file FeatureEditing.

Definition at line 70 of file FeatureEditing.


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