Commit abeaadae authored by sumpfralle's avatar sumpfralle

keep the latest selected view if no manual change occoured


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1134 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent a9236068
...@@ -86,6 +86,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -86,6 +86,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.initialized = False self.initialized = False
self.busy = False self.busy = False
self.is_visible = False self.is_visible = False
self._last_view = VIEWS["reset"]
self._position = [200, 200] self._position = [200, 200]
toggle_3d = self.gui.get_object("Toggle3DView") toggle_3d = self.gui.get_object("Toggle3DView")
handler = toggle_3d.connect("toggled", self.toggle_3d_view) handler = toggle_3d.connect("toggled", self.toggle_3d_view)
...@@ -195,6 +196,8 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -195,6 +196,8 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.core.register_event("visual-item-updated", self.update_view) self.core.register_event("visual-item-updated", self.update_view)
self.core.register_event("visualization-state-changed", self.core.register_event("visualization-state-changed",
self._update_widgets) self._update_widgets)
self.core.register_event("model-list-changed",
self._restore_latest_view)
# show the window # show the window
self.area.show() self.area.show()
self.container.show() self.container.show()
...@@ -298,6 +301,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -298,6 +301,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
ord("L"): (-1, 0), ord("L"): (-1, 0),
} }
if key_string and (key_string in '1234567'): if key_string and (key_string in '1234567'):
self._last_view = None
names = ["reset", "front", "back", "left", "right", "top", "bottom"] names = ["reset", "front", "back", "left", "right", "top", "bottom"]
index = '1234567'.index(key_string) index = '1234567'.index(key_string)
self.rotate_view(view=VIEWS[names[index]]) self.rotate_view(view=VIEWS[names[index]])
...@@ -319,12 +323,14 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -319,12 +323,14 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.glsetup() self.glsetup()
self.paint() self.paint()
elif key_string in ("+", "-"): elif key_string in ("+", "-"):
self._last_view = None
if key_string == "+": if key_string == "+":
self.camera.zoom_in() self.camera.zoom_in()
else: else:
self.camera.zoom_out() self.camera.zoom_out()
self._paint_ignore_busy() self._paint_ignore_busy()
elif keyval in move_keys_dict.keys(): elif keyval in move_keys_dict.keys():
self._last_view = None
move_x, move_y = move_keys_dict[keyval] move_x, move_y = move_keys_dict[keyval]
if get_state() & gtk.gdk.SHIFT_MASK: if get_state() & gtk.gdk.SHIFT_MASK:
# shift key pressed -> rotation # shift key pressed -> rotation
...@@ -483,6 +489,17 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -483,6 +489,17 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
return result return result
return gtkgl_functionwrapper_function return gtkgl_functionwrapper_function
def _restore_latest_view(self):
""" this function is called whenever the model list changes
The function will restore the latest selected view - including
automatic distance adjustment. The latest view is always reset to
None, if any manual change (e.g. panning via mouse or keyboard)
occoured.
"""
if self._last_view:
self.rotate_view(view=self._last_view)
@check_busy @check_busy
@gtkgl_functionwrapper @gtkgl_functionwrapper
def context_menu_handler(self, widget, event): def context_menu_handler(self, widget, event):
...@@ -504,6 +521,8 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -504,6 +521,8 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
shift key: horizontal pan instead of vertical shift key: horizontal pan instead of vertical
control key: zoom control key: zoom
""" """
remember_last_view = self._last_view
self._last_view = None
try: try:
modifier_state = event.get_state() modifier_state = event.get_state()
except AttributeError: except AttributeError:
...@@ -533,6 +552,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -533,6 +552,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.camera.shift_view(y_dist=-1) self.camera.shift_view(y_dist=-1)
else: else:
# no interesting event -> no re-painting # no interesting event -> no re-painting
self._last_view = remember_last_view
return return
self._paint_ignore_busy() self._paint_ignore_busy()
...@@ -557,6 +577,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -557,6 +577,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
if event.get_time() - self.mouse["event_timestamp"] < 40: if event.get_time() - self.mouse["event_timestamp"] < 40:
return return
elif state & self.mouse["button"] & BUTTON_ZOOM: elif state & self.mouse["button"] & BUTTON_ZOOM:
self._last_view = None
# the start button is still active: update the view # the start button is still active: update the view
start_x, start_y = self.mouse["start_pos"] start_x, start_y = self.mouse["start_pos"]
self.mouse["start_pos"] = [x, y] self.mouse["start_pos"] = [x, y]
...@@ -573,6 +594,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -573,6 +594,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self._paint_ignore_busy() self._paint_ignore_busy()
elif (state & self.mouse["button"] & BUTTON_MOVE) \ elif (state & self.mouse["button"] & BUTTON_MOVE) \
or (state & self.mouse["button"] & BUTTON_ROTATE): or (state & self.mouse["button"] & BUTTON_ROTATE):
self._last_view = None
start_x, start_y = self.mouse["start_pos"] start_x, start_y = self.mouse["start_pos"]
self.mouse["start_pos"] = [x, y] self.mouse["start_pos"] = [x, y]
if (state & BUTTON_MOVE): if (state & BUTTON_MOVE):
...@@ -601,10 +623,12 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -601,10 +623,12 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
@gtkgl_functionwrapper @gtkgl_functionwrapper
@gtkgl_refresh @gtkgl_refresh
def rotate_view(self, widget=None, view=None): def rotate_view(self, widget=None, view=None):
if view:
self._last_view = view.copy()
self.camera.set_view(view) self.camera.set_view(view)
def reset_view(self): def reset_view(self):
self.rotate_view(None, None) self.rotate_view(view=None)
@check_busy @check_busy
@gtkgl_functionwrapper @gtkgl_functionwrapper
......
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