Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1169 - trunk/SwigInterface
- Date: Sat, 12 Aug 2006 01:24:53 -0600 (MDT)
Author: abe
Date: Sat Aug 12 01:24:52 2006
New Revision: 1169
Modified:
trunk/SwigInterface/wxManta.py
Log:
Updates to wxManta interface. Added more camera interaction, can't
figure out how to implement shootOneRay, once this is acomplished the
UI should be able to replace the fox gui.
M wxManta.py
Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py (original)
+++ trunk/SwigInterface/wxManta.py Sat Aug 12 01:24:52 2006
@@ -7,6 +7,7 @@
import threading
import math
import wx.lib.colourselect as csel
+import os
from manta import *
from pycallback import *
@@ -294,6 +295,10 @@
manta_menu.Append(wx.NewId(), "&Quit Manta"))
menuBar.Append(manta_menu, "&Manta")
+ file_menu = wx.Menu()
+ self.Bind(wx.EVT_MENU, self.OnImportPython,
+ file_menu.Append(wx.NewId(), "Import &Python"))
+ menuBar.Append(file_menu, "&File")
view_menu = wx.Menu()
self.Bind(wx.EVT_MENU, self.OnAutoView,
@@ -372,10 +377,15 @@
# Setup the UI events.
self.canvas.Bind( wx.EVT_MOTION, self.OnMotion )
self.canvas.Bind( wx.EVT_LEFT_DOWN, self.OnLeftDown )
+ self.canvas.Bind( wx.EVT_LEFT_DCLICK, self.OnLeftDClick )
self.canvas.Bind( wx.EVT_LEFT_UP, self.OnLeftUp )
self.canvas.Bind( wx.EVT_RIGHT_DOWN, self.OnRightDown )
+ self.canvas.Bind( wx.EVT_RIGHT_UP, self.OnRightUp )
+ self.canvas.Bind( wx.EVT_MOUSEWHEEL, self.OnMouseWheel )
+
# Keyboard events are ignored for wx.Frame.
self.canvas.Bind( wx.EVT_KEY_DOWN, self.OnChar )
+
# Make canvas the initial focus
wx.CallAfter(self.canvas.SetFocus)
@@ -383,7 +393,8 @@
##################################################################
# globals
self.trackball_radius = 0.8
- self.mouse_is_down = False
+ self.left_mouse_is_down = False
+ self.right_mouse_is_down = False
###########################################################################
@@ -425,13 +436,62 @@
except: pass
self.engine.blockUntilFinished()
# print "Engine exited"
+
+
###########################################################################
+ ## OnImportPython
+
###########################################################################
+ def OnImportPython(self, event):
+ dialog = wx.FileDialog(self, "Open Python Module",
+ os.getcwd(),
+ style=wx.OPEN,
+ wildcard="Python (*.py)|*.py|All files
(*.*)|*.*")
+ if (dialog.ShowModal() == wx.ID_OK):
+ # Obtain the file name.
+ filename = dialog.GetPath()
+
+ # Invoke the script during a transaction.
+ self.PythonImportTransaction( filename )
+ dialog.Destroy()
+
+
###########################################################################
+ ## PythonImportTransaction
+
###########################################################################
+ def PythonImportTransaction( self, filename ):
+
+ self.engine.addTransaction("import python",
+
manta_new(createMantaTransaction(self.MantaPythonImport, (filename,))))
+
+
###########################################################################
+ ## MantaPythonImport
+
###########################################################################
+ def MantaPythonImport(self, filename):
+
+ # Determine the filename path.
+ filepath = os.path.dirname(filename)
+
+ # Add the filename path to the PYTHONPATH
+ sys.path.append( filepath )
+
+ # Extract the module name and import the script.
+ filename = os.path.splitext(os.path.basename(filename))[0];
+ try:
+ __import__( filename )
+ except(ImportError):
+ wx.MessageDialog(self,"Error importing " + filename,"Error",
+ style=wx.OK,
+ pos=wx.DefaultPosition)
+
+ # Remove the file path.
+ sys.path.remove( filepath )
###########################################################################
## OnMotion
###########################################################################
def OnMotion( self, event ):
- if ( self.mouse_is_down ):
+ if ( self.left_mouse_is_down ):
self.mouseRotate(event)
+ elif (self.right_mouse_is_down ):
+ self.mousePan(event)
event.Skip()
###########################################################################
@@ -462,8 +522,15 @@
## OnAbout
###########################################################################
def OnAbout(self, event):
- wx.MessageBox("This is the Python GUI to the Manta Interactive Ray
Tracer",
- "About Manta", wx.OK | wx.ICON_INFORMATION, self)
+
+ message = \
+ "The Manta Interactive Ray Tracer\n\n" + \
+ "(c) 2005-2006 Scientific Computing and Imaging Institute.\n" + \
+ "University of Utah\n\n" + \
+ "Revision Information:\n" + getAboutString()
+
+ wx.MessageBox( message, "About Manta",
+ wx.TE_MULTILINE | wx.OK | wx.ICON_INFORMATION, self)
###########################################################################
## OnAutoView
@@ -493,26 +560,47 @@
self.sync_display.doneRendering()
###########################################################################
- ## OnLeftDown
+ ## OnLeftUp
###########################################################################
def OnLeftUp( self, event ):
- self.mouse_is_down = False
+ self.left_mouse_is_down = False
###########################################################################
## OnRightDown
###########################################################################
def OnRightDown( self, event ):
+ # Set this for the motion event.
+ self.right_mouse_is_down = True
+ mouse_pos = event.GetPosition()
+
+ self.last_x = mouse_pos.x
+ self.last_y = mouse_pos.y
event.Skip()
###########################################################################
+ ## OnRightUp
+
###########################################################################
+ def OnRightUp( self, event ):
+
+ self.right_mouse_is_down = False
+
+
###########################################################################
+ ## OnMouseWheel
+
###########################################################################
+ def OnMouseWheel( self, event ):
+
+ self.mouseDolly( event )
+
+
+
###########################################################################
## OnLeftDown
###########################################################################
def OnLeftDown( self, event ):
# Set this for the motion event
- self.mouse_is_down = True
+ self.left_mouse_is_down = True
mouse_pos = event.GetPosition()
window_size = self.canvas.GetSize()
@@ -524,6 +612,42 @@
self.trackball_radius)
event.Skip()
+
###########################################################################
+ ## OnLeftDCLick
+
###########################################################################
+ def OnLeftDClick( self, event ):
+
+ print "Double click"
+
+ # Compute pixel coordinates.
+ mouse_pos = event.GetPosition()
+ window_size = self.canvas.GetSize()
+ xpos = 2.0*mouse_pos.x/window_size.width - 1.0
+ ypos = 1.0 - 2.0*mouse_pos.y/window_size.height
+
+ # Construct a ray packet.
+ data = RayPacketData()
+ rays = RayPacket( data, RayPacket.UnknownShape, 0, 1, 0, 0 )
+
+ # Shoot one ray.
+ color = Color(RGBColor())
+
+ rtrt.shootOneRay( color, rays, xpos, ypos, 0 )
+
+ if (rays.wasHit(0)):
+ position = rays.getHitPosition(0)
+
+ print position.x
+ print position.y
+ print position.z
+ else:
+ print "Missed"
+
+ event.Skip()
+
+
###########################################################################
+ ## mouseRotate
+
###########################################################################
def mouseRotate( self, event ):
mouse_pos = event.GetPosition()
window_size = self.canvas.GetSize()
@@ -535,6 +659,7 @@
trans.initWithRotation(to, self.rotate_from);
self.rotate_from = to;
+ # Obtain the camera.
channel = 0
camera = self.engine.getCamera(channel)
cbArgs = ( trans, Camera.LookAt )
@@ -543,6 +668,55 @@
self.last_x = mouse_pos.x;
self.last_y = mouse_pos.y;
+
###########################################################################
+ ## mousePan
+
###########################################################################
+ def mousePan( self, event ):
+
+ # Determine current mouse position.
+ mouse_pos = event.GetPosition();
+ window_size = self.canvas.GetSize()
+ xpos = 2.0*mouse_pos.x/window_size.width - 1.0
+ ypos = 1.0 - 2.0*mouse_pos.y/window_size.height
+
+ # Determine previous mouse position.
+ prev_xpos = 2.0*self.last_x/window_size.width - 1.0
+ prev_ypos = 1.0 - 2.0*self.last_y/window_size.height
+
+ delta_x = prev_xpos - xpos
+ delta_y = prev_ypos - ypos
+
+ # Obtain the camera.
+ channel = 0
+ camera = self.engine.getCamera(channel)
+
+ self.engine.addTransaction("pan",
+
manta_new(createMantaTransaction(camera.translate,
+
(Vector(delta_x, delta_y, 0),))))
+ # Update last position.
+ self.last_x = mouse_pos.x;
+ self.last_y = mouse_pos.y;
+
+
###########################################################################
+ ## mouseDolly
+
###########################################################################
+ def mouseDolly(self, event ):
+
+ # Get wheel input.
+ delta = event.GetWheelDelta()
+ rotation = event.GetWheelRotation()/delta
+
+ # Obtain the camera.
+ channel = 0
+ camera = self.engine.getCamera(channel)
+
+ # Add transaction.
+ self.engine.addTransaction("dolly",
+
manta_new(createMantaTransaction(camera.dolly, (0.25*rotation,))))
+
+
###########################################################################
+ ## projectToSphere
+
###########################################################################
def projectToSphere(self, x, y, radius):
x /= radius
y /= radius
- [MANTA] r1169 - trunk/SwigInterface, abe, 08/12/2006
Archive powered by MHonArc 2.6.16.