1 | # import libraries |
---|
2 | import salome |
---|
3 | import GEOM |
---|
4 | from salome.geom import geomBuilder |
---|
5 | import os |
---|
6 | from functools import partial |
---|
7 | # GUI library |
---|
8 | from PyQt5.QtWidgets import * |
---|
9 | from PyQt5.QtCore import * |
---|
10 | from PyQt5.QtGui import * |
---|
11 | from PyQt5 import QtWidgets |
---|
12 | import math |
---|
13 | geompy = geomBuilder.New(salome.myStudy) |
---|
14 | |
---|
15 | def createPanel(): |
---|
16 | global panelIsMade, panel_FW |
---|
17 | panelIsMade = True |
---|
18 | # If file is not opened, determine path with os library |
---|
19 | os.chdir(os.path.expanduser('d:/vaje_KT/')) |
---|
20 | with open('data.txt','r') as f: |
---|
21 | fileread = f.readlines() |
---|
22 | content = [x.strip() for x in fileread] |
---|
23 | # Define data list |
---|
24 | data = [] |
---|
25 | for coord in content: |
---|
26 | data.append([x.strip() for x in coord.split(" ")]) |
---|
27 | f.close() |
---|
28 | |
---|
29 | coord_x = [] |
---|
30 | coord_y = [] |
---|
31 | # convert coordinates to mm and to float type |
---|
32 | for i in range(len(data)): |
---|
33 | data[i][0] = float(data[i][0])*(1000) |
---|
34 | data[i][1] = float(data[i][1])*(1000) |
---|
35 | data[i][2] = float(data[i][1])*(1000) |
---|
36 | coord_x.append(data[i][0]) |
---|
37 | coord_y.append(data[i][1]) |
---|
38 | |
---|
39 | |
---|
40 | # mirror x coordinatex over yz - plane |
---|
41 | coord_mirror_x = coord_x[::-1] |
---|
42 | for n in range(len(coord_mirror_x)): |
---|
43 | coord_mirror_x[n] = coord_mirror_x[n]*(-1) |
---|
44 | coord_mirror_y = coord_y[::-1] |
---|
45 | |
---|
46 | # Iterate over coord_x and create geompy vertices and store those |
---|
47 | # vertices into python list. |
---|
48 | points_x = [] |
---|
49 | for i in range(len(coord_x)): |
---|
50 | point_x = geompy.MakeVertex(coord_x[i],coord_y[i],0) |
---|
51 | points_x.append(point_x) |
---|
52 | |
---|
53 | points_y = [] |
---|
54 | for i in range(len(coord_x)): |
---|
55 | point_y = geompy.MakeVertex(coord_mirror_x[i],coord_mirror_y[i],0) |
---|
56 | points_y.append(point_y) |
---|
57 | |
---|
58 | # Create B-Spline curve on the set of points with |
---|
59 | # geompy.MakeInterpol() and add curve to Salome study. |
---|
60 | b_spline = geompy.MakeInterpol(points_x) |
---|
61 | b_splineID = geompy.addToStudy(b_spline,"b_spline_ft") |
---|
62 | |
---|
63 | b_spline_mirror = geompy.MakeInterpol(points_y) |
---|
64 | b_splineID_mirror = geompy.addToStudy(b_spline_mirror,"b_spline_ft_mirrored") |
---|
65 | |
---|
66 | # Create line between both curves. |
---|
67 | ml_point1 = geompy.MakeVertex(-coord_x[0],coord_y[0],0) |
---|
68 | ml_point2 = geompy.MakeVertex(coord_x[0],coord_y[0],0) |
---|
69 | middle_line = geompy.MakeLineTwoPnt(ml_point1,ml_point2) |
---|
70 | middle_lineID = geompy.addToStudy(middle_line,"middle_line") |
---|
71 | |
---|
72 | # Create wire out of all three components |
---|
73 | wire = geompy.MakeWire([b_spline_mirror,middle_line,b_spline]) |
---|
74 | wireID = geompy.addToStudy(wire,"wire") |
---|
75 | |
---|
76 | # Load data for extrusion |
---|
77 | dataExtrusion = [] |
---|
78 | with open('dataPolyline.txt','r') as f: |
---|
79 | fileread = f.readlines() |
---|
80 | content = [x.strip() for x in fileread] |
---|
81 | # Define data list |
---|
82 | for coord in content: |
---|
83 | dataExtrusion.append([x.strip() for x in coord.split(" ")]) |
---|
84 | f.close() |
---|
85 | |
---|
86 | # Read data for extrusion |
---|
87 | coord_xe = [] |
---|
88 | coord_ye = [] |
---|
89 | coord_ze = [] |
---|
90 | for n in range(len(dataExtrusion)): |
---|
91 | coord_xe.append(float(dataExtrusion[n][0])) |
---|
92 | coord_ye.append(float(dataExtrusion[n][1])) |
---|
93 | coord_ze.append(float(dataExtrusion[n][2])) |
---|
94 | |
---|
95 | # Convert data to geompy point and store it in a list. |
---|
96 | points_e = [] |
---|
97 | for coord_e in range(len(coord_xe)): |
---|
98 | point_e = geompy.MakeVertex(coord_xe[coord_e],coord_ye[coord_e],coord_ze[coord_e]) |
---|
99 | points_e.append(point_e) |
---|
100 | |
---|
101 | # Create polyline for extrusion and add it to study. |
---|
102 | polylineVert = geompy.MakePolyline(points_e) |
---|
103 | polylineVertID = geompy.addToStudy(polylineVert,"polyline_ft_vert") |
---|
104 | panel_FW = geompy.MakePipe(wire, polylineVert) |
---|
105 | panel_FW = geompy.MakeTranslation(panel_FW, 0,-4200,0) |
---|
106 | geompy.addToStudy(panel_FW,'Panel') |
---|
107 | salome.sg.updateObjBrowser(True) |
---|
108 | |
---|
109 | def createNewPanel(lin1, lin2, lin3): |
---|
110 | # If panel is not made, there is nothing to rotate |
---|
111 | # If lin2.text() is not float, angle cannot be determined |
---|
112 | # If lin3.text() is not int, number of rotated panels cannot be determined |
---|
113 | if panelIsMade and float(lin2.text()) and int(lin3.text()): |
---|
114 | # Create rotation vector around z-axis |
---|
115 | p1 = geompy.MakeVertex(0, 0, 0) |
---|
116 | p2 = geompy.MakeVertex(0, 0, 1) |
---|
117 | v = geompy.MakeVector(p1, p2) |
---|
118 | # This for loop iterates over number of roteted panels and |
---|
119 | # adds angle to every new panel. Result is panel_FW_rotated |
---|
120 | # Name of panel is given by user + angle of rotation |
---|
121 | for nr in range(1,int(lin3.text())+1): |
---|
122 | panel_FW_rotated = geompy.MakeRotation(panel_FW, v, math.pi/180*nr*float(str(lin2.text()))) |
---|
123 | panel_name = str(lin1.text())+"_rotated_"+str(float(str(lin2.text()))*nr)+"_deg" |
---|
124 | geompy.addToStudy(panel_FW_rotated,panel_name) |
---|
125 | salome.sg.updateObjBrowser(True) |
---|
126 | |
---|
127 | |
---|
128 | widgetHDF = QtWidgets.QWidget() |
---|
129 | widgetHDF.setFixedSize(500, 250) |
---|
130 | widgetHDF.setWindowTitle('Rotate panel') |
---|
131 | #widgetHDF.setWindowFlags(widgetHDF.windowFlags() | QtCore.Qt.Window) |
---|
132 | lblPanel = QLabel('Create panel:') |
---|
133 | btnPanel = QPushButton('Create Panel') |
---|
134 | lbl1 = QLabel('Set name for rotation panels:') |
---|
135 | lin1 = QLineEdit('panel4') |
---|
136 | lbl2 = QLabel('Set rotation angle:') |
---|
137 | lin2 = QLineEdit('0') |
---|
138 | lbl3 = QLabel('Set number of rotations:') |
---|
139 | lin3 = QLineEdit('1') |
---|
140 | btn = QPushButton('Apply') |
---|
141 | panelIsMade = False |
---|
142 | |
---|
143 | btnPanel.setToolTip('Create panel') |
---|
144 | btn.setToolTip('Create rotated panels') |
---|
145 | btnPanel.clicked.connect(createPanel) |
---|
146 | btn.clicked.connect(partial(createNewPanel,lin1,lin2,lin3)) |
---|
147 | layout = QtWidgets.QVBoxLayout() |
---|
148 | layout.addWidget(lblPanel) |
---|
149 | layout.addWidget(btnPanel) |
---|
150 | layout.addWidget(lbl1) |
---|
151 | layout.addWidget(lin1) |
---|
152 | layout.addWidget(lbl2) |
---|
153 | layout.addWidget(lin2) |
---|
154 | layout.addWidget(lbl3) |
---|
155 | layout.addWidget(lin3) |
---|
156 | layout.addWidget(btn) |
---|
157 | widgetHDF.setLayout(layout) |
---|
158 | widgetHDF.move(500, 500) |
---|
159 | widgetHDF.show() |
---|
160 | |
---|