From e893c874273381c119066d7eadc81cef9832f50b Mon Sep 17 00:00:00 2001 From: asozinov Date: Fri, 9 Dec 2022 13:12:39 +0300 Subject: [PATCH] bos 32359 - Adaptation of SHAPER model - Added tests - Fix compilation problem - Cleanup --- CMakeLists.txt | 8 +- .../SAMConverter_ConvertConstraints.py | 6 + .../SAMConverter_ConvertSketch.py | 3 +- src/SAMConverter/SAMConverter_Logger.py | 4 + .../SAMConverter_SuggestConstraintsFeature.py | 31 ++- src/SAMConverter/SAMConverter_msg_fr.ts | 8 +- src/SAMConverter/Test/CMakeLists.txt | 40 +-- .../Test/CTestTestfileInstall.cmake | 19 +- .../Test/TestSAMConverter_Angle.py | 43 +++ src/SAMConverter/Test/TestSAMConverter_Arc.py | 94 +++++++ .../Test/TestSAMConverter_Circle.py | 63 +++++ .../Test/TestSAMConverter_Constraints.py | 45 ++++ .../Test/TestSAMConverter_Distance.py | 73 +++++ .../Test/TestSAMConverter_Geometrical.py | 253 ++++++++++++++++++ .../TestSAMConverter_HorisontalDistance.py | 101 +++++++ .../Test/TestSAMConverter_Length.py | 48 ++++ .../Test/TestSAMConverter_Line.py | 69 +++++ .../Test/TestSAMConverter_Point.py | 59 ++++ .../Test/TestSAMConverter_Primitives.py | 15 ++ .../Test/TestSAMConverter_Radius.py | 46 ++++ .../Test/TestSAMConverter_VerticalDistance.py | 100 +++++++ src/SAMConverter/Test/tests.set | 17 +- src/SAMConverterAPI/CMakeLists.txt | 12 +- src/SAMConverterAPI/Test/data/cube_ascii.stl | 86 ------ src/SAMConverterAPI/Test/data/cube_binary.stl | Bin 684 -> 0 bytes 25 files changed, 1102 insertions(+), 141 deletions(-) create mode 100644 src/SAMConverter/SAMConverter_Logger.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Angle.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Arc.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Circle.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Distance.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Geometrical.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Length.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Line.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Point.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_Radius.py create mode 100644 src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py delete mode 100644 src/SAMConverterAPI/Test/data/cube_ascii.stl delete mode 100644 src/SAMConverterAPI/Test/data/cube_binary.stl diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d84c7e26..3b8dfb1e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,18 +191,13 @@ ADD_SUBDIRECTORY (src/SketchSolver) ADD_SUBDIRECTORY (src/ModuleBase) ADD_SUBDIRECTORY (src/PartSet) -# -#ADD_SUBDIRECTORY (src/SketchConstraintsFinder) # Plugin -ADD_SUBDIRECTORY (src/SAMConverter) # Library -ADD_SUBDIRECTORY (src/SAMConverterAPI) -# - ADD_SUBDIRECTORY (src/XGUI) ADD_SUBDIRECTORY (src/ExchangePlugin) ADD_SUBDIRECTORY (src/GeomValidators) ADD_SUBDIRECTORY (src/FiltersPlugin) ADD_SUBDIRECTORY (src/InitializationPlugin) ADD_SUBDIRECTORY (src/ParametersPlugin) +ADD_SUBDIRECTORY (src/SAMConverter) ADD_SUBDIRECTORY (src/PythonAddons) ADD_SUBDIRECTORY (src/PythonAPI) # High Level C++/Python API @@ -219,6 +214,7 @@ ADD_SUBDIRECTORY (src/SketchAPI) ADD_SUBDIRECTORY (src/GDMLAPI) ADD_SUBDIRECTORY (src/ConnectorAPI) ADD_SUBDIRECTORY (src/FiltersAPI) +ADD_SUBDIRECTORY (src/SAMConverterAPI) # Tests ADD_SUBDIRECTORY (test.API/SHAPER) diff --git a/src/SAMConverter/SAMConverter_ConvertConstraints.py b/src/SAMConverter/SAMConverter_ConvertConstraints.py index 85db2e9fd..f6bbec7c3 100644 --- a/src/SAMConverter/SAMConverter_ConvertConstraints.py +++ b/src/SAMConverter/SAMConverter_ConvertConstraints.py @@ -10,6 +10,12 @@ def get_params_value(entity): try : value_attr = entity.feature().real("ConstraintValue") if value_attr is not None: + # Constraint value is negative in following cases: + # For horizontal distance: if first primitive is to the right of the second + # For vertical distance: if first primitive is to the above of the second + # For angle: if the angle is counted counterclockwise + if "Distance" in entity.getKind() or "Angle" in entity.getKind(): + return abs(value_attr.value()) return value_attr.value() except Exception as e : logger.info(f'Problem with constraint parameters: {e}') diff --git a/src/SAMConverter/SAMConverter_ConvertSketch.py b/src/SAMConverter/SAMConverter_ConvertSketch.py index 40d6ed6cf..792655b16 100644 --- a/src/SAMConverter/SAMConverter_ConvertSketch.py +++ b/src/SAMConverter/SAMConverter_ConvertSketch.py @@ -21,7 +21,6 @@ def convert_sketch(sketch: object): # a shaper sketch if feat is not None : entity = SketchAPI_SketchEntity(feat) entity_type = entity.getKind() - print(entity_type) convert, update_mapping = ShapertoSAMPrimitive.convert(entity) if convert is not None: @@ -42,6 +41,8 @@ def convert_sketch(sketch: object): # a shaper sketch entity_type = entity.getKind() if 'Constraint' in entity_type : + if entity_type == 'SuggestConstraints': + continue refs = [] l_attributs = [entity.refattr("ConstraintEntityA"), entity.refattr("ConstraintEntityB"), entity.refattr("ConstraintEntityC"), entity.refattr("ConstraintEntityD")] diff --git a/src/SAMConverter/SAMConverter_Logger.py b/src/SAMConverter/SAMConverter_Logger.py new file mode 100644 index 000000000..2a3f3b144 --- /dev/null +++ b/src/SAMConverter/SAMConverter_Logger.py @@ -0,0 +1,4 @@ +import logging + +logging.basicConfig(level=logging.DEBUG) +logger = logging.getLogger() diff --git a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py index 794d686c2..785f73e68 100644 --- a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py +++ b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py @@ -26,12 +26,13 @@ from SAMConverter_ConvertConstraints import * import ModelAPI import EventsAPI - from SketchAPI import * import salome from salome.shaper import model - +from GeomDataAPI import * +from ModelAPI import * +import math import os ## @ingroup Plugins @@ -71,7 +72,7 @@ class SuggestConstraintsFeature(ModelAPI.ModelAPI_Feature): pass ## Check that sketch can convert in SAM format - def isConvertedSketch(self, sketch): + def isConvertedSketch(self): avaliable_elements = ['SketchConstraintAngle', 'SketchConstraintCoincidence', 'SketchConstraintDistance', @@ -93,13 +94,15 @@ class SuggestConstraintsFeature(ModelAPI.ModelAPI_Feature): nonConvertablePrimitive = [] nonConvertableConstraint = [] - for sub in sketch.features().list(): + for sub in self.Sketch.features().list(): feat = ModelAPI.objectToFeature(sub) if feat is None : continue entity = SketchAPI_SketchEntity(feat) entity_type = entity.getKind() + if entity_type == 'SuggestConstraints': + continue if not entity_type in avaliable_elements: if 'Constraint' in entity_type : nonConvertableConstraint.append(entity_type) @@ -110,14 +113,24 @@ class SuggestConstraintsFeature(ModelAPI.ModelAPI_Feature): ## convert result in SAM format def convertToSAM(self): ## Check that all primitives and constraints is compability with SAM - nonConvertablePrimitive, nonConvertableConstraint = self.isConvertedSketch(aSketch) + nonConvertablePrimitive, nonConvertableConstraint = self.isConvertedSketch() if len(nonConvertablePrimitive) > 0 or len(nonConvertableConstraint) > 0 : - print("Primitives and constraints are incompatible with the SAM format. The sequence therefore cannot be translated.") - print(f'List of primitives not compatible with SAM: {nonConvertablePrimitive}') - print(f'List of constraints not compatible with SAM: {nonConvertableConstraint}') + logger.debug("SuggestConstraints", f'Primitives and constraints are incompatible with the SAM format. The sequence therefore cannot be translated.') + if len(nonConvertablePrimitive) > 0: + logger.debug("SuggestConstraints", f'List of primitives not compatible with SAM: {nonConvertablePrimitive}') + if len(nonConvertableConstraint) > 0: + logger.debug(f'List of constraints not compatible with SAM: {nonConvertableConstraint}') + ### For users + EventsAPI.Events_InfoMessage("SuggestConstraints", f'Impossible to apply the suggested constraints.', self).send() + if len(nonConvertablePrimitive) == 0: + EventsAPI.Events_InfoMessage("SuggestConstraints", f'The constraints {nonConvertableConstraint} are not currently taken into account by the model.', self).send() + elif len(nonConvertableConstraint) == 0: + EventsAPI.Events_InfoMessage("SuggestConstraints", f'The primitives: {nonConvertablePrimitive} are not currently taken into account by the model.', self).send() + else: + EventsAPI.Events_InfoMessage("SuggestConstraints", f'The primitives: {nonConvertablePrimitive} and constraints {nonConvertableConstraint} are not currently taken into account by the model.', self).send() return - convert_sketch(aSketch) + exchange_elements = convert_sketch(self.Sketch) print("SuggestConstraintsFeature: convertToSAM") pass diff --git a/src/SAMConverter/SAMConverter_msg_fr.ts b/src/SAMConverter/SAMConverter_msg_fr.ts index 10b7aeadb..0a0273ba9 100644 --- a/src/SAMConverter/SAMConverter_msg_fr.ts +++ b/src/SAMConverter/SAMConverter_msg_fr.ts @@ -4,8 +4,12 @@ SketchToSAMConverter - Impossible to apply the suggested constraints. The primitives %1 and constraints %2 are not currently considered by the model. - Impossible d'appliquer la suggestion de contraintes. Les primitives %1 et contraintes %2 ne sont pour le moment pas prises en compte par le modele. + Primitives and constraints are incompatible with the SAM format. The sequence therefore cannot be translated. List of primitives not compatible with SAM: % 1. List of constraints not compatible with SAM: %2 + Les primitives et les contraintes sont incompatibles avec le format SAM. La séquence ne peut donc pas être traduite. Liste des primitives non compatibles avec SAM: %1. Liste des contraintes non compatibles avec SAM: %2 + + + Impossible to apply the suggested constraints. The primitives: %1 and constraints %2 are not currently taken into account by the model. + Impossible d'appliquer les contraintes proposées. Les primitives : %1 et les contraintes %2 ne sont actuellement pas prises en compte par le modèle diff --git a/src/SAMConverter/Test/CMakeLists.txt b/src/SAMConverter/Test/CMakeLists.txt index affb127af..e8a3d70f5 100644 --- a/src/SAMConverter/Test/CMakeLists.txt +++ b/src/SAMConverter/Test/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 CEA/DEN, EDF R&D +# Copyright (C) 2014-2022 CEA/DEN, EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -17,26 +17,30 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -include(tests.set) +INCLUDE(tests.set) -ADD_UNIT_TESTS(${TEST_NAMES}) +SET(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/SAMConverter") -if(${HAVE_SALOME}) - enable_testing() - set(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/SAMConverter") +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) - install(FILES CTestTestfileInstall.cmake - DESTINATION ${TEST_INSTALL_DIRECTORY} - RENAME CTestTestfile.cmake) - install(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) - set(TMP_TESTS_NAMES) - foreach(tfile ${TEST_NAMES}) - list(APPEND TMP_TESTS_NAMES "${tfile}") - endforeach(tfile ${TEST_NAMES}) +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(NAME ${TEST_NAME} + COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_CURRENT_SOURCE_DIR}/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES ENVIRONMENT "${tests_env};SHAPER_UNIT_TEST_IN_PROGRESS=1") + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() - # tests which require SHAPER_SUGGESTION_GENERATOR - install(DIRECTORY data DESTINATION ${TEST_INSTALL_DIRECTORY}) +# salome test +FOREACH(tfile ${TEST_NAMES}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py + DESTINATION ${TEST_INSTALL_DIRECTORY}) +ENDFOREACH() - install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY}) -endif(${HAVE_SALOME}) +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${TEST_INSTALL_DIRECTORY} + RENAME CTestTestfile.cmake) + +INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) +INSTALL(DIRECTORY data DESTINATION ${TEST_INSTALL_DIRECTORY}) diff --git a/src/SAMConverter/Test/CTestTestfileInstall.cmake b/src/SAMConverter/Test/CTestTestfileInstall.cmake index fd3d28560..798d8a908 100644 --- a/src/SAMConverter/Test/CTestTestfileInstall.cmake +++ b/src/SAMConverter/Test/CTestTestfileInstall.cmake @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 CEA/DEN, EDF R&D +# Copyright (C) 2016-2022 CEA/DEN, EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -17,10 +17,15 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -include(tests.set) +INCLUDE(tests.set) -foreach(tfile ${TEST_NAMES}) - set(TEST_NAME ${COMPONENT_NAME}_${tfile}) - add_test(${TEST_NAME} python ${tfile}) - set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${SALOME_TEST_LABEL_ADV}") -endforeach() +SET(COMPONENT_NAME SHAPER) +SET(PYTHON_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/python_test_driver.py") +SET(TIMEOUT 300) + + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(${TEST_NAME} python ${PYTHON_TEST_DRIVER} ${TIMEOUT} ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() diff --git a/src/SAMConverter/Test/TestSAMConverter_Angle.py b/src/SAMConverter/Test/TestSAMConverter_Angle.py new file mode 100644 index 000000000..bd4e3969d --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Angle.py @@ -0,0 +1,43 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * + +from salome.shaper import model + +class TestConvertAngle(unittest.TestCase): + + def test_convert_angle_Line_Line(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Add primitives + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchLine_2 = Sketch_1.addLine(-3.9, 1., 8, 0.5) + SketchCoincident = Sketch_1.setAngle(SketchLine_1.result(), SketchLine_2.result(), 40) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_line2, _ = ShapertoSAMPrimitive.convert(SketchLine_2) + sam_constraint = ShapertoSAMConstraints.convert(SketchCoincident, refs = [sam_line1, sam_line2]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'ANGLE') + + # Check Angle value + self.assertEqual(sam_constraint.angle, 40) + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + self.assertEqual(sam_constraint.references[1], sam_line2) diff --git a/src/SAMConverter/Test/TestSAMConverter_Arc.py b/src/SAMConverter/Test/TestSAMConverter_Arc.py new file mode 100644 index 000000000..69e61baca --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Arc.py @@ -0,0 +1,94 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertPrimitives import * + + +from salome.shaper import model +from sam.catalog_primitive import Arc, Line, Circle, Point +from math import sqrt, acos, degrees, fabs + + + + +def compute_parameter(center_x, center_y, start_x, start_y, end_x, end_y): + center = (center_x, center_y) + + # First step, translate the arc such that center became the origin + start_2_x = start_x - center_x + start_2_y = start_y - center_y + end_2_x = end_x - center_x + end_2_y = end_y - center_y + + # Compute radius + radius_s = sqrt(start_2_x*start_2_x + start_2_y*start_2_y) + radius_e = sqrt(end_2_x*end_2_x + end_2_y*end_2_y) + + # Compute start angle start and end + angle_s = convert_angle(degrees(acos(start_2_x/radius_s))) + angle_e = convert_angle(degrees(acos(end_2_x/radius_e))) + + return center, (radius_s, radius_e), (angle_s, angle_e) + +class TestConvertArc(unittest.TestCase): + + def test_convert_arc(self): + + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchArc + SketchArc_1 = Sketch_1.addArc(0, 0, 0, 10, 10, 0, False) # center x, center y, start x, start y, endx, endy + SketchArc_2 = Sketch_1.addArc(5., 1, 5.5, 1, 5, 1.5, False) + SketchArc_2.setAuxiliary(True) + model.do() + model.end() + + # Test 1 : SketchArc_1 + sam_arc, mapping_info = ShapertoSAMPrimitive.convert(SketchArc_1) + + # - Verify the circle information + center, (radius_s, radius_e), (angle_s, angle_e) = compute_parameter(0, 0, 0, 10, 10, 0) # compute expected parms + self.assertAlmostEqual(radius_e, radius_s, delta = 10e-5) + self.assertEqual(sam_arc.radius, radius_e) + self.assertEqual(sam_arc.center.x, center[0]) + self.assertEqual(sam_arc.center.y, center[1]) + self.assertEqual(sam_arc.angle_start, angle_s) + self.assertEqual(sam_arc.angle_end, angle_e) + self.assertEqual(sam_arc.radian, False) + self.assertEqual(sam_arc.is_construction(), False) + + # - Verify the mapping information + self.assertIn((0.0, 0.0, 'SketchArc_1'), mapping_info) + self.assertEqual(str(mapping_info[(0.0, 0.0, 'SketchArc_1')]), 'Point P(0.0, 0.0)') + + # Test 2 : SketchArc_2 + sam_arc, mapping_info = ShapertoSAMPrimitive.convert(SketchArc_2) + + # - Verify the circle information + center, (radius_s, radius_e), (angle_s, angle_e) = compute_parameter(5., 1, 5.5, 1, 5, 1.5) # compute expected parms + self.assertAlmostEqual(radius_e, radius_s, delta = 10e-5) + self.assertAlmostEqual(sam_arc.radius, radius_e, delta = 10e-2) + self.assertEqual(sam_arc.center.x, center[0]) + self.assertEqual(sam_arc.center.y, center[1]) + self.assertEqual(convert_angle(sam_arc.angle_start), angle_s) + self.assertEqual(convert_angle(sam_arc.angle_end), angle_e) + self.assertEqual(sam_arc.radian, False) + self.assertEqual(sam_arc.is_construction(), True) + + + # - Verify the mapping information + self.assertIn((5.0, 1.0, 'SketchArc_2'), mapping_info) + self.assertEqual(str(mapping_info[(5.0, 1.0, 'SketchArc_2')]), 'Point P(5.0, 1.0)') + + if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/src/SAMConverter/Test/TestSAMConverter_Circle.py b/src/SAMConverter/Test/TestSAMConverter_Circle.py new file mode 100644 index 000000000..6aed96aa4 --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Circle.py @@ -0,0 +1,63 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertPrimitives import * + + +from salome.shaper import model +from sam.catalog_primitive import Arc, Line, Circle, Point + + +class TestConvertCircle(unittest.TestCase): + + def test_convert_circle(self): + + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchCircle_1 = Sketch_1.addCircle(1., 0, 30) + SketchCircle_2 = Sketch_1.addCircle(10., 4, 50) + SketchCircle_2.setAuxiliary(True) + model.do() + model.end() + + # Test 1 : SketchCircle_1 + sam_circle, mapping_info = ShapertoSAMPrimitive.convert(SketchCircle_1) + + # - Verify the circle information + self.assertEqual(sam_circle.radius, 30.0) + self.assertEqual(sam_circle.center.x, 1.) + self.assertEqual(sam_circle.center.y, 0.) + self.assertEqual(sam_circle.is_construction(), False) + + # Verify the mapping information + self.assertIn((1.0, 0.0, 'SketchCircle_1'), mapping_info) + self.assertEqual(str(mapping_info[(1.0, 0.0, 'SketchCircle_1')]), 'Point P(1.0, 0.0)') + + # Test 2 : SketchCircle_2 + sam_circle, mapping_info = ShapertoSAMPrimitive.convert(SketchCircle_2) + + # - Verify the circle information + self.assertEqual(sam_circle.radius, 50.0) + self.assertEqual(sam_circle.center.x, 10.) + self.assertEqual(sam_circle.center.y, 4.) + self.assertEqual(sam_circle.is_construction(), True) + + # Verify the mapping information + self.assertIn((10.0, 4.0, 'SketchCircle_2'), mapping_info) + self.assertEqual(str(mapping_info[(10.0, 4.0, 'SketchCircle_2')]), 'Point P(10.0, 4.0)') + + + self.assertTrue(True) + if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/src/SAMConverter/Test/TestSAMConverter_Constraints.py b/src/SAMConverter/Test/TestSAMConverter_Constraints.py index 8b1378917..0782f8b7e 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Constraints.py +++ b/src/SAMConverter/Test/TestSAMConverter_Constraints.py @@ -1 +1,46 @@ +from TestSAMConverter_Angle import TestConvertAngle +from TestSAMConverter_Distance import TestConvertDistance +from TestSAMConverter_Geometrical import TestConvertGeometrical +from TestSAMConverter_HorisontalDistance import TestConverHorizontalDistance +from TestSAMConverter_Length import TestConvertLength +from TestSAMConverter_Radius import TestConvertRadius +from TestSAMConverter_VerticalDistance import TestConvertVerticalDistance +### convert angle test +angle_test = TestConvertAngle() +#angle_test.test_convert_angle() +angle_test.test_convert_angle_Line_Line() + +### convert distance test +dist_test = TestConvertDistance() +dist_test.test_convert_distance_Point_Line() +dist_test.test_convert_distance_Point_Point() + +### convert horizontal distance +hDist_test = TestConverHorizontalDistance() +hDist_test.test_convert_distance_Point_Circle() +hDist_test.test_convert_distance_Point_Line() +hDist_test.test_convert_distance_Point_Point() + +### convert vertical distance +vDist_test = TestConvertVerticalDistance() +vDist_test.test_convert_distance_Point_Circle() +vDist_test.test_convert_distance_Point_Line() +vDist_test.test_convert_distance_Point_Point() + +### convert geometrical constraints test +geom_test = TestConvertGeometrical() +geom_test.test_convert_coincidence() +geom_test.test_convert_equal() +geom_test.test_convert_horizontal() +geom_test.test_convert_midpoint() +geom_test.test_convert_parallel() +geom_test.test_convert_perpendicular() +geom_test.test_convert_tangent() +geom_test.test_convert_vertical() + +len_test = TestConvertLength() +len_test.test_convert_length() + +rad_test = TestConvertRadius() +rad_test.test_convert_radius() diff --git a/src/SAMConverter/Test/TestSAMConverter_Distance.py b/src/SAMConverter/Test/TestSAMConverter_Distance.py new file mode 100644 index 000000000..1d7b3a7c2 --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Distance.py @@ -0,0 +1,73 @@ +import unittest + +import salome +salome.standalone() +from SketchAPI import * + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * + +from salome.shaper import model + +class TestConvertDistance(unittest.TestCase): + + def test_convert_distance_Point_Point(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchPoint + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchPoint_2 = Sketch_1.addPoint(4., 0) + constraint = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchAPI_Point(SketchPoint_2).coordinates(), 2, True) + model.do() + model.end() + + sam_point1, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_point2, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_2) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point1, sam_point2]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'DISTANCE') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_point1) + self.assertEqual(sam_constraint.references[1], sam_point2) + + # Check value + self.assertEqual(sam_constraint.distance_min, 2) + + + def test_convert_distance_Point_Line(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchPoint and SketchLine + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + constraint = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_1.result(), 2, True) + model.do() + model.end() + + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_line, mapping_info = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point, sam_line]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'DISTANCE') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_point) + self.assertEqual(sam_constraint.references[1], sam_line) + + # Check value + self.assertEqual(sam_constraint.distance_min, 2) diff --git a/src/SAMConverter/Test/TestSAMConverter_Geometrical.py b/src/SAMConverter/Test/TestSAMConverter_Geometrical.py new file mode 100644 index 000000000..57621716e --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Geometrical.py @@ -0,0 +1,253 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * + +from salome.shaper import model + +class TestConvertGeometrical(unittest.TestCase): + + def test_convert_coincidence(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchLine + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchLine_2 = Sketch_1.addLine(-3.9, 1., 8, 0.5) + SketchCoincident = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_line2, _ = ShapertoSAMPrimitive.convert(SketchLine_2) + sam_constraint = ShapertoSAMConstraints.convert(SketchCoincident, refs = [sam_line1, sam_line2]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'COINCIDENT') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + self.assertEqual(sam_constraint.references[1], sam_line2) + + # Check references + # - Verify the line 1 information + self.assertEqual(sam_line1.pnt1.x, 3.9) + self.assertEqual(sam_line1.pnt1.y, 0.) + self.assertEqual(sam_line1.pnt2.x, 8) + self.assertEqual(sam_line1.pnt2.y, 0.) + self.assertEqual(sam_line1.is_construction(), False) + + # - Verify the line 2 information + self.assertEqual(sam_line2.pnt1.x, 8.0) + self.assertEqual(sam_line2.pnt1.y, 0.) + self.assertEqual(sam_line2.pnt2.x, 8) + self.assertEqual(sam_line2.pnt2.y, 0.5) + self.assertEqual(sam_line2.is_construction(), False) + + def test_convert_equal(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchLine + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchLine_2 = Sketch_1.addLine(-3.9, 1., 8, 0.5) + constraint = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_2.result()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_line2, _ = ShapertoSAMPrimitive.convert(SketchLine_2) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_line1, sam_line2]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'EQUAL') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + self.assertEqual(sam_constraint.references[1], sam_line2) + + + # Check references + # - Verify the line 1 information + #TODO: The coordinates may differ from expected, but length of line is equal + #self.assertAlmostEqual(sam_line1.pnt1.x, 3.678, delta = 10e-3) + #self.assertEqual(sam_line1.pnt1.y, 0.) + #self.assertAlmostEqual(sam_line1.pnt2.x, 10.846, delta=10e-3) + #self.assertEqual(sam_line1.pnt2.y, 0.) + self.assertEqual(sam_line1.is_construction(), False) + + # - Verify the line 2 information + #self.assertAlmostEqual(sam_line2.pnt1.x, -1.531, delta=10e-3) + #self.assertAlmostEqual(sam_line2.pnt1.y, 0.900, delta=10e-3) + #self.assertAlmostEqual(sam_line2.pnt2.x, 5.631, delta=10e-3) + #self.assertAlmostEqual(sam_line2.pnt2.y, 0.599, delta = 10e-3) + self.assertEqual(sam_line2.is_construction(), False) + + + def test_convert_horizontal(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchLine + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 1) + constraint = Sketch_1.setHorizontal(SketchLine_1.result()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_line1]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'HORIZONTAL') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + + # Check references + # - Verify the line 1 information + self.assertEqual(sam_line1.pnt1.x, 3.9) + self.assertEqual(sam_line1.pnt1.y, 0.) + self.assertEqual(sam_line1.pnt2.x, 8) + self.assertEqual(sam_line1.pnt2.y, 0.) + self.assertEqual(sam_line1.is_construction(), False) + + + def test_convert_midpoint(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchLine and SketchCircle + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchCircle_1 = Sketch_1.addCircle(-17.41591725155751, 16.35177358773851, 29.02191596082682) + constraint = Sketch_1.setMiddlePoint(SketchLine_1.result(), SketchCircle_1.center()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_circle, _ = ShapertoSAMPrimitive.convert(SketchCircle_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_line1, sam_circle]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'MIDPOINT') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + self.assertEqual(sam_constraint.references[1], sam_circle) + + def test_convert_parallel(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchLine_2 = Sketch_1.addLine(-3.9, 1., 8, 0.5) + SketchCoincident = Sketch_1.setParallel(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_line2, _ = ShapertoSAMPrimitive.convert(SketchLine_2) + sam_constraint = ShapertoSAMConstraints.convert(SketchCoincident, refs = [sam_line1, sam_line2]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'PARALLEL') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + self.assertEqual(sam_constraint.references[1], sam_line2) + + def test_convert_perpendicular(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchLine_2 = Sketch_1.addLine(-3.9, 1., 8, 0.5) + SketchCoincident = Sketch_1.setPerpendicular(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_line2, _ = ShapertoSAMPrimitive.convert(SketchLine_2) + sam_constraint = ShapertoSAMConstraints.convert(SketchCoincident, refs = [sam_line1, sam_line2]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'PERPENDICULAR') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + self.assertEqual(sam_constraint.references[1], sam_line2) + + + def test_convert_tangent(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchCircle_1 = Sketch_1.addCircle(-17.41591725155751, 16.35177358773851, 29.02191596082682) + constraint = Sketch_1.setTangent(SketchLine_1.result(), SketchCircle_1.center()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_circle, _ = ShapertoSAMPrimitive.convert(SketchCircle_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_line1, sam_circle]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'TANGENT') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) + self.assertEqual(sam_constraint.references[1], sam_circle) + + + def test_convert_vertical(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + constraint = Sketch_1.setVertical(SketchLine_1.result()) + model.do() + model.end() + + sam_line1, _ = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_line1]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'VERTICAL') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_line1) diff --git a/src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py b/src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py new file mode 100644 index 000000000..c1f075469 --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py @@ -0,0 +1,101 @@ +import unittest + +import salome +salome.standalone() +from SketchAPI import * + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * + +from salome.shaper import model + +class TestConverHorizontalDistance(unittest.TestCase): + + def test_convert_distance_Point_Point(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchPoint_2 = Sketch_1.addPoint(4., 0) + constraint = Sketch_1.setHorizontalDistance(SketchPoint_1.coordinates(), SketchPoint_2.coordinates(), 10) + model.do() + model.end() + + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_line, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_2) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point, sam_line]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'HORIZONTAL_DISTANCE') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_point) + self.assertEqual(sam_constraint.references[1], sam_line) + + # Check value + self.assertEqual(sam_constraint.distance_min, 10.0) + + + def test_convert_distance_Point_Line(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + constraint = Sketch_1.setHorizontalDistance(SketchPoint_1.coordinates(), SketchLine_1.startPoint(), 2) + model.do() + model.end() + + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_line, mapping_info = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point, sam_line]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'HORIZONTAL_DISTANCE') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_point) + self.assertEqual(sam_constraint.references[1], sam_line) + + # Check value + self.assertEqual(sam_constraint.distance_min, 2) + + def test_convert_distance_Point_Circle(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchCircle_1 = Sketch_1.addCircle(-17.41591725155751, 16.35177358773851, 29.02191596082682) + constraint = Sketch_1.setHorizontalDistance( SketchPoint_1.coordinates(), SketchCircle_1.center(), 6) + model.do() + model.end() + + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_circle, mapping_info = ShapertoSAMPrimitive.convert(SketchCircle_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point, sam_circle]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'HORIZONTAL_DISTANCE') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_point) + self.assertEqual(sam_constraint.references[1], sam_circle) + + # Check value + self.assertEqual(sam_constraint.distance_min, 6) diff --git a/src/SAMConverter/Test/TestSAMConverter_Length.py b/src/SAMConverter/Test/TestSAMConverter_Length.py new file mode 100644 index 000000000..6f1e7549f --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Length.py @@ -0,0 +1,48 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * + +from salome.shaper import model + +class TestConvertLength(unittest.TestCase): + + def test_convert_length(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchLength_1 = Sketch_1.setLength(SketchLine_1.result(), 10) + model.do() + model.end() + + sam_line, mapping_info = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_length = ShapertoSAMConstraints.convert(SketchLength_1, refs = [sam_line]) + + # Check type + self.assertEqual(sam_length.get_name(), 'LENGTH') + + # Check Length value + self.assertEqual(sam_length.length, 10) + + # Check references + # - Verify the line information + ref_sam_line = sam_length.references[0] # Check that it is the same instance object + self.assertEqual(sam_line, ref_sam_line) + #TODO: X coordinate may differ from expected, but length is correct + #self.assertAlmostEqual(ref_sam_line.pnt1.x, 0.828, delta=10e-4) # - temporarily commented line + self.assertEqual(ref_sam_line.pnt1.y, 0.) + #self.assertAlmostEqual(ref_sam_line.pnt2.x, 10.828, delta=10e-4) # - temporarily commented line + self.assertEqual(ref_sam_line.pnt2.y, 0.) + self.assertEqual(ref_sam_line.is_construction(), False) diff --git a/src/SAMConverter/Test/TestSAMConverter_Line.py b/src/SAMConverter/Test/TestSAMConverter_Line.py new file mode 100644 index 000000000..2355c3955 --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Line.py @@ -0,0 +1,69 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertPrimitives import * + + +from salome.shaper import model +from sam.catalog_primitive import Arc, Line, Circle, Point + + +class TestConvertLine(unittest.TestCase): + + def test_convert_line(self): + + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchLine + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + SketchLine_2 = Sketch_1.addLine(0., 0, 1., 1) + SketchLine_2.setAuxiliary(True) + model.do() + model.end() + + # Test 1 : SketchLine_1 + sam_line, mapping_info = ShapertoSAMPrimitive.convert(SketchLine_1) + + # - Verify the line information + self.assertEqual(sam_line.pnt1.x, 3.9) + self.assertEqual(sam_line.pnt1.y, 0.) + self.assertEqual(sam_line.pnt2.x, 8) + self.assertEqual(sam_line.pnt2.y, 0.) + self.assertEqual(sam_line.is_construction(), False) + + # - Verify the mapping information + self.assertIn((3.9, 0.0, 'SketchLine_1'), mapping_info) + self.assertIn((8.0, 0.0, 'SketchLine_1'), mapping_info) + self.assertEqual(str(mapping_info[(3.9, 0.0, 'SketchLine_1')]), 'Point P(3.9, 0.0)') + self.assertEqual(str(mapping_info[(8.0, 0.0, 'SketchLine_1')]), 'Point P(8.0, 0.0)') + + # Test 1 : SketchLine_2 + sam_line, mapping_info = ShapertoSAMPrimitive.convert(SketchLine_2) + + # - Verify the line information + self.assertEqual(sam_line.pnt1.x, 0.) + self.assertEqual(sam_line.pnt1.y, 0.) + self.assertEqual(sam_line.pnt2.x, 1.) + self.assertEqual(sam_line.pnt2.y, 1.) + self.assertEqual(sam_line.is_construction(), True) + + # - Verify the mapping information + self.assertIn((0., 0.0, 'SketchLine_2'), mapping_info) + self.assertIn((1., 1., 'SketchLine_2'), mapping_info) + self.assertEqual(str(mapping_info[(0., 0.0, 'SketchLine_2')]), 'Point P(0.0, 0.0)') + self.assertEqual(str(mapping_info[(1., 1., 'SketchLine_2')]), 'Point P(1.0, 1.0)') + + + self.assertTrue(True) + if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/src/SAMConverter/Test/TestSAMConverter_Point.py b/src/SAMConverter/Test/TestSAMConverter_Point.py new file mode 100644 index 000000000..ad551b0f1 --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Point.py @@ -0,0 +1,59 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertPrimitives import * + + +from salome.shaper import model +from sam.catalog_primitive import Arc, Line, Circle, Point + + +class TestConvertPoint(unittest.TestCase): + + def test_convert_point(self): + + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchPoint + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchPoint_2 = Sketch_1.addPoint(10., 4) + SketchPoint_2.setAuxiliary(True) + model.do() + model.end() + + # Test 1 : SketchPoint_1 + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + + # - Verify the point information + self.assertEqual(sam_point.x, 1.) + self.assertEqual(sam_point.y, 0.) + self.assertEqual(sam_point.is_construction(), False) + + # Verify the mapping information + self.assertDictEqual(mapping_info, {}) + + # Test 2 : SketchPoint_2 + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_2) + + # - Verify the point information + self.assertEqual(sam_point.x, 10.) + self.assertEqual(sam_point.y, 4.) + self.assertEqual(sam_point.is_construction(), True) + + # Verify the mapping information + self.assertDictEqual(mapping_info, {}) + + + self.assertTrue(True) + if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/src/SAMConverter/Test/TestSAMConverter_Primitives.py b/src/SAMConverter/Test/TestSAMConverter_Primitives.py index 8b1378917..f8010871d 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Primitives.py +++ b/src/SAMConverter/Test/TestSAMConverter_Primitives.py @@ -1 +1,16 @@ +from TestSAMConverter_Arc import TestConvertArc +from TestSAMConverter_Circle import TestConvertCircle +from TestSAMConverter_Line import TestConvertLine +from TestSAMConverter_Point import TestConvertPoint +line = TestConvertLine() +line.test_convert_line() + +point = TestConvertPoint() +point.test_convert_point() + +arc = TestConvertArc() +arc.test_convert_arc() + +cir = TestConvertCircle() +cir.test_convert_circle() diff --git a/src/SAMConverter/Test/TestSAMConverter_Radius.py b/src/SAMConverter/Test/TestSAMConverter_Radius.py new file mode 100644 index 000000000..1deb20421 --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_Radius.py @@ -0,0 +1,46 @@ +import unittest + +import salome +salome.standalone() + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * + +from salome.shaper import model + +class TestConvertRadius(unittest.TestCase): + + def test_convert_radius(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchCircle + SketchCircle_1 = Sketch_1.addCircle(0, 0, 30) + SketchRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 40) + model.do() + model.end() + + sam_circle, mapping_info = ShapertoSAMPrimitive.convert(SketchCircle_1) + sam_radius = ShapertoSAMConstraints.convert(SketchRadius_1, refs = [sam_circle]) + + # Check type + self.assertEqual(sam_radius.get_name(), 'RADIUS') + + # Check Radius value + self.assertEqual(sam_radius.radius, 40) + + # Check references + # - Verify the circle information + ref_sam_circle = sam_radius.references[0] # Check that it is the same instance object + self.assertEqual(sam_circle, ref_sam_circle) + self.assertEqual(ref_sam_circle.radius, 40.0) + self.assertEqual(ref_sam_circle.center.x, 0.) + self.assertEqual(ref_sam_circle.center.y, 0.) + self.assertEqual(ref_sam_circle.is_construction(), False) diff --git a/src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py b/src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py new file mode 100644 index 000000000..97e2388ad --- /dev/null +++ b/src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py @@ -0,0 +1,100 @@ +import unittest + +import salome +salome.standalone() +from SketchAPI import * + +import sys +sys.path.append('sam') + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * + +from salome.shaper import model + +class TestConvertVerticalDistance(unittest.TestCase): + + def test_convert_distance_Point_Point(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchPoint + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchPoint_2 = Sketch_1.addPoint(4., 0) + constraint = Sketch_1.setVerticalDistance(SketchPoint_1.coordinates(), SketchPoint_2.coordinates(), 10) + model.do() + model.end() + + sam_point1, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_point2, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_2) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point1, sam_point2]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'VERTICAL_DISTANCE') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_point1) + self.assertEqual(sam_constraint.references[1], sam_point2) + + # Check value + self.assertEqual(sam_constraint.distance_min, 10.0) + + + def test_convert_distance_Point_Line(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchPoint and SketchLine + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) + constraint = Sketch_1.setVerticalDistance(SketchPoint_1.coordinates(), SketchLine_1.startPoint(), 2) + model.do() + model.end() + + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_line, mapping_info = ShapertoSAMPrimitive.convert(SketchLine_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point, sam_line]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'VERTICAL_DISTANCE') + + # Check references + self.assertEqual(sam_constraint.references[0], sam_point) + self.assertEqual(sam_constraint.references[1], sam_line) + + # Check value + self.assertEqual(sam_constraint.distance_min, 2) + + def test_convert_distance_Point_Circle(self): + model.begin() + partSet = model.moduleDocument() + + ### Create Sketch + Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + + ### Create SketchPoint and SketchCircle + SketchPoint_1 = Sketch_1.addPoint(1., 0) + SketchCircle_1 = Sketch_1.addCircle(-17.41591725155751, 16.35177358773851, 29.02191596082682) + constraint = Sketch_1.setVerticalDistance( SketchPoint_1.coordinates(), SketchCircle_1.center(), 6) + model.do() + model.end() + + sam_point, mapping_info = ShapertoSAMPrimitive.convert(SketchPoint_1) + sam_circle, mapping_info = ShapertoSAMPrimitive.convert(SketchCircle_1) + sam_constraint = ShapertoSAMConstraints.convert(constraint, refs = [sam_point, sam_circle]) + + # Check type + self.assertEqual(sam_constraint.get_name(), 'VERTICAL_DISTANCE') + # Check references + self.assertEqual(sam_constraint.references[0], sam_point) + self.assertEqual(sam_constraint.references[1], sam_circle) + + # Check value + self.assertEqual(sam_constraint.distance_min, 6) diff --git a/src/SAMConverter/Test/tests.set b/src/SAMConverter/Test/tests.set index 93fe4b60e..86799645c 100644 --- a/src/SAMConverter/Test/tests.set +++ b/src/SAMConverter/Test/tests.set @@ -18,7 +18,18 @@ # SET(TEST_NAMES - TestSAMConverter_Primitives.py - TestSAMConverter_Constraints.py - TestSAMConverter_Sketch.py + TestSAMConverter_Angle + TestSAMConverter_Arc + TestSAMConverter_Circle + TestSAMConverter_Constraints + TestSAMConverter_Distance + TestSAMConverter_Geometrical + TestSAMConverter_HorisontalDistance + TestSAMConverter_Length + TestSAMConverter_Line + TestSAMConverter_Point + TestSAMConverter_Primitives + TestSAMConverter_Radius + TestSAMConverter_Sketch + TestSAMConverter_VerticalDistance ) diff --git a/src/SAMConverterAPI/CMakeLists.txt b/src/SAMConverterAPI/CMakeLists.txt index c1ddd4a66..009a00efb 100644 --- a/src/SAMConverterAPI/CMakeLists.txt +++ b/src/SAMConverterAPI/CMakeLists.txt @@ -49,7 +49,7 @@ INCLUDE_DIRECTORIES( ) #TODO(spo): is ${OpenCASCADE_DEFINITIONS} necessary? -ADD_DEFINITIONS(-DCONNECTORAPI_EXPORTS ${OpenCASCADE_DEFINITIONS}) +ADD_DEFINITIONS(-DSAMCONVERTERAPI_EXPORTS ${OpenCASCADE_DEFINITIONS}) ADD_LIBRARY(SAMConverterAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) TARGET_LINK_LIBRARIES(SAMConverterAPI ${PROJECT_LIBRARIES}) @@ -62,9 +62,9 @@ SET_SOURCE_FILES_PROPERTIES(SAMConverterAPI.i PROPERTIES SWIG_DEFINITIONS "-shad #TODO(spo): is ModelAPI necessary or it could be received by INTERFACE_ (may require modern CMake)? SET(SWIG_LINK_LIBRARIES - SAMConverterAPI ModelHighAPI ModelAPI + SAMConverterAPI ${PYTHON_LIBRARIES} ) @@ -88,10 +88,4 @@ ENDIF(WIN32) INSTALL(TARGETS _SAMConverterAPI DESTINATION ${SHAPER_INSTALL_SWIG}) INSTALL(TARGETS SAMConverterAPI DESTINATION ${SHAPER_INSTALL_BIN}) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/SAMConverterAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) - -# Tests -#IF(${HAVE_SALOME}) -# ENABLE_TESTING() -# ADD_SUBDIRECTORY(Test) -#ENDIF(${HAVE_SALOME}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/SAMConverterAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) \ No newline at end of file diff --git a/src/SAMConverterAPI/Test/data/cube_ascii.stl b/src/SAMConverterAPI/Test/data/cube_ascii.stl deleted file mode 100644 index 125cfe199..000000000 --- a/src/SAMConverterAPI/Test/data/cube_ascii.stl +++ /dev/null @@ -1,86 +0,0 @@ -solid - facet normal -1.000000e+00 0.000000e+00 0.000000e+00 - outer loop - vertex 0.000000e+00 0.000000e+00 0.000000e+00 - vertex 0.000000e+00 8.000000e+00 5.000000e+00 - vertex 0.000000e+00 8.000000e+00 0.000000e+00 - endloop - endfacet - facet normal -1.000000e+00 0.000000e+00 0.000000e+00 - outer loop - vertex 0.000000e+00 0.000000e+00 5.000000e+00 - vertex 0.000000e+00 8.000000e+00 5.000000e+00 - vertex 0.000000e+00 0.000000e+00 0.000000e+00 - endloop - endfacet - facet normal 1.000000e+00 0.000000e+00 0.000000e+00 - outer loop - vertex 1.400000e+01 0.000000e+00 0.000000e+00 - vertex 1.400000e+01 8.000000e+00 0.000000e+00 - vertex 1.400000e+01 8.000000e+00 5.000000e+00 - endloop - endfacet - facet normal 1.000000e+00 -0.000000e+00 0.000000e+00 - outer loop - vertex 1.400000e+01 0.000000e+00 5.000000e+00 - vertex 1.400000e+01 0.000000e+00 0.000000e+00 - vertex 1.400000e+01 8.000000e+00 5.000000e+00 - endloop - endfacet - facet normal 0.000000e+00 -1.000000e+00 -0.000000e+00 - outer loop - vertex 1.400000e+01 0.000000e+00 5.000000e+00 - vertex 0.000000e+00 0.000000e+00 0.000000e+00 - vertex 1.400000e+01 0.000000e+00 0.000000e+00 - endloop - endfacet - facet normal -0.000000e+00 -1.000000e+00 0.000000e+00 - outer loop - vertex 1.400000e+01 0.000000e+00 5.000000e+00 - vertex 0.000000e+00 0.000000e+00 5.000000e+00 - vertex 0.000000e+00 0.000000e+00 0.000000e+00 - endloop - endfacet - facet normal 0.000000e+00 1.000000e+00 0.000000e+00 - outer loop - vertex 1.400000e+01 8.000000e+00 5.000000e+00 - vertex 1.400000e+01 8.000000e+00 0.000000e+00 - vertex 0.000000e+00 8.000000e+00 0.000000e+00 - endloop - endfacet - facet normal 0.000000e+00 1.000000e+00 0.000000e+00 - outer loop - vertex 1.400000e+01 8.000000e+00 5.000000e+00 - vertex 0.000000e+00 8.000000e+00 0.000000e+00 - vertex 0.000000e+00 8.000000e+00 5.000000e+00 - endloop - endfacet - facet normal -0.000000e+00 0.000000e+00 -1.000000e+00 - outer loop - vertex 1.400000e+01 8.000000e+00 0.000000e+00 - vertex 0.000000e+00 0.000000e+00 0.000000e+00 - vertex 0.000000e+00 8.000000e+00 0.000000e+00 - endloop - endfacet - facet normal 0.000000e+00 -0.000000e+00 -1.000000e+00 - outer loop - vertex 1.400000e+01 8.000000e+00 0.000000e+00 - vertex 1.400000e+01 0.000000e+00 0.000000e+00 - vertex 0.000000e+00 0.000000e+00 0.000000e+00 - endloop - endfacet - facet normal 0.000000e+00 0.000000e+00 1.000000e+00 - outer loop - vertex 1.400000e+01 8.000000e+00 5.000000e+00 - vertex 0.000000e+00 8.000000e+00 5.000000e+00 - vertex 0.000000e+00 0.000000e+00 5.000000e+00 - endloop - endfacet - facet normal 0.000000e+00 0.000000e+00 1.000000e+00 - outer loop - vertex 1.400000e+01 8.000000e+00 5.000000e+00 - vertex 0.000000e+00 0.000000e+00 5.000000e+00 - vertex 1.400000e+01 0.000000e+00 5.000000e+00 - endloop - endfacet -endsolid diff --git a/src/SAMConverterAPI/Test/data/cube_binary.stl b/src/SAMConverterAPI/Test/data/cube_binary.stl deleted file mode 100644 index 12ba5f12dbdf132095b13273a8a9cc92ddcdba23..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 684 zcmaivK@Ng25Jh_c5785F1=Aoq6BoEMF0gcoC2CUL^=4kp4#N*qKqVvMB!2P59C=BZLyNEhWFICL~L -- 2.39.2