Пример #1
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;
}
Пример #2
0
    virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        int x = ea.getX(), y = ea.getY(), width = ea.getWindowWidth(), height = ea.getWindowHeight();
        if ( ea.getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS )
            y = ea.getWindowHeight() - y;
        
        if ( !CEGUI::System::getSingletonPtr() )
            return false;

        CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext();

        switch ( ea.getEventType() )
        {
		case osgGA::GUIEventAdapter::KEYDOWN:
			context.injectKeyDown(key_conv(ea.getKey()));
			context.injectChar(char_conv(ea.getKey()));
			// return key_conv(ea.getKey()) != CEGUI::Key::Unknown;
			break;
		case osgGA::GUIEventAdapter::KEYUP:
			context.injectKeyUp(key_conv(ea.getKey()));
			// return key_conv(ea.getKey()) != CEGUI::Key::Unknown;
			break;
        case osgGA::GUIEventAdapter::PUSH:
            context.injectMousePosition( x, y );
            context.injectMouseButtonDown(convertMouseButton(ea.getButton()));
            break;
        case osgGA::GUIEventAdapter::RELEASE:
            context.injectMousePosition(x, y);
            context.injectMouseButtonUp(convertMouseButton(ea.getButton()));
            break;
        case osgGA::GUIEventAdapter::SCROLL:
            if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_DOWN )
                context.injectMouseWheelChange(-1);
            else if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_UP )
                context.injectMouseWheelChange(+1);
            break;
        case osgGA::GUIEventAdapter::DRAG:
        case osgGA::GUIEventAdapter::MOVE:
            context.injectMousePosition(x, y);
            break;
        case osgGA::GUIEventAdapter::RESIZE:
            if ( _camera.valid() )
            {
                _camera->setProjectionMatrix( osg::Matrixd::ortho2D(0.0, width, 0.0, height) );
                _camera->setViewport( 0.0, 0.0, width, height );
            }
            break;
        default:
            return false;
        }

        CEGUI::Window* rootWindow = context.getRootWindow();
        if ( rootWindow )
        {
            CEGUI::Window* anyWindow = rootWindow->getChildAtPosition( CEGUI::Vector2f(x, y) );
            if ( anyWindow ) return true;
        }
        return false;
    }
Пример #3
0
/***********************************************************
handle inputs
***********************************************************/
bool UserInputsHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{


	switch(ea.getEventType())
	{
		case(osgGA::GUIEventAdapter::PUSH):
		{
			if(ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
			{			
				_mouse_Y = ea.getY();
				_right_button_pressed = true;
				return true;
			}
		}

		case(osgGA::GUIEventAdapter::RELEASE):
		{
			if(ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
			{
				_right_button_pressed = false;
				return true;
			}
		}

		// update Zenit on mouse move with right button pressed
		case(osgGA::GUIEventAdapter::DRAG):
		{
			if(_right_button_pressed)
			{
				OsgHandler::getInstance()->DeltaUpdateCameraZenit(_mouse_Y-ea.getY());
				_mouse_Y = ea.getY();
				return true;
			}
		}

		// zoom on mouse scroll
		case(osgGA::GUIEventAdapter::SCROLL):
		{
			if(ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_DOWN)
				OsgHandler::getInstance()->DeltaUpdateCameraDistance(5);

			if(ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_UP)
				OsgHandler::getInstance()->DeltaUpdateCameraDistance(-5);

			return true;
		}


		default:
			return false;
	}
}
Пример #4
0
bool PickHandler::handle(const osgGA::GUIEventAdapter & ea,
		osgGA::GUIActionAdapter & aa) {
	if (!_f)
		return false;

	if (ea.getEventType() != osgGA::GUIEventAdapter::RELEASE
			|| ea.getButton() != osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
		return false;

	osgViewer::Viewer * viewer = dynamic_cast<osgViewer::Viewer*>(&aa);

	if (viewer) {
		osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
				new osgUtil::LineSegmentIntersector(
						osgUtil::Intersector::WINDOW, ea.getX(), ea.getY());
		osgUtil::IntersectionVisitor iv(intersector.get());
		iv.setTraversalMask(~0x1);
		viewer->getCamera()->accept(iv);
		if (intersector->containsIntersections()) {
			const osgUtil::LineSegmentIntersector::Intersection &result =
					*(intersector->getIntersections().begin());

			_f(result);
		}
	}
	return false;

}
Пример #5
0
bool MouseHandler::handle(
    const osgGA::GUIEventAdapter &gea,
    osgGA::GUIActionAdapter& /*gaa*/,
    osg::Object*                  /*obj*/,
    osg::NodeVisitor*             /*nv*/
    )
{
    osgGA::GUIEventAdapter::EventType ev = gea.getEventType();
    MouseAction                       ma = _isMouseEvent(ev);

    if (ma)
    {
        // If we're scrolling, we need to inform the WindowManager of that.
        _wm->setScrollingMotion(gea.getScrollingMotion());

        // osgWidget assumes origin is bottom left of window so make sure mouse coordinate are increaseing y upwards and are scaled to window size.
        float x = (gea.getX() - gea.getXmin()) / (gea.getXmax() - gea.getXmin()) * static_cast<float>(gea.getWindowWidth());
        float y = (gea.getY() - gea.getYmin()) / (gea.getYmax() - gea.getYmin()) * static_cast<float>(gea.getWindowHeight());
        if (gea.getMouseYOrientation() == osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS)
            y = static_cast<float>(gea.getWindowHeight()) - y;

        // OSG_NOTICE<<"MouseHandler(x="<<x<<", y="<<y<<")"<<std::endl;

        return (this->*ma)(x, y, gea.getButton());
    }

    return false;
}
      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;
      }
Пример #7
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);
}
Пример #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);
}
Пример #9
0
    virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
             ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
             !(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL) )
            return false;

        osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
        if ( viewer )
        {
            osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
                new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY());
            osgUtil::IntersectionVisitor iv( intersector.get() );
            iv.setTraversalMask( ~0x1 );
            viewer->getCamera()->accept( iv );

            if ( intersector->containsIntersections() )
            {
                const osgUtil::LineSegmentIntersector::Intersection& result =
                    *(intersector->getIntersections().begin());

                osg::BoundingBox bb = result.drawable->getBound();
                osg::Vec3 worldCenter = bb.center() * osg::computeLocalToWorld(result.nodePath);
                _selectionBox->setMatrix(
                    osg::Matrix::scale(bb.xMax()-bb.xMin(), bb.yMax()-bb.yMin(), bb.zMax()-bb.zMin()) *
                    osg::Matrix::translate(worldCenter) );
            }
        }
        return false;
    }
