Salome HOME
Merge remote branch 'origin/V8_5_asterstudy'
[modules/smesh.git] / src / Tools / ZCracksPlug / __init__.py
1 import sys, os, shutil, pickle, tempfile
2 from Zcracks import main, genereCrack, Zset
3 from Zcracks import utilityFunctions as uF
4
5 os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=os.path.join(os.environ['QTDIR'],'plugins','platforms')
6
7 #commande="/bin/bash -c ""source $HOME/zebulon/Z8.6.6_NEW/do_config_bash"""
8 #os.system(commande)
9
10 def IHM():
11
12   from PyQt5.QtWidgets import QApplication
13
14   app = QApplication(sys.argv)
15   myapp = main.ShipHolderApplication()
16   myapp.show()
17   sys.exit(app.exec_())
18
19
20 def SCRIPT(dataFile=None, data=None, dim=3, names=None):
21   if dim!=3 and dim!=2:
22     print('ERROR')
23     return(False)
24
25   if dataFile==None and data==None:
26     print('One of dataFile or data is mandatory')
27     return(False)
28
29   if data==None: data=pickle.load(open(dataFile,'r'))
30
31   print(data)
32
33   tmpdir=tempfile.mkdtemp(prefix='tmpZcracks')
34
35   if names==None: names={'saneGeoName':'salome_sane', 'crackGeoName':'salome_crack', 'crackedGeoName':'salome_cracked'}
36
37   crackedMed=data['crackedName']
38   crackMed=os.path.join(tmpdir,'crackMed.med')
39   saneMed=data['saneName']
40
41   saneGeo=os.path.join(tmpdir,names['saneGeoName']+'.geo')
42   crackGeo=os.path.join(tmpdir,names['crackGeoName']+'.geo')
43   crackedGeo=os.path.join(tmpdir,names['crackedGeoName']+'.geo')
44
45   for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
46     if os.path.isfile(f): os.remove(f)
47
48   print(crackMed)
49   genereCrack.main(data, crackMed)
50   goOn=os.path.isfile(crackMed)
51
52   if goOn: Zset.medToGeo(crackMed, crackGeo, tmpdir)
53   goOn=os.path.isfile(crackGeo)
54
55   if dim==3:
56     if goOn: Zset.medToGeo(saneMed,saneGeo, tmpdir)
57   elif dim==2:
58     if goOn: Zset.medToGeo(saneMed,saneGeo, tmpdir, opt=['  **to_3d'])
59   goOn=os.path.isfile(saneGeo)
60
61   if goOn: Zset.insertCrack(data, names, tmpdir)
62   goOn=os.path.isfile(crackedGeo)
63
64   if goOn: Zset.geoToMed(crackedMed, crackedGeo, tmpdir)
65   goOn=os.path.isfile(crackedMed)
66
67   if goOn: maxAR=uF.extendElsets(crackedMed)
68
69   shutil.rmtree(tmpdir)
70
71   return([os.path.isfile(crackedMed), maxAR])
72
73
74