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