1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2006-2015 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.
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
28 from blocFissure.gmu import initLog
32 from blocFissure.gmu import geomsmesh
33 from blocFissure.casStandard import casStandard
35 from blocFissure.ihm.fissureCoude_ihm import fissureCoude_ihm
37 def fissureCoudeDlg(context):
38 # get context study, studyId, salomeGui
40 studyId = context.studyId
46 from PyQt4 import QtCore
47 from PyQt4 import QtGui
48 from PyQt4.QtGui import QFileDialog
49 from PyQt4.QtGui import QMessageBox
50 from PyQt4.QtGui import QPalette
51 from PyQt4.QtGui import QColor
52 from fissureCoude_ui import Ui_Dialog
54 class fissureCoudeDialog(QtGui.QDialog):
57 QtGui.QDialog.__init__(self)
58 # Set up the user interface from Designer.
62 self.blackPalette = self.ui.dsb_angle.palette()
63 self.redPalette = QPalette()
64 self.redPalette.setColor(QPalette.Text, QColor(255,0,0))
68 self.initDialog(self.defaut)
69 self.ui.dsb_angle.setSpecialValueText("saisie_obligatoire")
70 self.ui.dsb_rCintr.setSpecialValueText("saisie_obligatoire")
71 self.ui.dsb_lTubeP1.setSpecialValueText("saisie_obligatoire")
72 self.ui.dsb_lTubeP2.setSpecialValueText("saisie_obligatoire")
73 self.ui.dsb_epais.setSpecialValueText("saisie_obligatoire")
74 self.ui.dsb_dext.setSpecialValueText("saisie_obligatoire")
75 self.ui.dsb_profondeur.setSpecialValueText("saisie_obligatoire")
76 self.ui.dsb_longueur.setSpecialValueText("saisie_obligatoire")
77 self.ui.dsb_azimut.setSpecialValueText("saisie_obligatoire")
78 self.ui.dsb_orientation.setSpecialValueText("saisie_obligatoire")
79 self.ui.dsb_posiAngul.setSpecialValueText("saisie_obligatoire")
80 self.ui.dsb_absCurv.setSpecialValueText("saisie_obligatoire")
81 self.ui.sb_nbTranches.setSpecialValueText("saisie_obligatoire")
82 self.ui.sb_nbCouronne.setSpecialValueText("saisie_obligatoire")
83 self.ui.sb_nbSecteur.setSpecialValueText("saisie_obligatoire")
84 self.ui.dsb_aretesFaceFissure.setSpecialValueText("automatique")
85 self.ui.dsb_influence.setSpecialValueText("automatique")
86 self.ui.lb_calcul.hide()
88 # Connect up the buttons.
89 self.connect(self.ui.pb_valPrec, QtCore.SIGNAL("clicked()"),
91 self.connect(self.ui.pb_reset, QtCore.SIGNAL("clicked()"),
93 self.connect(self.ui.pb_recharger, QtCore.SIGNAL("clicked()"),
95 self.connect(self.ui.pb_sauver, QtCore.SIGNAL("clicked()"),
97 self.disconnect(self.ui.buttonBox, QtCore.SIGNAL("accepted()"), self.accept)
98 self.connect(self.ui.buttonBox, QtCore.SIGNAL("accepted()"),
101 def initDefaut(self):
118 cbOptDiscrSain = False,
119 cbOptDiscrFiss = False,
122 cbForceEllipse = False,
129 aretesFaceFissure = 0.0,
133 def initDialog(self, dico):
134 self.ui.dsb_angle.setValue(dico['angle'])
135 self.ui.dsb_rCintr.setValue(dico['rCintr'])
136 self.ui.dsb_lTubeP1.setValue(dico['lTubeP1'])
137 self.ui.dsb_lTubeP2.setValue(dico['lTubeP2'])
138 self.ui.dsb_epais.setValue(dico['epais'])
139 self.ui.dsb_dext.setValue(dico['dext'])
140 self.ui.dsb_profondeur.setValue(dico['profondeur'])
141 self.ui.dsb_longueur.setValue(dico['longueur'])
142 self.ui.dsb_azimut.setValue(dico['azimut'])
143 self.ui.dsb_orientation.setValue(dico['orientation'])
144 self.ui.dsb_posiAngul.setValue(dico['posiAngul'])
145 self.ui.dsb_absCurv.setValue(dico['absCurv'])
146 self.ui.sb_nbTranches.setValue(dico['nbTranches'])
147 self.ui.sb_nbCouronne.setValue(dico['nbCouronnes'])
148 self.ui.sb_nbSecteur.setValue(dico['nbSecteurs'])
149 self.ui.dsb_aretesFaceFissure.setValue(dico['aretesFaceFissure'])
150 self.ui.dsb_influence.setValue(dico['influence'])
151 self.ui.sb_nbAxeTubeP1.setValue(dico['nbAxeTubeP1'])
152 self.ui.sb_nbAxeTubeP2.setValue(dico['nbAxeTubeP2'])
153 self.ui.sb_nbAxeCoude.setValue(dico['nbAxeCoude'])
154 self.ui.sb_nbCirconf.setValue(dico['nbCirconf'])
155 self.ui.sb_nbEpaisseur.setValue(dico['nbEpaisseur'])
156 self.ui.dsb_rayonTore.setValue(dico['rayonTore'])
157 #self.ui.cb_optDiscrSain.setChecked(False)
158 #self.ui.gb_discrSain.setShown(False)
159 self.ui.cb_optDiscrSain.setChecked(not(dico['cbOptDiscrSain']))
160 self.ui.cb_optDiscrSain.click()
161 self.ui.cb_optDiscrFiss.setChecked(not(dico['cbOptDiscrFiss']))
162 self.ui.cb_optDiscrFiss.click()
163 if dico['rbPosiAngul']:
164 self.ui.dsb_absCurv.setEnabled(False)
165 self.ui.dsb_posiAngul.setEnabled(True)
166 self.ui.rb_posiAngul.setChecked(True)
167 #self.ui.rb_posiAngul.click()
169 self.ui.dsb_absCurv.setEnabled(True)
170 self.ui.dsb_posiAngul.setEnabled(False)
171 self.ui.rb_absCurv.setChecked(True)
172 #self.ui.rb_absCurv.click()
173 self.ui.rb_fissExt.setChecked(dico['rbFissExt'])
174 self.ui.cb_forceEllipse.setChecked(dico['cbForceEllipse'])
175 incomplet = self.testval(dico)
178 def testval(self, dico):
180 if dico['angle'] < -180.0:
181 self.ui.dsb_angle.setPalette(self.redPalette)
184 self.ui.dsb_angle.setPalette(self.blackPalette)
186 if dico['rCintr'] == 0.0:
187 self.ui.dsb_rCintr.setPalette(self.redPalette)
190 self.ui.dsb_rCintr.setPalette(self.blackPalette)
192 if dico['lTubeP1'] == 0.0:
193 self.ui.dsb_lTubeP1.setPalette(self.redPalette)
196 self.ui.dsb_lTubeP1.setPalette(self.blackPalette)
198 if dico['lTubeP2'] == 0.0:
199 self.ui.dsb_lTubeP2.setPalette(self.redPalette)
202 self.ui.dsb_lTubeP2.setPalette(self.blackPalette)
204 if dico['epais'] == 0.0:
205 self.ui.dsb_epais.setPalette(self.redPalette)
208 self.ui.dsb_epais.setPalette(self.blackPalette)
210 if dico['dext'] == 0.0:
211 self.ui.dsb_dext.setPalette(self.redPalette)
214 self.ui.dsb_dext.setPalette(self.blackPalette)
216 if dico['profondeur'] == 0.0:
217 self.ui.dsb_profondeur.setPalette(self.redPalette)
220 self.ui.dsb_profondeur.setPalette(self.blackPalette)
222 if dico['longueur'] == 0.0:
223 self.ui.dsb_longueur.setPalette(self.redPalette)
226 self.ui.dsb_longueur.setPalette(self.blackPalette)
228 if dico['azimut'] < -180.0:
229 self.ui.dsb_azimut.setPalette(self.redPalette)
232 self.ui.dsb_azimut.setPalette(self.blackPalette)
234 if dico['orientation'] < 0.0:
235 self.ui.dsb_orientation.setPalette(self.redPalette)
238 self.ui.dsb_orientation.setPalette(self.blackPalette)
240 if dico['posiAngul'] < -180.0 and dico['rbPosiAngul'] == True:
241 self.ui.dsb_posiAngul.setPalette(self.redPalette)
244 self.ui.dsb_posiAngul.setPalette(self.blackPalette)
246 if dico['absCurv'] == 0.0 and dico['rbPosiAngul'] == False:
247 self.ui.dsb_absCurv.setPalette(self.redPalette)
250 self.ui.dsb_absCurv.setPalette(self.blackPalette)
252 if dico['nbTranches'] == 7:
253 self.ui.sb_nbTranches.setPalette(self.redPalette)
256 self.ui.sb_nbTranches.setPalette(self.blackPalette)
258 if dico['nbCouronnes'] == 1:
259 self.ui.sb_nbCouronne.setPalette(self.redPalette)
262 self.ui.sb_nbCouronne.setPalette(self.blackPalette)
264 if dico['nbSecteurs'] == 3:
265 self.ui.sb_nbSecteur.setPalette(self.redPalette)
268 self.ui.sb_nbSecteur.setPalette(self.blackPalette)
270 print "incomplet: ", incomplet
273 def fileDefault(self):
274 filedef = os.path.expanduser("~/.config/salome/dialogFissureCoude.dic")
278 def writeDefault(self, dico):
279 filedef = self.fileDefault()
280 f = open(filedef, 'w')
284 def readValPrec(self):
285 filedef = self.fileDefault()
286 if os.path.exists(filedef):
287 f = open(filedef, 'r')
291 self.initDialog(dico)
295 self.initDialog(self.defaut)
299 fileDiag = QFileDialog(self)
300 fileDiag.setFileMode(QFileDialog.AnyFile)
301 fileDiag.setNameFilter("Parametres *.dic (*.dic)")
302 fileDiag.setViewMode(QFileDialog.List)
303 if fileDiag.exec_() :
304 fileNames = fileDiag.selectedFiles()
305 filedef = fileNames[0]
306 dico = self.creeDico()
307 f = open(filedef, 'w')
313 fileDiag = QFileDialog(self)
314 fileDiag.setFileMode(QFileDialog.ExistingFile)
315 fileDiag.setNameFilter("Parametres *.dic (*.dic)")
316 fileDiag.setViewMode(QFileDialog.Detail)
317 if fileDiag.exec_() :
318 fileNames = fileDiag.selectedFiles()
319 filedef = fileNames[0]
321 if os.path.exists(filedef):
322 f = open(filedef, 'r')
326 self.initDialog(dico)
330 angle = self.ui.dsb_angle.value(),
331 rCintr = self.ui.dsb_rCintr.value(),
332 lTubeP1 = self.ui.dsb_lTubeP1.value(),
333 lTubeP2 = self.ui.dsb_lTubeP2.value(),
334 epais = self.ui.dsb_epais.value(),
335 dext = self.ui.dsb_dext.value(),
336 profondeur = self.ui.dsb_profondeur.value(),
337 longueur = self.ui.dsb_longueur.value(),
338 azimut = self.ui.dsb_azimut.value(),
339 orientation = self.ui.dsb_orientation.value(),
340 posiAngul = self.ui.dsb_posiAngul.value(),
341 absCurv = self.ui.dsb_absCurv.value(),
342 nbTranches = self.ui.sb_nbTranches.value(),
343 nbCouronnes = self.ui.sb_nbCouronne.value(),
344 nbSecteurs = self.ui.sb_nbSecteur.value(),
345 cbOptDiscrSain = self.ui.cb_optDiscrSain.isChecked(),
346 cbOptDiscrFiss = self.ui.cb_optDiscrFiss.isChecked(),
347 rbPosiAngul = self.ui.rb_posiAngul.isChecked(),
348 rbFissExt = self.ui.rb_fissExt.isChecked(),
349 cbForceEllipse = self.ui.cb_forceEllipse.isChecked(),
350 nbAxeTubeP1 = self.ui.sb_nbAxeTubeP1.value(),
351 nbAxeTubeP2 = self.ui.sb_nbAxeTubeP2.value(),
352 nbAxeCoude = self.ui.sb_nbAxeCoude.value(),
353 nbCirconf = self.ui.sb_nbCirconf.value(),
354 nbEpaisseur = self.ui.sb_nbEpaisseur.value(),
355 rayonTore = self.ui.dsb_rayonTore.value(),
356 aretesFaceFissure = self.ui.dsb_aretesFaceFissure.value(),
357 influence = self.ui.dsb_influence.value(),
362 def checkValues(self):
366 dico = self.creeDico()
367 NOK = self.testval(dico)
369 dico['lenSegPipe'] = (dico['longueur'] + math.pi*dico['profondeur'])/dico['nbTranches']
370 print 'lenSegPipe', dico['lenSegPipe']
371 areteMinAngle = (dico['rCintr'] -dico['dext']/2.0)*(dico['angle']*math.pi/180.0)/dico['nbAxeCoude']
372 print'areteMinAngle', areteMinAngle
373 areteMinCirco = dico['dext']*math.pi/(2*dico['nbCirconf'])
374 print'areteMinCirco', areteMinCirco
375 areteMinEpais = dico['epais']/dico['nbEpaisseur']
376 print'areteMinEpais', areteMinEpais
377 if dico['influence'] == 0:
378 dico['influence'] = max(areteMinAngle, areteMinCirco, areteMinEpais)
379 print 'influence', dico['influence']
380 if dico['aretesFaceFissure'] == 0:
381 dico['aretesFaceFissure'] = (areteMinAngle + areteMinCirco)/2.0
382 print 'aretesFaceFissure', dico['aretesFaceFissure']
383 if dico['rbPosiAngul'] == False:
384 rmoy = (dico['dext'] - dico['epais'])/2.0
386 if dico['rbFissExt'] == False:
388 dico['posiAngul'] = (180.0/math.pi)*dico['absCurv']/(dico['rCintr']+(rmoy+eta*dico['epais']/2.0)*math.cos(math.pi*dico['azimut']/180.))
389 print 'posiAngul' , dico['posiAngul']
391 self.writeDefault(dico)
392 self.ui.lb_calcul.show()
393 probleme = fissureCoude_ihm(0)
394 probleme.setDicoParams(dico)
395 probleme.executeProbleme()
401 # ----------------------------------------------------------------------------
403 window = fissureCoudeDialog()
404 # window.ui.dsb_tolerance.setValue(0.01)
409 result = window.result()
412 print "dialog accepted, check"
413 retry = window.checkValues()
415 print "dialog rejected, exit"