Esempio n. 1
0
	def drawPaths(self):
		if not self.draw_paths:
			for block in self.gcode.blocks:
				block.resetPath()
			return

		self._last = (0.,0.,0.)
		self.initPosition()
		self.cnc.resetAllMargins()
		drawG = self.draw_rapid or self.draw_paths or self.draw_margin
		for i,block in enumerate(self.gcode.blocks):
			start = True	# start location found
			block.resetPath()
			for j,line in enumerate(block):
				#cmd = self.cnc.parseLine(line)
				try:
					cmd = CNC.breakLine(self.gcode.evaluate(CNC.parseLine2(line)))
				except:
					sys.stderr.write(">>> ERROR: %s\n"%(str(sys.exc_info()[1])))
					sys.stderr.write("     line: %s\n"%(line))
					cmd = None

				if cmd is None or not drawG:
					block.addPath(None)
				else:
					path = self.drawPath(block, cmd)
					self._items[path] = i,j
					block.addPath(path)
					if start and self.cnc.gcode in (1,2,3):
						# Mark as start the first non-rapid motion
						block.startPath(self.cnc.x, self.cnc.y, self.cnc.z)
						start = False
			block.endPath(self.cnc.x, self.cnc.y, self.cnc.z)
Esempio n. 2
0
	def draw(self, view=None): #, lines):
		if self._inDraw : return
		self._inDraw  = True

		self._tzoom  = 1.0
		self._tafter = None
		xyz = self.canvas2xyz(
				self.canvasx(self.winfo_width()/2),
				self.canvasy(self.winfo_height()/2))

		if view is not None: self.view = view

		self._last = (0.,0.,0.)
		self.initPosition()
		drawG = self.draw_rapid or self.draw_paths or self.draw_margin
		for i,block in enumerate(self.gcode.blocks):
			block.resetPath()
			start = True	# start location found
			for j,line in enumerate(block):
				#cmd = self.cnc.parseLine(line)
				try:
					cmd = CNC.breakLine(self.gcode.evaluate(CNC.parseLine2(line)))
				except:
					sys.stderr.write(">>> ERROR: %s\n"%(str(sys.exc_info()[1])))
					sys.stderr.write("     line: %s\n"%(line))
					cmd = None

				if cmd is None or not drawG:
					block.addPath(None)
				else:
					path = self.drawPath(cmd, block.enable)
					self._items[path] = i,j
					block.addPath(path)
					if start and self.cnc.gcode in (1,2,3):
						# Mark as start the first non-rapid motion
						block.startPath(self.cnc.x, self.cnc.y, self.cnc.z)
						start = False
			block.endPath(self.cnc.x, self.cnc.y, self.cnc.z)

		self.drawGrid()
		self.drawMargin()
		self.drawWorkarea()
		self.drawProbe()
		self.drawAxes()
#		self.tag_lower(self._workarea)
		if self._gantry1: self.tag_raise(self._gantry1)
		if self._gantry2: self.tag_raise(self._gantry2)
		self._updateScrollBars()

		ij = self.plotCoords([xyz])[0]
		dx = int(round(self.canvasx(self.winfo_width()/2)  - ij[0]))
		dy = int(round(self.canvasy(self.winfo_height()/2) - ij[1]))
		self.scan_mark(0,0)
		self.scan_dragto(int(round(dx)), int(round(dy)), 1)

		self._inDraw  = False
Esempio n. 3
0
	def drawPaths(self):
		if not self.draw_paths:
			for block in self.gcode.blocks:
				block.resetPath()
			return

		self._last = (0.,0.,0.)
		self.initPosition()
		self.cnc.resetAllMargins()
		drawG = self.draw_rapid or self.draw_paths or self.draw_margin
		for i,block in enumerate(self.gcode.blocks):
			start = True	# start location found
			block.resetPath()
			# Draw block tabs
			if self.draw_margin:
				for tab in block.tabs:
					color = block.enable and TAB_COLOR or DISABLE_COLOR
					item = self._drawRect(tab.xmin, tab.ymin, tab.xmax, tab.ymax, 0., fill=color)
					tab.path = item
					self._items[item[0]] = i,tab
					self.tag_lower(item)
			# Draw block
			for j,line in enumerate(block):
				#cmd = self.cnc.parseLine(line)
				try:
					cmd = CNC.breakLine(self.gcode.evaluate(CNC.parseLine2(line)))
				except:
					sys.stderr.write(_(">>> ERROR: %s\n")%(str(sys.exc_info()[1])))
					sys.stderr.write(_("     line: %s\n")%(line))
					cmd = None

				if cmd is None or not drawG:
					block.addPath(None)
				else:
					path = self.drawPath(block, cmd)
					self._items[path] = i,j
					block.addPath(path)
					if start and self.cnc.gcode in (1,2,3):
						# Mark as start the first non-rapid motion
						block.startPath(self.cnc.x, self.cnc.y, self.cnc.z)
						start = False
			block.endPath(self.cnc.x, self.cnc.y, self.cnc.z)
