Ejemplo n.º 1
0
	def execute(self, app):
		#print("go!")
		blocks  = []
		for bid in app.editor.getSelectedBlocks():
			if len(app.gcode.toPath(bid)) < 1: continue
			path = app.gcode.toPath(bid)[0]
			x,y = path.center()
			eblock = Block("center of "+app.gcode[bid].name())
			eblock.append("G0 x"+str(x)+" y"+str(y))
			eblock.append("G1 Z0 F200")
			eblock.append("G0 Z10")
			blocks.append(eblock)


		#active = app.activeBlock()
		#if active == 0: active+=1
		active=-1 #add to end
		app.gcode.insBlocks(active, blocks, "Center created") #<<< insert blocks over active block in the editor
		app.refresh()                                                                                           #<<< refresh editor
		app.setStatus(_("Generated: Center"))                           #<<< feed back result
Ejemplo n.º 2
0
    def execute(self, app):
        # info =xnew,ynew,znew,dxy,dz

        xscale = self["xscale"]
        if xscale == "": xscale = 1
        yscale = self["yscale"]
        if yscale == "": yscale = 1
        zscale = self["zscale"]
        if zscale == "": zscale = 1

        surface = CNC.vars["surface"]
        if zscale > 0:
            surface *= zscale

        feed = self["feed"]
        zfeed = CNC.vars["cutfeedz"]
        rpm = self["rpm"]
        if self["zfeed"]:
            zfeed = self["zfeed"]

        #zup = self["zup"]

        centered = self["centered"]

        #		zbeforecontact=surface+CNC.vars["zretract"]
        #		hardcrust = surface - CNC.vars["hardcrust"]
        #		feedbeforecontact = CNC.vars["feedbeforecontact"]/100.0
        #		hardcrustfeed = CNC.vars["hardcrustfeed"]/100.0

        # Get selected blocks from editor

        selBlocks = app.editor.getSelectedBlocks()
        if not selBlocks:
            app.setStatus(_("Scaling abort: Please select some path"))
            return
        elements = len(app.editor.getSelectedBlocks())
        print("elements", elements)
        for bid in app.editor.getSelectedBlocks():
            if len(app.gcode.toPath(bid)) < 1: continue
            path = app.gcode.toPath(bid)[0]
            if centered:
                center = path.center()
            else:
                center = 0, 0
        print("center", center[0], center[1])
        #	if elements>=2:
        #		center=0,0

        #Get all segments from gcode
        allSegments = self.extractAllSegments(app, selBlocks)[0]
        name_block = self.extractAllSegments(app, selBlocks)[1]
        #		num_block = self.extractAllSegments(app,selBlocks)[2]

        #Create holes locations
        all_blocks = []
        for bidSegment in allSegments:
            if len(bidSegment) == 0:
                continue
    #		all_blocks = []
            n = self["name"]
            #		if not n or n=="default": n="Trochoidal_3D"
            if elements > 1:
                n = "scale "
            else:
                if centered:
                    n = "center scale " + str(name_block)
                else:
                    n = "scale " + str(name_block)
            bid_block = Block(n)

            for idx, segm in enumerate(bidSegment):
                #			if idx >= 0:
                #			bid_block.append("(idx "+str(idx)+" -------------- )")
                info = self.scaling(segm, center, xscale, yscale, zscale)
                if idx == 0:
                    bid_block.append("(---- Scale (x " + str(xscale) +
                                     " : 1.0),(y " + str(yscale) +
                                     " : 1.0),(z " + str(zscale) +
                                     " : 1.0) ---- )")
                    bid_block.append("(center " + str(center[0]) + " ," +
                                     str(center[1]) + " )")
                    bid_block.append("M03")
                    bid_block.append("S " + str(rpm))
                    bid_block.append(CNC.zsafe())
                    bid_block.append("F " + str(zfeed))
                    bid_block.append("g0 x " + str(info[0]) + " y " +
                                     str(info[1]))
                    currentfeed = oldfeed = zfeed
                else:
                    #	if B[5]>=0: #<< zsign
                    #		currentfeed=feed
                    #	else:
                    #relationship
                    if info[4] >= 0:
                        currentfeed = feed
                    else:
                        rel = info[3] / (info[3] + abs(info[4]))
                        currentfeed = int(rel * feed + (1 - rel) * zfeed)

                    if segm[0][2] > surface and segm[1][2] >= surface:
                        bid_block.append("g0 x " + str(info[0]) + " y " +
                                         str(info[1]) + " z " + str(info[2]))
                    else:
                        if currentfeed != oldfeed:
                            bid_block.append("F " + str(currentfeed))
                        bid_block.append("g1 x " + str(info[0]) + " y " +
                                         str(info[1]) + " z " + str(info[2]))
                    oldfeed = currentfeed

            bid_block.append(CNC.zsafe(
            ))  #<<< Move rapid Z axis to the safe height in Stock Material
            all_blocks.append(bid_block)
