def execute(self, app): blocks = [] for bid in app.editor.getSelectedBlocks(): if len(app.gcode.toPath(bid)) < 1: continue eblock = Block("closed " + app.gcode[bid].name()) for path in app.gcode.toPath(bid): if not path.isClosed(): path.append(Segment(Segment.LINE, path[-1].B, path[0].A)) eblock = app.gcode.fromPath(path, eblock) #blocks.append(eblock) app.gcode[bid] = eblock #active=-1 #add to end #app.gcode.insBlocks(active, blocks, "Path closed") #<<< insert blocks over active block in the editor app.refresh() #<<< refresh editor app.setStatus(_("Generated: Closepath")) #<<< feed back result
def execute(self, app): blocks = [] for bid in app.editor.getSelectedBlocks(): if len(app.gcode.toPath(bid)) < 1: continue eblock = Block("closed "+app.gcode[bid].name()) for path in app.gcode.toPath(bid): if not path.isClosed(): path.append(Segment(Segment.LINE, path[-1].B, path[0].A)) eblock = app.gcode.fromPath(path,eblock) #blocks.append(eblock) app.gcode[bid] = eblock #active=-1 #add to end #app.gcode.insBlocks(active, blocks, "Path closed") #<<< insert blocks over active block in the editor app.refresh() #<<< refresh editor app.setStatus(_("Generated: Closepath")) #<<< feed back result
def pocket(selectedblocks, RecursiveDepth,ProfileDir,CutDir,AdditionalCut,Overcuts, CustomRecursiveDepth, ignoreIslands, allowG1, diameter, stepover, name,gcode,app): undoinfo = [] msg = "" newblocks = [] allblocks = gcode.blocks islandslist = [] outpathslist= [] ignoreIslandschoicedict = { "Regard all islands except tabs":0, "Ignore all islands":1, "Regard only selected islands":2, } ignoreIslandschoice = ignoreIslandschoicedict.get(ignoreIslands,0) for bid,block in enumerate(allblocks):#all blocks if block.operationTest('island')and not block.operationTest('tab'): if ignoreIslandschoice==0: for islandPath in gcode.toPath(bid): islandslist.append(islandPath) for bid in reversed(selectedblocks):#selected blocks if allblocks[bid].name() in ("Header", "Footer"): continue newpath = [] block = allblocks[bid] if block.operationTest('island')and not block.operationTest('tab') and ignoreIslandschoice==2: for islandPath in gcode.toPath(bid): islandslist.append(islandPath) for path in gcode.toPath(bid): if not path.isClosed(): m = "Path: '%s' is OPEN"%(path.name) if m not in msg: if msg: msg += "\n" msg += m path.close() # Remove tiny segments path.removeZeroLength(abs(diameter)/100.) # Convert very small arcs to lines path.convert2Lines(abs(diameter)/10.) if not block.operationTest('island'): outpathslist.append(path) MyPocket = PocketIsland(outpathslist,RecursiveDepth,ProfileDir,CutDir,AdditionalCut, Overcuts,CustomRecursiveDepth, ignoreIslands, allowG1,diameter,stepover,0,app,islandslist) newpathList = MyPocket.getfullpath() #concatenate newpath in a single list and split2contours if allowG1 : MyFullPath = Path("Pocket") for path in newpathList : for seg in path: MyFullPath.append(seg) newpathList = MyFullPath.split2contours() if newpathList: # remember length to shift all new blocks # the are inserted before before = len(newblocks) undoinfo.extend(gcode.importPath(bid+1, newpathList, newblocks, True, False)) new = len(newblocks)-before for i in range(before): newblocks[i] += new allblocks[bid].enable = False gcode.addUndo(undoinfo) # return new blocks inside the blocks list del selectedblocks[:] selectedblocks.extend(newblocks) return msg
def pocket(blocks, allowG1, diameter, stepover, name,gcode,items): undoinfo = [] msg = "" newblocks = [] islandslist = [] for bid,block in enumerate(gcode.blocks): if block.operationTest('island'): for islandPath in gcode.toPath(bid): islandslist.append(islandPath) for bid in reversed(blocks): if gcode.blocks[bid].name() in ("Header", "Footer"): continue newpath = [] for path in gcode.toPath(bid): if not path.isClosed(): m = "Path: '%s' is OPEN"%(path.name) if m not in msg: if msg: msg += "\n" msg += m path.close() # Remove tiny segments path.removeZeroLength(abs(diameter)/100.) # Convert very small arcs to lines path.convert2Lines(abs(diameter)/10.) path.directionSet(1) #turn path to CW (conventional when milling inside) D = path.direction() if D==0: D=1 remove = ["cut","reverse","climb","conventional","cw","ccw","pocket"] if name is None: path.name = Block.operationName(path.name, "pocket,conventional,cw", remove) else: path.name = Block.operationName(path.name, name, remove) MyPocket = PocketIsland([path],allowG1,diameter,stepover,0,islandslist) newpathList = MyPocket.getfullpath() #concatenate newpath in a single list and split2contours if allowG1 : MyFullPath = Path("Pocket") for path in newpathList : for seg in path: MyFullPath.append(seg) newpathList = MyFullPath.split2contours() if newpathList: # remember length to shift all new blocks # the are inserted before before = len(newblocks) undoinfo.extend(gcode.importPath(bid+1, newpathList, newblocks, True, False)) new = len(newblocks)-before for i in range(before): newblocks[i] += new gcode.blocks[bid].enable = False gcode.addUndo(undoinfo) # return new blocks inside the blocks list del blocks[:] blocks.extend(newblocks) return msg