Exemple #1
0
    def _default_step_time(self):
        """ Determine the step time based on the device speed setting


        """
        #: Convert speed to px/s then to mm/s
        units = self.speed_units.split("/")[0]
        speed = parse_unit('%s%s' % (self.speed, units))
        speed = to_unit(speed, 'mm')
        if speed == 0:
            return 0

        #: No determine the time and convert to ms
        return max(0, round(1000 * self.step_size / speed))
Exemple #2
0
    def order(self, job, path):
        """ Sort subpaths by minimizing the distances between all start
        and end points.

        """
        subpaths = split_painter_path(path)
        log.debug("Subpath count: {}".format(len(subpaths)))

        # Cache all start and end points
        now = time()
        # This is in the UI thread
        time_limit = now + self.plugin.optimizer_timeout
        zero = QVector2D(0, 0)
        for sp in subpaths:
            # Average start and end into one "vertex"
            start = sp.elementAt(0)
            end = sp.elementAt(sp.elementCount() - 1)
            sp.start_point = QVector2D(start.x, start.y)
            sp.end_point = QVector2D(end.x, end.y)

        distance = QVector2D.distanceToPoint
        original = subpaths[:]
        result = []
        p = zero
        while subpaths:
            best = sys.maxsize
            shortest = None
            for sp in subpaths:
                d = distance(p, sp.start_point)
                if d < best:
                    best = d
                    shortest = sp

            p = shortest.end_point
            result.append(shortest)
            subpaths.remove(shortest)

            # time.time() is slow so limit the calls
            if time() > time_limit:
                result.extend(subpaths)  # At least part of it is optimized
                log.warning(
                    "Shortest path search aborted (time limit reached)")
                break

        duration = time() - now
        d = self.subpath_move_distance(zero, original)
        d = d - self.subpath_move_distance(zero, result)
        log.debug("Shortest path search: Saved {} in of movement in {}".format(
            to_unit(d, 'in'), duration))
        return join_painter_paths(result)
Exemple #3
0
    def _default_step_time(self):
        """ Determine the step time based on the device speed setting


        """
        #: Convert speed to px/s then to mm/s
        units = self.speed_units.split("/")[0]
        speed = parse_unit('%s%s' % (self.speed, units))
        speed = to_unit(speed, 'mm')
        if speed == 0:
            return 0

        #: No determine the time and convert to ms
        return max(0, round(1000*self.step_size/speed))
Exemple #4
0
 def order(self, job, path):
     """ Sort subpaths by minimizing the distances between all start
     and end points.
     
     """
     subpaths = split_painter_path(path)
     log.debug("Subpath count: {}".format(len(subpaths)))
     
     # Cache all start and end points
     time_limit = time()+self.time_limit
     zero = QVector2D(0, 0)
     for sp in subpaths:
         # Average start and end into one "vertex"
         start = sp.elementAt(0)
         end = sp.elementAt(sp.elementCount()-1)
         sp.start_point = QVector2D(start.x, start.y)
         sp.end_point = QVector2D(end.x, end.y)
         
     distance = QVector2D.distanceToPoint
     original = subpaths[:]
     result = []
     p = zero
     while subpaths:
         best = sys.maxsize
         shortest = None
         for sp in subpaths:
             d = distance(p, sp.start_point)
             if d < best:
                 best = d
                 shortest = sp
                 
         p = shortest.end_point
         result.append(shortest)
         subpaths.remove(shortest)
         
         # time.time() is slow so limit the calls
         if time() > time_limit:
             result.extend(subpaths)  # At least part of it is optimized
             log.debug("Shortest path search aborted (time limit reached)")
             break
     d = self.subpath_move_distance(zero, original)
     d = d-self.subpath_move_distance(zero, result)
     log.debug("Shortest path search: Saved {} in of movement ".format(
         to_unit(d, 'in')))
     return join_painter_paths(result)