void myMouseCB(void *userData, SoEventCallback *eventCB) { const SoEvent *event = eventCB->getEvent(); SoSeparator * scenegraph = (SoSeparator*) userData; if (SO_MOUSE_PRESS_EVENT(event, BUTTON2)) { std::cout << "mouse button 2" << std::endl; if (global_render_manager) { // attempting raypick in the event_cb() callback method SoRayPickAction rp( global_render_manager->getViewportRegion() ); rp.setPoint(event->getPosition()); rp.setPickAll(true); std::cout << "event position: " << event->getPosition()[0] << " " << event->getPosition()[1] << std::endl; rp.apply(global_render_manager->getSceneGraph()); const SoPickedPointList& pickedPoints = rp.getPickedPointList(); std::cout << "# of picked points: " << pickedPoints.getLength() << std::endl; for (int i=0; i<pickedPoints.getLength(); ++i) { SoPickedPoint * pickedPoint = pickedPoints[i]; SbVec3f point = pickedPoint->getPoint(); std::cout << "point " << i << " : " << point[0] << " " << point[1] << " " << point[2] << std::endl; } } eventCB->setHandled(); } else if (SO_MOUSE_PRESS_EVENT(event, BUTTON1)) { //std::cout << "mouse button 1" << std::endl; eventCB->setHandled(); } else if (SO_MOUSE_PRESS_EVENT(event, BUTTON3)) { //std::cout << "mouse button 3" << std::endl; eventCB->setHandled(); } }
int SoXipSegmentationOverlayManager::SetupOverlayAction ( SoHandleEventAction* action, SoXipShape *pshape ) { // Maximal distance between two consecutive mouse down positions // allowed to generate a double-click. int DoubleClickMaxJump = 2; // Maximal time between two mouse clicks to be considered as a // double-click. SbTime DoubleClickTime = SbTime(0.5); // Time corresponding to a click SbTime ClickTime = SbTime(0.1); if (pshape == NULL) return ( 0 ) ; const SbString& classname = shapeClassName.getValue(); char *szName = (char*)classname.getString () ; if (szName == NULL) return ( 0 ) ; SoDebugError::postInfo ( szName, "test" ) ; SbVec3f pos; const SbVec2s& mousePosition = action->getEvent()->getPosition() ; //if( SO_MOUSE_RELEASE_EVENT( action->getEvent(), BUTTON1 ) && action->getGrabber() == this ) if( SO_MOUSE_RELEASE_EVENT( action->getEvent(), BUTTON1 )) { SoDebugError::postInfo ( szName, "test" ) ; mMouseUpTime = action->getEvent()->getTime(); { } } else if( SO_MOUSE_PRESS_EVENT( action->getEvent(), BUTTON1 ) ) { SbTime tim = action->getEvent()->getTime(); // Compute the distance between the last mouse press event and this one SbVec2s v = (mMouseDownPos - mousePosition); float mouseJump = sqrtf( v.dot(v) ); // Do not perform a double-click if the time between two mouse press // events is higher than the default time set for double-clicks, or if // the mouse jumped further than the tolerance set (without tolerance // it is more difficult to get a double-click. if ( (tim - mMouseDownTime) < DoubleClickTime && mouseJump < DoubleClickMaxJump ) { mMouseDownTime = SbTime::zero(); mMouseDownPos = SbVec2s(-1, -1); } else { mMouseDownTime = action->getEvent()->getTime() ; } } return ( 1 ) ; }
void UMDSoMeasureTool::mousePressedCB(void* userData, SoEventCallback* eventCB) { // Wird die linke Maustaste gedrueckt, so wird der getroffene Punkt ermittelt; // getPickedObject wird von der Unterklasse separat implementiert const SoEvent* event = eventCB->getEvent(); UMDSoMeasureTool* obj = (UMDSoMeasureTool*) userData; // linke Maustaste if (SO_MOUSE_PRESS_EVENT(event, BUTTON1)) { //std::cout << " UMDSoMeasureTool::mousePressedCB::leftButton" << std::endl; if (obj->getPickedObjectMouseLeft(eventCB->getPickedPoint())) eventCB->setHandled(); } // mittlere Maustaste // alle Pfeile werden deselektiert if (SO_MOUSE_PRESS_EVENT(event, BUTTON2)) { obj->resetHighLightNode(_currentTool); obj->_currentTool = NULL; } }
void SoXipMenuBase::handleEvent( SoHandleEventAction* action ) { if( on.getValue() == FALSE ) return ; if( action->isHandled() || action->getGrabber() != this ) return ; const SoEvent* event = action->getEvent(); if( !event ) return ; int pickedItem; if( SO_MOUSE_PRESS_EVENT( action->getEvent(), BUTTON1 ) && action->getGrabber() == this ) { action->setHandled(); } else if( SO_MOUSE_RELEASE_EVENT( action->getEvent(), BUTTON1 ) && action->getGrabber() == this ) { if( getPickedItem( action, pickedItem ) && getItem( pickedItem )->isEnabled() ) { itemClicked.setValue( pickedItem ); } on.setValue( FALSE ); action->setHandled(); action->releaseGrabber(); } else if( event->isOfType( SoLocation2Event::getClassTypeId() ) ) { mActionNode = action->getNodeAppliedTo(); if( getPickedItem( action, pickedItem ) ) { itemFocused.setValue( pickedItem ); action->setHandled(); } } }
void SoXipDicomExaminer::handleEvent( SoHandleEventAction* action ) { // Set the Dicom Element setElement( action ); // Call base class first SoXipKit::handleEvent( action ); if( action->isHandled() ) return ; // Save the view information (so we can have access to it // while the event is grabbed) saveViewInformation( action ); const SoEvent* event = action->getEvent(); if( !event ) return ; if( mode.getValue() == NONE ) return ; if( SO_MOUSE_PRESS_EVENT( event, BUTTON1 ) ) { // Stop the animation as soon as we get a mouse down event stopAnimation(); mLastMousePosition = event->getNormalizedPosition( mViewport ); action->setHandled(); action->setGrabber( this ); mPan = SbBox2f(0.2, 0.2, 0.8, 0.8).intersect( mLastMousePosition ); } else if( event->isOfType( SoLocation2Event::getClassTypeId() ) ) { SbVec2f mousePos = event->getNormalizedPosition( mViewport ); if( action->getGrabber() != this ) { if( mousePos[0] >= 0 && mousePos[0] <= 1.f && mousePos[1] >= 0 && mousePos[1] <= 1.f ) { if( mode.getValue() == SHIFT ) { SoXipCursor::setCursor( "SHIFT" ); } else if( mode.getValue() == SCROLL ) { SoXipCursor::setCursor( "SCROLL" ); } else if( mode.getValue() == SHIFTSCROLL ) { SoXipCursor::setCursor( "SHIFTSCROLL" ); } else if( mode.getValue() == PANZOOM ) { SbBox2f panBox( 0.2, 0.2, 0.8, 0.8 ); if( panBox.intersect( event->getNormalizedPosition( mViewport ) ) ) SoXipCursor::setCursor( "SEL_PAN" ); else SoXipCursor::setCursor( "SEL_ZOOM" ); } action->setHandled(); } } else if( mode.getValue() == PANZOOM ) { if( mPan ) { // The user starts dragging in the center of the image // Apply a translation to the view matrix // SbVec3f pos1 = mPlaneProj.project( mousePos ); SbVec3f pos2 = mPlaneProj.project( mLastMousePosition ); getCamera()->position.setValue( getCamera()->position.getValue() - pos1 + pos2 ); mLastMousePosition = mousePos; SoXipCursor::setCursor( "SEL_PAN" ); } else { // The user starts dragging from the view border // Apply a zoom factor to the image // getCamera()->scaleHeight( 1.f + ( mLastMousePosition[1] - mousePos[1] ) ); mLastMousePosition = mousePos; SoXipCursor::setCursor( "SEL_ZOOM" ); } action->setHandled(); } else if( mode.getValue() == SHIFT || mode.getValue() == SCROLL || mode.getValue() == SHIFTSCROLL ) { float hStep = 0; float vStep = 0; if( mode.getValue() == SHIFT || mode.getValue() == SHIFTSCROLL ) { vStep = ( mousePos[1] - mLastMousePosition[1] ) * (float) mViewport.getViewportSizePixels()[1] / 60.; } if( mode.getValue() == SCROLL || mode.getValue() == SHIFTSCROLL ) { hStep = ( mousePos[0] - mLastMousePosition[0] ) * (float) mViewport.getViewportSizePixels()[0] / 60.; } // Change in direction: stop if( mAnimateVStep < 0 && vStep > 0 || mAnimateVStep > 0 && vStep < 0 || mAnimateHStep < 0 && hStep > 0 || mAnimateHStep > 0 && hStep < 0 ) { // Change in direction: stop stopAnimation(); mAnimateChange = 10; } else { if( mAnimateVStep == 0 && mAnimateHStep == 0 ) { if( mAnimateChange <= 0 ) { // Start new shift startAnimation( hStep, vStep ); } else -- mAnimateChange; } else { // Speed up a little mAnimateHStep += hStep; mAnimateVStep += vStep; } } mLastMousePosition = mousePos; action->setHandled(); if( mode.getValue() == SHIFT ) SoXipCursor::setCursor( "SHIFT" ); else if( mode.getValue() == SCROLL ) SoXipCursor::setCursor( "SCROLL" ); else if( mode.getValue() == SHIFTSCROLL ) SoXipCursor::setCursor( "SHIFTSCROLL" ); } } else if( SO_MOUSE_RELEASE_EVENT( event, BUTTON1 ) && action->getGrabber() == this ) { stopAnimation(); action->releaseGrabber(); action->setHandled(); } }
void SoXipOverlayTransformBoxManip::handleEvent( SoHandleEventAction* action ) { if( !on.getValue() ) return ; SoXipOverlayManipBase::handleEvent( action ); if( action->isHandled() ) return ; if( SO_MOUSE_RELEASE_EVENT( action->getEvent(), BUTTON1 ) ) { if( action->getGrabber() == this ) { applyTransform( mActionNode ); mode.setValue( NONE ); mTransformationMatrix = SbMatrix::identity(); action->setHandled(); action->releaseGrabber(); } } else if( action->getEvent()->isOfType( SoLocation2Event::getClassTypeId() ) ) { if( action->getGrabber() == this ) { switch( mode.getValue() ) { case ROTATION: rotate( action ); break ; case SCALE: scale( action ); break ; } action->setHandled(); } else { int cIndex = pickControlPoint( action ); if( action->getEvent()->wasShiftDown() ) { if( cIndex % 2 == 0 ) { SoXipCursor::setCursor( "ROTATE_POINT" ); action->setHandled(); } } else { switch( cIndex ) { case 0: case 4: SoXipCursor::setCursor( "UPRIGHT" ); break ; case 2: case 6: SoXipCursor::setCursor( "DOWNRIGHT" ); break ; case 1: case 5: SoXipCursor::setCursor( "UPDOWN" ); break ; case 3: case 7: SoXipCursor::setCursor( "LEFTRIGHT" ); break ; default: return ; } action->setHandled(); } } } else if( SO_MOUSE_PRESS_EVENT( action->getEvent(), BUTTON1 ) ) { if( getPoint( action, mTransformationOrigin ) ) { mControlPointId = pickControlPoint( action ); if( mControlPointId != -1 ) { ModeType newMode; if( action->getEvent()->wasShiftDown() ) newMode = mControlPointId % 2 == 0 ? ROTATION : SCALE; else newMode = SCALE; if( mode.getValue() != newMode ) mode.setValue( newMode ); action->setHandled(); action->setGrabber( this ); } } } }
void SoXipPlot2Ruler::handleEvent( SoHandleEventAction* action ) { const SoEvent* event = action->getEvent(); if( action->getGrabber() == this ) { if( SO_MOUSE_RELEASE_EVENT( event, BUTTON1 ) ) { action->releaseGrabber(); action->setHandled(); } else if( event->isOfType( SoLocation2Event::getClassTypeId() ) ) { SbVec3f proj = mPlaneProj.project( event->getNormalizedPosition( mViewportRegion ) ); if( type.getValue() == HORIZONTAL ) { SoXipCursor::setCursor( "UPDOWN" ); float val = proj[1]; if( val < mBBox.getMin()[1] ) val = mBBox.getMin()[1]; else if( val > mBBox.getMax()[1] ) val = mBBox.getMax()[1]; value.set1Value( mSelectedValue, val ); } else { SoXipCursor::setCursor( "LEFTRIGHT" ); float val = proj[0]; if( val < mBBox.getMin()[0] ) val = mBBox.getMin()[0]; else if( val > mBBox.getMax()[0] ) val = mBBox.getMax()[0]; value.set1Value( mSelectedValue, val ); } action->setHandled(); } } else if( !action->getGrabber() ) { saveViewInformation( action ); if( SO_MOUSE_PRESS_EVENT( event, BUTTON1 ) ) { SbVec3f proj = mPlaneProj.project( event->getNormalizedPosition( mViewportRegion ) ); if( type.getValue() == HORIZONTAL ) { float minDist = projectScreenOffsetToWorld( SbVec2s(0, 3) ).length(); int numValues = value.getNum(); for( int i = 0; i < numValues; ++ i ) { if( fabs( proj[1] - value[i] ) < minDist ) { action->setHandled(); action->setGrabber( this ); break ; } } } else if( type.getValue() == VERTICAL ) { float minDist = projectScreenOffsetToWorld( SbVec2s(3, 0) ).length(); int numValues = value.getNum(); for( int i = 0; i < numValues; ++ i ) { if( fabs( proj[0] - value[i] ) < minDist ) { action->setHandled(); action->setGrabber( this ); } } } } else if( event->isOfType( SoLocation2Event::getClassTypeId() ) ) { SbVec3f proj = mPlaneProj.project( event->getNormalizedPosition( mViewportRegion ) ); if( type.getValue() == HORIZONTAL ) { float minDist = projectScreenOffsetToWorld( SbVec2s(0, 3) ).length(); int numValues = value.getNum(); for( int i = 0; i < numValues; ++ i ) { if( fabs( proj[1] - value[i] ) < minDist ) { mSelectedValue = i; SoXipCursor::setCursor( "UPDOWN" ); action->setHandled(); break ; } } } else if( type.getValue() == VERTICAL ) { float minDist = projectScreenOffsetToWorld( SbVec2s(3, 0) ).length(); int numValues = value.getNum(); for( int i = 0; i < numValues; ++ i ) { if( fabs( proj[0] - value[i] ) < minDist ) { mSelectedValue = i; SoXipCursor::setCursor( "LEFTRIGHT" ); action->setHandled(); break ; } } } } } }