1 | import salome |
---|
2 | import GEOM |
---|
3 | from salome.geom import geomBuilder |
---|
4 | geompy = 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('~/')) |
---|
10 | with 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(" ")]) |
---|
17 | f.close() |
---|
18 | |
---|
19 | coord_x = [] |
---|
20 | coord_y = [] |
---|
21 | # convert coordinates to mm and to float type |
---|
22 | for 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 |
---|
31 | coord_mirror_x = coord_x[::-1] |
---|
32 | for n in range(len(coord_mirror_x)): |
---|
33 | coord_mirror_x[n] = coord_mirror_x[n]*(-1) |
---|
34 | coord_mirror_y = coord_y[::-1] |
---|
35 | |
---|
36 | # Iterate over coord_x and create geompy vertices and store those |
---|
37 | # vertices into python list. |
---|
38 | points_x = [] |
---|
39 | for 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 | |
---|
43 | points_y = [] |
---|
44 | for 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. |
---|
50 | b_spline = geompy.MakeInterpol(points_x) |
---|
51 | b_splineID = geompy.addToStudy(b_spline,"b_spline_ft") |
---|
52 | |
---|
53 | b_spline_mirror = geompy.MakeInterpol(points_y) |
---|
54 | b_splineID_mirror = geompy.addToStudy(b_spline_mirror,"b_spline_ft_mirrored") |
---|
55 | |
---|
56 | # Create line between both curves. |
---|
57 | ml_point1 = geompy.MakeVertex(-coord_x[0],coord_y[0],0) |
---|
58 | ml_point2 = geompy.MakeVertex(coord_x[0],coord_y[0],0) |
---|
59 | middle_line = geompy.MakeLineTwoPnt(ml_point1,ml_point2) |
---|
60 | middle_lineID = geompy.addToStudy(middle_line,"middle_line") |
---|
61 | |
---|
62 | # Create wire out of all three components |
---|
63 | wire = geompy.MakeWire([b_spline_mirror,middle_line,b_spline]) |
---|
64 | wireID = geompy.addToStudy(wire,"wire") |
---|
65 | |
---|
66 | # Load data for extrusion |
---|
67 | dataExtrusion = [] |
---|
68 | with 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(" ")]) |
---|
74 | f.close() |
---|
75 | |
---|
76 | # Read data for extrusion |
---|
77 | coord_xe = [] |
---|
78 | coord_ye = [] |
---|
79 | coord_ze = [] |
---|
80 | for 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. |
---|
86 | points_e = [] |
---|
87 | for 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. |
---|
92 | polylineVert = geompy.MakePolyline(points_e) |
---|
93 | polylineVertID = geompy.addToStudy(polylineVert,"polyline_ft_vert") |
---|
94 | |
---|
95 | # Create panel shape |
---|
96 | panel_FW = geompy.MakePipe(polylineVert, wire) |
---|
97 | geompy.addToStudy(panel_FW,'Panel') |
---|
98 | salome.sg.updateObjBrowser(True) |
---|
99 | |
---|