]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
bos 32359 - Adaptation of SHAPER model
authorasozinov <alexey.sozinov@opencascade.com>
Fri, 9 Dec 2022 10:12:39 +0000 (13:12 +0300)
committerasozinov <alexey.sozinov@opencascade.com>
Mon, 19 Dec 2022 08:22:43 +0000 (11:22 +0300)
- Added tests
- Fix compilation problem
- Cleanup

25 files changed:
CMakeLists.txt
src/SAMConverter/SAMConverter_ConvertConstraints.py
src/SAMConverter/SAMConverter_ConvertSketch.py
src/SAMConverter/SAMConverter_Logger.py [new file with mode: 0644]
src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py
src/SAMConverter/SAMConverter_msg_fr.ts
src/SAMConverter/Test/CMakeLists.txt
src/SAMConverter/Test/CTestTestfileInstall.cmake
src/SAMConverter/Test/TestSAMConverter_Angle.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Arc.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Circle.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Constraints.py
src/SAMConverter/Test/TestSAMConverter_Distance.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Geometrical.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Length.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Line.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Point.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Primitives.py
src/SAMConverter/Test/TestSAMConverter_Radius.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py [new file with mode: 0644]
src/SAMConverter/Test/tests.set
src/SAMConverterAPI/CMakeLists.txt
src/SAMConverterAPI/Test/data/cube_ascii.stl [deleted file]
src/SAMConverterAPI/Test/data/cube_binary.stl [deleted file]

index 9d84c7e26e934be27ad8e1abfc4a34333b09aad9..3b8dfb1e6f93255175b874979d3d97a76a8d30e8 100644 (file)
@@ -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)
 
index 85db2e9fd9b71900464d7bed25b7d4adc61fc0e4..f6bbec7c3c594cbce18424e37863e380c8d7fb7b 100644 (file)
@@ -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}')
index 40d6ed6cfae8bd4f93cdcd49c4ab655cd7d00df6..792655b162263ebdc172f046d547b04d00fcdb3e 100644 (file)
@@ -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 (file)
index 0000000..2a3f3b1
--- /dev/null
@@ -0,0 +1,4 @@
+import logging
+
+logging.basicConfig(level=logging.DEBUG)
+logger = logging.getLogger()
index 794d686c2c7fcc168fc6be989432fa317e055111..785f73e686c6db7420c30a3a0066b84fc8ad89c2 100644 (file)
@@ -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
index 10b7aeadb57de6d16e58970e6bfa84f2592b35a1..0a0273ba95ce278e6b4909a15ec0cf073976fbe6 100644 (file)
@@ -4,8 +4,12 @@
   <context>
     <name>SketchToSAMConverter</name>
     <message>
-      <source>Impossible to apply the suggested constraints. The primitives %1 and constraints %2 are not currently considered by the model.</source>
-      <translation>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.</translation>
+      <source>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 </source>
+      <translation>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 </translation>
+    </message>
+    <message>
+      <source>Impossible to apply the suggested constraints. The primitives: %1 and constraints %2 are not currently taken into account by the model.</source>
+      <translation>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</translation>
     </message>
   </context>
 </TS>
index affb127af3263745f3144d80d22a73df4c24f0b2..e8a3d70f539652b9b625347933c2c7999512b992 100644 (file)
@@ -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
 # 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})
index fd3d28560231bef0c16452c98ed03e99983b2053..798d8a9087fb83739eec62163d9f66f8a3fe38b2 100644 (file)
@@ -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
 # 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 (file)
index 0000000..bd4e396
--- /dev/null
@@ -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 (file)
index 0000000..69e61ba
--- /dev/null
@@ -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 (file)
index 0000000..6aed96a
--- /dev/null
@@ -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()
index 8b137891791fe96927ad78e64b0aad7bded08bdc..0782f8b7e6fc02d4b74e0362bc1d3b91b42ff912 100644 (file)
@@ -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 (file)
index 0000000..1d7b3a7
--- /dev/null
@@ -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 (file)
index 0000000..5762171
--- /dev/null
@@ -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 (file)
index 0000000..c1f0754
--- /dev/null
@@ -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 (file)
index 0000000..6f1e754
--- /dev/null
@@ -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 (file)
index 0000000..2355c39
--- /dev/null
@@ -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 (file)
index 0000000..ad551b0
--- /dev/null
@@ -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()
index 8b137891791fe96927ad78e64b0aad7bded08bdc..f8010871d11eaca95d1c65b21dca3666dbe626ee 100644 (file)
@@ -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 (file)
index 0000000..1deb204
--- /dev/null
@@ -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 (file)
index 0000000..97e2388
--- /dev/null
@@ -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)
index 93fe4b60e0389c56b58b77a32092f84d6ad16600..86799645cff70bd067d921610ef463eb3325114e 100644 (file)
 #
 
 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
 )
index c1ddd4a664d8e8bb36b4ba4f9c48435247bf2366..009a00efbb54bb1fd976228ac3d2fd8202ad7d9d 100644 (file)
@@ -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 (file)
index 125cfe1..0000000
+++ /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 (file)
index 12ba5f1..0000000
Binary files a/src/SAMConverterAPI/Test/data/cube_binary.stl and /dev/null differ