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
24 from mocles import parseKeywords
29 """Cet objet conserve toutes les informations relatives à un fichier de commandes .comm"""
31 def __init__(self,src,atraiter):
32 #----------------------------------------
33 self.atraiter=atraiter
34 self.init(src,atraiter)
36 def init(self,src,atraiter):
37 #---------------------------
38 # construction de self.lines
39 self.root=parseur.Parser(src,atraiter)
40 self.lines=src.splitlines(1)
42 def parseKeywords(self):
43 #-----------------------
44 # construction de fils (cf mocles.py)
45 parseKeywords(self.root)
48 #-----------------------
50 self.init(src,self.atraiter)
54 #-----------------------
55 # retourne la concatenation de
57 return "".join(self.getLines())
59 def getLine(self,linenum):
60 #-----------------------
61 # retourne la linenumieme ligne
62 return self.getLines()[linenum-1]
65 #----------------------------
66 # retourne toutes les lignes
69 def addLine(self,ligne,numero) :
70 #----------------------------
71 # insere le texte contenu dans ligne
72 # dans la liste self.lines au rang numero
73 Ldebut=self.lines[0:numero]
75 Lfin=self.lines[numero:]
76 self.lines=Ldebut+Lmilieu+Lfin
79 def splitLine(self,numeroLigne,numeroColonne) :
80 #----------------------------------------------
81 # coupe la ligne numeroLigne en 2 a numeroColonne
82 # ajoute des blancs en debut de 2nde Ligne pour
84 numeroLigne = numeroLigne -1
85 Ldebut=self.lines[0:numeroLigne]
86 if len(self.lines) > numeroLigne :
87 Lfin=self.lines[numeroLigne+1:]
90 Lsplit=self.lines[numeroLigne]
91 LigneSplitDebut=Lsplit[0:numeroColonne]+"\n"
92 LigneSplitFin=" "*numeroColonne+Lsplit[numeroColonne:]
93 Lmilieu=[LigneSplitDebut,LigneSplitFin]
95 self.lines=Ldebut+Lmilieu+Lfin
97 def joinLineandNext(self,numeroLigne) :
98 #--------------------------------------
99 # concatene les lignes numeroLigne et numeroLigne +1
100 # enleve les blancs de debut de la ligne (numeroLigne +1)
101 Ldebut=self.lines[0:numeroLigne-1]
102 if len(self.lines) > numeroLigne :
103 Lfin=self.lines[numeroLigne+1:]
107 ligneMilieuDeb=self.lines[numeroLigne - 1 ]
108 ligneMilieuDeb=ligneMilieuDeb[0:-1]
109 ligneMilieuFin=self.lines[numeroLigne]
110 for i in range(len(ligneMilieuFin)):
111 if ligneMilieuFin[i] != " " :
112 ligneMilieuFin=ligneMilieuFin[i:]
114 Lmilieu=[ligneMilieuDeb+ligneMilieuFin,]
116 self.lines=Ldebut+Lmilieu+Lfin
118 def supLignes(self,debut,fin):
119 #------------------------
120 Ldebut=self.lines[0:debut-1]
121 Lfin=self.lines[fin:]
122 self.lines=Ldebut+Lfin
124 def remplaceLine(self,numeroLigne,nouveauTexte) :
125 #------------------------------------------------
126 self.lines[numeroLigne]=nouveauTexte
128 def getJDC(filename,atraiter):
129 #----------------------------
134 jdc=JDCTrad(src,atraiter)
137 def getJDCFromTexte(texte,atraiter):
138 #-----------------------------------
140 jdc=JDCTrad(texte,atraiter)