Salome HOME
Avoid using special object library, because some problems on WIN32 platform .
[modules/paravis.git] / src / VTKWrapping / getwrapclasses.py
1 # Copyright (C) 2010-2013  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 try:
39     from vtkPVVTKExtensionsCorePython import *
40 except:
41     pass
42 try:
43     from vtkPVVTKExtensionsDefaultPython import *
44 except:
45     pass
46 try:
47     from vtkPVVTKExtensionsRenderingPython import *
48 except:
49     pass
50 try:
51     from vtkPVVTKExtensionsWebGLExporterPython import *
52 except:
53     pass
54
55 l1 = dir()
56 for a in l1:
57     if a.startswith("vtk") and (len(a) > 3):
58         classeslistsm.append(a)
59         
60 from paraview.vtk import *
61 l2 = dir()
62
63 for a in l2:
64     if (a not in l1) and a.startswith("vtk"):
65         classeslistvtk.append(a)
66
67 dic=dict()
68
69 non_wrap_list = ["vtkVariant", "vtkTimeStamp"]
70
71 pv_classes_new=classeslistsm
72 while len(pv_classes_new):
73     pv_classes_cur=pv_classes_new
74     pv_classes_new=[]
75     for c in pv_classes_cur:
76         ## ignore non wrappable classes
77         if c in non_wrap_list:
78             continue
79         filename=sys.argv[1]+"/"+c+".h"
80         if os.path.isfile(filename):
81             c_new=[]
82             f=open(filename)
83             for line in f:
84                 if re.match('\s*/',line) is None:
85                     if re.match('\s*public\s*:',line):
86                         continue
87
88                     m=re.match('\s*class\s+(vtk\w+)\s*;',line)
89                     if m is not None:
90                         cn=m.group(1)
91                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk and issubclass(globals()[cn], vtkObjectBase):
92                             pv_classes_new.append(cn)
93                             continue
94
95                     m=re.match('\s*struct\s+(vtk\w+)\s*;',line)
96                     if m is not None:
97                         cn=m.group(1)
98                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk and issubclass(globals()[cn], vtkObjectBase):
99                             pv_classes_new.append(cn)
100                             continue
101
102                     m=re.match('\s*#include\s+"(vtk\w+)\.h"',line)
103                     if m is not None:
104                         cn=m.group(1)
105                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk and issubclass(globals()[cn], vtkObjectBase):
106                             pv_classes_new.append(cn)
107                             continue
108
109                     cm=re.findall('public\s+(vtk\w+)',line)
110                     if len(cm) == 0:
111                         continue
112                     for cn in cm:
113                         ## do not extract Call Back classes
114                         if cn.count('vtkClassMemberCallback'):
115                             continue
116                         if cn not in dic.keys() and cn not in pv_classes_new:
117                             pv_classes_new.append(cn)
118                         if cn not in c_new:
119                             c_new.append(cn)
120             f.close()
121             dic[c]=[0, c_new]
122
123
124 pv_classes_sort=[]
125
126 def collect_dic(cc):
127     ret=[]
128     for c in cc:
129         if c not in dic.keys():
130             continue
131         if len(dic[c][1]) and dic[c][0] == 0:
132              ret+=collect_dic(dic[c][1])
133         if dic[c][0] == 0:
134             ret.append(c)
135             dic[c][0]=1
136     return ret
137
138 pv_classes_sort=collect_dic(dic.keys())
139
140 wf_str=""
141 if(os.path.exists('wrapfiles.txt')):
142     wf_txt=open('wrapfiles.txt','r')
143     strs=wf_txt.readlines()
144     wf_txt.close()
145     for s in strs:
146         wf_str+=s
147 str=""
148
149 for c in pv_classes_sort:
150     str+=c
151     for cc in dic[c][1]:
152         str+=' '+cc
153     str+='\n'
154
155 if(str!=wf_str):
156     wf_txt=open('wrapfiles.txt','w')
157     wf_txt.write(str)
158     wf_txt.close()