Exemplo n.º 1
0
    def doMove(self, data):
        fromX = int(data['fromX'])
        fromY = int(data['fromY'])

        toX = int(data['toX'])
        toY = int(data['toY'])

        p = int(data['pen'])
        pen = PenDirection.Down if p == 0 else PenDirection.Up

        logger.info("Starting to Move to {},{} from {},{}".format(
            toX, toY, fromX, fromY))

        config = Config().getConfig()
        plotter = Plotter(config, fromX, fromY)
        plotter.init(False)
        plotter.enableSteppers()
        plotter.moveTo(toX, toY, pen)
        plotter.disableSteppers()

        self.isPlottingInProgress = False

        logger.info("Done Stepping")
        return {'atX': toX, 'atY': toY}
Exemplo n.º 2
0
    def doPlot(self, data):
        self.isPlottingInProgress = True
        self.progress.clear()
        logger.info("Starting  to Plot")
        orgX = int(data['orgX'])
        orgY = int(data['orgY'])
        cords = data['cords']
        config = Config().getConfig()
        plotter = Plotter(config, orgX, orgY)
        plotter.init(False)
        plotter.enableSteppers()
        minX = min(cords['x'])
        maxX = max(cords['x'])

        minY = min(cords['y'])
        maxY = max(cords['y'])

        ax = []  # additional coordinates
        ay = []  # additional coordinates
        ap = []

        # move to origin, even if we are already there
        ax.append(orgX)
        ay.append(orgY)
        ap.append(0)  # PenDirection.Up

        #plotter.moveTo(minX, minY, PenDirection.Up)
        ax.append(minX)
        ay.append(minY)
        ap.append(0)  # PenDirection.Up

        # top left corner horizontal line
        #plotter.moveTo(minX+10, minY, PenDirection.Down)
        ax.append(minX + 10)
        ay.append(minY)
        ap.append(1)  # PenDirection.Down

        #plotter.moveTo(maxX-10, minY, PenDirection.Up)
        ax.append(maxX - 10)
        ay.append(minY)
        ap.append(0)  # PenDirection.up

        # top Right
        # top right corner horizontal line
        #plotter.moveTo(maxX, minY, PenDirection.Down)
        ax.append(maxX)
        ay.append(minY)
        ap.append(1)

        # top right corner vertical line
        #plotter.moveTo(maxX, minY+10, PenDirection.Down)
        ax.append(maxX)
        ay.append(minY + 10)
        ap.append(1)

        #plotter.moveTo(maxX, maxY-10, PenDirection.Up)
        ax.append(maxX)
        ay.append(maxY - 10)
        ap.append(0)

        # bottom Right
        # bottom right corner vertical line
        #plotter.moveTo(maxX, maxY, PenDirection.Down)
        ax.append(maxX)
        ay.append(maxY)
        ap.append(0)

        # bottom right corner horizontal line
        #plotter.moveTo(maxX-10, maxY, PenDirection.Down)
        ax.append(maxX - 10)
        ay.append(maxY)
        ap.append(1)
        #plotter.moveTo(minX+10, maxY, PenDirection.Up)
        ax.append(minX + 10)
        ay.append(maxY)
        ap.append(0)

        # bottom left
        # bottom left corner horizontal line
        #plotter.moveTo(minX, maxY, PenDirection.Down)
        ax.append(minX)
        ay.append(maxY)
        ap.append(1)
        # bottom left corner vertical line
        #plotter.moveTo(minX, maxY-10, PenDirection.Down)
        ax.append(minX)
        ay.append(maxY - 10)
        ap.append(1)

        ax.append(minX)
        ay.append(minY)
        ap.append(0)

        cords['x'] = ax + cords['x']
        cords['y'] = ay + cords['y']
        cords['p'] = ap + cords['p']

        total = len(cords['x'])

        for index in range(0, total - 1):
            x = int(cords['x'][index])
            y = int(cords['y'][index])
            pen = PenDirection.Down if cords['p'][
                index] == 0 else PenDirection.Up
            perComplete = round(index / total * 100, 2)
            self.progress.append((x, y, perComplete))
            plotter.moveTo(x, y, pen)
            logger.debug("Plotting {}%%".format(perComplete))
        plotter.finalize()
        self.progress.append((plotter.orgX, plotter.orgY, 100))
        logger.info("Done Plotting")
        self.isPlottingInProgress = False
        return "Complete"