From: mzn Date: Mon, 20 Aug 2018 13:05:36 +0000 (+0300) Subject: Porting to SALOME 9.1.0. X-Git-Tag: SHAPER_V9_1_0RC1~54 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a1baede8e41ab33d4d133cfa42f1fbafb50c8438;p=modules%2Fshaper.git Porting to SALOME 9.1.0. --- diff --git a/CMakeCommon/FindPython.cmake b/CMakeCommon/FindPython.cmake index e48b6c206..c38d22127 100644 --- a/CMakeCommon/FindPython.cmake +++ b/CMakeCommon/FindPython.cmake @@ -5,15 +5,15 @@ UNSET(PYTHON_LIBRARIES) IF(WIN32) IF(CMAKE_BUILD_TYPE STREQUAL "Debug") - SET(PYTHON_LIBRARY_FILE "python27_d.lib") + SET(PYTHON_LIBRARY_FILE "python36_d.lib") ElSE() - SET(PYTHON_LIBRARY_FILE "python27.lib") + SET(PYTHON_LIBRARY_FILE "python36.lib") ENDIF() ElSE() - SET(PYTHON_LIBRARY_FILE "libpython2.7.so") + SET(PYTHON_LIBRARY_FILE "libpython3.6.so") ENDIF() -IF($ENV{PYTHONHOME}) +IF(DEFINED ENV{PYTHONHOME}) IF(WIN32) FILE(TO_CMAKE_PATH "$ENV{PYTHONHOME}/libs/${PYTHON_LIBRARY_FILE}" PATH_PYTHON_LIBRARY) ElSE() @@ -22,12 +22,12 @@ IF($ENV{PYTHONHOME}) SET(PYTHON_LIBRARY ${PATH_PYTHON_LIBRARY} CACHE FILEPATH "path to the python library" FORCE) ENDIF() -IF($ENV{PYTHON_INCLUDE}) +IF(DEFINED ENV{PYTHON_INCLUDE}) FILE(TO_CMAKE_PATH $ENV{PYTHON_INCLUDE} PATH_PYTHON_INCLUDE_DIR) SET(PYTHON_INCLUDE_DIR ${PATH_PYTHON_INCLUDE_DIR} CACHE PATH "path to where Python.h is found" FORCE) ENDIF() -FIND_PACKAGE(PythonLibs REQUIRED) FIND_PACKAGE(PythonInterp REQUIRED) +FIND_PACKAGE(PythonLibs REQUIRED) -INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR}) \ No newline at end of file diff --git a/correction_auto_2.py b/correction_auto_2.py index ec3b240fc..477303a47 100644 --- a/correction_auto_2.py +++ b/correction_auto_2.py @@ -40,14 +40,14 @@ from utils import * ### whitespace/semicolon ### def extra_space_before_last_semicolon(ligne, previous_ligne = None, warning=None): - liste=ligne.split(u';\n') + liste=ligne.split(';\n') ligne2=liste[0] ligne3=ligne2.rstrip() - ligne=ligne3 + u';\n' + ligne=ligne3 + ';\n' return ligne, previous_ligne, False def missing_space_after_semicolon(ligne, previous_ligne = None, warning=None): - ligne=ligne.replace(u';',u'; ') + ligne=ligne.replace(';','; ') return ligne, previous_ligne, False ######################### @@ -55,86 +55,86 @@ def missing_space_after_semicolon(ligne, previous_ligne = None, warning=None): ### whitespace/operators ### def missing_space_around_operator_egal(ligne, previous_ligne = None, warning=None): - i=ligne.find(u'=') + i=ligne.find('=') nextchar=ligne[i+1] previouschar=ligne[i-1] if nextchar not in OPERATORS and previouschar not in OPERATORS: if nextchar.isspace() == False and previouschar.isspace()==True: - ligne=ligne.replace(u'=', u'= ') + ligne=ligne.replace('=', '= ') elif nextchar.isspace() == True and previouschar.isspace()==False: - ligne=ligne.replace(u'=', u' =') + ligne=ligne.replace('=', ' =') elif nextchar.isspace() == False and previouschar.isspace()==False: - ligne=ligne.replace(u'=', u' = ') + ligne=ligne.replace('=', ' = ') else: pass return ligne, previous_ligne, False def extra_space_for_operator_add(ligne, previous_ligne = None, warning=None): - while ligne.find(u'++ ') > -1: - ligne = ligne.replace(u'++ ',u'++') - while ligne.find(u' ++') > -1 and ligne.find(u'; ++') == -1: - ligne = ligne.replace(u' ++',u'++') + while ligne.find('++ ') > -1: + ligne = ligne.replace('++ ','++') + while ligne.find(' ++') > -1 and ligne.find('; ++') == -1: + ligne = ligne.replace(' ++','++') return ligne, previous_ligne, False def extra_space_for_operator_diff(ligne, previous_ligne = None, warning=None): - while ligne.find(u'! ') > -1: - ligne = ligne.replace(u'! ',u'!') + while ligne.find('! ') > -1: + ligne = ligne.replace('! ','!') return ligne, previous_ligne, False def missing_space_around_operator_double_chevron(ligne, previous_ligne = None, warning=None): - i=ligne.find(u'<<') + i=ligne.find('<<') nextchar=ligne[i+1] previouschar=ligne[i-1] if nextchar.isspace() == False and previouschar.isspace()==True: - ligne=ligne.replace(u'<<', u'<< ') + ligne=ligne.replace('<<', '<< ') elif nextchar.isspace() == True and previouschar.isspace()==False: - ligne=ligne.replace(u'<<', u' <<') + ligne=ligne.replace('<<', ' <<') elif nextchar.isspace() == False and previouschar.isspace()==False: - ligne=ligne.replace(u'<<', u' << ') + ligne=ligne.replace('<<', ' << ') else: pass return ligne, previous_ligne, False def missing_space_around_operator_simple_chevron(ligne, previous_ligne = None, warning=None): - i=ligne.find(u'<') + i=ligne.find('<') nextchar=ligne[i+1] previouschar=ligne[i-1] if nextchar not in OPERATORS and previouschar not in OPERATORS: if nextchar.isspace() == False and previouschar.isspace()==True: - ligne=ligne.replace(u'<', u'< ') + ligne=ligne.replace('<', '< ') elif nextchar.isspace() == True and previouschar.isspace()==False: - ligne=ligne.replace(u'<', u' <') + ligne=ligne.replace('<', ' <') elif nextchar.isspace() == False and previouschar.isspace()==False: - ligne=ligne.replace(u'<', u' < ') + ligne=ligne.replace('<', ' < ') else: pass return ligne, previous_ligne, False def missing_space_around_operator_diff_egal(ligne, previous_ligne = None, warning=None): - i=ligne.find(u'!=') + i=ligne.find('!=') nextchar=ligne[i+1] previouschar=ligne[i-1] if nextchar.isspace() == False and previouschar.isspace()==True: - ligne=ligne.replace(u'!=', u'!= ') + ligne=ligne.replace('!=', '!= ') elif nextchar.isspace() == True and previouschar.isspace()==False: - ligne=ligne.replace(u'!=', u' !=') + ligne=ligne.replace('!=', ' !=') elif nextchar.isspace() == False and previouschar.isspace()==False: - ligne=ligne.replace(u'!=', u' != ') + ligne=ligne.replace('!=', ' != ') else: pass return ligne, previous_ligne, False def missing_space_around_operator_double_egal(ligne, previous_ligne = None, warning=None): - i=ligne.find(u'==') + i=ligne.find('==') nextchar=ligne[i+1] previouschar=ligne[i-1] if nextchar.isspace() == False and previouschar.isspace()==True: - ligne=ligne.replace(u'==', u'== ') + ligne=ligne.replace('==', '== ') elif nextchar.isspace() == True and previouschar.isspace()==False: - ligne=ligne.replace(u'==', u' ==') + ligne=ligne.replace('==', ' ==') elif nextchar.isspace() == False and previouschar.isspace()==False: - ligne=ligne.replace(u'==', u' == ') + ligne=ligne.replace('==', ' == ') else: pass return ligne, previous_ligne, False @@ -145,16 +145,16 @@ def missing_space_around_operator_double_egal(ligne, previous_ligne = None, warn ### whitespace/comments ### def space_between_comments_and_code(ligne, previous_ligne = None, warning=None): - if ligne.find(u'//')>=0 : - ligne=ligne.replace(u'//', u' //') - elif ligne.find(u' //')>=0 : - ligne=ligne.replace(u' //', u' //') + if ligne.find('//')>=0 : + ligne=ligne.replace('//', ' //') + elif ligne.find(' //')>=0 : + ligne=ligne.replace(' //', ' //') else: pass return ligne, previous_ligne, False def space_between_comments_and_double_slash(ligne, previous_ligne = None, warning=None): - return ligne.replace(u'//', u'// '), previous_ligne, False + return ligne.replace('//', '// '), previous_ligne, False ######################### @@ -175,11 +175,11 @@ def ifndef_header(ficpath, ficline, warning): # replace_fic_ifndef(ficpath, ficline, warning, "no_guard_found") def endif_line(ligne, previous_ligne = None, warning=None): - liste1=warning.split(u'// ') + liste1=warning.split('// ') ligne1=liste1[1] - liste2=ligne1.split(u'"') + liste2=ligne1.split('"') header_guard=liste2[0] - ligne= u'#endif // ' + header_guard +u'\n' + ligne= '#endif // ' + header_guard +'\n' return ligne, previous_ligne, False ######################### @@ -196,7 +196,7 @@ def whitespace_end_of_line(ligne, previous_ligne = None, warning=None): ### whitespace/comma ### def missing_space_after_comma(ligne, previous_ligne = None, warning=None): - ligne=ligne.replace(u',',u', ') + ligne=ligne.replace(',',', ') return ligne, previous_ligne, False ######################### @@ -204,18 +204,18 @@ def missing_space_after_comma(ligne, previous_ligne = None, warning=None): ### readability/namespace ### def namespace_should_be_terminated(ligne, previous_ligne = None, warning=None): - ligne2=ligne.rstrip(u'\n') - liste = warning.split(u'"') + ligne2=ligne.rstrip('\n') + liste = warning.split('"') namespace=liste[1] - if ligne.find(u'\r')>=0: - ligne=ligne2+u' '+namespace+u'\r\n' + if ligne.find('\r')>=0: + ligne=ligne2+' '+namespace+'\r\n' else: - ligne=ligne2+u' '+namespace+u'\n' + ligne=ligne2+' '+namespace+'\n' return ligne, previous_ligne, False def anonymous_namespace_should_be_terminated(ligne, previous_ligne = None, warning=None): - ligne2=ligne.rstrip(u'\n') - ligne=ligne2+u' // namespace\n' + ligne2=ligne.rstrip('\n') + ligne=ligne2+' // namespace\n' return ligne, previous_ligne, False ######################### @@ -223,37 +223,37 @@ def anonymous_namespace_should_be_terminated(ligne, previous_ligne = None, warni ### whitespace/parens ### def extra_space_after_opening_paranthesis(ligne, previous_ligne = None, warning=None): - while ligne.find(u'( ') > -1: - ligne = ligne.replace(u'( ',u'(') + while ligne.find('( ') > -1: + ligne = ligne.replace('( ','(') return ligne, previous_ligne, False def extra_space_before_closing_paranthesis(ligne, previous_ligne = None, warning=None): - while ligne.find(u' )') > -1: - ligne = ligne.replace(u' )',u')') + while ligne.find(' )') > -1: + ligne = ligne.replace(' )',')') return ligne, previous_ligne, False def extra_space_before_opening_paranthesis_in_function_call(ligne, previous_ligne = None, warning=None): - while ligne.find(u' (') > -1 and ligne.find(u', (')==-1: - ligne = ligne.replace(u' (',u'(') + while ligne.find(' (') > -1 and ligne.find(', (')==-1: + ligne = ligne.replace(' (','(') return ligne, previous_ligne, False def missing_space_before_opening_parenthesis_in_for(ligne, previous_ligne = None, warning=None): - return ligne.replace(u'for(',u'for ('), previous_ligne, False + return ligne.replace('for(','for ('), previous_ligne, False def missing_space_before_opening_parenthesis_in_if(ligne, previous_ligne = None, warning=None): - return ligne.replace(u'if(',u'if ('), previous_ligne, False + return ligne.replace('if(','if ('), previous_ligne, False def missing_space_before_opening_parenthesis_in_switch(ligne, previous_ligne = None, warning=None): - return ligne.replace(u'switch(',u'switch ('), previous_ligne, False + return ligne.replace('switch(','switch ('), previous_ligne, False def missing_space_before_opening_parenthesis_in_while(ligne, previous_ligne = None, warning=None): - return ligne.replace(u'while(',u'while ('), previous_ligne, False + return ligne.replace('while(','while ('), previous_ligne, False def mismatching_spaces_inside_paranthesis(ligne, previous_ligne = None, warning=None): - while ligne.find(u'( ') > -1: - ligne = ligne.replace(u'( ',u'(') - while ligne.find(u' )') > -1: - ligne = ligne.replace(u' )',u')') + while ligne.find('( ') > -1: + ligne = ligne.replace('( ','(') + while ligne.find(' )') > -1: + ligne = ligne.replace(' )',')') return ligne, previous_ligne, False ######################### @@ -322,7 +322,7 @@ def use_spaces_instead_of_tab(ligne, previous_ligne = None, warning=None): ### readability/braces ### def no_semicolon_after_brace(ligne, previous_ligne = None, warning=None): - return ligne.replace(u'};',u'}'), previous_ligne, False + return ligne.replace('};','}'), previous_ligne, False def position_of_else(ligne, previous_ligne=None, warning=None): '''Remonte une ligne du type } else {''' @@ -347,21 +347,21 @@ def position_of_opening_brace(ligne, previous_ligne=None, warning=None): m = re.match("(\s*){(.*)", ligne) # On ne fait rien si on trouve un commentaire sur la ligne précédente (ce sera une correction manuelle) - if previous_ligne.find(u'//') == -1: + if previous_ligne.find('//') == -1: previous_ligne = previous_ligne.rstrip("\n") + ' {' + m.group(2) + '\n' ligne = '' else: - print "The previous line contains a comment, fixing has to be manual." + print("The previous line contains a comment, fixing has to be manual.") return ligne, previous_ligne, False def missing_space_before_opening_brace(ligne, previous_ligne = None, warning=None): m = re.match("(.+)(\S){(.*)", ligne) if(m): - print 'group_0', m.group(0) - print 'group_1', m.group(1) - print 'group_2', m.group(2) - print 'group_3', m.group(3) + print('group_0', m.group(0)) + print('group_1', m.group(1)) + print('group_2', m.group(2)) + print('group_3', m.group(3)) ligne = m.group(1) + m.group(2) + ' {' + m.group(3) + '\n' return ligne, previous_ligne, False @@ -373,10 +373,10 @@ def missing_space_before_opening_brace(ligne, previous_ligne = None, warning=Non def missing_space_before_else(ligne, previous_ligne = None, warning=None): m = re.match("(.+)(\S)else(.*)", ligne) if(m): - print 'group_0', m.group(0) - print 'group_1', m.group(1) - print 'group_2', m.group(2) - print 'group_3', m.group(3) + print('group_0', m.group(0)) + print('group_1', m.group(1)) + print('group_2', m.group(2)) + print('group_3', m.group(3)) ligne = m.group(1) + m.group(2) + ' else' + m.group(3) + '\n' return ligne, previous_ligne, False @@ -385,15 +385,15 @@ def missing_space_before_else(ligne, previous_ligne = None, warning=None): def make_const_reference(ficpath, ligne, previous_ligne = None, warning=None): """ Adding keyword 'const' """ - print "ficpath = ", ficpath - print "ligne = ", ligne - print "warning = ", warning + print("ficpath = ", ficpath) + print("ligne = ", ligne) + print("warning = ", warning) m = re.match("(.+)Is this a non-const reference\? If so, make const or use a pointer: (.+) (.+)", warning) if(m): - print 'group_0', m.group(0) - print 'group_1', m.group(1) - print 'group_2', m.group(2) - print 'group_3', m.group(3) + print('group_0', m.group(0)) + print('group_1', m.group(1)) + print('group_2', m.group(2)) + print('group_3', m.group(3)) arg_to_modify = m.group(2) ligne = ligne.replace(arg_to_modify, "const "+arg_to_modify) @@ -404,13 +404,13 @@ def make_const_reference(ficpath, ligne, previous_ligne = None, warning=None): global H_FILE_MAKE_CONST_REFERENCE_MODIFIED H_FILE_MAKE_CONST_REFERENCE_MODIFIED = True else: - print "ERROR : The following pattern was not found : 'Is this a non-const reference? If so, make const or use a pointer:'" + print("ERROR : The following pattern was not found : 'Is this a non-const reference? If so, make const or use a pointer:'") return ligne, previous_ligne, False def make_const_reference_cpp_file(ficpath, arg_to_modify): if not os.path.isfile(ficpath): - print "WARNING : The file ", ficpath, " doesn't exist, manual fixing is required in methods of the file ", ficpath.replace('.cpp', '.h'), " in which arguments have been declared 'const'" + print("WARNING : The file ", ficpath, " doesn't exist, manual fixing is required in methods of the file ", ficpath.replace('.cpp', '.h'), " in which arguments have been declared 'const'") return fic = open(get_src_path(ficpath),'r') @@ -436,12 +436,12 @@ def make_const_reference_cpp_file(ficpath, arg_to_modify): ### runtime/int ### def replace_short_by_int16(ligne, previous_ligne = None, warning=None): - ligne = ligne.replace(u'short', u'int16_t') + ligne = ligne.replace('short', 'int16_t') return ligne, None, False def replace_long_by_int64(ligne, previous_ligne = None, warning=None): - ligne = ligne.replace(u'long', u'int64_t') + ligne = ligne.replace('long', 'int64_t') return ligne, None, False @@ -452,10 +452,10 @@ def replace_long_by_int64(ligne, previous_ligne = None, warning=None): def make_constructor_explicit(ligne, previous_ligne = None, warning=None): m = re.match("(\s*)(.+)", ligne) if(m): - print 'group_0', m.group(0) - print 'group_1', m.group(1) - print 'group_2', m.group(2) - ligne = ligne.replace(m.group(2), u'explicit '+m.group(2)) + print('group_0', m.group(0)) + print('group_1', m.group(1)) + print('group_2', m.group(2)) + ligne = ligne.replace(m.group(2), 'explicit '+m.group(2)) return ligne, None, False @@ -470,9 +470,9 @@ def cpp_file_should_include_h_file(ficpath, ficline, warning): m = re.match("(.+) should include its header file (.+) (.+)", warning) if(m): - print 'group_0', m.group(0) - print 'group_1', m.group(1) - print 'group_2', m.group(2) + print('group_0', m.group(0)) + print('group_1', m.group(1)) + print('group_2', m.group(2)) # Nouveau chemin du fichier .h new_h_file_path = m.group(2) @@ -483,13 +483,13 @@ def cpp_file_should_include_h_file(ficpath, ficline, warning): for ligne in liste: m2 = re.match("#include.*"+h_file_name+".*", ligne) if(m2): - print "FOUND : ", ligne + print("FOUND : ", ligne) new_liste.append("#include \""+new_h_file_path+"\"\n") else: - print "NOT FOUND : ", ligne + print("NOT FOUND : ", ligne) new_liste.append(ligne) else: - print "ERROR : Pattern not found : \"should include its header file\"" + print("ERROR : Pattern not found : \"should include its header file\"") newliste=fic_writelines(new_liste) fichier = open(get_src_path(ficpath), "w") @@ -515,7 +515,7 @@ def do_not_leave_blank_line_after_public_protected_private(ficpath, ficline, war flag = True if flag and ligne.isspace(): # Supprimer les lignes vides après public:, protected: et :private - print "Deleting empty line" + print("Deleting empty line") new_liste.append("") continue if not ligne.isspace() and not re.match(".*public.*:|.*protected.*:|.*private.*:", ligne): @@ -538,7 +538,7 @@ def do_not_leave_blank_line_at_the_start_of_code_block(ficpath, ficline, warning flag = True if flag and ligne.isspace(): # Supprimer les lignes vides après un début de bloc - print "Deleting empty line" + print("Deleting empty line") new_liste.append("") continue if not ligne.isspace() and not re.match(".*{", ligne): @@ -599,8 +599,8 @@ def add_include_what_you_use(ficpath, ficline, warning): m = re.match("\s*Add (.+) for (.+)", warning) if(m): - print 'group_0', m.group(0) - print 'group_1', m.group(1) + print('group_0', m.group(0)) + print('group_1', m.group(1)) include = m.group(1) # Recherche la ligne dans laquelle ajouter le #include @@ -617,7 +617,7 @@ def add_include_what_you_use(ficpath, ficline, warning): num_ligne_include = max(num_ligne_include_system, num_ligne_include_local) if num_ligne_include == 0: - print "WARNING : #include not found in file ", ficpath + print("WARNING : #include not found in file ", ficpath) return new_liste = [] @@ -634,75 +634,75 @@ def add_include_what_you_use(ficpath, ficline, warning): fichier = open(get_src_path(ficpath), "w") fichier.writelines(newliste) else: - print "ERROR : Pattern of include_what_you_use not found" + print("ERROR : Pattern of include_what_you_use not found") return ################################## HOOKS_DICT = { - extra_space_before_last_semicolon:{'pattern':u'whitespace/semicolon', 'pattern_AND':u'Extra space before last semicolon'}, - missing_space_after_semicolon:{'pattern':u'whitespace/semicolon', 'pattern_AND':u'Missing space after'}, - missing_space_around_operator_egal:{'pattern':u'whitespace/operators', 'pattern_AND':u'Missing spaces around = '}, - extra_space_for_operator_add:{'pattern':u'whitespace/operators', 'pattern_AND':u'Extra space for operator ++'}, - extra_space_for_operator_diff:{'pattern':u'whitespace/operators', 'pattern_AND':u'Extra space for operator !'}, - missing_space_around_operator_double_chevron:{'pattern':u'whitespace/operators', 'pattern_AND':u'Missing spaces around << '}, - missing_space_around_operator_simple_chevron:{'pattern':u'whitespace/operators', 'pattern_AND':u'Missing spaces around < '}, - missing_space_around_operator_diff_egal:{'pattern':u'whitespace/operators', 'pattern_AND':u'Missing spaces around !='}, - missing_space_around_operator_double_egal:{'pattern':u'whitespace/operators', 'pattern_AND':u'Missing spaces around =='}, - space_between_comments_and_code:{'pattern':u'whitespace/comments', 'pattern_AND':u'At least two spaces is best between code and comments'}, - space_between_comments_and_double_slash:{'pattern':u'whitespace/comments', 'pattern_AND':u'Should have a space between // and comment '}, - legal_copyright:{'pattern':u'legal/copyright'}, # Script à n'executer qu'une fois - ifndef_header:{'pattern':u'build/header_guard', 'pattern_AND':u'#ifndef header guard has wrong style, please use'}, + extra_space_before_last_semicolon:{'pattern':'whitespace/semicolon', 'pattern_AND':'Extra space before last semicolon'}, + missing_space_after_semicolon:{'pattern':'whitespace/semicolon', 'pattern_AND':'Missing space after'}, + missing_space_around_operator_egal:{'pattern':'whitespace/operators', 'pattern_AND':'Missing spaces around = '}, + extra_space_for_operator_add:{'pattern':'whitespace/operators', 'pattern_AND':'Extra space for operator ++'}, + extra_space_for_operator_diff:{'pattern':'whitespace/operators', 'pattern_AND':'Extra space for operator !'}, + missing_space_around_operator_double_chevron:{'pattern':'whitespace/operators', 'pattern_AND':'Missing spaces around << '}, + missing_space_around_operator_simple_chevron:{'pattern':'whitespace/operators', 'pattern_AND':'Missing spaces around < '}, + missing_space_around_operator_diff_egal:{'pattern':'whitespace/operators', 'pattern_AND':'Missing spaces around !='}, + missing_space_around_operator_double_egal:{'pattern':'whitespace/operators', 'pattern_AND':'Missing spaces around =='}, + space_between_comments_and_code:{'pattern':'whitespace/comments', 'pattern_AND':'At least two spaces is best between code and comments'}, + space_between_comments_and_double_slash:{'pattern':'whitespace/comments', 'pattern_AND':'Should have a space between // and comment '}, + legal_copyright:{'pattern':'legal/copyright'}, # Script à n'executer qu'une fois + ifndef_header:{'pattern':'build/header_guard', 'pattern_AND':'#ifndef header guard has wrong style, please use'}, # no_ifndef_header:{'pattern':u'build/header_guard', 'pattern_AND':u'No #ifndef header guard found'}, - endif_line:{'pattern':u'build/header_guard', 'pattern_AND':u'#endif line should be'}, - whitespace_end_of_line:{'pattern':u'whitespace/end_of_line', 'pattern_AND':u'Line ends in whitespace'}, - missing_space_after_comma:{'pattern':u'whitespace/comma'}, - namespace_should_be_terminated:{'pattern':u'readability/namespace', 'pattern_AND':u'Namespace should be terminated with'}, - anonymous_namespace_should_be_terminated:{'pattern':u'readability/namespace', 'pattern_AND':u'Anonymous namespace should be terminated with'}, - extra_space_after_opening_paranthesis:{'pattern':u'whitespace/parens', 'pattern_AND':u'Extra space after ('}, - extra_space_before_closing_paranthesis:{'pattern':u'whitespace/parens', 'pattern_AND':u'Extra space before )'}, - extra_space_before_opening_paranthesis_in_function_call:{'pattern':u'whitespace/parens', 'pattern':u'Extra space before ( in function call'}, - missing_space_before_opening_parenthesis_in_for:{'pattern':u'whitespace/parens', 'pattern_AND':u'Missing space before ( in for('}, - missing_space_before_opening_parenthesis_in_if:{'pattern':u'whitespace/parens', 'pattern_AND':u'Missing space before ( in if('}, - missing_space_before_opening_parenthesis_in_switch:{'pattern':u'whitespace/parens', 'pattern_AND':u'Missing space before ( in switch('}, - missing_space_before_opening_parenthesis_in_while:{'pattern':u'whitespace/parens', 'pattern_AND':u'Missing space before ( in while('}, - mismatching_spaces_inside_paranthesis:{'pattern':u'whitespace/parens', 'pattern_AND':u'Mismatching spaces inside ()'}, - missing_space_before_public_protected_private:{'pattern':u'whitespace/indent', 'pattern_AND':u' should be indented +1 space inside class'}, + endif_line:{'pattern':'build/header_guard', 'pattern_AND':'#endif line should be'}, + whitespace_end_of_line:{'pattern':'whitespace/end_of_line', 'pattern_AND':'Line ends in whitespace'}, + missing_space_after_comma:{'pattern':'whitespace/comma'}, + namespace_should_be_terminated:{'pattern':'readability/namespace', 'pattern_AND':'Namespace should be terminated with'}, + anonymous_namespace_should_be_terminated:{'pattern':'readability/namespace', 'pattern_AND':'Anonymous namespace should be terminated with'}, + extra_space_after_opening_paranthesis:{'pattern':'whitespace/parens', 'pattern_AND':'Extra space after ('}, + extra_space_before_closing_paranthesis:{'pattern':'whitespace/parens', 'pattern_AND':'Extra space before )'}, + extra_space_before_opening_paranthesis_in_function_call:{'pattern':'whitespace/parens', 'pattern':'Extra space before ( in function call'}, + missing_space_before_opening_parenthesis_in_for:{'pattern':'whitespace/parens', 'pattern_AND':'Missing space before ( in for('}, + missing_space_before_opening_parenthesis_in_if:{'pattern':'whitespace/parens', 'pattern_AND':'Missing space before ( in if('}, + missing_space_before_opening_parenthesis_in_switch:{'pattern':'whitespace/parens', 'pattern_AND':'Missing space before ( in switch('}, + missing_space_before_opening_parenthesis_in_while:{'pattern':'whitespace/parens', 'pattern_AND':'Missing space before ( in while('}, + mismatching_spaces_inside_paranthesis:{'pattern':'whitespace/parens', 'pattern_AND':'Mismatching spaces inside ()'}, + missing_space_before_public_protected_private:{'pattern':'whitespace/indent', 'pattern_AND':' should be indented +1 space inside class'}, - wrong_number_of_spaces_while_indenting:{'pattern':u'whitespace/indent', 'pattern_AND':u'Weird number of spaces at line-start'}, + wrong_number_of_spaces_while_indenting:{'pattern':'whitespace/indent', 'pattern_AND':'Weird number of spaces at line-start'}, - no_newline_at_the_end_of_file:{'pattern':u'whitespace/ending_newline'}, + no_newline_at_the_end_of_file:{'pattern':'whitespace/ending_newline'}, - order_of_storage_class_specifier:{'pattern':u'build/storage_class'}, + order_of_storage_class_specifier:{'pattern':'build/storage_class'}, - use_spaces_instead_of_tab:{'pattern':u'whitespace/tab'}, + use_spaces_instead_of_tab:{'pattern':'whitespace/tab'}, - no_semicolon_after_brace:{'pattern':u'readability/braces', 'pattern_AND':u'You don\'t need a ; after a }'}, + no_semicolon_after_brace:{'pattern':'readability/braces', 'pattern_AND':'You don\'t need a ; after a }'}, # position_of_else:{'pattern':u'readability/braces', 'pattern_AND':u'If an else has a brace on one side'}, # else_should_be_previous_line:{'pattern':u'whitespace/newline', 'pattern_AND':u'An else should appear on the same line as the preceding'}, - position_of_opening_brace:{'pattern':u'whitespace/braces', 'pattern_AND':u'{ should almost always be at the end of the previous line'}, - missing_space_before_opening_brace:{'pattern':u'whitespace/braces', 'pattern_AND':u'Missing space before {'}, - missing_space_before_else:{'pattern':u'whitespace/braces', 'pattern_AND':u'Missing space before else'}, + position_of_opening_brace:{'pattern':'whitespace/braces', 'pattern_AND':'{ should almost always be at the end of the previous line'}, + missing_space_before_opening_brace:{'pattern':'whitespace/braces', 'pattern_AND':'Missing space before {'}, + missing_space_before_else:{'pattern':'whitespace/braces', 'pattern_AND':'Missing space before else'}, - make_const_reference:{'pattern':u'runtime/references', 'pattern_AND':u'Is this a non-const reference? If so, make const or use a pointer'}, + make_const_reference:{'pattern':'runtime/references', 'pattern_AND':'Is this a non-const reference? If so, make const or use a pointer'}, - make_constructor_explicit:{'pattern':u'runtime/explicit'}, + make_constructor_explicit:{'pattern':'runtime/explicit'}, - cpp_file_should_include_h_file:{'pattern':u'build/include', 'pattern_AND':u'should include its header file'}, - _h_file_already_included:{'pattern':u'build/include', 'pattern_AND':u'already included at'}, + cpp_file_should_include_h_file:{'pattern':'build/include', 'pattern_AND':'should include its header file'}, + _h_file_already_included:{'pattern':'build/include', 'pattern_AND':'already included at'}, - replace_short_by_int16:{'pattern':u'runtime/int', 'pattern_AND':u'Use int16/int64/etc, rather than the C type short'}, - replace_long_by_int64:{'pattern':u'runtime/int', 'pattern_AND':u'Use int16/int64/etc, rather than the C type long'}, + replace_short_by_int16:{'pattern':'runtime/int', 'pattern_AND':'Use int16/int64/etc, rather than the C type short'}, + replace_long_by_int64:{'pattern':'runtime/int', 'pattern_AND':'Use int16/int64/etc, rather than the C type long'}, - do_not_leave_blank_line_after_public_protected_private:{'pattern':u'whitespace/blank_line', 'pattern_AND':u'Do not leave a blank line after'}, - do_not_leave_blank_line_at_the_start_of_code_block:{'pattern':u'whitespace/blank_line', 'pattern_AND':u'Redundant blank line at the start of a code block should be deleted'}, - do_not_leave_blank_line_at_the_end_of_code_block:{'pattern':u'whitespace/blank_line', 'pattern_AND':u'Redundant blank line at the end of a code block should be deleted'}, - add_blank_line_before_public:{'pattern':u'whitespace/blank_line', 'pattern_AND':u'"public:" should be preceded by a blank line'}, - add_blank_line_before_protected:{'pattern':u'whitespace/blank_line', 'pattern_AND':u'"protected:" should be preceded by a blank line'}, - add_blank_line_before_private:{'pattern':u'whitespace/blank_line', 'pattern_AND':u'"private:" should be preceded by a blank line'}, + do_not_leave_blank_line_after_public_protected_private:{'pattern':'whitespace/blank_line', 'pattern_AND':'Do not leave a blank line after'}, + do_not_leave_blank_line_at_the_start_of_code_block:{'pattern':'whitespace/blank_line', 'pattern_AND':'Redundant blank line at the start of a code block should be deleted'}, + do_not_leave_blank_line_at_the_end_of_code_block:{'pattern':'whitespace/blank_line', 'pattern_AND':'Redundant blank line at the end of a code block should be deleted'}, + add_blank_line_before_public:{'pattern':'whitespace/blank_line', 'pattern_AND':'"public:" should be preceded by a blank line'}, + add_blank_line_before_protected:{'pattern':'whitespace/blank_line', 'pattern_AND':'"protected:" should be preceded by a blank line'}, + add_blank_line_before_private:{'pattern':'whitespace/blank_line', 'pattern_AND':'"private:" should be preceded by a blank line'}, - add_include_what_you_use:{'pattern':u'build/include_what_you_use'}, + add_include_what_you_use:{'pattern':'build/include_what_you_use'}, } @@ -716,14 +716,14 @@ def replace_line_no(path, nol, oldline, newline): Remplace, la ligne No nol du fichier path (relatif à SRCROOTDIR) par la chaîne newline (un unicode) oldline sert uniquement pour vérifier que tout est ok """ - print "replace_line_no : ", oldline, " by ", newline + print("replace_line_no : ", oldline, " by ", newline) # récupérer le contenu du fichier fic = open(get_src_path(path), "r") liste = fic.readlines() fic.close() # test de corruption if liste[nol-1].decode(ENCODING) != oldline : - raise Exception(u"Le fichier source %s semble être corrompu" %path) + raise Exception("Le fichier source %s semble être corrompu" %path) # remplacement de la ligne liste[nol-1] = newline.encode(ENCODING) # recréation du fichier corrigé @@ -740,8 +740,8 @@ def replace_fic_copyright(ficpath, warning=None): liste=fic_readlines(fic) fic.close() new_liste = [] - if liste[0].find(u'/ Copyright (C) 2014-20xx CEA/DEN, EDF R&D\n\n')== -1: - newliste=[u'// Copyright (C) 2014-20xx CEA/DEN, EDF R&D\n\n']+liste + if liste[0].find('/ Copyright (C) 2014-20xx CEA/DEN, EDF R&D\n\n')== -1: + newliste=['// Copyright (C) 2014-20xx CEA/DEN, EDF R&D\n\n']+liste newliste=fic_writelines(newliste) fic = open(get_src_path(ficpath), "w") fic.writelines(newliste) @@ -762,9 +762,9 @@ def replace_fic_ifndef(ficpath, ficline, warning, mode): m = re.match("(.*)ifndef header guard has wrong style, please use: (.+) (.+)", warning) if(m): - print 'group_0', m.group(0) - print 'group_1', m.group(1) - print 'group_2', m.group(2) + print('group_0', m.group(0)) + print('group_1', m.group(1)) + print('group_2', m.group(2)) # Header à changer header_guard=m.group(2) @@ -775,24 +775,24 @@ def replace_fic_ifndef(ficpath, ficline, warning, mode): for ligne in liste: i += 1 if i == ficline: - if ligne.find(u'#ifndef') >= 0: + if ligne.find('#ifndef') >= 0: new_liste.append("#ifndef "+header_guard+"\n") trouve = True else: - print "ERROR : Pattern #ifndef not found in line ", ficline + print("ERROR : Pattern #ifndef not found in line ", ficline) return else: if trouve == True: - if ligne.find(u'#define') >= 0: + if ligne.find('#define') >= 0: new_liste.append("#define "+header_guard+"\n") trouve = False else: - print "WARNING : Pattern #define not found in the line following the pattern #ifndef, we abandon." + print("WARNING : Pattern #define not found in the line following the pattern #ifndef, we abandon.") return else: new_liste.append(ligne) else: - print "ERROR : Pattern not found : \"#ifndef header guard has wrong style, please use\"" + print("ERROR : Pattern not found : \"#ifndef header guard has wrong style, please use\"") newliste=fic_writelines(new_liste) fichier = open(get_src_path(ficpath), "w") @@ -848,33 +848,33 @@ def main_routine(cpplint_output_file): previous_oldline = get_line_no(ficpath, ficline-1) else: previous_oldline = None - print "===\nNew warning:" - print "\tFile = "+ficpath - print "\tlast_ficpath_with_modified_nb_lines = "+last_ficpath_with_modified_nb_lines - print "\tNo ligne =" , ficline + print("===\nNew warning:") + print("\tFile = "+ficpath) + print("\tlast_ficpath_with_modified_nb_lines = "+last_ficpath_with_modified_nb_lines) + print("\tNo ligne =" , ficline) if VERBOSE_FLAG == "True": - print "\tWarning ='"+warning+"'" - print "\tOld text of current line = '"+oldline+"'" + print("\tWarning ='"+warning+"'") + print("\tOld text of current line = '"+oldline+"'") if previous_oldline: - print "\tOld text of previous line = '"+previous_oldline+"'" + print("\tOld text of previous line = '"+previous_oldline+"'") if ficpath == last_ficpath_with_modified_nb_lines: - print "File ", ficpath, "already modified. Waiting next cpplint run to process it." + print("File ", ficpath, "already modified. Waiting next cpplint run to process it.") continue hook = get_hook(warning, ficpath) - print "hook = ", hook + print("hook = ", hook) if hook is None: - print u"No hook found" + print("No hook found") continue if VERBOSE_FLAG == "True": - print "\t=> Processing with hook", hook + print("\t=> Processing with hook", hook) if hook in HOOKS_DELETING_OR_ADDING_LINES: last_ficpath_with_modified_nb_lines = ficpath if hook in HOOKS_PARSING_THE_WHOLE_FILE: hook(ficpath, ficline, warning) - print "Done" + print("Done") continue # Cas particulier pour le hook make_const_reference : il faut faire un traitement sur le fichier .cpp associé au fichier .h concerné par le hook @@ -890,31 +890,31 @@ def main_routine(cpplint_output_file): newline, previous_newline, huchk = hook(oldline, previous_oldline, warning) if VERBOSE_FLAG == "True": - print "\tNew text = '"+newline+"'" + print("\tNew text = '"+newline+"'") if huchk: if previous_newline: - print "Replace line : \n'%s'\n with line \n'%s'\n O/N ? :"%(previous_oldline, previous_newline) - reponse = raw_input() + print("Replace line : \n'%s'\n with line \n'%s'\n O/N ? :"%(previous_oldline, previous_newline)) + reponse = input() if reponse in ['O', 'o']: replace_line_no(ficpath, ficline-1, previous_oldline, previous_newline) - print "Replacement done." + print("Replacement done.") else : - print "Replacement aborted." + print("Replacement aborted.") - print "Replace line : \n'%s'\n with line \n'%s'\n O/N ? :"%(oldline, newline) - reponse = raw_input() + print("Replace line : \n'%s'\n with line \n'%s'\n O/N ? :"%(oldline, newline)) + reponse = input() if reponse in ['O', 'o']: replace_line_no(ficpath, ficline, oldline, newline) - print "Replacement done." + print("Replacement done.") else : - print "Replacement aborted." + print("Replacement aborted.") else : if previous_newline: replace_line_no(ficpath, ficline-1, previous_oldline, previous_newline) replace_line_no(ficpath, ficline, oldline, newline) - print "Done" + print("Done") logfile.close() if __name__ == '__main__': diff --git a/salome_pid.py b/salome_pid.py index 07ebf9f06..ca879e5a8 100755 --- a/salome_pid.py +++ b/salome_pid.py @@ -35,4 +35,4 @@ for list_item in process_ids: if process in name_list: pid = _pid -print pid +print(pid) diff --git a/src/BuildAPI/CMakeLists.txt b/src/BuildAPI/CMakeLists.txt index 0cc22fed3..4f1c32c70 100644 --- a/src/BuildAPI/CMakeLists.txt +++ b/src/BuildAPI/CMakeLists.txt @@ -96,7 +96,11 @@ SET(SWIG_MODULE_BuildAPI_EXTRA_DEPS ${SWIG_MODULE_BuildAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(BuildAPI python BuildAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(BuildAPI LANGUAGE python SOURCES BuildAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(BuildAPI python BuildAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(BuildAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/CollectionAPI/CMakeLists.txt b/src/CollectionAPI/CMakeLists.txt index 935c38bfb..62543034b 100644 --- a/src/CollectionAPI/CMakeLists.txt +++ b/src/CollectionAPI/CMakeLists.txt @@ -74,7 +74,11 @@ SET(SWIG_MODULE_CollectionAPI_EXTRA_DEPS ${SWIG_MODULE_CollectionAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(CollectionAPI python CollectionAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(CollectionAPI LANGUAGE python SOURCES CollectionAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(CollectionAPI python CollectionAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(CollectionAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/CollectionAPI/CollectionAPI.i b/src/CollectionAPI/CollectionAPI.i index 821bcd33c..26d54394e 100644 --- a/src/CollectionAPI/CollectionAPI.i +++ b/src/CollectionAPI/CollectionAPI.i @@ -39,7 +39,7 @@ #include "ModelHighAPI_swig.h" // fix for SWIG v2.0.4 - #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj)) + #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj)) %} %include "doxyhelp.i" diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index e120e21b8..05bafb324 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -76,7 +76,11 @@ SET(SWIG_LINK_LIBRARIES Config ${PYTHON_LIBRARIES} ) -SWIG_ADD_MODULE(ConfigAPI python ConfigAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ConfigAPI LANGUAGE python SOURCES ConfigAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ConfigAPI python ConfigAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ConfigAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) SET_TARGET_PROPERTIES(_ConfigAPI PROPERTIES DEBUG_OUTPUT_NAME _ConfigAPI_d) diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 452fc4ca3..4471234b4 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -211,7 +211,7 @@ void Config_ModuleReader::loadScript(const std::string& theFileName, bool theSen PyErr_Fetch(&ptype, &pvalue, &ptraceback); PyErr_NormalizeException(&ptype, &pvalue, &ptraceback); pstr = PyObject_Str(pvalue); - std::string aPyError = std::string(PyString_AsString(pstr)); + std::string aPyError = std::string(PyUnicode_AsUTF8(pstr)); if (!aPyError.empty()) { anErrorMsg += ":\n" + aPyError; } diff --git a/src/ConnectorAPI/CMakeLists.txt b/src/ConnectorAPI/CMakeLists.txt index 99f15351a..19d6e2bca 100644 --- a/src/ConnectorAPI/CMakeLists.txt +++ b/src/ConnectorAPI/CMakeLists.txt @@ -75,7 +75,11 @@ SET(SWIG_MODULE_ConnectorAPI_EXTRA_DEPS ${SWIG_MODULE_ConnectorAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(ConnectorAPI python ConnectorAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ConnectorAPI LANGUAGE python SOURCES ConnectorAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ConnectorAPI python ConnectorAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ConnectorAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/ConnectorAPI/Test/TestExportToGEOM.py b/src/ConnectorAPI/Test/TestExportToGEOM.py index 0403f1e9e..fd363f3c7 100644 --- a/src/ConnectorAPI/Test/TestExportToGEOM.py +++ b/src/ConnectorAPI/Test/TestExportToGEOM.py @@ -26,8 +26,8 @@ from salome.geom import geomBuilder import os import tempfile -salome.salome_init(0,1) -geompy = geomBuilder.New(salome.myStudy) +salome.salome_init(1) +geompy = geomBuilder.New() ## Get the last object published in the GEOM section of the object browser def getLastGEOMShape(): @@ -124,10 +124,10 @@ def testSeveralExportsToGEOM(): dumpShaper(dumpFileShaper) # Load SHAPER dump - execfile(dumpFileShaper) + exec(compile(open(dumpFileShaper).read(), dumpFileShaper, 'exec')) # Load GEOM dump - execfile(dumpFileGeom) + exec(compile(open(dumpFileGeom).read(), dumpFileGeom, 'exec')) # Clean files files = [dumpFileGeom, dumpFileShaper] @@ -139,4 +139,4 @@ def testSeveralExportsToGEOM(): if __name__ == '__main__': - testSeveralExportsToGEOM() \ No newline at end of file + testSeveralExportsToGEOM() diff --git a/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py b/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py index 49b09bc6f..130fb7090 100644 --- a/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py +++ b/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py @@ -31,7 +31,7 @@ theStudy = salome.myStudy from salome.shaper import model from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) +geompy = geomBuilder.New() ## Get the last object published in the GEOM section of the object browser def getLastGEOMShape(): @@ -185,10 +185,10 @@ def checkDump(): dumpShaper(dumpFileShaper) # Load SHAPER dump - execfile(dumpFileShaper) + exec(compile(open(dumpFileShaper).read(), dumpFileShaper, 'exec')) # Load GEOM dump - execfile(dumpFileGeom) + exec(compile(open(dumpFileGeom).read(), dumpFileGeom, 'exec')) # Clean files files = [dumpFileGeom, dumpFileShaper] diff --git a/src/ConnectorPlugin/ConnectorPlugin.py b/src/ConnectorPlugin/ConnectorPlugin.py index e91ca3152..78c1c65eb 100644 --- a/src/ConnectorPlugin/ConnectorPlugin.py +++ b/src/ConnectorPlugin/ConnectorPlugin.py @@ -39,7 +39,7 @@ class ConnectorPlugin(ModelAPI.ModelAPI_Plugin): if theFeatureID == ExportFeature.ID(): return ExportFeature().__disown__() else: - print "ConnectorPlugin: No such feature %s" % theFeatureID + print("ConnectorPlugin: No such feature %s" % theFeatureID) ## The plugin created on module importing (from c++) plugin = ConnectorPlugin() diff --git a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py index b529eac73..1fccfcef6 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py @@ -104,8 +104,8 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): ## List of objects created in the old geom for later use self.geomObjects = [] ## geomBuilder tool - salome.salome_init(0,1) - self.geompy = geomBuilder.New(salome.myStudy) + salome.salome_init(1) + self.geompy = geomBuilder.New() self.exportViaXAO() diff --git a/src/ConstructionAPI/CMakeLists.txt b/src/ConstructionAPI/CMakeLists.txt index 18830093d..88fd35809 100644 --- a/src/ConstructionAPI/CMakeLists.txt +++ b/src/ConstructionAPI/CMakeLists.txt @@ -79,7 +79,11 @@ SET(SWIG_MODULE_ConstructionAPI_EXTRA_DEPS ${SWIG_MODULE_ConstructionAPI_EXTRA_D ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(ConstructionAPI python ConstructionAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ConstructionAPI LANGUAGE python SOURCES ConstructionAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ConstructionAPI python ConstructionAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ConstructionAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/Events/CMakeLists.txt b/src/Events/CMakeLists.txt index 574e12f99..1dc931fd1 100644 --- a/src/Events/CMakeLists.txt +++ b/src/Events/CMakeLists.txt @@ -64,7 +64,11 @@ SET(SWIG_LINK_LIBRARIES ${PYTHON_LIBRARIES} ) -SWIG_ADD_MODULE(EventsAPI python Events.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(EventsAPI LANGUAGE python SOURCES Events.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(EventsAPI python Events.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(EventsAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/ExchangeAPI/CMakeLists.txt b/src/ExchangeAPI/CMakeLists.txt index 40e5d303a..e4ec3f065 100644 --- a/src/ExchangeAPI/CMakeLists.txt +++ b/src/ExchangeAPI/CMakeLists.txt @@ -76,7 +76,11 @@ SET(SWIG_MODULE_ExchangeAPI_EXTRA_DEPS ${SWIG_MODULE_ExchangeAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(ExchangeAPI python ExchangeAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ExchangeAPI LANGUAGE python SOURCES ExchangeAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ExchangeAPI python ExchangeAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ExchangeAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index 5d05d3f8d..91dcb6690 100644 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -84,23 +84,3 @@ ADD_UNIT_TESTS(TestImport.py Test2290.py Test2459.py TestExportToXAOWithGroupNotUpdated.py) - -SET(DATA_FILES - solid.brep - solid.brp - screw.step - screw.stp - bearing.iges - bearing.igs - Box_1.brep - test.xao - export_ref.xao -) - -FOREACH(file ${DATA_FILES}) - CONFIGURE_FILE( - ${CMAKE_CURRENT_SOURCE_DIR}/Test/Data/${file} - ${CMAKE_CURRENT_BINARY_DIR}/Data/${file} - COPYONLY) -ENDFOREACH(file ${DATA_FIELS}) - diff --git a/src/ExchangePlugin/Test/TestExport.py b/src/ExchangePlugin/Test/TestExport.py index 696a2b0c2..8a6f1e320 100644 --- a/src/ExchangePlugin/Test/TestExport.py +++ b/src/ExchangePlugin/Test/TestExport.py @@ -27,6 +27,7 @@ #========================================================================= import os import math +from tempfile import TemporaryDirectory from ModelAPI import * @@ -58,7 +59,8 @@ def testExport(theType, theFormat, theFile, theVolume, theDelta): aSession.startOperation("Import screw") anImportFeature = aPart.addFeature("Import") - anImportFeature.string("file_path").setValue("Data/screw.step") + aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "screw.step") + anImportFeature.string("file_path").setValue(aShapePath) aSession.finishOperation() removeFile(theFile) @@ -66,7 +68,7 @@ def testExport(theType, theFormat, theFile, theVolume, theDelta): aSession.startOperation("Export part") anExportFeature = aPart.addFeature("Export") anExportFeature.string("file_format").setValue(theFormat) - print "theFile=",theFile + print("theFile=",theFile) anExportFeature.string("file_path").setValue(theFile) anExportFeature.string("ExportType").setValue("Regular") aSelectionListAttr = anExportFeature.selectionList("selection_list") @@ -79,7 +81,7 @@ def testExport(theType, theFormat, theFile, theVolume, theDelta): # Test exported file by importing testImport(theType, theFile, theVolume, theDelta) -def testExportXAO(): +def testExportXAO(theFile): # Import a reference part aSession.startOperation("Add part") aPartFeature = aSession.moduleDocument().addFeature("Part") @@ -88,7 +90,8 @@ def testExportXAO(): aSession.startOperation("Import Box_1") anImportFeature = aPart.addFeature("Import") - anImportFeature.string("file_path").setValue("Data/Box_1.brep") + aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Brep", "box1.brep") + anImportFeature.string("file_path").setValue(aShapePath) aSession.finishOperation() # Create groups @@ -105,16 +108,16 @@ def testExportXAO(): aGroupFeature.data().setName("") aSelectionListAttr = aGroupFeature.selectionList("group_list") aSelectionListAttr.setSelectionType("face") - aSelectionListAttr.append("Box_1_1/Shape1") - aSelectionListAttr.append("Box_1_1/Shape2") + aSelectionListAttr.append("box1_1/Shape1") + aSelectionListAttr.append("box1_1/Shape2") aSession.finishOperation() aSession.startOperation("Create a field") aField = aSession.activeDocument().addFeature("Field") aSelectionListAttr = aField.selectionList("selected") aSelectionListAttr.setSelectionType("face") - aSelectionListAttr.append("Box_1_1/Shape1") - aSelectionListAttr.append("Box_1_1/Shape2") + aSelectionListAttr.append("box1_1/Shape1") + aSelectionListAttr.append("box1_1/Shape2") aComponentNames = aField.stringArray("components_names") aComponentNames.setSize(2) # two components aComponentNames.setValue(0, "temperatue") @@ -136,7 +139,7 @@ def testExportXAO(): # Export aSession.startOperation("Export to XAO") anExportFeature = aPart.addFeature("Export") - anExportFeature.string("xao_file_path").setValue("Data/export.xao") + anExportFeature.string("xao_file_path").setValue(theFile) anExportFeature.string("file_format").setValue("XAO") anExportFeature.string("ExportType").setValue("XAO") anExportFeature.string("xao_author").setValue("me") @@ -144,34 +147,36 @@ def testExportXAO(): aSession.finishOperation() # Check exported file + aRefPath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Xao", "box2.xao") import filecmp - assert filecmp.cmp("Data/export.xao", "Data/export_ref.xao") + assert filecmp.cmp(theFile, aRefPath) if __name__ == '__main__': -#========================================================================= -# Export a shape into BREP -#========================================================================= - aRealVolume = 3.78827401738e-06 - testExport("BREP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brep"), aRealVolume, 10 ** -17) - testExport("BRP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brp"), aRealVolume, 10 ** -17) -#========================================================================= -# Export a shape into STEP -#========================================================================= - testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.78825807533e-06, 10 ** -17) - testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.78825807533e-06, 10 ** -17) -#========================================================================= -# Export a shape into IGES -#========================================================================= - testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17) - testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17) - testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17) - testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17) -#========================================================================= -# Export a shape into XAO -#========================================================================= - testExportXAO() -#========================================================================= -# End of test -#========================================================================= - -assert(model.checkPythonDump()) + with TemporaryDirectory() as tmp_dir: + #========================================================================= + # Export a shape into BREP + #========================================================================= + aRealVolume = 3.78827401738e-06 + testExport("BREP", "BREP", os.path.join(tmp_dir, "screw_export.brep"), aRealVolume, 10 ** -17) + testExport("BRP", "BREP", os.path.join(tmp_dir, "screw_export.brp"), aRealVolume, 10 ** -17) + #========================================================================= + # Export a shape into STEP + #========================================================================= + testExport("STEP", "STEP", os.path.join(tmp_dir, "screw_export.step"), 3.78825807533e-06, 10 ** -17) + testExport("STP", "STEP", os.path.join(tmp_dir, "screw_export.stp"), 3.78825807533e-06, 10 ** -17) + #========================================================================= + # Export a shape into IGES + #========================================================================= + testExport("IGES-5.1", "IGES-5.1", os.path.join(tmp_dir, "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17) + testExport("IGS-5.1", "IGES-5.1", os.path.join(tmp_dir, "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17) + testExport("IGES-5.3", "IGES-5.3", os.path.join(tmp_dir, "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17) + testExport("IGS-5.3", "IGES-5.3", os.path.join(tmp_dir, "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17) + #========================================================================= + # Export a shape into XAO + #========================================================================= + testExportXAO(os.path.join(tmp_dir, "export.xao")) + #========================================================================= + # End of test + #========================================================================= + + assert(model.checkPythonDump()) diff --git a/src/ExchangePlugin/Test/TestImport.py b/src/ExchangePlugin/Test/TestImport.py index 8f95e8a23..0d42f9207 100644 --- a/src/ExchangePlugin/Test/TestImport.py +++ b/src/ExchangePlugin/Test/TestImport.py @@ -27,14 +27,23 @@ #========================================================================= from ModelAPI import * from GeomAlgoAPI import * + +import os import math +import shutil +from tempfile import TemporaryDirectory __updated__ = "2015-05-22" aSession = ModelAPI_Session.get() + #========================================================================= # Common test function #========================================================================= +def getShapePath(path): + shapes_dir = os.path.join(os.getenv("DATA_DIR"), "Shapes") + return os.path.join(shapes_dir, path) + def testImport(theType, theFile, theVolume, theDelta): # Create a part for import aSession.startOperation("Create part for import") @@ -74,7 +83,7 @@ def testImportXAO(): aSession.startOperation("Import XAO") anImportFeature = aPart.addFeature("Import") - anImportFeature.string("file_path").setValue("Data/test.xao") + anImportFeature.string("file_path").setValue(getShapePath("Xao/box1.xao")) aSession.finishOperation() # Check results @@ -104,7 +113,7 @@ def testImportXAO(): assert aSelectionList.selectionType() == "face" assert aSelectionList.size() == 2 assert aSelectionList.value(0).namingName("") == "mygeom_1/Shape1" - print aSelectionList.value(1).namingName("") + print(aSelectionList.value(1).namingName("")) assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2" aFeature3 = aCompositeFeature.subFeature(2, False) @@ -118,28 +127,37 @@ def testImportXAO(): assert aFeature3.selectionList("selected").size() == 1 if __name__ == '__main__': -#========================================================================= -# Create a shape imported from BREP -#========================================================================= - testImport("BREP", "Data/solid.brep", 259982.297176, 10 ** -5) - testImport("BRP", "Data/solid.brp", 259982.297176, 10 ** -5) -#========================================================================= -# Create a shape imported from STEP -#========================================================================= - testImport("STP", "Data/screw.stp", 3.78827401738e-06, 10 ** -17) - testImport("STEP", "Data/screw.step", 3.78827401738e-06, 10 ** -17) -#========================================================================= -# Create a shape imported from IGES -#========================================================================= - testImport("IGES", "Data/bearing.iges", 6.86970803067e-14, 10 ** -25) - testImport("IGS", "Data/bearing.igs", 6.86970803067e-14, 10 ** -25) -#========================================================================= -# Create a shape imported from XAO -#========================================================================= - testImportXAO() -#========================================================================= -# End of test -#========================================================================= - -from salome.shaper import model -assert(model.checkPythonDump()) + with TemporaryDirectory() as tmp_dir: + #========================================================================= + # Create a shape imported from BREP + #========================================================================= + shape_path = getShapePath("Brep/solid.brep") + testImport("BREP", shape_path, 259982.297176, 10 ** -5) + shape_path = shutil.copyfile(shape_path, os.path.join(tmp_dir, "solid.brp")) + testImport("BRP", shape_path, 259982.297176, 10 ** -5) + #========================================================================= + # Create a shape imported from STEP + #========================================================================= + shape_path = getShapePath("Step/screw.step") + testImport("STP", shape_path, 3.78827401738e-06, 10 ** -17) + shape_path = shutil.copyfile(shape_path, os.path.join(tmp_dir, "screw.stp")) + testImport("STEP", shape_path, 3.78827401738e-06, 10 ** -17) + #========================================================================= + # Create a shape imported from IGES + #========================================================================= + shape_path = getShapePath("Iges/bearing.igs") + testImport("IGES", shape_path, 6.86970803067e-14, 10 ** -25) + shape_path = shutil.copyfile(shape_path, os.path.join(tmp_dir, "bearing.iges")) + testImport("IGS", shape_path, 6.86970803067e-14, 10 ** -25) + + #========================================================================= + # Create a shape imported from XAO + #========================================================================= + testImportXAO() + + #========================================================================= + # End of test + #========================================================================= + + from salome.shaper import model + assert(model.checkPythonDump()) diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index b511fc640..b4ac9a4bb 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -118,7 +118,11 @@ SET(SWIG_MODULE_FeaturesAPI_EXTRA_DEPS ${SWIG_MODULE_FeaturesAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(FeaturesAPI python FeaturesAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(FeaturesAPI LANGUAGE python SOURCES FeaturesAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(FeaturesAPI python FeaturesAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(FeaturesAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/FeaturesPlugin/Test/TestMultiBoolean.py b/src/FeaturesPlugin/Test/TestMultiBoolean.py index d332d786f..c65d2c4bc 100644 --- a/src/FeaturesPlugin/Test/TestMultiBoolean.py +++ b/src/FeaturesPlugin/Test/TestMultiBoolean.py @@ -67,8 +67,8 @@ radius = 95. / N / 2. aSession.startOperation() aSketchFeatures = [] -for i in xrange(0, N): - for j in xrange(0, N): +for i in range(0, N): + for j in range(0, N): # Create circle aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) @@ -95,7 +95,7 @@ aSession.finishOperation() aSession.startOperation() anExtrusions = [] -for i in xrange(0, N * N): +for i in range(0, N * N): aSketchResult = aSketchFeatures[i].firstResult() aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape() origin = geomDataAPI_Point(aSketchFeatures[i].attribute("Origin")).pnt() @@ -196,7 +196,7 @@ aSession.startOperation() aBooleanFt = aPart.addFeature("Cut") aBooleanFt.selectionList("main_objects").append(aCurrentResult, aCurrentResult.shape()) -for i in xrange(0, N * N): +for i in range(0, N * N): anExtrusionResult = modelAPI_ResultBody(anExtrusions[i].firstResult()) aBooleanFt.selectionList("tool_objects").append(anExtrusionResult, anExtrusionResult.shape()) aBooleanFt.execute() diff --git a/src/FeaturesPlugin/Test/TestSerialBoolean.py b/src/FeaturesPlugin/Test/TestSerialBoolean.py index 08f4887d0..ddbde4793 100644 --- a/src/FeaturesPlugin/Test/TestSerialBoolean.py +++ b/src/FeaturesPlugin/Test/TestSerialBoolean.py @@ -67,8 +67,8 @@ radius = 95. / N / 2. aSession.startOperation() aSketchFeatures = [] -for i in xrange(0, N): - for j in xrange(0, N): +for i in range(0, N): + for j in range(0, N): # Create circle aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) @@ -95,7 +95,7 @@ aSession.finishOperation() aSession.startOperation() anExtrusions = [] -for i in xrange(0, N * N): +for i in range(0, N * N): aSketchResult = aSketchFeatures[i].firstResult() aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape() origin = geomDataAPI_Point(aSketchFeatures[i].attribute("Origin")).pnt() @@ -195,7 +195,7 @@ aSession.finishOperation() aCurrentResult = modelAPI_ResultBody(aBox.firstResult()) aSession.startOperation() aFactory = ModelAPI_Session.get().validators() -for i in xrange(0, N * N): +for i in range(0, N * N): anExtrusionResult = modelAPI_ResultBody(anExtrusions[i].firstResult()) aBooleanFt = aPart.addFeature("Cut") aBooleanFt.selectionList("main_objects").append(aCurrentResult, aCurrentResult.shape()) diff --git a/src/GDMLAPI/CMakeLists.txt b/src/GDMLAPI/CMakeLists.txt index 6654525fa..701d3570d 100644 --- a/src/GDMLAPI/CMakeLists.txt +++ b/src/GDMLAPI/CMakeLists.txt @@ -74,7 +74,11 @@ SET(SWIG_MODULE_GDMLAPI_EXTRA_DEPS ${SWIG_MODULE_GDMLAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(GDMLAPI python GDMLAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(GDMLAPI LANGUAGE python SOURCES GDMLAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(GDMLAPI python GDMLAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(GDMLAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index d441758f8..889e8344c 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -146,7 +146,11 @@ SET(SWIG_LINK_LIBRARIES ${PYTHON_LIBRARIES} ) -SWIG_ADD_MODULE(GeomAPI python GeomAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(GeomAPI LANGUAGE python SOURCES GeomAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(GeomAPI python GeomAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(GeomAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index 89e39adfe..270118fcd 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -97,9 +97,9 @@ bool GeomAPI_Face::isEqual(std::shared_ptr theFace) const return false; Handle(IntTools_Context) aContext = new IntTools_Context(); - // Double check needed bacause BOPTools_AlgoTools::CheckSameGeom not very smart. - Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext) - && BOPTools_AlgoTools::CheckSameGeom(aInFace, aMyFace, aContext); + // Double check needed because BOPTools_AlgoTools::AreFacesSameDomain not very smart. + Standard_Boolean aRes = BOPTools_AlgoTools::AreFacesSameDomain(aMyFace, aInFace, aContext) + && BOPTools_AlgoTools::AreFacesSameDomain(aInFace, aMyFace, aContext); return aRes == Standard_True; } diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index f24b06d69..956eb9cd2 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -189,7 +189,11 @@ SET(SWIG_LINK_LIBRARIES ${PYTHON_LIBRARIES} ) -SWIG_ADD_MODULE(GeomAlgoAPI python GeomAlgoAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(GeomAlgoAPI LANGUAGE python SOURCES GeomAlgoAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(GeomAlgoAPI python GeomAlgoAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(GeomAlgoAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/GeomDataAPI/CMakeLists.txt b/src/GeomDataAPI/CMakeLists.txt index 90e0654b5..f22839d32 100644 --- a/src/GeomDataAPI/CMakeLists.txt +++ b/src/GeomDataAPI/CMakeLists.txt @@ -64,7 +64,11 @@ SET(SWIG_LINK_LIBRARIES ${PYTHON_LIBRARIES} ) -SWIG_ADD_MODULE(GeomDataAPI python GeomDataAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(GeomDataAPI LANGUAGE python SOURCES GeomDataAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(GeomDataAPI python GeomDataAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(GeomDataAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp b/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp index de159cffc..b7d591b29 100644 --- a/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp +++ b/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp @@ -68,8 +68,8 @@ InitializationPlugin_PyInterp::positions(const std::string& theExpression, std::string anExpression = adjustExpression(theExpression); // extend aContext with variables - PyDict_SetItemString(aContext, "expression", PyString_FromString(anExpression.c_str())); - PyDict_SetItemString(aContext, "name", PyString_FromString(theName.c_str())); + PyDict_SetItemString(aContext, "expression", PyUnicode_FromString(anExpression.c_str())); + PyDict_SetItemString(aContext, "name", PyUnicode_FromString(theName.c_str())); PyDict_SetItemString(aContext, "positions", Py_BuildValue("[]")); // run the search code @@ -84,8 +84,8 @@ InitializationPlugin_PyInterp::positions(const std::string& theExpression, PyObject* aColOffset = PyTuple_GetItem(aPosition, 1); aResult.push_back( - std::pair((int)PyInt_AsLong(aLineNo), - (int)PyInt_AsLong(aColOffset))); + std::pair((int)PyLong_AsLong(aLineNo), + (int)PyLong_AsLong(aColOffset))); } // TODO(spo): after this refCount of the variable is not 0. Is there memory leak? @@ -117,17 +117,18 @@ std::list InitializationPlugin_PyInterp::compile(const std::string& } PyCodeObject* aCodeObj = (PyCodeObject*) aCodePyObj; - std::string aCodeName(PyString_AsString(aCodeObj->co_code)); + std::string aCodeName(PyBytes_AsString(aCodeObj->co_code)); // co_names should be tuple, but can be changed in modern versions of python (>2.7.3) - if(!PyTuple_Check(aCodeObj->co_names)) + if(!PyTuple_Check(aCodeObj->co_names)) { return aResult; + } size_t params_size = PyTuple_Size(aCodeObj->co_names); if (params_size > 0) { for (size_t i = 0; i < params_size; i++) { PyObject* aParamObj = PyTuple_GetItem(aCodeObj->co_names, i); PyObject* aParamObjStr = PyObject_Str(aParamObj); - std::string aParamName(PyString_AsString(aParamObjStr)); + std::string aParamName(PyUnicode_AsUTF8(aParamObjStr)); aResult.push_back(aParamName); Py_XDECREF(aParamObjStr); } @@ -171,7 +172,7 @@ double InitializationPlugin_PyInterp::evaluate(const std::string& theExpression, return 0.; } - PyObject* anEvalResult = PyEval_EvalCode(anExprCode, _global_context, _local_context); + PyObject* anEvalResult = PyEval_EvalCode((PyObject *)anExprCode, _global_context, _local_context); if(!anEvalResult) { theError = errorMessage(); Py_XDECREF(anExprCode); @@ -180,7 +181,7 @@ double InitializationPlugin_PyInterp::evaluate(const std::string& theExpression, } PyObject* anEvalStrObj = PyObject_Str(anEvalResult); - std::string anEvalStr(PyString_AsString(anEvalStrObj)); + std::string anEvalStr(PyUnicode_AsUTF8(anEvalStrObj)); Py_XDECREF(anExprCode); Py_XDECREF(anEvalResult); Py_XDECREF(anEvalStrObj); @@ -207,7 +208,7 @@ std::string InitializationPlugin_PyInterp::errorMessage() PyErr_Fetch(&ptype, &pvalue, &ptraceback); PyErr_NormalizeException(&ptype, &pvalue, &ptraceback); pstr = PyObject_Str(pvalue); - aPyError = std::string(PyString_AsString(pstr)); + aPyError = std::string(PyUnicode_AsUTF8(pstr)); Py_XDECREF(pstr); Py_XDECREF(ptype); Py_XDECREF(pvalue); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 16fb0c518..2c828ff96 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -144,7 +144,11 @@ SET(SWIG_LINK_LIBRARIES ${PYTHON_LIBRARIES} ) -SWIG_ADD_MODULE(ModelAPI python ModelAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ModelAPI LANGUAGE python SOURCES ModelAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ModelAPI python ModelAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ModelAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 6199cb72a..3285881c9 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -93,22 +93,22 @@ %shared_ptr(ModelAPI_ResultCompSolid) %typecheck(SWIG_TYPECHECK_POINTER) const ModelAPI_AttributeTables::Value { - $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input) || PyBool_Check($input)) ? 1 : 0; + $1 = (PyFloat_Check($input) || PyLong_Check($input) || PyUnicode_Check($input) || PyBool_Check($input)) ? 1 : 0; } // Tables Value reading as int, double, boolean or string %typemap(in) const ModelAPI_AttributeTables::Value { - if (PyInt_Check($input)) { - $1.myInt = int(PyInt_AsLong($input)); - $1.myDouble = double(PyInt_AsLong($input)); - $1.myBool = PyInt_AsLong($input) != 0; + if (PyLong_Check($input)) { + $1.myInt = int(PyLong_AsLong($input)); + $1.myDouble = double(PyLong_AsLong($input)); + $1.myBool = PyLong_AsLong($input) != 0; } else if (PyFloat_Check($input)) { $1.myInt = int(PyFloat_AsDouble($input)); $1.myDouble = PyFloat_AsDouble($input); } else if (PyBool_Check($input)) { $1.myBool = $input == Py_True; - } else if (PyString_Check($input)) { - $1.myStr = PyString_AsString($input); + } else if (PyUnicode_Check($input)) { + $1.myStr = PyUnicode_AsUTF8($input); } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { } else { PyErr_SetString(PyExc_ValueError, "Tables value must be int, double, string or bool."); diff --git a/src/ModelAPI/Test/TestCustomName_CutGroup.py b/src/ModelAPI/Test/TestCustomName_CutGroup.py index 211275e52..ca2ac6c92 100644 --- a/src/ModelAPI/Test/TestCustomName_CutGroup.py +++ b/src/ModelAPI/Test/TestCustomName_CutGroup.py @@ -94,7 +94,7 @@ model.do() Extrusions = [Extrusion_1, Extrusion_2, Extrusion_3] BooleanResults = Boolean_1.results() -for i in xrange(len(BooleanResults)): +for i in range(len(BooleanResults)): assert(BooleanResults[i].name() == Extrusions[i].result().name()), "Name of result {} of Boolean CUT '{}' != '{}'".format(i, BooleanResults[i].name(), Extrusions[i].result().name()) BooleanName = Boolean_1.name() + "_" + str(i + 1) for sub in range(0, BooleanResults[i].numberOfSubs()): diff --git a/src/ModelGeomAlgo/CMakeLists.txt b/src/ModelGeomAlgo/CMakeLists.txt index b6cdf135b..58e55ff58 100755 --- a/src/ModelGeomAlgo/CMakeLists.txt +++ b/src/ModelGeomAlgo/CMakeLists.txt @@ -74,7 +74,11 @@ SET(SWIG_LINK_LIBRARIES ${PYTHON_LIBRARIES} ) -SWIG_ADD_MODULE(ModelGeomAlgo python ModelGeomAlgo.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ModelGeomAlgo LANGUAGE python SOURCES ModelGeomAlgo.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ModelGeomAlgo python ModelGeomAlgo.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ModelGeomAlgo ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index 9c0ce38a1..db374645c 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -93,7 +93,11 @@ set(SWIG_MODULE_ModelHighAPI_EXTRA_DEPS ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(ModelHighAPI python ModelHighAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ModelHighAPI LANGUAGE python SOURCES ModelHighAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ModelHighAPI python ModelHighAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ModelHighAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 0b49cf05c..2d4b6a8c8 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -32,7 +32,7 @@ #include "ModelHighAPI_swig.h" // fix for SWIG v2.0.4 - #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj)) + #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj)) %} %include "doxyhelp.i" @@ -62,11 +62,11 @@ // typemaps %typemap(in) const ModelHighAPI_Double & (ModelHighAPI_Double temp) { - if (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) { + if (PyFloat_Check($input) || PyLong_Check($input)) { temp = ModelHighAPI_Double(PyFloat_AsDouble($input)); $1 = &temp; - } else if (PyString_Check($input)) { - temp = ModelHighAPI_Double(PyString_AsString($input)); + } else if (PyUnicode_Check($input)) { + temp = ModelHighAPI_Double(PyUnicode_AsUTF8($input)); $1 = &temp; } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { } else { @@ -75,15 +75,15 @@ } } %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Double, const ModelHighAPI_Double & { - $1 = ((PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input)) && !PyBool_Check($input)) ? 1 : 0; + $1 = ((PyFloat_Check($input) || PyLong_Check($input) || PyUnicode_Check($input)) && !PyBool_Check($input)) ? 1 : 0; } %typemap(in) const ModelHighAPI_Integer & (ModelHighAPI_Integer temp) { - if (PyInt_Check($input)) { - temp = ModelHighAPI_Integer(static_cast(PyInt_AsLong($input))); + if (PyLong_Check($input)) { + temp = ModelHighAPI_Integer(static_cast(PyLong_AsLong($input))); $1 = &temp; - } else if (PyString_Check($input)) { - temp = ModelHighAPI_Integer(PyString_AsString($input)); + } else if (PyUnicode_Check($input)) { + temp = ModelHighAPI_Integer(PyUnicode_AsUTF8($input)); $1 = &temp; } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { } else { @@ -92,7 +92,7 @@ } } %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Integer, const ModelHighAPI_Integer & { - $1 = ((PyInt_Check($input) || PyString_Check($input)) && !PyBool_Check($input)) ? 1 : 0; + $1 = ((PyLong_Check($input) || PyUnicode_Check($input)) && !PyBool_Check($input)) ? 1 : 0; } %typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) { diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index b7b5f1dab..70995d6a7 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -435,7 +435,7 @@ bool checkPythonDump() return false; // something is wrong during dump } - // map from document name to feature name to feature data + // map from document name to feature name to feature data std::map > aStore; std::string anError = storeFeatures( aSession->moduleDocument()->kind(), aSession->moduleDocument(), aStore, false); @@ -444,14 +444,16 @@ bool checkPythonDump() anErrorMsg.send(); return false; } + // close all before importation of the script aSession->closeAll(); + // execute the dumped PyGILState_STATE gstate = PyGILState_Ensure(); /* acquire python thread */ static char aDumpName[] = "./check_dump.py"; static char aReadMode[] = "r"; - PyObject* PyFileObject = PyFile_FromString(aDumpName, aReadMode); - PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), aDumpName, 1); + FILE* aFile = _Py_fopen(aDumpName, aReadMode); + PyRun_SimpleFileEx(aFile, aDumpName, 1); PyGILState_Release(gstate); /* release python thread */ // compare with the stored data diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index cf141d592..035d6c52a 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -371,9 +371,12 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a AIS_Shape::ComputeSelection(aSelection, theMode); if (myAdditionalSelectionPriority > 0) { - for (aSelection->Init(); aSelection->More(); aSelection->Next()) { - Handle(SelectBasics_EntityOwner) aBasicsOwner = - aSelection->Sensitive()->BaseSensitive()->OwnerId(); + NCollection_Vector anEntities = aSelection->Entities(); + for (NCollection_Vector::Iterator anIt(anEntities); + anIt.More(); + anIt.Next()) { + Handle(SelectMgr_SensitiveEntity) anEntity = anIt.Value(); + Handle(SelectBasics_EntityOwner) aBasicsOwner = anEntity->BaseSensitive()->OwnerId(); if (!aBasicsOwner.IsNull()) aBasicsOwner->Set(aBasicsOwner->Priority() + myAdditionalSelectionPriority); } @@ -397,12 +400,18 @@ bool ModuleBase_ResultPrs::appendVertexSelection(const Handle(SelectMgr_Selectio StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection, aDeflection, myDrawer->HLRAngle(), 9, 500); - for (aSelection->Init(); aSelection->More(); aSelection->Next()) { + + NCollection_Vector anEntities = aSelection->Entities(); + for (NCollection_Vector::Iterator anIt(anEntities); + anIt.More(); + anIt.Next()) { + Handle(SelectMgr_SensitiveEntity) anEntity = anIt.Value(); Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner) - ::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId()); + ::DownCast(anEntity->BaseSensitive()->OwnerId()); anOwner->Set(this); } + return true; } return false; diff --git a/src/ParametersAPI/CMakeLists.txt b/src/ParametersAPI/CMakeLists.txt index bad153b70..08e513cc5 100644 --- a/src/ParametersAPI/CMakeLists.txt +++ b/src/ParametersAPI/CMakeLists.txt @@ -75,7 +75,11 @@ SET(SWIG_MODULE_ParametersAPI_EXTRA_DEPS ${SWIG_MODULE_ParametersAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(ParametersAPI python ParametersAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(ParametersAPI LANGUAGE python SOURCES ParametersAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(ParametersAPI python ParametersAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(ParametersAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/ParametersPlugin/Test/TestParameterCreation.py b/src/ParametersPlugin/Test/TestParameterCreation.py index 0c98f7a80..3e5b38c1f 100644 --- a/src/ParametersPlugin/Test/TestParameterCreation.py +++ b/src/ParametersPlugin/Test/TestParameterCreation.py @@ -89,7 +89,7 @@ for name, expr in zip(ltNames, ltExpressions): assert(aResultAttr.data()) assert(aResultAttr.data().real("Value")) aResultValue = aResultAttr.data().real("Value").value() - print aResultValue, " == ", float(expr) + print(aResultValue, " == ", float(expr)) assert(aResultValue == float(expr)) # Check referencing between parameters diff --git a/src/PartSetAPI/CMakeLists.txt b/src/PartSetAPI/CMakeLists.txt index 265571df5..4b2e45c7c 100644 --- a/src/PartSetAPI/CMakeLists.txt +++ b/src/PartSetAPI/CMakeLists.txt @@ -76,7 +76,11 @@ SET(SWIG_MODULE_PartSetAPI_EXTRA_DEPS ${SWIG_MODULE_PartSetAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(PartSetAPI python PartSetAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(PartSetAPI LANGUAGE python SOURCES PartSetAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(PartSetAPI python PartSetAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(PartSetAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/PrimitivesAPI/CMakeLists.txt b/src/PrimitivesAPI/CMakeLists.txt index 82f6558b0..8cd9c647e 100644 --- a/src/PrimitivesAPI/CMakeLists.txt +++ b/src/PrimitivesAPI/CMakeLists.txt @@ -80,7 +80,11 @@ SET(SWIG_MODULE_PrimitivesAPI_EXTRA_DEPS ${SWIG_MODULE_PrimitivesAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(PrimitivesAPI python PrimitivesAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(PrimitivesAPI LANGUAGE python SOURCES PrimitivesAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(PrimitivesAPI python PrimitivesAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(PrimitivesAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/PythonAPI/Test/TestFeatures.py b/src/PythonAPI/Test/TestFeatures.py index 7358f11ef..f70dc0355 100644 --- a/src/PythonAPI/Test/TestFeatures.py +++ b/src/PythonAPI/Test/TestFeatures.py @@ -84,7 +84,11 @@ class FeaturesTestCase(FeaturesFixture): ExchangeAPI.ExchangeAPI_Import(self.part.addFeature("Import")) import FeaturesAPI - FeaturesAPI.FeaturesAPI_Boolean(self.part.addFeature("Boolean")) + FeaturesAPI.FeaturesAPI_BooleanCut(self.part.addFeature("BooleanCut")) + FeaturesAPI.FeaturesAPI_BooleanFuse(self.part.addFeature("BooleanFuse")) + FeaturesAPI.FeaturesAPI_BooleanCommon(self.part.addFeature("BooleanCommon")) + FeaturesAPI.FeaturesAPI_BooleanFill(self.part.addFeature("BooleanFill")) + FeaturesAPI.FeaturesAPI_BooleanSmash(self.part.addFeature("BooleanSmash")) FeaturesAPI.FeaturesAPI_Extrusion(self.part.addFeature("Extrusion")) FeaturesAPI.FeaturesAPI_ExtrusionCut(self.part.addFeature("ExtrusionCut")) FeaturesAPI.FeaturesAPI_ExtrusionFuse(self.part.addFeature("ExtrusionFuse")) diff --git a/src/PythonAPI/doc/source/conf.py b/src/PythonAPI/doc/source/conf.py index 2acabd660..3f3490f55 100644 --- a/src/PythonAPI/doc/source/conf.py +++ b/src/PythonAPI/doc/source/conf.py @@ -74,8 +74,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'Shaper python API' -copyright = u'2014-20xx CEA/DEN, EDF R&D' +project = 'Shaper python API' +copyright = '2014-20xx CEA/DEN, EDF R&D' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -227,8 +227,8 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'ShaperpythonAPI.tex', u'Shaper python API Documentation', - u'Renaud Nédélec', 'manual'), + ('index', 'ShaperpythonAPI.tex', 'Shaper python API Documentation', + 'Renaud Nédélec', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -257,8 +257,8 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'shaperpythonapi', u'Shaper python API Documentation', - [u'Renaud Nédélec'], 1) + ('index', 'shaperpythonapi', 'Shaper python API Documentation', + ['Renaud Nédélec'], 1) ] # If true, show URL addresses after external links. @@ -271,8 +271,8 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'ShaperpythonAPI', u'Shaper python API Documentation', - u'Renaud Nédélec', 'ShaperpythonAPI', 'One line description of project.', + ('index', 'ShaperpythonAPI', 'Shaper python API Documentation', + 'Renaud Nédélec', 'ShaperpythonAPI', 'One line description of project.', 'Miscellaneous'), ] diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index 29364c692..d4d142f13 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -8,20 +8,20 @@ All features are available via model.add*() functions. Exceptions are: # General purpose functions and abstract root classes -from services import * -from roots import * +from .services import * +from .roots import * # Built-in features -from build import * -from sketcher import * -from connection import * -from construction import * -from exchange import * -from features import * -from collection import * -from parameter import * -from partset import * -from primitives import * -from gdml import * -from tests import * +from .build import * +from .sketcher import * +from .connection import * +from .construction import * +from .exchange import * +from .features import * +from .collection import * +from .parameter import * +from .partset import * +from .primitives import * +from .gdml import * +from .tests import * diff --git a/src/PythonAPI/model/dump/__init__.py b/src/PythonAPI/model/dump/__init__.py index 78a1de4e5..2bb02cfdc 100644 --- a/src/PythonAPI/model/dump/__init__.py +++ b/src/PythonAPI/model/dump/__init__.py @@ -1,4 +1,4 @@ """Package for dumping purposes. """ -from DumpAssistant import * +from .DumpAssistant import * diff --git a/src/PythonAPI/model/sketcher/__init__.py b/src/PythonAPI/model/sketcher/__init__.py index 8c0319a1e..2d5622aee 100644 --- a/src/PythonAPI/model/sketcher/__init__.py +++ b/src/PythonAPI/model/sketcher/__init__.py @@ -2,5 +2,5 @@ """ from SketchAPI import addSketch -from tools import * -from tests import * +from .tools import * +from .tests import * diff --git a/src/PythonAPI/model/sketcher/tools.py b/src/PythonAPI/model/sketcher/tools.py index f3dcdb37a..0a2c4f6d4 100644 --- a/src/PythonAPI/model/sketcher/tools.py +++ b/src/PythonAPI/model/sketcher/tools.py @@ -68,7 +68,7 @@ def dof(sketch): aSketch = sketch if issubclass(type(aSketch), ModelHighAPI.ModelHighAPI_Interface): aSketch = sketch.feature() - return int(filter(str.isdigit, aSketch.string("SolverDOF").value())) + return int(''.join(filter(str.isdigit, aSketch.string("SolverDOF").value()))) def distancePointPoint(thePoint1, thePoint2): aPnt1 = toList(thePoint1) diff --git a/src/PythonAPI/model/tests/__init__.py b/src/PythonAPI/model/tests/__init__.py index f853b103f..b8f079e04 100644 --- a/src/PythonAPI/model/tests/__init__.py +++ b/src/PythonAPI/model/tests/__init__.py @@ -1 +1 @@ -from tests import * \ No newline at end of file +from .tests import * \ No newline at end of file diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index e2ba9dfe4..45c8ffbf3 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -42,14 +42,14 @@ def generateTests(theFeature, theFeatureName, theTestsList = []): """ if "testNbResults" in theTestsList or len(theTestsList) == 0: aNbResults = len(theFeature.results()) - print "model.testNbResults({}, {})".format(theFeatureName, aNbResults) + print("model.testNbResults({}, {})".format(theFeatureName, aNbResults)) if "testNbSubResults" in theTestsList or len(theTestsList) == 0: aNbResults = len(theFeature.results()) aNbSubResults = [] for anIndex in range(0, aNbResults): aNbSubResults.append(theFeature.results()[anIndex].numberOfSubs()) - print "model.testNbSubResults({}, {})".format(theFeatureName, aNbSubResults) + print("model.testNbSubResults({}, {})".format(theFeatureName, aNbSubResults)) if "testNbSubShapes" in theTestsList or len(theTestsList) == 0: aNbResults = len(theFeature.results()) @@ -61,16 +61,16 @@ def generateTests(theFeature, theFeatureName, theTestsList = []): aShapeExplorer = GeomAPI_ShapeExplorer(aShape, aShapeType) while aShapeExplorer.more(): aNbResultSubShapes += 1 - aShapeExplorer.next(); + aShapeExplorer.next() aNbSubShapes.append(aNbResultSubShapes) - print "model.testNbSubShapes({}, {}, {})".format(theFeatureName, aShapeTypes[aShapeType], aNbSubShapes) + print("model.testNbSubShapes({}, {}, {})".format(theFeatureName, aShapeTypes[aShapeType], aNbSubShapes)) if "testResultsVolumes" in theTestsList or len(theTestsList) == 0: aNbResults = len(theFeature.results()) aResultsVolumes = [] for anIndex in range(0, aNbResults): aResultsVolumes.append(GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape())) - print "model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes)) + print("model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes))) def testNbResults(theFeature, theExpectedNbResults): @@ -112,7 +112,7 @@ def testNbSubShapes(theFeature, theShapeType, theExpectedNbSubShapes): aShapeExplorer = GeomAPI_ShapeExplorer(aShape, theShapeType) while aShapeExplorer.more(): aNbResultSubShapes += 1 - aShapeExplorer.next(); + aShapeExplorer.next() assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes) diff --git a/src/PythonAddons/addons_Features.py b/src/PythonAddons/addons_Features.py index b5ebf59fa..3fcb67d12 100644 --- a/src/PythonAddons/addons_Features.py +++ b/src/PythonAddons/addons_Features.py @@ -50,7 +50,7 @@ class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin): aFeature = SketchPlugin_Rectangle().__disown__() else: - raise StandardError("No such feature %s" % theFeatureID) + raise Exception("No such feature %s" % theFeatureID) return aFeature diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index c647ef0e6..c61a089ee 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -105,7 +105,11 @@ SET(SWIG_MODULE_SketchAPI_EXTRA_DEPS ${SWIG_MODULE_SketchAPI_EXTRA_DEPS} ${PROJECT_HEADERS} ) -SWIG_ADD_MODULE(SketchAPI python SketchAPI.i ${PROJECT_HEADERS}) +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(SketchAPI LANGUAGE python SOURCES SketchAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(SketchAPI python SketchAPI.i ${PROJECT_HEADERS}) +ENDIF() SWIG_LINK_LIBRARIES(SketchAPI ${SWIG_LINK_LIBRARIES}) IF(WIN32) diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index e443e5f23..0f76546eb 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -27,7 +27,7 @@ #include "ModelHighAPI_swig.h" // fix for SWIG v2.0.4 - #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj)) + #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj)) %} %include "doxyhelp.i" diff --git a/src/SketchAPI/SketchAPI_Constraint.h b/src/SketchAPI/SketchAPI_Constraint.h index 8f79cca41..2ad165065 100644 --- a/src/SketchAPI/SketchAPI_Constraint.h +++ b/src/SketchAPI/SketchAPI_Constraint.h @@ -46,8 +46,8 @@ public: static std::string ID() { - static const std::string DUMMY; - return DUMMY; + static const std::string MY_SKETCH_CONSTRAINT_ID = "SketchConstraint"; + return MY_SKETCH_CONSTRAINT_ID; } virtual std::string getID() { return ID(); } diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 412c19605..12493c5f1 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -258,13 +258,3 @@ if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE}) TestMovementComplex.py ) endif() - -# Copy data-files to corresponding directory -file(GLOB DATA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Test/Data/*") -foreach(data_file ${DATA_FILES}) - get_filename_component(data_file_name "${data_file}" NAME) - configure_file( - ${data_file} - ${CMAKE_CURRENT_BINARY_DIR}/Data/${data_file_name} - COPYONLY) -endforeach() diff --git a/src/SketchPlugin/Test/Test1673.py b/src/SketchPlugin/Test/Test1673.py index 6eea668e5..af9cc1f11 100644 --- a/src/SketchPlugin/Test/Test1673.py +++ b/src/SketchPlugin/Test/Test1673.py @@ -248,7 +248,7 @@ SketchConstraintVertical_11.setName("SketchConstraintVertical_12") model.do() sketchTime = timer() - sketchTime -print "Sketch creation time: {0}".format(sketchTime) +print("Sketch creation time: {0}".format(sketchTime)) expectedTime = MOVE_BUILD_RATIO * sketchTime averageTime = 0 nbMoves = 0 @@ -289,7 +289,7 @@ for ang in range(0, 50): nbMoves += 1 aDeltaX = aEndPoint.x() - aCenter.x() aDeltaY = aEndPoint.y() - aCenter.y() -print "Movement average time: {0}".format(averageTime / nbMoves) +print("Movement average time: {0}".format(averageTime / nbMoves)) model.end() diff --git a/src/SketchPlugin/Test/Test1966.py b/src/SketchPlugin/Test/Test1966.py index a42983b7e..8da4ac2dc 100644 --- a/src/SketchPlugin/Test/Test1966.py +++ b/src/SketchPlugin/Test/Test1966.py @@ -288,7 +288,7 @@ SketchConstraintLength_8 = Sketch_1.setLength(SketchLine_37.result(), 0.088) model.do() sketchTime = timer() - sketchTime -print "Sketch creation time: {0}".format(sketchTime) +print("Sketch creation time: {0}".format(sketchTime)) expectedTime = MOVE_BUILD_RATIO * sketchTime averageTime = 0 nbMoves = 0 @@ -310,7 +310,7 @@ for deltaX, deltaY in deltas: assert math.fabs(aPoint.x() - X) < TOLERANCE and math.fabs(aPoint.y() - Y) < TOLERANCE, "({0}, {1}) != ({2}, {3})".format(aPoint.x(), aPoint.y(), X, Y) averageTime += movementTime nbMoves += 1 -print "Movement average time: {0}".format(averageTime / nbMoves) +print("Movement average time: {0}".format(averageTime / nbMoves)) #========================================================================= # Change value of SketchConstraintAngle_6 and check execution time. @@ -329,7 +329,7 @@ for ang in range(12, 30): assert math.fabs(curAngle - ang) < TOLERANCE, "angle {0} != {1} expected".format(curAngle, ang) averageTime += movementTime nbMoves += 1 -print "Changing angle average time: {0}".format(averageTime / nbMoves) +print("Changing angle average time: {0}".format(averageTime / nbMoves)) model.end() diff --git a/src/SketchPlugin/Test/Test1967.py b/src/SketchPlugin/Test/Test1967.py index ae9bfaf69..05c5a1b0b 100644 --- a/src/SketchPlugin/Test/Test1967.py +++ b/src/SketchPlugin/Test/Test1967.py @@ -267,7 +267,7 @@ SketchConstraintMiddle_3 = Sketch_1.setMiddlePoint(SketchLine_17.startPoint(), S model.do() sketchTime = timer() - sketchTime -print "Sketch creation time: {0}".format(sketchTime) +print("Sketch creation time: {0}".format(sketchTime)) expectedTime = MOVE_BUILD_RATIO * sketchTime averageTime = 0 nbMoves = 0 @@ -290,7 +290,7 @@ for deltaX, deltaY in deltas: averageTime += movementTime nbMoves += 1 -print "Movement average time: {0}".format(averageTime / nbMoves) +print("Movement average time: {0}".format(averageTime / nbMoves)) model.end() diff --git a/src/SketchPlugin/Test/Test2440.py b/src/SketchPlugin/Test/Test2440.py index 0a0ba1bb1..eb4077a58 100644 --- a/src/SketchPlugin/Test/Test2440.py +++ b/src/SketchPlugin/Test/Test2440.py @@ -30,11 +30,14 @@ from salome.shaper import model from math import fabs +import os + model.begin() partSet = model.moduleDocument() Part_1 = model.addPart(partSet) Part_1_doc = Part_1.document() -Import_1 = model.addImport(Part_1_doc, "Data/profile_top.brep") +shape_path = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Brep", "profile_top.brep") +Import_1 = model.addImport(Part_1_doc, shape_path) model.do() Import_1.setName("profile_top") Import_1.result().setName("profile_top_1") diff --git a/src/SketchPlugin/Test/TestConstraintFixed.py b/src/SketchPlugin/Test/TestConstraintFixed.py index db20680aa..ad3921f04 100644 --- a/src/SketchPlugin/Test/TestConstraintFixed.py +++ b/src/SketchPlugin/Test/TestConstraintFixed.py @@ -92,8 +92,8 @@ kLineCEnd = (aLineCEndPoint.x(), aLineCEndPoint.y()) #========================================================================= # Link triange lines with concidence #========================================================================= -concidenceLinks = zip([aLineBStartPoint, aLineCStartPoint, aLineAStartPoint], - [aLineAEndPoint, aLineBEndPoint, aLineCEndPoint]) +concidenceLinks = list(zip([aLineBStartPoint, aLineCStartPoint, aLineAStartPoint], + [aLineAEndPoint, aLineBEndPoint, aLineCEndPoint])) aSession.startOperation() for eachLink in concidenceLinks: aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") diff --git a/src/SketchPlugin/Test/TestHighload.py b/src/SketchPlugin/Test/TestHighload.py index befac2e27..dc9c84bf7 100644 --- a/src/SketchPlugin/Test/TestHighload.py +++ b/src/SketchPlugin/Test/TestHighload.py @@ -44,7 +44,7 @@ def createNAngle(theSketch, theN, theRadius, theEdgeLength=0): # Create an N-Angle at (0,0) rad = 2. * math.pi / theN points = [] - for a in xrange(theN): + for a in range(theN): x = round(math.cos(rad * a), 10) * theRadius y = round(math.sin(rad * a), 10) * theRadius points.append((x, y)) @@ -126,8 +126,8 @@ aDOF = 0 deltaX = deltaY = 50. n = 5 aSession.startOperation() -for i in xrange(4): - for j in xrange(4): +for i in range(4): + for j in range(4): allNangleLines = createNAngle(aSketchFeature, n, 50) fixLineLength(aSketchFeature, allNangleLines) moveTo(allNangleLines, deltaX, deltaY) diff --git a/src/SketchPlugin/Test/TestMirror.py b/src/SketchPlugin/Test/TestMirror.py index c51f35a83..73d51f1e0 100644 --- a/src/SketchPlugin/Test/TestMirror.py +++ b/src/SketchPlugin/Test/TestMirror.py @@ -245,7 +245,7 @@ refAttrA.setAttr(anArcStartPoint) refAttrB.setAttr(aMirroredArcStartPoint) aConstraint.real("ConstraintValue").setValue(200.) aSession.finishOperation() -print "Sketch error : {}".format(aSketchErrorAttr.value()) +print("Sketch error : {}".format(aSketchErrorAttr.value())) assert len(aSketchErrorAttr.value()) != 0, "ERROR: Sketch has not been failed as expected" aSession.startOperation() aDocument.removeFeature(aConstraint) diff --git a/src/SketchPlugin/Test/TestSnowflake.py b/src/SketchPlugin/Test/TestSnowflake.py index c98b5a4da..ebdcd2b11 100644 --- a/src/SketchPlugin/Test/TestSnowflake.py +++ b/src/SketchPlugin/Test/TestSnowflake.py @@ -81,7 +81,7 @@ def initContour(theNumLines): prevPoint = (35, 0) result = [] deltaY = random.uniform(20, 25) - for i in xrange(1, theNumLines): + for i in range(1, theNumLines): rangeXMax = (prevPoint[1] + deltaY) * (30. / i if i % 2 != 0 else 2) newX = random.uniform(prevPoint[1] + deltaY, max(rangeXMax, prevPoint[1] + deltaY + 25.)) @@ -102,9 +102,9 @@ def makeLinesCoincident(theSketch, allLines): anEndPointValue = (anEndPoint.x(), anEndPoint.y()) allPoints[aStartPointValue].append(aStartPoint) allPoints[anEndPointValue].append(anEndPoint) - for keyPoint, valuePoints in allPoints.iteritems(): + for keyPoint, valuePoints in allPoints.items(): if len(valuePoints) != 2: - print "Strange point: ", keyPoint, "has in coincidence: ", len(valuePoints) + print("Strange point: ", keyPoint, "has in coincidence: ", len(valuePoints)) continue aConstraint = theSketch.addFeature("SketchConstraintCoincidence") aConstraint.refattr("ConstraintEntityA").setAttr(valuePoints[0]) diff --git a/src/XAO/tests/BrepGeometryTest.cxx b/src/XAO/tests/BrepGeometryTest.cxx index 2139f1439..0c39997a7 100644 --- a/src/XAO/tests/BrepGeometryTest.cxx +++ b/src/XAO/tests/BrepGeometryTest.cxx @@ -41,14 +41,15 @@ void BrepGeometryTest::cleanUp() void readBrep(Geometry* geom, const std::string& fileName) { - char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(fileName)); + std::string filePath = "Shapes/Brep/" + fileName; + char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(filePath)); geom->setShapeString(txt); } void BrepGeometryTest::testGetIDs() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_1.brep"); + readBrep(geom, "box1.brep"); CPPUNIT_ASSERT_EQUAL(8, geom->countElements(XAO::VERTEX)); CPPUNIT_ASSERT_EQUAL(8, geom->countVertices()); @@ -78,7 +79,7 @@ void BrepGeometryTest::testGetIDs() void BrepGeometryTest::testGetReferences() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_1.brep"); + readBrep(geom, "box1.brep"); // vertex of index 1 has id = 7 CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getElementReference(XAO::VERTEX, 1)); @@ -114,7 +115,7 @@ void BrepGeometryTest::testGetReferences() void BrepGeometryTest::testGetNames() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_1.brep"); + readBrep(geom, "box1.brep"); int id; @@ -156,7 +157,7 @@ void BrepGeometryTest::testGetNames() void BrepGeometryTest::testGetEdgeVertices() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_2.brep"); + readBrep(geom, "box2.brep"); // edge of index 23, id = #63 // vertex are 47 (#12), 59 (#15) @@ -179,7 +180,7 @@ void printVector(std::vector& v) void BrepGeometryTest::testGetFaceEdges() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_2.brep"); + readBrep(geom, "box2.brep"); CPPUNIT_ASSERT_EQUAL(2, geom->countFaceWires(1)); // face 13 CPPUNIT_ASSERT_EQUAL(1, geom->countFaceWires(2)); // face 29 @@ -204,7 +205,7 @@ void BrepGeometryTest::testGetFaceEdges() void BrepGeometryTest::testSolidFaces() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Cut_2.brep"); + readBrep(geom, "cut.brep"); CPPUNIT_ASSERT_EQUAL(5, geom->countSolidShells(0)); @@ -226,7 +227,7 @@ void BrepGeometryTest::testSolidFaces() void BrepGeometryTest::testGetVertex() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_2.brep"); + readBrep(geom, "box2.brep"); double x, y, z; geom->getVertexXYZ(15, x, y, z); @@ -240,7 +241,7 @@ void BrepGeometryTest::testGetVertex() void BrepGeometryTest::testGetEdgeLength() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_2.brep"); + readBrep(geom, "box2.brep"); // edges 0 (#5), 7 (#21) CPPUNIT_ASSERT_DOUBLES_EQUAL(200., geom->getEdgeLength(0), 0); @@ -252,7 +253,7 @@ void BrepGeometryTest::testGetEdgeLength() void BrepGeometryTest::testGetFaceArea() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_2.brep"); + readBrep(geom, "box2.brep"); // faces 0 (#3), 1 (#13) CPPUNIT_ASSERT_DOUBLES_EQUAL(40000., geom->getFaceArea(0), 1e-9); @@ -264,7 +265,7 @@ void BrepGeometryTest::testGetFaceArea() void BrepGeometryTest::testGetSolidVolume() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_2.brep"); + readBrep(geom, "box2.brep"); CPPUNIT_ASSERT_DOUBLES_EQUAL(7488000., geom->getSolidVolume(0), 1e-9); @@ -274,7 +275,7 @@ void BrepGeometryTest::testGetSolidVolume() void BrepGeometryTest::testParse() { BrepGeometry* geom = new BrepGeometry("box"); - readBrep(geom, "Box_2.brep"); + readBrep(geom, "box2.brep"); std::cout << std::endl; for (int solidIndex = 0; solidIndex < geom->countSolids(); ++solidIndex) diff --git a/src/XAO/tests/GeometryTest.cxx b/src/XAO/tests/GeometryTest.cxx index f9bcd7bc7..87a37cf46 100644 --- a/src/XAO/tests/GeometryTest.cxx +++ b/src/XAO/tests/GeometryTest.cxx @@ -135,7 +135,7 @@ void GeometryTest::testSetElement() CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), XAO_Exception); - char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep")); + char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Shapes/Brep/box1.brep")); geom->setShapeString(txt); CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0)); diff --git a/src/XAO/tests/ImportExportTest.cxx b/src/XAO/tests/ImportExportTest.cxx index 2c060200e..75f17d74c 100644 --- a/src/XAO/tests/ImportExportTest.cxx +++ b/src/XAO/tests/ImportExportTest.cxx @@ -122,13 +122,13 @@ void ImportExportTest::testGeometryError() void ImportExportTest::testImportXao() { Xao xao; - xao.importXAO(TestUtils::getTestFilePath("test.xao")); + xao.importXAO(TestUtils::getTestFilePath("Shapes/Xao/box1.xao")); checkImport(xao); } void ImportExportTest::testImportXaoFromText() { - char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao")); + char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Shapes/Xao/box1.xao")); Xao xao; xao.setXML(txt); diff --git a/src/XAO/tests/TestUtils.hxx b/src/XAO/tests/TestUtils.hxx index 593916c22..aa1f5d104 100644 --- a/src/XAO/tests/TestUtils.hxx +++ b/src/XAO/tests/TestUtils.hxx @@ -28,11 +28,10 @@ namespace XAO class TestUtils { public: - static std::string getTestFilePath(const std::string& fileName) + static std::string getTestFilePath(const std::string& filePath) { - std::string dataDir = getenv("GEOM_SRC_DIR"); - dataDir += "/src/XAO/tests/data/"; - dataDir += fileName; + std::string dataDir = getenv("DATA_DIR"); + dataDir += filePath; return dataDir; } diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index 3073bf450..da67a6bbb 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -373,11 +373,14 @@ void XGUI_Selection::entityOwners(const Handle(AIS_InteractiveObject)& theObject continue; Handle(SelectMgr_Selection) aSelection = theObject->Selection(aMode); - for (aSelection->Init(); aSelection->More(); aSelection->Next()) { - Handle(SelectMgr_SensitiveEntity) anEntity = aSelection->Sensitive(); + NCollection_Vector anEntities = aSelection->Entities(); + for (NCollection_Vector::Iterator anIt(anEntities); + anIt.More(); + anIt.Next()) { + Handle(SelectMgr_SensitiveEntity) anEntity = anIt.Value(); if (anEntity.IsNull()) continue; - Handle(SelectMgr_EntityOwner) anOwner = + Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anEntity->BaseSensitive()->OwnerId()); if (!anOwner.IsNull()) theOwners.Add(anOwner); diff --git a/test.API/SHAPER/GDML/TestAPI_ConeSegment.py b/test.API/SHAPER/GDML/TestAPI_ConeSegment.py index fde6fef28..6b6205fab 100644 --- a/test.API/SHAPER/GDML/TestAPI_ConeSegment.py +++ b/test.API/SHAPER/GDML/TestAPI_ConeSegment.py @@ -32,40 +32,40 @@ CS7 = shaperpy.makeConeSegment(7.,11.,5.,8.,12.,0.,360.) try : CS8 = shaperpy.makeConeSegment(-5.,11.,5.,8.,12.,0.,270.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: rmin1 is negative.") try : CS9 = shaperpy.makeConeSegment(11.,7.,5.,8.,12.,0.,270.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: rmin1 is larger than rmax1.") try : CS10 = shaperpy.makeConeSegment(7.,11.,8.,5.,12.,0.,270.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: rmin2 is larger than rmax2.") try : CS11 = shaperpy.makeConeSegment(7.,11.,-3.,5.,12.,0.,270.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: rmin2 is negative.") try : CS12 = shaperpy.makeConeSegment(7.,11.,5.,8.,0.,0.,270.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: z is negative or null.") try : CS13 = shaperpy.makeConeSegment(7.,11.,5.,8.,-10.,0.,270.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: z is negative or null.") try : CS14 = shaperpy.makeConeSegment(7.,11.,5.,8.,12.,-45.,-45.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: deltaphi is negative or null.") try : CS15 = shaperpy.makeConeSegment(7.,11.,5.,8.,12.,45.,450.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cone Segment builder :: deltaphi is larger than 360 degree.") \ No newline at end of file diff --git a/test.API/SHAPER/Primitives/TestAPI_Box.py b/test.API/SHAPER/Primitives/TestAPI_Box.py index 8b24b8049..8ea9d29dc 100644 --- a/test.API/SHAPER/Primitives/TestAPI_Box.py +++ b/test.API/SHAPER/Primitives/TestAPI_Box.py @@ -27,32 +27,32 @@ Box_1 = shaperpy.makeBox(10.,10.,10.) try : Box_2 = shaperpy.makeBox(0.,10.,10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with dimensions :: Dx is null or negative.") try : Box_3 = shaperpy.makeBox(10.,0.,10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with dimensions :: Dy is null or negative.") try : Box_4 = shaperpy.makeBox(10.,10.,0.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with dimensions :: Dz is null or negative.") try : Box_5 = shaperpy.makeBox(-10.,10.,10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with dimensions :: Dx is null or negative.") try : Box_6 = shaperpy.makeBox(10.,-10.,10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with dimensions :: Dy is null or negative.") try : Box_7 = shaperpy.makeBox(10.,10.,-10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with dimensions :: Dz is null or negative.") # Create a box with two points defining the diagonal @@ -62,33 +62,33 @@ Box_8 = shaperpy.makeBox(pnt1,pnt2) try : Box_9 = shaperpy.makeBox(pnt1,pnt1) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with points :: the distance between the two points is null.") try : pnt3 = pnt(0.,50.,50.) Box_10 = shaperpy.makeBox(pnt1,pnt3) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.") try : pnt4 = pnt(50.,0.,50.) Box_11 = shaperpy.makeBox(pnt1,pnt4) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.") try : pnt5 = pnt(50.,50.,0.) Box_12 = shaperpy.makeBox(pnt1,pnt5) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.") try : Box_13 = shaperpy.makeBox(None, pnt2) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with points :: the first point is not valid.") try : Box_14 = shaperpy.makeBox(pnt2, None) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Box builder with points :: the second point is not valid.") \ No newline at end of file diff --git a/test.API/SHAPER/Primitives/TestAPI_Cylinder.py b/test.API/SHAPER/Primitives/TestAPI_Cylinder.py index f6862ab88..95cb08f95 100644 --- a/test.API/SHAPER/Primitives/TestAPI_Cylinder.py +++ b/test.API/SHAPER/Primitives/TestAPI_Cylinder.py @@ -46,32 +46,32 @@ Cylinder_3 = shaperpy.makeCylinder(pnt2, edg1, 7., 12.) try: Cylinder_4 = shaperpy.makeCylinder(0., 10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: radius is negative or null.") try: Cylinder_5 = shaperpy.makeCylinder(-5., 10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: radius is negative or null.") try: Cylinder_6 = shaperpy.makeCylinder(5., 0.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: height is negative or null.") try: Cylinder_7 = shaperpy.makeCylinder(5., -10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: height is negative or null.") try: Cylinder_8 = shaperpy.makeCylinder(None, edgz, 5., 10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: the base point is not valid.") try: Cylinder_9 = shaperpy.makeCylinder(pnt1, None, 5., 10.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: the axis is not valid.") Cylinder_14 = shaperpy.makeCylinder(5., 10., 45.) @@ -81,45 +81,45 @@ Cylinder_17 = shaperpy.makeCylinder(pnt2, edgy, 5., 10., 360.) try: Cylinder_18 = shaperpy.makeCylinder(0., 10., 45.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: radius is negative or null.") try: Cylinder_19 = shaperpy.makeCylinder(-5., 10., 45.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: radius is negative or null.") try: Cylinder_20 = shaperpy.makeCylinder(5., 0., 45.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: height is negative or null.") try: Cylinder_21 = shaperpy.makeCylinder(5., -10., 45.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: height is negative or null.") try: Cylinder_22 = shaperpy.makeCylinder(5., 10., 0.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: angle is negative or null.") try: Cylinder_23 = shaperpy.makeCylinder(5., 10., -45.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: angle is negative or null.") try: Cylinder_24 = shaperpy.makeCylinder(5., 10., 450.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: angle greater than 360 degrees.") try: Cylinder_25 = shaperpy.makeCylinder(None, edgz, 5., 10., 90.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: the base point is not valid.") try: Cylinder_26 = shaperpy.makeCylinder(pnt1, None, 5., 10., 90.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Cylinder builder :: the axis is not valid.") \ No newline at end of file diff --git a/test.API/SHAPER/Transformations/TestAPI_MultiTranslation.py b/test.API/SHAPER/Transformations/TestAPI_MultiTranslation.py index 2195df285..0a3ac7619 100644 --- a/test.API/SHAPER/Transformations/TestAPI_MultiTranslation.py +++ b/test.API/SHAPER/Transformations/TestAPI_MultiTranslation.py @@ -51,7 +51,7 @@ MultiTranslation_2 = shaperpy.makeMultiTranslation(Box_2, ax1, -15., 5) try: MultiTranslation_3 = shaperpy.makeMultiTranslation(Box_3, ax1, 15., -2) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Multitranslation builder :: the number of copies for the first direction is null or negative.") MultiTranslation_5 = shaperpy.makeMultiTranslation(Box_5, ax1, 10., 5, ax2, 10., 5) @@ -66,7 +66,7 @@ MultiTranslation_6 = shaperpy.makeMultiTranslation(Box_6, ax1, 15., 5, ax2, -10. # Pas d'exception levee alors qu'une devrait y en avoir une try: MultiTranslation_7 = shaperpy.makeMultiTranslation(Box_7, ax1, 15., 5, ax2, 10., -2) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Multitranslation builder :: the number of copies for the second direction is null or negative.") #try: diff --git a/test.API/SHAPER/Transformations/TestAPI_Rotation.py b/test.API/SHAPER/Transformations/TestAPI_Rotation.py index 5b0800484..1e9323572 100644 --- a/test.API/SHAPER/Transformations/TestAPI_Rotation.py +++ b/test.API/SHAPER/Transformations/TestAPI_Rotation.py @@ -58,22 +58,22 @@ Rotation_4 = shaperpy.makeRotation(Box_4, ax1, -360) try: Rotation_5 = shaperpy.makeRotation(Box_5, ax1, 450) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: angle greater than 360 degrees.") try: Rotation_6 = shaperpy.makeRotation(Box_6, ax1, -450) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: angle smaller than -360 degrees.") try: Rotation_7 = shaperpy.makeRotation(Box_7, None, 180) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: axis is not valid.") try: Rotation_8 = shaperpy.makeRotation(None, ax1, 180) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: source shape is not valid.") Rotation_9 = shaperpy.makeRotation(Box_8, pntOrigin, pnt1, pnt2) @@ -81,35 +81,35 @@ Rotation_10 = shaperpy.makeRotation(Box_9, pnt3, pnt1, pnt2) try: Rotation_11 = shaperpy.makeRotation(Box_10, pnt3, pnt1, pnt1) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: start point and end point coincide.") try: Rotation_12 = shaperpy.makeRotation(Box_11, pnt3, pnt3, pnt1) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: center point and start point coincide.") try: Rotation_13 = shaperpy.makeRotation(Box_12, pnt3, pnt1, pnt3) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: center point and end point coincide.") try: Rotation_14 = shaperpy.makeRotation(Box_13, pntOrigin, pnt1, None) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: end point is not valid.") try: Rotation_15 = shaperpy.makeRotation(Box_14, None, pnt3, pnt2) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: center point is not valid.") try: Rotation_16 = shaperpy.makeRotation(Box_15, pntOrigin, None, pnt1) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: start point is not valid.") try: Rotation_17 = shaperpy.makeRotation(None, pntOrigin, pnt3, pnt2) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Rotation builder :: source shape is not valid.") diff --git a/test.API/SHAPER/Transformations/TestAPI_Scale.py b/test.API/SHAPER/Transformations/TestAPI_Scale.py index 2904d5bd4..8fc2c5244 100644 --- a/test.API/SHAPER/Transformations/TestAPI_Scale.py +++ b/test.API/SHAPER/Transformations/TestAPI_Scale.py @@ -46,14 +46,14 @@ Scale_1 = shaperpy.makeScale(Box_1, pntOrigin, 2.) Scale_2 = shaperpy.makeScale(Box_2, pnt1, 2.) try : Scale_6 = shaperpy.makeScale(Box_3, pntOrigin, 0) -except myExcept,ec : +except myExcept as ec : assert(ec.what() == "Scale builder :: the scale factor is null.") Scale_7 = shaperpy.makeScale(Box_4, pntOrigin, -3.) try : Scale_8 = shaperpy.makeScale(Box_5, None, 2.) -except myExcept,ec : +except myExcept as ec : assert(ec.what() == "Scale builder :: center point is not valid.") Scale_9 = shaperpy.makeScale(Box_6, pntOrigin, 2., 3., 1.) @@ -61,20 +61,20 @@ Scale_10 = shaperpy.makeScale(Box_7, pnt1, 2., 3., 1.) try : Scale_14 = shaperpy.makeScale(Box_8, pntOrigin, 0., 3., 1.) -except myExcept,ec : +except myExcept as ec : assert(ec.what() == "Scale builder :: the scale factor in X is null.") try : Scale_15 = shaperpy.makeScale(Box_9, pntOrigin, 2., 0., 1.) -except myExcept,ec : +except myExcept as ec : assert(ec.what() == "Scale builder :: the scale factor in Y is null.") try : Scale_16 = shaperpy.makeScale(Box_10, pntOrigin, 2., 3., 0.) -except myExcept,ec : +except myExcept as ec : assert(ec.what() == "Scale builder :: the scale factor in Z is null.") Scale_17 = shaperpy.makeScale(Box_11, pntOrigin, -2., -3., 0.5) try : Scale_18 = shaperpy.makeScale(Box_12, None, 2., 3., 1.) -except myExcept,ec : +except myExcept as ec : assert(ec.what() == "Scale builder :: center point is not valid.") \ No newline at end of file diff --git a/test.API/SHAPER/Transformations/TestAPI_Symmetry.py b/test.API/SHAPER/Transformations/TestAPI_Symmetry.py index 0e0110fa3..6356d227f 100644 --- a/test.API/SHAPER/Transformations/TestAPI_Symmetry.py +++ b/test.API/SHAPER/Transformations/TestAPI_Symmetry.py @@ -64,7 +64,7 @@ Symmetry_2 = shaperpy.makeSymmetry(Box_2, pnt1) try : Symmetry_6 = shaperpy.makeSymmetry(Box_2, None) -except myExcept,ec : +except myExcept as ec : assert(ec.what() == "Symmetry builder :: point is not valid.") Symmetry_7 = shaperpy.makeSymmetry(Box_7, axZ) diff --git a/test.API/SHAPER/Transformations/TestAPI_Translation.py b/test.API/SHAPER/Transformations/TestAPI_Translation.py index 376f12497..1d6a18c1f 100644 --- a/test.API/SHAPER/Transformations/TestAPI_Translation.py +++ b/test.API/SHAPER/Transformations/TestAPI_Translation.py @@ -69,7 +69,7 @@ Translation_3 = shaperpy.makeTranslation(Box_3, ax1, -15.) try: Translation_4 = shaperpy.makeTranslation(Box_4, None, 15.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Translation builder :: axis is not valid.") Translation_9 = shaperpy.makeTranslation(Box_5, ax4, 15.) @@ -86,7 +86,7 @@ Translation_12 = shaperpy.makeTranslation(MultiTranslation_3, ax3, -15.) MultiTranslation_4 = shaperpy.makeMultiTranslation(Box_9, ax1, 15., 3, ax2, 15., 3) try: Translation_13 = shaperpy.makeTranslation(MultiTranslation_4, None, 15.) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Translation builder :: axis is not valid.") MultiTranslation_5 = shaperpy.makeMultiTranslation(Box_10, ax1, 15., 3, ax2, 15., 3) @@ -106,15 +106,15 @@ Translation_99 = shaperpy.makeTranslation(Box_11, pnt1, pnt2) try: Translation_100 = shaperpy.makeTranslation(Box_11, pnt1, pnt1) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Translation builder :: start point and end point coincide.") try: Translation_101 = shaperpy.makeTranslation(Box_11, None, pnt1) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Translation builder :: start point is not valid.") try: Translation_102 = shaperpy.makeTranslation(Box_11, pnt1, None) -except myExcept,ec: +except myExcept as ec: assert(ec.what() == "Translation builder :: end point is not valid.") \ No newline at end of file diff --git a/test.squish/suite_FEATURE_PARAMETERS/shared/scripts/bdd_hooks.py b/test.squish/suite_FEATURE_PARAMETERS/shared/scripts/bdd_hooks.py index c67df2890..93d49269c 100644 --- a/test.squish/suite_FEATURE_PARAMETERS/shared/scripts/bdd_hooks.py +++ b/test.squish/suite_FEATURE_PARAMETERS/shared/scripts/bdd_hooks.py @@ -36,7 +36,7 @@ # See the section 'Performing Actions During Test Execution Via Hooks' in the Squish # manual for a complete reference of the available API. -import __builtin__ +import builtins # Detach (i.e. potentially terminate) all AUTs at the end of a scenario @OnScenarioEnd diff --git a/test.squish/suite_FEATURE_PARAMETERS/shared/steps/steps.py b/test.squish/suite_FEATURE_PARAMETERS/shared/steps/steps.py index 81e103f7f..77b413af5 100644 --- a/test.squish/suite_FEATURE_PARAMETERS/shared/steps/steps.py +++ b/test.squish/suite_FEATURE_PARAMETERS/shared/steps/steps.py @@ -48,7 +48,7 @@ # specified. In that case, make sure to set the (optional) 'regexp' argument # to True. -import __builtin__ +import builtins @Given("Launch application in salome mode") def step(context): diff --git a/utils.py b/utils.py index 847f242d8..5e811fd40 100644 --- a/utils.py +++ b/utils.py @@ -26,8 +26,8 @@ import os, os.path SHAPER_SRC = os.environ['PWD'] # VERBOSE_FLAG = os.environ['VERBOSE_FLAG'] VERBOSE_FLAG = "" -ENCODING = u"utf-8" -OPERATORS=[u">", u"<", u"+", u"=", u"-", u"*", u"/"] +ENCODING = "utf-8" +OPERATORS=[">", "<", "+", "=", "-", "*", "/"] def create_warning_generator(fichier): """ @@ -40,14 +40,14 @@ def create_warning_generator(fichier): while ligne.strip("\n") : ligne = ligne.decode(ENCODING) liste = ligne.split(":") - print "Size of liste = ", len(liste) - print "ligne = ", ligne - print "n° ligne = ", i - print "XXX : ", ligne.find(u'Done processing ') + print("Size of liste = ", len(liste)) + print("ligne = ", ligne) + print("n° ligne = ", i) + print("XXX : ", ligne.find('Done processing ')) if len(liste) < 3: - if ligne.find(u'Done processing ') == -1 and ligne.find(u'Category ') == -1 and ligne.find(u'Total errors found: ') == -1: - raise Exception(u"Fichier de log mal formé") + if ligne.find('Done processing ') == -1 and ligne.find('Category ') == -1 and ligne.find('Total errors found: ') == -1: + raise Exception("Fichier de log mal formé") else: ligne = fichier.readline() i += 1 @@ -55,12 +55,12 @@ def create_warning_generator(fichier): elif len(liste) != 3: item1=liste[0] item2=liste[1] - merge = u"" - sep = u"" + merge = "" + sep = "" for item in liste[2:]: merge += sep merge += item - sep = u":" + sep = ":" liste = [item1, item2, merge] ligne = fichier.readline() i += 1 @@ -73,7 +73,7 @@ def get_line_no(path, nol): """retourne la ligne No nol du fichier path (relatif à DST_SRC_PARENT) sous forme d'un unicode""" ligne = "" fic = open(get_src_path(path), "r") - for i in xrange(nol): + for i in range(nol): ligne = fic .readline() fic.close() ligne_u = ligne.decode(ENCODING)