1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017 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 Existence 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 Existence 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 Existence 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 Existence 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 Existence du mot-clé simple
210 def __init__(self, list_arg):
211 self.genea = list_arg
213 def chercheMot(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.chercheMot(niveau, c)
226 def verif(self, commande):
230 bool = self.chercheMot(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 chercheMot(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.chercheMot(niveau, c)
256 def verif(self, commande):
260 bool = self.chercheMot(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 MCsousMCFnaPasPourValeurDansListe(MCsousMCFaPourValeurDansListe) :
403 #-----------------------------------------
405 Non égalité du mot-clé simple à une valeur dans une liste
406 sous le mot-clé facteur
408 def __init__(self, list_arg):
409 MCsousMCFaPourValeurDansListe.__init__(self, list_arg)
412 def verif(self, commande):
413 bool = MCsousMCFaPourValeurDansListe.verif(self, commande)
417 #------------------------------
418 class MCaPourValeur :
419 #------------------------------
421 Égalité du mot-clé à une valeur
423 def __init__(self, list_arg):
424 assert (len(list_arg)==3)
425 self.MC = list_arg[0]
426 self.Val = list_arg[1]
427 self.Jdc = list_arg[2]
429 def verif(self, commande):
434 for mc in commande.childNodes :
435 if mc.name != self.MC : continue
436 TexteMC = mc.getText(self.Jdc)
437 if (TexteMC.find(self.Val) < 0 ): continue
441 #-----------------------------------------
442 class MCnaPasPourValeur(MCaPourValeur) :
443 #-----------------------------------------
445 Non égalité du mot-clé à une valeur
447 def __init__(self, list_arg):
448 MCaPourValeur.__init__(self, list_arg)
450 def verif(self, commande):
454 bool = MCaPourValeur.verif(self, commande)
458 #------------------------------
459 class MCaPourValeurDansListe :
460 #------------------------------
462 Égalité du mot-clé à une valeur dans une liste
464 def __init__(self, list_arg):
465 assert (len(list_arg)==3)
466 self.MC = list_arg[0]
467 self.LVal = list_arg[1]
468 self.Jdc = list_arg[2]
470 def verif(self, commande):
475 for mc in commande.childNodes :
476 if mc.name != self.MC : continue
477 TexteMC = mc.getText(self.Jdc)
478 #print "TexteMC=",type(TexteMC),TexteMC
479 #print "LVal=",type(self.LVal),self.LVal
480 for Val in self.LVal:
481 #print "Val=",type(Val),Val
482 #print "Find",TexteMC.find(Val)
483 if (TexteMC.find(Val) < 0 ): continue
487 #-----------------------------------------
488 class MCnaPasPourValeurDansListe(MCaPourValeurDansListe) :
489 #-----------------------------------------
491 Non égalité du mot-clé à une valeur dans une liste
493 def __init__(self, list_arg):
494 MCaPourValeurDansListe.__init__(self, list_arg)
496 def verif(self, commande):
500 bool = MCaPourValeurDansListe.verif(self, commande)
504 dictionnaire_regle = {"existe":existe,
505 "nexistepas":nexistepas,
506 "existeMCFParmi":existeMCFParmi,
507 "nexistepasMCFParmi":nexistepasMCFParmi,
508 "existeMCsousMCF":existeMCsousMCF,
509 "nexistepasMCsousMCF":nexistepasMCsousMCF,
510 "MCsousMCFaPourValeur":MCsousMCFaPourValeur,
511 "MCsousMCFaPourValeurDansListe":MCsousMCFaPourValeurDansListe,
512 "MCaPourValeur":MCaPourValeur,
513 "MCnaPasPourValeur":MCnaPasPourValeur,
514 "existeMCsousMCFcourant":existeMCsousMCFcourant,
515 "nexistepasMCsousMCFcourant":nexistepasMCsousMCFcourant,
516 "MCsousMCFcourantaPourValeur":MCsousMCFcourantaPourValeur,
517 "MCsousMCFcourantaPourValeurDansListe":MCsousMCFcourantaPourValeurDansListe,
518 "MCsousMCFcourantnaPasPourValeurDansListe":MCsousMCFcourantnaPasPourValeurDansListe,
519 "MCsousMCFnaPasPourValeurDansListe":MCsousMCFnaPasPourValeurDansListe,
520 "MCaPourValeurDansListe":MCaPourValeurDansListe,
521 "MCnaPasPourValeurDansListe":MCnaPasPourValeurDansListe}
524 SansRegle = pasDeRegle()