1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2024 CEA/DES, EDF
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.qrbDist.clicked.connect(self.OnqrbDistClicked)
52 self.qrbPar.clicked.connect(self.OnqrbParClicked)
53 self.qrbSeq.clicked.connect(self.OnqrbSeqClicked)
54 self.SALOME_TMP_DIR = None
56 self.qleTmpDir.setText(os.path.join('/tmp',getpass.getuser(),'top-ii-vol'))
58 self.qleTmpDir.setText('/tmp')
61 def OnQpbHelpClicked(self):
63 sgPyQt = SalomePyQt.SalomePyQt()
65 mydir=os.environ["SMESH_ROOT_DIR"]
67 QMessageBox.warning(self, "Help", "Help unavailable $SMESH_ROOT_DIR not found")
70 myDoc=mydir + "/share/doc/salome/gui/SMESH/TopIIVolMesh/index.html"
71 sgPyQt.helpContext(myDoc,"")
73 def OnQpbMeshFileClicked(self):
74 fd = QFileDialog(self, "select an existing Mesh file", self.qleMeshFile.text(), "Mesh-Files (*.xyz);;All Files (*)")
76 infile = fd.selectedFiles()[0]
77 self.qleMeshFile.setText(infile)
79 def OnQpbComputeClicked(self):
80 if self.qleMeshFile.text() == '':
81 QMessageBox.critical(self, "Mesh", "select an input mesh")
83 inputMesh = self.qleMeshFile.text()
84 # retrieve x,y,z and depth parameters
85 xPoints = self.qsbXPoints.value()
86 yPoints = self.qsbYPoints.value()
87 zPoints = self.qsbZPoints.value()
88 depth = self.qsbDepth.value()
89 nProcs = self.qsbNBprocs.value()
90 if not self.qrbDist.isChecked():
92 shellCmd = "topIIvol_Mesher"
94 shellCmd = "mpirun -np {} topIIvol_ParMesher".format(nProcs)
95 shellCmd+= " --xpoints " + str(xPoints)
96 shellCmd+= " --ypoints " + str(yPoints)
97 shellCmd+= " --zpoints " + str(zPoints)
98 shellCmd+= " --depth " + str(depth)
99 shellCmd+= " --in " + inputMesh
101 xParts = self.qsbXParts.value()
102 yParts = self.qsbYParts.value()
103 zParts = self.qsbZParts.value()
104 shellCmd = "mpirun -np {} topIIvol_DistMesher".format(nProcs)
105 shellCmd+= " --xpoints " + str(xPoints)
106 shellCmd+= " --ypoints " + str(yPoints)
107 shellCmd+= " --zpoints " + str(zPoints)
108 shellCmd+= " --depth " + str(depth)
109 shellCmd+= " --partition_x " + str(xParts)
110 shellCmd+= " --partition_y " + str(yParts)
111 shellCmd+= " --partition_z " + str(zParts)
112 shellCmd+= " --in " + inputMesh
113 if platform.system()=="Windows" :
114 self.SALOME_TMP_DIR = os.getenv("SALOME_TMP_DIR")
116 self.SALOME_TMP_DIR = os.path.join(self.qleTmpDir.text(), time.strftime("%Y-%m-%d-%H-%M-%S"))
117 pathlib.Path(self.SALOME_TMP_DIR).mkdir(parents=True, exist_ok=True)
118 self.outputMesh= os.path.join(self.SALOME_TMP_DIR, inputMesh.split('/').pop().replace('.xyz','.mesh'))
119 shellCmd+= " --out " + self.outputMesh
120 os.chdir(self.SALOME_TMP_DIR)
121 print("INFO: ", shellCmd)
122 myMonitorView=TopIIVolMeshMonitor(self, shellCmd)
124 def OnqrbDistClicked(self):
125 state = self.qrbDist.isChecked()
126 self.qgbDist.setEnabled(state)
127 self.qsbNBprocs.setEnabled(state)
128 self.qlbNBprocs.setEnabled(state)
130 def OnqrbParClicked(self):
131 state = self.qrbPar.isChecked()
132 self.qgbDist.setEnabled(not state)
133 self.qsbNBprocs.setEnabled(state)
134 self.qlbNBprocs.setEnabled(state)
136 def OnqrbSeqClicked(self):
137 state = self.qrbSeq.isChecked()
139 self.qsbNBprocs.setValue(1)
140 self.qgbDist.setEnabled(not state)
141 self.qsbNBprocs.setEnabled(not state)
142 self.qlbNBprocs.setEnabled(not state)
144 def OnQpbCloseClicked(self):
147 def saveOutputMesh(self):
148 if not self.qcbDisplayMesh.isChecked():
151 import SMESH, SALOMEDS
152 from salome.smesh import smeshBuilder
153 smesh = smeshBuilder.New()
154 self.outputMesh.split('/')
155 for mesh in pathlib.Path(self.SALOME_TMP_DIR).glob('*.mesh'):
156 (outputMesh, status) = smesh.CreateMeshesFromGMF(os.path.join(self.SALOME_TMP_DIR, mesh))
157 if salome.sg.hasDesktop():
158 salome.sg.updateObjBrowser()
165 This function returns a singleton instance of the plugin dialog.
166 It is mandatory in order to call show without a parent ...
169 if __instance is None:
170 __instance = TopIIVolMeshPluginDialog()