Пример #10
0
bool QOsgEventHandler::handle(
    const osgGA::GUIEventAdapter &ea
,   osgGA::GUIActionAdapter &)
{
    if(ea.getEventType() == osgGA::GUIEventAdapter::FRAME
    || ea.getEventType() == osgGA::GUIEventAdapter::MOVE)
        return false;

    switch(ea.getEventType())
    {

  case(osgGA::GUIEventAdapter::KEYDOWN):
            {
                if(ea.getKey() == '-'
                || ea.getKey() == '+')
                {
                    const float f = 1.00f
                        + (ea.getKey() == '+' ? +0.004f : -0.004f);

                    if(m_fov * f >= 1.f && m_fov * f <= 179.f)
                        m_fov *= f;

                    emit fovChanged(m_fov);
                }
            }
            break;

    case(osgGA::GUIEventAdapter::SCROLL):
        {
            const float f = 1.00f
                + (ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_DOWN ? -0.08f : +0.08f);

            if(m_fov * f >= 1.f && m_fov * f <= 179.f)
                m_fov *= f;

            emit fovChanged(m_fov);

            return true;
        }
        break;

    case(osgGA::GUIEventAdapter::RELEASE):

        if(ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON
        && (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_CTRL) != 0)
        {
            m_fov = m_fovBackup;
            emit fovChanged(m_fov);

            return true;
        }
        break;

    default:
        break;
    };
    return false;
}
Пример #11
0
    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;
    }
Пример #12
0
MouseButton NoesisEventCallback::convertMouseButton( const osgGA::GUIEventAdapter& ea )
{
    switch ( ea.getButton() )
    {
    case osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON: return MouseButton_Left;
    case osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON: return MouseButton_Middle;
    case osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON: return MouseButton_Right;
    default: break;
    }
    return MouseButton_Left;
}
bool ThirdPersonCameraManipulator::handleMouseRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	if (ea.getButton() == GUIEventAdapter::LEFT_MOUSE_BUTTON)
	{
		osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
		osgUtil::LineSegmentIntersector::Intersections intersections;
		if (view->computeIntersections(ea, intersections ))
		{
			getActivePlayer()->setPosition(intersections.begin()->getWorldIntersectPoint());
		}
	}
	centerMousePointer( ea, aa );
	return false;
}
Пример #14
0
bool GestionEvenements::handle( const osgGA::GUIEventAdapter& ea,
 osgGA::GUIActionAdapter& aa)
{
	switch(ea.getEventType()){
		case osgGA::GUIEventAdapter::KEYDOWN :
		
			switch(ea.getKey()){
				
				case 'a':
					viewer.setCameraManipulator(trackCone.get());
					break;
				case 'z':
					viewer.setCameraManipulator(trackBoite.get());
					break;
				case 'e':
					viewer.setCameraManipulator(trackSphere.get());
					break;
			}
			break;
		
		case osgGA::GUIEventAdapter::PUSH :{
			int x = ea.getX();
			int y = ea.getY();
			if( ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
				std::cout << "bouton gauche" << std::endl;
			if (ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
				std::cout << "bouton milieu" << std::endl;
			if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
				std::cout << "bouton droit" << std::endl;
			break;
 }
		case osgGA::GUIEventAdapter::DOUBLECLICK :
			break;
			}
 return false; // pour que l'événement soit traité par d'autres gestionnaires
}
Пример #15
0
int OscSendingDevice::getButtonNum(const osgGA::GUIEventAdapter& ea)
{
    switch(ea.getButton())
    {
        case osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON:
            return 1;
            break;
        case osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON:
            return 2;
            break;
        case osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON:
            return 3;
            break;
        default:
            return -1;
    }
    return -1;
}
Пример #16
0
bool MouseHandler::handle(
    const osgGA::GUIEventAdapter& gea,
    osgGA::GUIActionAdapter&      gaa,
    osg::Object*                  obj,
    osg::NodeVisitor*             nv
) {
    osgGA::GUIEventAdapter::EventType ev = gea.getEventType();
    MouseAction                       ma = _isMouseEvent(ev);

    if(ma) {
        // If we're scrolling, we need to inform the WindowManager of that.
        _wm->setScrollingMotion(gea.getScrollingMotion());

        return (this->*ma)(gea.getX(), gea.getY(), gea.getButton());
    }
    
    return false;
}
Пример #17
0
bool
GeometrySelector::handle( const osgGA::GUIEventAdapter& ea
                        , osgGA::GUIActionAdapter& aa
                        )
{
    // RECORD_INFO("reaching here");
    osgViewer::View* viewer = dynamic_cast<osgViewer::View*>(&aa);

    if ( !viewer )
    {
        return false;

    }

    bool drag_event_occurred = ea.getEventType() & osgGA::GUIEventAdapter::DRAG;
    bool push_event_occurred = ea.getEventType() & osgGA::GUIEventAdapter::PUSH;
    bool release_event_occurred = ea.getEventType() & osgGA::GUIEventAdapter::RELEASE;
    bool left_mouse_button_pressed = ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON;
    bool ctrl_key_pressed = ea.getModKeyMask() &  osgGA::GUIEventAdapter::MODKEY_CTRL;

    if(left_mouse_button_pressed && push_event_occurred)
    {
        Geometry * geometry = _get_intersection(ea,viewer);
        bool blank_click    = geometry == nullptr;
        if(blank_click)
        {
            id = "";
            selected = false;
            RECORD_INFO("not selected");
        }
        else
        {
            id = geometry -> getName();
            selected = true;
            RECORD_INFO(std::string("Selected") + geometry -> getName() );
        }
    }
    else
    {
        selected = false;
    }
    return false;
}
Пример #18
0
 void write(const osgGA::GUIEventAdapter& event)
 {
     writeUInt(event.getEventType());
     writeUInt(event.getKey());
     writeUInt(event.getButton());
     writeInt(event.getWindowX());
     writeInt(event.getWindowY());
     writeUInt(event.getWindowWidth());
     writeUInt(event.getWindowHeight());
     writeFloat(event.getXmin());
     writeFloat(event.getYmin());
     writeFloat(event.getXmax());
     writeFloat(event.getYmax());
     writeFloat(event.getX());
     writeFloat(event.getY());
     writeUInt(event.getButtonMask());
     writeUInt(event.getModKeyMask());
     writeDouble(event.getTime());
 }
bool ThirdPersonCameraManipulator::handleMousePush( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{

	/// At the moment, OSG doesn't have support for extra mouse buttons, but I plan to add that later, at which point you'll be able to zoom with the forwards and backwards buttons (if you have them)
	switch(ea.getButton())
	{
#ifdef SUPPORTS_EXTRA_MOUSE_BUTTONS
	case osgGA::GUIEventAdapter::FORWARD_MOUSE_BUTTON :
		zoom(_zoomFactor);
		aa.requestRedraw();
		return true;
	case osgGA::GUIEventAdapter::BACKWARD_MOUSE_BUTTON :
		zoom(-_zoomFactor);
		aa.requestRedraw();
		return true;
#endif
	default:
		return false;
	}

	return false;
}
Пример #20
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);
}
Пример #21
0
	bool MouseEventHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) {
		if (ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
			ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
			!(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL))
				return false;
	
		osgViewer::Viewer* viewer= dynamic_cast<osgViewer::Viewer*>(&aa);
		if (viewer) {
			osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector=
			new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY());
			osgUtil::IntersectionVisitor iv(intersector.get());
			// Sólo recorrer aquellos nodos con nodeMask=0x1
			iv.setTraversalMask(~0x1);
			viewer->getCamera()->accept(iv);
			if (intersector->containsIntersections()) {
				//osgUtil::LineSegmentIntersector::Intersection& elegido= *(intersector->getIntersections().begin());
				//orbita= elegido.;
				//std::cout<<"ola k ase\n";
			// Hagamos lo que tengamos que hacer...
			}
		}
		return false;
	}
