Exemple #1
0
def recur(arealist, a1, stepover, from_center):
    # this makes arealist by recursively offsetting a1 inwards

    if a1.NumCurves() == 0:
        return

    if from_center:
        arealist.insert(0, a1)
    else:
        arealist.append(a1)

    a_offset = geom.Area(a1)
    a_offset.Offset(stepover)

    # split curves into new areas
    a_offset.Reorder()
    a2 = None

    for curve in a_offset.GetCurves():
        if curve.IsClockwise():
            if a2 != None:
                a2.Append(curve)
        else:
            if a2 != None:
                recur(arealist, a2, stepover, from_center)
            a2 = geom.Area()
            a2.Append(curve)

    if a2 != None:
        recur(arealist, a2, stepover, from_center)
Exemple #2
0
    def Offset(self, leftwards_value):
        save_curve = copy.deepcopy(self)

        # try offsetting with Geoff's method
        if self._Offset(leftwards_value):
            return True

        if self.IsClosed() == False:
            return False

        # use clipper to offset the closed curve
        inwards_offset = leftwards_value
        cw = False
        if self.IsClockwise():
            inwards_offset = -inwards_offset
            cw = True
        a = geom.Area()
        a.Append(self)
        a.Offset(inwards_value)
        if len(a.curves) == 1:
            start_span = None
            if len(self.vertices) > 1:
                start_span = geom.Span(self.vertices[0].p, self.vertices[1],
                                       True)
            self.vertices = copy.deepcopy(a.curves[0].vertices)
            if self.IsClockwise() != cw:
                self.Reverse()
            if start_span:
                forward = start_span.GetVector(0.0)
                left = ~forward
                offset_start = start_span.p + left * leftwards_value
                self.ChangeStart(self.NearestPointToPoint(offset_start))
                return True
        return False
Exemple #3
0
    def OnGlCommands(self, select, marked, no_color):
        points = self.GetPoints(0.1)
        if len(points) == 0:
            return

        cad.DrawPushMatrix()
        cad.DrawMultMatrix(self.tm)

        if not no_color:
            cad.DrawContrastBlackOrWhite()
        cad.BeginLines()
        for point in points:
            cad.GlVertex2D(point)
        cad.GlVertex2D(points[0])
        cad.EndLinesOrTriangles()

        a = geom.Area()
        c = geom.Curve()
        for point in points:
            c.Append(point)
        c.Append(points[0])
        a.Append(c)

        t_list = a.GetTrianglesList()
        if not no_color:
            cad.DrawColor(self.color)
        for t in t_list:
            cad.DrawTris(t, True)
        cad.DrawPopMatrix()
Exemple #4
0
def rotated_area(a):
    an = geom.Area()
    for curve in a.GetCurves():
        curve_new = geom.Curve()
        for v in curve.GetVertices():
            curve_new.Append(rotated_vertex(v))
        an.Append(curve_new)
    return an
Exemple #5
0
def feed_possible(p0, p1):
    if p0 == p1:
        return True
    obround = make_obround(p0, p1, tool_radius_for_pocket)
    a = geom.Area(area_for_feed_possible)
    obround.Subtract(a)
    if obround.NumCurves() > 0:
        return False
    return True
Exemple #6
0
def zigzag(a, stepover, zig_unidirectional):
    if a.NumCurves() == 0:
        return

    global rightward_for_zigs
    global curve_list_for_zigs
    global sin_angle_for_zigs
    global cos_angle_for_zigs
    global sin_minus_angle_for_zigs
    global cos_minus_angle_for_zigs
    global one_over_units

    one_over_units = 1 / geom.get_units()

    a = rotated_area(a)

    b = a.GetBox()

    x0 = b.MinX() - 1.0
    x1 = b.MaxX() + 1.0

    height = b.MaxY() - b.MinY()
    num_steps = int(height / stepover + 1)
    y = b.MinY() + 0.1 * one_over_units
    null_point = geom.Point(0, 0)
    rightward_for_zigs = True
    curve_list_for_zigs = []

    for i in range(0, num_steps):
        y0 = y
        y = y + stepover
        p0 = geom.Point(x0, y0)
        p1 = geom.Point(x0, y)
        p2 = geom.Point(x1, y)
        p3 = geom.Point(x1, y0)
        c = geom.Curve()
        c.Append(geom.Vertex(0, p0, null_point, 0))
        c.Append(geom.Vertex(0, p1, null_point, 0))
        c.Append(geom.Vertex(0, p2, null_point, 1))
        c.Append(geom.Vertex(0, p3, null_point, 0))
        c.Append(geom.Vertex(0, p0, null_point, 1))
        a2 = geom.Area()
        a2.Append(c)
        a2.Intersect(a)
        make_zig(a2, y0, y, zig_unidirectional)
        if zig_unidirectional == False:
            rightward_for_zigs = (rightward_for_zigs == False)

    reorder_zigs()
