diff --git a/scripts/addons/cam/__init__.py b/scripts/addons/cam/__init__.py index 2c02d216..804e40b6 100644 --- a/scripts/addons/cam/__init__.py +++ b/scripts/addons/cam/__init__.py @@ -31,7 +31,7 @@ from bpy.types import Menu, Operator, UIList, AddonPreferences #from . import patterns #from . import chunk_operations -from cam import ui, ops,utils, simple,polygon_utils_cam#, post_processors +from cam import ui, ops, utils, simple, polygon_utils_cam#, post_processors import numpy import Polygon from bpy.app.handlers import persistent diff --git a/scripts/addons/cam/utils.py b/scripts/addons/cam/utils.py index bde4e6a6..d2ce3127 100644 --- a/scripts/addons/cam/utils.py +++ b/scripts/addons/cam/utils.py @@ -2058,228 +2058,235 @@ def addBridges(ch,o): ch.points[p[0]]=p[1] for pi in range(len(insertpoints)-1,-1,-1): ch.points.insert(insertpoints[pi][0],insertpoints[pi][1]) + +###########cutout strategy is completely here: +def strategy_cutout( o ): + #ob=bpy.context.active_object + print('operation: cutout') + offset=True + if o.cut_type=='ONLINE' and o.onlycurves==True:#is separate to allow open curves :) + print('separate') + chunksFromCurve=[] + for ob in o.objects: + chunksFromCurve.extend(curveToChunks(ob)) + p=Polygon.Polygon() + for ch in chunksFromCurve: + #print(ch.points) + + if len(ch.points)>2: + ch.poly=chunkToPoly(ch) + #p.addContour(ch.poly) + else: + chunksFromCurve=[] + if o.cut_type=='ONLINE': + p=getObjectOutline(0,o,True) + + else: + offset=True + if o.cut_type=='INSIDE': + offset=False + p=getObjectOutline(o.cutter_diameter/2,o,offset) + if o.outlines_count>1: + for i in range(1,o.outlines_count): + chunksFromCurve.extend(polyToChunks(p,-1)) + p=outlinePoly(p,o.dist_between_paths,o.circle_detail,o.optimize,o.optimize_threshold,offset) + + + chunksFromCurve.extend(polyToChunks(p,-1)) + if o.outlines_count>1 and o.movement_insideout=='OUTSIDEIN': + chunksFromCurve.reverse() + #parentChildPoly(chunksFromCurve,chunksFromCurve,o) + chunksFromCurve=limitChunks(chunksFromCurve,o) + parentChildPoly(chunksFromCurve,chunksFromCurve,o) + if o.outlines_count==1: + chunksFromCurve=sortChunks(chunksFromCurve,o) + + #if o.outlines_count>0 and o.cut_type!='ONLINE' and o.movement_insideout=='OUTSIDEIN':#reversing just with more outlines + # chunksFromCurve.reverse() + + if (o.movement_type=='CLIMB' and o.spindle_rotation_direction=='CCW') or (o.movement_type=='CONVENTIONAL' and o.spindle_rotation_direction=='CW'): + for ch in chunksFromCurve: + ch.points.reverse() + + if o.cut_type=='INSIDE':#there would bee too many conditions above, so for now it gets reversed once again when inside cutting. + for ch in chunksFromCurve: + ch.points.reverse() + + + if o.use_layers: + layers=[] + n=math.ceil((o.maxz-o.min.z)/o.stepdown) + layerstart=o.maxz + for x in range(0,n): + layerend=max(o.maxz-((x+1)*o.stepdown),o.min.z) + if int(layerstart*10**8)!=int(layerend*10**8):#it was possible that with precise same end of operation, last layer was done 2x on exactly same level... + layers.append([layerstart,layerend]) + layerstart=layerend + else: + layers=[[o.maxz,o.min.z]] + + print(layers) + extendorder=[] + if o.first_down:#each shape gets either cut all the way to bottom, or every shape gets cut 1 layer, then all again. has to create copies, because same chunks are worked with on more layers usually + for chunk in chunksFromCurve: + for layer in layers: + extendorder.append([chunk.copy(),layer]) + else: + for layer in layers: + for chunk in chunksFromCurve: + extendorder.append([chunk.copy(),layer]) + + for chl in extendorder:#Set Z for all chunks + chunk=chl[0] + layer=chl[1] + print(layer[1]) + chunk.setZ(layer[1]) + + chunks=[] + + if o.use_bridges:#add bridges to chunks + #bridges=getBridges(p,o) + bridgeheight=min(0,o.min.z+o.bridges_height) + for chl in extendorder: + chunk=chl[0] + layer=chl[1] + if layer[1]2: - ch.poly=chunkToPoly(ch) - #p.addContour(ch.poly) - else: - chunksFromCurve=[] - if o.cut_type=='ONLINE': - p=getObjectOutline(0,o,True) - - else: - offset=True - if o.cut_type=='INSIDE': - offset=False - p=getObjectOutline(o.cutter_diameter/2,o,offset) - if o.outlines_count>1: - for i in range(1,o.outlines_count): - chunksFromCurve.extend(polyToChunks(p,-1)) - p=outlinePoly(p,o.dist_between_paths,o.circle_detail,o.optimize,o.optimize_threshold,offset) - - - chunksFromCurve.extend(polyToChunks(p,-1)) - if o.outlines_count>1 and o.movement_insideout=='OUTSIDEIN': - chunksFromCurve.reverse() - #parentChildPoly(chunksFromCurve,chunksFromCurve,o) - chunksFromCurve=limitChunks(chunksFromCurve,o) - parentChildPoly(chunksFromCurve,chunksFromCurve,o) - if o.outlines_count==1: - chunksFromCurve=sortChunks(chunksFromCurve,o) + strategy_cutout( o ) - #if o.outlines_count>0 and o.cut_type!='ONLINE' and o.movement_insideout=='OUTSIDEIN':#reversing just with more outlines - # chunksFromCurve.reverse() - - if (o.movement_type=='CLIMB' and o.spindle_rotation_direction=='CCW') or (o.movement_type=='CONVENTIONAL' and o.spindle_rotation_direction=='CW'): - for ch in chunksFromCurve: - ch.points.reverse() - - if o.cut_type=='INSIDE':#there would bee too many conditions above, so for now it gets reversed once again when inside cutting. - for ch in chunksFromCurve: - ch.points.reverse() - - - if o.use_layers: - layers=[] - n=math.ceil((o.maxz-o.min.z)/o.stepdown) - layerstart=o.maxz - for x in range(0,n): - layerend=max(o.maxz-((x+1)*o.stepdown),o.min.z) - if int(layerstart*10**8)!=int(layerend*10**8):#it was possible that with precise same end of operation, last layer was done 2x on exactly same level... - layers.append([layerstart,layerend]) - layerstart=layerend - else: - layers=[[o.maxz,o.min.z]] - - print(layers) - extendorder=[] - if o.first_down:#each shape gets either cut all the way to bottom, or every shape gets cut 1 layer, then all again. has to create copies, because same chunks are worked with on more layers usually - for chunk in chunksFromCurve: - for layer in layers: - extendorder.append([chunk.copy(),layer]) - else: - for layer in layers: - for chunk in chunksFromCurve: - extendorder.append([chunk.copy(),layer]) - - for chl in extendorder:#Set Z for all chunks - chunk=chl[0] - layer=chl[1] - print(layer[1]) - chunk.setZ(layer[1]) - - chunks=[] - - if o.use_bridges:#add bridges to chunks - #bridges=getBridges(p,o) - bridgeheight=min(0,o.min.z+o.bridges_height) - for chl in extendorder: - chunk=chl[0] - layer=chl[1] - if layer[1]