1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2022 CEA/DES, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
29 from datetime import datetime
30 random.seed(datetime.now())
34 from TopIIVolMeshPluginDialog_ui import Ui_TopIIVolMeshMainFrame
35 from TopIIVolMeshMonitor import TopIIVolMeshMonitor
36 from qtsalome import *
40 class TopIIVolMeshPluginDialog(Ui_TopIIVolMeshMainFrame,QWidget):
44 QWidget.__init__(self)
46 self.qpbHelp.clicked.connect(self.OnQpbHelpClicked)
47 self.qpbCompute.clicked.connect(self.OnQpbComputeClicked)
48 self.qpbMeshFile.clicked.connect(self.OnQpbMeshFileClicked)
49 self.qpbMeshFile.setToolTip("Select input DEM file")
50 self.qpbClose.clicked.connect(self.OnQpbCloseClicked)
51 self.qcbDistributed.stateChanged[int].connect(self.OnqcbDistributedClicked)
52 self.qlbXParts.setVisible(False)
53 self.qlbYParts.setVisible(False)
54 self.qlbZParts.setVisible(False)
55 self.qsbXParts.setVisible(False)
56 self.qsbYParts.setVisible(False)
57 self.qsbZParts.setVisible(False)
58 self.SALOME_TMP_DIR = None
60 self.qleTmpDir.setText(os.path.join('/tmp',getpass.getuser(),'top-ii-vol'))
62 self.qleTmpDir.setText('/tmp')
65 def OnQpbHelpClicked(self):
67 sgPyQt = SalomePyQt.SalomePyQt()
69 mydir=os.environ["SMESH_ROOT_DIR"]
71 QMessageBox.warning(self, "Help", "Help unavailable $SMESH_ROOT_DIR not found")
74 myDoc=mydir + "/share/doc/salome/gui/SMESH/TopIIVolMesh/index.html"
75 sgPyQt.helpContext(myDoc,"")
77 def OnQpbMeshFileClicked(self):
78 fd = QFileDialog(self, "select an existing Mesh file", self.qleMeshFile.text(), "Mesh-Files (*.xyz);;All Files (*)")
80 infile = fd.selectedFiles()[0]
81 self.qleMeshFile.setText(infile)
83 def OnQpbComputeClicked(self):
84 if self.qleMeshFile.text() == '':
85 QMessageBox.critical(self, "Mesh", "select an input mesh")
87 inputMesh = self.qleMeshFile.text()
88 # retrieve x,y,z and depth parameters
89 xPoints = self.qsbXPoints.value()
90 yPoints = self.qsbYPoints.value()
91 zPoints = self.qsbZPoints.value()
92 depth = self.qsbDepth.value()
93 nProcs = self.qsbNBprocs.value()
94 if not self.qcbDistributed.isChecked():
96 shellCmd = "topIIvol_Mesher"
98 shellCmd = "mpirun -np {} topIIvol_ParMesher".format(nProcs)
99 shellCmd+= " --xpoints " + str(xPoints)
100 shellCmd+= " --ypoints " + str(yPoints)
101 shellCmd+= " --zpoints " + str(zPoints)
102 shellCmd+= " --depth " + str(depth)
103 shellCmd+= " --in " + inputMesh
105 xParts = self.qsbXParts.value()
106 yParts = self.qsbYParts.value()
107 zParts = self.qsbZParts.value()
108 shellCmd = "mpirun -np {} topIIvol_DistMesher".format(nProcs)
109 shellCmd+= " --xpoints " + str(xPoints)
110 shellCmd+= " --ypoints " + str(yPoints)
111 shellCmd+= " --zpoints " + str(zPoints)
112 shellCmd+= " --depth " + str(depth)
113 shellCmd+= " --partition_x " + str(xParts)
114 shellCmd+= " --partition_y " + str(yParts)
115 shellCmd+= " --partition_z " + str(zParts)
116 shellCmd+= " --in " + inputMesh
117 if platform.system()=="Windows" :
118 self.SALOME_TMP_DIR = os.getenv("SALOME_TMP_DIR")
120 self.SALOME_TMP_DIR = os.path.join(self.qleTmpDir.text(), time.strftime("%Y-%m-%d-%H-%M-%S"))
121 pathlib.Path(self.SALOME_TMP_DIR).mkdir(parents=True, exist_ok=True)
122 self.outputMesh= os.path.join(self.SALOME_TMP_DIR, inputMesh.split('/').pop().replace('.xyz','.mesh'))
123 shellCmd+= " --out " + self.outputMesh
124 print("INFO: ", shellCmd)
125 myMonitorView=TopIIVolMeshMonitor(self, shellCmd)
127 def OnqcbDistributedClicked(self):
128 state = self.qcbDistributed.isChecked()
129 self.qlbXParts.setVisible(state)
130 self.qlbYParts.setVisible(state)
131 self.qlbZParts.setVisible(state)
132 self.qsbXParts.setVisible(state)
133 self.qsbYParts.setVisible(state)
134 self.qsbZParts.setVisible(state)
136 def OnQpbCloseClicked(self):
139 def saveOutputMesh(self):
140 if not self.qcbDisplayMesh.isChecked():
143 import SMESH, SALOMEDS
144 from salome.smesh import smeshBuilder
145 smesh = smeshBuilder.New()
146 self.outputMesh.split('/')
147 for mesh in pathlib.Path(self.SALOME_TMP_DIR).glob('*.mesh'):
148 (outputMesh, status) = smesh.CreateMeshesFromGMF(os.path.join(self.SALOME_TMP_DIR, mesh))
149 if salome.sg.hasDesktop():
150 salome.sg.updateObjBrowser()
157 This function returns a singleton instance of the plugin dialog.
158 It is mandatory in order to call show without a parent ...
161 if __instance is None:
162 __instance = TopIIVolMeshPluginDialog()