Back to index

salome-paravis  6.5.0
getwrapclasses.py
Go to the documentation of this file.
00001 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 import paraview, os, sys
00021 import string
00022 import re
00023 
00024 classeslistsm = []
00025 classeslistvtk = []
00026 
00027 from vtkPVClientServerCorePython import *
00028 from vtkPVServerImplementationPython import *
00029 from vtkPVServerManagerPython import *
00030 from vtkPVCommonPython import *
00031 
00032 l1 = dir()
00033 for a in l1:
00034     if a.startswith("vtk") and (len(a) > 3):
00035         classeslistsm.append(a)
00036         
00037 from paraview.vtk import *
00038 l2 = dir()
00039 
00040 for a in l2:
00041     if (a not in l1) and a.startswith("vtk"):
00042         classeslistvtk.append(a)
00043 
00044 dic=dict()
00045 
00046 non_wrap_list = ["vtkVariant", "vtkTimeStamp"]
00047 
00048 pv_classes_new=classeslistsm
00049 while len(pv_classes_new):
00050     pv_classes_cur=pv_classes_new
00051     pv_classes_new=[]
00052     for c in pv_classes_cur:
00053         ## ignore non wrappable classes
00054         if c in non_wrap_list:
00055             continue
00056         filename=sys.argv[1]+"/"+c+".h"
00057         if os.path.isfile(filename):
00058             c_new=[]
00059             f=open(filename)
00060             for line in f:
00061                 if re.match('\s*/',line) is None:
00062                     if re.match('\s*public\s*:',line):
00063                         continue
00064 
00065                     m=re.match('\s*class\s+(vtk\w+)\s*;',line)
00066                     if m is not None:
00067                         cn=m.group(1)
00068                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk:
00069                             pv_classes_new.append(cn)
00070                             continue
00071 
00072                     m=re.match('\s*struct\s+(vtk\w+)\s*;',line)
00073                     if m is not None:
00074                         cn=m.group(1)
00075                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk:
00076                             pv_classes_new.append(cn)
00077                             continue
00078 
00079                     m=re.match('\s*#include\s+"(vtk\w+)\.h"',line)
00080                     if m is not None:
00081                         cn=m.group(1)
00082                         if cn not in dic.keys() and cn not in pv_classes_new and cn in classeslistvtk:
00083                             pv_classes_new.append(cn)
00084                             continue
00085 
00086                     cm=re.findall('public\s+(vtk\w+)',line)
00087                     if len(cm) == 0:
00088                         continue
00089                     for cn in cm:
00090                         ## do not extract Call Back classes
00091                         if cn.count('vtkClassMemberCallback'):
00092                             continue
00093                         if cn not in dic.keys() and cn not in pv_classes_new:
00094                             pv_classes_new.append(cn)
00095                         if cn not in c_new:
00096                             c_new.append(cn)
00097             f.close()
00098             dic[c]=[0, c_new]
00099 
00100 
00101 pv_classes_sort=[]
00102 
00103 def collect_dic(cc):
00104     ret=[]
00105     for c in cc:
00106         if c not in dic.keys():
00107             continue
00108         if len(dic[c][1]) and dic[c][0] == 0:
00109              ret+=collect_dic(dic[c][1])
00110         if dic[c][0] == 0:
00111             ret.append(c)
00112             dic[c][0]=1
00113     return ret
00114 
00115 pv_classes_sort=collect_dic(dic.keys())
00116 
00117 wf_str=""
00118 if(os.path.exists('wrapfiles.txt')):
00119     wf_txt=open('wrapfiles.txt','r')
00120     strs=wf_txt.readlines()
00121     wf_txt.close()
00122     for s in strs:
00123         wf_str+=s
00124 str=""
00125 
00126 for c in pv_classes_sort:
00127     str+=c
00128     for cc in dic[c][1]:
00129         str+=' '+cc
00130     str+='\n'
00131 
00132 if(str!=wf_str):
00133     wf_txt=open('wrapfiles.txt','w')
00134     wf_txt.write(str)
00135     wf_txt.close()