예제 #1
0
def gen_dxf(name, c0, c1):

    lines = c1.gen_lines()

    drawing = dxf.drawing(name)

    # base line is the circumfrence of c1
    base = 2.0 * math.pi * c1.r
    drawing.add(dxf.line((0.0, 0.0), (base, 0.0)))

    for i in range(_NDIVS):
        x = i * base / _NDIVS
        t_vals = c0.intersect_line(lines[i])
        if t_vals[0] == 'inf':
            pass
        elif t_vals[0] == '0':
            drawing.add(dxf.line((x, 0.0), (x, c1.l)))
        elif t_vals[0] == '1':
            drawing.add(dxf.line((x, 0.0), (x, c1.l)))
        elif t_vals[0] == '2':
            if t_vals[1] > t_vals[2]:
                y0 = t_vals[2]
                y1 = t_vals[1]
            else:
                y1 = t_vals[2]
                y0 = t_vals[1]
            drawing.add(dxf.line((x, 0.0), (x, y0)))
            drawing.add(dxf.line((x, y1), (x, c1.l)))

    drawing.save()
예제 #2
0
def gen_dxf(name, c0, c1):

    lines = c1.gen_lines()

    drawing = dxf.drawing(name)

    # base line is the circumfrence of c1
    base = 2.0 * math.pi * c1.r
    drawing.add(dxf.line((0.0, 0.0), (base, 0.0)))

    for i in range(_NDIVS):
        x = i * base / _NDIVS
        t_vals = c0.intersect_line(lines[i])
        if t_vals[0] == 'inf':
            pass
        elif t_vals[0] == '0':
            drawing.add(dxf.line((x, 0.0), (x, c1.l)))
        elif t_vals[0] == '1':
            drawing.add(dxf.line((x, 0.0), (x, c1.l)))
        elif t_vals[0] == '2':
            if t_vals[1] > t_vals[2]:
                y0 = t_vals[2]
                y1 = t_vals[1]
            else:
                y1 = t_vals[2]
                y0 = t_vals[1]
            drawing.add(dxf.line((x, 0.0), (x, y0)))
            drawing.add(dxf.line((x, y1), (x, c1.l)))

    drawing.save()
예제 #3
0
 def build_dxf(self, scale, offset, diameter):
     drawing = dxf.drawing('Drawing.dxf')
     print('\n' + Fore.RESET + 'Выполняется построение объекта...')
     counter = 0
     for pin in self.pins:
         x = int(pin[0]) * scale
         y = int(pin[1]) * scale
         drawing.add(dxf.circle(diameter / 2, (x, y)))
         counter += 1
         print('item added', x, y)
     drawing.add(dxf.line((min(self.rangex) * scale - offset, min(self.rangey) * scale - offset),
                          (max(self.rangex) * scale + offset, min(self.rangey) * scale - offset),
                          color=1))
     drawing.add(dxf.line((max(self.rangex) * scale + offset, min(self.rangey) * scale - offset),
                          (max(self.rangex) * scale + offset, max(self.rangey) * scale + offset),
                          color=1))
     drawing.add(dxf.line((max(self.rangex) * scale + offset, max(self.rangey) * scale + offset),
                          (min(self.rangex) * scale - offset, max(self.rangey) * scale + offset),
                          color=1))
     drawing.add(dxf.line((min(self.rangex) * scale - offset, max(self.rangey) * scale + offset),
                          (min(self.rangex) * scale - offset, min(self.rangey) * scale - offset),
                          color=1))
     print('Построение завершено.')
     printtable()
     try:
         drawing.save()
         print('Результат сохранен в файл ' + Fore.CYAN + 'Drawing.dxf' + Fore.RESET)
     except PermissionError:
         print(Fore.RED + 'ФАЙЛ ЗАНЯТ ДРУГИМ ПРИЛОЖЕНИЕМ.' + Fore.RESET)
예제 #4
0
def generate_template_trophy(h1, h2, w, drawing):
    """
    Generates a outline around all the tropies on the drawing given. (c) shovel
    """
    drawing.add(dxf.line((0, 0), (600,0), color=255, layer='LINES', thickness=0.00))
    drawing.add(dxf.line((600, 0), (600,450), color=255, layer='LINES', thickness=0.00))
    drawing.add(dxf.line((600,450), (0,450), color=255, layer='LINES', thickness=0.00))
    drawing.add(dxf.line((0,450), (0,0), color=255, layer='LINES', thickness=0.00))
    refpoint = generate_ref_trophy(h1, h2, w)
    for i in refpoint[:4]:
        x,y = i
        draw(x,y,x+h1,y,drawing)
        draw(x,y,x,y-w,drawing)
        draw(x,y-w,x+h2,y-w,drawing)
        draw(x+h1,y,x+h2,y-w,drawing)
    for i in refpoint[4:8]:
        x,y=i
        draw(x,y,x-h1,y,drawing)
        draw(x,y,x,y+w,drawing)
        draw(x,y+w,x-h2,y+w,drawing)
        draw(x-h2,y+w,x-h1,y,drawing)
    x,y = refpoint[-2]
    draw(x,y,x,y+h1,drawing)
    draw(x,y,x+w,y,drawing)
    draw(x+w,y,x+w,y+h2,drawing)
    draw(x+w,y+h2,x,y+h1,drawing)
    x,y = refpoint[-1]
    draw(x,y,x,y-h1,drawing)
    draw(x,y,x-w,y,drawing)
    draw(x-w,y,x-w,y-h2,drawing)
    draw(x-w,y-h2,x,y-h1,drawing)
예제 #5
0
def slates(drawing, startx, starty, number_of_slates):
  x_increment = 0
  y_increment = 0
  for n in range(0, number_of_slates):
      # top of slates
      drawing.add(dxf.line( (startx, starty + (slate_length*n) ), 
                            (startx+slate_width, starty + (slate_length*n) ),
                            layer='CUTSINNEREARLY', color=3) 
                 )
      # left hand side cable tie hole
      drawing.add(dxf.rectangle((startx + 5, starty + 5 + (slate_length*n)) , 5, 5,  layer='CUTSINNEREARLY', color=3))
      # right hand side cable tie hole
      drawing.add(dxf.rectangle((startx + slate_width- 10, starty + 5 + (slate_length*n)) , 5, 5,  layer='CUTSINNEREARLY', color=3))
      # Cog hole
      drawing.add(dxf.rectangle((startx + 130, starty + 5 + (slate_length*n)) , 5, 5,  layer='CUTSINNEREARLY', color=3))

      y_increment = y_increment + slate_length
  # bottom of slates
  drawing.add(dxf.line( (startx, starty + (slate_length*number_of_slates) ), 
                            (startx+slate_width, starty + (slate_length*number_of_slates) ),
                            layer='CUTSINNEREARLY', color=3) 
                 )

  # left and right sides of slates
  drawing.add(dxf.line( (startx, starty ), 
                        (startx, starty + (slate_length*number_of_slates) ),
                        layer='CUTSINNER', color=4) 
             )
  drawing.add(dxf.line( (startx+slate_width, starty ), 
                        (startx+slate_width, starty + (slate_length*number_of_slates) ),
                        layer='CUTSINNER', color=4) 
             )
   
  return (x_increment, y_increment)
