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