Exemple #7
0
def make_obround(p0, p1, radius):
    dir = p1 - p0
    d = dir.Length()
    dir.Normalize()
    right = geom.Point(dir.y, -dir.x)
    obround = geom.Area()
    c = geom.Curve()
    vt0 = p0 + right * radius
    vt1 = p1 + right * radius
    vt2 = p1 - right * radius
    vt3 = p0 - right * radius
    c.Append(geom.Vertex(0, vt0, geom.Point(0, 0)))
    c.Append(geom.Vertex(0, vt1, geom.Point(0, 0)))
    c.Append(geom.Vertex(1, vt2, p1))
    c.Append(geom.Vertex(0, vt3, geom.Point(0, 0)))
    c.Append(geom.Vertex(1, vt0, p0))
    obround.Append(c)
    return obround
Exemple #8
0
def pocket(a,
           tool_radius,
           extra_offset,
           stepover,
           depthparams,
           from_center,
           keep_tool_down_if_poss,
           use_zig_zag,
           zig_angle,
           zig_unidirectional=False,
           start_point=None,
           cut_mode='conventional'):
    global tool_radius_for_pocket
    global area_for_feed_possible

    tool_radius_for_pocket = tool_radius

    if keep_tool_down_if_poss:
        area_for_feed_possible = geom.Area(a)
        area_for_feed_possible.Offset(extra_offset - 0.01)

    global sin_angle_for_zigs
    global cos_angle_for_zigs
    global sin_minus_angle_for_zigs
    global cos_minus_angle_for_zigs
    radians_angle = zig_angle * math.pi / 180
    sin_angle_for_zigs = math.sin(-radians_angle)
    cos_angle_for_zigs = math.cos(-radians_angle)
    sin_minus_angle_for_zigs = math.sin(radians_angle)
    cos_minus_angle_for_zigs = math.cos(radians_angle)

    arealist = list()

    a_offset = geom.Area(a)
    current_offset = tool_radius + extra_offset
    a_offset.Offset(current_offset)

    do_recursive = True

    if use_zig_zag:
        zigzag(a_offset, stepover, zig_unidirectional)
        curve_list = curve_list_for_zigs
    else:
        if do_recursive:
            recur(arealist, a_offset, stepover, from_center)
        else:
            while (a_offset.NumCurves() > 0):
                if from_center:
                    arealist.insert(0, a_offset)
                else:
                    arealist.Append(a_offset)
                current_offset = current_offset + stepover
                a_offset = geom.Area(a)
                a_offset.Offset(current_offset)

        for area in arealist:
            geom.set_accuracy(0.01)
            area.FitArcs()

        curve_list = get_curve_list(arealist, cut_mode == 'climb')

    depths = depthparams.get_depths()

    current_start_depth = depthparams.start_depth

    if start_point == None:
        for depth in depths:
            cut_curvelist1(curve_list, depthparams.rapid_safety_space,
                           current_start_depth, depth,
                           depthparams.clearance_height,
                           keep_tool_down_if_poss)
            current_start_depth = depth

    else:
        for depth in depths:
            cut_curvelist2(curve_list, depthparams.rapid_safety_space,
                           current_start_depth, depth,
                           depthparams.clearance_height,
                           keep_tool_down_if_poss, start_point)
            current_start_depth = depth