Пример #22
0
bool
Selector::handle( const osgGA::GUIEventAdapter& ea
                , osgGA::GUIActionAdapter& aa
                )
{
    osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);

    if ( !viewer )
    {
        return false;
    }

    // Geometry * geometry   = _get_intersection(ea,viewer);
    // cout << geometry;
    // bool blank_click      = geometry == nullptr;
    // if(!blank_click)
    // {
    //     RECORD_INFO("Compartment clicked " + geometry -> getName());
    // }
    // else
    // {
    //     // return true;
    //     // RECORD_INFO("Problem");
    // }

    if(select_info -> get_event_type() == 2)
    {
        // RECORD_INFO("Event Type => 2");
        return true;
    }

    // select_info -> set_event_type(0);
    // select_info -> set_id("");

    // if(ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
    // {
    //     RECORD_INFO(to_string(mode));
    //     if(mode == -1)
    //     {
    //         return false;
    //     }
    //     if(mode == 2)
    //     {
    //         menu -> exec(QCursor::pos());
    //     }
    //     if(mode == 3)
    //     {
    //         menu -> exec(QCursor::pos());
    //     }
    //     mode = -1;
    //     return true;
    // }

    // if(ea.getEventType() == osgGA::GUIEventAdapter::DRAG)
    // {
    //     QDrag *drag = new QDrag(this);
    //     // The data to be transferred by the drag and drop operation is contained in a QMimeData object
    //     QMimeData *data = new QMimeData;
    //     data->setText("This is a test");
    //     // Assign ownership of the QMimeData object to the QDrag object.
    //     drag->setMimeData(data);
    //     // Start the drag and drop operation
    //     drag->start();
    // }

    bool drag_event_occurred = ea.getEventType() & osgGA::GUIEventAdapter::DRAG;
    bool push_event_occurred = ea.getEventType() & osgGA::GUIEventAdapter::PUSH;
    bool release_event_occurred = ea.getEventType() & osgGA::GUIEventAdapter::RELEASE;
    bool left_mouse_button_pressed = ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON;
    bool ctrl_key_pressed = ea.getModKeyMask() &  osgGA::GUIEventAdapter::MODKEY_CTRL;

    if(left_mouse_button_pressed && push_event_occurred && ctrl_key_pressed)
    {
        Geometry * geometry = _get_intersection(ea,viewer);
        bool blank_click    = geometry == nullptr;
        if(blank_click)
        {
            _deselect_everything();
            return false;
        }
        else
        {
            _select_compartment(geometry);
            RECORD_INFO("Compartment clicked " + geometry -> getName());
            // viewer -> emit_signal(geometry -> getName());
            select_info -> set_event_type(2);
            select_info -> set_id(geometry -> getName().c_str());
            return true;
        }
        return false;
    }

    if(release_event_occurred && left_mouse_button_pressed)
    {
        Geometry * geometry   = _get_intersection(ea,viewer);
        bool blank_click      = geometry == nullptr;
        bool selection_exists = false; //blank_click ? false : selections.find(geometry -> getName()) == selection.end()
        if(!ctrl_key_pressed)
        {
            if(blank_click)
            {
                _deselect_everything();
            }
            else
            {
                // RECORD_INFO("Select Compartment"); // do nothing
                _select_compartment(geometry);
                select_info -> set_event_type(1);
                select_info -> set_id(geometry -> getName().c_str());
                return true;
            }
        }
        return false;
        // else
        // {
        //     if(blank_click)
        //     {
        //         RECORD_INFO("Deselect Everything."); // do nothing
        //         // _deselect_everything();
        //     }
        //     else if(selection_exists)
        //     {
        //         RECORD_INFO("Select Neuron.");
        //         _select_neuron(geometry);
        //     }
        //     else
        //     {
        //         RECORD_INFO("Select Compartment"); // do nothing
        //         // _deselect_everything();
        //         _select_compartment(geometry);
        //     }
        // }
    }

    // if(ea.getEventType() == osgGA::GUIEventAdapter::PUSH)
    // {
    //     if(ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
    //     {
    //         Geometry * geometry = _get_intersection(ea,viewer);
    //         if(geometry)
    //         {
    //             if
    //             {
    //                 _select_compartment(geometry);
    //                 mode = 0;
    //             }
    //             else
    //             {
    //                 _select_neuron(geometry);
    //                 mode = 1;
    //             }
    //             return true;
    //         }
    //         mode = -1;
    //         return false;
    //     }

    //     if(ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
    //     {
    //         Geometry * geometry = _get_intersection(ea,viewer);
    //         if(geometry)
    //         {
    //             if(ea.getModKeyMask() &  osgGA::GUIEventAdapter::MODKEY_CTRL)
    //             {
    //                 _select_compartment(geometry);
    //                 mode = 2;
    //             }
    //             else
    //             {
    //                 _select_neuron(geometry);
    //                 mode = 3;
    //             }
    //             return true;
    //         }
    //         mode = -1;
    //         return false;
    //     }
    // }
    return false;
}
Пример #23
0
/* virtual */ bool 
av::osg::viewer::InputEventHandler::handle(const ::osgGA::GUIEventAdapter& event, ::osgGA::GUIActionAdapter& action)
{
  logger.trace() << "handle()";

  if (mEventFields->MouseButtonLeftDoubleClick.getValue())
    mEventFields->MouseButtonLeftDoubleClick.setValue(false);
  if (mEventFields->MouseButtonMiddleDoubleClick.getValue())
    mEventFields->MouseButtonMiddleDoubleClick.setValue(false);
  if (mEventFields->MouseButtonRightDoubleClick.getValue())
    mEventFields->MouseButtonRightDoubleClick.setValue(false);
  if (mEventFields->MouseScrollUp.getValue())
    mEventFields->MouseScrollUp.setValue(false);
  if (mEventFields->MouseScrollDown.getValue())
    mEventFields->MouseScrollDown.setValue(false);

  switch(event.getEventType())
  {
    case(::osgGA::GUIEventAdapter::DRAG):
    {
      const ::osg::Vec2 mousePos(event.getX(), event.getY());
      mEventFields->DragEvent.setValue(mousePos);

      break;
    }

    case(::osgGA::GUIEventAdapter::MOVE):
    {
      const ::osg::Vec2 mousePos(event.getX(), event.getY());
      mEventFields->MoveEvent.setValue(mousePos);

      break;
    }

    case(::osgGA::GUIEventAdapter::PUSH):
    case(::osgGA::GUIEventAdapter::RELEASE):
    {
      const unsigned int buttonmask = event.getButtonMask();
      const bool left   = (buttonmask & ::osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) != 0u;
      const bool middle = (buttonmask & ::osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) != 0u;
      const bool right  = (buttonmask & ::osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) != 0u;

      if (mEventFields->MouseButtonLeft.getValue() != left)
        mEventFields->MouseButtonLeft.setValue(left);
      if (mEventFields->MouseButtonMiddle.getValue() != middle)
        mEventFields->MouseButtonMiddle.setValue(middle);
      if (mEventFields->MouseButtonRight.getValue() != right)
        mEventFields->MouseButtonRight.setValue(right);

      if (mEventFields->MouseButtons_OnlyLeft.getValue() != (left && !middle && !right))
        mEventFields->MouseButtons_OnlyLeft.setValue(left && !middle && !right);
      if (mEventFields->MouseButtons_OnlyMiddle.getValue() != (!left && middle && !right))
        mEventFields->MouseButtons_OnlyMiddle.setValue(!left && middle && !right);
      if (mEventFields->MouseButtons_OnlyRight.getValue() != (!left && !middle && right))
        mEventFields->MouseButtons_OnlyRight.setValue(!left && !middle && right);
      if (mEventFields->MouseButtons_LeftAndMiddle.getValue() != (left && middle && !right))
        mEventFields->MouseButtons_LeftAndMiddle.setValue(left && middle && !right);
      if (mEventFields->MouseButtons_LeftAndRight.getValue() != (left && !middle && right))
        mEventFields->MouseButtons_LeftAndRight.setValue(left && !middle && right);
      if (mEventFields->MouseButtons_MiddleAndRight.getValue() != (!left && middle && right))
        mEventFields->MouseButtons_MiddleAndRight.setValue(!left && middle && right);
      if (mEventFields->MouseButtons_LeftAndMiddleAndRight.getValue() != (left && middle && right))
        mEventFields->MouseButtons_LeftAndMiddleAndRight.setValue(left && middle && right);

      break;
    }

    case(::osgGA::GUIEventAdapter::DOUBLECLICK):
    {
      switch (event.getButton())
      {
        case ::osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON:
        {
          mEventFields->MouseButtonLeftDoubleClick.setValue(true);
          break;
        }

        case ::osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON:
        {
          mEventFields->MouseButtonMiddleDoubleClick.setValue(true);
          break;
        }

        case ::osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON:
        {
          mEventFields->MouseButtonRightDoubleClick.setValue(true);
          break;
        }

        default:
          break;
      }

      break;
    }

    case(::osgGA::GUIEventAdapter::SCROLL):
    {
      switch (event.getScrollingMotion())
      {
        case ::osgGA::GUIEventAdapter::SCROLL_UP:
        {
          mEventFields->MouseScrollUp.setValue(true);
          break;
        }

        case ::osgGA::GUIEventAdapter::SCROLL_DOWN:
        {
          mEventFields->MouseScrollDown.setValue(true);
          break;
        }

        default:
          break;
      }

      break;
    }

    case(::osgGA::GUIEventAdapter::KEYDOWN):
    case(::osgGA::GUIEventAdapter::KEYUP):
    {
      const bool pressed = (event.getEventType() == ::osgGA::GUIEventAdapter::KEYDOWN);
      const int key = event.getKey();

      const bool shiftPressed =
        (event.getModKeyMask() & (::osgGA::GUIEventAdapter::MODKEY_LEFT_SHIFT |
                                  ::osgGA::GUIEventAdapter::MODKEY_RIGHT_SHIFT)) != 0u;
      const bool ctrlPressed =
        (event.getModKeyMask() & (::osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL |
                                  ::osgGA::GUIEventAdapter::MODKEY_RIGHT_CTRL)) != 0u;
      const bool altPressed =
        (event.getModKeyMask() & (::osgGA::GUIEventAdapter::MODKEY_LEFT_ALT |
                                  ::osgGA::GUIEventAdapter::MODKEY_RIGHT_ALT)) != 0u;

      if (mEventFields->KeyShift.getValue() != shiftPressed)
        mEventFields->KeyShift.setValue(shiftPressed);
      if (mEventFields->KeyCtrl.getValue() != ctrlPressed)
        mEventFields->KeyCtrl.setValue(ctrlPressed);
      if (mEventFields->KeyAlt.getValue() != altPressed)
        mEventFields->KeyAlt.setValue(altPressed);

      if (pressed)
        mKeys.insert(key);
      else
        mKeys.erase(key);

      std::vector<int> keys(mKeys.size());
      std::copy(mKeys.begin(), mKeys.end(), keys.begin());
      mEventFields->KeysPressed.setValue(keys);

      switch (key)
      {
        case ::osgGA::GUIEventAdapter::KEY_Insert:    mEventFields->KeyInsert.setValue(pressed);   break;
        case ::osgGA::GUIEventAdapter::KEY_Delete:    mEventFields->KeyDelete.setValue(pressed);   break;
        case ::osgGA::GUIEventAdapter::KEY_Home:      mEventFields->KeyHome.setValue(pressed);     break;
        case ::osgGA::GUIEventAdapter::KEY_End:       mEventFields->KeyEnd.setValue(pressed);      break;
        case ::osgGA::GUIEventAdapter::KEY_Page_Up:   mEventFields->KeyPageUp.setValue(pressed);   break;
        case ::osgGA::GUIEventAdapter::KEY_Page_Down: mEventFields->KeyPageDown.setValue(pressed); break;
        case ::osgGA::GUIEventAdapter::KEY_Left:      mEventFields->KeyLeft.setValue(pressed);     break;
        case ::osgGA::GUIEventAdapter::KEY_Right:     mEventFields->KeyRight.setValue(pressed);    break;
        case ::osgGA::GUIEventAdapter::KEY_Up:        mEventFields->KeyUp.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_Down:      mEventFields->KeyDown.setValue(pressed);     break;
        case ::osgGA::GUIEventAdapter::KEY_Escape:    mEventFields->KeyEsc.setValue(pressed);      break;
        case ::osgGA::GUIEventAdapter::KEY_Space:     mEventFields->KeySpace.setValue(pressed);    break;
        case ::osgGA::GUIEventAdapter::KEY_Return:    mEventFields->KeyEnter.setValue(pressed);    break;
        case ::osgGA::GUIEventAdapter::KEY_F1:        mEventFields->KeyF1.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F2:        mEventFields->KeyF2.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F3:        mEventFields->KeyF3.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F4:        mEventFields->KeyF4.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F5:        mEventFields->KeyF5.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F6:        mEventFields->KeyF6.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F7:        mEventFields->KeyF7.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F8:        mEventFields->KeyF8.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F9:        mEventFields->KeyF9.setValue(pressed);       break;
        case ::osgGA::GUIEventAdapter::KEY_F10:       mEventFields->KeyF10.setValue(pressed);      break;
        case ::osgGA::GUIEventAdapter::KEY_F11:       mEventFields->KeyF11.setValue(pressed);      break;
        case ::osgGA::GUIEventAdapter::KEY_F12:       mEventFields->KeyF12.setValue(pressed);      break;

      }

      if (altPressed && key == ::osgGA::GUIEventAdapter::KEY_Return && pressed)
      {
        mEventFields->KeyAltReturn.setValue(true);
      }

      break;
    }

    default:
      break;
  }

  return false;
}
Пример #24
0
bool SelNodeHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	if(!_enable)
		return false;

	switch(ea.getEventType())
	{
	case(osgGA::GUIEventAdapter::PUSH):
		{
			switch(ea.getButton())
			{
			case(osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON):
				{
					osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
					if (!view) return false;

					//////////////////////////////////////////////////////////////////////////

					double mx = ea.getXnormalized();
					double my = ea.getYnormalized();
					double w = 0.05;
					double h = 0.05;
					osgUtil::PolytopeIntersector*  picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::PROJECTION, mx-w, my-h, mx+w, my+h );

					osgUtil::IntersectionVisitor iv(picker);

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

					if (picker->containsIntersections())
					{
						osgUtil::PolytopeIntersector::Intersection intersection = picker->getFirstIntersection();

						osg::NodePath& nodePath = intersection.nodePath;

						osg::NodePath::iterator iter_p = nodePath.begin();
						for(iter_p;iter_p!=nodePath.end();++iter_p)
						{
							owScene::FeatureNode* fn = dynamic_cast<owScene::FeatureNode*>(*iter_p);
							if(fn)
							{
								owScene::Feature* f = fn->getFeature();
								if(f)
								{
									std::cout<<std::endl;
									std::cout<<"Start List FeatureOID: "<<f->getOID()<<" AttributeList: "<<std::endl;
									owScene::AttributeList list = f->getAttributes();
									owScene::AttributeList::iterator iter = list.begin();
									for(iter;iter!=list.end();++iter)
									{
										owScene::Attribute atr = *iter;
										std::cout<<atr.getKey()<<" : "<<atr.asString()<<std::endl;
									}
									std::cout<<"End List FeatureOID: "<<f->getOID()<<" AttributeList: "<<std::endl;
									std::cout<<std::endl;
								}
								break;
							}
						}


					}
					//////////////////////////////////////////////////////////////////////////

					break;
				}
			default:
				break;
			}
			return false;
		}
	default:
		return false;
	}
	return false;
}
Пример #25
0
bool VdsViewEventHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
{
	if (!_eventClass)
		return false;
	int x = ea.getX();
	int y = ea.getY();
	MonoImage* monoImage = NULL;
	MonoClass* eventClass = NULL;
	MonoObject* eventClassObject = NULL;
	MonoMethod*	mousePushMethod = NULL;
	MonoMethod*	mouseReleaseMethod = NULL;
	MonoMethod*	mouseMoveMethod = NULL;
	MonoMethod*	mouseDoubleClickMethod = NULL;
	MonoMethod*	mouseZoomMethod = NULL;
	MonoMethod*	keyDownMethod = NULL;
	MonoMethod*	keyUpMethod = NULL;
	MonoMethod*	layerInSceneChangedMethod = NULL;
	MonoMethod*	gameManagerAddActorEventMethod = NULL;
	MonoMethod*	gameManagerRemoveActorEventMethod = NULL;
	MonoMethod*	gameManagerPlayPlotEventMethod = NULL;
	MonoMethod*	gameManagerStopPlotEventMethod = NULL;
	MonoMethod*	gameManagerPausePlotEventMethod = NULL;
	MonoMethod*	uiEventMethod = NULL;
	{
		OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_pMutex);
		monoImage = _monoImage;
		eventClass = _eventClass;
		eventClassObject = _eventClassObject;
		mousePushMethod = _mousePushMethod;
		mouseReleaseMethod = _mouseReleaseMethod;
		mouseMoveMethod = _mouseMoveMethod;
		mouseDoubleClickMethod = _mouseDoubleClickMethod;
		mouseZoomMethod = _mouseZoomMethod;
		keyDownMethod = _keyDownMethod;
		keyUpMethod = _keyUpMethod;
		layerInSceneChangedMethod = _layerInSceneChangedMethod;
		gameManagerAddActorEventMethod = _gameManagerAddActorEventMethod;
		gameManagerRemoveActorEventMethod = _gameManagerRemoveActorEventMethod;
		gameManagerPlayPlotEventMethod = _gameManagerPlayPlotEventMethod;
		gameManagerStopPlotEventMethod = _gameManagerStopPlotEventMethod;
		gameManagerPausePlotEventMethod = _gameManagerPausePlotEventMethod;
		uiEventMethod = _uiEventMethod;
	}
	switch (ea.getEventType())
	{
	case osgGA::GUIEventAdapter::MOVE:
	{
		if (!mouseMoveMethod)
			mouseMoveMethod = mono_class_get_method_from_name(eventClass, "MouseMoveEvent", 3);
		MonoObject* exception = NULL;
		void* args[3];
		args[0] = &_viewID;
		args[1] = &x;
		args[2] = &y;
		_eventThread = mono_thread_attach(mono_get_root_domain());
		mono_runtime_invoke(mouseMoveMethod, eventClassObject, args, &exception);
		break;
	}
	case osgGA::GUIEventAdapter::PUSH:
	{
		if (!mousePushMethod)
			mousePushMethod = mono_class_get_method_from_name(eventClass, "MouseButtonPressEvent", 4);
		MonoObject* exception = NULL;
		int arg0 = 1;
		void* args[4];
		args[0] = &_viewID;
		if (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
			arg0 = 1;
		else if (ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
			arg0 = 2;
		else if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
			arg0 = 3;
		args[1] = &arg0;
		args[2] = &x;
		args[3] = &y;
		_eventThread = mono_thread_attach(mono_get_root_domain());
		mono_runtime_invoke(mousePushMethod, eventClassObject, args, &exception);
		break;
	}
	case osgGA::GUIEventAdapter::RELEASE:
	{
		if (!mouseReleaseMethod)
			mouseReleaseMethod = mono_class_get_method_from_name(eventClass, "MouseButtonReleaseEvent", 4);
		MonoObject* exception = NULL;
		int arg0 = 1;
		void* args[4];
		args[0] = &_viewID;
		if (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
			arg0 = 1;
		else if (ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
			arg0 = 2;
		else if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
			arg0 = 3;
		args[1] = &arg0;
		args[2] = &x;
		args[3] = &y;
		_eventThread = mono_thread_attach(mono_get_root_domain());
		mono_runtime_invoke(mouseReleaseMethod, eventClassObject, args, &exception);
		break;
	}
	case osgGA::GUIEventAdapter::DOUBLECLICK:
	{
		if (!mouseDoubleClickMethod)
			mouseDoubleClickMethod = mono_class_get_method_from_name(eventClass, "MouseDoubleClickEvent", 4);
		MonoObject* exception = NULL;
		int arg0 = 1;
		void* args[4];
		args[0] = &_viewID;
		if (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
			arg0 = 1;
		else if (ea.getButton() == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
			arg0 = 2;
		else if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
			arg0 = 3;
		args[1] = &arg0;
		args[2] = &x;
		args[3] = &y;
		_eventThread = mono_thread_attach(mono_get_root_domain());
		mono_runtime_invoke(mouseDoubleClickMethod, eventClassObject, args, &exception);
		break;
	}
	case osgGA::GUIEventAdapter::KEYDOWN:
	{
		if (!keyDownMethod)
			keyDownMethod = mono_class_get_method_from_name(eventClass, "KeyboardDownEvent", 2);
		MonoObject* exception = NULL;
		void* args[2];
		args[0] = &_viewID;
		int keyValue = ea.getKey();
		args[1] = &keyValue;
		_eventThread = mono_thread_attach(mono_get_root_domain());
		mono_runtime_invoke(keyDownMethod, eventClassObject, args, &exception);
		break;
	}
	case osgGA::GUIEventAdapter::KEYUP:
	{
		if (!keyUpMethod)
			keyUpMethod = mono_class_get_method_from_name(eventClass, "KeyboardUpEvent", 2);
		MonoObject* exception = NULL;
		void* args[2];
		args[0] = &_viewID;
		int keyValue = ea.getKey();
		args[1] = &keyValue;
		_eventThread = mono_thread_attach(mono_get_root_domain());
		mono_runtime_invoke(keyUpMethod, eventClassObject, args, &exception);
		break;
	}
	case osgGA::GUIEventAdapter::SCROLL:
	{
		if (!mouseZoomMethod)
			mouseZoomMethod = mono_class_get_method_from_name(eventClass, "MouseZoomEvent", 2);
		MonoObject* exception = NULL;
		void* args[2];
		args[0] = &_viewID;
		osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();
		int zoomValue = 0;
		if (sm == osgGA::GUIEventAdapter::SCROLL_DOWN)
			zoomValue = 1;
		args[1] = &zoomValue;
		_eventThread = mono_thread_attach(mono_get_root_domain());
		mono_runtime_invoke(mouseZoomMethod, eventClassObject, args, &exception);
		break;
	}
	case osgGA::GUIEventAdapter::USER:
	{
		osg::ref_ptr<osg::Referenced> userData = const_cast<osg::Referenced*>(ea.getUserData());
		UserEventData* data = static_cast<UserEventData*>(userData.get());
		switch (data->_eventType)
		{
		case UserEventData::LAYERCHANGED:
		{
			if (!layerInSceneChangedMethod)
				layerInSceneChangedMethod = mono_class_get_method_from_name(eventClass, "LayerInSceneChangedEvent", 1);
			MonoObject* exception = NULL;
			void* args[1];
			args[0] = &_viewID;
			_eventThread = mono_thread_attach(mono_get_root_domain());
			mono_runtime_invoke(layerInSceneChangedMethod, eventClassObject, args, &exception);
			break;
		}
		case UserEventData::UI_EVENT:
		{
			if (!uiEventMethod)
				uiEventMethod = mono_class_get_method_from_name(eventClass, "UIEvent", 3);
			void* widthData = data->_data;
			std::vector<std::string>* dList = (std::vector<std::string>*)widthData;
			MonoDomain* domain = mono_object_get_domain(eventClassObject);
			MonoObject* exception = NULL;
			void* args[3];
			args[0] = &_viewID;
			args[1] = mono_string_new(domain, dList->at(0).c_str());
			args[2] = mono_string_new(domain, dList->at(1).c_str());
			_eventThread = mono_thread_attach(mono_get_root_domain());
			mono_runtime_invoke(uiEventMethod, eventClassObject, args, &exception);
			break;
		}
		case UserEventData::GAMEMANAGER_ACTORADD:
		{
			if (!gameManagerAddActorEventMethod)
				gameManagerAddActorEventMethod = mono_class_get_method_from_name(eventClass, "GameLayerAddActorEvent", 2);
			MonoDomain* domain = mono_object_get_domain(eventClassObject);
			MonoObject* exception = NULL;
			void* args[2];
			args[0] = &_viewID;
			args[1] = mono_string_new(domain, dynamic_cast<VirtualDataSceneBase::ActorBase*>(data->_eventObject.get())->getId().c_str());
			_eventThread = mono_thread_attach(mono_get_root_domain());
			mono_runtime_invoke(gameManagerAddActorEventMethod, eventClassObject, args, &exception);
			break;
		}
		case UserEventData::GAMEMANAGER_ACTORREMOVE:
		{
			if (!gameManagerRemoveActorEventMethod)
				gameManagerRemoveActorEventMethod = mono_class_get_method_from_name(eventClass, "GameLayerRemoveActorEvent", 2);
			MonoDomain* domain = mono_object_get_domain(eventClassObject);
			MonoObject* exception = NULL;
			void* args[2];
			args[0] = &_viewID;
			args[1] = mono_string_new(domain, dynamic_cast<VirtualDataSceneBase::ActorBase*>(data->_eventObject.get())->getId().c_str());
			_eventThread = mono_thread_attach(mono_get_root_domain());
			mono_runtime_invoke(gameManagerRemoveActorEventMethod, eventClassObject, args, &exception);
			break;
		}
		case UserEventData::GAMEMANAGER_PLAYPLOT:
		{
			if (!gameManagerPlayPlotEventMethod)
				gameManagerPlayPlotEventMethod = mono_class_get_method_from_name(eventClass, "PlayPlotScriptEvent", 3);
			void* widthData = data->_data;
			std::vector<std::string>* dList = (std::vector<std::string>*)widthData;
			MonoDomain* domain = mono_object_get_domain(eventClassObject);
			MonoObject* exception = NULL;
			void* args[3];
			args[0] = &_viewID;
			args[1] = mono_string_new(domain, dList->at(0).c_str());
			args[2] = mono_string_new(domain, dList->at(1).c_str());
			_eventThread = mono_thread_attach(mono_get_root_domain());
			mono_runtime_invoke(gameManagerPlayPlotEventMethod, eventClassObject, args, &exception);
			break;
		}
		case UserEventData::GAMEMANAGER_STOPPLOT:
		{
			if (!gameManagerStopPlotEventMethod)
				gameManagerStopPlotEventMethod = mono_class_get_method_from_name(eventClass, "StopPlotScriptEvent", 2);
			MonoDomain* domain = mono_object_get_domain(eventClassObject);
			MonoObject* exception = NULL;
			void* args[2];
			args[0] = &_viewID;
			args[1] = mono_string_new(domain, dynamic_cast<VirtualDataSceneBase::ActorBase*>(data->_eventObject.get())->getId().c_str());
			_eventThread = mono_thread_attach(mono_get_root_domain());
			mono_runtime_invoke(gameManagerStopPlotEventMethod, eventClassObject, args, &exception);
			break;
		}
		case UserEventData::GAMEMANAGER_PAUSEPLOT:
		{
			if (!gameManagerPausePlotEventMethod)
				gameManagerPausePlotEventMethod = mono_class_get_method_from_name(eventClass, "PausePlotScriptEvent", 2);
			MonoDomain* domain = mono_object_get_domain(eventClassObject);
			MonoObject* exception = NULL;
			void* args[2];
			args[0] = &_viewID;
			args[1] = mono_string_new(domain, dynamic_cast<VirtualDataSceneBase::ActorBase*>(data->_eventObject.get())->getId().c_str());
			_eventThread = mono_thread_attach(mono_get_root_domain());
			mono_runtime_invoke(gameManagerPausePlotEventMethod, eventClassObject, args, &exception);
			break;
		}
		default:
			break;
		}
		break;
	}
	case osgGA::GUIEventAdapter::CLOSE_WINDOW:
	case osgGA::GUIEventAdapter::QUIT_APPLICATION:
	{
		//mono_thread_detach(_eventThread);
		break;
	}
	default:
		break;
	}
	return false;
}
Пример #26
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;
}
Пример #27
0
bool LaunchHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& )
{
    // We want a shift-leftmouse event. Return false if we don't have it.
    if( ( ea.getEventType() != osgGA::GUIEventAdapter::PUSH ) ||
        ( ea.getButton() != osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) ||
        ( ( ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_SHIFT ) == 0 ) )
        return( false );

    osg::Matrix view = _camera->getViewMatrix();
    osg::Vec3 look, at, up;
    view.getLookAt( look, at, up );

    osg::Matrix proj = _camera->getProjectionMatrix();
    double fovy, aspect, zNear, zFar;
    proj.getPerspective( fovy, aspect, zNear, zFar );

    view.invert( view );
    proj.invert( proj );
    osg::Vec4 clip( ea.getXnormalized() * zFar, ea.getYnormalized() * zFar, zFar, zFar );
    osg::Vec4 wc = clip * proj * view;

    const osg::Vec3 launchPos = look + ( up * ( _launchModel->getBound()._radius * 2. ) );

    osg::Matrix parentTrans = osg::Matrix::translate( launchPos );
    osg::Vec3 launchDir = osg::Vec3( wc[0], wc[1], wc[2] ) - launchPos;
    launchDir.normalize();

    osg::ref_ptr< osgwTools::AbsoluteModelTransform > amt = new osgwTools::AbsoluteModelTransform;
    amt->setDataVariance( osg::Object::DYNAMIC );
    amt->addChild( _launchModel.get() );

    _attachPoint->addChild( amt.get() );
    _nodeList.push_back( amt.get() );

    osg::ref_ptr< osgbDynamics::CreationRecord > cr = new osgbDynamics::CreationRecord;
    cr->_sceneGraph = amt.get();
    cr->_mass = 1.;
    cr->_parentTransform = parentTrans;
    btRigidBody* rb = osgbDynamics::createRigidBody( cr.get(), _launchCollisionShape );
    rb->setLinearVelocity( osgbCollision::asBtVector3( launchDir * _initialVelocity ) );
    rb->setAngularVelocity( btVector3( .2, .3, 1.5 ) );

    osgbDynamics::MotionState* motion = static_cast< osgbDynamics::MotionState* >( rb->getMotionState() );
    if( _tb != NULL )
        motion->registerTripleBuffer( _tb );
    if( _msl != NULL )
        _msl->insert( motion );

    if( _pt != NULL )
        _pt->pause( true );

    bool added( false );
    amt->setUserData( new osgbCollision::RefRigidBody( rb ) );
    if( (_group != 0) || (_mask != 0) )
    {
        // Collision filters were specified. Get the discrete dynamics world.
        btDiscreteDynamicsWorld* ddw = dynamic_cast< btDiscreteDynamicsWorld* >( _dw );
        if( ddw != NULL )
        {
            ddw->addRigidBody( rb, _group, _mask );
            added = true;
        }
    }
    if( !added )
    {
        // This is both the main path for not using collision filters, and
        // also the fallback if the btDiscreteDynamicsWorld* dynamic cast fails.
        _dw->addRigidBody( rb );
    }

    if( _pt != NULL )
        _pt->pause( false );

    return( true );
}
Пример #28
0
bool MYGUIHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	static bool terminalOn = false;
	static bool CTRLpressed = false;
	static bool cameraMaskCaptured = false;
	static unsigned cameraMask = 0x0;
	static bool on = false;

    int width = ea.getWindowWidth(), height = ea.getWindowHeight();
	width = osg::minimum(width, (int)_screenWidth);
    switch ( ea.getEventType() )
    {
    case osgGA::GUIEventAdapter::RESIZE:
        if ( _camera.valid() )
        {
            _camera->setProjectionMatrix( osg::Matrixd::ortho2D(0.0, width, 0.0, height) );
            _camera->setViewport( 0.0, 0.0, width, height );
        }
		break;
	case osgGA::GUIEventAdapter::PUSH:
		if (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON && CTRLpressed)
		{
			osgUtil::LineSegmentIntersector::Intersections intersections;
			if (_ig->getViewer()->getView(0)->computeIntersections(ea, intersections))
			{
				osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
				if (hitr != intersections.end())
				{
					osg::Vec3d intersection = hitr->getWorldIntersectPoint();

					_manager->setIntersectionPoint(intersection);
				}
			}
		}
		break;
	case osgGA::GUIEventAdapter::KEYUP:
		if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L)
		{
			CTRLpressed = false;
			_manager->setOverallAlpha(0.8);
		}
		break;
	case osgGA::GUIEventAdapter::KEYDOWN:
		if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L)
		{
			CTRLpressed = true;
			_manager->setOverallAlpha(0.05);
		}

		if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F8)
		{
			terminalOn = !terminalOn;
		}

		if (ea.getKey() == osgGA::GUIEventAdapter::KEY_F9 || ea.getKey() == osgGA::GUIEventAdapter::KEY_F12)
		{
			on = !on;
			switch (on)
			{
			case true:
				_camera->setNodeMask(0xFFFFFFFF);
				_cameraManipulator = _ig->getViewer()->getView(0)->getCameraManipulator();
				_ig->getViewer()->getView(0)->setCameraManipulator(0);
				break;
			case false:
				_camera->setNodeMask(0x0);
				_ig->getViewer()->getView(0)->setCameraManipulator(_cameraManipulator,false);
				break;
			}
		}
		break;
    default:
        break;
    }

	if (CTRLpressed) return false;
	if (terminalOn) return false;
    
    // As MyGUI handle all events within the OpenGL context, we have to record the event here
    // and process it later in the draw implementation
    if ( ea.getEventType()!=osgGA::GUIEventAdapter::FRAME )
        _manager->pushEvent( &ea );
    return false;
}
Пример #29
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;
    }
