-// SALOME VTKViewer : build VTK viewer into Salome desktop
+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 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, or (at your option) any later version.
//
-// 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
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
+// SALOME VTKViewer : build VTK viewer into Salome desktop
// File : SVTK_SpaceMouse.cxx
// Author : Alexander SLADKOV
-// Module : SALOME
-// $Header$
#include <string.h>
#include <math.h>
#include <stdio.h>
+#ifndef WIN32
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
+#endif
#include "SVTK_SpaceMouse.h"
-//---------------------------------------------
SVTK_SpaceMouse* SVTK_SpaceMouse::myInstance = 0;
-//---------------------------------------------
+/*!
+ \return shared instance of object (creates if there is no one)
+*/
SVTK_SpaceMouse* SVTK_SpaceMouse::getInstance()
{
if ( !myInstance )
return myInstance;
}
-//---------------------------------------------
+/*!
+ Constructor
+*/
SVTK_SpaceMouse::SVTK_SpaceMouse()
{
+#ifndef WIN32
win = InputFocus;
+#endif
spaceMouseOn = 0;
}
-//---------------------------------------------
+#ifndef WIN32
+
+/*!
+ Initialization
+*/
int SVTK_SpaceMouse::initialize( Display *display, Window window )
{
XMotionEvent = XInternAtom( display, "MotionEvent", 1 );
return spaceMouseOn;
}
-//---------------------------------------------
static int errorCallback( Display *display, XErrorEvent *Error )
{
char msg[ 128 ];
return 0;
}
-//---------------------------------------------
+/*!
+ Initialize by window
+*/
int SVTK_SpaceMouse::setWindow( Display *display, Window window )
{
XTextProperty winName;
PropReturn = NULL;
XGetWindowProperty( display, root, XCommandEvent, 0,1, 0,
- AnyPropertyType, &type, &format, &NItems,
- &BytesReturn, &PropReturn );
+ AnyPropertyType, &type, &format, &NItems,
+ &BytesReturn, &PropReturn );
win = InputFocus;
if ( PropReturn != NULL ) {
return result;
}
-//---------------------------------------------
+/*!
+ Close
+*/
int SVTK_SpaceMouse::close(Display *display)
{
initialize( display, (Window)InputFocus );
return 1;
}
-//---------------------------------------------
+/*!
+ Custom event handler
+*/
int SVTK_SpaceMouse::translateEvent( Display* display, XEvent* xEvent, MoveEvent* spaceMouseEvent,
- double scale, double rScale )
+ double scale, double rScale )
{
if ( !spaceMouseOn )
return 0;
if ( xEvent->xclient.message_type == XMotionEvent ) {
spaceMouseEvent->type = SpaceMouseMove;
spaceMouseEvent->data[ x ] =
- xEvent->xclient.data.s[2] * scale;
+ xEvent->xclient.data.s[2] * scale;
spaceMouseEvent->data[ y ] =
- xEvent->xclient.data.s[3] * scale;
+ xEvent->xclient.data.s[3] * scale;
spaceMouseEvent->data[ z ] =
- xEvent->xclient.data.s[4] * scale;
+ xEvent->xclient.data.s[4] * scale;
spaceMouseEvent->data[ a ] =
- xEvent->xclient.data.s[5] * rScale;
+ xEvent->xclient.data.s[5] * rScale;
spaceMouseEvent->data[ b ] =
- xEvent->xclient.data.s[6] * rScale;
+ xEvent->xclient.data.s[6] * rScale;
spaceMouseEvent->data[ c ] =
- xEvent->xclient.data.s[7] * rScale;
+ xEvent->xclient.data.s[7] * rScale;
spaceMouseEvent->period = xEvent->xclient.data.s[8];
return 1;
}
return (!display);
}
+#endif