Esempio n. 1
0
bool
RTTPicker::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    if ( ea.getEventType() == ea.FRAME )
    {
        osg::FrameStamp* fs = aa.asView() ? aa.asView()->getFrameStamp() : 0L;
        if ( fs )
        {
            runPicks( fs->getFrameNumber() );           
        }

        // if there are picks in the queue, need to continuing rendering:
        if ( !_picks.empty() )
        {
            aa.requestRedraw();
        }
    }

    else if ( _defaultCallback.valid() && _defaultCallback->accept(ea, aa) )
    {        
        pick( aa.asView(), ea.getX(), ea.getY(), _defaultCallback.get() );
        aa.requestRedraw();
    }

    return false;
}
Esempio n. 2
0
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if ( ea.getEventType() == osgGA::GUIEventAdapter::RESIZE || _first )
        {
            osg::Camera* cam = aa.asView()->getCamera();
            if ( cam && cam->getViewport() )
            {
                const osg::Viewport* vp = cam->getViewport();
                if ( _first || vp->width() != _width || vp->height() != _height )
                {
                    _cs->setProjectionMatrix(osg::Matrix::ortho2D( 0, vp->width()-1, 0, vp->height()-1 ) );

                    ControlContext cx;
                    cx._vp = new osg::Viewport( 0, 0, vp->width(), vp->height() );
                    cx._viewContextID = aa.asView()->getCamera()->getGraphicsContext()->getState()->getContextID();
                    _cs->setControlContext( cx );

                    _width = vp->width();
                    _height = vp->height();
                }
                if ( vp->width() != 0 && vp->height() != 0 )
                {
                    _first = false;
                }
            }
        }
        return false;
    }
Esempio n. 3
0
bool QueryCoordinatesHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
  if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE )
  {
    osgViewer::View* view = static_cast<osgViewer::View*>( aa.asView() );
    osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false );
    mGlobe->showCurrentCoordinates( coords.x(), coords.y() );
  }
  if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH
       && ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
  {
    osgViewer::View* view = static_cast<osgViewer::View*>( aa.asView() );
    osg::Vec3d coords = getCoords( ea.getX(), ea.getY(), view, false );

    OE_NOTICE << "SelectedCoordinates set to:\nLon: " << coords.x() << " Lat: " << coords.y()
    << " Ele: " << coords.z() << std::endl;

    mGlobe->setSelectedCoordinates( coords );

    if ( ea.getModKeyMask() == osgGA::GUIEventAdapter::MODKEY_CTRL )
      //ctrl + rightclick pops up a QMessageBox
    {
      mGlobe->showSelectedCoordinates();
    }
  }

  return false;
}
Esempio n. 4
0
    bool WeaponHUD::WeaponSwitchHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) {
        switch (ea.getEventType()) {
        case osgGA::GUIEventAdapter::SCROLL:
        {
	  /*
	   * catches multiple activations of the weapon switching
	   * per frame because linux triggers keys twice
	   */
            if (_frameNumber == aa.asView()->getFrameStamp()->getFrameNumber()) {
                return false;
            }
            _frameNumber = aa.asView()->getFrameStamp()->getFrameNumber();
	    //Debug message
            OSG_ALWAYS << "SCROLL: " << aa.asView()->getFrameStamp()->getFrameNumber() << std::endl;
            osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();
            switch (sm) {
            /*
	     * switches backwards through weapon list when
	     * the mouse wheel is scrolled down
	     */
            case osgGA::GUIEventAdapter::SCROLL_DOWN:
	    //Debug message
	      OSG_ALWAYS << "SCROLL DOWN" << std::endl;
		_switch->setValue(_curWeapon, false);
                _curWeapon--;
                /*
		 * if the first weapon is selected and another
		 * scroll backwards is triggered, the last weapon
		 * gets selected
		 */
		if (_curWeapon < 0)
                    _curWeapon = _switch->getNumChildren() - 1;
                _curWeapon = _curWeapon % _switch->getNumChildren();
                _switch->setValue(_curWeapon, true);
                return true;
	    /*
	     * switches forward through weapon list when
	     * the mouse wheel is scrolled up
	     */
	    case osgGA::GUIEventAdapter::SCROLL_UP:
	      //Debug message
                OSG_ALWAYS << "SCROLL UP" << std::endl;
                _switch->setValue(_curWeapon, false);
                _curWeapon++;
                _curWeapon = _curWeapon % _switch->getNumChildren();
                _switch->setValue(_curWeapon, true);
                return true;
            default:
                return false;
            }
        }
        default:
            return false;
        }
    }
