2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2016 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, or (at your option) any later version.
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
22 these file is using in GHS3DPRL Plugin
23 to convert output files .mesh of Tepal V2
24 to output files files .faces and .points of Tepal V1
25 assume compatibility GHS3DPRL Plugin Tepal V1 => Tepal V2
26 example of use (when Tepal V2):
27 facespoints2mesh.py GHS3DPRL
28 tepal2med --casename=GHS3DPRL --number=12 --medname=DOMAIN --launchtepal=no
29 mesh2facespoints.py DOMAIN
41 if len(sys.argv) == 2:
45 def find_cr_or_not(fs, tag):
46 """find number after tag with cr or sp"""
48 if tag + '\n' in line:
53 # print 'vertices<sp>'
56 res = res.strip("\t\n ")
57 print(tag + ' ' + res)
62 """convert .mesh file to .points and .faces and .noboite"""
63 print('\nconversion ' + f1 + ' to .points and .faces and .noboite')
65 # fs=fileinput.FileInput(f1,mode='r') #mode not in v2.4.4
66 fs = fileinput.FileInput(f1)
67 shortname = os.path.splitext(f1)[0]
68 f2 = shortname + '.points'
70 with codecs.open(f2, 'w') as fp:
71 nb = find_cr_or_not(fs, 'Vertices')
72 np = nb # for .noboite
74 for _ in range(int(nb)):
75 fp.write(fs.readline())
77 f2 = shortname + '.faces'
79 with codecs.open(f2, 'w') as ff:
80 nb = find_cr_or_not(fs, 'Triangles')
82 for _ in range(int(nb)):
83 ff.write('3 ' + fs.readline().strip('\t\n ') + ' 0 0 0\n')
85 ne = find_cr_or_not(fs, 'Tetrahedra')
86 f3 = shortname + '.noboite'
87 with codecs.open(f3, 'w') as fb:
89 fb.write(ne + ' ' + np + ' ' + npfixe + ' 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n')
90 for _ in range(int(ne)):
91 lig = fs.readline().strip('\t\n ')
93 fb.write(lig[0] + " " + lig[1] + " " + lig[2] + " " + lig[3] + " ")
96 fs = fileinput.FileInput(shortname + '.points')
97 nb = fs.readline() # eqal to np
98 for _ in range(int(nb)):
99 lig = fs.readline().strip('\t\n ')
101 fb.write(lig[0] + " " + lig[1] + " " + lig[2] + " ")
102 fb.write('\n0\n') # subnumber
106 def rename_tepal_v1(f1, imax):
107 """rename files as version v1 of tepal expect"""
108 shortname = os.path.splitext(f1)[0]
109 fs = os.path.splitext(shortname)
110 i = int(fs[1].strip('.'))
111 ff = fs[0] + '.' + str(imax) + '.' + str(i).zfill(len(str(imax)))
112 # noboite en ".32.02.noboite!"
113 f2 = shortname + '.points'
114 f3 = ff + os.path.splitext(f2)[1]
117 f2 = shortname + '.faces'
118 f3 = ff + os.path.splitext(f2)[1]
121 f2 = shortname + '.noboite'
122 f3 = ff + os.path.splitext(f2)[1]
125 f2 = shortname + '.glo'
126 f3 = ff + os.path.splitext(f2)[1]
129 f2 = shortname + '.msg'
130 f3 = ff + os.path.splitext(f2)[1]
136 return int(os.path.basename(a).split('.')[1])
140 return (a > b) - (a < b)
142 f0 = file_m + '.?????.mesh'
145 fics.sort(lambda a, b: cmp(my_test(b), my_test(a))) # tri ordre decroissant
146 print('conversion of files:\n', fics)
151 rename_tepal_v1(f, imax)