# import libraries import salome import GEOM from salome.geom import geomBuilder import os from functools import partial # GUI library from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5 import QtWidgets import math geompy = geomBuilder.New(salome.myStudy) def createPanel(): global panelIsMade, panel_FW panelIsMade = True # If file is not opened, determine path with os library os.chdir(os.path.expanduser('d:/vaje_KT/')) with open('data.txt','r') as f: fileread = f.readlines() content = [x.strip() for x in fileread] # Define data list data = [] for coord in content: data.append([x.strip() for x in coord.split(" ")]) f.close() coord_x = [] coord_y = [] # convert coordinates to mm and to float type for i in range(len(data)): data[i][0] = float(data[i][0])*(1000) data[i][1] = float(data[i][1])*(1000) data[i][2] = float(data[i][1])*(1000) coord_x.append(data[i][0]) coord_y.append(data[i][1]) # mirror x coordinatex over yz - plane coord_mirror_x = coord_x[::-1] for n in range(len(coord_mirror_x)): coord_mirror_x[n] = coord_mirror_x[n]*(-1) coord_mirror_y = coord_y[::-1] # Iterate over coord_x and create geompy vertices and store those # vertices into python list. points_x = [] for i in range(len(coord_x)): point_x = geompy.MakeVertex(coord_x[i],coord_y[i],0) points_x.append(point_x) points_y = [] for i in range(len(coord_x)): point_y = geompy.MakeVertex(coord_mirror_x[i],coord_mirror_y[i],0) points_y.append(point_y) # Create B-Spline curve on the set of points with # geompy.MakeInterpol() and add curve to Salome study. b_spline = geompy.MakeInterpol(points_x) b_splineID = geompy.addToStudy(b_spline,"b_spline_ft") b_spline_mirror = geompy.MakeInterpol(points_y) b_splineID_mirror = geompy.addToStudy(b_spline_mirror,"b_spline_ft_mirrored") # Create line between both curves. ml_point1 = geompy.MakeVertex(-coord_x[0],coord_y[0],0) ml_point2 = geompy.MakeVertex(coord_x[0],coord_y[0],0) middle_line = geompy.MakeLineTwoPnt(ml_point1,ml_point2) middle_lineID = geompy.addToStudy(middle_line,"middle_line") # Create wire out of all three components wire = geompy.MakeWire([b_spline_mirror,middle_line,b_spline]) wireID = geompy.addToStudy(wire,"wire") # Load data for extrusion dataExtrusion = [] with open('dataPolyline.txt','r') as f: fileread = f.readlines() content = [x.strip() for x in fileread] # Define data list for coord in content: dataExtrusion.append([x.strip() for x in coord.split(" ")]) f.close() # Read data for extrusion coord_xe = [] coord_ye = [] coord_ze = [] for n in range(len(dataExtrusion)): coord_xe.append(float(dataExtrusion[n][0])) coord_ye.append(float(dataExtrusion[n][1])) coord_ze.append(float(dataExtrusion[n][2])) # Convert data to geompy point and store it in a list. points_e = [] for coord_e in range(len(coord_xe)): point_e = geompy.MakeVertex(coord_xe[coord_e],coord_ye[coord_e],coord_ze[coord_e]) points_e.append(point_e) # Create polyline for extrusion and add it to study. polylineVert = geompy.MakePolyline(points_e) polylineVertID = geompy.addToStudy(polylineVert,"polyline_ft_vert") panel_FW = geompy.MakePipe(wire, polylineVert) panel_FW = geompy.MakeTranslation(panel_FW, 0,-4200,0) geompy.addToStudy(panel_FW,'Panel') salome.sg.updateObjBrowser(True) def createNewPanel(lin1, lin2, lin3): # If panel is not made, there is nothing to rotate # If lin2.text() is not float, angle cannot be determined # If lin3.text() is not int, number of rotated panels cannot be determined if panelIsMade and float(lin2.text()) and int(lin3.text()): # Create rotation vector around z-axis p1 = geompy.MakeVertex(0, 0, 0) p2 = geompy.MakeVertex(0, 0, 1) v = geompy.MakeVector(p1, p2) # This for loop iterates over number of roteted panels and # adds angle to every new panel. Result is panel_FW_rotated # Name of panel is given by user + angle of rotation for nr in range(1,int(lin3.text())+1): panel_FW_rotated = geompy.MakeRotation(panel_FW, v, math.pi/180*nr*float(str(lin2.text()))) panel_name = str(lin1.text())+"_rotated_"+str(float(str(lin2.text()))*nr)+"_deg" geompy.addToStudy(panel_FW_rotated,panel_name) salome.sg.updateObjBrowser(True) widgetHDF = QtWidgets.QWidget() widgetHDF.setFixedSize(500, 250) widgetHDF.setWindowTitle('Rotate panel') #widgetHDF.setWindowFlags(widgetHDF.windowFlags() | QtCore.Qt.Window) lblPanel = QLabel('Create panel:') btnPanel = QPushButton('Create Panel') lbl1 = QLabel('Set name for rotation panels:') lin1 = QLineEdit('panel4') lbl2 = QLabel('Set rotation angle:') lin2 = QLineEdit('0') lbl3 = QLabel('Set number of rotations:') lin3 = QLineEdit('1') btn = QPushButton('Apply') panelIsMade = False btnPanel.setToolTip('Create panel') btn.setToolTip('Create rotated panels') btnPanel.clicked.connect(createPanel) btn.clicked.connect(partial(createNewPanel,lin1,lin2,lin3)) layout = QtWidgets.QVBoxLayout() layout.addWidget(lblPanel) layout.addWidget(btnPanel) layout.addWidget(lbl1) layout.addWidget(lin1) layout.addWidget(lbl2) layout.addWidget(lin2) layout.addWidget(lbl3) layout.addWidget(lin3) layout.addWidget(btn) widgetHDF.setLayout(layout) widgetHDF.move(500, 500) widgetHDF.show()