Commit 5ab6767b authored by sumpfralle's avatar sumpfralle

r659@erker: lars | 2010-02-14 21:21:09 +0100

 implemented proper handling of the separate 3d window (toggling - even with the "destroy window" button)
 cleaned up some unused code


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@124 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 40a02714
...@@ -29,7 +29,7 @@ BUTTON_ZOOM = gtk.gdk.BUTTON3_MASK ...@@ -29,7 +29,7 @@ BUTTON_ZOOM = gtk.gdk.BUTTON3_MASK
class GLView: class GLView:
def __init__(self, gui, settings): def __init__(self, gui, settings, notify_destroy=None):
# assume, that initialization will fail # assume, that initialization will fail
self.enabled = False self.enabled = False
try: try:
...@@ -42,9 +42,13 @@ class GLView: ...@@ -42,9 +42,13 @@ class GLView:
self.enabled = True self.enabled = True
self.settings = settings self.settings = settings
self.gui = gui self.gui = gui
self.is_visible = False
self.window = self.gui.get_object("view3dwindow") self.window = self.gui.get_object("view3dwindow")
self.window.connect("destroy", self.destroy) self.notify_destroy_func = notify_destroy
self.window.connect("delete-event", self.destroy)
self.window.set_default_size(560, 400) self.window.set_default_size(560, 400)
self._position = self.gui.get_object("ProjectWindow").get_position()
self._position = (self._position[0] + 100, self._position[1] + 100)
self.container = self.gui.get_object("view3dbox") self.container = self.gui.get_object("view3dbox")
self.gui.get_object("Reset View").connect("clicked", self.rotate_view, ogl_tools.VIEWS["reset"]) self.gui.get_object("Reset View").connect("clicked", self.rotate_view, ogl_tools.VIEWS["reset"])
self.gui.get_object("Left View").connect("clicked", self.rotate_view, ogl_tools.VIEWS["left"]) self.gui.get_object("Left View").connect("clicked", self.rotate_view, ogl_tools.VIEWS["left"])
...@@ -70,8 +74,18 @@ class GLView: ...@@ -70,8 +74,18 @@ class GLView:
self.camera = ogl_tools.Camera(self.settings, lambda: (self.area.allocation.width, self.area.allocation.height)) self.camera = ogl_tools.Camera(self.settings, lambda: (self.area.allocation.width, self.area.allocation.height))
self.container.add(self.area) self.container.add(self.area)
self.container.show() self.container.show()
self.show()
def show(self):
self.is_visible = True
self.window.move(*self._position)
self.window.show() self.window.show()
def hide(self):
self.is_visible = False
self._position = self.window.get_position()
self.window.hide()
def check_busy(func): def check_busy(func):
def busy_wrapper(self, *args, **kwargs): def busy_wrapper(self, *args, **kwargs):
if self.busy: if self.busy:
...@@ -117,9 +131,12 @@ class GLView: ...@@ -117,9 +131,12 @@ class GLView:
GL.glLoadIdentity() GL.glLoadIdentity()
GL.glViewport(0, 0, self.area.allocation.width, self.area.allocation.height) GL.glViewport(0, 0, self.area.allocation.width, self.area.allocation.height)
def destroy(self, widget=None): def destroy(self, widget=None, data=None):
self.area.destroy() print "destroy"
self.window.destroy() if self.notify_destroy_func:
self.notify_destroy_func()
# don't close the window
return True
def gtkgl_functionwrapper(function): def gtkgl_functionwrapper(function):
def decorated(self, *args, **kwords): def decorated(self, *args, **kwords):
...@@ -154,8 +171,10 @@ class GLView: ...@@ -154,8 +171,10 @@ class GLView:
# a button was pressed before # a button was pressed before
if state == self.mouse["button"] == BUTTON_ZOOM: if state == self.mouse["button"] == BUTTON_ZOOM:
# the start button is still active: update the view # the start button is still active: update the view
scale = 1 - 0.01 * (x - self.mouse["start_pos"][0]) start_x, start_y = self.mouse["start_pos"]
self.mouse["start_pos"][0] = x self.mouse["start_pos"] = [x, y]
# move the mouse from lower left to top right corner for scale up
scale = 1 - 0.01 * ((x - start_x) + (start_y - y))
# do some sanity checks, scale no more than # do some sanity checks, scale no more than
# 1:100 on any given click+drag # 1:100 on any given click+drag
if scale < 0.01: if scale < 0.01:
...@@ -222,7 +241,6 @@ class ProjectGui: ...@@ -222,7 +241,6 @@ class ProjectGui:
def __init__(self, master=None): def __init__(self, master=None):
gtk.gdk.threads_init() gtk.gdk.threads_init()
self.settings = pycam.Gui.Settings.Settings() self.settings = pycam.Gui.Settings.Settings()
self.notify_visual = threading.Condition()
self.gui_is_active = False self.gui_is_active = False
self.view3d = None self.view3d = None
self._batch_queue = [] self._batch_queue = []
...@@ -302,20 +320,16 @@ class ProjectGui: ...@@ -302,20 +320,16 @@ class ProjectGui:
def update_view(self): def update_view(self):
if self.view3d: if self.view3d:
self.notify_visual.acquire()
self.notify_visual.notify()
self.notify_visual.release()
self.view3d.paint() self.view3d.paint()
def reload_model(self): def reload_model(self):
self.physics = GuiCommon.generate_physics(self.settings) self.physics = GuiCommon.generate_physics(self.settings)
if self.view3d: if self.view3d:
self.settings.set("model_view_request_reset", True)
self.update_view() self.update_view()
@gui_activity_guard @gui_activity_guard
def toggle_3d_view(self, widget=None, value=None): def toggle_3d_view(self, widget=None, value=None):
current_state = not (self.view3d is None) current_state = not ((self.view3d is None) or (not self.view3d.is_visible))
if value is None: if value is None:
new_state = not current_state new_state = not current_state
else: else:
...@@ -323,19 +337,18 @@ class ProjectGui: ...@@ -323,19 +337,18 @@ class ProjectGui:
if new_state == current_state: if new_state == current_state:
return return
elif new_state: elif new_state:
self.settings.set("model_view_request_quit", False) if self.view3d is None:
# do the gl initialization # do the gl initialization
self.view3d = GLView(self.gui, self.settings) self.view3d = GLView(self.gui, self.settings, notify_destroy=self.toggle_3d_view)
if self.model and self.view3d.enabled: if self.model and self.view3d.enabled:
self.reset_bounds() self.reset_bounds()
self.view3d.reset_view() self.view3d.reset_view()
#self.thread3d = VisualThread(self.notify_visual, self.settings) else:
#self.thread3d.start() # the window is just hidden
self.view3d.show()
self.update_view() self.update_view()
else: else:
self.settings.set("model_view_request_quit", True) self.view3d.hide()
self.view3d.destroy()
self.view3d = None
self.gui.get_object("Toggle3dView").set_active(new_state) self.gui.get_object("Toggle3dView").set_active(new_state)
@gui_activity_guard @gui_activity_guard
...@@ -420,7 +433,6 @@ class ProjectGui: ...@@ -420,7 +433,6 @@ class ProjectGui:
self.update_view() self.update_view()
def destroy(self, widget=None, data=None): def destroy(self, widget=None, data=None):
self.settings.set("model_view_request_quit", True)
self.update_view() self.update_view()
gtk.main_quit() gtk.main_quit()
......
...@@ -3,16 +3,6 @@ import OpenGL.GLUT as GLUT ...@@ -3,16 +3,6 @@ import OpenGL.GLUT as GLUT
import ode_objects import ode_objects
VIEW_ROTATIONS = {
"reset": [(110, 1.0, 0.0, 0.0), (180, 0.0, 1.0, 0.0), (160, 0.0, 0.0, 1.0)],
"front": [(-90, 1.0, 0, 0)],
"back": [(-90, 1.0, 0, 0), (180, 0, 0, 1.0)],
"left": [(-90, 1.0, 0, 0), (90, 0, 0, 1.0)],
"right": [(-90, 1.0, 0, 0), (-90, 0, 0, 1.0)],
"top": [],
"bottom": [(180, 1.0, 0, 0)],
}
MODEL_TRANSFORMATIONS = { MODEL_TRANSFORMATIONS = {
"normal": ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0)), "normal": ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0)),
"x": ((1, 0, 0, 0), (0, 0, 1, 0), (0, -1, 0, 0)), "x": ((1, 0, 0, 0), (0, 0, 1, 0), (0, -1, 0, 0)),
...@@ -161,27 +151,6 @@ def rotate_view(scale, rotation=None): ...@@ -161,27 +151,6 @@ def rotate_view(scale, rotation=None):
for one_rot in rotation: for one_rot in rotation:
GL.glRotatef(*one_rot) GL.glRotatef(*one_rot)
def reset_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["reset"])
def front_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["front"])
def back_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["back"])
def top_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["top"])
def bottom_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["bottom"])
def left_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["left"])
def right_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["right"])
def transform_model(model, direction="normal"): def transform_model(model, direction="normal"):
model.transform(MODEL_TRANSFORMATIONS[direction]) model.transform(MODEL_TRANSFORMATIONS[direction])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment