salome: salomePanelExample.py

File salomePanelExample.py, 3.0 KB (added by brankm, 7 years ago)

Primer za izdelavo panela. Brez numpy knjiznice.

Line 
1import salome
2import GEOM
3from salome.geom import geomBuilder
4geompy = geomBuilder.New(salome.myStudy)
5
6# Load data
7# If file is not opened, determine path with os library
8# import os
9# os.chdir(os.path.expanduser('~/'))
10with open('data.txt','r') as f:
11    fileread = f.readlines()
12    content = [x.strip() for x in fileread]
13    # Define data list
14    data = []
15    for coord in content:
16        data.append([x.strip() for x in coord.split(" ")])
17f.close()
18
19coord_x = []
20coord_y = []
21# convert coordinates to mm and to float type
22for i in range(len(data)):
23    data[i][0] = float(data[i][0])*(1000)
24    data[i][1] = float(data[i][1])*(1000)
25    data[i][2] = float(data[i][1])*(1000)
26    coord_x.append(data[i][0])
27    coord_y.append(data[i][1])
28
29
30# mirror x coordinatex over yz - plane
31coord_mirror_x = coord_x[::-1]
32for n in range(len(coord_mirror_x)):
33    coord_mirror_x[n] = coord_mirror_x[n]*(-1)
34coord_mirror_y = coord_y[::-1]
35
36# Iterate over coord_x and create geompy vertices and store those
37# vertices into python list.
38points_x = []
39for i in range(len(coord_x)):
40    point_x = geompy.MakeVertex(coord_x[i],coord_y[i],0)
41    points_x.append(point_x)
42
43points_y = []
44for i in range(len(coord_x)):
45    point_y = geompy.MakeVertex(coord_mirror_x[i],coord_mirror_y[i],0)
46    points_y.append(point_y)
47
48# Create B-Spline curve on the set of points with
49# geompy.MakeInterpol() and add curve to Salome study.
50b_spline = geompy.MakeInterpol(points_x)
51b_splineID = geompy.addToStudy(b_spline,"b_spline_ft")
52
53b_spline_mirror = geompy.MakeInterpol(points_y)
54b_splineID_mirror = geompy.addToStudy(b_spline_mirror,"b_spline_ft_mirrored")
55
56# Create line between both curves.
57ml_point1 = geompy.MakeVertex(-coord_x[0],coord_y[0],0)
58ml_point2 = geompy.MakeVertex(coord_x[0],coord_y[0],0)
59middle_line = geompy.MakeLineTwoPnt(ml_point1,ml_point2)
60middle_lineID = geompy.addToStudy(middle_line,"middle_line")
61
62# Create wire out of all three components
63wire = geompy.MakeWire([b_spline_mirror,middle_line,b_spline])
64wireID = geompy.addToStudy(wire,"wire")
65
66# Load data for extrusion
67dataExtrusion = []
68with open('dataPolyline.txt','r') as f:
69    fileread = f.readlines()
70    content = [x.strip() for x in fileread]
71    # Define data list
72    for coord in content:
73        dataExtrusion.append([x.strip() for x in coord.split(" ")])
74f.close()
75
76# Read data for extrusion
77coord_xe = []
78coord_ye = []
79coord_ze = []
80for n in range(len(dataExtrusion)):
81    coord_xe.append(float(dataExtrusion[n][0]))
82    coord_ye.append(float(dataExtrusion[n][1]))
83    coord_ze.append(float(dataExtrusion[n][2]))
84
85# Convert data to geompy point and store it in a list.
86points_e = []
87for coord_e in range(len(coord_xe)):
88    point_e = geompy.MakeVertex(coord_xe[coord_e],coord_ye[coord_e],coord_ze[coord_e])
89    points_e.append(point_e)
90
91# Create polyline for extrusion and add it to study.
92polylineVert = geompy.MakePolyline(points_e)
93polylineVertID = geompy.addToStudy(polylineVert,"polyline_ft_vert")
94
95# Create panel shape
96panel_FW = geompy.MakePipe(polylineVert, wire)
97geompy.addToStudy(panel_FW,'Panel')
98salome.sg.updateObjBrowser(True)
99