예제 #1
0
    def __init__(self, shape=None):
        if shape is None:
            return

        self.shape = shape

        self.start, self.angle = self.shape.get_start_end_points(True, True)
        self.end = self.start

        self.geos = Geos([])

        self.make_start_moves()
예제 #2
0
 def getNewGeos(self, geos):
     # TODO use intersect class and update_start_end_points
     new_geos = Geos([])
     for geo in geos.abs_iter():
         if isinstance(geo, LineGeo):
             new_geos.extend(self.breakLineGeo(geo))
         elif isinstance(geo, ArcGeo):
             new_geos.extend(self.breakArcGeo(geo))
         else:
             new_geos.append(geo)
     return new_geos
예제 #3
0
 def breakArcGeo(self, arcGeo):
     """
     Try to break passed arcGeo with any of the shapes on a break layers.
     Will break arcGeos recursively.
     @return: The list of geometries after breaking (arcGeo itself if no breaking happened)
     """
     newGeos = Geos([])
     for breakLayer in self.breakLayers:
         for breakShape in breakLayer.shapes.not_disabled_iter():
             intersections = self.intersectArcGeometry(arcGeo, breakShape)
             if len(intersections) == 2:
                 (near,
                  far) = self.classifyIntersections(arcGeo, intersections)
                 logger.debug(
                     "Arc %s broken from (%f, %f) to (%f, %f)" %
                     (arcGeo.toShortString(), near.x, near.y, far.x, far.y))
                 newGeos.extend(
                     self.breakArcGeo(
                         ArcGeo(Ps=arcGeo.Ps,
                                Pe=near,
                                O=arcGeo.O,
                                r=arcGeo.r,
                                s_ang=arcGeo.s_ang,
                                direction=arcGeo.ext)))
                 newGeos.append(
                     BreakGeo(near, far, breakShape.axis3_mill_depth,
                              breakShape.f_g1_plane, breakShape.f_g1_depth))
                 newGeos.extend(
                     self.breakArcGeo(
                         ArcGeo(Ps=far,
                                Pe=arcGeo.Pe,
                                O=arcGeo.O,
                                r=arcGeo.r,
                                e_ang=arcGeo.e_ang,
                                direction=arcGeo.ext)))
                 return newGeos
     return [arcGeo]
예제 #4
0
 def breakLineGeo(self, lineGeo):
     """
     Try to break passed lineGeo with any of the shapes on a break layers.
     Will break lineGeos recursively.
     @return: The list of geometries after breaking (lineGeo itself if no breaking happened)
     """
     newGeos = Geos([])
     for breakLayer in self.breakLayers:
         for breakShape in breakLayer.shapes.not_disabled_iter():
             intersections = self.intersectLineGeometry(lineGeo, breakShape)
             if len(intersections) == 2:
                 (near,
                  far) = self.classifyIntersections(lineGeo, intersections)
                 logger.debug("Line %s broken from (%f, %f) to (%f, %f)" %
                              (lineGeo.to_short_string(), near.x, near.y,
                               far.x, far.y))
                 newGeos.extend(self.breakLineGeo(LineGeo(lineGeo.Ps,
                                                          near)))
                 newGeos.append(
                     BreakGeo(near, far, breakShape.axis3_mill_depth,
                              breakShape.f_g1_plane, breakShape.f_g1_depth))
                 newGeos.extend(self.breakLineGeo(LineGeo(far, lineGeo.Pe)))
                 return newGeos
     return [lineGeo]
