Salome HOME
49aef48cb56098def4402fb60d66a13c50efcc33
[tools/eficas.git] / InterfaceQT4 / gereRegles.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
21 from __future__ import absolute_import
22 try :
23     from builtins import object
24 except : pass
25
26 from PyQt5.QtCore import Qt
27 from  .monViewRegles  import ViewRegles
28 from Extensions.i18n import tr
29
30 class GereRegles(object) :
31
32     def appellebuildLBRegles(self):
33         from .browser import JDCTree
34         if isinstance(self,JDCTree):
35             self.appellebuildLBReglesForJdC()
36         else :
37             self.appellebuildLBReglesForCommand()
38         self.buildLBRegles(self.listeRegles,self.listeNomsEtapes)
39         self.afficheRegles()
40
41     def appellebuildLBReglesForCommand(self):
42         self.listeRegles     = self.item.getRegles()
43         self.listeNomsEtapes = self.item.getMcPresents()
44
45     def appellebuildLBReglesForJdC(self):
46         self.listeRegles=self.item.getRegles()
47         self.listeNomsEtapes = self.item.getLNomsEtapes()
48
49
50     def buildLBRegles(self,listeRegles,listeNomsEtapes):
51         self.liste=[]
52         if len(listeRegles) > 0:
53             for regle in listeRegles :
54                 texteRegle=regle.getText()
55                 texteMauvais,test = regle.verif(listeNomsEtapes)
56                 for ligne in texteRegle.split("\n") :
57                     if ligne == "" : continue
58                     if ligne[0]=="\t" :  ligne="     "+ligne[1:]
59                     if test :
60                         self.liste.append((ligne,Qt.black))
61                     else :
62                         self.liste.append((ligne,Qt.red))
63                 self.liste.append(("",Qt.red))
64         if self.liste==[] : self.liste.append(("pas de regle de construction pour ce jeu de commandes",Qt.black))
65
66
67     def afficheRegles(self):
68         titre="Regles pour "+self.item.nom
69         w = ViewRegles( self.editor,self.liste,titre  )
70         w.exec_()