1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2012 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 class ensembleRegles :
32 def __init__(self, liste_regles):
34 for item in liste_regles :
35 args, clefRegle = item
36 r = regle(clefRegle, args)
39 def verif(self, commande) :
44 for regle in self.liste :
45 result = regle.verif(commande)
49 #--------------------------------
50 class pasDeRegle(ensembleRegles):
51 #--------------------------------
58 def verif (self, commande) :
71 def __init__(self, clef_regle, args):
72 self.fonction = dictionnaire_regle[clef_regle]
76 def verif(self, commande):
80 f = self.fonction(self.list_args)
81 return f.verif(commande)
83 #---------------------
84 class existeMCFParmi :
85 #---------------------
87 Existance du mot-clé facteur parmi la liste
89 def __init__(self, list_arg):
90 self.listeMCF = list_arg
92 def verif(self, commande) :
97 for c in commande.childNodes :
98 if c.name in self.listeMCF :
103 #---------------------
104 class nexistepasMCFParmi(existeMCFParmi) :
105 #---------------------
107 Existance du mot-clé facteur parmi la liste
109 def __init__(self, list_arg):
110 self.listeMCF = list_arg
112 def verif(self, commande) :
116 bool = existeMCFParmi.verif(self, commande)
120 #----------------------
121 class existeMCsousMCF :
122 #----------------------
124 Existance du mot-clé simple sous le mot-clé facteur
126 def __init__(self, list_arg):
127 self.liste = list_arg
128 self.MCF = self.liste[0]
129 self.MC = self.liste[1]
131 def verif(self, commande):
136 for mcf in commande.childNodes :
137 if mcf.name != self.MCF : continue
138 l = mcf.childNodes[:]
141 for mc in ll.childNodes:
142 if mc.name != self.MC : continue
146 #----------------------
147 class existeMCsousMCFcourant :
148 #----------------------
150 Existance du mot-clé simple sous le mot-clé facteur courant
152 def __init__(self, list_arg):
153 self.liste = list_arg
154 self.MC = self.liste[0]
156 def verif(self, mcf):
161 l = mcf.childNodes[:]
164 if mc.name != self.MC : continue
168 #-----------------------------------------
169 class nexistepasMCsousMCF(existeMCsousMCF):
170 #-----------------------------------------
172 Absence du mot-clé simple sous le mot-clé facteur
174 def __init__(self, list_arg):
175 existeMCsousMCF.__init__(self, list_arg)
178 def verif(self, commande):
182 bool = existeMCsousMCF.verif(self, commande)
186 #-----------------------------------------
187 class nexistepasMCsousMCFcourant(existeMCsousMCFcourant):
188 #-----------------------------------------
190 Absence du mot-clé simple sous le mot-clé facteur courant
192 def __init__(self, list_arg):
193 existeMCsousMCFcourant.__init__(self, list_arg)
196 def verif(self, commande):
200 bool = existeMCsousMCFcourant.verif(self, commande)
208 Existance du mot-clé simple
210 def __init__(self, list_arg):
211 self.genea = list_arg
213 def cherche_mot(self, niveau, commande):
217 if commande == None : return 0
218 if niveau == len(self.genea) : return 1
219 texte = self.genea[niveau]
220 for c in commande.childNodes :
223 return self.cherche_mot(niveau, c)
226 def verif(self, commande):
230 bool = self.cherche_mot(0, commande)
231 if bool == None : bool = 0
238 Absence du mot-clé simple
240 def __init__(self, list_arg):
241 self.genea = list_arg
243 def cherche_mot(self, niveau, commande):
247 if commande == None : return 0
248 if niveau == len(self.genea) : return 1
249 texte = self.genea[niveau]
250 for c in commande.childNodes :
253 return self.cherche_mot(niveau, c)
256 def verif(self, commande):
260 bool = self.cherche_mot(0, commande)
264 #-------------------------------
265 class MCsousMCFaPourValeur :
266 #------------------------------
268 Égalité du mot-clé simple à une valeur sous le mot-clé facteur
270 def __init__(self, list_arg):
271 assert (len(list_arg)==4)
272 self.genea = list_arg[0:-2]
273 self.MCF = list_arg[0]
274 self.MC = list_arg[1]
275 self.Val = list_arg[2]
276 self.Jdc = list_arg[3]
278 def verif(self, commande):
283 for mcf in commande.childNodes :
284 if mcf.name != self.MCF : continue
285 l = mcf.childNodes[:]
288 for mc in ll.childNodes:
289 if mc.name != self.MC : continue
290 TexteMC = mc.getText(self.Jdc)
291 if (TexteMC.find(self.Val) < 0 ): continue
295 #-------------------------------
296 class MCsousMCFcourantaPourValeur :
297 #------------------------------
299 Égalité du mot-clé simple à une valeur sous le mot-clé facteur courant
301 def __init__(self, list_arg):
302 assert (len(list_arg)==3)
303 self.genea = list_arg[0:-1]
304 self.MC = list_arg[0]
305 self.Val = list_arg[1]
306 self.Jdc = list_arg[2]
308 def verif(self, mcf):
313 l = mcf.childNodes[:]
316 if mc.name != self.MC : continue
317 TexteMC = mc.getText(self.Jdc)
318 if (TexteMC.find(self.Val) < 0 ): continue
323 #-----------------------------
324 class MCsousMCFaPourValeurDansListe :
325 #----------------------------
327 Égalité du mot-clé simple à une valeur dans une liste
328 sous le mot-clé facteur
330 def __init__(self, list_arg):
331 assert (len(list_arg)==4)
332 self.genea = list_arg[0:-2]
333 self.MCF = list_arg[0]
334 self.MC = list_arg[1]
335 self.LVal = list_arg[2]
336 self.Jdc = list_arg[3]
338 def verif(self, commande):
343 for mcf in commande.childNodes :
344 if mcf.name != self.MCF : continue
345 l = mcf.childNodes[:]
348 for mc in ll.childNodes:
349 if mc.name != self.MC : continue
350 TexteMC = mc.getText(self.Jdc)
351 for Val in self.LVal:
352 if (TexteMC.find(Val) < 0 ): continue
356 #-----------------------------
357 class MCsousMCFcourantaPourValeurDansListe :
358 #----------------------------
360 Égalité du mot-clé simple à une valeur dans une liste
361 sous le mot-clé facteur
363 def __init__(self, list_arg):
364 assert (len(list_arg)==3)
365 self.genea = list_arg[0:-1]
366 self.MC = list_arg[0]
367 self.LVal = list_arg[1]
368 self.Jdc = list_arg[2]
370 def verif(self, mcf):
375 l = mcf.childNodes[:]
378 if mc.name != self.MC : continue
379 TexteMC = mc.getText(self.Jdc)
380 for Val in self.LVal:
381 if (TexteMC.find(Val) < 0 ): continue
385 #-----------------------------------------
386 class MCsousMCFcourantnaPasPourValeurDansListe(MCsousMCFcourantaPourValeurDansListe) :
387 #-----------------------------------------
389 Non égalité du mot-clé simple à une valeur dans une liste
390 sous le mot-clé facteur
392 def __init__(self, list_arg):
393 MCsousMCFcourantaPourValeurDansListe.__init__(self, list_arg)
396 def verif(self, commande):
397 bool = MCsousMCFcourantaPourValeurDansListe.verif(self, commande)
401 #------------------------------
402 class MCaPourValeur :
403 #------------------------------
405 Égalité du mot-clé à une valeur
407 def __init__(self, list_arg):
408 assert (len(list_arg)==3)
409 self.MC = list_arg[0]
410 self.Val = list_arg[1]
411 self.Jdc = list_arg[2]
413 def verif(self, commande):
418 for mc in commande.childNodes :
419 if mc.name != self.MC : continue
420 TexteMC = mc.getText(self.Jdc)
421 if (TexteMC.find(self.Val) < 0 ): continue
425 #-----------------------------------------
426 class MCnaPasPourValeur(MCaPourValeur) :
427 #-----------------------------------------
429 Non égalité du mot-clé à une valeur
431 def __init__(self, list_arg):
432 MCaPourValeur.__init__(self, list_arg)
434 def verif(self, commande):
438 bool = MCaPourValeur.verif(self, commande)
442 #------------------------------
443 class MCaPourValeurDansListe :
444 #------------------------------
446 Égalité du mot-clé à une valeur dans une liste
448 def __init__(self, list_arg):
449 assert (len(list_arg)==3)
450 self.MC = list_arg[0]
451 self.LVal = list_arg[1]
452 self.Jdc = list_arg[2]
454 def verif(self, commande):
459 for mc in commande.childNodes :
460 if mc.name != self.MC : continue
461 TexteMC = mc.getText(self.Jdc)
462 #print "TexteMC=",type(TexteMC),TexteMC
463 #print "LVal=",type(self.LVal),self.LVal
464 for Val in self.LVal:
465 #print "Val=",type(Val),Val
466 #print "Find",TexteMC.find(Val)
467 if (TexteMC.find(Val) < 0 ): continue
471 #-----------------------------------------
472 class MCnaPasPourValeurDansListe(MCaPourValeurDansListe) :
473 #-----------------------------------------
475 Non égalité du mot-clé à une valeur dans une liste
477 def __init__(self, list_arg):
478 MCaPourValeurDansListe.__init__(self, list_arg)
480 def verif(self, commande):
484 bool = MCaPourValeurDansListe.verif(self, commande)
488 dictionnaire_regle = {"existe":existe,
489 "nexistepas":nexistepas,
490 "existeMCFParmi":existeMCFParmi,
491 "nexistepasMCFParmi":nexistepasMCFParmi,
492 "existeMCsousMCF":existeMCsousMCF,
493 "nexistepasMCsousMCF":nexistepasMCsousMCF,
494 "MCsousMCFaPourValeur":MCsousMCFaPourValeur,
495 "MCsousMCFaPourValeurDansListe":MCsousMCFaPourValeurDansListe,
496 "MCaPourValeur":MCaPourValeur,
497 "MCnaPasPourValeur":MCnaPasPourValeur,
498 "existeMCsousMCFcourant":existeMCsousMCFcourant,
499 "nexistepasMCsousMCFcourant":nexistepasMCsousMCFcourant,
500 "MCsousMCFcourantaPourValeur":MCsousMCFcourantaPourValeur,
501 "MCsousMCFcourantaPourValeurDansListe":MCsousMCFcourantaPourValeurDansListe,
502 "MCsousMCFcourantnaPasPourValeurDansListe":MCsousMCFcourantnaPasPourValeurDansListe,
503 "MCaPourValeurDansListe":MCaPourValeurDansListe,
504 "MCnaPasPourValeurDansListe":MCnaPasPourValeurDansListe}
507 SansRegle = pasDeRegle()