예제 #5
0
    def make_start_moves(self):
        """
        This function called to create the start move. It will
        be generated based on the given values for start and angle.
        """
        self.geos = Geos([])

        if g.config.machine_type == 'drag_knife':
            self.make_swivelknife_move()
            return

        # Get the start rad. and the length of the line segment at begin.
        start_rad = self.shape.parentLayer.start_radius

        # Get tool radius based on tool diameter.
        tool_rad = self.shape.parentLayer.getToolRadius()

        # Calculate the starting point with and without compensation.
        start = self.start
        angle = self.angle

        if self.shape.cut_cor == 40:
            self.append(RapidPos(start))

        elif self.shape.cut_cor != 40 and not g.config.vars.Cutter_Compensation[
                "done_by_machine"]:

            toolwidth = self.shape.parentLayer.getToolRadius()
            offtype = "in" if self.shape.cut_cor == 42 else "out"
            offshape = offShapeClass(parent=self.shape,
                                     offset=toolwidth,
                                     offtype=offtype)

            if len(offshape.rawoff) > 0:
                start, angle = offshape.rawoff[0].get_start_end_points(
                    True, True)

                self.append(RapidPos(start))
                self.geos += offshape.rawoff

        # Cutting Compensation Left
        elif self.shape.cut_cor == 41:
            # Center of the Starting Radius.
            Oein = start.get_arc_point(angle + pi / 2, start_rad + tool_rad)
            # Start Point of the Radius
            Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad)
            # Start Point of the straight line segment at begin.
            Pg_ein = Ps_ein.get_arc_point(angle + pi / 2, start_rad)

            # Get the dive point for the starting contour and append it.
            start_ein = Pg_ein.get_arc_point(angle, tool_rad)
            self.append(RapidPos(start_ein))

            # generate the Start Line and append it including the compensation.
            start_line = LineGeo(start_ein, Ps_ein)
            self.append(start_line)

            # generate the start rad. and append it.
            start_rad = ArcGeo(Ps=Ps_ein,
                               Pe=start,
                               O=Oein,
                               r=start_rad + tool_rad,
                               direction=1)
            self.append(start_rad)

        # Cutting Compensation Right
        elif self.shape.cut_cor == 42:
            # Center of the Starting Radius.
            Oein = start.get_arc_point(angle - pi / 2, start_rad + tool_rad)
            # Start Point of the Radius
            Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad)
            # Start Point of the straight line segment at begin.
            Pg_ein = Ps_ein.get_arc_point(angle - pi / 2, start_rad)

            # Get the dive point for the starting contour and append it.
            start_ein = Pg_ein.get_arc_point(angle, tool_rad)
            self.append(RapidPos(start_ein))

            # generate the Start Line and append it including the compensation.
            start_line = LineGeo(start_ein, Ps_ein)
            self.append(start_line)

            # generate the start rad. and append it.
            start_rad = ArcGeo(Ps=Ps_ein,
                               Pe=start,
                               O=Oein,
                               r=start_rad + tool_rad,
                               direction=0)
            self.append(start_rad)