Esempio n. 5
0
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE &&
            aa.asView()->getFrameStamp()->getFrameNumber() % 10 == 0)
        {
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
            update( ea.getX(), ea.getY(), view );
        }

        return false;
    }
Esempio n. 6
0
bool WaitingForSecondSelection::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	bool handled = false;

	osgUtil::LineSegmentIntersector::Intersections results;
	osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
	if ((ea.getEventType() == ea.DRAG) && view->computeIntersections(ea.getX(), ea.getY(), results, 0x01))
	{
		// find the first hit under the mouse:
		osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
		osg::Vec3d point = first.getWorldIntersectPoint();

		// transform it to map coordinates:
		osg::Vec3d newPoint;
		m_control->getMapNode()->getMap()->worldPointToMapPoint(point, newPoint);
		m_control->setSecondPoint(newPoint);
		m_control->drawRectangle();
	}
	else if ((ea.getEventType() == ea.DOUBLECLICK) && (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON))
	{
		m_control->currentState() = new Complete(m_control);
		handled = true;
	}

	return (handled);
}
      bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
      {
          if (ea.getEventType() == ea.PUSH && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
          {
              osg::Vec3d world;
              if ( _mapNode->getTerrain()->getWorldCoordsUnderMouse( aa.asView(), ea.getX(), ea.getY(), world ))
              {
                  GeoPoint mapPoint;
                  _mapNode->getMap()->worldPointToMapPoint( world, mapPoint );

                  if (!_startValid)
                  {
                      _startValid = true;
                      _start = mapPoint.vec3d();
                      if (_featureNode.valid())
                      {
                          _root->removeChild( _featureNode.get() );
                          _featureNode = 0;
                      }
                  }
                  else
                  {
                      _end = mapPoint.vec3d();
                      compute();
                      _startValid = false;                    
                  }
              }        
          }
          return false;
      }
Esempio n. 8
0
bool Start::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	m_control->clearDrawing();

	if ((ea.getEventType() == ea.PUSH) && (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON))
	{
		m_control->clearDrawing();
		osgUtil::LineSegmentIntersector::Intersections results;
		osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
		if (view->computeIntersections(ea.getX(), ea.getY(), results, 0x01))
		{
			// find the first hit under the mouse:
			osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
			osg::Vec3d point = first.getWorldIntersectPoint();

			// transform it to map coordinates:
			osg::Vec3d newPoint;
			m_control->getMapNode()->getMap()->worldPointToMapPoint(point, newPoint);
			m_control->setFirstPoint(newPoint);
			m_control->currentState() = new  FirstSelected(m_control);

			return (true);
		}
	}
	return (false);
}
Esempio n. 9
0
bool
AddPointHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
    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;
}
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if (ea.getEventType() == osgGA::GUIEventAdapter::PUSH && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
        {
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
            update( ea.getX(), ea.getY(), view );
        }

        return false;
    }