예제 #6
0
def dxf_code(file_name, table_point, table_line, table_chain, table_shaft,
             table_slider, table_rod):
    mechanism = dxf.drawing(file_name)
    for i in range(len(table_point)):
        pt = dxf.point((table_point[i][3], table_point[i][4]))
        mechanism.add(pt)
    for i in range(len(table_line)):
        ln = dxf.line((table_point[table_line[i][0]][3],
                       table_point[table_line[i][0]][4]),
                      (table_point[table_line[i][1]][3],
                       table_point[table_line[i][1]][4]))
        mechanism.add(ln)
    for i in range(len(table_chain)):
        ln1 = dxf.line((table_point[table_chain[i][0]][3],
                        table_point[table_chain[i][0]][4]),
                       (table_point[table_chain[i][1]][3],
                        table_point[table_chain[i][1]][4]))
        ln2 = dxf.line((table_point[table_chain[i][1]][3],
                        table_point[table_chain[i][1]][4]),
                       (table_point[table_chain[i][2]][3],
                        table_point[table_chain[i][2]][4]))
        ln3 = dxf.line((table_point[table_chain[i][0]][3],
                        table_point[table_chain[i][0]][4]),
                       (table_point[table_chain[i][2]][3],
                        table_point[table_chain[i][2]][4]))
        mechanism.add(ln1)
        mechanism.add(ln2)
        mechanism.add(ln3)
    mechanism.save()
예제 #7
0
def ScaleBarCreation(fs, text_h, drawing):
    # lenght of 1 cm scalebar
    fs1 = fs / 100
    drawing.add_layer('scale_bar', color=7)
    # insertion point of scale bar
    x0 = 10.
    y0 = -20.
    z0 = 0.
    P0 = (x0, y0, z0)
    P1 = (x0, y0 + (fs1 / 20.), z0)
    P2 = ((x0 + fs1), y0, z0)
    P3 = ((x0 + fs1), y0 + (fs1 / 20.), z0)

    line1 = dxf.line(P0, P1)
    line1['layer'] = 'scale_bar'
    drawing.add(line1)

    line2 = dxf.line(P0, P2)
    line2['layer'] = 'scale_bar'
    drawing.add(line2)

    line3 = dxf.line(P2, P3)
    line3['layer'] = 'scale_bar'
    drawing.add(line3)

    text = dxf.text('0', P1, height=text_h)
    text['layer'] = 'scale_bar'
    drawing.add(text)

    text = dxf.text('1 cm', P3, height=text_h)
    text['layer'] = 'scale_bar'
    drawing.add(text)
예제 #8
0
파일: draw.py 프로젝트: e76nystrom/pnc
    def material(self, xSize, ySize):
        if self.svg is not None:
            self.offset = 0.0
            path = self.materialPath
            if path is None:
                self.materialPath = Path(stroke_width=.5, stroke='red', \
                                      fill='none')
                path = self.materialPath
            path.push('M', (self.scaleOffset((0, 0))))
            path.push('L', (self.scaleOffset((xSize, 0))))
            path.push('L', (self.scaleOffset((xSize, ySize))))
            path.push('L', (self.scaleOffset((0, ySize))))
            path.push('L', (self.scaleOffset((0, 0))))

            self.path.push('M', (self.scaleOffset((0, 0))))

            # dwg = svgwrite.Drawing(name, (svg_size_width, svg_size_height), \
            # debug=True)

        cfg = self.cfg
        if self.d is not None:
            orientation = cfg.orientation
            if orientation == O_UPPER_LEFT:
                p0 = (0.0, 0.0)
                p1 = (xSize, 0.0)
                p2 = (xSize, -ySize)
                p3 = (0.0, -ySize)
            elif orientation == O_LOWER_LEFT:
                p0 = (0.0, 0.0)
                p1 = (xSize, 0.0)
                p2 = (xSize, ySize)
                p3 = (0.0, ySize)
            elif orientation == O_UPPER_RIGHT:
                p0 = (0.0, 0.0)
                p1 = (-xSize, 0.0)
                p2 = (-xSize, -ySize)
                p3 = (0.0, -ySize)
            elif orientation == O_LOWER_RIGHT:
                p0 = (0.0, 0.0)
                p1 = (-xSize, 0.0)
                p2 = (-xSize, ySize)
                p3 = (0.0, ySize)
            elif orientation == O_CENTER:
                p0 = (-xSize / 2, -ySize / 2)
                p1 = (xSize / 2, -ySize / 2)
                p2 = (xSize / 2, ySize / 2)
                p3 = (-xSize / 2, ySize / 2)
            elif orientation == O_POINT:
                dxfInput = cfg.dxfInput
                p0 = (dxfInput.xMin, dxfInput.yMin)
                p1 = (dxfInput.xMin, dxfInput.yMax)
                p2 = (dxfInput.xMax, dxfInput.yMax)
                p3 = (dxfInput.xMax, dxfInput.yMin)
            else:
                ePrint("invalid orientation")
            self.d.add(dxf.line(p0, p1, layer=self.lBorder))
            self.d.add(dxf.line(p1, p2, layer=self.lBorder))
            self.d.add(dxf.line(p2, p3, layer=self.lBorder))
            self.d.add(dxf.line(p3, p0, layer=self.lBorder))
def dxflist_example(x=0, y=0, w=1, h=1):
    # dxf list can contain any dxf entity, that supports __dxf__()
    rect = dxfwrite.DXFList()
    rect.append(dxf.line(start=(x, y), end=(x + w, y), color=1))
    rect.append(dxf.line(start=(x + w, y), end=(x + w, y + h), color=2))
    rect.append(dxf.line(start=(x + w, y + h), end=(x, y + h), color=3))
    rect.append(dxf.line(start=(x, y + h), end=(x, y), color=4))
    return rect
예제 #10
0
def dxflist_example(x=0, y=0, w=1, h=1):
    # dxf list can contain any dxf entity, that supports __dxf__()
    rect = dxfwrite.DXFList()
    rect.append(dxf.line(start=(x, y), end=(x+w, y), color=1))
    rect.append(dxf.line(start=(x+w, y), end=(x+w, y+h), color=2))
    rect.append(dxf.line(start=(x+w, y+h), end=(x, y+h), color=3))
    rect.append(dxf.line(start=(x, y+h), end=(x, y), color=4))
    return rect
예제 #11
0
    def removeOverlappingVerticalLines(self, for_prime_center):

        for x in self.x_unique:
            vertical_lines = self.getVerticalLinesPerXValue(x)

            i = 0
            j = 1

            while self.thereAreOverlappingLines(vertical_lines):
                l1 = vertical_lines[i]
                l2 = vertical_lines[j]
                
                if i != j:
                    if l1.overlaps(l2):
                        if l2.end_point[1] > l1.end_point[1]:
                            l1.setEndPoint(l2.end_point)

                        if l2.start_point[1] < l1.start_point[1]:
                            l1.setStartPoint(l2.start_point)

                        del vertical_lines[j]

                        i = 0
                        j = 1
                    else:
                        if (j + 1 >= len(vertical_lines)):
                            if (i + 1 >= len(vertical_lines)):
                                break
                            else:
                                i += 1
                                j = 0
                        else:
                            j += 1
                else:
                    if (j + 1 >= len(vertical_lines)):
                        if (i + 1 >= len(vertical_lines)):
                            break
                        else:
                            i += 1
                            j = 0
                    else:
                        j += 1            
            
            if for_prime_center == True:
                for line in vertical_lines:
                    new_line = Line()
                    new_line.setStartPoint([Helper.toMillimeters(line.start_point[1]), Helper.toMillimeters(line.start_point[0])])
                    new_line.setEndPoint([Helper.toMillimeters(line.end_point[1]), Helper.toMillimeters(line.end_point[0])])    

                    x = Helper.toMillimeters(x)

                    self.lines_without_overlap.append(new_line)
                    self.dxf_lines_without_overlap.append(dxf.line((new_line.start_point[1], x), (new_line.end_point[1], x)))
            else:
                for line in vertical_lines:
                    dxf_line = dxf.line((x, line.start_point[1]), (x, line.end_point[1]), color=random.randint(0, 255), thickness=100.0)
                    self.lines_without_overlap.append(line)
                    self.dxf_lines_without_overlap.append(dxf_line)
