Commit 6f2d0362 authored by sumpfralle's avatar sumpfralle

r570@erker: lars | 2010-02-03 11:55:23 +0100

 implemented rotation and transformation of model


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@93 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent f423901d
......@@ -78,7 +78,7 @@ class Model:
model.append(s)
return model
def reset_cache(self):
def _reset_cache(self):
self.minx = None
self.miny = None
self.minz = None
......@@ -101,6 +101,5 @@ class Model:
point.x = x
point.y = y
point.z = z
tr.reset_cache()
self.reset_cache()
self._reset_cache()
......@@ -14,12 +14,12 @@ GTKBUILD_FILE = os.path.join(os.path.dirname(__file__), "gtk-interface", "pycam-
def gtkgl_functionwrapper(function):
def decorated(self, widget, *args, **kwords):
def decorated(self, *args, **kwords):
gldrawable=self.area.get_gl_drawable()
glcontext=self.area.get_gl_context()
if not gldrawable.gl_begin(glcontext):
return
function(self, widget, *args, **kwords)
function(self, *args, **kwords)
gldrawable.gl_end()
return decorated # TODO: make this a well behaved decorator (keeping name, docstring etc)
......@@ -89,17 +89,20 @@ class GLView:
def _realize(self, widget):
self.glsetup()
@gtkgl_functionwrapper
def _expose_event(self, widget, event):
self._gl_clear()
self.paint()
self._gl_finish()
@gtkgl_functionwrapper
def _resize_window(self, widget, data=None):
GL.glViewport(0, 0, widget.allocation.width, widget.allocation.height)
def paint(self):
self._gl_clear()
self._paint()
self._gl_finish()
@gtkgl_functionwrapper
def _paint(self, widget=None):
GuiCommon.draw_complete_model_view(self.settings)
......@@ -141,6 +144,26 @@ class ProjectGui:
# connect the "Bounds" action
self.gui.get_object("Minimize bounds").connect("clicked", self.minimize_bounds)
self.gui.get_object("Reset bounds").connect("clicked", self.reset_bounds)
# Transformations
self.gui.get_object("Rotate").connect("clicked", self.transform_model)
self.gui.get_object("Flip").connect("clicked", self.transform_model)
self.gui.get_object("Swap").connect("clicked", self.transform_model)
def transform_model(self, widget):
if widget.get_name() == "Rotate":
controls = (("x-axis", "x"), ("y-axis", "y"), ("z-axis", "z"))
elif widget.get_name() == "Flip":
controls = (("xy-plane", "xy"), ("xz-plane", "xz"), ("yz-plane", "yz"))
elif widget.get_name() == "Swap":
controls = (("x <-> y", "x_swap_y"), ("x <-> z", "x_swap_z"), ("y <-> z", "y_swap_z"))
else:
# broken gui
print sys.stderr, "Unknown button action: %s" % str(widget.get_name())
return
for obj, value in controls:
if self.gui.get_object(obj).get_active():
GuiCommon.transform_model(self.model, value)
self.view3d.paint()
def minimize_bounds(self, widget, data=None):
# be careful: this depends on equal names of "settings" keys and "model" variables
......
......@@ -12,6 +12,18 @@ VIEW_ROTATIONS = {
"bottom": [(180, 1.0, 0, 0)],
}
MODEL_TRANSFORMATIONS = {
"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)),
"y": ((0, 0, -1, 0), (0, 1, 0, 0), (1, 0, 0, 0)),
"z": ((0, 1, 0, 0), (-1, 0, 0, 0), (0, 0, 1, 0)),
"xy": ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, -1, 0)),
"xz": ((1, 0, 0, 0), (0, -1, 0, 0), (0, 0, 1, 0)),
"yz": ((-1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0)),
"x_swap_y": ((0, 1, 0, 0), (1, 0, 0, 0), (0, 0, 1, 0)),
"x_swap_z": ((0, 0, 1, 0), (0, 1, 0, 0), (1, 0, 0, 0)),
"y_swap_z": ((1, 0, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0)),
}
def draw_string(x, y, z, p, s, scale=.01):
GL.glPushMatrix()
......@@ -136,4 +148,6 @@ def left_view(scale):
def right_view(scale):
rotate_view(scale, rotation=VIEW_ROTATIONS["right"])
def transform_model(model, direction="normal"):
model.transform(MODEL_TRANSFORMATIONS[direction])
......@@ -126,7 +126,7 @@
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkRadioButton" id="xy">
<object class="GtkRadioButton" id="xy-plane">
<property name="label" translatable="yes">xy-plane</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
......@@ -141,13 +141,13 @@
</packing>
</child>
<child>
<object class="GtkRadioButton" id="xz">
<object class="GtkRadioButton" id="xz-plane">
<property name="label" translatable="yes">xz-plane</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<property name="group">xy</property>
<property name="group">xy-plane</property>
</object>
<packing>
<property name="expand">False</property>
......@@ -156,13 +156,13 @@
</packing>
</child>
<child>
<object class="GtkRadioButton" id="yz">
<object class="GtkRadioButton" id="yz-plane">
<property name="label" translatable="yes">yz-plane</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<property name="group">xy</property>
<property name="group">xy-plane</property>
</object>
<packing>
<property name="expand">False</property>
......
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