Salome HOME
Merge from V6_main_20120808 08Aug12
[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 vtkPVClientServerCorePython import *
28 from vtkPVServerImplementationPython import *
29 from vtkPVServerManagerPython import *
30 from vtkPVCommonPython import *
31
32 l1 = dir()
33 for a in l1:
34     if a.startswith("vtk") and (len(a) > 3):
35         classeslistsm.append(a)
36         
37 from paraview.vtk import *
38 l2 = dir()
39
40 for a in l2:
41     if (a not in l1) and a.startswith("vtk"):
42         classeslistvtk.append(a)
43
44 dic=dict()
45
46 non_wrap_list = ["vtkVariant", "vtkTimeStamp"]
47
48 pv_classes_new=classeslistsm
49 while len(pv_classes_new):
50     pv_classes_cur=pv_classes_new
51     pv_classes_new=[]
52     for c in pv_classes_cur:
53         ## ignore non wrappable classes
54         if c in non_wrap_list:
55             continue
56         filename=sys.argv[1]+"/"+c+".h"
57         if os.path.isfile(filename):
58             c_new=[]
59             f=open(filename)
60             for line in f:
61                 if re.match('\s*/',line) is None:
62                     if re.match('\s*public\s*:',line):
63                         continue
64
65                     m=re.match('\s*class\s+(vtk\w+)\s*;',line)
66                     if m is not None:
67                         cn=m.group(1)
68                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk:
69                             pv_classes_new.append(cn)
70                             continue
71
72                     m=re.match('\s*struct\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*#include\s+"(vtk\w+)\.h"',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                     cm=re.findall('public\s+(vtk\w+)',line)
87                     if len(cm) == 0:
88                         continue
89                     for cn in cm:
90                         ## do not extract Call Back classes
91                         if cn.count('vtkClassMemberCallback'):
92                             continue
93                         if cn not in dic.keys() and cn not in pv_classes_new:
94                             pv_classes_new.append(cn)
95                         if cn not in c_new:
96                             c_new.append(cn)
97             f.close()
98             dic[c]=[0, c_new]
99
100
101 pv_classes_sort=[]
102
103 def collect_dic(cc):
104     ret=[]
105     for c in cc:
106         if c not in dic.keys():
107             continue
108         if len(dic[c][1]) and dic[c][0] == 0:
109              ret+=collect_dic(dic[c][1])
110         if dic[c][0] == 0:
111             ret.append(c)
112             dic[c][0]=1
113     return ret
114
115 pv_classes_sort=collect_dic(dic.keys())
116
117 wf_str=""
118 if(os.path.exists('wrapfiles.txt')):
119     wf_txt=open('wrapfiles.txt','r')
120     strs=wf_txt.readlines()
121     wf_txt.close()
122     for s in strs:
123         wf_str+=s
124 str=""
125
126 for c in pv_classes_sort:
127     str+=c
128     for cc in dic[c][1]:
129         str+=' '+cc
130     str+='\n'
131
132 if(str!=wf_str):
133     wf_txt=open('wrapfiles.txt','w')
134     wf_txt.write(str)
135     wf_txt.close()