OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
init_spacenav.py
Go to the documentation of this file.
1 from PyQt4 import QtCore
2 
3 from ost import gfx, gui
4 
5 class SpacenavControl(QtCore.QObject):
6  def __init__(self, spnav,
7  parent=None):
8  QtCore.QObject.__init__(self, parent)
9  QtCore.QObject.connect(spnav,QtCore.SIGNAL("deviceTransformed(int,int,int,int,int,int)"), self.Changed)
10  QtCore.QObject.connect(spnav,QtCore.SIGNAL("deviceButtonPressed(int)"), self.Toggle)
11 
12  self.trans = True
13  self.rot = True
14  self.speed = 480.0
15 
16  def Changed(self, tx,ty,tz,rx,ry,rz):
17  transf = gfx.Scene().GetTransform()
18  if(self.trans):
19  transf.ApplyXAxisTranslation(tx/self.speed)
20  transf.ApplyYAxisTranslation(ty/self.speed)
21  transf.ApplyZAxisTranslation(-tz/self.speed)
22  if(self.rot):
23  transf.ApplyXAxisRotation(rx/self.speed)
24  transf.ApplyYAxisRotation(ry/self.speed)
25  transf.ApplyZAxisRotation(rz/self.speed)
26  gfx.Scene().SetTransform(transf)
27  gfx.Scene().RequestRedraw()
28 
29  def Toggle(self, button):
30  if button == 0:
31  self.trans = not self.trans
32  print "Translation Enabled:",self.trans
33  elif button == 1:
34  self.rot = not self.rot
35  print "Rotation Enabled:",self.rot
36  elif button == 12:
37  if self.speed > 20:
38  self.speed *= 0.8
39  print "Speed Increased:",self.speed
40  elif button == 13:
41  self.speed /= 0.8
42  print "Speed Reduced:",self.speed
43  else:
44  print "other:",button
45 
46 
47 def _InitSpaceNav(app):
48  try:
49  spnav = gui.SpnavInput.GetQThread()
50  spnav.start()
51  parent = app.gl_win.qobject
52  SpacenavControl(spnav,parent)
53  except AttributeError:
54  pass