#			print "bid", bid_block.name(), bid_block,"*****************"
        self.finish_blocks(app, all_blocks, elements)
Ejemplo n.º 3
0
	def execute(self, app):
		# info =xnew,ynew,znew,dxy,dz

		xscale= self["xscale"]
		if xscale=="":xscale=1
		yscale= self["yscale"]
		if yscale=="":yscale=1
		zscale= self["zscale"]
		if zscale=="":zscale=1

		surface = CNC.vars["surface"]
		if zscale>0:
			surface*=zscale

		feed = self["feed"]
		zfeed = CNC.vars["cutfeedz"]
		rpm = self["rpm"]
		if self["zfeed"]:
				zfeed = self["zfeed"]

		#zup = self["zup"]


		centered = self["centered"]

#		zbeforecontact=surface+CNC.vars["zretract"]
#		hardcrust = surface - CNC.vars["hardcrust"]
#		feedbeforecontact = CNC.vars["feedbeforecontact"]/100.0
#		hardcrustfeed = CNC.vars["hardcrustfeed"]/100.0

		# Get selected blocks from editor

		selBlocks = app.editor.getSelectedBlocks()
		if not selBlocks:
			app.setStatus(_("Scaling abort: Please select some path"))
			return 
		elements=len(app.editor.getSelectedBlocks())
		print("elements",elements)
		for bid in app.editor.getSelectedBlocks():
				if len(app.gcode.toPath(bid)) < 1: continue
				path = app.gcode.toPath(bid)[0]
				if centered:
					center = path.center()
				else:
					center=0,0
		print ("center",center[0],center[1])
	#	if elements>=2:
	#		center=0,0


		#Get all segments from gcode
		allSegments = self.extractAllSegments(app,selBlocks)[0]
		name_block = self.extractAllSegments(app,selBlocks)[1]
#		num_block = self.extractAllSegments(app,selBlocks)[2]

		#Create holes locations
		all_blocks=[]
		for bidSegment in allSegments:
			if len(bidSegment)==0:
				continue
	#		all_blocks = []
			n = self["name"]
	#		if not n or n=="default": n="Trochoidal_3D"
			if elements>1:
				n="scale "
			else:
				if centered:
					n="center scale "+str(name_block)
				else:
					n="scale "+str(name_block)
			bid_block = Block(n)

			for idx, segm in enumerate(bidSegment):
	#			if idx >= 0:
	#			bid_block.append("(idx "+str(idx)+" -------------- )")
				info=self.scaling(segm,center,xscale,yscale,zscale)
				if idx == 0:
					bid_block.append("(---- Scale (x "+str(xscale)+" : 1.0),(y "+str(yscale)+" : 1.0),(z "+str(zscale)+" : 1.0) ---- )")
					bid_block.append("(center "+str(center[0])+" ,"+str(center[1])+" )")
					bid_block.append("M03")
					bid_block.append("S "+str(rpm))
					bid_block.append(CNC.zsafe())
					bid_block.append("F "+str(zfeed))
					bid_block.append("g0 x "+str(info[0])+" y "+str(info[1]))
					currentfeed=oldfeed=zfeed
				else:
				#	if B[5]>=0: #<< zsign
				#		currentfeed=feed
				#	else:
					#relationship
					if info[4]>=0:
						currentfeed=feed
					else:
						rel=info[3]/(info[3]+abs(info[4])) 
						currentfeed=int(rel*feed+(1-rel)*zfeed)

					if segm[0][2]> surface and segm[1][2]>=surface:
						bid_block.append("g0 x "+str(info[0])+" y "+str(info[1])+ " z "+str(info[2]))
					else:
						if currentfeed!=oldfeed:
							bid_block.append("F "+str(currentfeed))
						bid_block.append("g1 x "+str(info[0])+" y "+str(info[1])+ " z "+str(info[2]))
					oldfeed=currentfeed

			bid_block.append(CNC.zsafe()) 			#<<< Move rapid Z axis to the safe height in Stock Material
			all_blocks.append(bid_block)
#			print "bid", bid_block.name(), bid_block,"*****************"
		self.finish_blocks(app, all_blocks,elements)