Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 18 additions & 40 deletions src/generate_swig_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

##Copyright 2008-2011 Thomas Paviot (tpaviot@gmail.com)
##Copyright 2008-2013 Thomas Paviot (tpaviot@gmail.com)
##
##This file is part of pythonOCC.
##
Expand All @@ -20,8 +20,8 @@
import sys
import os
import glob
# add the ./src directory to the sys.path list
sys.path.append(os.path.join(os.getcwd(),'wrapper'))

sys.path.append(os.path.join(os.getcwd(), 'wrapper'))
import SWIG_generator
import Modules
import environment
Expand All @@ -37,80 +37,59 @@
MULTI_PROCESS_GENERATION = False
import time


def check_paths():
#
# Under WNT, modify Standard_Real.hxx so that it can be parsed by GCCXML without issue
# Under WNT, modify Standard_Real.hxx so that it can be parsed by
# GCCXML without issue
#
if sys.platform == 'win32':
standard_real_header = os.path.join(environment.OCC_INC,"Standard_Real.hxx")
standard_real_header = os.path.join(environment.OCC_INC, "Standard_Real.hxx")
if not os.path.isfile(standard_real_header):
print "%s not found."%standard_real_header
print "%s not found." % standard_real_header
sys.exit(0)
# else:
# import shutil
# fp = open(standard_real_header,"r")
# file_content = fp.read()
# fp.close()
# if not '__SWIG_GENERATION__' in file_content:#need rewriting
# key = raw_input("Original Standard_Real.hxx header file needs to be modified. Original file will be available with the name Standard_Real_Original.hxx.\nEnter 'y' or 'Y' if you whish to continue.'n' otherwise:")# first mode Standard_Real.hxx to Standard_Real_Original.hxx
# if key.lower()=='y':
# shutil.copy(standard_real_header, os.path.join(environment.OCC_INC,"Standard_Real_Original.hxx"))
# #replacing string
# file_content = file_content.replace("#if defined(WNT)","#if defined(WNT) && !defined(__SWIG_GENERATION__)")
# fp = open(standard_real_header,"w")
# fp.write(file_content)
# fp.close()
# else:
# sys.exit(0)
# else:
# print "Found modified Standard_Real.hxx header file."
#
# Remove all files from OCC folder
#
#files_to_remove = glob.glob(os.path.join(os.getcwd(),'OCC','*'))
#for file_to_remove in files_to_remove:
# os.remove(file_to_remove)
#
# Create paths
#
if not os.path.isdir(environment.SWIG_FILES_PATH_MODULAR):
os.mkdir(environment.SWIG_FILES_PATH_MODULAR)


def generate_SWIG_file_for_module(module):
''' For each module, create the siwg .i file to be processed
'''
if module in Modules.SALOME_GEOM_MODULES:
SWIG_generator.ModularBuilder(module,environment.SALOME_GEOM_INC)
SWIG_generator.ModularBuilder(module, environment.SALOME_GEOM_INC)
elif module in Modules.SALOME_SMESH_MODULES:
SWIG_generator.ModularBuilder(module,environment.SALOME_SMESH_INC)
SWIG_generator.ModularBuilder(module, environment.SALOME_SMESH_INC)
else:
SWIG_generator.ModularBuilder(module)


def generate_swig_multiprocess(module_list):
''' Generate swig files with parallel support
'''
#raw_input('Enter something')
init_time = time.time()
P = processing.Pool(nprocs)
P.map(generate_SWIG_file_for_module,module_list)
P.map(generate_SWIG_file_for_module, module_list)
final_time = time.time()
#print "%i exported classes"%SWIG_generator.nb_exported_classes
print final_time-init_time


def generate_swig_single_process(module_list):
''' Generate swig files in single process mode (multiprocessing not found)
'''
init_time = time.time()
for module in module_list:
generate_SWIG_file_for_module(module)
final_time = time.time()
print "%i exported classes"%SWIG_generator.nb_exported_classes
print "%i exported classes" % SWIG_generator.nb_exported_classes
print final_time-init_time

