Salome HOME
Copyright update 2021
[modules/smesh.git] / src / Tools / ZCracksPlug / __init__.py
1 # Copyright (C) 2016-2021  EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import sys, os, shutil, pickle, tempfile
21 from Zcracks import main, genereCrack, Zset
22 from Zcracks import utilityFunctions as uF
23
24 os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=os.path.join(os.environ['QTDIR'],'plugins','platforms')
25
26 #commande="/bin/bash -c ""source $HOME/zebulon/Z8.6.6_NEW/do_config_bash"""
27 #os.system(commande)
28
29 def IHM():
30
31   from PyQt5.QtWidgets import QApplication
32
33   app = QApplication(sys.argv)
34   myapp = main.ShipHolderApplication()
35   myapp.show()
36   sys.exit(app.exec_())
37
38
39 def SCRIPT(dataFile=None, data=None, dim=3, names=None):
40   if dim!=3 and dim!=2:
41     print('ERROR')
42     return(False)
43
44   if dataFile==None and data==None:
45     print('One of dataFile or data is mandatory')
46     return(False)
47
48   if data==None: data=pickle.load(open(dataFile,'r'))
49
50   print(data)
51
52   tmpdir=tempfile.mkdtemp(prefix='tmpZcracks')
53
54   if names==None: names={'saneGeoName':'salome_sane', 'crackGeoName':'salome_crack', 'crackedGeoName':'salome_cracked'}
55
56   crackedMed=data['crackedName']
57   crackMed=os.path.join(tmpdir,'crackMed.med')
58   saneMed=data['saneName']
59
60   saneGeo=os.path.join(tmpdir,names['saneGeoName']+'.geo')
61   crackGeo=os.path.join(tmpdir,names['crackGeoName']+'.geo')
62   crackedGeo=os.path.join(tmpdir,names['crackedGeoName']+'.geo')
63
64   for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
65     if os.path.isfile(f): os.remove(f)
66
67   print(crackMed)
68   genereCrack.main(data, crackMed)
69   goOn=os.path.isfile(crackMed)
70
71   if goOn: Zset.medToGeo(crackMed, crackGeo, tmpdir)
72   goOn=os.path.isfile(crackGeo)
73
74   if dim==3:
75     if goOn: Zset.medToGeo(saneMed,saneGeo, tmpdir)
76   elif dim==2:
77     if goOn: Zset.medToGeo(saneMed,saneGeo, tmpdir, opt=['  **to_3d'])
78   goOn=os.path.isfile(saneGeo)
79
80   if goOn: Zset.insertCrack(data, names, tmpdir)
81   goOn=os.path.isfile(crackedGeo)
82
83   if goOn: Zset.geoToMed(crackedMed, crackedGeo, tmpdir)
84   goOn=os.path.isfile(crackedMed)
85
86   if goOn: maxAR=uF.extendElsets(crackedMed)
87
88   shutil.rmtree(tmpdir)
89
90   return([os.path.isfile(crackedMed), maxAR])
91
92
93