Esempio n. 11
0
void
AutoClipPlaneHandler::frame( osgGA::GUIActionAdapter& aa )
{
    osg::Camera* cam = aa.asView()->getCamera();

    if ( _rp < 0 )
    {
        osg::ref_ptr<MapNode> tempNode = osgEarth::findTopMostNodeOfType<MapNode>( cam );
        if ( tempNode.valid() && tempNode->getMap()->getProfile() )
        {
            _geocentric = tempNode->getMap()->isGeocentric();
            if ( _geocentric )
                _rp = tempNode->getMap()->getProfile()->getSRS()->getEllipsoid()->getRadiusPolar();
            else
                OE_INFO << "[AutoClipPlaneHandler] disabled for non-geocentric map" << std::endl;

            //_mapNode = tempNode.get();
        }
    }

    if ( _rp > 0 && _geocentric ) // _mapNode.valid() && _geocentric )
    {
        cam->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

        osg::Vec3d eye, center, up;
        cam->getViewMatrixAsLookAt( eye, center, up );

        double d = eye.length();

        if ( d < _rp )
            d = _rp;

        if ( d > _rp )
        {
            double fovy, ar, znear, zfar, finalZfar;
            cam->getProjectionMatrixAsPerspective( fovy, ar, znear, finalZfar );

            // far clip at the horizon:
            zfar = sqrt( d*d - _rp*_rp );

            if (_autoFarPlaneClipping)
            {
                finalZfar = zfar;
            }

            double nfr = _nfrAtRadius + _nfrAtDoubleRadius * ((d-_rp)/d);
            znear = osg::clampAbove( zfar * nfr, 1.0 );

            cam->setProjectionMatrixAsPerspective( fovy, ar, znear, finalZfar );

            //OE_NOTICE << fixed
            //    << "near=" << znear << ", far=" << zfar << std::endl;
        }
    }
}
Esempio n. 12
0
bool
MouseCoordsTool::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
    if (ea.getEventType() == ea.MOVE || ea.getEventType() == ea.DRAG)
    {
        osg::Vec3d world;
        if ( _mapNode->getTerrain()->getWorldCoordsUnderMouse(aa.asView(), ea.getX(), ea.getY(), world) )
        {
            GeoPoint map;
            map.fromWorld( _mapNode->getMapSRS(), world );

            for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); ++i )
                i->get()->set( map, aa.asView(), _mapNode );
        }
        else
        {
            for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); ++i )
                i->get()->reset( aa.asView(), _mapNode );
        }

#if 1 // testing AGL, Dist to Point
        osg::Vec3d eye, center, up;
        aa.asView()->getCamera()->getViewMatrixAsLookAt(eye, center, up);
        DPLineSegmentIntersector* lsi = new DPLineSegmentIntersector(eye, osg::Vec3d(0,0,0));
        osgUtil::IntersectionVisitor iv(lsi);
        lsi->setIntersectionLimit(lsi->LIMIT_NEAREST);
        //iv.setUserData( new Map() );
        _mapNode->accept(iv);

        if ( !lsi->getIntersections().empty() )
        {            
            double agl = (eye - lsi->getFirstIntersection().getWorldIntersectPoint()).length();
            double dtp = (eye - world).length();
            //OE_NOTICE << "AGL = " << agl << "m; DPT = " << dtp << "m" << std::endl;
            Registry::instance()->startActivity("AGL", Stringify() << agl << " m");
            Registry::instance()->startActivity("Range", Stringify() << dtp << " m");
        }
#endif
    }

    return false;
}
Esempio n. 13
0
 bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*)
 {
     if (ea.getEventType() == ea.KEYDOWN && ea.getKey() == _c)
     {
         osg::Vec3d world;
         _mapNode->getTerrain()->getWorldCoordsUnderMouse(aa.asView(), ea.getX(), ea.getY(), world);
         GeoPoint coords;
         coords.fromWorld(s_activeMap->getSRS(), world);
         osg::ref_ptr<ElevationEnvelope> env = s_activeMap->getElevationPool()->createEnvelope(s_activeMap->getSRS(), 23u);
         float ep_elev = env->getElevation(coords.x(), coords.y());
         OE_NOTICE << "Elevations under mouse. EP=" << ep_elev << "\n";
     }
     return false;
 }