예제 #6
0
class StMove(object):
    """
    This Function generates the StartMove for each shape. It
    also performs the Plotting and Export of this moves. It is linked
    to the shape of its parent
    """

    # only need default arguments here because of the change of usage with super in QGraphicsLineItem
    def __init__(self, shape=None):
        if shape is None:
            return

        self.shape = shape

        self.start, self.angle = self.shape.get_start_end_points(True, True)
        self.end = self.start

        self.geos = Geos([])

        self.make_start_moves()

    def append(self, geo):
        # we don't want to additional scale / rotate the stmove geo
        # so no geo.make_abs_geo(self.shape.parentEntity)
        geo.make_abs_geo()
        self.geos.append(geo)

    def make_start_moves(self):
        """
        This function called to create the start move. It will
        be generated based on the given values for start and angle.
        """
        self.geos = Geos([])

        if g.config.machine_type == 'drag_knife':
            self.make_swivelknife_move()
            return

        # Get the start rad. and the length of the line segment at begin.
        start_rad = self.shape.parentLayer.start_radius

        # Get tool radius based on tool diameter.
        tool_rad = self.shape.parentLayer.getToolRadius()

        # Calculate the starting point with and without compensation.
        start = self.start
        angle = self.angle

        if self.shape.cut_cor == 40:
            self.append(RapidPos(start))

        elif self.shape.cut_cor != 40 and not g.config.vars.Cutter_Compensation[
                "done_by_machine"]:

            toolwidth = self.shape.parentLayer.getToolRadius()
            offtype = "in" if self.shape.cut_cor == 42 else "out"
            offshape = offShapeClass(parent=self.shape,
                                     offset=toolwidth,
                                     offtype=offtype)

            if len(offshape.rawoff) > 0:
                start, angle = offshape.rawoff[0].get_start_end_points(
                    True, True)

                self.append(RapidPos(start))
                self.geos += offshape.rawoff

        # Cutting Compensation Left
        elif self.shape.cut_cor == 41:
            # Center of the Starting Radius.
            Oein = start.get_arc_point(angle + pi / 2, start_rad + tool_rad)
            # Start Point of the Radius
            Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad)
            # Start Point of the straight line segment at begin.
            Pg_ein = Ps_ein.get_arc_point(angle + pi / 2, start_rad)

            # Get the dive point for the starting contour and append it.
            start_ein = Pg_ein.get_arc_point(angle, tool_rad)
            self.append(RapidPos(start_ein))

            # generate the Start Line and append it including the compensation.
            start_line = LineGeo(start_ein, Ps_ein)
            self.append(start_line)

            # generate the start rad. and append it.
            start_rad = ArcGeo(Ps=Ps_ein,
                               Pe=start,
                               O=Oein,
                               r=start_rad + tool_rad,
                               direction=1)
            self.append(start_rad)

        # Cutting Compensation Right
        elif self.shape.cut_cor == 42:
            # Center of the Starting Radius.
            Oein = start.get_arc_point(angle - pi / 2, start_rad + tool_rad)
            # Start Point of the Radius
            Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad)
            # Start Point of the straight line segment at begin.
            Pg_ein = Ps_ein.get_arc_point(angle - pi / 2, start_rad)

            # Get the dive point for the starting contour and append it.
            start_ein = Pg_ein.get_arc_point(angle, tool_rad)
            self.append(RapidPos(start_ein))

            # generate the Start Line and append it including the compensation.
            start_line = LineGeo(start_ein, Ps_ein)
            self.append(start_line)

            # generate the start rad. and append it.
            start_rad = ArcGeo(Ps=Ps_ein,
                               Pe=start,
                               O=Oein,
                               r=start_rad + tool_rad,
                               direction=0)
            self.append(start_rad)

    def make_swivelknife_move(self):
        """
        Set these variables for your tool and material
        @param offset: knife tip distance from tool centerline. The radius of the
        tool is used for this.
        """
        offset = self.shape.parentLayer.getToolRadius()
        drag_angle = self.shape.drag_angle

        startnorm = offset * Point(
            1, 0)  # TODO make knife direction a config setting
        prvend, prvnorm = Point(), Point()
        first = True

        for geo in self.shape.geos.abs_iter():
            if isinstance(geo, LineGeo):
                geo_b = deepcopy(geo)
                if first:
                    first = False
                    prvend = geo_b.Ps + startnorm
                    prvnorm = startnorm
                norm = offset * (geo_b.Pe - geo_b.Ps).unit_vector()
                geo_b.Ps += norm
                geo_b.Pe += norm
                if not prvnorm == norm:
                    direction = prvnorm.to3D().cross_product(norm.to3D()).z
                    swivel = ArcGeo(Ps=prvend,
                                    Pe=geo_b.Ps,
                                    r=offset,
                                    direction=direction)
                    swivel.drag = drag_angle < abs(swivel.ext)
                    self.append(swivel)
                self.append(geo_b)

                prvend = geo_b.Pe
                prvnorm = norm
            elif isinstance(geo, ArcGeo):
                geo_b = deepcopy(geo)
                if first:
                    first = False
                    prvend = geo_b.Ps + startnorm
                    prvnorm = startnorm
                if geo_b.ext > 0.0:
                    norma = offset * Point(cos(geo_b.s_ang + pi / 2),
                                           sin(geo_b.s_ang + pi / 2))
                    norme = Point(cos(geo_b.e_ang + pi / 2),
                                  sin(geo_b.e_ang + pi / 2))
                else:
                    norma = offset * Point(cos(geo_b.s_ang - pi / 2),
                                           sin(geo_b.s_ang - pi / 2))
                    norme = Point(cos(geo_b.e_ang - pi / 2),
                                  sin(geo_b.e_ang - pi / 2))
                geo_b.Ps += norma
                if norme.x > 0:
                    geo_b.Pe = Point(
                        geo_b.Pe.x + offset / (sqrt(1 +
                                                    (norme.y / norme.x)**2)),
                        geo_b.Pe.y + (offset * norme.y / norme.x) /
                        (sqrt(1 + (norme.y / norme.x)**2)))
                elif norme.x == 0:
                    geo_b.Pe = Point(geo_b.Pe.x, geo_b.Pe.y)
                else:
                    geo_b.Pe = Point(
                        geo_b.Pe.x - offset / (sqrt(1 +
                                                    (norme.y / norme.x)**2)),
                        geo_b.Pe.y - (offset * norme.y / norme.x) /
                        (sqrt(1 + (norme.y / norme.x)**2)))
                if prvnorm != norma:
                    direction = prvnorm.to3D().cross_product(norma.to3D()).z
                    swivel = ArcGeo(Ps=prvend,
                                    Pe=geo_b.Ps,
                                    r=offset,
                                    direction=direction)
                    swivel.drag = drag_angle < abs(swivel.ext)
                    self.append(swivel)
                prvend = geo_b.Pe
                prvnorm = offset * norme
                if -pi < geo_b.ext < pi:
                    self.append(
                        ArcGeo(Ps=geo_b.Ps,
                               Pe=geo_b.Pe,
                               r=sqrt(geo_b.r**2 + offset**2),
                               direction=geo_b.ext))
                else:
                    geo_b = ArcGeo(Ps=geo_b.Ps,
                                   Pe=geo_b.Pe,
                                   r=sqrt(geo_b.r**2 + offset**2),
                                   direction=-geo_b.ext)
                    geo_b.ext = -geo_b.ext
                    self.append(geo_b)
            # TODO support different geos, or disable them in the GUI
            # else:
            #     self.append(copy(geo))
        if not prvnorm == startnorm:
            direction = prvnorm.to3D().cross_product(startnorm.to3D()).z
            self.append(
                ArcGeo(Ps=prvend,
                       Pe=prvend - prvnorm + startnorm,
                       r=offset,
                       direction=direction))

        self.geos.insert(0, RapidPos(self.geos.abs_el(0).Ps))
        self.geos[0].make_abs_geo()

    def make_path(self, drawHorLine, drawVerLine):
        for geo in self.geos.abs_iter():
            drawVerLine(self.shape, geo.get_start_end_points(True))
            geo.make_path(self.shape, drawHorLine)
        if len(self.geos):
            drawVerLine(self.shape, geo.get_start_end_points(False))