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
23 from Traducteur import parseur
24 from Traducteur.mocles import parseKeywords
30 """Cet objet conserve toutes les informations relatives a un fichier de commandes .comm"""
32 def __init__(self,src,atraiter):
33 #----------------------------------------
34 self.atraiter=atraiter
35 self.init(src,atraiter)
36 commands= self.root.childNodes[:]
41 def init(self,src,atraiter):
42 #---------------------------
43 # construction de self.lines
44 self.root=parseur.parser(src,atraiter)
45 self.lines=src.splitlines(1)
47 def parseKeywords(self):
48 #-----------------------
49 # construction de fils (cf mocles.py)
50 parseKeywords(self.root)
53 #-----------------------
55 self.init(src,self.atraiter)
59 #-----------------------
60 # retourne la concatenation de
62 return "".join(self.getLines())
64 def getLine(self,linenum):
65 #-----------------------
66 # retourne la linenumieme ligne
67 return self.getLines()[linenum-1]
70 #----------------------------
71 # retourne toutes les lignes
74 def addLine(self,ligne,numero) :
75 #----------------------------
76 # insere le texte contenu dans ligne
77 # dans la liste self.lines au rang numero
78 Ldebut=self.lines[0:numero]
80 Lfin=self.lines[numero:]
81 self.lines=Ldebut+Lmilieu+Lfin
84 def splitLine(self,numeroLigne,numeroColonne) :
85 #----------------------------------------------
86 # coupe la ligne numeroLigne en 2 a numeroColonne
87 # ajoute des blancs en debut de 2nde Ligne pour
89 numeroLigne = numeroLigne -1
90 Ldebut=self.lines[0:numeroLigne]
91 if len(self.lines) > numeroLigne :
92 Lfin=self.lines[numeroLigne+1:]
95 Lsplit=self.lines[numeroLigne]
96 LigneSplitDebut=Lsplit[0:numeroColonne]+"\n"
97 LigneSplitFin=" "*numeroColonne+Lsplit[numeroColonne:]
98 Lmilieu=[LigneSplitDebut,LigneSplitFin]
100 self.lines=Ldebut+Lmilieu+Lfin
102 def joinLineandNext(self,numeroLigne) :
103 #--------------------------------------
104 # concatene les lignes numeroLigne et numeroLigne +1
105 # enleve les blancs de debut de la ligne (numeroLigne +1)
106 Ldebut=self.lines[0:numeroLigne-1]
107 if len(self.lines) > numeroLigne :
108 Lfin=self.lines[numeroLigne+1:]
112 ligneMilieuDeb=self.lines[numeroLigne - 1 ]
113 ligneMilieuDeb=ligneMilieuDeb[0:-1]
114 ligneMilieuFin=self.lines[numeroLigne]
115 for i in range(len(ligneMilieuFin)):
116 if ligneMilieuFin[i] != " " :
117 ligneMilieuFin=ligneMilieuFin[i:]
119 Lmilieu=[ligneMilieuDeb+ligneMilieuFin,]
121 self.lines=Ldebut+Lmilieu+Lfin
123 def supLignes(self,debut,fin):
124 #------------------------
125 Ldebut=self.lines[0:debut-1]
126 Lfin=self.lines[fin:]
127 self.lines=Ldebut+Lfin
129 def remplaceLine(self,numeroLigne,nouveauTexte) :
130 #------------------------------------------------
131 self.lines[numeroLigne]=nouveauTexte
133 def getJDC(filename,atraiter):
134 #----------------------------
139 jdc=JDCTrad(src,atraiter)
142 def getJDCFromTexte(texte,atraiter):
143 #-----------------------------------
145 jdc=JDCTrad(texte,atraiter)