예제 #12
0
def outline_arc_line_with_dxfwrite(ai_segments, ai_outline_closed):
    """ Generates the arcs and lines outline with the mozman dxfwrite
  """
    dxf_points = [tuple((ai_segments[0][0], ai_segments[0][1]))]
    segment_nb = len(ai_segments) - 1
    dxf_outline = []
    for i in range(segment_nb):
        segment_type = 'line'
        dxf_points.append(tuple(
            (ai_segments[i + 1][0], ai_segments[i + 1][1])))
        point_start = dxf_points[-2]
        point_end = dxf_points[-1]
        if (len(ai_segments[i + 1]) == 4):
            segment_type = 'arc'
            dxf_points.append(
                tuple((ai_segments[i + 1][2], ai_segments[i + 1][3])))
            point_start = dxf_points[-3]
            point_mid = dxf_points[-2]
            point_end = dxf_points[-1]
        if (i == segment_nb - 1):
            #print("dbg306: last segment")
            if (ai_outline_closed):
                #print("dbg307: close")
                point_end = dxf_points[0]
        #print("dbg563: i: {:d}  segment: {:s}".format(i, segment_type))
        if (segment_type == 'line'):
            #dxf_line = DXFEngine.line(start=point_start, end=point_end, color=7, layer=default_dxf_layer_name)
            dxf_line = DXFEngine.line(start=point_start, end=point_end)
            dxf_outline.append(dxf_line)
        elif (segment_type == 'arc'):
            (lia, ptix, ptiy, u, v, w, uv, vw,
             uw) = arc_3_points_to_radius_center_angles(
                 point_start, point_mid, point_end)
            u2 = u
            w2 = u + uw
            if (uw < 0):
                #w2 = u + uw + 2*math.pi
                u2 = w
                w2 = u
            #print("dbg384: lia {:0.3f}  ptix {:0.3f}  ptiy {:0.3f}  u2 {:0.3f}  w2 {:0.3f}".format(lia, ptix, ptiy, u2*180/math.pi, w2*180/math.pi))
            if (
                    lia == 0
            ):  # when arc_3_points_to_radius_center_angles found that the 3 points are too colinear
                dxf_arc = DXFEngine.line(start=point_start, end=point_end)
            else:
                dxf_arc = DXFEngine.arc(lia, (ptix, ptiy), u2 * 180 / math.pi,
                                        w2 * 180 / math.pi)
            dxf_outline.append(dxf_arc)
            #arc_polyline = arc_of_circle(point_start, point_mid, point_end, unit_circle_resolution)
            #arc_polyline_dxf = []
            #for i in arc_polyline:
            #  arc_polyline_dxf.append(tuple(i))
            ##dxf_polyline = DXFEngine.polyline(arc_polyline_dxf, color=7, layer=default_dxf_layer_name)
            ##dxf_polyline = DXFEngine.polyline(arc_polyline_dxf, flags=DXFEngine.POLYLINE_3D_POLYLINE)
            #dxf_polyline = DXFEngine.polyline(arc_polyline_dxf)
            #dxf_outline.append(dxf_polyline)
    r_outline = dxf_outline
    return (r_outline)
def drawRectangle(drawing,topLeft,w,h):

    dX,dY = topLeft
    

    drawing.add(dxf.line((dX,dY),(dX + w,dY)))
    drawing.add(dxf.line((dX,dY),(dX,dY + h)))
    drawing.add(dxf.line((dX + w,dY),(dX + w,dY + h)))
    drawing.add(dxf.line((dX,dY + h),(dX + w,dY + h)))
def drawBox(drawing, topLeft, size = 0.5):
    

    dX,dY = topLeft
    

    drawing.add(dxf.line((dX,dY),(dX + size,dY)))
    drawing.add(dxf.line((dX,dY),(dX,dY + size)))
    drawing.add(dxf.line((dX + size,dY),(dX + size,dY + size)))
    drawing.add(dxf.line((dX,dY + size),(dX + size,dY + size)))
예제 #15
0
def triangle( cx, cy, sz):
    cx0 = cx
    cy0 = cy - TOP_Y * sz
    cx1 = cx - sz/2
    cy1 = cy + BOT_Y * sz
    cx2 = cx + sz/2
    cy2 = cy + BOT_Y * sz
    drawing.add(dxf.line((cx0, cy0), (cx1, cy1), layer='Prova'))
    drawing.add(dxf.line((cx1, cy1), (cx2, cy2), color=4))
    drawing.add(dxf.line((cx2, cy2), (cx0, cy0), color=2))
예제 #16
0
class DXFPlato(Plato):
    """Plate renderer with DXF backend."""

    # DXF colours are specified as indexes in to a colour table.
    stroke_default = 7  # White
    stroke_alt = 6  # Magenta

    def __init__(self, file_path='out.dxf', **kwargs):
        """Create instance with this file name."""
        super(DXFPlato, self).__init__(**kwargs)
        self.drawing = dxf.drawing(file_path)

    def save(self):
        """Write to file."""
        self.drawing.save()

    def draw_roundrect(self,
                       (x, y),
                       (width, height),
                       radius,
                       color=stroke_default,
                       **kwargs):
        """Draw a rectangle with rounded corners."""
        left, right = x - 0.5 * width, x + 0.5 * width
        bottom, top = y - 0.5 * height, y + 0.5 * height

        self.drawing.add(
            dxf.line((left + radius, bottom), (right - radius, bottom),
                     color=color))
        self.drawing.add(
            dxf.arc(radius, (right - radius, bottom + radius),
                    270,
                    0,
                    color=color))
        self.drawing.add(
            dxf.line((right, bottom + radius), (right, top - radius),
                     color=color))
        self.drawing.add(
            dxf.arc(radius, (right - radius, top - radius), 0, 90,
                    color=color))
        self.drawing.add(
            dxf.line((left + radius, top), (right - radius, top), color=color))
        self.drawing.add(
            dxf.arc(radius, (left + radius, top - radius),
                    90,
                    180,
                    color=color))
        self.drawing.add(
            dxf.line((left, bottom + radius), (left, top - radius),
                     color=color))
        self.drawing.add(
            dxf.arc(radius, (left + radius, bottom + radius),
                    180,
                    270,
                    color=color))
예제 #17
0
    def cutOutRectangle(self, cx, cy, width, length, bit_diameter, cutx, cuty):

        ## copy class parameters
        drawing = self.drawing

        ## draw both x-lines
        ##  shorten lines appropriately, if cutx set to 1 == yes
        drawing.add(
            dxf.line((cx + cutx * bit_diameter, cy),
                     (cx + width - cutx * bit_diameter, cy)))
        drawing.add(
            dxf.line((cx + cutx * bit_diameter, cy + length),
                     (cx + width - cutx * bit_diameter, cy + length)))

        ## draw both y-lines
        ##  shorten lines appropriately, if cutx set to 1 == yes
        drawing.add(
            dxf.line((cx, cy + cuty * bit_diameter),
                     (cx, cy + length - cuty * bit_diameter)))
        drawing.add(
            dxf.line((cx + width, cy + cuty * bit_diameter),
                     (cx + width, cy + length - cuty * bit_diameter)))

        ## draw the dog-ears for both x-lines, if wanted
        if cutx == 1:
            drawing.add(
                dxf.arc(bit_diameter / 2, (cx + bit_diameter / 2, cy), 180,
                        360))
            drawing.add(
                dxf.arc(bit_diameter / 2, (cx + width - bit_diameter / 2, cy),
                        180, 360))
            drawing.add(
                dxf.arc(bit_diameter / 2, (cx + bit_diameter / 2, cy + length),
                        360, 180))
            drawing.add(
                dxf.arc(bit_diameter / 2,
                        (cx + width - bit_diameter / 2, cy + length), 360,
                        180))

        ## draw the dog-ears for both y-lines, if wanted
        if cuty == 1:
            drawing.add(
                dxf.arc(bit_diameter / 2, (cx, cy + bit_diameter / 2), 90,
                        270))
            drawing.add(
                dxf.arc(bit_diameter / 2, (cx, cy + length - bit_diameter / 2),
                        90, 270))
            drawing.add(
                dxf.arc(bit_diameter / 2, (cx + width, cy + bit_diameter / 2),
                        270, 90))
            drawing.add(
                dxf.arc(bit_diameter / 2,
                        (cx + width, cy + length - bit_diameter / 2), 270, 90))
def drawBoxGrid(drawing,topLeft, n = 6, boxSize = 0.5,gapSize = 0.5):
    dX,dY = topLeft

    for i in range(n):
        drawing.add(dxf.line((dX-gapSize,dY+i*(boxSize+gapSize)),(dX+gapSize,dY+i*(boxSize+gapSize))))
        
        for j in range(n):
            drawBox(drawing,(dX+i*(boxSize+gapSize),dY+j*(boxSize+gapSize)),boxSize)
        

        
    drawing.add(dxf.line((dX,dY-gapSize),(dX,dY+boxSize*(n-1) +gapSize*n)))
예제 #19
0
def outline_arc_line_with_dxfwrite(ai_segments, ai_outline_closed):
  """ Generates the arcs and lines outline with the mozman dxfwrite
  """
  dxf_points = [tuple((ai_segments[0][0], ai_segments[0][1]))]
  segment_nb = len(ai_segments)-1
  dxf_outline = []
  for i in range(segment_nb):
    segment_type = 'line'
    dxf_points.append(tuple((ai_segments[i+1][0], ai_segments[i+1][1])))
    point_start = dxf_points[-2]
    point_end = dxf_points[-1]
    if(len(ai_segments[i+1])==4):
      segment_type = 'arc'
      dxf_points.append(tuple((ai_segments[i+1][2], ai_segments[i+1][3])))
      point_start = dxf_points[-3]
      point_mid = dxf_points[-2]
      point_end = dxf_points[-1]
    if(i==segment_nb-1):
      #print("dbg306: last segment")
      if(ai_outline_closed):
        #print("dbg307: close")
        point_end = dxf_points[0]
    #print("dbg563: i: {:d}  segment: {:s}".format(i, segment_type))
    if(segment_type=='line'):
      #dxf_line = DXFEngine.line(start=point_start, end=point_end, color=7, layer=default_dxf_layer_name)
      dxf_line = DXFEngine.line(start=point_start, end=point_end)
      dxf_outline.append(dxf_line)
    elif(segment_type=='arc'):
      (lia, ptix, ptiy, u, v, w, uv, vw, uw) = arc_3_points_to_radius_center_angles(point_start, point_mid, point_end)
      u2 = u
      w2 = u + uw
      if(uw<0):
        #w2 = u + uw + 2*math.pi
        u2 = w
        w2 = u
      #print("dbg384: lia {:0.3f}  ptix {:0.3f}  ptiy {:0.3f}  u2 {:0.3f}  w2 {:0.3f}".format(lia, ptix, ptiy, u2*180/math.pi, w2*180/math.pi))
      if(lia==0): # when arc_3_points_to_radius_center_angles found that the 3 points are too colinear
        dxf_arc = DXFEngine.line(start=point_start, end=point_end)
      else:
        dxf_arc = DXFEngine.arc(lia, (ptix, ptiy), u2*180/math.pi, w2*180/math.pi)
      dxf_outline.append(dxf_arc)
      #arc_polyline = arc_of_circle(point_start, point_mid, point_end, unit_circle_resolution)
      #arc_polyline_dxf = []
      #for i in arc_polyline:
      #  arc_polyline_dxf.append(tuple(i))
      ##dxf_polyline = DXFEngine.polyline(arc_polyline_dxf, color=7, layer=default_dxf_layer_name)
      ##dxf_polyline = DXFEngine.polyline(arc_polyline_dxf, flags=DXFEngine.POLYLINE_3D_POLYLINE)
      #dxf_polyline = DXFEngine.polyline(arc_polyline_dxf)
      #dxf_outline.append(dxf_polyline)
  r_outline = dxf_outline
  return(r_outline)
예제 #20
0
    def draw_borders(self):
        min_x = -self.output_spacing
        max_x = self.output_width
        min_y = -self.output_spacing
        max_y = self.output_height

        self.dxf_drawing.add(dxf.line(start=(min_x, min_y),
                                      end=(min_x, max_y)))
        self.dxf_drawing.add(dxf.line(start=(min_x, min_y),
                                      end=(max_x, min_y)))
        self.dxf_drawing.add(dxf.line(start=(max_x, min_y),
                                      end=(max_x, max_y)))
        self.dxf_drawing.add(dxf.line(start=(min_x, max_y),
                                      end=(max_x, max_y)))
예제 #21
0
def tile(width, height, offsetX=0, offsetY=0, drawing=None, allNegative=False):
    if drawing is None:
        drawing = empty_drawing()
    entities = []
    for x in range(0, width):
        px = 32 * x + offsetX
        xDir = Direction.NORTH if x % 2 == 0 else Direction.SOUTH
        for y in range(0, height):
            yDir = Direction.WEST if y % 2 == 0 else Direction.EAST
            py = 32 * y + offsetY
            # right
            if x == width - 1:
                right = notchedLine(px + 32, py, yDir)
                if allNegative:
                    right = notchedLine(px + 32, py, Direction.EAST)
                entities.append(right)
            # top
            if y == height - 1:
                top = notchedLine(px, py + 32, xDir)
                if allNegative:
                    top = notchedLine(px, py + 32, Direction.NORTH)
                entities.append(top)
            # bottom
            bottom = dxf.line((px, py), (px + 32, py), layer='mark')
            if y == 0:
                bottom = notchedLine(px, py, xDir)
                if allNegative:
                    bottom = notchedLine(px, py, Direction.SOUTH)
            entities.append(bottom)
            # left
            left = dxf.line((px, py), (px, py + 32), layer='mark')
            if x == 0:
                left = notchedLine(px, py, yDir)
                if allNegative:
                    left = notchedLine(px, py, Direction.WEST)
            entities.append(left)
            # circles
            entities.append(
                dxf.circle(radius=circle_rad,
                           center=(px + 4, py + 4),
                           layer='engrave'))
            entities.append(
                dxf.circle(radius=circle_rad,
                           center=(px + 28, py + 28),
                           layer='engrave'))
    for entity in entities:
        drawing.add(entity)
    return drawing
예제 #22
0
def generate_dxf(root_path, session_id, lines_dict, sheet_length):
    x_offset = int(sheet_length * 1.1)
    y_offset = 30
    keys = lines_dict.keys()

    drawing = dxf.drawing(root_path + "/data/" + session_id + '/cutout.dxf')
    drawing.add_layer('LINES')

    for i in range(len(keys)):
        key = keys[i]
        for line in lines_dict[key]:
            start = (line[0][0] + x_offset * i, line[0][1] + y_offset)
            end = (line[1][0] + x_offset * i, line[1][1] + y_offset)
            drawing.add(dxf.line(start, end, color=7, layer='LINES'))

    drawing.add_layer('TEXTLAYER', color=2)

    for i in range(len(keys)):
        key = keys[i]
        drawing.add(
            dxf.text(key,
                     insert=(i * x_offset, 0),
                     layer='TEXTLAYER',
                     height=25))

    drawing.add_vport('*ACTIVE',
                      upper_right=(100, 100),
                      center_point=(50, 50),
                      grid_spacing=(1, 1),
                      snap_spacing=(1, 1),
                      aspect_ratio=20)
    drawing.save()
def drawSlotCube(drawing,topLeft,baseSideLength,slotDepth=0,numSlots=0,cornerdepth=0):
    oX,oY = topLeft
    L = baseSideLength

    squarePositions =[
        (1,0),
        (1,1),
        (0,2),
        (1,2),
        (2,2),
        (1,3)]

    linesDict = {}

    for square in squarePositions:
        dX = oX + square[0]*L
        dY = oY + square[1]*L

        for side in [((0,0),(0,L)),((0,0),(L,0)),((L,L),(0,L)),((L,L),(L,0))]:
            line = ((dX + side[0][0], dY + side[0][1]),(dX + side[1][0], dY + side[1][1]))
            
            if line not in linesDict:
                linesDict[line] = "Single"
            else:
                linesDict[line] = "Double"

    for line in linesDict:
        if linesDict[line] == "Single":
            print line
            drawing.add(dxf.line(line[0],line[1]))
예제 #24
0
파일: draw.py 프로젝트: e76nystrom/pnc
    def materialOutline(self, lines, layer=None):
        cfg = self.cfg
        if self.svg is not None:
            self.xOffset = 0.0
            self.yOffset = cfg.dxfInput.ySize
            self.svg.add(Rect((0, 0), (cfg.dxfInput.xSize * self.pScale, \
                                       cfg.dxfInput.ySize * self.pScale), \
                              fill='rgb(255, 255, 255)'))
            path = self.materialPath
            if path is None:
                self.materialPath = Path(stroke_width=.5, stroke='red', \
                                         fill='none')
                path = self.materialPath
            for l in lines:
                (start, end) = l
                path.push('M', (self.scaleOffset(start)))
                path.push('L', (self.scaleOffset(end)))

        if self.d is not None:
            if layer is None:
                layer = self.lBorder
            for l in lines:
                (start, end) = l
                self.d.add(dxf.line(cfg.dxfInput.fix(start), \
                                    cfg.dxfInput.fix(end), layer=layer))
예제 #25
0
파일: meDXF.py 프로젝트: soldocode/mystuff
def Draw(p):

    lay=0
    path=p['path']
    n=p['nodes']
    d=p['drawing']
    rx=p['position'][0]
    ry=p['position'][1]
    if 'layer' in p.keys(): lay=p['layer']

    for c in path:
        if c[0]=='line':
            d.add(dxf.line((rx+n[c[1]][0],ry+n[c[1]][1]),
                           (rx+n[c[2]][0],ry+n[c[2]][1]),layer=lay))
        elif c[0]=='arc':
            cr=geo.CircleFrom3Points(n[c[1]],n[c[3]],n[c[2]])
            if cr['Direction']<0:
                d.add(dxf.arc(center=(rx+cr['Center'][0],ry+cr['Center'][1]),
                              radius=cr['Radius'],
                              startangle=math.degrees(cr['P1Degree']),
                              endangle=math.degrees(cr['P3Degree']),
                              layer=lay))
            else:    
                d.add(dxf.arc(center=(rx+cr['Center'][0],ry+cr['Center'][1]),
                              radius=cr['Radius'],
                              startangle=math.degrees(cr['P3Degree']),
                              endangle=math.degrees(cr['P1Degree']),
                              layer=lay))
            
        elif c[0]=='circle':
            rds=n[c[2]][0]-n[c[1]][0]
            d.add(dxf.circle(rds,(rx+n[c[1]][0],ry+n[c[1]][1]),layer=lay))
예제 #26
0
def drawLineColouredLayer(draw, pxOrig, pyOrig, pxDstn, pyDstn, colorL, capa):
    linex = dxf.line((pxOrig, pyOrig), (pxDstn, pyDstn))
    linex["color"] = colorL
    linex["layer"] = capa
    draw.add(linex)
    draw.add_layer(capa, color=colorL)
    return pxDstn, pyDstn
def drawline(points_list):
    for i in range(len(points_list) - 1):
            if(i==8):
                continue
            c = tuple(points_list[i])
            d = tuple(points_list[i+1])
            drawing.add(dxf.line(c, d, color=7))
def drawline(points_list):
    for i in range(len(points_list) - 1):
        if(i == 7):
            continue
        c = tuple(scale_factor*p for p in points_list[i])
        d = tuple(scale_factor*q for q in points_list[i+1])
        drawing.add(dxf.line(c, d, color=7))
예제 #29
0
def block(length, height, inner_height, inner_length):
    block_lx = -length / 2
    block_rx = length / 2
    block_y = float(elem1[1])
    vertical_depth = (length - inner_length) / 2

    drawing.add(
        dxf.line((block_lx, block_y), (block_rx, block_y),
                 color=75,
                 layer='Block'))

    block_height = block_y + height
    horizontal_depth = height - inner_height
    inner_lx = block_lx + vertical_depth
    inner_rx = block_rx - vertical_depth
    inner_y = block_y + horizontal_depth

    blockList = [(block_lx, block_y), (block_rx, block_y),
                 (block_rx, block_height), (inner_rx, block_height),
                 (inner_rx, inner_y), (inner_lx, inner_y),
                 (inner_lx, block_height), (block_lx, block_height),
                 (block_lx, block_y)]

    drawing.add(dxf.polyline(blockList, color=75, layer='Block'))
    return blockList
def arrow(bottom_point,arrow_point, length_arrow = 3):
    drawing.add(dxf.line(bottom_point,arrow_point, color= 7))
    vertex = arrow_point
    left_pt = (arrow_point[0] - length_arrow / 6.0 , arrow_point[1] - length_arrow )
    right_pt = (arrow_point[0] + length_arrow / 6.0 , arrow_point[1] - length_arrow)
    drawing.add(dxf.trace([vertex, left_pt, right_pt]))
    return
예제 #31
0
def drawLineColouredLayer(draw, pxOrig, pyOrig, pxDstn, pyDstn, colorL, capa):
    linex = dxf.line((pxOrig, pyOrig), (pxDstn, pyDstn))
    linex['color'] = colorL
    linex['layer'] = capa
    draw.add(linex)
    draw.add_layer(capa, color=colorL)
    return pxDstn, pyDstn
예제 #32
0
파일: box.py 프로젝트: ocxtal/box.py
def plot(drawing, a, offset):
	a0 = a[0]
	a1 = a[1]
	prev_point = [a0[0][0]+offset[0], a0[0][1]+offset[1]]
	for elem in a0:
		point = [elem[0]+offset[0], elem[1]+offset[1]]
		drawing.add(dxf.line(prev_point, [point[0], prev_point[1]], color=7))
		drawing.add(dxf.line([point[0], prev_point[1]], point, color=7))
		prev_point = point

	prev_point = [a1[0][0]+offset[0], a1[0][1]+offset[1]]
	for elem in a1:
		point = [elem[0]+offset[0], elem[1]+offset[1]]
		drawing.add(dxf.line(prev_point, [prev_point[0], point[1]], color=7))
		drawing.add(dxf.line([prev_point[0], point[1]], point, color=7))
		prev_point = point
def drawline(points_list):
    for i in range(len(points_list) - 1):
            if(i==10):
                continue
            c = tuple(points_list[i])
            d = tuple(points_list[i+1])
            drawing.add(dxf.line(c, d, color=7))
def arrow(bottom_point,arrow_point, length_arrow = 3):
    drawing.add(dxf.line(bottom_point,arrow_point, color= 7))
    vertex = arrow_point
    left_pt = (arrow_point[0] - length_arrow / 6.0 , arrow_point[1] - length_arrow )
    right_pt = (arrow_point[0] + length_arrow / 6.0 , arrow_point[1] - length_arrow)
    drawing.add(dxf.trace([vertex, left_pt, right_pt]))
    return
예제 #35
0
 def line(self, xd, yd):
     if self._pen_down and (xd != 0 or yd != 0):
         self.dwg.add(dxf.line(
             (self.x, self.y),
             (self.x + xd, self.y + yd),
             layer=self.name,
         ))
     self.move(xd, yd)
예제 #36
0
    def addLargeHorizontalLineAtTop(self):
        y_start = Helper.toMillimeters(self.getHighestVerticalPoint())
        x_start = 0
        y_end = Helper.toMillimeters(self.getHighestVerticalPoint())
        x_end = Helper.toMillimeters(self.getWidth() + 20)

        line = dxf.line((y_start, x_start), (y_end, x_end))
        self.dxf_drawing.add(line)
예제 #37
0
def generate_dxf(layouts_list):
    """
    Generate dxfs for each layout. Name the file based on the mat spec:
    Date_mat_color_W_H_numpanel
    Save file in directory based on job# (batch#?)
    """

    # Create new directory with job name
    dir_path = create_dir("TEST")

    # For each layout, create a new dir:
    for l in layouts_list:
        color = l.color
        thickness = l.thickness
        file_path = os.path.join(dir_path,
                                 "{0}_{1}mm".format(l.color, l.thickness))
        if not os.path.exists(file_path):
            os.makedirs(file_path)
        os.chdir(file_path)

        # for each panel in the layout
        index = 0
        for panel in l.layout:
            drawing = dxf.drawing('panel_{}_w_{}_h_{}.dxf'.format(
                index, panel.width, panel.height))
            drawing.add_layer('LINES')
            for rect in panel:
                x = rect.x
                y = rect.y
                w = rect.width
                h = rect.height

                drawing.add(
                    dxf.line((x, y), (x + w, y), color=7, layer='LINES'))
                drawing.add(
                    dxf.line((x + w, y), (x + w, y + h),
                             color=7,
                             layer='LINES'))
                drawing.add(
                    dxf.line((x + w, y + h), (x, y + h),
                             color=7,
                             layer='LINES'))
                drawing.add(
                    dxf.line((x, y + h), (x, y), color=7, layer='LINES'))
            drawing.save()
            index += 1
예제 #38
0
def DXFWrite(edges, filename):
  from dxfwrite import DXFEngine as dxf
  dwg = dxf.drawing(filename)
  for e in edges:
    if e[2] is None:
      kwargs = {"layer": "Cut"}
    else:
      kwargs = {"layer": repr(e[2])}
    dwg.add(dxf.line((e[0][0], e[0][1]), (e[1][0], e[1][1]), **kwargs))
  dwg.save()
예제 #39
0
파일: graph.py 프로젝트: donrv/ROSLab
def DXFWrite(edges, filename):
    from dxfwrite import DXFEngine as dxf
    dwg = dxf.drawing(filename)
    for e in edges:
        if e[2] is None:
            kwargs = {"layer": "Cut"}
        else:
            kwargs = {"layer": repr(e[2])}
        dwg.add(dxf.line((e[0][0], e[0][1]), (e[1][0], e[1][1]), **kwargs))
    dwg.save()
예제 #40
0
def dxfSketch(VPointList, VLinkList, fileName):
    edges = v_to_slvs(VPointList, VLinkList)
    mechanism = dxf.drawing(fileName)
    for vpoint in VPointList:
        mechanism.add(dxf.point((vpoint.cx, vpoint.cy)))
    for p1, p2 in edges:
        vp1 = VPointList[p1]
        vp2 = VPointList[p2]
        mechanism.add(dxf.line((vp1.cx, vp1.cy), (vp2.cx, vp2.cy)))
    mechanism.save()
예제 #41
0
def print_box(grid_x,
              grid_y,
              offset,
              angle,
              mirror,
              bend_width=5,
              rng=grid_spacing,
              hinge=0.07):
    x_min = grid_x * rng
    y_min = grid_y * rng
    ref = np.array([x_min, y_min])

    if angle < 0.1 and not flag:
        return
    top_left = (np.array([bend_width, 0]), np.array([offset, offset + angle]))
    bottom_right = (np.array([rng - bend_width, rng]),
                    np.array([rng - offset, rng - (offset + angle)]))
    top_right = (np.array([rng, bend_width]),
                 np.array([rng - (offset + angle), offset]))
    bottom_left = (np.array([0, rng - bend_width]),
                   np.array([offset + angle, rng - offset]))

    lines = [top_left, top_right, bottom_right, bottom_left]

    lines = [line + ref for line in lines]

    if mirror:
        lines = [[point[::-1] for point in line] for line in lines]

    for l in lines:
        line = dxf.line(l[0], l[1], color=7)
        drawing.add(line)

    square = []
    for i in range(len(lines)):
        line = dxf.line(lines[i][1],
                        (hinge * lines[i][1] + lines[i - 1][1]) / (1 + hinge),
                        color=7)
        square.append(lines[i][1])
        drawing.add(line)

    square.reverse()
예제 #42
0
def dxfwrite(t1):
  i=0
  t1=t1.append(t1[0])
  n=len(t1)-1
  print("Начало")
  drawing = dxf.drawing('test.dxf')
  drawing.add_layer('LINES')
  while i<n:
    drawing.add(dxf.line((t1[i][0], t1[i][1]), (t1[i+1][0], t1[i+1][1]), color=7, layer='LINES'))
    i=i+1
  drawing.save()
예제 #43
0
 def writeDxf(self, nodeDict, drawing, layerName):
     numNodes = len(self.nodeIds)
     if (numNodes == 2):
         coordsA = nodeDict[self.nodeIds[0]].coords
         coordsB = nodeDict[self.nodeIds[1]].coords
         drawing.add(
             DXFEngine.line((coordsA[0], coordsA[1], coordsA[2]),
                            (coordsB[0], coordsB[1], coordsB[2]),
                            color=0,
                            layer=layerName))
     elif (numNodes == 3):
         coordsA = nodeDict[self.nodeIds[0]].coords
         coordsB = nodeDict[self.nodeIds[1]].coords
         coordsC = nodeDict[self.nodeIds[2]].coords
         drawing.add(
             DXFEngine.face3d([(coordsA[0], coordsA[1], coordsA[2]),
                               (coordsB[0], coordsB[1], coordsB[2]),
                               (coordsC[0], coordsC[1], coordsC[2])],
                              color=0,
                              layer=layerName))
     elif (numNodes == 4):
         coordsA = nodeDict[self.nodeIds[0]].coords
         coordsB = nodeDict[self.nodeIds[1]].coords
         coordsC = nodeDict[self.nodeIds[2]].coords
         coordsD = nodeDict[self.nodeIds[3]].coords
         drawing.add(
             DXFEngine.face3d([(coordsA[0], coordsA[1], coordsA[2]),
                               (coordsB[0], coordsB[1], coordsB[2]),
                               (coordsC[0], coordsC[1], coordsC[2]),
                               (coordsD[0], coordsD[1], coordsD[2])],
                              color=0,
                              layer=layerName))
     else:
         for i in range(0, numNodes - 1):
             coordsA = nodeDict[self.nodeIds[i]].coords
             coordsB = nodeDict[self.nodeIds[i + 1]].coords
             drawing.add(
                 DXFEngine.line((coordsA[0], coordsA[1], coordsA[2]),
                                (coordsB[0], coordsB[1], coordsB[2]),
                                color=0,
                                layer=layerName))
예제 #44
0
파일: trees.py 프로젝트: kmartine/trees
def dxf_gen():
    drawing = dxf.drawing(sys.argv[2] + ".dxf")
    drawing.header['$LUNITS'] = 4
    drawing.add_layer('LINES')

    for i in xrange(len(coords)):
       drawing.add(dxf.line((coords[i-1].x, coords[i-1].y),
                                  (coords[i].x,coords[i].y),
                                  color=1,
                                  layer='LINES'))

    drawing.save()
예제 #45
0
def koch(x1, y1, x2, y2, size):
    angle = 60*pi/180
    x3 = (2*x1 + x2)/3
    y3 = (2*y1 + y2)/3

    x4 = (x1 + 2*x2)/3
    y4 = (y1 + 2*y2)/3
 
    x = x3 + (x4 - x3)*cos(angle) + (y4 - y3)*sin(angle)
    y = y3 - (x4 - x3)*sin(angle) + (y4 - y3)*cos(angle)

    if(size > 0):
        koch(x1,y1,x3,y3, size-1)
        koch(x3,y3,x,y, size-1)
        koch(x,y,x4,y4, size-1)
        koch(x4,y4,x2,y2, size-1)
    else :
        drawing.add(dxf.line((x1, y1), (x3, y3), layer='Prova'))
        drawing.add(dxf.line((x3, y3), (x, y), layer='Prova'))
        drawing.add(dxf.line((x, y), (x4, y4), layer='Prova'))
        drawing.add(dxf.line((x4, y4), (x2, y2), layer='Prova'))
예제 #46
0
def textblock(mtext, x, y, rot, color=3, mirror=0):
    dwg.add(dxf.line((x+50, y), (x+50, y+50),  color=color))
    dwg.add(dxf.line((x+100, y), (x+100, y+50), color=color))
    dwg.add(dxf.line((x+150, y), (x+150, y+50), color=color))

    dwg.add(dxf.line((x+50, y), (x+150, y), color=color))
    dwg.add(dxf.mtext(mtext, (x+50, y), mirror=mirror, rotation=rot))
    dwg.add(dxf.mtext(mtext, (x+100, y), mirror=mirror, rotation=rot,
                      halign=dxfwrite.CENTER))
    dwg.add(dxf.mtext(mtext, (x+150, y), mirror=mirror, rotation=rot,
                      halign=dxfwrite.RIGHT))

    dwg.add(dxf.line((x+50, y+25), (x+150, y+25), color=color))
    dwg.add(dxf.mtext(mtext, (x+50, y+25), mirror=mirror, rotation=rot,
                      valign=dxfwrite.MIDDLE))
    dwg.add(dxf.mtext(mtext, (x+100, y+25), mirror=mirror, rotation=rot,
                      valign=dxfwrite.MIDDLE, halign=dxfwrite.CENTER))
    dwg.add(dxf.mtext(mtext, (x+150, y+25), mirror=mirror, rotation=rot,
                      valign=dxfwrite.MIDDLE, halign=dxfwrite.RIGHT))

    dwg.add(dxf.line((x+50, y+50), (x+150, y+50), color=color))
    dwg.add(dxf.mtext(mtext, (x+50, y+50), mirror=mirror,
                      valign=dxfwrite.BOTTOM, rotation=rot))
    dwg.add(dxf.mtext(mtext, (x+100, y+50), mirror=mirror,
                      valign=dxfwrite.BOTTOM, rotation=rot,
                      halign=dxfwrite.CENTER))
    dwg.add(dxf.mtext(mtext, (x+150, y+50), mirror=mirror,
                      valign=dxfwrite.BOTTOM, rotation=rot,
                      halign=dxfwrite.RIGHT))
예제 #47
0
def drawconti(data):
    for i in range(len(data) - 1):
        element1 = tuple(data[i])
        element2 = tuple(data[i + 1])
        """drawing lines for base. First 10 lines in CSV contains the
        coordinates that will create the base.
        """
        if i < 9:
            drawing.add(dxf.line(element1, element2, color=50, layer='Base'))
            # pdb.set_trace()
            points.append(element1)
        elif i < 11:
            points.append(element1)
예제 #48
0
파일: draw.py 프로젝트: e76nystrom/pnc
 def hole(self, end, drillSize):
     if self.enable:
         if self.svg is not None:
             self.path.push('L', self.scaleOffset(end))
             # dprt("svg line %7.4f %7.4f" % self.scaleOffset(end))
             self.svg.add(Circle(self.scaleOffset(end), \
                                 (drillSize / 2) * self.pScale, \
                                 stroke='black', stroke_width=.5, \
                                 fill="none"))
         if self.d is not None:
             self.d.add(dxf.line(self.last, end, layer=self.lPath))
             self.d.add(dxf.circle(drillSize / 2, end, layer=self.lHole))
     self.last = end
예제 #49
0
파일: dxf.py 프로젝트: davidbebb/camcam
def line_dxf(self, direction=True):
    c = self.parent.get_config()
    if 'z1' in c and c['z1'] is not None and c['z1'] is not False:
        colour = colour_from_z(c['z1'])
    elif hasattr(self, 'z1'):
        colour = colour_from_z(self.z1)
    elif (hasattr(self, "parent") and hasattr(self.parent, 'z1')):
        colour = colour_from_z(self.parent.z1)
    else:
        colour = 1
    if (direction):
        return [
            dxf.line((self.cutfrom[0], self.cutfrom[1]),
                     (self.cutto[0], self.cutto[1]),
                     color=colour)
        ]
    else:
        return [
            dxf.line((self.cutto[0], self.cutto[1]),
                     (self.cutfrom[0], self.cutfrom[1]),
                     color=colour)
        ]
예제 #50
0
def drawconti(data):
    for i in range(len(data) - 1):
        element1 = tuple(data[i])
        element2 = tuple(data[i+1])

        """drawing lines for base. First 10 lines in CSV contains the
        coordinates that will create the base.
        """
        if i < 9:
            drawing.add(dxf.line(element1, element2, color=50, layer='Base'))
            # pdb.set_trace()
            points.append(element1)
        elif i < 11:
            points.append(element1)
예제 #51
0
  def draw_lines(self, i):
    drawn = set()
    d = self.ds[i]
    all_fold_edges = self.fold_edges[i]
    all_cut_edges = self.cut_edges[i]
    edge_numbering = self.edge_numbering
    for k in d:
      v1, v2, v3 = d[k].transformed_vertices
      v1 = tuple(v1)
      v2 = tuple(v2)
      v3 = tuple(v3)
      cut_edges = all_cut_edges[k]
      fold_edges = all_fold_edges[k]
      
      for j, edge in enumerate([(v1,v2), (v2,v3), (v3,v1)]):
        if edge not in drawn:
          if cut_edges[j] != None and edge not in drawn:  
            self.drawings[i].add(dxf.line(edge[0][:2], edge[1][:2], color=self.cutting_color))
            drawn.add(edge)

          elif fold_edges[j] != None and edge not in drawn:
            self.drawings[i].add(dxf.line(edge[0][:2], edge[1][:2], color=self.folding_color1))
            drawn.add(edge)
예제 #52
0
파일: box1.py 프로젝트: ruddj/Box-Creator
 def save(self):
     """A function with joins all the points in self.allpoints together and chucks it onto the same file as the directory the
        file is located at: DEPRECIATED!!! Use insert() into an empty drawing, only for debugging/legacy"""
     prev_point = None
     drawing = dxf.drawing('forcedsave.dxf')
     drawing.add_layer("LINES")
     for list_points in self.all_points:
         for point in list_points:
             if prev_point:
                 drawing.add(
                     dxf.line(prev_point,
                              point,
                              thickness=K_THICKNESS,
                              color=K_RED,
                              layer="LINES"))
             prev_point = point
     drawing.add(
         dxf.line(prev_point,
                  self.all_points[0][0],
                  thickness=K_THICKNESS,
                  color=K_RED,
                  layer="LINES"))
     save_read_only(drawing, name='forcedsave.dxf')
예제 #53
0
def decoding(word, pos, dim, space):
    for z in range(len(word)):
        c = word[z]
        if( c == 'F'):
            drawing.add(dxf.line((pos[0][0], pos[0][1]), 
                (pos[1][0], pos[1][1]), color = 2))
            translate(pos, space)
        elif( c == 'G'):
            translate(pos, space)
        elif(c == '+'):
            rotate(theta, pos, dim)
        elif(c == '-'):
            rotate(-theta, pos, dim)
        elif(c == '['):
            old_pos.append(pos)
        elif(c == ']'):
            pos = old_pos.pop()
예제 #54
0
파일: gpx2dxf.py 프로젝트: 2000dB/scripts
def draw_gpx(g, d):
    """
    Draws gpx trk points to the specified a dxf file
    Each gpx file gets drawn to a corresponding layer
    """
    try:
        gpx_file = open(g + ".gpx", 'r' )
    except:
        print "error opening file: " + g + ".gpx"
        
    gpx_parser = parser.GPXParser(gpx_file)
    gpx_parser.parse()
    gpx_file.close()
    gpx = gpx_parser.get_gpx()

    for track in gpx.tracks:
        for segment in track.segments:
            point_num = len(segment.points)
            for i in range(point_num-1):
                d.add(dxf.line((segment.points[i].latitude, segment.points[i].longitude),(segment.points[i+1].latitude, segment.points[i+1].longitude),
                               layer=g.split('/')[-1]))
예제 #55
0
def pts_to_dxf(pts, name='test.dxf'):
    """
    Takes a set of (x,y) points, interpolates the curve, then writes to dxf.
    
    Args:
        curve: the (x,y) points to be converted. Do not duplicate endpoints
        name: filename of output
    """
    curve = make_shape(pts, max_output_len=300)
    assert len(curve[0]) == len(curve[1])
    cpts = list(zip(*curve))
    cpts.append(cpts[0]) # duplicate endpoints
    n_pts = len(cpts)
    drawing = dxf.drawing(name)
    drawing.add_layer('LINES')
    # build points
    i = 0
    while i < n_pts-1:
        drawing.add(dxf.line(cpts[i], cpts[i+1], color=7, layer='LINES'))
        i += 1
    drawing.save()
예제 #56
0
def block(length, height, inner_height, inner_length):
    block_lx = -length / 2
    block_rx = length / 2
    block_y = float(elem1[1])
    vertical_depth = (length - inner_length) / 2

    drawing.add(dxf.line((block_lx, block_y), (block_rx, block_y), color=75,
                         layer='Block'))

    block_height = block_y + height
    horizontal_depth = height - inner_height
    inner_lx = block_lx + vertical_depth
    inner_rx = block_rx - vertical_depth
    inner_y = block_y + horizontal_depth

    blockList = [(block_lx, block_y), (block_rx, block_y),
                 (block_rx, block_height), (inner_rx, block_height),
                 (inner_rx, inner_y),  (inner_lx, inner_y),
                 (inner_lx, block_height), (block_lx, block_height),
                 (block_lx, block_y)]

    drawing.add(dxf.polyline(blockList, color=75, layer='Block'))
    return blockList
예제 #57
0
파일: meDXF.py 프로젝트: soldocode/mystuff
    def drawPath(self,
                 outlines=mePath.Outline(),
                 xy=[0,0],
                 layer=-1):
        
                     
        self.Paths.append(outlines)#???
        lay=layer
        path=outlines.Path
        n=outlines.Nodes
        d=self.DXFDrawing
        rx=xy[0]
        ry=xy[1]

        for c in path:
         if c[0]=='line':
            d.add(dxf.line((rx+n[c[1]][0],ry+n[c[1]][1]),
                           (rx+n[c[2]][0],ry+n[c[2]][1]),layer=lay))
         elif c[0]=='arc':
            cr=geo.CircleFrom3Points(n[c[1]],n[c[3]],n[c[2]])
            if cr['Direction']<0:
                d.add(dxf.arc(center=(rx+cr['Center'][0],ry+cr['Center'][1]),
                              radius=cr['Radius'],
                              startangle=math.degrees(cr['P1Degree']),
                              endangle=math.degrees(cr['P3Degree']),
                              layer=lay))
            else:    
                d.add(dxf.arc(center=(rx+cr['Center'][0],ry+cr['Center'][1]),
                              radius=cr['Radius'],
                              startangle=math.degrees(cr['P3Degree']),
                              endangle=math.degrees(cr['P1Degree']),
                              layer=lay))
            
         elif c[0]=='circle':
            rds=n[c[2]][0]-n[c[1]][0]
            d.add(dxf.circle(rds,(rx+n[c[1]][0],ry+n[c[1]][1]),layer=lay))
예제 #58
0
파일: e_max.py 프로젝트: leszekdubicki/e2s
	def converttodxf(self, nazwapliku = None, points = True, d3d = True):
		#konwertuje uzywajac modulu dxfwrite
		#points - czy wstawiac punkty wybierane podczas montazu
		if nazwapliku == None:
			nazwapliku = os.path.basename(self._nazwa_pliku)[:-3]+"dxf"
		from dxfwrite import DXFEngine as dxf
		drawing = dxf.drawing(nazwapliku)
		for OBJ in self._objects:
			#print "hehe"
			if OBJ==None:
				continue
			if OBJ.type()=='POINT':
				p=OBJ.P()
				if d3d:
					drawing.add(dxf.point((p[0],p[1],p[2])))
				else:
					drawing.add(dxf.point((p[0],p[1])))
			elif OBJ.type()=='LINE':
				p1=OBJ.P1(); p2=OBJ.P2()
				drawing.add(dxf.line((p1[0], p1[1]), (p2[0], p2[1])))
				#ent = adoc.CreateLine2(p1[0]/1000., p1[1]/1000., p1[2]/1000., p2[0]/1000., p2[1]/1000., p2[2]/1000.)
			elif OBJ.type()=='CIRCLE':
				p1=OBJ.O()
				drawing.add(dxf.circle(OBJ.d()/2.,(p1[0], p1[1])))
				#ent = adoc.CreateCircle2(p1[0]/1000., p1[1]/1000., p1[2]/1000., p2[0]/1000., p2[1]/1000., p2[2]/1000.)
			if points and not OBJ.type()=="POINT":
				PTS = OBJ.meas_points()
				print "dodawanie punktow pomiarowych:"
				for pp in PTS:
					#print (pp[0],pp[1],pp[2])
					if d3d:
						drawing.add(dxf.point((pp[0],pp[1],pp[2])))
					else:
						drawing.add(dxf.point((pp[0],pp[1])))
					
		drawing.save()
예제 #59
0
def dxf_render(pattern, x, y, spacing):
  drawing = dxf.drawing("spray_pattern.dxf")
  drawing.add_layer("2D")

  # if the spacing does not correlate perfectly with sample size, Research-o-Matic will add another loop to overspray and ensure coverage
  if y % spacing != 0:
    y = floor(y) + spacing 

  if pattern == "grid": # classic square grid pattern
    horline = 0
    vertline = 0
    if x % spacing != 0:
      x = floor(x) + spacing
    while horline <= y :
        drawing.add(dxf.line((0, horline), (x, horline), color=7, layer="2D"))
        horline += spacing
    while vertline < x:
        drawing.add(dxf.line((vertline, 0), (vertline, y), color=7, layer="2D"))
        vertline += spacing

  elif pattern == "horlines": # a collection of uni-directional lines sprayed horizontally (x-direction) going from left to right(-x to +x)
    horline = 0
    while horline <= y :
      drawing.add(dxf.line((0, horline), (x, horline), color=7, layer="2D"))
      horline += spacing
   
  else: # default pattern of "snakes" from the eponymous game
    horline = 0
    vertlineright = 0
    vertlineleft = spacing
    while horline <= y :
        drawing.add(dxf.line((0, horline), (x, horline), color=7, layer="2D"))
        horline += spacing
    while vertlineright < y:
        drawing.add(dxf.line((x, vertlineright), (x, vertlineright + spacing), color=7, layer="2D"))
        vertlineright += 2 * spacing
    while vertlineleft < y:
        drawing.add(dxf.line((0, vertlineleft), (0, vertlineleft + spacing), color=7, layer="2D"))
        vertlineleft += 2 * spacing
  drawing.saveas("spray_pattern.dxf")