Пример #30
0
bool PickModelHandler::handle(const osgGA::GUIEventAdapter& ea,
								osgGA::GUIActionAdapter& aa){
		osg::ref_ptr<osgViewer::View> view=dynamic_cast<osgViewer::View*>(&aa);
		if(!view)return false;
		switch(ea.getEventType()){
		case osgGA::GUIEventAdapter::DOUBLECLICK:
			{
				if(ea.getButton()==1){
					osgUtil::LineSegmentIntersector::Intersections hits;

					if(view->computeIntersections(ea.getX(),ea.getY(),hits)){
						osgUtil::LineSegmentIntersector::Intersection intersection = *hits.begin();
						osg::NodePath& nodePath = intersection.nodePath;

						node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
						parent = (nodePath.size()>=2)?dynamic_cast<osg::MatrixTransform*>(nodePath[nodePath.size()-2]):0;
						
						if(parent.get()&&node.get()){//如果node是一个模型零件,那么parent应该是一个selection类型节点
							selections = manager->getConnectedSelections(*dragger);
							if(!selections.empty()){
								selection = selections.front();
								if(node->getName()==selection->getChild(0)->getName()){
									manager->disconnect(*dragger);
									root->removeChild(dragger);
									break;
								}
							}
							float scale=node->getBound().radius()*1.2;
							manager->disconnect(*dragger);
							dragger->setupDefaultGeometry();
							dragger->setName("dragger");
							dragger->setMatrix(osg::Matrix::scale(scale,scale,scale)*
												osg::Matrix::translate(parent->getBound().center()));
							
							root->addChild(dragger.get());
							manager->connect(*dragger,*parent);
						}
					}else{
						manager->disconnect(*dragger);
						root->removeChild(dragger);
					}
				}
			}
			break;
		case osgGA::GUIEventAdapter::PUSH:
			{
				_pointer.reset();
				osgUtil::LineSegmentIntersector::Intersections hits;
				if(view->computeIntersections(ea.getX(),ea.getY(),hits)){
					_pointer.setCamera(view->getCamera());
					_pointer.setMousePosition(ea.getX(),ea.getY());
					osgUtil::LineSegmentIntersector::Intersections::iterator hitr;
					for(hitr=hits.begin();hitr!=hits.end();++hitr){
						_pointer.addIntersection(hitr->nodePath,
							hitr->getLocalIntersectPoint());
					}
					osg::NodePath::iterator itr;
					for(itr=_pointer._hitList.front().first.begin();
						itr!=_pointer._hitList.front().first.end();++itr){
						dragger_pick=dynamic_cast<osgManipulator::Dragger*>(*itr);
						if(dragger){
							dragger->handle(_pointer,ea,aa);
							_activeDragger=dragger;
							break;
						}
					}
				}
				break;
			}
		case osgGA::GUIEventAdapter::DRAG:
		case osgGA::GUIEventAdapter::RELEASE:
			{
				if(_activeDragger){
					_pointer._hitIter=_pointer._hitList.begin();
					_pointer.setCamera(view->getCamera());
					_pointer.setMousePosition(ea.getX(),ea.getY());
					_activeDragger->handle(_pointer,ea,aa);
				}
				if(ea.getEventType()==osgGA::GUIEventAdapter::RELEASE){
					_activeDragger=NULL;
					_pointer.reset();
				}
				break;
			}
		default:break;
		}
		return true;
}