Example #1
0
    def offsetPath(self, step_over):
        # TODO Sort Edges to ensure they're in order.

        if step_over == 0:
            return self

        segs = self.get_segments()
        segmentgroup = SegmentGroup()

        for i in range(len(segs)):
            seg = segs[i]
            if seg.bulge != 0:

                if seg.bulge > 0:
                    vec = Vector().normalise(seg.start, seg.get_centre_point())
                    vec2 = Vector().normalise(seg.end, seg.get_centre_point())
                    pt = vec.multiply(step_over)
                    pt2 = vec2.multiply(step_over)
                    new_start = seg.start.add(pt)
                    new_end = seg.end.add(pt2)

                    new_start.X = new_start.X - step_over
                    new_end.X = new_end.X - step_over
                    rad = seg.get_radius() - step_over
                    # print('offsetPath arc dims', new_start.X, new_start.Z, new_end.X, new_end.Z)
                else:
                    vec = Vector().normalise(seg.get_centre_point(), seg.start)
                    vec2 = Vector().normalise(seg.get_centre_point(), seg.end)
                    pt = vec.multiply(step_over)
                    pt2 = vec2.multiply(step_over)
                    new_start = pt.add(seg.start)
                    new_end = pt2.add(seg.end)
                    rad = seg.get_radius() + step_over  # seg.get_centre_point().distance_to(new_start)

                segment = Segment(new_start, new_end)

                if seg.bulge < 0:
                    rad = 0 - rad
                segment.set_bulge_from_radius(rad)

            if seg.bulge == 0:
                vec = Vector().normalise(seg.start, seg.end)
                vec = vec.rotate_x(-1.570796)
                pt = vec.multiply(step_over)
                segment = Segment(pt.add(seg.start), pt.add(seg.end))

            segmentgroup.add_segment(segment)

        segmentgroup.join_segments()
        return segmentgroup
Example #2
0
    def join_segments(self):
        """join segments of the segmentgroup"""

        segments = self.get_segments()
        segmentgroupOut = SegmentGroup()

        for i in range(len(segments)):

            pt1 = segments[i].start
            pt2 = segments[i].end

            if i != 0:
                seg1 = segments[i - 1]
                intersect, pt = seg1.intersect(segments[i], extend=True)
                if intersect:
                    if type(pt) is list:
                        pt = pt1.nearest(pt)
                    pt1 = pt

            if i != len(segments) - 1:
                seg2 = segments[i + 1]
                intersect2, pt = seg2.intersect(segments[i], extend=True)
                if intersect2:
                    # print('intersect2')
                    if type(pt) is list:
                        # print('join_segments type of', type(pt))
                        pt = pt2.nearest(pt)
                    pt2 = pt

                    # print('join_segments', i, pt1, pt2, pt2.X, pt2.Z)

            if pt1 and pt2:
                if segments[i].bulge != 0:
                    nseg = Segment(pt1, pt2)
                    rad = segments[i].get_centre_point().distance_to(pt1)
                    if segments[i].bulge < 0:
                        rad = 0 - rad
                    nseg.set_bulge_from_radius(rad)
                    segmentgroupOut.add_segment(nseg)
                else:
                    segmentgroupOut.add_segment(Segment(pt1, pt2))
            else:
                # No Intersections found. Return the segment in its current state
                # print('join_segments - No Intersection found for index:', i)
                segmentgroupOut.add_segment(segments[i])

        self.segments = segmentgroupOut.get_segments()
        self.clean_offset_path()
Example #3
0
    def remove_the_groove(self, stock_zmin, tool, allow_grooving=False):
        segments = self.get_segments()
        segs_out = SegmentGroup()
        index = 0

        while index < len(segments):
            seg = segments[index]
            next_index = False
            pt1 = seg.start
            pt2 = seg.end
            pt = None

            if seg.bulge != 0:
                print('arc segment')
                if seg.bulge > 0:
                    # TODO: handle segments with a positive bulge
                    seg = Segment(pt1, pt2)
                    segs_out.add_segment(seg)
                if seg.bulge < 0:
                    # Limit the arc movement to the X extents or the tangent at the max tool angle if allow_grooving
                    angle_limit = 180 if allow_grooving is False else tool.get_tool_cutting_angle() - 90
                    if seg.get_centre_point().angle_to(pt2) <= angle_limit:
                        segs_out.add_segment(seg)
                    else:
                        rad = seg.get_radius()
                        if not allow_grooving:
                            x = seg.get_centre_point().X - rad
                            y = seg.get_centre_point().Y
                            z = seg.get_centre_point().Z
                            pt = Point(x, y, z)
                        else:
                            pt = seg.get_centre_point().project(angle_limit, rad)

                        if seg.bulge < 0:
                            rad = 0 - rad

                        seg = Segment(pt1, pt)
                        seg.set_bulge_from_radius(rad)
                        segs_out.add_segment(seg)

                        pt1 = pt
                        next_index, pt = self.find_next_good_edge(index, stock_zmin, tool, allow_grooving, pt)

            elif seg.bulge == 0:
                print('line segment')
                if pt1.angle_to(pt2) > tool.get_tool_cutting_angle():
                    next_index, pt = self.find_next_good_edge(index, stock_zmin, tool, allow_grooving)
                else:
                    segs_out.add_segment(seg)

            if next_index is False and pt is not None:
                seg = Segment(pt1, pt)
                segs_out.add_segment(seg)
                break
            if next_index is not False and next_index != index:
                seg = Segment(pt1, pt)
                segs_out.add_segment(seg)
                next_pt1 = pt
                next_pt2 = segments[next_index].end
                seg = Segment(next_pt1, next_pt2)
                segs_out.add_segment(seg)
                next_index += 1
                index = next_index
                continue

            index += 1
        return segs_out