Commit 34077802 authored by sumpfralle's avatar sumpfralle

added a common base class for all path processors


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@836 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d2961f69
......@@ -50,7 +50,7 @@ class EngraveCutter:
self.pa_push = path_processor
# We use a separated path processor for the last "drop" layer.
# This path processor does not need to be configurable.
self.pa_drop = pycam.PathProcessors.PathAccumulator()
self.pa_drop = pycam.PathProcessors.PathAccumulator.PathAccumulator()
self.physics = physics
def GenerateToolPath(self, minz, maxz, horiz_step, dz, draw_callback=None):
......
......@@ -23,13 +23,17 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry.Point import Point
from pycam.PathGenerators import get_free_paths_ode, get_free_paths_triangles
import pycam.PathProcessors.PathAccumulator
import pycam.PathProcessors
from pycam.Geometry.utils import epsilon, ceil
from pycam.Utils.threading import run_in_parallel
from pycam.Utils import ProgressCounter
import pycam.Utils.log
import math
log = pycam.Utils.log.get_logger()
# We need to use a global function here - otherwise it does not work with
# the multiprocessing Pool.
def _process_one_line((p1, p2, depth, models, cutter, physics)):
......@@ -91,7 +95,7 @@ class PushCutter:
other_models = self.models[1:]
# TODO: this is complicated and hacky :(
# we don't use parallelism or ODE (for the sake of simplicity)
final_pa = pycam.PathProcessors.SimpleCutter()
final_pa = pycam.PathProcessors.SimpleCutter.SimpleCutter()
for path in self.pa.paths:
final_pa.new_scanline()
pairs = []
......
......@@ -20,11 +20,12 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.PathProcessors
from pycam.Geometry.PolygonExtractor import PolygonExtractor
from pycam.Geometry.Point import Point
from pycam.Toolpath import simplify_toolpath
class ContourCutter:
class ContourCutter(pycam.PathProcessors.BasePathProcessor):
def __init__(self, reverse=False):
self.paths = []
self.curr_path = None
......
......@@ -21,11 +21,12 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.PathProcessors
from pycam.Toolpath import simplify_toolpath
from pycam.Geometry.Path import Path
class PathAccumulator:
class PathAccumulator(pycam.PathProcessors.BasePathProcessor):
def __init__(self, zigzag=False, reverse=False):
self.paths = []
self.curr_path = None
......@@ -41,9 +42,6 @@ class PathAccumulator:
def new_direction(self, direction):
self.scanline = 0
def end_direction(self):
pass
def new_scanline(self):
self.scanline += 1
if self.curr_path:
......@@ -60,6 +58,3 @@ class PathAccumulator:
self.paths.append(self.curr_path)
self.curr_path = None
def finish(self):
pass
......@@ -21,12 +21,13 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.PathProcessors
from pycam.Geometry.Path import Path
from pycam.Geometry.PolygonExtractor import PolygonExtractor
from pycam.Toolpath import simplify_toolpath
class PolygonCutter:
class PolygonCutter(pycam.PathProcessors.BasePathProcessor):
def __init__(self, reverse=False):
self.paths = []
self.curr_path = None
......
......@@ -20,10 +20,11 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.PathProcessors
from pycam.Geometry.Path import Path
from pycam.Toolpath import simplify_toolpath
class SimpleCutter:
class SimpleCutter(pycam.PathProcessors.BasePathProcessor):
def __init__(self, reverse=False):
self.paths = []
self.curr_path = None
......@@ -46,12 +47,6 @@ class SimpleCutter:
else:
self.paths.append(curr_path)
def new_direction(self, direction):
pass
def end_direction(self):
pass
def new_scanline(self):
if self.curr_path:
print "ERROR: curr_path expected to be empty"
......@@ -62,5 +57,3 @@ class SimpleCutter:
print "ERROR: curr_path expected to be empty"
self.curr_path = None
def finish(self):
pass
......@@ -20,10 +20,11 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.PathProcessors
from pycam.Geometry.Path import Path
from pycam.Toolpath import simplify_toolpath
class ZigZagCutter:
class ZigZagCutter(pycam.PathProcessors.BasePathProcessor):
def __init__(self, reverse=False):
self.paths = []
self.curr_path = None
......@@ -52,9 +53,6 @@ class ZigZagCutter:
def new_direction(self, direction):
self.scanline = 0
def end_direction(self):
pass
def new_scanline(self):
self.scanline += 1
self.curr_scanline = []
......@@ -67,6 +65,3 @@ class ZigZagCutter:
self.paths.append(path)
self.curr_scanline = None
def finish(self):
pass
......@@ -21,11 +21,17 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
__all__ = ["PathAccumulator", "SimpleCutter", "ZigZagCutter", "PolygonCutter",
"ContourCutter"]
"ContourCutter", "BasePathProcessor"]
from pycam.PathProcessors.PathAccumulator import PathAccumulator
from pycam.PathProcessors.SimpleCutter import SimpleCutter
from pycam.PathProcessors.ZigZagCutter import ZigZagCutter
from pycam.PathProcessors.PolygonCutter import PolygonCutter
from pycam.PathProcessors.ContourCutter import ContourCutter
class BasePathProcessor(object):
def new_direction(self, direction):
pass
def end_direction(self):
pass
def finish(self):
pass
......@@ -23,7 +23,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.PathGenerators import DropCutter, PushCutter, EngraveCutter, \
ContourFollow
from pycam.Geometry.utils import number
import pycam.PathProcessors
from pycam.PathProcessors import PathAccumulator, SimpleCutter, ZigZagCutter, \
PolygonCutter, ContourCutter
import pycam.Cutters
import pycam.Toolpath.SupportGrid
import pycam.Toolpath.MotionGrid
......@@ -318,9 +319,9 @@ def _get_pathgenerator_instance(trimesh_models, contour_model, cutter,
+ "is 'Engraving'.")
if pathgenerator == "DropCutter":
if pathprocessor == "ZigZagCutter":
processor = pycam.PathProcessors.PathAccumulator(zigzag=True)
processor = PathAccumulator.PathAccumulator(zigzag=True)
elif pathprocessor == "PathAccumulator":
processor = pycam.PathProcessors.PathAccumulator()
processor = PathAccumulator.PathAccumulator()
else:
return ("Invalid postprocessor (%s) for 'DropCutter': only " \
+ "'ZigZagCutter' or 'PathAccumulator' are allowed") \
......@@ -329,15 +330,15 @@ def _get_pathgenerator_instance(trimesh_models, contour_model, cutter,
physics=physics)
elif pathgenerator == "PushCutter":
if pathprocessor == "PathAccumulator":
processor = pycam.PathProcessors.PathAccumulator()
processor = PathAccumulator.PathAccumulator()
elif pathprocessor == "SimpleCutter":
processor = pycam.PathProcessors.SimpleCutter()
processor = SimpleCutter.SimpleCutter()
elif pathprocessor == "ZigZagCutter":
processor = pycam.PathProcessors.ZigZagCutter()
processor = ZigZagCutter.ZigZagCutter()
elif pathprocessor == "PolygonCutter":
processor = pycam.PathProcessors.PolygonCutter()
processor = PolygonCutter.PolygonCutter()
elif pathprocessor == "ContourCutter":
processor = pycam.PathProcessors.ContourCutter()
processor = ContourCutter.ContourCutter()
else:
return ("Invalid postprocessor (%s) for 'PushCutter' - it should " \
+ "be one of these: %s") % (pathprocessor, PATH_POSTPROCESSORS)
......@@ -346,7 +347,7 @@ def _get_pathgenerator_instance(trimesh_models, contour_model, cutter,
elif pathgenerator == "EngraveCutter":
reverse = (milling_style == "conventional")
if pathprocessor == "SimpleCutter":
processor = pycam.PathProcessors.SimpleCutter(reverse=reverse)
processor = SimpleCutter.SimpleCutter(reverse=reverse)
else:
return ("Invalid postprocessor (%s) for 'EngraveCutter' - it " \
+ "should be: SimpleCutter") % str(pathprocessor)
......@@ -358,7 +359,7 @@ def _get_pathgenerator_instance(trimesh_models, contour_model, cutter,
elif pathgenerator == "ContourFollow":
reverse = (milling_style == "conventional")
if pathprocessor == "SimpleCutter":
processor = pycam.PathProcessors.SimpleCutter(reverse=reverse)
processor = SimpleCutter.SimpleCutter(reverse=reverse)
else:
return ("Invalid postprocessor (%s) for 'ContourFollow' - it " \
+ "should be: SimpleCutter") % str(pathprocessor)
......
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