Esempio n. 4
0
    def autolevelBlock(self, block):
        """Expand block with autolevel information"""
        new = []
        autolevel = not self.probe.isEmpty()
        for line in block:
            # newcmd = [] # seems to be not used
            cmds = CNC.compileLine(line)
            if cmds is None:
                new.append(line)
                continue
            elif isinstance(cmds, str):
                cmds = CNC.breakLine(cmds)
            else:
                new.append(line)
                continue

            self.cnc.motionStart(cmds)

            if autolevel and self.cnc.gcode in (0, 1, 2, 3) and\
                  self.cnc.mval == 0:

                xyz = self.cnc.motionPath()

                if not xyz:
                    # while auto-levelling, do not ignore non-movement
                    # commands, just append the line as-is
                    new.append(line)
                else:
                    extra = ""
                    for c in cmds:
                        if c[0].upper() not in (
                            'G', 'X', 'Y', 'Z',
                            'I', 'J', 'K', 'R'):

                            extra += c

                    x1, y1, z1 = xyz[0]

                    if self.cnc.gcode == 0:
                        g = 0
                    else:
                        g = 1

                    for x2, y2, z2 in xyz[1:]:
                        for x, y, z in self.probe.splitLine(
                                x1, y1, z1, x2, y2, z2):

                            new.append("G{0:d} {1} {2} {3} {4}".format(
                                g,
                                OCV.fmt('X', x/OCV.unit),
                                OCV.fmt('Y', y/OCV.unit),
                                OCV.fmt('Z', z/OCV.unit),
                                extra))

                            extra = ""
                        x1, y1, z1 = x2, y2, z2
                self.cnc.motionEnd()
            else:
                self.cnc.motionEnd()
                new.append(line)
        return new
Esempio n. 5
0
    def comp_level(self, queue, stopFunc=None):
        """Use probe information (if exist) to modify the g-code to autolevel"""
      
        paths = []
        # empty the gctos value
        OCV.gctos = []

        def add(line, path):
            if line is not None:
                if isinstance(line, str):
                    queue.put(line + "\n")
                    OCV.gctos.append(line)
                else:
                    queue.put(line)
                    OCV.gctos.append(line)

            paths.append(path)
        
        # check the existence of an autolevel file        
        autolevel = not self.probe.isEmpty()

        self.initPath()

        for line in CNC.compile_pgm(OCV.startup.splitlines()):
            add(line, None)

        every = 1
        for i, block in enumerate(OCV.blocks):

            if not block.enable:
                continue

            for j, line in enumerate(block):
                every -= 1
                if every <= 0:
                    if stopFunc is not None and stopFunc():
                        return None
                    every = 50

                newcmd = []
                cmds = CNC.compileLine(line)
                if cmds is None:
                    continue
                elif isinstance(cmds, str):
                    cmds = CNC.breakLine(cmds)
                else:
                    # either CodeType or tuple, list[] append at it as is
                    if isinstance(cmds, types.CodeType) or\
                          isinstance(cmds, int):
                        add(cmds, None)
                    else:
                        add(cmds, (i, j))
                    continue

                skip = False
                expand = None
                self.cnc.motionStart(cmds)

                # FIXME append feed on cut commands.
                # It will be obsolete in grbl v1.0
                if OCV.appendFeed and self.cnc.gcode in (1, 2, 3):
                    # Check is not existing in cmds
                    for c in cmds:
                        if c[0] in ('f', 'F'):
                            break
                    else:
                        cmds.append(
                            OCV.fmt(
                                'F',
                                self.cnc.feed / OCV.unit))

                if autolevel and self.cnc.gcode in (0, 1, 2, 3) and \
                      self.cnc.mval == 0:
                    xyz = self.cnc.motionPath()

                    if not xyz:
                        # while auto-levelling, do not ignore non-movement
                        # commands, just append the line as-is
                        add(line, None)
                    else:
                        extra = ""
                        for c in cmds:
                            if c[0].upper() not in (
                                    'G', 'X', 'Y', 'Z', 'I', 'J', 'K', 'R'):
                                extra += c
                        x1, y1, z1 = xyz[0]
                        if self.cnc.gcode == 0:
                            g = 0
                        else:
                            g = 1
                        for x2, y2, z2 in xyz[1:]:
                            for x, y, z in self.probe.splitLine(
                                    x1, y1, z1, x2, y2, z2):
                                add("G{0:d} {1} {2} {3} {4}".format(
                                    g,
                                    OCV.fmt('X', x/OCV.unit),
                                    OCV.fmt('Y', y/OCV.unit),
                                    OCV.fmt('Z', z/OCV.unit),
                                    extra),
                                    (i, j))

                                extra = ""

                            x1, y1, z1 = x2, y2, z2
                    self.cnc.motionEnd()
                    continue
                else:
                    # FIXME expansion policy here variable needed
                    # Canned cycles
                    if OCV.drillPolicy == 1 and \
                       self.cnc.gcode in (81, 82, 83, 85, 86, 89):
                        expand = self.cnc.macroGroupG8X()
                    # Tool change
                    elif self.cnc.mval == 6:
                        if OCV.toolPolicy == 0:
                            # send to grbl
                            pass
                        elif OCV.toolPolicy == 1:
                            # skip whole line
                            skip = True
                        elif OCV.toolPolicy >= 2:
                            expand = CNC.compile_pgm(self.cnc.toolChange())
                    self.cnc.motionEnd()

                if expand is not None:
                    for line in expand:
                        add(line, None)
                    expand = None
                    continue
                elif skip:
                    skip = False
                    continue

                for cmd in cmds:
                    c = cmd[0]
                    try:
                        value = float(cmd[1:])
                    except Exception:
                        value = 0.0

                    if c.upper() in (
                            "F", "X", "Y", "Z",
                            "I", "J", "K", "R", "P"):

                        cmd = OCV.fmt(c, value)
                    else:
                        opt = OCV.ERROR_HANDLING.get(cmd.upper(), 0)

                        if opt == OCV.GSTATE_SKIP:
                            cmd = None

                    if cmd is not None:
                        newcmd.append(cmd)

                add("".join(newcmd), (i, j))

        return paths