From: asv Date: Thu, 18 Aug 2005 06:51:28 +0000 (+0000) Subject: Implementation of connectivity with 3D SpaceMouse control. X-Git-Tag: BR-D5-38-2003_D2005-12-09~42 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=87d316dcfe7557abd7b7325974c9cee82dede38f;p=modules%2Fgui.git Implementation of connectivity with 3D SpaceMouse control. --- diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index f197eaff1..4e5379138 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -28,6 +28,8 @@ EXPORT_HEADERS= SVTK.h \ SVTK_Selector.h \ SVTK_Selection.h \ SVTK_SelectionEvent.h \ + SVTK_SpaceMouse.h \ + SVTK_SpaceMouseEvent.h \ SVTK_ViewModelBase.h # Libraries targets @@ -45,6 +47,7 @@ LIB_SRC= SVTK_Prs.cxx \ SVTK_RenderWindow.cxx \ SVTK_InteractorStyle.cxx \ SVTK_RenderWindowInteractor.cxx \ + SVTK_SpaceMouse.cxx \ SVTK_Selector.cxx LIB_MOC = SVTK_RenderWindowInteractor.h \ diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 351b30062..b2876bc34 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -35,13 +35,17 @@ #include "SVTK_RenderWindow.h" #include "SVTK_ViewWindow.h" #include "SVTK_Selection.h" +#include "SVTK_SpaceMouseEvent.h" +#include "SVTK_Selector.h" #include "SALOME_Actor.h" -#include "SVTK_Selector.h" #include "SALOME_ListIteratorOfListIO.hxx" #include "SALOME_ListIO.hxx" +#include "SUIT_Session.h" +#include "SUIT_ResourceMgr.h" + #include #include #include @@ -50,6 +54,8 @@ #include #include #include +#include +#include #include //VRV: porting on Qt 3.0.5 @@ -100,6 +106,9 @@ SVTK_InteractorStyle this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE; loadCursors(); + // set custom event handling function (to handle 3d space mouse events) + EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents ); + myPicker = vtkPicker::New(); myPicker->Delete(); @@ -1014,6 +1023,7 @@ SVTK_InteractorStyle // called during viewer operation when user moves mouse (!put necessary processing here!) +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::onOperation(QPoint mousePos) @@ -1080,6 +1090,7 @@ SVTK_InteractorStyle // called when user moves mouse inside viewer window and there is no active viewer operation // (!put necessary processing here!) +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::onCursorMove(QPoint mousePos) @@ -1113,6 +1124,7 @@ SVTK_InteractorStyle } // called on finsh GlobalPan operation +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::Place(const int theX, const int theY) @@ -1140,6 +1152,7 @@ SVTK_InteractorStyle // Translates view from Point to Point +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::TranslateView(int toX, int toY, int fromX, int fromY) @@ -1173,6 +1186,7 @@ SVTK_InteractorStyle motionVector[2] + viewPoint[2]); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::SetFilter( const Handle(VTKViewer_Filter)& theFilter ) @@ -1180,6 +1194,7 @@ SVTK_InteractorStyle myFilters[ theFilter->GetId() ] = theFilter; } +//---------------------------------------------------------------------------- bool SVTK_InteractorStyle ::IsFilterPresent( const int theId ) @@ -1187,6 +1202,7 @@ SVTK_InteractorStyle return myFilters.find( theId ) != myFilters.end(); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::RemoveFilter( const int theId ) @@ -1195,7 +1211,7 @@ SVTK_InteractorStyle myFilters.erase( theId ); } - +//---------------------------------------------------------------------------- bool SVTK_InteractorStyle ::IsValid( SALOME_Actor* theActor, @@ -1213,6 +1229,7 @@ SVTK_InteractorStyle return true; } +//---------------------------------------------------------------------------- Handle(VTKViewer_Filter) SVTK_InteractorStyle ::GetFilter( const int theId ) @@ -1220,6 +1237,7 @@ SVTK_InteractorStyle return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)(); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::IncrementalPan( const int incrX, const int incrY ) @@ -1227,6 +1245,7 @@ SVTK_InteractorStyle this->PanXY( incrX, incrY, 0, 0 ); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::IncrementalZoom( const int incr ) @@ -1234,9 +1253,129 @@ SVTK_InteractorStyle this->DollyXY( incr, incr ); } +//---------------------------------------------------------------------------- void SVTK_InteractorStyle ::IncrementalRotate( const int incrX, const int incrY ) { this->RotateXY( incrX, -incrY ); } + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::SetInteractor( vtkRenderWindowInteractor* interactor ) +{ + // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc) + vtkInteractorStyle::SetInteractor( interactor ); + + // register EventCallbackCommand as observer of custorm event (3d space mouse event) + interactor->AddObserver( SpaceMouseMoveEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SpaceMouseButtonEvent, EventCallbackCommand, Priority ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::onSpaceMouseMove( double* data ) +{ + // printf( "x=%+5.0lf y=%+5.0lf z=%+5.0lf a=%+5.0lf b=%+5.0lf c=%+5.0lf\n", + // data[0], data[1], data[2], data[3], data[4], data[5] ); + + // general things, do SetCurrentRenderer() within FindPokedRenderer() + int x, y; + Interactor->GetEventPosition( x, y ); // current mouse position (from last mouse move event or any other event) + FindPokedRenderer( x, y ); // calls SetCurrentRenderer + + IncrementalZoom( (int)data[2] ); // 1. push toward / pull backward = zoom out / zoom in + IncrementalPan( (int)data[0], (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right + IncrementalRotate( 0, (int)data[4] ); // 4. twist the control = rotate around Y axis +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::onSpaceMouseButton( int button ) +{ + // printf( "Button pressed [%d] \n", button ); + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + if ( resMgr->integerValue( "VISU", "spacemouse_func1_btn" ) == button ) + DecreaseSpeedIncrement(); + if ( resMgr->integerValue( "VISU", "spacemouse_func2_btn" ) == button ) + IncreaseSpeedIncrement(); + if ( resMgr->integerValue( "VISU", "spacemouse_func3_btn" ) == button ) + DecreaseGaussPointMagnification(); + if ( resMgr->integerValue( "VISU", "spacemouse_func4_btn" ) == button ) + IncreaseGaussPointMagnification(); + if ( resMgr->integerValue( "VISU", "spacemouse_func5_btn" ) == button ) + DominantCombinedSwitch(); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::DecreaseSpeedIncrement() +{ + printf( "\n--DecreaseSpeedIncrement() NOT IMPLEMENTED--\n" ); + +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::IncreaseSpeedIncrement() +{ + printf( "\n--IncreaseSpeedIncrement() NOT IMPLEMENTED--\n" ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::DecreaseGaussPointMagnification() +{ + printf( "\n--DecreaseGaussPointMagnification() NOT IMPLEMENTED--\n" ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::IncreaseGaussPointMagnification() +{ + printf( "\n--IncreaseGaussPointMagnification() NOT IMPLEMENTED--\n" ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::DominantCombinedSwitch() +{ + printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::ProcessEvents( vtkObject* object, + unsigned long event, + void* clientData, + void* callData ) +{ + if ( event != SpaceMouseMoveEvent && event != SpaceMouseButtonEvent ) + vtkInteractorStyle::ProcessEvents( object, event, clientData, callData ); + + else if ( clientData && callData ) { + vtkObject* anObject = reinterpret_cast( clientData ); + SVTK_InteractorStyle* self = dynamic_cast( anObject ); + if ( self ) { + switch ( event ) { + case SpaceMouseMoveEvent : + self->onSpaceMouseMove( (double*)callData ); + break; + case SpaceMouseButtonEvent : + self->onSpaceMouseButton( *((int*)callData) ); + break; + } + } + } +} + diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index dc362274d..9627e93d3 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -34,6 +34,9 @@ #include #include +class vtkCell; +class vtkRenderWindowInteractor; + #include #include #include @@ -84,6 +87,15 @@ class SVTK_EXPORT SVTK_InteractorStyle : SVTK_SelectionEvent GetSelectionEvent(); + //merge with V2_2_0_VISU_improvements:void setTriedron(VTKViewer_Trihedron* theTrihedron); + void setPreselectionProp(const double& theRed = 0, + const double& theGreen = 1, + const double& theBlue = 1, + const int& theWidth = 5); + + // redefined in order to add an observer (callback) for custorm event (space mouse event) + virtual void SetInteractor( vtkRenderWindowInteractor* ); + // VTK events virtual void OnMouseMove(); virtual void OnLeftButtonDown(); @@ -144,6 +156,10 @@ class SVTK_EXPORT SVTK_InteractorStyle : void Place(const int theX, const int theY); void TranslateView(int toX, int toY, int fromX, int fromY); + // custom event handling function (to handle 3d space mouse events) + static void ProcessEvents( vtkObject* object, unsigned long event, + void* clientData, void* callData ); + float MotionFactor; float RadianToDegree; // constant: for conv from deg to rad double myScale; @@ -167,6 +183,15 @@ class SVTK_EXPORT SVTK_InteractorStyle : void onCursorMove(QPoint mousePos); void setCursor(const int operation); + void onSpaceMouseMove( double* data ); + void onSpaceMouseButton( int button ); + + void DecreaseSpeedIncrement(); + void IncreaseSpeedIncrement(); + void DecreaseGaussPointMagnification(); + void IncreaseGaussPointMagnification(); + void DominantCombinedSwitch(); + signals: void RenderWindowModified() ; diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 7a98ca3ec..4ef7a4cbd 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -31,6 +31,8 @@ #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" #include "SALOME_Actor.h" +#include "SVTK_SpaceMouse.h" +#include "SVTK_SpaceMouseEvent.h" #include #include @@ -49,6 +51,8 @@ // QT Includes #include +#include +#include #include "utilities.h" @@ -81,6 +85,11 @@ SVTK_RenderWindowInteractor { if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor::~SVTK_RenderWindowInteractor()"); + // stop 3d space mouse driver + SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); + if ( sm->isSpaceMouseOn() ) + sm->close( x11Display() ); + delete mTimer ; myInteractor->Delete(); @@ -153,7 +162,7 @@ int SVTK_RenderWindowInteractor ::GetDisplayMode() { - return myDisplayMode; + return myDisplayMode; } @@ -506,7 +515,6 @@ SVTK_RenderWindowInteractor myInteractor->SetEventInformation( event->x(), event->y(), ( event->state() & ControlButton ), ( event->state() & ShiftButton ) ); - myInteractor->MouseMoveEvent(); //emit MouseMove( event ) ; @@ -669,6 +677,62 @@ SVTK_RenderWindowInteractor theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. ); } +//---------------------------------------------------------------------------- +bool +SVTK_RenderWindowInteractor +::x11Event( XEvent *xEvent ) +{ + // handle 3d space mouse events + SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); + if ( sm->isSpaceMouseOn() && xEvent->type == ClientMessage ) { + SVTK_SpaceMouse::MoveEvent spaceMouseEvent; + int type = sm->translateEvent( x11Display(), xEvent, &spaceMouseEvent, 1.0, 1.0 ); + switch ( type ) + { + case SVTK_SpaceMouse::SpaceMouseMove : + myInteractor->InvokeEvent( SpaceMouseMoveEvent, spaceMouseEvent.data ); + break; + case SVTK_SpaceMouse::SpaceButtonPress : + myInteractor->InvokeEvent( SpaceMouseButtonEvent, &spaceMouseEvent.button ); + break; + case SVTK_SpaceMouse::SpaceButtonRelease : + break; + } + return true; // stop handling the event + } + + return SVTK_RenderWindow::x11Event( xEvent ); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::focusInEvent ( QFocusEvent* event ) +{ + QWidget::focusInEvent( event ); + + // register set space mouse events receiver + SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); + if ( !sm->isSpaceMouseOn() ) {// initialize 3D space mouse driver + sm->initialize( x11Display(), winId() ); + if ( !sm->isSpaceMouseOn() ) + printf( "\nError: 3D Space Mouse driver was not started.\n" ); + } + else + SVTK_SpaceMouse::getInstance()->setWindow( x11Display(), winId() ); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::focusOutEvent ( QFocusEvent* event ) +{ + QWidget::focusInEvent( event ); + // unregister set space mouse events receiver + if ( SVTK_SpaceMouse::getInstance()->isSpaceMouseOn() ) + SVTK_SpaceMouse::getInstance()->setWindow( x11Display(), 0 ); +} + //---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index b2055d85d..03d9f39b2 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -157,11 +157,17 @@ public: virtual void keyPressEvent( QKeyEvent* ); virtual void keyReleaseEvent( QKeyEvent* ); virtual void contextMenuEvent( QContextMenuEvent * e ); + virtual bool x11Event( XEvent *e ); virtual void paintEvent( QPaintEvent* ); virtual void resizeEvent( QResizeEvent* ); virtual void onChangeBackgroundColor(); + // reimplemented from QWidget in order to set window - receiver + // of space mouse events. + virtual void focusInEvent ( QFocusEvent* ); + virtual void focusOutEvent( QFocusEvent* ); + private slots: // Not all of these slots are needed in VTK_MAJOR_VERSION=3, // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, diff --git a/src/SVTK/SVTK_SpaceMouse.cxx b/src/SVTK/SVTK_SpaceMouse.cxx new file mode 100644 index 000000000..620e97ec0 --- /dev/null +++ b/src/SVTK/SVTK_SpaceMouse.cxx @@ -0,0 +1,196 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_SpaceMouse.cxx +// Author : Alexander SLADKOV +// Module : SALOME +// $Header$ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "SVTK_SpaceMouse.h" + +//--------------------------------------------- +SVTK_SpaceMouse* SVTK_SpaceMouse::myInstance = 0; + +//--------------------------------------------- +SVTK_SpaceMouse* SVTK_SpaceMouse::getInstance() +{ + if ( !myInstance ) + myInstance = new SVTK_SpaceMouse(); + return myInstance; +} + +//--------------------------------------------- +SVTK_SpaceMouse::SVTK_SpaceMouse() +{ + win = InputFocus; + spaceMouseOn = 0; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::initialize( Display *display, Window window ) +{ + XMotionEvent = XInternAtom( display, "MotionEvent", 1 ); + XButtonPressEvent = XInternAtom( display, "ButtonPressEvent", 1 ); + XButtonReleaseEvent = XInternAtom( display, "ButtonReleaseEvent", 1 ); + XCommandEvent = XInternAtom( display, "CommandEvent", 1 ); + + spaceMouseOn = (XMotionEvent != 0) && + (XButtonPressEvent != 0) && + (XButtonReleaseEvent != 0) && + (XCommandEvent != 0); + if ( !spaceMouseOn ) + return 0; + + spaceMouseOn = setWindow( display, window ); + if ( !spaceMouseOn ) + return 0; + + return spaceMouseOn; +} + +//--------------------------------------------- +static int errorCallback( Display *display, XErrorEvent *Error ) +{ + char msg[ 128 ]; + if ( Error->error_code != BadWindow ) { + XGetErrorText( display,Error->error_code,msg,sizeof( msg ) ); + fprintf( stderr, "SpaceMouse reported error = %s. Exit ... \n", msg ); + } + return 0; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::setWindow( Display *display, Window window ) +{ + XTextProperty winName; + XEvent xEvent; + Atom type; + int format; + unsigned long NItems, BytesReturn; + unsigned char *PropReturn; + Window root; + int result; + int (*errorHandler)(Display *,XErrorEvent *); + + result = 1; + errorHandler = XSetErrorHandler( errorCallback ); + + root = RootWindow( display, DefaultScreen(display) ); + + PropReturn = NULL; + XGetWindowProperty( display, root, XCommandEvent, 0,1, 0, + AnyPropertyType, &type, &format, &NItems, + &BytesReturn, &PropReturn ); + + win = InputFocus; + if ( PropReturn != NULL ) { + win = *(Window *) PropReturn; + XFree( PropReturn ); + } + else + return result = 0; + + if ( XGetWMName( display, win, &winName ) == 0 ) + return result = 0; + + if ( strcmp( (char *) "Magellan Window", (char *) winName.value) != 0 ) + return result = 0; + + xEvent.type = ClientMessage; + xEvent.xclient.format = 16; + xEvent.xclient.send_event = 0; + xEvent.xclient.display = display; + xEvent.xclient.window = win; + xEvent.xclient.message_type = XCommandEvent; + + xEvent.xclient.data.s[0] = (short) ((window>>16)&0x0000FFFF); + xEvent.xclient.data.s[1] = (short) (window&0x0000FFFF); + xEvent.xclient.data.s[2] = 27695; + + if ( XSendEvent( display, win, 0, 0x0000, &xEvent ) == 0 ) + return result = 0; + + XFlush( display ); + + XSetErrorHandler( errorHandler ); + return result; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::close(Display *display) +{ + initialize( display, (Window)InputFocus ); + spaceMouseOn = 0; + + return 1; +} + +//--------------------------------------------- +int SVTK_SpaceMouse::translateEvent( Display* display, XEvent* xEvent, MoveEvent* spaceMouseEvent, + double scale, double rScale ) +{ + if ( !spaceMouseOn ) + return 0; + + if ( xEvent->type == ClientMessage ) { + if ( xEvent->xclient.message_type == XMotionEvent ) { + spaceMouseEvent->type = SpaceMouseMove; + spaceMouseEvent->data[ x ] = + xEvent->xclient.data.s[2] * scale; + spaceMouseEvent->data[ y ] = + xEvent->xclient.data.s[3] * scale; + spaceMouseEvent->data[ z ] = + xEvent->xclient.data.s[4] * scale; + spaceMouseEvent->data[ a ] = + xEvent->xclient.data.s[5] * rScale; + spaceMouseEvent->data[ b ] = + xEvent->xclient.data.s[6] * rScale; + spaceMouseEvent->data[ c ] = + xEvent->xclient.data.s[7] * rScale; + spaceMouseEvent->period = xEvent->xclient.data.s[8]; + return 1; + } + else if ( xEvent->xclient.message_type == XButtonPressEvent ) { + spaceMouseEvent->type = SpaceButtonPress; + spaceMouseEvent->button = xEvent->xclient.data.s[2]; + return 2; + } + else if ( xEvent->xclient.message_type == XButtonReleaseEvent ) { + spaceMouseEvent->type = SpaceButtonRelease; + spaceMouseEvent->button = xEvent->xclient.data.s[2]; + return 3; + } + } + return (!display); +} + diff --git a/src/SVTK/SVTK_SpaceMouse.h b/src/SVTK/SVTK_SpaceMouse.h new file mode 100644 index 000000000..57a6f8470 --- /dev/null +++ b/src/SVTK/SVTK_SpaceMouse.h @@ -0,0 +1,75 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_SpaceMouse.h +// Author : Alexander SLADKOV +// Module : SALOME +// $Header$ + +#ifndef SVTK_SpaceMouse_h +#define SVTK_SpaceMouse_h + +extern "C" +{ +#include +#include +} + +class SVTK_SpaceMouse +{ + public: + + // access to SpaceMouse utility class + static SVTK_SpaceMouse* getInstance(); + + enum MoveData { x, y, z, a, b, c }; + enum EventType { SpaceMouseMove = 1, SpaceButtonPress, SpaceButtonRelease }; + + typedef struct { + int type; + int button; + double data[6]; + int period; + } MoveEvent; + + bool isSpaceMouseOn() const { return spaceMouseOn != 0; } + + int initialize ( Display*, Window ); + int setWindow ( Display*, Window ); + int translateEvent ( Display*, XEvent*, MoveEvent*, double, double ); + int close ( Display* ); + + private: + SVTK_SpaceMouse(); + static SVTK_SpaceMouse* myInstance; + + Atom XMotionEvent; + Atom XButtonPressEvent; + Atom XButtonReleaseEvent; + Atom XCommandEvent; + + Window win; + int spaceMouseOn; +}; + +#endif diff --git a/src/SVTK/SVTK_SpaceMouseEvent.h b/src/SVTK/SVTK_SpaceMouseEvent.h new file mode 100644 index 000000000..a7c4885fd --- /dev/null +++ b/src/SVTK/SVTK_SpaceMouseEvent.h @@ -0,0 +1,39 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SVTK_SpaceMouseEvent.h +// Author : Alexander SLADKOV +// Module : SALOME +// $Header$ + +#ifndef SVTK_SpaceMouseEvent_h +#define SVTK_SpaceMouseEvent_h + +#include + +enum SpaceMouseEvent { + SpaceMouseMoveEvent = vtkCommand::UserEvent+1, + SpaceMouseButtonEvent +}; + +#endif diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 368090079..77f183465 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -96,6 +96,9 @@ SVTK_ViewWindow this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); onResetView(); + + setFocusProxy( myView ); // send focus events to myView (fixes a bug + // when on module activation myView received focusOutEvent } //----------------------------------------------------------------------------