Commit 339d7538 authored by sumpfralle's avatar sumpfralle

moved model manipulation functions from pycam.Gui.common to pycam.Geometry.Model

fixed bug that rendered the model manipulation buttons useless


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@331 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d8699696
...@@ -32,6 +32,21 @@ try: ...@@ -32,6 +32,21 @@ try:
except: except:
GL_enabled = False GL_enabled = False
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)),
}
class Model: class Model:
id = 0 id = 0
...@@ -112,7 +127,7 @@ class Model: ...@@ -112,7 +127,7 @@ class Model:
self._update_limits(t) self._update_limits(t)
self._maxsize = None self._maxsize = None
def transform(self, matrix): def transform_by_matrix(self, matrix):
processed = [] processed = []
for tr in self._triangles: for tr in self._triangles:
for point in (tr.p1, tr.p2, tr.p3): for point in (tr.p1, tr.p2, tr.p3):
...@@ -127,3 +142,19 @@ class Model: ...@@ -127,3 +142,19 @@ class Model:
tr.reset_cache() tr.reset_cache()
self.reset_cache() self.reset_cache()
def transform_by_template(self, direction="normal"):
if direction in MODEL_TRANSFORMATIONS.keys():
self.transform_by_matrix(MODEL_TRANSFORMATIONS[direction])
def shift(self, shift_x, shift_y, shift_z):
matrix = ((1, 0, 0, shift_x), (0, 1, 0, shift_y), (0, 0, 1, shift_z))
self.transform_by_matrix(matrix)
def scale(self, scale_x, scale_y=None, scale_z=None):
if scale_y is None:
scale_y = scale_x
if scale_z is None:
scale_z = scale_x
matrix = ((scale_x, 0, 0, 0), (0, scale_y, 0, 0), (0, 0, scale_z, 0))
self.transform_by_matrix(matrix)
...@@ -27,7 +27,6 @@ import pycam.Exporters.STLExporter ...@@ -27,7 +27,6 @@ import pycam.Exporters.STLExporter
import pycam.Exporters.SimpleGCodeExporter import pycam.Exporters.SimpleGCodeExporter
import pycam.Exporters.EMCToolExporter import pycam.Exporters.EMCToolExporter
import pycam.Gui.Settings import pycam.Gui.Settings
import pycam.Gui.common as GuiCommon
import pycam.Cutters import pycam.Cutters
import pycam.Toolpath.Generator import pycam.Toolpath.Generator
import pycam.Toolpath import pycam.Toolpath
...@@ -681,11 +680,11 @@ class ProjectGui: ...@@ -681,11 +680,11 @@ class ProjectGui:
@gui_activity_guard @gui_activity_guard
def transform_model(self, widget): def transform_model(self, widget):
if widget.get_name() == "Rotate": if widget is self.gui.get_object("Rotate"):
controls = (("x-axis", "x"), ("y-axis", "y"), ("z-axis", "z")) controls = (("x-axis", "x"), ("y-axis", "y"), ("z-axis", "z"))
elif widget.get_name() == "Flip": elif widget is self.gui.get_object("Flip"):
controls = (("xy-plane", "xy"), ("xz-plane", "xz"), ("yz-plane", "yz")) controls = (("xy-plane", "xy"), ("xz-plane", "xz"), ("yz-plane", "yz"))
elif widget.get_name() == "Swap": elif widget is self.gui.get_object("Swap"):
controls = (("x <-> y", "x_swap_y"), ("x <-> z", "x_swap_z"), ("y <-> z", "y_swap_z")) controls = (("x <-> y", "x_swap_y"), ("x <-> z", "x_swap_z"), ("y <-> z", "y_swap_z"))
else: else:
# broken gui # broken gui
...@@ -693,7 +692,7 @@ class ProjectGui: ...@@ -693,7 +692,7 @@ class ProjectGui:
return return
for obj, value in controls: for obj, value in controls:
if self.gui.get_object(obj).get_active(): if self.gui.get_object(obj).get_active():
GuiCommon.transform_model(self.model, value) self.model.transform_by_template(value)
self.update_view() self.update_view()
def _treeview_get_active_index(self, table, datalist): def _treeview_get_active_index(self, table, datalist):
...@@ -962,7 +961,7 @@ class ProjectGui: ...@@ -962,7 +961,7 @@ class ProjectGui:
shift_x = -self.model.minx shift_x = -self.model.minx
shift_y = -self.model.miny shift_y = -self.model.miny
shift_z = -self.model.minz shift_z = -self.model.minz
GuiCommon.shift_model(self.model, shift_x, shift_y, shift_z) self.model.shift(shift_x, shift_y, shift_z)
self.update_view() self.update_view()
def _get_model_center(self): def _get_model_center(self):
...@@ -976,7 +975,7 @@ class ProjectGui: ...@@ -976,7 +975,7 @@ class ProjectGui:
def _set_model_center(self, center): def _set_model_center(self, center):
new_x, new_y, new_z = center new_x, new_y, new_z = center
old_x, old_y, old_z = self._get_model_center() old_x, old_y, old_z = self._get_model_center()
GuiCommon.shift_model(self.model, new_x - old_x, new_y - old_y, new_z - old_z) self.model.shift(new_x - old_x, new_y - old_y, new_z - old_z)
@gui_activity_guard @gui_activity_guard
def scale_model(self, widget=None, percent=None): def scale_model(self, widget=None, percent=None):
...@@ -986,7 +985,7 @@ class ProjectGui: ...@@ -986,7 +985,7 @@ class ProjectGui:
if (factor <= 0) or (factor == 1): if (factor <= 0) or (factor == 1):
return return
old_center = self._get_model_center() old_center = self._get_model_center()
GuiCommon.scale_model(self.model, factor) self.model.scale(factor)
self._set_model_center(old_center) self._set_model_center(old_center)
self.update_view() self.update_view()
...@@ -1019,7 +1018,7 @@ class ProjectGui: ...@@ -1019,7 +1018,7 @@ class ProjectGui:
# store the original center of the model # store the original center of the model
old_center = self._get_model_center() old_center = self._get_model_center()
if proportionally: if proportionally:
GuiCommon.scale_model(self.model, factor) self.model.scale(factor)
else: else:
factor_x, factor_y, factor_z = (1, 1, 1) factor_x, factor_y, factor_z = (1, 1, 1)
if index == 0: if index == 0:
...@@ -1030,7 +1029,7 @@ class ProjectGui: ...@@ -1030,7 +1029,7 @@ class ProjectGui:
factor_z = factor factor_z = factor
else: else:
return return
GuiCommon.scale_model(self.model, factor_x, factor_y, factor_z) self.model.scale(factor_x, factor_y, factor_z)
# move the model to its previous center # move the model to its previous center
self._set_model_center(old_center) self._set_model_center(old_center)
self.update_view() self.update_view()
......
...@@ -26,19 +26,6 @@ import sys ...@@ -26,19 +26,6 @@ import sys
import os import os
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)),
}
DEPENDENCY_DESCRIPTION = { DEPENDENCY_DESCRIPTION = {
"gtk": ("Python bindings for GTK+", "gtk": ("Python bindings for GTK+",
"Install the package 'python-gtk2'", "Install the package 'python-gtk2'",
...@@ -60,21 +47,6 @@ DEPENDENCY_DESCRIPTION = { ...@@ -60,21 +47,6 @@ DEPENDENCY_DESCRIPTION = {
REQUIREMENTS_LINK = "http://sourceforge.net/apps/mediawiki/pycam/index.php?title=Requirements" REQUIREMENTS_LINK = "http://sourceforge.net/apps/mediawiki/pycam/index.php?title=Requirements"
def transform_model(model, direction="normal"):
model.transform(MODEL_TRANSFORMATIONS[direction])
def shift_model(model, shift_x, shift_y, shift_z):
matrix = ((1, 0, 0, shift_x), (0, 1, 0, shift_y), (0, 0, 1, shift_z))
model.transform(matrix)
def scale_model(model, scale_x, scale_y=None, scale_z=None):
if scale_y is None:
scale_y = scale_x
if scale_z is None:
scale_z = scale_x
matrix = ((scale_x, 0, 0, 0), (0, scale_y, 0, 0), (0, 0, scale_z, 0))
model.transform(matrix)
def dependency_details_gtk(): def dependency_details_gtk():
result = {} result = {}
try: try:
......
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