Salome HOME
Add COPYING license file
[tools/eficas.git] / generator / generator_dicoImbrique.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """Ce module contient le plugin generateur de fichier au format  Code_Carmel3D pour EFICAS.
21 """
22
23 from __future__ import absolute_import
24 try :
25     from builtins import str
26 except : pass
27
28 import traceback
29 import types,re,os
30 from Extensions.i18n import tr
31 from .generator_python import PythonGenerator
32
33 def entryPoint():
34     """
35        Retourne les informations necessaires pour le chargeur de plugins
36        Ces informations sont retournees dans un dictionnaire
37     """
38     return {
39          # Le nom du plugin
40            'name' : 'dicoImbrique',
41          # La factory pour creer une instance du plugin
42            'factory' : DicoImbriqueGenerator,
43            }
44
45
46 class DicoImbriqueGenerator(PythonGenerator):
47     """
48        Ce generateur parcourt un objet de type JDC et produit
49        un texte au format eficas et
50        un texte au format dictionnaire
51
52     """
53     # Les extensions de fichier permis?
54     extensions=('.comm',)
55
56 #----------------------------------------------------------------------------------------
57     def gener(self,obj,format='brut',config=None, appliEficas=None):
58
59         self.initDico()
60
61         # Cette instruction genere le contenu du fichier de commandes (persistance)
62         self.text=PythonGenerator.gener(self,obj,format)
63         #print (self.text)
64         print (self.Dico)
65         return self.text
66
67
68
69 #----------------------------------------------------------------------------------------
70 # initialisations
71 #----------------------------------------------------------------------------------------
72
73     def initDico(self) :
74
75         self.Dico={}
76         self.DicoDejaLa={}
77         self.Entete = ''
78
79
80 #----------------------------------------------------------------------------------------
81 # ecriture
82 #----------------------------------------------------------------------------------------
83
84     def writeDefault(self,fn) :
85         fileDico = fn[:fn.rfind(".")] + '.py'
86         f = open( str(fileDico), 'w')
87
88         f.write( "Dico =" + str(self.Dico) )
89         #f.write( self.Entete + "Dico =" + str(self.Dico) )
90         f.close()
91
92 #----------------------------------------------------------------------------------------
93 #  analyse de chaque noeud de l'arbre
94 #----------------------------------------------------------------------------------------
95
96     def generMCSIMP(self,obj) :
97         """recuperation de l objet MCSIMP"""
98
99         s=PythonGenerator.generMCSIMP(self,obj)
100         if obj.isInformation() : return s
101         if not obj.isValid() :  return s
102
103         liste=obj.getGenealogiePrecise()
104
105         if obj.etape.nom=='MODIFICATION_CATALOGUE' : return s
106         nom = obj.etape.nom
107
108         if hasattr(obj.etape,'sdnom') and obj.etape.sdnom != None and obj.etape.sdnom != "" :
109             nom = nom+ obj.etape.sdnom
110
111         if not(nom in self.Dico) : dicoCourant={}
112         else : dicoCourant=self.Dico [nom]
113
114         nomFeuille=liste[-1]
115         if nomFeuille in dicoCourant or nomFeuille in self.DicoDejaLa:
116             if nomFeuille in self.DicoDejaLa:
117                 nomTravail= nomFeuille +'_'+str(self.DicoDejaLa[nomFeuille])
118                 self.DicoDejaLa[nomFeuille]=self.DicoDejaLa[nomFeuille]+1
119                 nomFeuille=nomTravail
120             else :
121                 self.DicoDejaLa[nomFeuille]=3
122                 nom1=nomFeuille +'_1'
123                 dicoCourant[nom1]= dicoCourant[nomFeuille]
124                 del dicoCourant[nomFeuille]
125                 nomFeuille=nomFeuille +'_2'
126
127
128         if hasattr(obj.valeur,'nom'): dicoCourant[nomFeuille]=obj.valeur.nom
129         else :
130             if type(obj.valeur)  in (list,tuple):
131                 try :
132 #PNPNPN a remplacer par plus propre
133                     if obj.definition.validators.typeDesTuples[0] !='R' :
134                         val=[]
135                         elt=[]
136                         for tupleElt in obj.valeur :
137                             elt=(str(tupleElt[0]),tupleElt[1])
138                             val.append(elt)
139                         dicoCourant[nomFeuille]=val
140                     else :
141                         dicoCourant[nomFeuille]=obj.valeur
142                 except :
143                     dicoCourant[nomFeuille]=obj.valeurFormatee
144             #else :dicoCourant[nomFeuille]=obj.valeurFormatee
145             else :
146                 dicoCourant[nomFeuille]=obj.valeurFormatee
147                 #print nomFeuille, obj.valeurFormatee
148         self.Dico[nom]=dicoCourant
149
150         return s