Esempio n. 14
0
bool
MouseCoordsTool::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
    if (ea.getEventType() == ea.MOVE || ea.getEventType() == ea.DRAG)
    {
        osg::Vec3d world;
        if ( _mapNode->getTerrain()->getWorldCoordsUnderMouse(aa.asView(), ea.getX(), ea.getY(), world) )
        {
            GeoPoint map;
            map.fromWorld( _mapNode->getMapSRS(), world );

            for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); ++i )
                i->get()->set( map, aa.asView(), _mapNode );
        }
        else
        {
            for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); ++i )
                i->get()->reset( aa.asView(), _mapNode );
        }
    }

    return false;
}
Esempio n. 15
0
bool SelectionManipulator::handleMouseRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us )
{
	osgViewer::View* curView = (osgViewer::View*)us.asView();
	bool release = osgGA::StandardManipulator::handleMouseRelease(ea, us);
	if (m_edgeGroup != NULL)
	{
		m_edgeGroup->setNodeMask(m_orgEdgeState);
	}
	if(m_vertexGroup != NULL)
	{
		m_vertexGroup->setNodeMask(m_orgVertexState);
	}
	curView->requestRedraw();
	return release;
}
Esempio n. 16
0
 bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
 {
   if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE )
   {
     osgViewer::View* view = static_cast<osgViewer::View*>( aa.asView() );
     osgUtil::LineSegmentIntersector::Intersections hits;
     if ( view->computeIntersections( ea.getX(), ea.getY(), hits ) )
     {
       osgEarth::GeoPoint isectPoint;
       isectPoint.fromWorld( mGlobe->mapNode()->getMapSRS()->getGeodeticSRS(), hits.begin()->getWorldIntersectPoint() );
       mGlobe->showCurrentCoordinates( isectPoint );
     }
   }
   return false;
 }
bool TerrainZoomManipulator::setCenterByMousePointer( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us )
{
    osg::View* view = us.asView();
    if( !view )
        return false;

    osg::Camera *camera = view->getCamera();
    if( !camera )
        return false;

    // prepare variables
    float x = ( ea.getX() - ea.getXmin() ) / ( ea.getXmax() - ea.getXmin() );
    float y = ( ea.getY() - ea.getYmin() ) / ( ea.getYmax() - ea.getYmin() );

    osg::Matrix VPW = camera->getProjectionMatrix()
            * camera->getViewport()->computeWindowMatrix();

    osg::Matrix invVPW;
    bool success = invVPW.invert(VPW);

    osg::Vec3f nearPoint = osg::Vec3f(ea.getX(), ea.getY(), 0.f) * invVPW;
    osg::Vec3f farPoint = osg::Vec3f(ea.getX(), ea.getY(), 1.f) * invVPW;

    // scale
    float scale = 1.0f -_wheelZoomFactor;
    float distance = _distance * scale;

    float x_new = ((_distance - distance) * farPoint.x()) / _distance;
    float y_new = ((_distance - distance) * farPoint.y()) / _distance;


    switch( ea.getScrollingMotion() )
    {
        case osgGA::GUIEventAdapter::SCROLL_DOWN:
        {
            panModel(x_new, y_new, 0);
            return true;
        }
        default:
            return false;
    }    
}
Esempio n. 18
0
 bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
 {
     if ( ea.getEventType() == ea.RELEASE )
     {
         IntersectionPicker picker(dynamic_cast<osgViewer::View*>(aa.asView()));
         IntersectionPicker::Hits hits;
         if(picker.pick(ea.getX(), ea.getY(), hits)) {
             std::set<ObjectID> oids;
             if (picker.getObjectIDs(hits, oids)) {
                 ObjectIndex* index = Registry::objectIndex();
                 ObjectID oid = *oids.begin();
                 osg::ref_ptr<FeatureIndex> fi = index->get<FeatureIndex>(oid);
                 if ( fi.valid() ) {
                     OE_NOTICE << "IsectPicker: found OID " << oid << "\n";
                     Feature* f = fi->getFeature(oid);
                     if ( f ) {
                         OE_NOTICE << "...feature ID = " << f->getFID() << "\n";
                     }
                 }      
                 osg::ref_ptr<Feature> f = index->get<Feature>(oid);
                 if ( f.valid() ) {
                     OE_NOTICE << "IsectPicker: found OID " << oid << "\n";
                     OE_NOTICE << "...feature ID = " << f->getFID() << "\n";
                 }
                 osg::ref_ptr<AnnotationNode> a = index->get<AnnotationNode>(oid);
                 if ( a ) {
                     OE_NOTICE << "IsectPicker: found annotation " << a->getName() << "\n";
                 }
             }
             else {
                 OE_NOTICE << "IsectPicker: picked, but no OIDs\n";
             }
         }
         else {
             OE_NOTICE << "IsectPicker: no intersect\n";
         }
     }
     return false;
 }
