Salome HOME
Merge branch 'V8_3_BR' into ngr/python3_dev
[modules/smesh.git] / src / Tools / Verima / Stats / getStats.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 import logging
5
6 # -----------------------------------------------------------------------------
7 # --- satistiques maillage
8
9 def getGroupesRef(fichierMed):
10       fichier=fichierMed.replace('.med','_groupesRef.res')
11       try:
12          text=open(fichier).read()
13       except:
14          return []
15       liste=text.split(",")
16       return liste
17
18
19 def getStatsMaillage(maillage,fichierMed):
20   """
21   """
22   logging.info('start')
23
24   OK = False
25   fichier=fichierMed.replace('.med','.res')
26   if maillage is not None:
27     mesures = maillage.GetMeshInfo()
28     txt=""
29     import SMESH
30     for i in range(len(mesures)):
31       txt += str(SMESH.EntityType._item(i))+ " " +str(mesures[SMESH.EntityType._item(i)]) + "\n"
32
33     from .utiles import writeFile
34     writeFile(fichier,txt)
35
36
37 def getStatsGroupes(maillage,fichierMedResult):
38   """
39   """
40   logging.info('start')
41   fichierGroupe=fichierMedResult.replace('.med','_groupesRef.res')
42   lGroups=getGroupesRef(fichierGroupe)
43   if len(lGroups)==0: 
44     print("pas de Groupe de Reference ")
45     try :
46       os.remove(fichierGroupe)
47       return
48     except :
49       return
50   lGroupsSMESH=maillage.GetGroups()
51   for groupe in lGroupsSMESH :
52      groupeName= groupe.GetName()
53      if groupeName not in lGroups : continue
54      extension='_'+groupeName+'.res'
55      fichierStatGroupe=fichierGroupe.replace('_groupesRef.res',extension)
56      getStatsStatSurGroupes(maillage,groupe,fichierStatGroupe)
57
58
59 def getStatsStatSurGroupes(maillage,groupe,fichierStatGroupe):
60   mesures = maillage.GetMeshInfo(groupe)
61   txt=""
62   import SMESH
63   for i in range(len(mesures)):
64       txt += str(SMESH.EntityType._item(i))+ " " +str(mesures[SMESH.EntityType._item(i)]) + "\n"
65   from .utiles import writeFile
66   writeFile(fichierStatGroupe,txt)
67
68
69