Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/paravis.git] / getwrapclasses.py
1 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import paraview, os, sys
21 import string
22 import re
23
24 classeslistsm = []
25 classeslistvtk = []
26
27 from vtkPVCommonPython import *
28 from vtkPVClientServerCoreCorePython import *
29 from vtkPVClientServerCoreDefaultPython import *
30 from vtkPVClientServerCoreRenderingPython import *
31 from vtkPVServerImplementationCorePython import *
32 from vtkPVServerImplementationDefaultPython import *
33 from vtkPVServerImplementationRenderingPython import *
34 from vtkPVServerManagerApplicationPython import *
35 from vtkPVServerManagerCorePython import *
36 from vtkPVServerManagerDefaultPython import *
37 from vtkPVServerManagerRenderingPython import *
38
39 l1 = dir()
40 for a in l1:
41     if a.startswith("vtk") and (len(a) > 3):
42         classeslistsm.append(a)
43         
44 from paraview.vtk import *
45 l2 = dir()
46
47 for a in l2:
48     if (a not in l1) and a.startswith("vtk"):
49         classeslistvtk.append(a)
50
51 dic=dict()
52
53 non_wrap_list = ["vtkVariant", "vtkTimeStamp"]
54
55 pv_classes_new=classeslistsm
56 while len(pv_classes_new):
57     pv_classes_cur=pv_classes_new
58     pv_classes_new=[]
59     for c in pv_classes_cur:
60         ## ignore non wrappable classes
61         if c in non_wrap_list:
62             continue
63         filename=sys.argv[1]+"/"+c+".h"
64         if os.path.isfile(filename):
65             c_new=[]
66             f=open(filename)
67             for line in f:
68                 if re.match('\s*/',line) is None:
69                     if re.match('\s*public\s*:',line):
70                         continue
71
72                     m=re.match('\s*class\s+(vtk\w+)\s*;',line)
73                     if m is not None:
74                         cn=m.group(1)
75                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk:
76                             pv_classes_new.append(cn)
77                             continue
78
79                     m=re.match('\s*struct\s+(vtk\w+)\s*;',line)
80                     if m is not None:
81                         cn=m.group(1)
82                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk:
83                             pv_classes_new.append(cn)
84                             continue
85
86                     m=re.match('\s*#include\s+"(vtk\w+)\.h"',line)
87                     if m is not None:
88                         cn=m.group(1)
89                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk:
90                             pv_classes_new.append(cn)
91                             continue
92
93                     cm=re.findall('public\s+(vtk\w+)',line)
94                     if len(cm) == 0:
95                         continue
96                     for cn in cm:
97                         ## do not extract Call Back classes
98                         if cn.count('vtkClassMemberCallback'):
99                             continue
100                         if cn not in dic.keys() and cn not in pv_classes_new:
101                             pv_classes_new.append(cn)
102                         if cn not in c_new:
103                             c_new.append(cn)
104             f.close()
105             dic[c]=[0, c_new]
106
107
108 pv_classes_sort=[]
109
110 def collect_dic(cc):
111     ret=[]
112     for c in cc:
113         if c not in dic.keys():
114             continue
115         if len(dic[c][1]) and dic[c][0] == 0:
116              ret+=collect_dic(dic[c][1])
117         if dic[c][0] == 0:
118             ret.append(c)
119             dic[c][0]=1
120     return ret
121
122 pv_classes_sort=collect_dic(dic.keys())
123
124 wf_str=""
125 if(os.path.exists('wrapfiles.txt')):
126     wf_txt=open('wrapfiles.txt','r')
127     strs=wf_txt.readlines()
128     wf_txt.close()
129     for s in strs:
130         wf_str+=s
131 str=""
132
133 for c in pv_classes_sort:
134     str+=c
135     for cc in dic[c][1]:
136         str+=' '+cc
137     str+='\n'
138
139 if(str!=wf_str):
140     wf_txt=open('wrapfiles.txt','w')
141     wf_txt.write(str)
142     wf_txt.close()