1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 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
31 """Cet objet conserve toutes les informations relatives à un fichier de commandes .comm"""
33 def __init__(self,src,atraiter):
34 #----------------------------------------
35 self.atraiter=atraiter
36 self.init(src,atraiter)
37 commands= self.root.childNodes[:]
42 def init(self,src,atraiter):
43 #---------------------------
44 # construction de self.lines
45 self.root=parseur.Parser(src,atraiter)
46 self.lines=src.splitlines(1)
48 def parseKeywords(self):
49 #-----------------------
50 # construction de fils (cf mocles.py)
51 parseKeywords(self.root)
54 #-----------------------
56 self.init(src,self.atraiter)
60 #-----------------------
61 # retourne la concatenation de
63 return "".join(self.getLines())
65 def getLine(self,linenum):
66 #-----------------------
67 # retourne la linenumieme ligne
68 return self.getLines()[linenum-1]
71 #----------------------------
72 # retourne toutes les lignes
75 def addLine(self,ligne,numero) :
76 #----------------------------
77 # insere le texte contenu dans ligne
78 # dans la liste self.lines au rang numero
79 Ldebut=self.lines[0:numero]
81 Lfin=self.lines[numero:]
82 self.lines=Ldebut+Lmilieu+Lfin
85 def splitLine(self,numeroLigne,numeroColonne) :
86 #----------------------------------------------
87 # coupe la ligne numeroLigne en 2 a numeroColonne
88 # ajoute des blancs en debut de 2nde Ligne pour
90 numeroLigne = numeroLigne -1
91 Ldebut=self.lines[0:numeroLigne]
92 if len(self.lines) > numeroLigne :
93 Lfin=self.lines[numeroLigne+1:]
96 Lsplit=self.lines[numeroLigne]
97 LigneSplitDebut=Lsplit[0:numeroColonne]+"\n"
98 LigneSplitFin=" "*numeroColonne+Lsplit[numeroColonne:]
99 Lmilieu=[LigneSplitDebut,LigneSplitFin]
101 self.lines=Ldebut+Lmilieu+Lfin
103 def joinLineandNext(self,numeroLigne) :
104 #--------------------------------------
105 # concatene les lignes numeroLigne et numeroLigne +1
106 # enleve les blancs de debut de la ligne (numeroLigne +1)
107 Ldebut=self.lines[0:numeroLigne-1]
108 if len(self.lines) > numeroLigne :
109 Lfin=self.lines[numeroLigne+1:]
113 ligneMilieuDeb=self.lines[numeroLigne - 1 ]
114 ligneMilieuDeb=ligneMilieuDeb[0:-1]
115 ligneMilieuFin=self.lines[numeroLigne]
116 for i in range(len(ligneMilieuFin)):
117 if ligneMilieuFin[i] != " " :
118 ligneMilieuFin=ligneMilieuFin[i:]
120 Lmilieu=[ligneMilieuDeb+ligneMilieuFin,]
122 self.lines=Ldebut+Lmilieu+Lfin
124 def supLignes(self,debut,fin):
125 #------------------------
126 Ldebut=self.lines[0:debut-1]
127 Lfin=self.lines[fin:]
128 self.lines=Ldebut+Lfin
130 def remplaceLine(self,numeroLigne,nouveauTexte) :
131 #------------------------------------------------
132 self.lines[numeroLigne]=nouveauTexte
134 def getJDC(filename,atraiter):
135 #----------------------------
140 jdc=JDCTrad(src,atraiter)
143 def getJDCFromTexte(texte,atraiter):
144 #-----------------------------------
146 jdc=JDCTrad(texte,atraiter)