1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2022 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')
66 def OnQpbHelpClicked(self):
68 sgPyQt = SalomePyQt.SalomePyQt()
70 mydir=os.environ["SMESH_ROOT_DIR"]
72 QMessageBox.warning(self, "Help", "Help unavailable $SMESH_ROOT_DIR not found")
75 myDoc=mydir + "/share/doc/salome/gui/SMESH/TopIIVolMesh/index.html"
76 sgPyQt.helpContext(myDoc,"")
78 def OnQpbMeshFileClicked(self):
79 fd = QFileDialog(self, "select an existing Mesh file", self.qleMeshFile.text(), "Mesh-Files (*.xyz);;All Files (*)")
81 infile = fd.selectedFiles()[0]
82 self.qleMeshFile.setText(infile)
84 def OnQpbComputeClicked(self):
85 if self.qleMeshFile.text() == '':
86 QMessageBox.critical(self, "Mesh", "select an input mesh")
88 inputMesh = self.qleMeshFile.text()
89 # retrieve x,y,z and depth parameters
90 xPoints = self.qsbXPoints.value()
91 yPoints = self.qsbYPoints.value()
92 zPoints = self.qsbZPoints.value()
93 depth = self.qsbDepth.value()
94 nProcs = self.qsbNBprocs.value()
95 if not self.qcbDistributed.isChecked():
97 shellCmd = "topIIvol_Mesher"
99 shellCmd = "mpirun -np {} topIIvol_ParMesher".format(nProcs)
100 shellCmd+= " --xpoints " + str(xPoints)
101 shellCmd+= " --ypoints " + str(yPoints)
102 shellCmd+= " --zpoints " + str(zPoints)
103 shellCmd+= " --depth " + str(depth)
104 shellCmd+= " --in " + inputMesh
106 xParts = self.qsbXParts.value()
107 yParts = self.qsbYParts.value()
108 zParts = self.qsbZParts.value()
109 shellCmd = "mpirun -np {} topIIvol_DistMesher".format(nProcs)
110 shellCmd+= " --xpoints " + str(xPoints)
111 shellCmd+= " --ypoints " + str(yPoints)
112 shellCmd+= " --zpoints " + str(zPoints)
113 shellCmd+= " --depth " + str(depth)
114 shellCmd+= " --partition_x " + str(xParts)
115 shellCmd+= " --partition_y " + str(yParts)
116 shellCmd+= " --partition_z " + str(zParts)
117 shellCmd+= " --in " + inputMesh
118 if platform.system()=="Windows" :
119 self.SALOME_TMP_DIR = os.getenv("SALOME_TMP_DIR")
121 self.SALOME_TMP_DIR = os.path.join(self.qleTmpDir.text(), time.strftime("%Y-%m-%d-%H-%M-%S"))
122 pathlib.Path(self.SALOME_TMP_DIR).mkdir(parents=True, exist_ok=True)
123 self.outputMesh= os.path.join(self.SALOME_TMP_DIR, inputMesh.split('/').pop().replace('.xyz','.mesh'))
124 shellCmd+= " --out " + self.outputMesh
125 print("INFO: ", shellCmd)
126 myMonitorView=TopIIVolMeshMonitor(self, shellCmd)
128 def OnqcbDistributedClicked(self):
129 state = self.qcbDistributed.isChecked()
130 self.qlbXParts.setVisible(state)
131 self.qlbYParts.setVisible(state)
132 self.qlbZParts.setVisible(state)
133 self.qsbXParts.setVisible(state)
134 self.qsbYParts.setVisible(state)
135 self.qsbZParts.setVisible(state)
137 def OnQpbCloseClicked(self):
140 def saveOutputMesh(self):
141 if not self.qcbDisplayMesh.isChecked():
144 import SMESH, SALOMEDS
145 from salome.smesh import smeshBuilder
146 smesh = smeshBuilder.New()
147 self.outputMesh.split('/')
148 for mesh in pathlib.Path(self.SALOME_TMP_DIR).glob('*.mesh'):
149 (outputMesh, status) = smesh.CreateMeshesFromGMF(os.path.join(self.SALOME_TMP_DIR, mesh))
150 if salome.sg.hasDesktop():
151 salome.sg.updateObjBrowser()
158 This function returns a singleton instance of the plugin dialog.
159 It is mandatory in order to call show without a parent ...
162 if __instance is None:
163 __instance = TopIIVolMeshPluginDialog()