if __name__ == '__main__':
check_paths()
# Check if a module name is passed to the command line
if len(sys.argv)>1:
if len(sys.argv) > 1:
module_name_to_wrap = sys.argv[1]
if module_name_to_wrap == 'GEOM':
print "Generating swig files for the GEOM library"
Expand All @@ -126,14 +105,13 @@ def generate_swig_single_process(module_list):
modules_to_wrap = [module]
break
#print modules_to_wrap
if modules_to_wrap == None:
raise NameError,"Unknown module"
if modules_to_wrap is None:
raise NameError("Unknown module")
else:
if sys.platform == 'win32':
modules_to_wrap = Modules.COMMON_MODULES + Modules.WIN_MODULES
else:
modules_to_wrap = Modules.COMMON_MODULES + Modules.UNIX_MODULES

if MULTI_PROCESS_GENERATION:
print "Generating pythonOCC SWIG files (MultiProcess mode)."
generate_swig_multiprocess(modules_to_wrap)
Expand Down
67 changes: 35 additions & 32 deletions src/unittest/SMESH_wrapper_features_unittest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

##Copyright 2009-2011 Thomas Paviot (tpaviot@gmail.com)
##Copyright 2009-2013 Thomas Paviot (tpaviot@gmail.com)
##
##This file is part of pythonOCC.
##
Expand All @@ -18,56 +18,59 @@
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.

import unittest
import sys

from OCC.Standard import *
from OCC.Utils.Topology import *
from OCC.BRepPrimAPI import *
from OCC.BRepBuilderAPI import *
from OCC.gp import *
from OCC.StdMeshers import *
from OCC.SMESH import SMESH_Gen


class TestSMESHWrapperFeatures(unittest.TestCase):

def testSTLVectorInt(self):
'''
Checks the IntVector and DoubleVector classes that are used in the StdMeshers
module
Checks the IntVector and DoubleVector classes that are used
in the StdMeshers module
'''
# The IntVector must be initialized from a list/tuple of integers
i_v = IntVector([1,2,3,4])
self.assertEqual(i_v[0],1)
self.assertEqual(i_v[1],2)
self.assertEqual(i_v[2],3)
self.assertEqual(i_v[3],4)
# If at least one item of the list is not an integer, raise an exception
self.assertRaises(TypeError,IntVector,[1,2,3,4.0])

i_v = IntVector([1, 2, 3, 4])
self.assertEqual(i_v[0], 1)
self.assertEqual(i_v[1], 2)
self.assertEqual(i_v[2], 3)
self.assertEqual(i_v[3], 4)
# If at least one item of the list is not an integer,
# raise an exception
self.assertRaises(TypeError, IntVector, [1, 2, 3, 4.0])

def testSTLVectorDouble(self):
'''
Checks the IntVector and DoubleVector classes that are used in the StdMeshers
module
Checks the IntVector and DoubleVector classes that are
used in the StdMeshers module
'''
# The IntVector must be initialized from a list/tuple of floats/integers. Integers will
# be converted to floats
d_v = DoubleVector([0.1,0.2,0.6,0.7])
self.assertEqual(d_v[0],0.1)
self.assertEqual(d_v[1],0.2)
self.assertEqual(d_v[2],0.6)
self.assertEqual(d_v[3],0.7)
# If at least one item of the list is not an float or an integer, raise an exception
self.assertRaises(TypeError,DoubleVector,[1.0,2.0,3.0,"string"])
# Test one method of StdMeshers that takes/returns such a parameter type
from OCC.SMESH import SMESH_Gen
number_of_segments = StdMeshers_NumberOfSegments(1,10,SMESH_Gen())
# The IntVector must be initialized from a list/tuple of
# floats/integers. Integers will be converted into floats
d_v = DoubleVector([0.1, 0.2, 0.6, 0.7])
self.assertEqual(d_v[0], 0.1)
self.assertEqual(d_v[1], 0.2)
self.assertEqual(d_v[2], 0.6)
self.assertEqual(d_v[3], 0.7)
# If at least one item of the list is not an float or an integer,
# raise an exception
self.assertRaises(TypeError, DoubleVector, [1.0, 2.0, 3.0, "string"])
# Test one method of StdMeshers that takes/returns such
# a parameter type
number_of_segments = StdMeshers_NumberOfSegments(1, 10, SMESH_Gen())
number_of_segments.SetTableFunction(d_v)
self.assertEquals(number_of_segments.GetTableFunction(),(0.1,0.2,0.6,0.7))

self.assertEquals(number_of_segments.GetTableFunction(), (0.1, 0.2, 0.6, 0.7))


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSMESHWrapperFeatures))
return suite
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSMESHWrapperFeatures))
return suite

if __name__ == "__main__":
unittest.main()

Loading