]> SALOME platform Git repositories - tools/eficas.git/blobdiff - generator/Formatage.py
Salome HOME
onItem=Deplie
[tools/eficas.git] / generator / Formatage.py
index a8b0599fe7aa4635d7ae8f8f18267deee6948b16..0f8efaa9328aeca5a69d525834a0cfd295d86fb1 100644 (file)
@@ -1,29 +1,31 @@
 # -*- coding: utf-8 -*-
-#            CONFIGURATION MANAGEMENT OF EDF VERSION
-# ======================================================================
-# COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
-# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
-# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
-# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
-# (AT YOUR OPTION) ANY LATER VERSION.
+# Copyright (C) 2007-2013   EDF R&D
 #
-# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
-# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
-# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
-# GENERAL PUBLIC LICENSE FOR MORE DETAILS.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
 #
-# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
-# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
-#    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-# ======================================================================
 """
     Ce module contient la classe Formatage qui permet le formatage d'une 
     liste de chaines de caractères dans une syntaxe représentative d'un
     jeu de commandes en un texte présentable
 """
 import types,string,re
+from Extensions.i18n import tr
+filePattern="'[^\(\)]([^\(\)]*\([^\(\)]*\))*[^\(\)]*'"
+filePattern2='"[^\(\)]([^\(\)]*\([^\(\)]*\))*[^\(\)]*"'
 
 class Formatage :
   """ 
@@ -124,10 +126,10 @@ class Formatage :
         try:
           increment = len(('\n'+self.indent_courant*' ')*ind + element[0])
         except:
-          print 'ERREUR'
+          print tr('ERREUR')
           print liste
           print element
-        self.texte_etape = self.texte_etape + ('\n'+self.indent_courant*' ')*ind + element[0]
+        self.texte_etape = self.texte_etape + (u'\n'+self.indent_courant*' ')*ind + element[0]
         length = len(self.indent)
         self.indent.insert(length,self.indent[length-1]+len(element[0]))
         self.indent_courant = self.indent[length]
@@ -205,10 +207,9 @@ class Formatage :
       else : 
           bool_fonction=0
       longueur = self.longueur(self.texte_etape)
-      increment = len(('\n'+self.indent_courant*' ')*ind + string.strip(s_mcsimp))
-      #self.jdc_fini = self.jdc_fini + ('\n'+self.indent_courant*' ')*ind + string.strip(s_mcsimp)
+      increment = len((u'\n'+self.indent_courant*' ')*ind + string.strip(s_mcsimp))
       if (bool_fonction == 1 ) :
-          self.texte_etape = self.texte_etape +s_mcsimp
+          self.texte_etape = self.texte_etape+'\n'+self.indent_courant*' ' +s_mcsimp
       elif ( ((1-ind)*longueur+increment) <= self.l_max ) :
           self.texte_etape = self.texte_etape + ('\n'+self.indent_courant*' ')*ind + string.strip(s_mcsimp)
       else :
@@ -241,14 +242,21 @@ class Formatage :
       s=texte + label
       longueur = len(increment + label)
 
-      if ('(' not in valeur) or (valeur[0:3]=='"""'):
-#      if ('(' not in valeur):
+      if ('(' not in valeur) or (valeur[0:3]=='"""') :
         # il s'agit d'une vraie chaîne de caractères
         val = len(valeur)
         texte = (self.l_max-2-val)*' '+valeur
         s=s+'\n'+texte
-
+      elif re.match(filePattern,valeur) or re.match(filePattern2,valeur):
+        val = len(valeur)
+        texte = (self.l_max-2-val)*' '+valeur
+        s=s+'\n'+texte
       elif ',' in valeur:
+        # il s'agit d'une liste de tuple
+        # c est trop complique on ne splitte pas
+        if valeur[0:2]=='((' or valeur[0:2]=='[(':
+           s=s+valeur
+           return s
         # il s'agit d'une liste
         liste = string.split(valeur,',')
         i=0
@@ -278,3 +286,28 @@ class Formatage :
         s=s+'\n'+texte
 
     return s
+
+class FormatageLigne(Formatage) :
+  def __init__(self,l_jdc,code=None,mode=None,sep='=',l_max="**"):
+      Formatage.__init__(self,l_jdc,code=None,mode=None,sep='=',l_max="**")
+      
+  def formate_jdc(self):
+      texte1=Formatage.formate_jdc(self)
+      newText=""
+      lignes=texte1.split("\n")
+      texte=""
+      pattern_debut_blanc  = re.compile(r"^ \s*.*")
+      pattern_commentaire   = re.compile(r"^\s*#.*")
+      pattern_vide=re.compile(r"\s*^$")
+      for l in lignes :
+          if pattern_commentaire.match(l) or pattern_vide.match(l): 
+             newText+=l+"\n"
+             continue
+          if not pattern_debut_blanc.match(l) : texte=l 
+          else : texte+=re.sub(r'^ \s*',' ',l)
+          if texte[-1]==";" :
+             newText+=texte+"\n"
+             texte=""
+      return newText
+
+