1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2006-2020 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # if you already have plugins defined in a salome_plugins.py file, add this file at the end.
23 # if not, copy this file as ${HOME}/Plugins/smesh_plugins.py or ${APPLI}/Plugins/smesh_plugins.py
27 from blocFissure import gmu
29 def fissureGeneraleDlg(context):
30 # get context study, salomeGui
37 from PyQt5 import QtCore
38 from PyQt5 import QtWidgets
39 from PyQt5 import QtGui
40 from PyQt5.QtWidgets import QFileDialog
41 from PyQt5.QtWidgets import QMessageBox
42 from PyQt5.QtGui import QPalette
43 from PyQt5.QtGui import QColor
44 from blocFissure.ihm.fissureGenerale_ui import Ui_Dialog
46 class fissureGeneraleDialog(QtWidgets.QDialog):
50 QtWidgets.QDialog.__init__(self)
51 # Set up the user interface from Designer.
55 self.blackPalette = self.ui.dsb_influence.palette()
56 self.redPalette = QPalette()
57 self.redPalette.setColor(QPalette.Text, QColor(255,0,0))
61 self.initDialog(self.defaut)
62 self.ui.lb_calcul.hide()
64 # Connect up the buttons.
66 self.ui.pb_exemple.clicked.connect(self.genereExemples)
67 self.ui.pb_valPrec.clicked.connect(self.readValPrec)
68 self.ui.pb_reset.clicked.connect(self.resetVal)
69 self.ui.pb_recharger.clicked.connect(self.recharger)
70 self.ui.pb_sauver.clicked.connect(self.sauver)
71 self.ui.pb_maillage.clicked.connect(self.selectMaillage)
72 self.ui.pb_facefiss.clicked.connect(self.selectFacefiss)
73 self.ui.pb_reptrav.clicked.connect(self.selectReptrav)
74 self.ui.bb_OkCancel.accepted.disconnect(self.accept)
75 self.ui.bb_OkCancel.accepted.connect(self.execute)
79 nomCas = "angleCube", \
80 maillageSain = os.path.join(gmu.pathBloc, "materielCasTests", "CubeAngle.med"), \
81 brepFaceFissure = os.path.join(gmu.pathBloc, "materielCasTests", "CubeAngleFiss.brep"), \
89 areteFaceFissure = 10, \
91 reptrav = os.curdir, \
92 nomres = "maillage_avec_fissure", \
96 def initDialog(self, dico):
97 self.ui.le_maillage.setText(dico['maillageSain'])
98 self.ui.le_facefiss.setText(dico['brepFaceFissure'])
99 self.ui.le_fondfiss.setText(str(dico['edgeFissIds']))
100 self.ui.dsb_influence.setValue(dico['lgInfluence'])
101 self.ui.dsb_meshBrepMin.setValue(dico['meshBrep'][0])
102 self.ui.dsb_meshBrepMax.setValue(dico['meshBrep'][1])
103 self.ui.dsb_rayonPipe.setValue(dico['rayonPipe'])
104 self.ui.dsb_lenSegPipe.setValue(dico['lenSegPipe'])
105 self.ui.sb_couronnes.setValue(dico['nbSegRad'])
106 self.ui.sb_secteurs.setValue(dico['nbSegCercle'])
107 self.ui.dsb_areteFaceFissure.setValue(dico['areteFaceFissure'])
108 if 'aretesVives' in dico:
109 self.ui.dsb_aretesVives.setValue(dico['aretesVives'])
111 self.ui.dsb_aretesVives.setValue(0)
112 self.ui.le_reptrav.setText(os.path.abspath(dico['reptrav']))
113 self.ui.le_nomres.setText(os.path.split(dico['nomres'])[1])
114 self.ui.cb_log.setCurrentIndex(dico['verbosite'])
115 incomplet = self.testval(dico)
118 def testval(self, dico):
120 if not os.path.lexists(dico['maillageSain']):
121 self.ui.le_maillage.setPalette(self.redPalette)
124 self.ui.le_maillage.setPalette(self.blackPalette)
125 cao_file = dico['brepFaceFissure']
126 if not os.path.lexists(cao_file):
127 self.ui.le_facefiss.setPalette(self.redPalette)
130 suffix = os.path.basename(cao_file).split(".")[-1]
131 if ( suffix.upper() not in ("BREP","XAO") ):
132 print ("Suffixe inconnu pour le fichier {}".format(cao_file))
133 self.ui.le_facefiss.setPalette(self.redPalette)
136 self.ui.le_facefiss.setPalette(self.blackPalette)
137 if dico['edgeFissIds']:
139 param_0 = dico['edgeFissIds'][0]
140 type_param_id = type(param_0)
141 for param in dico['edgeFissIds'][1:]:
142 if not isinstance(param,type_param_id):
143 print ("La donnée {} n'est pas du même type que la première de la liste : {}.".format(param,type(param)))
147 if isinstance(param_0, int):
149 elif isinstance(param_0, str):
152 print("Il faut une liste d'IDs d'arêtes ou une liste de noms de groupes d'arêtes.")
159 self.ui.le_fondfiss.setPalette(self.blackPalette)
161 self.ui.le_fondfiss.setPalette(self.redPalette)
162 if dico['meshBrep'][0] == 0:
163 self.ui.dsb_meshBrepMin.setPalette(self.redPalette)
166 self.ui.dsb_meshBrepMin.setPalette(self.blackPalette)
167 if dico['meshBrep'][1] == 0:
168 self.ui.dsb_meshBrepMax.setPalette(self.redPalette)
171 self.ui.dsb_meshBrepMax.setPalette(self.blackPalette)
172 if dico['rayonPipe'] == 0:
173 self.ui.dsb_rayonPipe.setPalette(self.redPalette)
176 self.ui.dsb_rayonPipe.setPalette(self.blackPalette)
177 if dico['lenSegPipe'] == 0:
178 self.ui.dsb_lenSegPipe.setPalette(self.redPalette)
181 self.ui.dsb_lenSegPipe.setPalette(self.blackPalette)
182 if dico['areteFaceFissure'] == 0:
183 self.ui.dsb_areteFaceFissure.setPalette(self.redPalette)
186 self.ui.dsb_areteFaceFissure.setPalette(self.blackPalette)
188 print("incomplet: ", incomplet)
191 def fileDefault(self):
192 filedef = os.path.expanduser( os.path.join(os.environ["HOME"],".config", "salome", "dialogFissureGenerale.dic") )
196 def writeDefault(self, dico):
197 filedef = self.fileDefault()
198 with open(filedef, 'w') as f:
201 def genereExemples(self):
202 maillageSain = os.path.join(gmu.pathBloc, "materielCasTests", "CubeAngle.med")
203 brepFaceFissure = os.path.join(gmu.pathBloc, "materielCasTests", "CubeAngleFiss.brep")
204 if (os.path.exists(maillageSain) and os.path.exists(brepFaceFissure)):
205 self.initDialog(self.defaut)
207 self.ui.lb_calcul.setText("--- Generation exemples en cours ---")
208 self.ui.lb_calcul.show()
209 from blocFissure.materielCasTests import genereMateriel
210 self.ui.lb_calcul.hide()
211 self.initDialog(self.defaut)
213 def readValPrec(self):
214 filedef = self.fileDefault()
215 if os.path.exists(filedef):
216 with open(filedef, 'r') as f:
220 self.initDialog(dico)
224 self.initDialog(self.defaut)
226 def setLogVerbosity(self, logfile):
227 from blocFissure.gmu import initLog # le mode de log s'initialise une seule fois
228 print("setLogVerbosity")
229 index = self.ui.cb_log.currentIndex()
232 initLog.setRelease(logfile)
234 initLog.setVerbose(logfile)
236 initLog.setDebug(logfile)
241 fileDiag = QFileDialog(self)
242 fileDiag.setFileMode(QFileDialog.AnyFile)
243 fileDiag.setNameFilter("Parametres *.dic (*.dic)")
244 fileDiag.setViewMode(QFileDialog.List)
245 if fileDiag.exec_() :
246 fileNames = fileDiag.selectedFiles()
248 filedef = fileNames[0]
249 if filedef[-4:] not in ['.dic']:
251 dico = self.creeDico()
252 with open(filedef, 'w') as f:
257 fileDiag = QFileDialog(self)
258 fileDiag.setFileMode(QFileDialog.ExistingFile)
259 fileDiag.setNameFilter("Parametres *.dic (*.dic)")
260 fileDiag.setViewMode(QFileDialog.Detail)
261 if fileDiag.exec_() :
262 fileNames = fileDiag.selectedFiles()
263 filedef = fileNames[0]
265 if os.path.exists(filedef):
266 with open(filedef, 'r') as f:
270 self.initDialog(dico)
272 def selectMaillage(self):
273 fileDiag = QFileDialog(self)
274 fileDiag.setFileMode(QFileDialog.ExistingFile)
275 fileDiag.setNameFilter("Maillage *.med (*.med)")
276 fileDiag.setViewMode(QFileDialog.Detail)
277 if fileDiag.exec_() :
278 fileNames = fileDiag.selectedFiles()
279 filedef = fileNames[0]
281 self.ui.le_maillage.setText(filedef)
283 def selectFacefiss(self):
284 fileDiag = QFileDialog(self)
285 fileDiag.setFileMode(QFileDialog.ExistingFile)
286 fileDiag.setNameFilter("Face fissure *.brep (*.brep)")
287 fileDiag.setViewMode(QFileDialog.Detail)
288 if fileDiag.exec_() :
289 fileNames = fileDiag.selectedFiles()
290 filedef = fileNames[0]
292 self.ui.le_facefiss.setText(filedef)
294 def selectReptrav(self):
295 fileDiag = QFileDialog(self)
296 fileDiag.setFileMode(QFileDialog.Directory)
297 fileDiag.setViewMode(QFileDialog.Detail)
298 fileDiag.setDirectory(self.ui.le_reptrav.text())
299 if fileDiag.exec_() :
300 fileNames = fileDiag.selectedFiles()
301 reptrav = str(fileNames[0])
302 print("reptrav ", reptrav)
303 self.ui.le_reptrav.setText(os.path.abspath(reptrav))
306 def selectNomres(self):
307 fileDiag = QFileDialog(self)
308 fileDiag.setFileMode(QFileDialog.AnyFile)
309 fileDiag.setViewMode(QFileDialog.Detail)
310 nomres=str(os.path.split(str(self.ui.le_nomres.text()))[1])
311 fileDiag.setDirectory(self.ui.le_reptrav.text())
312 fileDiag.selectFile(nomres)
313 fileDiag.setNameFilter("Maillage *.med (*.med)")
314 self.ui.le_nomres.setText(nomres)
315 if fileDiag.exec_() :
316 fileNames = fileDiag.selectedFiles()
317 tempnom = os.path.split(str(fileNames[0]))[1]
318 print("nomres ", tempnom)
319 self.ui.le_nomres.setText(tempnom)
321 self.ui.le_nomres.setText(nomres)
325 maillageSain = str(self.ui.le_maillage.text()), \
326 brepFaceFissure = str(self.ui.le_facefiss.text()), \
327 edgeFissIds = eval(str(self.ui.le_fondfiss.text())), \
328 lgInfluence = self.ui.dsb_influence.value(), \
329 meshBrep = [self.ui.dsb_meshBrepMin.value(),self.ui.dsb_meshBrepMax.value()], \
330 rayonPipe = self.ui.dsb_rayonPipe.value(), \
331 lenSegPipe = self.ui.dsb_lenSegPipe.value(), \
332 nbSegRad = self.ui.sb_couronnes.value(), \
333 nbSegCercle = self.ui.sb_secteurs.value(), \
334 areteFaceFissure = self.ui.dsb_areteFaceFissure.value(), \
335 aretesVives = self.ui.dsb_aretesVives.value(), \
336 reptrav = str(self.ui.le_reptrav.text()), \
337 nomres = str(self.ui.le_nomres.text()), \
338 verbosite = self.ui.cb_log.currentIndex() \
343 def checkValues(self):
348 dico = self.creeDico()
349 NOK = self.testval(dico)
351 self.writeDefault(dico)
352 self.ui.lb_calcul.setText("--- Calcul en cours ---")
353 self.ui.lb_calcul.show()
354 logfile=os.path.join(dico['reptrav'], dico['nomres']+".log")
355 self.setLogVerbosity(logfile)
356 from blocFissure.gmu import geomsmesh # après intialisation log dans setLogVerbosity
357 from blocFissure.gmu.casStandard import casStandard # après intialisation log dans setLogVerbosity
358 from blocFissure.gmu.fissError import fissError
360 execInstance = casStandard(dico)
361 except fissError as erreur:
367 for ligne in erreur.pile:
371 # texte += +"<br>" +'-'*60 +"<br>"
372 # for ligne in erreur.pile:
373 # texte += repr(ligne) +"<br>"
374 mbox = QMessageBox(self)
375 mbox.setWindowTitle("erreur blocFissure")
376 mbox.setText(str(texte))
378 # except Exception as erreur:
379 # print "exception non répertoriée"
381 self.ui.lb_calcul.hide()
386 # ----------------------------------------------------------------------------
389 window = fissureGeneraleDialog()
394 result = window.result()
397 print("dialog accepted, check")
398 retry = window.checkValues()
400 print("dialog rejected, exit")