2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 these file is using in GHS3DPRL Plugin
24 to convert output files .mesh of Tepal V2
25 to output files files .faces and .points of Tepal V1
26 assume compatibility GHS3DPRL Plugin Tepal V1 => Tepal V2
27 example of use (when Tepal V2):
28 facespoints2mesh.py GHS3DPRL
29 tepal2med --casename=GHS3DPRL --number=12 --medname=DOMAIN --launchtepal=no
30 mesh2facespoints.py DOMAIN
43 def find_cr_or_not(fs,tag):
44 """find number after tag with cr or sp"""
54 res=res.strip("\t\n ")
59 """convert .mesh file to .points and .faces and .noboite"""
60 print '\nconversion '+f1+' to .points and .faces and .noboite'
62 #fs=fileinput.FileInput(f1,mode='r') #mode not in v2.4.4
63 fs=fileinput.FileInput(f1)
64 (shortname, extension)=os.path.splitext(f1)
65 f2=shortname+'.points'
68 nb=find_cr_or_not(fs,'Vertices')
71 for i in xrange(0,int(nb)):
72 fp.write(fs.readline())
78 nb=find_cr_or_not(fs,'Triangles')
80 for i in xrange(0,int(nb)):
81 ff.write('3 '+fs.readline().strip('\t\n ')+' 0 0 0\n')
84 ne=find_cr_or_not(fs,'Tetrahedra')
85 f3=shortname+'.noboite'
88 fb.write(ne+' '+np+' '+npfixe+' 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n')
89 for i in xrange(0,int(ne)):
90 lig=fs.readline().strip('\t\n ')
92 fb.write(lig[0]+" "+lig[1]+" "+lig[2]+" "+lig[3]+" ")
95 fs=fileinput.FileInput(shortname+'.points')
96 nb=fs.readline() #eqal to np
97 for i in xrange(0,int(nb)):
98 lig=fs.readline().strip('\t\n ')
100 fb.write(lig[0]+" "+lig[1]+" "+lig[2]+" ")
101 fb.write('\n0\n') #subnumber
105 def rename_tepal_v1(f1,imax):
106 """rename files as version v1 of tepal expect"""
107 (shortname, extension)=os.path.splitext(f1)
108 fs=os.path.splitext(shortname)
109 i=int(fs[1].strip('.'))
110 ff=fs[0]+'.'+str(imax)+'.'+string.zfill(str(i),len(str(imax)))
111 #noboite en ".32.02.noboite!"
113 f2=shortname+'.points' ; f3=ff+os.path.splitext(f2)[1]
114 print f2,'->',f3 ; os.system(mvcp+f2+' '+f3)
115 f2=shortname+'.faces' ; f3=ff+os.path.splitext(f2)[1]
116 print f2,'->',f3 ; os.system(mvcp+f2+' '+f3)
117 f2=shortname+'.noboite' ; f3=ff+os.path.splitext(f2)[1]
118 print f2,'->',f3 ; os.system(mvcp+f2+' '+f3)
119 f2=shortname+'.glo' ; f3=ff+os.path.splitext(f2)[1]
120 print f2,'->',f3 ; os.system(mvcp+f2+' '+f3)
121 f2=shortname+'.msg' ; f3=ff+os.path.splitext(f2)[1]
122 print f2,'->',f3 ; os.system(mvcp+f2+' '+f3)
124 def my_test(a): return int(os.path.basename(a).split('.')[1])
126 f0=file_m+'.?????.mesh'
129 fics.sort(lambda a, b: cmp(my_test(b), my_test(a))) #tri ordre decroissant
130 print 'conversion of files:\n',fics
135 rename_tepal_v1(f,imax)