Back to index

salome-gui  6.5.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
SVTK_SpaceMouse Class Reference

#include <SVTK_SpaceMouse.h>

Collaboration diagram for SVTK_SpaceMouse:
Collaboration graph
[legend]

List of all members.

Classes

struct  MoveEvent

Public Types

enum  MoveData {
  x, y, z, a,
  b, c
}
enum  EventType { SpaceMouseMove = 1, SpaceButtonPress, SpaceButtonRelease }

Public Member Functions

bool isSpaceMouseOn () const
int initialize (Display *, Window)
 Initialization.
int setWindow (Display *, Window)
 Initialize by window.
int translateEvent (Display *, XEvent *, MoveEvent *, double, double)
 Custom event handler.
int close (Display *)
 Close.

Static Public Member Functions

static SVTK_SpaceMousegetInstance ()

Private Member Functions

 SVTK_SpaceMouse ()
 Constructor.

Private Attributes

Atom XMotionEvent
Atom XButtonPressEvent
Atom XButtonReleaseEvent
Atom XCommandEvent
Window win
int spaceMouseOn

Static Private Attributes

static SVTK_SpaceMousemyInstance = 0

Detailed Description

Definition at line 38 of file SVTK_SpaceMouse.h.


Class Documentation

struct SVTK_SpaceMouse::MoveEvent

Definition at line 48 of file SVTK_SpaceMouse.h.

Class Members
int button
double data
int period
int type

Member Enumeration Documentation

Enumerator:
SpaceMouseMove 
SpaceButtonPress 
SpaceButtonRelease 

Definition at line 46 of file SVTK_SpaceMouse.h.

Enumerator:
x 
y 
z 
a 
b 
c 

Definition at line 45 of file SVTK_SpaceMouse.h.

{ x, y, z, a, b, c };

Constructor & Destructor Documentation

Constructor.

Definition at line 56 of file SVTK_SpaceMouse.cxx.

{
#ifndef WIN32
  win = InputFocus;
#endif
  spaceMouseOn = 0;
}

Here is the caller graph for this function:


Member Function Documentation

int SVTK_SpaceMouse::close ( Display *  display)

Close.

Definition at line 162 of file SVTK_SpaceMouse.cxx.

{
  initialize( display, (Window)InputFocus );
  spaceMouseOn = 0;
  
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
shared instance of object (creates if there is no one)

Definition at line 46 of file SVTK_SpaceMouse.cxx.

{
  if ( !myInstance )
    myInstance = new SVTK_SpaceMouse();
  return myInstance;
}

Here is the call graph for this function:

int SVTK_SpaceMouse::initialize ( Display *  display,
Window  window 
)

Initialization.

Definition at line 69 of file SVTK_SpaceMouse.cxx.

{
 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; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool SVTK_SpaceMouse::isSpaceMouseOn ( ) const [inline]

Definition at line 55 of file SVTK_SpaceMouse.h.

{ return spaceMouseOn != 0; }
int SVTK_SpaceMouse::setWindow ( Display *  display,
Window  window 
)

Initialize by window.

Definition at line 103 of file SVTK_SpaceMouse.cxx.

{
  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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int SVTK_SpaceMouse::translateEvent ( Display *  display,
XEvent *  xEvent,
MoveEvent spaceMouseEvent,
double  scale,
double  rScale 
)

Custom event handler.

Definition at line 173 of file SVTK_SpaceMouse.cxx.

{
  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);
}

Member Data Documentation

Definition at line 66 of file SVTK_SpaceMouse.h.

Definition at line 76 of file SVTK_SpaceMouse.h.

Definition at line 74 of file SVTK_SpaceMouse.h.

Definition at line 70 of file SVTK_SpaceMouse.h.

Definition at line 71 of file SVTK_SpaceMouse.h.

Definition at line 72 of file SVTK_SpaceMouse.h.

Definition at line 69 of file SVTK_SpaceMouse.h.


The documentation for this class was generated from the following files: