Пример #1
0
def main(argv):                         
    filename = '../../ag03.dat'
    chord = 10
                      
    try:
        opts, args = getopt.getopt(argv, "c:f:o:", ["chord=", "filename=", "outputfilename="])
    except getopt.GetoptError:          
        usage()                         
        sys.exit(2)
    
    for opt, arg in opts:                
        if opt in ("-c", "chord="):      
            chord = float(arg)               
        elif opt in ("-f", "filename="): 
            filename = str(arg)    
        elif opt in ("-o", "outputfilename="): 
            outputfilename = str(arg)          

    #DXF related INIT
    
    d=sdxf.Drawing()
    d.layers.append(sdxf.Layer(name="textlayer",color=3))
    d.layers.append(sdxf.Layer(name="drawinglayer",color=2))
    #I found the below constant on the internet,  this could use verification
    scale = 100 
    xOffset = 0 
    yOffset = 0
    
    
    linePoints = []
    #pts = ""
    line= 0
    # Read airfoil data
    spamReader = csv.reader(open(filename, 'rb'), delimiter=' ', quotechar='|', skipinitialspace="true")
    for row in spamReader:
        #Skip the first line of header information
        if(line!=0):
            #Format and store in a string
            p= ((float(row[0])*chord+xOffset)*scale, (float(row[1])*-chord+yOffset)*scale)
            linePoints.append(p)
            d.layers.append(sdxf.Point(points=(row[0], row[1]), layer="drawinglayer"))
        line=1            
    print linePoints
    d.append(sdxf.Text('Hello World!',point=(3,0),layer="textlayer"))
    d.layers.append(sdxf.Layer(name="drawinglayer",color=2))
    d.append(sdxf.Text('BLUEKULU!',point=(20,20),layer="drawinglayer"))
    #d.layers.append(sdxf.LineList(points=linePoints, layer="drawinglayer"))
    

    (root, ext) = os.path.splitext(outputfilename)
    saveName = root+'.dxf'    
    d.saveas(saveName)
Пример #2
0
 def __init__(self):
     # create a layer for each pen and give it a matching color
     layers = [
         sdxf.Layer(name=str(pen), color=_pen_to_color[pen])
         for pen in xrange(1, 9)
     ]
     self.dxf = sdxf.Drawing(layers=layers)
Пример #3
0
 def setup(self):
     sdxf.Drawing.__init__(self)
     self.used = [[False for y in range(self.sheet_size[1])]
                  for x in range(self.sheet_size[0])]
     for layer in self.layers:
         if layer.name == "TEXT_LAYER":
             break
     else:
         self.layers.append(
             sdxf.Layer(name="TEXT_LAYER", color=DXFColours.Blue.value()))
Пример #4
0
    def generateCubes(self, d):
        layers = {}

        for x in range(len(self.grid)):
            x2 = x + 1
            for y in range(len(self.grid[x])):
                y2 = y + 1
                for z in range(len(self.grid[x][y])):
                    z2 = z + 1

                    if len(self.grid[x][y][z]) == 0:
                        continue

                    owner = self.grid[x][y][z][0]

                    if owner.colour.value() not in layers:
                        layers[owner.colour.value()] = (
                            "layer-%d" % owner.colour.value()).upper()
                        d.layers.append(
                            sdxf.Layer(name=layers[owner.colour.value()],
                                       color=owner.colour.value()))

                    def doSide(points):
                        d.append(
                            sdxf.Face(points=points,
                                      layer=layers[owner.colour.value()]))

                    doSide([(x, y, z), (x2, y, z), (x2, y2, z), (x, y2, z)])
                    doSide([(x, y, z), (x, y2, z), (x, y2, z2), (x, y, z2)])
                    doSide([(x, y, z), (x2, y, z), (x2, y, z2), (x, y, z2)])

                    doSide([(x2, y2, z2), (x, y2, z2), (x, y, z2),
                            (x2, y, z2)])
                    doSide([(x2, y2, z2), (x2, y, z2), (x2, y, z),
                            (x2, y2, z)])
                    doSide([(x2, y2, z2), (x, y2, z2), (x, y2, z),
                            (x2, y2, z)])
Пример #5
0
import sdxf

# Set your parabola's parameters here
width = 450
focus = width * .23
range = (-width / 2, width / 2)
delta = 5
centerRadius = 5  # radius of circle marking center

d = sdxf.Drawing()

d.layers.append(sdxf.Layer(name="PARABOLA"))


def parabolaPoint(x, focus):
    return (x, (x**2) / (4 * focus))


def addParabola(drawing, focus=1, range=(-5.0, 5.0), delta=0.1):
    middle = sum(range) / 2.0
    if (middle - range[0] < delta):
        p1 = parabolaPoint(range[0], focus)
        p2 = parabolaPoint(range[1], focus)
        drawing.append(sdxf.Line(points=[p1, p2], layer="PARABOLA"))
    else:
        addParabola(drawing, focus, (range[0], middle), delta)
        addParabola(drawing, focus, (middle, range[1]), delta)


d.append(sdxf.Circle(center=(0, focus), radius=centerRadius, layer="PARABOLA"))
addParabola(d, focus, range, delta)
Пример #6
0
"""

import getopt
import sys
import sdxf
import math


#
#	Enter values here to run within the Python IDE.
# 


dxf=sdxf.Drawing()

dxf.layers.append(sdxf.Layer(name="TEXT", color=2) )    #yellow text layer
dxf.layers.append(sdxf.Layer(name="ROTOR", color=1) )     #red rotor layer
dxf.layers.append(sdxf.Layer(name="STATOR", color=5) )  #blue stator layer

# Add text to describe the design
# later dxf.append( sdxf.Text( "lobes="       +str(l), point=(p*n+d, 0.7), layer="text", height=0.1) )

# angle steps = lines in dxf profiles
s = 100
q=2*math.pi/float(s)

#generate the rotor profile
#xhypo(th) := 3*cos(th) + cos(3*th) $
def xhypo(t):
    return 5*math.cos(t)+math.cos(5*t)
	
Пример #7
0
def main():
    print('Введите длины участков b0-b5:')
    b = [0 for _ in range(6)]
    for i in range(6):
        b[i] = input_float('b%d = ' % i,
                           cond=lambda x: x >= 0,
                           msg_on_false_cond='Длина участка не может быть отрицательной.')

    N = int(input_float('Введите количество волн N = ',
                        cond=lambda x: 0 < x < 1000 and int(x) == x,
                        msg_on_false_cond='Количество волн должно быть целым числом больше нуля.'))

    M = int(input_float('Введите количество клетей M = ',
                        cond=lambda x: 1 < x < 1000 and int(x) == x,
                        msg_on_false_cond='Количество клетей должно быть целым числом больше единицы.'))

    amin = Angle(
        deg=input_float('Введите начальный угол Amin = ',
                        cond=lambda x: 0 <= x < 180,
                        msg_on_false_cond='Начальный угол должен быть больше или равен нулю и меньше 180 градусов.'))

    amax = Angle(
        deg=input_float('Введите конечный угол Amax = ',
                        cond=lambda x: amin.deg < x < 180,
                        msg_on_false_cond='Конечный угол должен быть больше начального, но меньше 180 градусов.'))

    eps = 1e-5

    angles = []

    if amin.rad == 0:
        amin = Angle(rad=sys.float_info.epsilon)
        M += 1  # Не считаем полностью развернутый лист клетью
    else:
        angles.append(amin)
    
    # При минимальном угле альфа получается максимальная ширина и наоборот
    Wmax = partial_width(b, amin.rad)
    Wmin = partial_width(b, amax.rad)

    DW = (Wmax-Wmin)/(M-1)
    W = Wmax - DW

    a = amin
    for i in range(M-2):
        a = Angle(rad=secant_method(lambda x: partial_width(b, x)-W, a.rad, amax.rad, eps))
        W -= DW
        angles.append(a)
    angles.append(amax)

    calc = []
    for i, angle in enumerate(angles):
        profile = Profile(b=b, waves=N, angle=angle)
        print('Клеть №%d' % (i+1))
        profile.print()
        print()
        calc.append(profile)
    
    # Write to dxf file
    d = sdxf.Drawing()

    # Reserve two layers
    # d.layers.append(sdxf.Layer('0'))
    # d.append(sdxf.Line(points=[(0, 0), (0, 0)], layer='0'))
    # d.layers.append(sdxf.Layer('1'))
    # d.append(sdxf.Line(points=[(0, 0), (0, 0)], layer='1'))

    for i, profile in enumerate(calc):
        layer = str(i)
        d.layers.append(sdxf.Layer(layer))
        d.extend(profile.dxf_draw(layer=layer))

    fname = input('Введите имя файла dxf: ')
    if not fname:
        fname = 'profile'
    fname += '.dxf'

    d.saveas(fname)

    print('Файл сохранён.')

    input()
Пример #8
0
import sdxf

d = sdxf.Drawing()

#set the color of the text layer to green
d.layers.append(sdxf.Layer(name="textlayer", color=3))

#add drawing elements
d.append(sdxf.Text('Hello World!', point=(3, 0), layer="textlayer"))
d.append(sdxf.Line(points=[(0, 0), (1, 1)], layer="drawinglayer"))

d.saveas('hello_world.dxf')