Esempio n. 1
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()
Esempio n. 2
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
Esempio n. 3
0
 def GetTrailingEdgePoint(self, leading_edge_point):
     backward_curve = geom.Curve()
     backward_curve.Append(leading_edge_point)
     backward_curve.Append(leading_edge_point + geom.Point(0, -1000.0))
     pts = backward_curve.Intersections(self.curves[1])
     if len(pts) == 0:
         return None
     return pts[0]
Esempio n. 4
0
 def GetAngle(self, fraction):
     if self.curves[4] == None:
         return 0.0
     box = self.curves[4].GetBox()
     x = box.MinX() + box.Width() * fraction
     curve = geom.Curve()
     curve.Append(geom.Point(x, box.MinY() - 1.0))
     curve.Append(geom.Point(x, box.MaxY() + 1.0))
     pts = curve.Intersections(self.curves[4])
     if len(pts) == 0: return 0.0
     angle = pts[0].y - box.MinY()
     return angle
Esempio n. 5
0
def make_smaller( curve, start = None, finish = None, end_beyond = False ):
    if start != None:
        curve.ChangeStart(curve.NearestPoint(start))

    if finish != None:
        if end_beyond:
            curve2 = geom.Curve(curve)
            curve2.ChangeEnd(curve2.NearestPoint(finish))
            first = True
            for vertex in curve2.getVertices():
                if first == False: curve.Append(vertex)
                first = False
        else:
            curve.ChangeEnd(curve.NearestPoint(finish))
Esempio n. 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()
Esempio n. 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
Esempio n. 8
0
def make_zig_curve(curve, y0, y, zig_unidirectional):
    if rightward_for_zigs:
        curve.Reverse()

    # find a high point to start looking from
    high_point = None
    for vertex in curve.GetVertices():
        if high_point == None:
            high_point = vertex.p
        elif vertex.p.y > high_point.y:
            # use this as the new high point
            high_point = vertex.p
        elif math.fabs(vertex.p.y - high_point.y) < 0.002 * one_over_units:
            # equal high point
            if rightward_for_zigs:
                # use the furthest left point
                if vertex.p.x < high_point.x:
                    high_point = vertex.p
            else:
                # use the furthest right point
                if vertex.p.x > high_point.x:
                    high_point = vertex.p

    zig = geom.Curve()

    high_point_found = False
    zig_started = False
    zag_found = False

    for i in range(
            0, 2
    ):  # process the curve twice because we don't know where it will start
        prev_p = None
        for vertex in curve.GetVertices():
            if zag_found: break
            if prev_p != None:
                if zig_started:
                    zig.Append(unrotated_vertex(vertex))
                    if math.fabs(vertex.p.y - y) < 0.002 * one_over_units:
                        zag_found = True
                        break
                elif high_point_found:
                    if math.fabs(vertex.p.y - y0) < 0.002 * one_over_units:
                        if zig_started:
                            zig.Append(unrotated_vertex(vertex))
                        elif math.fabs(
                                prev_p.y - y0
                        ) < 0.002 * one_over_units and vertex.type == 0:
                            zig.Append(
                                geom.Vertex(0, unrotated_point(prev_p),
                                            geom.Point(0, 0)))
                            zig.Append(unrotated_vertex(vertex))
                            zig_started = True
                elif vertex.p.x == high_point.x and vertex.p.y == high_point.y:
                    high_point_found = True
            prev_p = vertex.p

    if zig_started:

        if zig_unidirectional == True:
            # remove the last bit of zig
            if math.fabs(zig.LastVertex().p.y - y) < 0.002 * one_over_units:
                vertices = zig.GetVertices()
                while len(vertices) > 0:
                    v = vertices[len(vertices) - 1]
                    if math.fabs(v.p.y - y0) < 0.002 * one_over_units:
                        break
                    else:
                        vertices.pop()
                zig = geom.Curve()
                for v in vertices:
                    zig.Append(v)

        curve_list_for_zigs.append(zig)
Esempio n. 9
0
def MakeCurveFromD(d, group_name):
    curve = geom.Curve()
    mode = 'x'  # x y h v cx1 cx2 cy1 cy2
    nums = ''
    curp = geom.Point(0, 0)
    absolute = True
    move = True
    d += ' '

    for c in d:
        if c == 'm':
            absolute = False
            move = True
            mode = 'x'
        elif c == 'M':
            absolute = True
            move = True
            mode = 'x'
        elif c == 'l':
            absolute = False
            mode = 'x'
        elif c == 'L':
            absolute = True
            mode = 'x'
        elif c == 'h':
            absolute = False
            mode = 'h'
        elif c == 'H':
            mode = 'h'
            absolute = True
        elif c == 'v':
            absolute = False
            mode = 'v'
        elif c == 'V':
            absolute = True
            mode = 'v'
        elif c == 'c':
            mode = 'cx1'
            absolute = False
        elif c == 'C':
            mode = 'cx1'
            absolute = True
        elif c == ' ':
            if len(nums) > 0:
                if mode == 'y':
                    if absolute or move: curp.y = -float(nums)
                    else: curp.y -= float(nums)
                    curve.Append(curp)
                    mode = 'x'
                    move = False
                elif mode == 'x':
                    raise NameError("mode x expecting comma!\n" + d)
                elif mode == 'h':
                    if absolute: curp.x = float(nums)
                    else: curp.x += float(nums)
                    curve.Append(curp)
                elif mode == 'v':
                    if absolute: curp.y = -float(nums)
                    else: curp.y -= float(nums)
                    curve.Append(curp)
                elif mode == 'cy1':
                    mode = 'cx2'
                elif mode == 'cy2':
                    mode = 'x'
                nums = ''
        elif c == ',':
            if mode == 'x':
                if absolute: curp.x = float(nums)
                else: curp.x += float(nums)
                mode = 'y'
            elif mode == 'cx1':
                mode = 'cy1'
            elif mode == 'cx2':
                mode = 'cy2'
            else:
                raise NameError("mode " + mode + " not expecting comma!")
            nums = ''
        elif c == 'z' or c == 'Z':
            # close the curve
            curve.Append(curve.FirstVertex().p)
        else:
            nums += c

    return curve
Esempio n. 10
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
Esempio n. 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