Exemple #9
0
def profile(curve, direction = "on", radius = 1.0, offset_extra = 0.0, roll_radius = 2.0, roll_on = None, roll_off = None, depthparams = None, extend_at_start = 0.0, extend_at_end = 0.0, lead_in_line_len=0.0,lead_out_line_len= 0.0):
    global tags

    offset_curve = geom.Curve(curve)

    if offset_curve.NumVertices() <= 1:
        raise NameError("sketch has no spans!")
    
    if direction == "on":
        use_CRC() == False 
        
    if direction != "on":
        if direction != "left" and direction != "right":
            raise NameError("direction must be left or right" + str(direction))

        # get tool diameter
        offset = radius + offset_extra
        
        if use_CRC() == False or (use_CRC()==True and CRC_nominal_path()==True):
            
            if math.fabs(offset) > 0.00005:
                if direction == "right":
                    offset = -offset
                geom.Curve.__str__ = curve_str
                
                if offset_curve.IsClosed():
                    # calculate the closed offset to see if the area disappears          
                    cw = curve.IsClockwise()
                    a = geom.Area()
                    if cw:
                        ccw_curve = geom.Curve(curve)
                        ccw_curve.Reverse()
                        a.Append(ccw_curve)
                    else:
                        a.Append(curve)
                    a.Offset(-offset if cw else offset)
                    if a.NumCurves() == 0:
                        raise NameError("tool too big to profile curve")
                
                offset_success = offset_curve.Offset(offset)
                if offset_success == False:
                    global using_area_for_offset
                    if curve.IsClosed() and (using_area_for_offset == False):
                        using_area_for_offset = True                        
                        for curve in a.GetCurves():
                            curve_cw = curve.IsClockwise()
                            if cw != curve_cw:
                                curve.Reverse()
                            set_good_start_point(curve, False)
                            profile(curve, direction, 0.0, 0.0, roll_radius, roll_on, roll_off, depthparams, extend_at_start, extend_at_end, lead_in_line_len, lead_out_line_len)
                        using_area_for_offset = False
                        return                    
                    else:
                        raise NameError( "couldn't offset curve " + str(offset_curve) )
            
    # extend curve
    if extend_at_start > 0.0:
        span = offset_curve.GetFirstSpan()
        new_start = span.p + span.GetVector(0.0) * ( -extend_at_start)
        new_curve = geom.Curve()
        new_curve.Append(new_start)
        for vertex in offset_curve.getVertices():
            new_curve.Append(vertex)
        offset_curve = new_curve
        
    if extend_at_end > 0.0:
        span = offset_curve.GetLastSpan()
        new_end = span.v.p + span.GetVector(1.0) * extend_at_end
        offset_curve.Append(new_end)
                
    # remove tags further than radius from the offset kurve
    new_tags = []
    for tag in tags:
        if tag.dist(offset_curve) <= radius + 0.001:
            new_tags.append(tag)
    tags = new_tags

    if offset_curve.NumVertices() <= 1:
        raise NameError("sketch has no spans!")

    # do multiple depths
    depths = depthparams.get_depths()

    current_start_depth = depthparams.start_depth

    # tags
    if len(tags) > 0:
        # make a copy to restore to after each level
        copy_of_offset_curve = geom.Curve(offset_curve)
    
    prev_depth = depthparams.start_depth
    
    endpoint = None
    
    for depth in depths:
        mat_depth = prev_depth
        
        if len(tags) > 0:
            split_for_tags(offset_curve, radius, depthparams.start_depth, depth, depthparams.final_depth)

        # make the roll on and roll off kurves
        roll_on_curve = geom.Curve()
        add_roll_on(offset_curve, roll_on_curve, direction, roll_radius, offset_extra, roll_on)
        roll_off_curve = geom.Curve()
        add_roll_off(offset_curve, roll_off_curve, direction, roll_radius, offset_extra, roll_off)
        if use_CRC():
            crc_start_point = geom.Point()
            add_CRC_start_line(offset_curve,roll_on_curve,roll_off_curve,radius,direction,crc_start_point,lead_in_line_len)
        
        # get the tag depth at the start
        start_z = get_tag_z_for_span(0, offset_curve, radius, depthparams.start_depth, depth, depthparams.final_depth)
        
        if start_z and start_z > mat_depth: mat_depth = start_z

        # rapid across to the start
        s = roll_on_curve.FirstVertex().p
        
        # start point 
        if (endpoint == None) or (endpoint != s):
            if use_CRC():
                rapid(crc_start_point.x,crc_start_point.y)
            else:
                rapid(s.x, s.y)
        
            # rapid down to just above the material
            if endpoint == None:
                rapid(z = mat_depth + depthparams.rapid_safety_space)
            else:
                rapid(z = mat_depth)

        # feed down to depth
        mat_depth = depth
        if start_z and start_z > mat_depth: mat_depth = start_z
        feed(z = mat_depth)

        if use_CRC():
            start_CRC(direction == "left", radius)
            # move to the startpoint
            feed(s.x, s.y)
        
        # cut the roll on arc
        cut_curve(roll_on_curve)
        
        # cut the main kurve
        current_perim = 0.0
        
        for span in offset_curve.GetSpans():
            # height for tags
            current_perim += span.Length()
            ez = get_tag_z_for_span(current_perim, offset_curve, radius, depthparams.start_depth, depth, depthparams.final_depth)
            
            if span.v.type == 0:#line
                feed(span.v.p.x, span.v.p.y, ez)
            else:
                if span.v.type == 1:# anti-clockwise arc
                    arc_ccw(span.v.p.x, span.v.p.y, ez, i = span.v.c.x, j = span.v.c.y)
                else:
                    arc_cw(span.v.p.x, span.v.p.y, ez, i = span.v.c.x, j = span.v.c.y)
                    
    
        # cut the roll off arc
        cut_curve(roll_off_curve)

        endpoint = offset_curve.LastVertex().p
        if roll_off_curve.NumVertices() > 0:
            endpoint = roll_off_curve.LastVertex().p
        
        #add CRC end_line
        if use_CRC():
            crc_end_point = geom.Point()
            add_CRC_end_line(offset_curve,roll_on_curve,roll_off_curve,radius,direction,crc_end_point,lead_out_line_len)
            if direction == "on":
                rapid(z = depthparams.clearance_height)
            else:
                feed(crc_end_point.x, crc_end_point.y)
            
              
        # restore the unsplit kurve
        if len(tags) > 0:
            offset_curve = geom.Curve(copy_of_offset_curve)
        if use_CRC():
            end_CRC()            
        
        if endpoint != s:
            # rapid up to the clearance height
            rapid(z = depthparams.clearance_height)   
            
        prev_depth = depth

    rapid(z = depthparams.clearance_height)        

    del offset_curve
                
    if len(tags) > 0:
        del copy_of_offset_curve
