home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 November / WNnov2005.iso / Windows / Equipement / Blender / blender-2.37a-windows.exe / $_5_ / .blender / scripts / bpymodules / svg2obj.py < prev   
Text File  |  2005-06-13  |  25KB  |  819 lines

  1. """
  2. SVG 2 OBJ translater, 0.3.1
  3. (c) jm soler juillet/novembre 2004, released under Blender Artistic Licence 
  4.     for the Blender 2.34/33 Python Scripts Bundle.
  5. #---------------------------------------------------------------------------
  6. # Page officielle :
  7. #   http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_import_svg.htm
  8. # Communiquer les problemes et erreurs sur:
  9. #   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
  10. #---------------------------------------------------------------------------
  11.  
  12. -- Concept : translate SVG file in GEO .obj file and try to load it. 
  13. -- Curiousity : the original matrix must be :
  14.  
  15.                          0.0 0.0 1.0 0.0
  16.                          0.0 1.0 0.0 0.0
  17.                          0.0 0.0 1.0 0.0
  18.                          0.0 0.0 0.0 1.0 
  19.  
  20.                   and not:
  21.                          1.0 0.0 0.0 0.0
  22.                          0.0 1.0 0.0 0.0
  23.                          0.0 0.0 1.0 0.0
  24.                          0.0 0.0 0.0 1.0 
  25.  
  26. -- Options :
  27.     SHARP_IMPORT = 0 
  28.             choise between "As is", "Devide by height" and "Devide by width"
  29.     SHARP_IMPORT = 1
  30.             no choise
  31.  
  32. -- Possible bug : sometime, the new curves object's RotY value 
  33.                   jumps to -90.0 degrees without any reason.
  34.  
  35. Yet done: 
  36.    M : absolute move to 
  37.    Z : close path
  38.    L : absolute line to  
  39.    C : absolute curve to
  40.    S : absolute curve to with only one handle
  41.    l : relative line to     2004/08/03
  42.    c : relative curve to    2004/08/03
  43.    s : relative curve to with only one handle  
  44.  
  45.  
  46.    A : courbe_vers_a, 
  47.    V : ligne_tracee_v,
  48.    H : ligne_tracee_h, 
  49.    Z : boucle_z,
  50.    Q : courbe_vers_q,
  51.    T : courbe_vers_t,
  52.    a : courbe_vers_a, 
  53.    v : ligne_tracee_v,
  54.    h : ligne_tracee_h, 
  55.    z : boucle_z,
  56.    q : courbe_vers_q,
  57.  
  58.    transfrom for <g> tag 
  59.    transform for <path> tag
  60.  
  61. Changelog:
  62.       0.1.1 : - control file without extension
  63.       0.2.0 : - improved reading of several data of the same type 
  64.                 following the same command (for gimp import)
  65.       0.2.1 : - better choice for viewboxing ( takes the viewbox if found, 
  66.                 instead of x,y,width and height              
  67.       0.2.2 : - read compact path data from Illustrator 10             
  68.       0.2.3 : - read a few new relative displacements
  69.       0.2.4 : - better hash for command followed by a lone data 
  70.                 (h,v) or uncommun number (a) 
  71.       0.2.5 : - correction for gimp import 
  72.       0.2.6 : - correction for illustrator 10 SVG
  73.       0.2.7 : - correction for inskape 0.40 cvs  SVG
  74.       0.2.8 : - correction for inskape plain SVG
  75.       0.3   : - transform properties added
  76.       0.3.1 : - compatibility restored with gimp 
  77.                 
  78. ==================================================================================   
  79. =================================================================================="""
  80.  
  81. SHARP_IMPORT=0
  82. SCALE=1
  83. scale=1
  84. DEBUG =0 #print
  85. DEVELOPPEMENT=0
  86.     
  87. import sys
  88. #oldpath=sys.path
  89. import Blender
  90. BLversion=Blender.Get('version')
  91.  
  92. try:
  93.     import nt
  94.     os=nt
  95.     os.sep='\\'
  96.  
  97. except:    
  98.     import posix
  99.     os=posix
  100.     os.sep='/'
  101.     
  102. def isdir(path):
  103.     try:
  104.         st = os.stat(path)
  105.         return 1 
  106.     except:
  107.         return 0
  108.     
  109. def split(pathname):
  110.          if pathname.find(os.sep)!=-1:
  111.              k0=pathname.split(os.sep)
  112.          else:
  113.             if os.sep=='/':
  114.                 k0=pathname.split('\\')
  115.             else:
  116.                 k0=pathname.split('/') 
  117.  
  118.          directory=pathname.replace(k0[len(k0)-1],'')
  119.          Name=k0[len(k0)-1]
  120.          return directory, Name
  121.         
  122. def join(l0,l1):        
  123.      return  l0+os.sep+l1
  124.     
  125. os.isdir=isdir
  126. os.split=split
  127. os.join=join
  128.  
  129. def filtreFICHIER(nom):
  130.      f=open(nom,'rU')
  131.      t=f.read()
  132.      f.close()
  133.      
  134.      t=t.replace('\r','')
  135.      t=t.replace('\n','')
  136.      
  137.      if t.upper().find('<SVG')==-1 :
  138.          name = "ERROR: invalid or empty file ... "  # if no %xN int is set, indices start from 1
  139.          result = Blender.Draw.PupMenu(name)
  140.          return "false"
  141.      elif  t.upper().find('<PATH')==-1:
  142.          name = "ERROR: there's no Path in this file ... "  # if no %xN int is set, indices start from 1
  143.          result = Blender.Draw.PupMenu(name)
  144.          return "false"
  145.      else:
  146.           return t
  147.  
  148. #===============================
  149. # Data
  150. #===============================
  151. #===============================
  152. # Blender Curve Data
  153. #===============================
  154. objBEZIER=0
  155. objSURFACE=5
  156. typBEZIER3D=1  #3D
  157. typBEZIER2D=9  #2D
  158.  
  159. class Bez:
  160.       def __init__(self):
  161.            self.co=[]
  162.            self.ha=[0,0]
  163.            
  164. class ITEM:
  165.       def __init__(self):
  166.                self.type        =  typBEZIER3D,        
  167.                self.pntsUV      =  [0,0]              
  168.                self.resolUV     =  [32,0]            
  169.                self.orderUV     =  [0,0]             
  170.                self.flagUV      =  [0,0]              
  171.                self.Origine     =  [0.0,0.0]
  172.                self.beziers_knot = []
  173.  
  174. class COURBE:
  175.       def __init__(self):
  176.               self.magic_number='3DG3'              
  177.               self.type            =  objBEZIER        
  178.               self.number_of_items =  0              
  179.               self.ext1_ext2       =  [0,0]             
  180.               self.matrix          =  """0.0 0.0 1.0 0.0
  181. 0.0 1.0 0.0 0.0
  182. 0.0 0.0 1.0 0.0
  183. 0.0 0.0 0.0 1.0 """ 
  184.               self.ITEM = {}
  185.  
  186.  
  187. courbes=COURBE()
  188. PATTERN={}
  189. BOUNDINGBOX={'rec':[],'coef':1.0}
  190. npat=0
  191. #=====================================================================
  192. #======== name of the curve in the curves dictionnary ===============
  193. #=====================================================================
  194. n0=0
  195.  
  196. #=====================================================================
  197. #====================== current Point ================================
  198. #=====================================================================
  199. CP=[0.0,0.0] #currentPoint
  200.  
  201. #=====================================================================
  202. #===== to compare last position to the original move to displacement =
  203. #=====  needed for cyclic definition inAI, EPS forma  ================
  204. #=====================================================================
  205. def test_egalitedespositions(f1,f2):
  206.     if f1[0]==f2[0] and f1[1]==f2[1]:
  207.        return Blender.TRUE
  208.     else:
  209.        return Blender.FALSE
  210.  
  211.  
  212. def Open_GEOfile(dir,nom):
  213.     global SCALE,BOUNDINGBOX, scale
  214.     if BLversion>=233:
  215.        Blender.Load(dir+nom+'OOO.obj', 1)
  216.        BO=Blender.Object.Get()
  217.  
  218.        BO[-1].RotY=3.1416
  219.        BO[-1].RotZ=3.1416
  220.        BO[-1].RotX=3.1416/2.0
  221.        
  222.        if scale==1:
  223.           BO[-1].LocY+=BOUNDINGBOX['rec'][3]
  224.        else:
  225.          BO[-1].LocY+=BOUNDINGBOX['rec'][3]/SCALE
  226.  
  227.        BO[-1].makeDisplayList() 
  228.        Blender.Window.RedrawAll()
  229.     else:
  230.        print "Not yet implemented"
  231.  
  232. def create_GEOtext(courbes):
  233.     global SCALE, B, BOUNDINGBOX,scale
  234.     r=BOUNDINGBOX['rec']
  235.  
  236.     if scale==1:
  237.        SCALE=1.0
  238.     elif scale==2:
  239.        SCALE=r[2]-r[0]
  240.     elif scale==3:
  241.        SCALE=r[3]-r[1]
  242.  
  243.     t=[]
  244.     t.append(courbes.magic_number+'\n')
  245.     t.append(str(courbes.type)+'\n')
  246.     t.append(str(courbes.number_of_items)+'\n')
  247.     t.append(str(courbes.ext1_ext2[0])+' '+str(courbes.ext1_ext2[1])+'\n')
  248.     t.append(courbes.matrix+'\n')
  249.     
  250.     for k in courbes.ITEM.keys():
  251.         t.append("%s\n"%courbes.ITEM[k].type)
  252.         t.append("%s %s \n"%(courbes.ITEM[k].pntsUV[0],courbes.ITEM[k].pntsUV[1]))
  253.         t.append("%s %s \n"%(courbes.ITEM[k].resolUV[0],courbes.ITEM[k].resolUV[1]))
  254.         t.append("%s %s \n"%(courbes.ITEM[k].orderUV[0],courbes.ITEM[k].orderUV[1]))
  255.         t.append("%s %s \n"%(courbes.ITEM[k].flagUV[0],courbes.ITEM[k].flagUV[1]))
  256.  
  257.         flag =0#courbes.ITEM[k].flagUV[0]
  258.  
  259.         for k2 in range(flag,len(courbes.ITEM[k].beziers_knot)):
  260.            #k1 =courbes.ITEM[k].beziers_knot[k2]
  261.            k1=ajustement(courbes.ITEM[k].beziers_knot[k2], SCALE)
  262.            
  263.            t.append("%4f 0.0 %4f \n"%(k1[4],k1[5]))
  264.            t.append("%4f 0.0 %4f \n"%(k1[0],k1[1]))
  265.            t.append("%4f 0.0 %4f \n"%(k1[2],k1[3]))
  266.            t.append(str(courbes.ITEM[k].beziers_knot[k2].ha[0])+' '+str(courbes.ITEM[k].beziers_knot[k2].ha[1])+'\n')
  267.  
  268.     return t
  269.  
  270. def save_GEOfile(dir,nom,t):
  271.      f=open(dir+nom+'OOO.obj','w')
  272.      f.writelines(t)
  273.      f.close()
  274.  
  275.  
  276. def filtre_DATA(c,D,n):
  277.     global DEBUG,TAGcourbe
  278.     l=[] 
  279.     if len(c[0])==1 and D[c[1]+1].find(',')!=-1:
  280.         for n2 in range(1,n+1): 
  281.            ld=D[c[1]+n2].split(',')
  282.            for l_ in ld: 
  283.                l.append(l_)
  284.                
  285.     elif len(c[0])==1 and D[c[1]+2][0] not in  TAGcourbe:
  286.         for n2 in range(1,n*2+1):
  287.            l.append(D[c[1]+n2])
  288.         if DEBUG==1 : print l 
  289.  
  290.     return l
  291.  
  292. #=====================================================================
  293. #=====      SVG format   :  DEBUT             =========================
  294. #=====================================================================
  295.  
  296. def contruit_SYMETRIC(l):
  297.     L=[float(l[0]), float(l[1]),
  298.        float(l[2]),float(l[3])]
  299.     X=L[0]-(L[2]-L[0])
  300.     Y=L[1]-(L[3]-L[1])
  301.     l =[l[0],l[1],"%4s"%X,"%4s"%Y,l[2],l[3]]   
  302.     return l
  303.  
  304. def mouvement_vers(c, D, n0,CP):
  305.     global DEBUG,TAGcourbe
  306.     #print 'c',c,'D[c[1]+1]',D[c[1]+1]
  307.  
  308.     l=filtre_DATA(c,D,1)
  309.     #print 'l',l
  310.     if n0 in courbes.ITEM.keys():
  311.        n0+=1
  312.     #
  313.     #   CP=[l[0],l[1]]        
  314.     #else:
  315.     #   CP=[l[0],l[1]] 
  316.     CP=[l[0],l[1]] 
  317.  
  318.     courbes.ITEM[n0]=ITEM() 
  319.     courbes.ITEM[n0].Origine=[l[0],l[1]] 
  320.  
  321.     B=Bez()
  322.     B.co=[CP[0],CP[1],CP[0],CP[1],CP[0],CP[1]]
  323.     B.ha=[0,0]
  324.     
  325.     courbes.ITEM[n0].beziers_knot.append(B)
  326.     if DEBUG==1: print courbes.ITEM[n0], CP
  327.     
  328.  
  329.     return  courbes,n0,CP     
  330.     
  331. def boucle_z(c,D,n0,CP): #Z,z
  332.     #print c, 'close'
  333.     courbes.ITEM[n0].flagUV[0]=1 
  334.     return  courbes,n0,CP    
  335.    
  336. def courbe_vers_s(c,D,n0,CP):  #S,s
  337.     l=filtre_DATA(c,D,2) 
  338.     if c[0]=='s':
  339.        l=["%4s"%(float(l[0])+float(CP[0])),
  340.           "%4s"%(float(l[1])+float(CP[1])),
  341.           "%4s"%(float(l[2])+float(CP[0])),
  342.           "%4s"%(float(l[3])+float(CP[1]))]
  343.     l=contruit_SYMETRIC(l)    
  344.     B=Bez()
  345.     B.co=[l[4],l[5],l[2],l[3],l[0],l[1]] #plus toucher au 2-3
  346.     B.ha=[0,0]
  347.  
  348.     BP=courbes.ITEM[n0].beziers_knot[-1]
  349.     BP.co[2]=l[2]  #4-5 point prec
  350.     BP.co[3]=l[3]
  351.  
  352.     courbes.ITEM[n0].beziers_knot.append(B)
  353.     if DEBUG==1: print B.co,BP.co
  354.     CP=[l[4],l[5]]    
  355.  
  356.     if len(D)<c[1]+3 and D[c[1]+3] not in TAGcourbe :
  357.         c[1]+=2
  358.         courbe_vers_c(c, D, n0,CP)
  359.     return  courbes,n0,CP
  360.  
  361. def courbe_vers_a(c,D,n0,CP):  #A
  362.     #print c
  363.     return  courbes,n0,CP     
  364.  
  365. def courbe_vers_q(c,D,n0,CP):  #Q
  366.     #print c
  367.     return  courbes,n0,CP     
  368.  
  369. def courbe_vers_t(c,D,n0,CP):  #T
  370.     return  courbes,n0,CP     
  371.        
  372. def courbe_vers_c(c, D, n0,CP): #c,C
  373.  
  374.     l=filtre_DATA(c,D,3) 
  375.     #print l, c, CP
  376.  
  377.     if c[0]=='c':
  378.        l=["%4s"%(float(l[0])+float(CP[0])),
  379.           "%4s"%(float(l[1])+float(CP[1])),
  380.           "%4s"%(float(l[2])+float(CP[0])),
  381.           "%4s"%(float(l[3])+float(CP[1])),
  382.           "%4s"%(float(l[4])+float(CP[0])),
  383.           "%4s"%(float(l[5])+float(CP[1]))]
  384.  
  385.     #print l
  386.    
  387.     B=Bez()
  388.     B.co=[l[4],
  389.           l[5],
  390.           l[0],
  391.           l[1],
  392.           l[2],
  393.           l[3]] #plus toucher au 2-3
  394.  
  395.     B.ha=[0,0]
  396.  
  397.     BP=courbes.ITEM[n0].beziers_knot[-1]
  398.  
  399.     BP.co[2]=l[0]
  400.     BP.co[3]=l[1]
  401.  
  402.     courbes.ITEM[n0].beziers_knot.append(B)
  403.     if DEBUG==1: print B.co,BP.co
  404.  
  405.     CP=[l[4],l[5]]
  406.     if DEBUG==1:
  407.        pass #print 'D[c[1]]', D[c[1]], c
  408.        #print D
  409.     if len(D)<c[1]+4 and D[c[1]+4] not in TAGcourbe :
  410.         c[1]+=3
  411.         courbe_vers_c(c, D, n0,CP)
  412.  
  413.     return  courbes,n0,CP
  414.     
  415.     
  416. def ligne_tracee_l(c, D, n0,CP): #L,l
  417.     #print c
  418.     
  419.     l=filtre_DATA(c,D,1)
  420.     if c[0]=='l':
  421.        l=["%4s"%(float(l[0])+float(CP[0])),
  422.           "%4s"%(float(l[1])+float(CP[1]))]
  423.  
  424.     B=Bez()
  425.     B.co=[l[0],l[1],l[0],l[1],l[0],l[1]]
  426.     B.ha=[0,0]
  427.     courbes.ITEM[n0].beziers_knot.append(B)    
  428.  
  429.     CP=[l[0],l[1]]
  430.  
  431.     if len(D)<c[1]+2 and D[c[1]+2] not in TAGcourbe :
  432.         c[1]+=1
  433.         ligne_tracee_l(c, D, n0,CP) #L
  434.             
  435.     return  courbes,n0,CP    
  436.     
  437.     
  438. def ligne_tracee_h(c,D,n0,CP): #H,h
  439.     #print '|',c[0],'|',len(c[0]),'  --> ',CP[0]
  440.     if c[0]=='h':
  441.        l=["%4s"%(float(D[c[1]+1])+float(CP[0])),
  442.           "%4s"%float(CP[1])]
  443.     else:
  444.        l=["%4s"%float(D[c[1]+1]),
  445.           "%4s"%float(CP[1])]        
  446.     B=Bez()
  447.     B.co=[l[0],l[1],l[0],l[1],l[0],l[1]]
  448.     B.ha=[0,0]
  449.     courbes.ITEM[n0].beziers_knot.append(B)    
  450.  
  451.     CP=[l[0],l[1]]
  452.     #print 'CP', CP    
  453.     return  courbes,n0,CP    
  454.  
  455. def ligne_tracee_v(c,D,n0,CP): #V, v
  456.     #l=filtre_DATA(c,D,0)
  457.     
  458.     if c[0]=='v':
  459.        l=["%4s"%float(CP[0]),
  460.           "%4s"%(float(D[c[1]+1])+float(CP[1]))]
  461.        #print '|',c[0],'|', len(c[0]) ,'  --> ',CP
  462.     else:
  463.        l=["%4s"%float(CP[0]),
  464.           "%4s"%float(D[c[1]+1])]        
  465.        #print '|',c[0],'|', len(c[0]) ,'  --> ',CP
  466.  
  467.     B=Bez()
  468.     B.co=[l[0],l[1],l[0],l[1],l[0],l[1]]
  469.     B.ha=[0,0]
  470.     courbes.ITEM[n0].beziers_knot.append(B)    
  471.  
  472.     CP=[l[0],l[1]]
  473.     #print 'CP', CP
  474.     return  courbes,n0,CP    
  475.  
  476. def boucle_tracee_z(c,D,n0,CP): #Z
  477.     #print c
  478.     #CP=[]
  479.     return  courbes,n0,CP    
  480.      
  481. Actions=   {     "C" : courbe_vers_c,
  482.                  "A" : courbe_vers_a, 
  483.                  "S" : courbe_vers_s,
  484.                  "M" : mouvement_vers,
  485.                  "V" : ligne_tracee_v,
  486.                  "L" : ligne_tracee_l,
  487.                  "H" : ligne_tracee_h,                
  488.                  "Z" : boucle_z,
  489.                  "Q" : courbe_vers_q,
  490.                  "T" : courbe_vers_t,
  491.  
  492.                  "c" : courbe_vers_c,
  493.                  "a" : courbe_vers_a, 
  494.                  "s" : courbe_vers_s,
  495.                  "m" : mouvement_vers,
  496.                  "v" : ligne_tracee_v,
  497.                  "l" : ligne_tracee_l,
  498.                  "h" : ligne_tracee_h,                
  499.                  "z" : boucle_z,
  500.                  "q" : courbe_vers_q,
  501.                  "T" : courbe_vers_t
  502. }
  503.      
  504. TAGcourbe=Actions.keys()
  505. TAGtransform=['M','L','C','S','H','V','T','Q']
  506. tagTRANSFORM=0
  507.  
  508. def get_content(val,t0):
  509.     t=t0[:] 
  510.     if t.find(' '+val+'="')!=-1:
  511.        t=t[t.find(' '+val+'="')+len(' '+val+'="'):]
  512.        val=t[:t.find('"')]
  513.        t=t[t.find('"'):]
  514.        #----------------------------------------------------------------
  515.        #print t[:10], val
  516.        #wait=raw_input('wait:'  )
  517.  
  518.        return t0,val
  519.     else:
  520.        return t0,0
  521.  
  522. def get_tag(val,t):
  523.  
  524.     t=t[t.find('<'+val):]
  525.     val=t[:t.find('>')+1]
  526.     t=t[t.find('>')+1:]
  527.     
  528.     if DEBUG==3 : print t[:10], val
  529.  
  530.     return t,val
  531.  
  532. def get_data(val,t):
  533.  
  534.     t=t[t.find('<'+val):]
  535.     val=t[:t.find('</'+val+'>')]
  536.     t=t[t.find('</'+val+'>')+3+len(val):]
  537.     
  538.     if DEBUG==3 : print t[:10], val
  539.  
  540.     return t,val
  541.     
  542. def get_val(val,t):
  543.     d=""
  544.     #print t
  545.     for l in t:
  546.         if l.find(val+'="')!=-1:
  547.             #print 'l', l
  548.             # 0.2.7 : - correction for inskape 0.40 cvs  SVG
  549.             l=l.replace('>','')
  550.             # 0.2.7 : -- end 
  551.             d=l[l[:-1].rfind('"')+1:-1]
  552.             #print 'd', d   
  553.             for nn in d:
  554.                 if '0123456789.'.find(nn)==-1:
  555.                      d=d.replace(nn,"")
  556.                      #print d
  557.             d=float(d)
  558.             break
  559.         #else:
  560.         #  print l
  561.         d=0.0 
  562.     return d
  563.  
  564. def get_BOUNDBOX(BOUNDINGBOX,SVG,viewbox):
  565.     if viewbox==0:
  566.         h=get_val('height',SVG)
  567.         if DEBUG==1 : print 'h : ',h
  568.         w=get_val('width',SVG)
  569.         if DEBUG==1 : print 'w :',w
  570.         BOUNDINGBOX['rec']=[0.0,0.0,w,h]
  571.         r=BOUNDINGBOX['rec']
  572.         BOUNDINGBOX['coef']=w/h       
  573.     else:
  574.         viewbox=viewbox.split()
  575.         BOUNDINGBOX['rec']=[float(viewbox[0]),float(viewbox[1]),float(viewbox[2]),float(viewbox[3])]
  576.         r=BOUNDINGBOX['rec']
  577.         BOUNDINGBOX['coef']=(r[2]-r[0])/(r[3]-r[1])       
  578.  
  579.     return BOUNDINGBOX
  580.  
  581. # 0.2.8 : - correction for inskape 0.40 cvs  SVG
  582. def repack_DATA(DATA):   
  583.     for d in Actions.keys():
  584.         DATA=DATA.replace(d,d+' ')
  585.     return DATA    
  586.  
  587.  
  588. def unpack_DATA(DATA):
  589.     DATA[0]=DATA[0].replace('-',',-')
  590.     
  591.     for d in Actions.keys():
  592.         DATA[0]=DATA[0].replace(d,', '+d+',')
  593.  
  594.     DATA[0]=DATA[0].replace(',,',',')
  595.     
  596.     if DATA[0][0]==',':DATA[0]=DATA[0][1:]
  597.     if DATA[0][-1]==',':DATA[0]=DATA[0][:-1]
  598.  
  599.     DATA[0]=DATA[0].replace('\n','')
  600.     DATA[0]=DATA[0].replace('\t','')
  601.     DATA[0]=DATA[0].split(',')
  602.  
  603.     D2=[]
  604.     D1=DATA[0]
  605.     
  606.     for cell in range(len(D1)):
  607.        if D1[cell] in Actions.keys():
  608.           D2.append(D1[cell])
  609.           n=1
  610.           if D1[cell] not in ['h','v','H','V','a','A']:
  611.               while cell+n+1<len(D1) and (D1[cell+n] not in  Actions.keys()):
  612.                  D2.append(D1[cell+n]+','+D1[cell+n+1])               
  613.                  n+=2
  614.           elif D1[cell] in ['h','v','H','V']:       
  615.               while cell+n+1<len(D1) and (D1[cell+n] not in  Actions.keys()):
  616.                  D2.append(D1[cell+n])
  617.                  n+=1
  618.           elif D1[cell] in ['a','A']:       
  619.                  #(rx ry rotation-axe-x drapeau-arc-large drapeau-balayage x y)
  620.                  #150,150 0 1,0 150,-150
  621.                  D2.append(D1[cell+n]+','+D1[cell+n+1])
  622.                  D2.append(D1[cell+n+2])
  623.                  D2.append(D1[cell+n+3]+','+D1[cell+n+4])
  624.                  D2.append(D1[cell+n+5]+','+D1[cell+n+6])
  625.                  n+=7
  626.     return D2
  627.  
  628. def translate(a,b):
  629.     return [a,b]
  630.  
  631. def get_TRANSFORM(STRING):
  632.     STRING,TRANSFORM=get_content('transform',STRING)
  633.     if TRANSFORM.find('translate')!=-1:
  634.        exec "TRANSFORM=%s"%TRANSFORM
  635.     return  TRANSFORM
  636.  
  637. def G_move(l,a,t):
  638.     if a!=-1:
  639.        return str(float(l)+float(t[a]))
  640.     else :
  641.        l=l.split(',')
  642.        return str(float(l[0])+float(t[0]))+','+str(float(l[1])+float(t[1]))
  643.     
  644. def transform_DATA(D1,TRANSFORM):   
  645.     for cell in range(len(D1)):
  646.         if D1[cell] in TAGtransform:
  647.            try:       
  648.                 if D1[cell] == 'C': #6 valeurs
  649.                     D1[cell+1]=G_move(D1[cell+1],0,TRANSFORM)
  650.                     D1[cell+2]=G_move(D1[cell+2],1,TRANSFORM)
  651.                     D1[cell+3]=G_move(D1[cell+3],0,TRANSFORM)
  652.                     D1[cell+4]=G_move(D1[cell+4],1,TRANSFORM)
  653.                     D1[cell+5]=G_move(D1[cell+5],0,TRANSFORM)
  654.                     D1[cell+6]=G_move(D1[cell+6],1,TRANSFORM)
  655.                 elif D1[cell] in ['M','L','T']: #2 valeurs
  656.                     D1[cell+1]=G_move(D1[cell+1],0,TRANSFORM)
  657.                     D1[cell+2]=G_move(D1[cell+2],1,TRANSFORM)
  658.                 elif D1[cell] == ['S','Q']: #4 valeurs
  659.                     D1[cell+1]=G_move(D1[cell+1],0,TRANSFORM)
  660.                     D1[cell+2]=G_move(D1[cell+2],1,TRANSFORM)
  661.                     D1[cell+3]=G_move(D1[cell+3],0,TRANSFORM)
  662.                     D1[cell+4]=G_move(D1[cell+4],1,TRANSFORM)
  663.            except :
  664.                 if D1[cell] == 'C': #6 valeurs
  665.                     D1[cell+1]=G_move(D1[cell+1],-1,TRANSFORM)
  666.                     D1[cell+2]=G_move(D1[cell+2],-1,TRANSFORM)
  667.                     D1[cell+3]=G_move(D1[cell+3],-1,TRANSFORM)
  668.                 elif D1[cell] in ['M','L','T']: #2 valeurs
  669.                     D1[cell+1]=G_move(D1[cell+1],-1,TRANSFORM)
  670.                 elif D1[cell] == ['S','Q']: #4 valeurs
  671.                     D1[cell+1]=G_move(D1[cell+1],-1,TRANSFORM)
  672.                     D1[cell+2]=G_move(D1[cell+2],-1,TRANSFORM)
  673.            if D1[cell] == 'H': #1 valeurs x
  674.                 n=0
  675.                 D1[cell+1]=G_move(D1[cell+1],0,TRANSFORM)
  676.            elif D1[cell] == 'V': #1 valeurs y
  677.                 n=0
  678.                 D1[cell+1]=G_move(D1[cell+1],1,TRANSFORM)
  679.     return D1            
  680.                 
  681. def format_PATH(t,TRANSFORM):
  682.     global tagTRANSFORM
  683.     
  684.     t,PATH=get_tag('path',t)
  685.  
  686.     if PATH.find(' transform="')!=-1:
  687.        TRANSFORM2=get_TRANSFORM(PATH)
  688.        TRANSFORM[0]+=TRANSFORM2[0]
  689.        TRANSFORM[1]+=TRANSFORM2[1]
  690.        tagTRANSFORM+=1
  691.        
  692.     if PATH.find(' id="')!=-1:
  693.        PATH,ID=get_content('id',PATH)
  694.        #print 'ident = ', ID
  695.  
  696.     if PATH.find(' STROKE="')!=-1:
  697.        PATH,ID=get_content('stroke',PATH)
  698.        #print 'path stroke = ', ID
  699.  
  700.     if PATH.find(' stroke-width="')!=-1:
  701.        PATH,ID=get_content('stroke-width',PATH)
  702.        #print 'path stroke-width = ', ID
  703.  
  704.     if PATH.find(' d="')!=-1:
  705.        PATH,D=get_content('d',PATH)
  706.  
  707.     # 0.2.8 : - correction for inskape plain SVG    
  708.     if D.find(',')==-1:
  709.         D=repack_DATA(D)
  710.     # 0.2.8 : end
  711.         
  712.     D=D.split(' ')
  713.  
  714.     if  tagTRANSFORM in [1,2] : D=transform_DATA(D,TRANSFORM)
  715.     
  716.     try:
  717.       while D.index(''):
  718.          del D[D.index('')]
  719.     except:
  720.       pass
  721.     
  722.     if len(D)==1 or len(D[0])>1 :
  723.        D1=[]     
  724.        for D0 in D:
  725.            D1+=unpack_DATA([D0])[:]
  726.        D=D1
  727.  
  728.  
  729.     return t,D
  730.  
  731.  
  732.  
  733.                         
  734. def scan_FILE(nom):
  735.   global CP, courbes, SCALE, DEBUG, BOUNDINGBOX, scale, tagTRANSFORM
  736.   dir,name=split(nom)
  737.   name=name.split('.')
  738.   n0=0
  739.   result=0
  740.   
  741.   t=filtreFICHIER(nom)
  742.   
  743.   if t!='false':
  744.      if not SHARP_IMPORT:
  745.          warning = "Select Size : %t| As is %x1 | Scale on Height %x2| Scale on Width %x3" 
  746.          scale = Blender.Draw.PupMenu(warning)
  747.      npat=0
  748.      l=0
  749.      do=0
  750.      t,SVG=get_tag('svg',t)
  751.  
  752.      SVG,viewbox=get_content('viewBox',SVG)
  753.  
  754.      SVG=SVG.split(' ')
  755.      if DEBUG==1 : print SVG
  756.      if viewbox==0:
  757.           BOUNDINGBOX = get_BOUNDBOX(BOUNDINGBOX,SVG,0)
  758.      else:
  759.           BOUNDINGBOX = get_BOUNDBOX(BOUNDINGBOX,SVG,viewbox)
  760.           
  761.      while t.find('<g')!=-1:
  762.          t,G=get_data('g',t)
  763.          TRANSFORM=[0.0,0.0]
  764.          tagTRANSFORM=0
  765.          if G.find(' transform="')!=-1:  
  766.             TRANSFORM=get_TRANSFORM(G)
  767.             tagTRANSFORM=1
  768.          while G.find('path')!=-1: 
  769.             G,D=format_PATH(G,TRANSFORM)
  770.             cursor=0
  771.             for cell in D: 
  772.               if DEBUG==2 : print 'cell : ',cell ,' --'                   
  773.               if len(cell)>=1 and cell[0] in TAGcourbe:
  774.                    courbes,n0,CP=Actions[cell]([cell,cursor], D, n0,CP)            
  775.               cursor+=1
  776.  
  777.      while t.find('path')!=-1:
  778.             TRANSFORM=[0.0,0.0]
  779.             t,D=format_PATH(t,TRANSFORM)
  780.             cursor=0
  781.             for cell in D: 
  782.               if DEBUG==2 : print 'cell : ',cell ,' --'                   
  783.               if len(cell)>=1 and cell[0] in TAGcourbe:
  784.                    courbes,n0,CP=Actions[cell]([cell,cursor], D, n0,CP)            
  785.               cursor+=1
  786.  
  787.   courbes.number_of_items=len(courbes.ITEM.keys())
  788.  
  789.   for k in courbes.ITEM.keys():
  790.      courbes.ITEM[k].pntsUV[0] =len(courbes.ITEM[k].beziers_knot)
  791.  
  792.   if courbes.number_of_items>0:
  793.      if len(PATTERN.keys() )>0:
  794.         if DEBUG == 3 : print len(PATTERN.keys() )
  795.      t=create_GEOtext(courbes)
  796.      save_GEOfile(dir,name[0],t)
  797.      Open_GEOfile(dir,name[0])
  798.   else:
  799.       pass
  800.     
  801. def  ajustement(v,s):
  802.      
  803.      a,b,c,d,e,f=float(v.co[0]),float(v.co[1]),float(v.co[2]),float(v.co[3]),float(v.co[4]),float(v.co[5])
  804.      return [a/s,-b/s,c/s,-d/s,e/s,-f/s]
  805.  
  806. #=====================================================================
  807. #====================== SVG format mouvements ========================
  808. #=====================================================================
  809.  
  810. #=====================================================================
  811. # une sorte de contournement qui permet d'utiliser la fonction
  812. # et de documenter les variables Window.FileSelector
  813. #=====================================================================
  814. def fonctionSELECT(nom):
  815.     scan_FILE(nom)
  816.  
  817. if __name__=='__main__':
  818.    Blender.Window.FileSelector (fonctionSELECT, 'SELECT a .SVG FILE')
  819.