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