Commit 7aa44e0a authored by Lars Kruse's avatar Lars Kruse

implement toolpath grid plugin with another filter

parent e37feb5b
...@@ -53,7 +53,7 @@ def pcmp(a,b): ...@@ -53,7 +53,7 @@ def pcmp(a,b):
else: else:
return cmp(a[2], b[2]) return cmp(a[2], b[2])
def ptransform_by_matrix(a, matrix, transformed_list=None): def ptransform_by_matrix(a, matrix):
if len(a) > 3: if len(a) > 3:
return (a[0] * matrix[0][0] + a[1] * matrix[0][1] + a[2] * matrix[0][2], return (a[0] * matrix[0][0] + a[1] * matrix[0][1] + a[2] * matrix[0][2],
a[0] * matrix[1][0] + a[1] * matrix[1][1] + a[2] * matrix[1][2], a[0] * matrix[1][0] + a[1] * matrix[1][1] + a[2] * matrix[1][2],
......
...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins import pycam.Plugins
from pycam.Geometry.PointUtils import * from pycam.Geometry.PointUtils import *
import pycam.Toolpath.Filters
class ToolpathGrid(pycam.Plugins.PluginBase): class ToolpathGrid(pycam.Plugins.PluginBase):
...@@ -94,19 +95,20 @@ class ToolpathGrid(pycam.Plugins.PluginBase): ...@@ -94,19 +95,20 @@ class ToolpathGrid(pycam.Plugins.PluginBase):
y_space = self.gui.get_object("GridYDistance").get_value() y_space = self.gui.get_object("GridYDistance").get_value()
x_dim, y_dim = self._get_toolpaths_dim(toolpaths) x_dim, y_dim = self._get_toolpaths_dim(toolpaths)
for toolpath in toolpaths: for toolpath in toolpaths:
new_paths = [] new_path = list(toolpath.path)
for x in range(x_count): for x in range(x_count):
for y in range(y_count): for y in range(y_count):
shift = (x * (x_space + x_dim), y * (y_space + y_dim), 0, 'v') shift_x = x * (x_space + x_dim)
for index in len(toolpath.paths): shift_y = y * (y_space + y_dim)
new_path = [shift.add(p) for p in toolpath.paths[index]] shift_filter = pycam.Toolpath.Filters.TransformPosition((
new_paths.append(new_path) (1, 0, 0, shift_x), (0, 1, 0, shift_y), (0, 0, 1, 0)))
new_path.extend(toolpath.path | shift_filter)
if not self.gui.get_object("KeepOriginal").get_active(): if not self.gui.get_object("KeepOriginal").get_active():
toolpath.paths = new_paths toolpath.path = new_path
self.core.emit_event("toolpath-changed") self.core.emit_event("toolpath-changed")
else: else:
new_toolpath = toolpath.copy() new_toolpath = toolpath.copy()
new_toolpath.paths = new_paths new_toolpath.path = new_path
self.core.get("toolpaths").append(new_toolpath) self.core.get("toolpaths").append(new_toolpath)
self.core.get("toolpaths").select(toolpaths) self.core.get("toolpaths").select(toolpaths)
...@@ -22,7 +22,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,7 +22,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Toolpath import MOVE_STRAIGHT, MOVE_STRAIGHT_RAPID, MOVE_SAFETY, MACHINE_SETTING from pycam.Toolpath import MOVE_STRAIGHT, MOVE_STRAIGHT_RAPID, MOVE_SAFETY, MACHINE_SETTING
from pycam.Geometry.PointUtils import psub, pdist from pycam.Geometry.PointUtils import psub, pdist, ptransform_by_matrix
from pycam.Geometry.Line import Line from pycam.Geometry.Line import Line
from pycam.Geometry.utils import epsilon from pycam.Geometry.utils import epsilon
import pycam.Utils.log import pycam.Utils.log
...@@ -177,3 +177,18 @@ class Crop(BaseFilter): ...@@ -177,3 +177,18 @@ class Crop(BaseFilter):
new_path.append((move_type, args)) new_path.append((move_type, args))
return new_path return new_path
class TransformPosition(BaseFilter):
PARAMS = ("matrix", )
def filter_toolpath(self, toolpath):
new_path = []
for move_type, args in toolpath:
if move_type in (MOVE_STRAIGHT, MOVE_STRAIGHT_RAPID):
new_pos = ptransform_by_matrix(args, self.settings["matrix"])
new_path.append((move_type, new_pos))
else:
new_path.append((move_type, args))
return new_path
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