Exemple #10
0
def curve_str(self):
    area = geom.Area()
    area.Append(self)
    return area.str()
Exemple #11
0
    def MakePatternedArea(self, outline, wing_box):
        box = geom.Box(geom.Point(wing_box.MinX(), wing_box.MinY()),
                       geom.Point(wing_box.MaxX(), wing_box.MaxY()))
        box.minxy.x -= 5.0
        box.minxy.y -= 5.0
        box.maxxy.x += 5.0
        box.maxxy.y += 5.0

        tx = self.pattern_x_step - self.pattern_wall * 2.309
        if tx < 0.0:
            return
        ty = self.pattern_y_step * 0.5 - self.pattern_wall
        if ty < 0.0:
            return

        a = geom.Area()

        x = box.MinX()
        while x < box.MaxX():
            y = box.MinY()
            while y < box.MaxY():
                c = geom.Curve()
                c.Append(geom.Point(x - tx * 0.5, y))
                c.Append(geom.Point(x + tx * 0.5, y))
                c.Append(geom.Point(x, y + ty))
                c.Append(geom.Point(x - tx * 0.5, y))
                a.Append(c)

                c = geom.Curve()
                c.Append(geom.Point(x + self.pattern_x_step * 0.5, y))
                c.Append(
                    geom.Point(x + self.pattern_x_step * 0.5 + tx * 0.5,
                               y + ty))
                c.Append(
                    geom.Point(x + self.pattern_x_step * 0.5 - tx * 0.5,
                               y + ty))
                c.Append(geom.Point(x + self.pattern_x_step * 0.5, y))
                a.Append(c)

                c = geom.Curve()
                c.Append(
                    geom.Point(x + self.pattern_x_step * 0.5 - tx * 0.5,
                               y + self.pattern_y_step * 0.5))
                c.Append(
                    geom.Point(x + self.pattern_x_step * 0.5 + tx * 0.5,
                               y + self.pattern_y_step * 0.5))
                c.Append(
                    geom.Point(x + self.pattern_x_step * 0.5,
                               y + self.pattern_y_step * 0.5 + ty))
                c.Append(
                    geom.Point(x + self.pattern_x_step * 0.5 - tx * 0.5,
                               y + self.pattern_y_step * 0.5))
                a.Append(c)

                c = geom.Curve()
                c.Append(geom.Point(x, y + self.pattern_y_step * 0.5))
                c.Append(
                    geom.Point(x + tx * 0.5,
                               y + self.pattern_y_step * 0.5 + ty))
                c.Append(
                    geom.Point(x - tx * 0.5,
                               y + self.pattern_y_step * 0.5 + ty))
                c.Append(geom.Point(x, y + self.pattern_y_step * 0.5))
                a.Append(c)
                y += self.pattern_y_step
            x += self.pattern_x_step

        if self.split_into_pieces > 1:
            wall_a = geom.Area()
            for i in range(0, self.split_into_pieces):
                x = wing_box.MinX() + (wing_box.MaxX() - wing_box.MinX(
                )) * float(i + 1) / self.split_into_pieces
                c = geom.Curve()
                c.Append(
                    geom.Point(x - self.split_wall_width * 0.5,
                               wing_box.MinX() - 10.0))
                c.Append(
                    geom.Point(x + self.split_wall_width * 0.5,
                               wing_box.MinX() - 10.0))
                c.Append(
                    geom.Point(x + self.split_wall_width * 0.5,
                               wing_box.MaxX() + 10.0))
                c.Append(
                    geom.Point(x - self.split_wall_width * 0.5,
                               wing_box.MaxX() + 10.0))
                c.Append(
                    geom.Point(x - self.split_wall_width * 0.5,
                               wing_box.MinX() - 10.0))
                wall_a.Append(c)
            a.Subtract(wall_a)

        outline.Intersect(a)

        return outline