int PoseTool::processMouseEvent( ViewportMouseEvent& event )
{
    int flags = 0;

    if( event.leftDown() )
    {
        ROS_ASSERT( state_ == Position );

        Ogre::Vector3 intersection;
        Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0.0f );
        if( getPointOnPlaneFromWindowXY( event.viewport,
                                         ground_plane,
                                         event.x, event.y, intersection ))
        {
            pos_ = intersection;
            arrow_->setPosition( pos_ );

            state_ = Orientation;
            flags |= Render;
        }
    }
    else if( event.type == QEvent::MouseMove && event.left() )
    {
        if( state_ == Orientation )
        {
            //compute angle in x-y plane
            Ogre::Vector3 cur_pos;
            Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0.0f );
            if( getPointOnPlaneFromWindowXY( event.viewport,
                                             ground_plane,
                                             event.x, event.y, cur_pos ))
            {
                double angle = atan2( cur_pos.y - pos_.y, cur_pos.x - pos_.x );

                arrow_->getSceneNode()->setVisible( true );

                //we need base_orient, since the arrow goes along the -z axis by default (for historical reasons)
                Ogre::Quaternion orient_x = Ogre::Quaternion( Ogre::Radian(-Ogre::Math::HALF_PI), Ogre::Vector3::UNIT_Y );

                arrow_->setOrientation( Ogre::Quaternion( Ogre::Radian(angle), Ogre::Vector3::UNIT_Z ) * orient_x );

                flags |= Render;
            }
        }
    }
    else if( event.leftUp() )
    {
        if( state_ == Orientation )
        {
            //compute angle in x-y plane
            Ogre::Vector3 cur_pos;
            Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0.0f );
            if( getPointOnPlaneFromWindowXY( event.viewport,
                                             ground_plane,
                                             event.x, event.y, cur_pos ))
            {
                double angle = atan2( cur_pos.y - pos_.y, cur_pos.x - pos_.x );

                onPoseSet(pos_.x, pos_.y, angle);

                flags |= (Finished|Render);
            }
        }
    }

    return flags;
}
void InteractiveMarkerControl::handleMouseEvent( ViewportMouseEvent& event )
{
  // * check if this is just a receive/lost focus event
  // * try to hand over the mouse event to the parent interactive marker
  // * otherwise, execute mouse move handling

  // handle receive/lose focus
  if( event.type == QEvent::FocusIn )
  {
    has_focus_ = true;
    std::set<Ogre::Pass*>::iterator it;
    setHighlight( HOVER_HIGHLIGHT );
    event.panel->setCursor( cursor_ );
  }
  else if( event.type == QEvent::FocusOut )
  {
    has_focus_ = false;
    setHighlight(0.0);
    return;
  }

  // change dragging state
  switch( interaction_mode_ )
  {
  case visualization_msgs::InteractiveMarkerControl::BUTTON:
    if( event.leftUp() )
    {
      Ogre::Vector3 point_rel_world;
      bool got_3D_point = context_->getSelectionManager()->get3DPoint( event.viewport, event.x, event.y, point_rel_world );

      visualization_msgs::InteractiveMarkerFeedback feedback;
      feedback.event_type = visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK;
      feedback.control_name = name_;
      feedback.marker_name = parent_->getName();
      parent_->publishFeedback( feedback, got_3D_point, point_rel_world );
    }
    break;

  case visualization_msgs::InteractiveMarkerControl::MOVE_AXIS:
  case visualization_msgs::InteractiveMarkerControl::MOVE_PLANE:
  case visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE:
  case visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS:
    if( event.leftDown() )
    {
      parent_->startDragging();
      dragging_ = true;
      drag_viewport_ = event.viewport;

      recordDraggingInPlaceEvent( event );
      if( ! context_->getSelectionManager()->get3DPoint( event.viewport, event.x, event.y, grab_point_ ))
      {
        // If we couldn't get a 3D point for the grab, just use the
        // current relative position of the control frame.
        grab_point_ = control_frame_node_->getPosition();
      }
      else
      {
        // If we could get a 3D point for the grab, convert it from
        // the world frame to the reference frame (in case those are different).
        grab_point_ = reference_node_->convertWorldToLocalPosition(grab_point_);
      }
      grab_pixel_.x = event.x;
      grab_pixel_.y = event.y;
      parent_position_at_mouse_down_ = parent_->getPosition();
      parent_orientation_at_mouse_down_ = parent_->getOrientation();

      if( orientation_mode_ == visualization_msgs::InteractiveMarkerControl::VIEW_FACING &&
          drag_viewport_ )
      {
        updateControlOrientationForViewFacing( drag_viewport_ );
      }
      control_frame_orientation_at_mouse_down_ = control_frame_node_->getOrientation();
      rotation_at_mouse_down_ = rotation_;

      rotation_axis_ = control_frame_node_->getOrientation() * control_orientation_.xAxis();

      // Find rotation_center = 3D point closest to grab_point_ which is
      // on the rotation axis, relative to the reference frame.
      Ogre::Vector3 rotation_center_rel_ref = closestPointOnLineToPoint( parent_->getPosition(),
                                                                         rotation_axis_,
                                                                         grab_point_ );
      Ogre::Matrix4 reference_rel_control_frame;
      reference_rel_control_frame.makeInverseTransform( control_frame_node_->getPosition(),
                                                        Ogre::Vector3::UNIT_SCALE,
                                                        control_frame_node_->getOrientation() );
      rotation_center_rel_control_ = reference_rel_control_frame * rotation_center_rel_ref;
      grab_point_rel_control_ = reference_rel_control_frame * grab_point_;
    }
    if( event.leftUp() )
    {
      dragging_ = false;
      drag_viewport_ = NULL;
      parent_->stopDragging();
    }
    break;

  default:
    break;
  }

  if( event.leftDown() )
  {
    setHighlight( ACTIVE_HIGHLIGHT );
  }
  else if( event.leftUp() )
  {
    setHighlight( HOVER_HIGHLIGHT );
  }

  if (!parent_->handleMouseEvent(event, name_))
  {
    if( event.type == QEvent::MouseMove && event.left() )
    {
      recordDraggingInPlaceEvent( event );
      handleMouseMovement( event );
    }
  }
}
Beispiel #3
0
int SelectionTool::processMouseEvent( ViewportMouseEvent& event )
{
  SelectionManager* sel_manager = context_->getSelectionManager();

  int flags = 0;

  if( event.alt() )
  {
    moving_ = true;
    selecting_ = false;
  }
  else
  {
    moving_ = false;

    if( event.leftDown() )
    {
      selecting_ = true;

      sel_start_x_ = event.x;
      sel_start_y_ = event.y;
    }
  }

  if( selecting_ )
  {
    sel_manager->highlight( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y );

    if( event.leftUp() )
    {
      SelectionManager::SelectType type = SelectionManager::Replace;

      M_Picked selection;

      if( event.shift() )
      {
        type = SelectionManager::Add;
      }
      else if( event.control() )
      {
        type = SelectionManager::Remove;
      }

      sel_manager->select( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y, type );

      selecting_ = false;
    }

    flags |= Render;
  }
  else if( moving_ )
  {
    sel_manager->removeHighlight();

    flags = move_tool_->processMouseEvent( event );

    if( event.type == QEvent::MouseButtonRelease )
    {
      moving_ = false;
    }
  }
  else
  {
    sel_manager->highlight( event.viewport, event.x, event.y, event.x, event.y );
  }

  return flags;
}
int ImageSelectionToolCustom::processMouseEvent( ViewportMouseEvent& event )
{
    //SelectionManager* sel_manager = context_->getSelectionManager();
    Q_EMIT mouseHasMoved(event.x, event.y);
    int flags = 0;

    moving_ = false;

    if( event.leftDown() )
    {
        selecting_ = true;

        sel_start_x_ = event.x;
        sel_start_y_ = event.y;
    }

    if( selecting_ )
    {
        /**std::cout<<"tool selected x1 " <<sel_start_x_<<std::endl;
        std::cout<<"tool selected y1 " <<sel_start_y_<<std::endl;
        std::cout<<"tool selected x2 " <<event.x<<std::endl;
        std::cout<<"selected y2 " <<event.y<<std::endl;**/
        theX1 = sel_start_x_;
        theX2 = event.x;
        theY1 = sel_start_y_;
        theY2 = event.y;
        port = event.viewport;
        highlight( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y );


        if( event.leftUp() )
        {
            SelectionManager::SelectType type = SelectionManager::Replace;

            M_Picked selection;

            /*if( event.shift() )
            {
            type = SelectionManager::Add;
            }
            else if( event.control() )
            {
            type = SelectionManager::Remove;
            }*/

            //sel_manager->select( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y, type );
            removeHighlight();

            Q_EMIT select( sel_start_x_, sel_start_y_, event.x, event.y );

            selecting_ = false;
        }

        flags |= Render;
    }
    else
    {
        highlight( event.viewport, theX1, theY1, theX2, theY2 );
    }

    return flags;
}