Esempio n. 19
0
bool Dragging::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	bool handled = false;

	osgUtil::LineSegmentIntersector::Intersections results;
	osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
	if ((ea.getEventType() == ea.DRAG) && view->computeIntersections(ea.getX(), ea.getY(), results, 0x01))
	{
		//double x = ea.getX();
		//double y = ea.getY();

		//QKeyEvent* event = 0;
		//if ((x /(double)(m_control->getViewerWidget()->width())) > 0.85)
		{
			//event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier);
			//QCoreApplication::postEvent(m_control->getViewerWidget(), event);
		}

		// find the first hit under the mouse:
		osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
		osg::Vec3d point = first.getWorldIntersectPoint();

		// transform it to map coordinates:
		osg::Vec3d newPoint;
		m_control->getMapNode()->getMap()->worldPointToMapPoint(point, newPoint);
		m_control->setSecondPoint(newPoint);

		m_control->drawRectangle();

		handled = true;
	}
	else if ((ea.getEventType() == ea.RELEASE) && (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON))
	{
		m_control->currentState() = new Complete(m_control);
		handled = true;
	}

	return (handled);
}
Esempio n. 20
0
bool ImageOverlayEditor::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
    osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
    if (!viewer) return false;

    if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )
    {                        
        // use window coordinates
        // remap the mouse x,y into viewport coordinates.
        osg::Viewport* viewport = viewer->getCamera()->getViewport();
        double mx = viewport->x() + (int)((double )viewport->width()*(ea.getXnormalized()*0.5+0.5));
        double my = viewport->y() + (int)((double )viewport->height()*(ea.getYnormalized()*0.5+0.5));

        // half width, height.
        double w = 5.0f;
        double h = 5.0f;
        osgUtil::PolytopeIntersector* picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW, mx-w, my-h, mx+w, my+h );
        osgUtil::IntersectionVisitor iv(picker);

        viewer->getCamera()->accept(iv);

        if (picker->containsIntersections())
        {
            osgUtil::PolytopeIntersector::Intersection intersection = picker->getFirstIntersection();                                
            osg::NodePath& nodePath = intersection.nodePath;
            _editPoint = getEditPoint(nodePath);
            if (_editPoint != EDITPOINT_NONE)
            {                    
                _dragging = true;
                //_moveVert = ((ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL) == osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL);
            }
        }

    }
    else if ( ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )
    {
        _dragging = false;
    }
    else if ( ea.getEventType() == osgGA::GUIEventAdapter::DRAG)
    {         
        if (_dragging)
        {
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());            
            osgUtil::LineSegmentIntersector::Intersections results;            
            if ( view->computeIntersections( ea.getX(), ea.getY(), results ) )
            {                
                // find the first hit under the mouse:
                osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
                osg::Vec3d point = first.getWorldIntersectPoint();

                double lat_rad, lon_rad, height;                
                _imageOverlay->getEllipsoid()->convertXYZToLatLongHeight( point.x(), point.y(), point.z(), lat_rad, lon_rad, height );

                switch (_editPoint)
                {
                case EDITPOINT_LOWER_LEFT:
                    if (_moveVert)
                    {
                        _imageOverlay->setLowerLeft(osg::RadiansToDegrees(lon_rad), osg::RadiansToDegrees(lat_rad));                
                    }
                    else
                    {
                        _imageOverlay->setSouth(osg::RadiansToDegrees(lat_rad));
                        _imageOverlay->setWest(osg::RadiansToDegrees(lon_rad));
                    }
                    break;
                case EDITPOINT_LOWER_RIGHT:
                    if (_moveVert)
                    {
                        _imageOverlay->setLowerRight(osg::RadiansToDegrees(lon_rad), osg::RadiansToDegrees(lat_rad));                
                    }
                    else
                    {
                        _imageOverlay->setSouth(osg::RadiansToDegrees(lat_rad));
                        _imageOverlay->setEast(osg::RadiansToDegrees(lon_rad));
                    }
                    break;
                case EDITPOINT_UPPER_LEFT:
                    if (_moveVert)
                    {
                        _imageOverlay->setUpperLeft(osg::RadiansToDegrees(lon_rad), osg::RadiansToDegrees(lat_rad));                
                    }
                    else
                    {
                        _imageOverlay->setNorth(osg::RadiansToDegrees(lat_rad));
                        _imageOverlay->setWest(osg::RadiansToDegrees(lon_rad));
                    }
                    break;
                case EDITPOINT_UPPER_RIGHT:
                    if (_moveVert)
                    {
                        _imageOverlay->setUpperRight(osg::RadiansToDegrees(lon_rad), osg::RadiansToDegrees(lat_rad));                
                    }
                    else
                    {
                        _imageOverlay->setNorth(osg::RadiansToDegrees(lat_rad));
                        _imageOverlay->setEast(osg::RadiansToDegrees(lon_rad));
                    }
                    break;
                case EDITPOINT_CENTER:
                    _imageOverlay->setCenter(osg::RadiansToDegrees(lon_rad), osg::RadiansToDegrees(lat_rad));                
                    break;

                }

                updateEditor();
                return true;
            }
        }
    }
    return false;
}
Esempio n. 21
0
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE ||
            ea.getEventType() == osgGA::GUIEventAdapter::DRAG)
        {
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
            update( ea.getX(), ea.getY(), view );
            if (_mouseDown)
            {                
                applyDeformation();
            }
        }
        if (ea.getEventType() == osgGA::GUIEventAdapter::PUSH && ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
        {
            _mouseDown = true;
            osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
            update( ea.getX(), ea.getY(), view );
            applyDeformation();
        }
        if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
        {
            _mouseDown = false;
        }
        else if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN)
        {
            if (ea.getKey() == 'k')
            {
                if (_tool == TOOL_CIRCLE)
                {
                    OE_NOTICE << "Switching to rectangle tool" << std::endl;
                    _tool = TOOL_RECTANGLE;
                }
                else if (_tool == TOOL_RECTANGLE)
                {
                    OE_NOTICE << "Switching to blast tool" << std::endl;
                    _tool = TOOL_BLAST;
                }
                else if (_tool == TOOL_BLAST)
                {
                    OE_NOTICE << "Switching to circle tool" << std::endl;
                    _tool = TOOL_CIRCLE;
                }
                return true;
            }
            else if (ea.getKey() == 'o')
            {
                _offset -= 10;
                OE_NOTICE << "Offset " << _offset << std::endl;
                return true;
            }
            else if (ea.getKey() == 'O')
            {
                _offset += 10;
                OE_NOTICE << "Offset " << _offset << std::endl;
                return true;
            }
            else if (ea.getKey() == 'r')
            {
                _radius = osg::clampAbove(_radius - 10.0, 1.0);
                OE_NOTICE << "Radius = " << _radius << std::endl;
            }
            else if (ea.getKey() == 'R')
            {
                _radius += 10;
                OE_NOTICE << "Radius = " << _radius << std::endl;
            }
        }

        return false;
    }
Esempio n. 22
0
bool EventHandler::handle(const osgGA::GUIEventAdapter& eventAdapter,
                    osgGA::GUIActionAdapter& actionAdapter, osg::Object*,
                                   osg::NodeVisitor*)
{
    if (eventAdapter.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL)
    {
      clearPrehighlight();
      return false;
    }
  
    if(eventAdapter.getHandled())
    {
      clearPrehighlight();
      return true; //overlay has taken event;
    }
    
    //escape key should dispatch to cancel command.
    if (eventAdapter.getEventType() == osgGA::GUIEventAdapter::KEYUP)
    {
      if (eventAdapter.getKey() == osgGA::GUIEventAdapter::KEY_Escape)
      {
	observer->messageOutSignal(msg::Request | msg::Command | msg::Cancel);
	return true;
      }
    }
  
    currentIntersections.clear();
    if (eventAdapter.getEventType() == osgGA::GUIEventAdapter::MOVE)
    {
        osg::View* view = actionAdapter.asView();
        if (!view)
            return false;

        osg::ref_ptr<Intersector>picker = new Intersector(
                    osgUtil::Intersector::WINDOW, eventAdapter.getX(),
                    eventAdapter.getY());
        picker->setPickRadius(16.0); //32 x 32 cursor

        osgUtil::IntersectionVisitor iv(picker.get());
        iv.setTraversalMask(nodeMask);
        view->getCamera()->accept(iv);
	
        if (picker->containsIntersections())
        {
           currentIntersections = picker->getMyIntersections();
	   Interpreter interpreter(currentIntersections, selectionMask);

           slc::Container newContainer;
	   //loop to get first non selected geometry.
	   for (const auto& container : interpreter.containersOut)
	   {
	     if(alreadySelected(container))
	      continue;
	     newContainer = container;
	     break;
	   }
	   
	   if (newContainer == lastPrehighlight)
	   {
	     //update the point location though.
	     lastPrehighlight.pointLocation = newContainer.pointLocation;
	     return false;
	   }
	   
           clearPrehighlight();
	   
	   if (newContainer.selectionType == slc::Type::None)
	      return false;
           
	   //this is here so we make sure we get through all selection
	   //conditions before we construct point geometry.
           if (isPointType(newContainer.selectionType))
	   {
	     ref_ptr<Geometry> pointGeometry(buildTempPoint(newContainer.pointLocation));
	     newContainer.pointGeometry = pointGeometry.get();
	     viewerRoot->addChild(pointGeometry.get());
	   }
	   
	   setPrehighlight(newContainer);
        }
        else
            clearPrehighlight();
    }

    if (eventAdapter.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON &&
            eventAdapter.getEventType() == osgGA::GUIEventAdapter::RELEASE)
    {
        if
	(
	  (!lastPrehighlight.selectionIds.empty()) ||
	  (slc::isPointType(lastPrehighlight.selectionType))
	)
        {
	  //prehighlight gets 'moved' into selections so can't call
	  //clear prehighlight, but we still clear the prehighlight
	  //selections we need to make observers aware of this 'hidden' change.
	    msg::Message clearMessage;
	    clearMessage.mask = msg::Response | msg::Pre | msg::Preselection | msg::Subtraction;
	    clearMessage.payload = containerToMessage(lastPrehighlight);
	    observer->messageOutSignal(clearMessage);
	    
	    if (slc::isPointType(lastPrehighlight.selectionType))
	    {
	      assert(lastPrehighlight.pointGeometry.valid());
	      osg::Vec4Array *colors = dynamic_cast<osg::Vec4Array*>(lastPrehighlight.pointGeometry->getColorArray());
	      assert(colors);
	      (*colors)[0] = osg::Vec4(1.0, 1.0, 1.0, 1.0);
	      colors->dirty();
	      lastPrehighlight.pointGeometry->dirtyDisplayList();
	    }
	    else
	      selectionOperation(lastPrehighlight.featureId, lastPrehighlight.selectionIds,
				HighlightVisitor::Operation::Highlight);
	    
            add(selectionContainers, lastPrehighlight);
	    
	    msg::Message addMessage;
	    addMessage.mask = msg::Response | msg::Post | msg::Selection | msg::Addition;
	    addMessage.payload = containerToMessage(lastPrehighlight);
	    observer->messageOutSignal(addMessage);
	    
            lastPrehighlight = Container();
        }
        //not clearing the selection anymore on a empty pick.
//         else
//             clearSelections();

    }
    
    if (eventAdapter.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON &&
            eventAdapter.getEventType() == osgGA::GUIEventAdapter::RELEASE)
    {
      clearSelections();
    }

    if (eventAdapter.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON &&
            eventAdapter.getEventType() == osgGA::GUIEventAdapter::PUSH)
    {
        clearPrehighlight();
    }

    if (eventAdapter.getEventType() == osgGA::GUIEventAdapter::DRAG)
    {
        //don't get button info here, need to cache.
    }

    return false;
}
bool
FeatureQueryTool::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
    bool handled = false;
    bool attempt;

    if ( _inputPredicate.valid() )
    {
        attempt = _inputPredicate->accept(ea);
    }
    else
    {
        attempt =
            ea.getEventType() == osgGA::GUIEventAdapter::RELEASE &&
            _mouseDown && 
            fabs(ea.getX()-_mouseDownX) <= 3.0 && 
            fabs(ea.getY()-_mouseDownY) <= 3.0;
    }

    if ( attempt )
    {
        osg::View* view = aa.asView();

        Picker picker(
            dynamic_cast<osgViewer::View*>(view),
            _mapNode->getModelLayerGroup() );

        Picker::Hits hits;

        if ( picker.pick( ea.getX(), ea.getY(), hits ) )
        {
            // find the closest indexed feature to the camera. It must be a feature
            // that is not only closest, but exists in the index as well.

            FeatureSourceIndexNode* closestIndex    = 0L;
            FeatureID               closestFID;
            double                  closestDistance = DBL_MAX;
            osg::Vec3d              closestWorldPt;

            for(Picker::Hits::iterator hit = hits.begin(); hit != hits.end(); ++hit )
            {
                FeatureSourceIndexNode* index = picker.getNode<FeatureSourceIndexNode>( *hit );
                if ( index && (hit->distance < closestDistance) )
                {
                    FeatureID fid;
                    if ( index->getFID( hit->drawable, hit->primitiveIndex, fid ) )
                    {
                        closestIndex    = index;
                        closestFID      = fid;
                        closestDistance = hit->distance;
                        closestWorldPt  = hit->matrix.valid() ? hit->localIntersectionPoint * (*hit->matrix.get()) : hit->localIntersectionPoint;
                    }
                }
            }

            if ( closestIndex )
            {
                OE_DEBUG << LC << "HIT: feature ID = " << (unsigned)closestFID << std::endl;

                Callback::EventArgs args;
                args._ea = &ea;
                args._aa = &aa;
                args._worldPoint = closestWorldPt;

                for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); )
                {
                    if ( i->valid() )
                    {
                        i->get()->onHit( closestIndex, closestFID, args );
                        ++i;
                    }
                    else
                    {
                        i = _callbacks.erase( i );
                    }
                }

                handled = true;
            }
        }

        if ( !handled )
        {
            OE_DEBUG << LC << "miss" << std::endl;

            Callback::EventArgs args;
            args._ea = &ea;
            args._aa = &aa;

            for( Callbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); )
            {
                if ( i->valid() )
                {
                    i->get()->onMiss( args );
                    ++i;
                }
                else
                {
                    i = _callbacks.erase( i );
                }
            }
        }

        _mouseDown = false;
    }

    // unmodified left mouse click
    else if (
        ea.getEventType()  == osgGA::GUIEventAdapter::PUSH &&
        ea.getModKeyMask() == 0 &&
        ea.getButtonMask() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
    {
        _mouseDown = true;
        _mouseDownX = ea.getX();
        _mouseDownY = ea.getY();
    }

    return handled;
}