]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[bos#32539] [EDF] Shaper constrains suggestions - Adaptation of SHAPER model
authorasozinov <alexey.sozinov@opencascade.com>
Mon, 28 Nov 2022 08:28:09 +0000 (11:28 +0300)
committerasozinov <alexey.sozinov@opencascade.com>
Fri, 9 Dec 2022 08:36:04 +0000 (11:36 +0300)
29 files changed:
CMakeLists.txt
src/CTestTestfileInstall.cmake
src/Config/plugins.xml.in
src/SAMConverter/CMakeLists.txt [new file with mode: 0644]
src/SAMConverter/SAMConverter.py [new file with mode: 0644]
src/SAMConverter/SAMConverter_ConvertConstraints.py [new file with mode: 0644]
src/SAMConverter/SAMConverter_ConvertPrimitives.py [new file with mode: 0644]
src/SAMConverter/SAMConverter_ConvertSketch.py [new file with mode: 0644]
src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py [new file with mode: 0644]
src/SAMConverter/SAMConverter_msg_fr.ts [new file with mode: 0644]
src/SAMConverter/Test/CMakeLists.txt [new file with mode: 0644]
src/SAMConverter/Test/CTestTestfileInstall.cmake [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Constraints.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Primitives.py [new file with mode: 0644]
src/SAMConverter/Test/TestSAMConverter_Sketch.py [new file with mode: 0644]
src/SAMConverter/Test/tests.set [new file with mode: 0644]
src/SAMConverter/doc/SAMConverter.rst [new file with mode: 0644]
src/SAMConverter/doc/images/suggest_dialog.png [new file with mode: 0644]
src/SAMConverter/icons/suggest_constraints.png [new file with mode: 0644]
src/SAMConverter/plugin-SAM.xml [new file with mode: 0644]
src/SAMConverterAPI/CMakeLists.txt [new file with mode: 0644]
src/SAMConverterAPI/SAMConverterAPI.h [new file with mode: 0644]
src/SAMConverterAPI/SAMConverterAPI.i [new file with mode: 0644]
src/SAMConverterAPI/SAMConverterAPI_SAMConverter.cpp [new file with mode: 0644]
src/SAMConverterAPI/SAMConverterAPI_SAMConverter.h [new file with mode: 0644]
src/SAMConverterAPI/SAMConverterAPI_swig.h [new file with mode: 0644]
src/SAMConverterAPI/Test/data/cube_ascii.stl [new file with mode: 0644]
src/SAMConverterAPI/Test/data/cube_binary.stl [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml

index 6154d45d9c92a43037ff4cb74f1848ddeebefcec..9d84c7e26e934be27ad8e1abfc4a34333b09aad9 100644 (file)
@@ -191,6 +191,12 @@ 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)
index b9e1c1ebf5728b3d470ef6cd0e3471e320dd0257..591d5ca185b0cb7d22a4e45c0a798fa1f46497ba 100644 (file)
@@ -44,6 +44,7 @@ SUBDIRS(ConnectorAPI
         Config
         ExchangeAPI
         ModelGeomAlgo
+        SAMConverter
         Locale
         test_API
 )
index 7c23b377e2d0a272b04a7b945f0a8e59e7c9c188..c3452b99a44fec31efe0a94eac9364512779fe19 100644 (file)
@@ -15,6 +15,8 @@
   <plugin library="SketchPlugin" configuration="plugin-SketchCopy.xml"/>
   <plugin script="ConnectorPlugin" configuration="plugin-Connector.xml" dependency="GEOM"/>
   <plugin library="ParametersPlugin" configuration="plugin-Parameters.xml"/>
+  <plugin script="SAMConverter" configuration="plugin-SAM.xml"/>
+  <!--<plugin script="SAMConverter" configuration="plugin-SAM.xml" dependency="SAM"/>-->
 @DEFAULT_SOLVER@
 <!--
 @ALL_SOLVERS@
diff --git a/src/SAMConverter/CMakeLists.txt b/src/SAMConverter/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e4988d8
--- /dev/null
@@ -0,0 +1,48 @@
+# 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+INCLUDE(Common)
+INCLUDE(UnitTest)
+
+SET(PYTHON_FILES
+    SAMConverter.py
+    SAMConverter_SuggestConstraintsFeature.py
+    SAMConverter_ConvertSketch.py
+    SAMConverter_ConvertPrimitives.py
+    SAMConverter_ConvertConstraints.py
+    SAMConverter_Logger.py
+)
+
+SET(XML_RESOURCES
+  plugin-SAM.xml
+)
+
+SET(TEXT_RESOURCES
+    SAMConverter_msg_fr.ts
+)
+
+SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES})
+
+ADD_CUSTOM_TARGET(SAMConverter SOURCES ${PYTHON_FILES} ${XML_RESOURCES} ${TEXT_RESOURCES})
+
+INSTALL(FILES ${PYTHON_FILES} DESTINATION ${SHAPER_INSTALL_PYTHON_FILES})
+INSTALL(FILES ${XML_RESOURCES} ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
+INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/SAMConverter)
+
+ADD_SUBDIRECTORY(Test)
\ No newline at end of file
diff --git a/src/SAMConverter/SAMConverter.py b/src/SAMConverter/SAMConverter.py
new file mode 100644 (file)
index 0000000..7cd95b9
--- /dev/null
@@ -0,0 +1,51 @@
+# 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+## @package Plugins
+#  Python plugin for exporting entities into Salome's GEOM module
+
+import ModelAPI
+
+from SAMConverter_SuggestConstraintsFeature import SuggestConstraintsFeature
+
+## @ingroup Plugins
+#  The main class for management the construction features as plugin.
+class SAMConverter(ModelAPI.ModelAPI_Plugin):
+
+    ## The constructor.
+    def __init__(self):
+        ModelAPI.ModelAPI_Plugin.__init__(self)
+        pass
+
+    ## Creates the feature objects of this plugin by the feature string ID.
+    def createFeature(self, theFeatureID):
+        if theFeatureID == SuggestConstraintsFeature.ID():
+            return SuggestConstraintsFeature().__disown__()
+        else:
+            print("SAMConverter: No such feature %s" % theFeatureID)
+
+## The plugin created on module importing (from c++)
+isSHAPER_SUGGESTION_GENERATOR = True
+#TODO
+if isSHAPER_SUGGESTION_GENERATOR:
+    plugin = SAMConverter()
+    ## Main session of the application
+    aSession = ModelAPI.ModelAPI_Session.get()
+    aSession.registerPlugin(plugin)
+    pass
diff --git a/src/SAMConverter/SAMConverter_ConvertConstraints.py b/src/SAMConverter/SAMConverter_ConvertConstraints.py
new file mode 100644 (file)
index 0000000..85db2e9
--- /dev/null
@@ -0,0 +1,64 @@
+from sam.catalog_constraint import *
+
+import math
+
+from SketchAPI import *
+from SAMConverter_Logger import logger
+
+
+def get_params_value(entity):
+    try :
+        value_attr = entity.feature().real("ConstraintValue")
+        if value_attr is not None:
+            return value_attr.value()
+    except Exception as e :
+        logger.info(f'Problem with constraint parameters: {e}')
+    return None
+
+class ShapertoSAMConstraints:
+
+    def convert(entity, refs):
+        entity_type = entity.getKind()
+        if entity_type == 'SketchConstraintAngle':
+            return Angle(references = refs, angle = get_params_value(entity))
+
+        if entity_type == 'SketchConstraintCoincidence':
+            return Coincident(references = refs)
+
+        if entity_type == 'SketchConstraintDistance':
+            return Distance(references = refs, distance_min = get_params_value(entity))
+
+        if entity_type == 'SketchConstraintDistanceHorizontal':
+            return HorizontalDistance(references = refs, distance_min = get_params_value(entity))
+
+        if entity_type == 'SketchConstraintDistanceVertical':
+            return VerticalDistance(references = refs, distance_min = get_params_value(entity))
+
+        if entity_type == 'SketchConstraintEqual':
+            return Equal(references = refs)
+
+        if entity_type == 'SketchConstraintHorizontal':
+            return Horizontal(references = refs)
+
+        if entity_type == 'SketchConstraintMiddle' :
+            return Midpoint(references = refs)
+
+        if entity_type == 'SketchConstraintParallel' :
+            return Parallel(references = refs)
+
+        if entity_type == 'SketchConstraintPerpendicular' :
+            return Perpendicular(references = refs)
+
+        if entity_type == 'SketchConstraintTangent' :
+            return Tangent(references = refs)
+
+        if entity_type == 'SketchConstraintVertical':
+            return Vertical(references = refs)
+
+        if entity_type == 'SketchConstraintRadius':
+            return Radius(references = refs, radius = get_params_value(entity))
+
+        if entity_type == 'SketchConstraintLength':
+            return Length(references = refs, length = get_params_value(entity))
+
+        return None
diff --git a/src/SAMConverter/SAMConverter_ConvertPrimitives.py b/src/SAMConverter/SAMConverter_ConvertPrimitives.py
new file mode 100644 (file)
index 0000000..3243b95
--- /dev/null
@@ -0,0 +1,72 @@
+from sam.catalog_primitive import Arc, Line, Circle, Point
+
+import math
+
+from SketchAPI import *
+from GeomAPI import *
+from SAMConverter_Logger import logger
+
+def convert_angle(angle):
+    a =  int(angle / 360)
+    if math.fabs(angle)  >= 360. :
+        return angle - a * 360
+    else :
+        return angle
+
+class ShapertoSAMPrimitive:
+
+    def convert(entity):
+        entity_type = entity.getKind()
+        if entity_type == 'SketchPoint':
+            return ShapertoSAMPrimitive.convert_point(entity)
+        if entity_type == 'SketchArc':
+            return ShapertoSAMPrimitive.convert_arc(entity)
+        if entity_type == 'SketchCircle':
+            return ShapertoSAMPrimitive.convert_circle(entity)
+        if entity_type == 'SketchLine':
+            return ShapertoSAMPrimitive.convert_line(entity)
+        return None, {}
+
+    def check_construction(entity):
+        auxAttr = entity.auxiliary()
+        return auxAttr is not None and auxAttr.value()
+
+    def convert_point(entity):
+        feat = SketchAPI_Point(entity)
+        p1 = feat.coordinates()
+        return Point(status_construction= ShapertoSAMPrimitive.check_construction(entity), point = [p1.x(), p1.y()]), {}
+
+    def convert_line(entity):
+        feat = SketchAPI_Line(entity)
+
+        p1 = feat.startPoint()
+        p2 = feat.endPoint()
+        line = Line(status_construction=ShapertoSAMPrimitive.check_construction(entity), pnt1= [p1.x(), p1.y()], pnt2= [p2.x(), p2.y()])
+        return line, {(p1.x(), p1.y(), feat.name()) : line.pnt1, (p2.x(), p2.y(), feat.name()) : line.pnt2}
+
+    def convert_circle(entity):
+        feat = SketchAPI_Circle(entity)
+        c = feat.center()
+        radius = feat.radius()
+
+        circle =  Circle(status_construction=ShapertoSAMPrimitive.check_construction(entity),
+                        center = [c.x(), c.y()],
+                        radius= radius.value())#feat.radius().value())
+        return circle, {(c.x(), c.y(), feat.name()) : circle.center}
+
+    def convert_arc(entity):
+        status = ShapertoSAMPrimitive.check_construction(entity)
+        feat = SketchAPI_Arc(entity)
+        c = feat.center()
+        s = entity.defaultResult()
+        edge = GeomAPI_Edge(s.shape())
+        a0,a1 = edge.getRange()
+        start_angle = convert_angle(math.degrees(a0))
+        end_angle = convert_angle(math.degrees(a1))
+
+        arc = Arc(status_construction=status,
+                        center = [c.x(), c.y()],
+                        radius= feat.radius().value(),
+                        angles= [start_angle, end_angle])
+        arc.add_points_startend()
+        return arc, {(c.x(), c.y(), feat.name()) : arc.center}
diff --git a/src/SAMConverter/SAMConverter_ConvertSketch.py b/src/SAMConverter/SAMConverter_ConvertSketch.py
new file mode 100644 (file)
index 0000000..40d6ed6
--- /dev/null
@@ -0,0 +1,63 @@
+from SAMConverter_Logger import logger
+
+from SAMConverter_ConvertPrimitives import ShapertoSAMPrimitive
+from SAMConverter_ConvertConstraints import ShapertoSAMConstraints
+from sam.sketch import Sketch
+
+from ModelAPI import *
+from SketchAPI import *
+from GeomDataAPI import *
+
+
+def convert_sketch(sketch: object): # a shaper sketch
+
+       exchange_sketch = Sketch()
+
+       mapping = {}
+       # Add the primitives
+       for sub in sketch.features().list():
+               feat =  ModelAPI.objectToFeature(sub)
+
+               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:
+                               mapping[entity.name()] = convert
+
+                       mapping.update(update_mapping)
+
+                       if convert is not None:
+                               exchange_sketch.add(convert)
+
+       logger.debug(f'Mapping; {mapping}')
+
+       # Add the constraints
+       sketchFeature = featureToCompositeFeature(sketch.feature())
+       n = sketchFeature.numberOfSubs()
+       for i in range(n):
+               entity = sketchFeature.subFeature(i)
+               entity_type = entity.getKind()
+
+               if 'Constraint' in entity_type :
+                       refs = []
+                       l_attributs = [entity.refattr("ConstraintEntityA"), entity.refattr("ConstraintEntityB"),
+                                               entity.refattr("ConstraintEntityC"), entity.refattr("ConstraintEntityD")]
+                       for ref in l_attributs:
+                               if ref is None: continue
+                               if ref.isObject():
+                                       attr = ModelAPI_Feature.feature(ref.object())
+                                       refs.append(mapping[attr.name()])
+
+                               else :
+                                       attr = ref.attr()
+                                       owner = objectToFeature(attr.owner())
+                                       elt = geomDataAPI_Point2D(attr).pnt()
+                                       refs.append(mapping.get((elt.x(), elt.y(), owner.name()), owner.name()))
+
+                       convert = ShapertoSAMConstraints.convert(entity, refs)
+                       exchange_sketch.add(convert)
+
+       return exchange_sketch
diff --git a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py
new file mode 100644 (file)
index 0000000..794d686
--- /dev/null
@@ -0,0 +1,140 @@
+# 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+## @package Plugins
+#  SuggestConstraintsFeature class definition
+
+from SAMConverter_ConvertSketch import *
+from SAMConverter_ConvertPrimitives import *
+from SAMConverter_ConvertConstraints import *
+
+import ModelAPI
+import EventsAPI
+
+from SketchAPI import *
+import salome
+
+from salome.shaper import model
+
+import os
+
+## @ingroup Plugins
+#  Feature to suggest constraints using a Machine Learning model
+class SuggestConstraintsFeature(ModelAPI.ModelAPI_Feature):
+
+    ## The constructor.
+    def __init__(self):
+        ModelAPI.ModelAPI_Feature.__init__(self)
+        pass
+
+    @staticmethod
+    ## Export kind. Static.
+    def ID():
+        return "SuggestConstraints"
+
+    ## Returns the kind of a feature.
+    def getKind(self):
+        return SuggestConstraintsFeature.ID()
+
+    ## True: This feature is action: has no property panel and executes immediately.
+    ## False: Otherwise.
+    def isAction(self):
+        return False
+        #TODO
+        #return True
+
+    def isMacro(self):
+        """
+        Override Feature.isMacro().
+        Rectangle feature is macro: removes itself on the creation transaction finish.
+        """
+        return True
+
+    ## Init attributes
+    def initAttributes(self):
+        pass
+
+    ## Check that sketch can convert in SAM format
+    def isConvertedSketch(self, sketch):
+        avaliable_elements = ['SketchConstraintAngle',
+                              'SketchConstraintCoincidence',
+                              'SketchConstraintDistance',
+                              'SketchConstraintDistanceHorizontal',
+                              'SketchConstraintDistanceVertical',
+                              'SketchConstraintEqual',
+                              'SketchConstraintHorizontal',
+                              'SketchConstraintMiddle',
+                              'SketchConstraintParallel',
+                              'SketchConstraintPerpendicular',
+                              'SketchConstraintTangent',
+                              'SketchConstraintVertical',
+                              'SketchConstraintRadius',
+                              'SketchConstraintLength',
+                              'SketchPoint',
+                              'SketchArc',
+                              'SketchCircle',
+                              'SketchLine']
+        nonConvertablePrimitive = []
+        nonConvertableConstraint = []
+
+        for sub in sketch.features().list():
+            feat =  ModelAPI.objectToFeature(sub)
+            if feat is None :
+                continue
+
+            entity = SketchAPI_SketchEntity(feat)
+            entity_type = entity.getKind()
+            if not entity_type in avaliable_elements:
+                if 'Constraint' in entity_type :
+                    nonConvertableConstraint.append(entity_type)
+                else:
+                    nonConvertablePrimitive.append(entity_type)
+        return nonConvertablePrimitive, nonConvertableConstraint
+
+    ## convert result in SAM format
+    def convertToSAM(self):
+        ## Check that all primitives and constraints is compability with SAM
+        nonConvertablePrimitive, nonConvertableConstraint = self.isConvertedSketch(aSketch)
+        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}')
+            return
+
+        convert_sketch(aSketch)
+        print("SuggestConstraintsFeature: convertToSAM")
+
+        pass
+
+    ## Exports all shapes and groups into the GEOM module.
+    def execute(self):
+        ## Find skecth
+        aSession = ModelAPI.ModelAPI_Session.get()
+        aPartSet = aSession.moduleDocument()
+        self.Part = model.activeDocument()
+        for feat in self.Part.allFeatures():
+            if feat.getKind() == "Sketch":
+                self.Sketch = SketchAPI_Sketch(feat)
+                break
+
+        print("SuggestConstraintsFeature: execute")
+        self.convertToSAM()
+        # TODO: Lot3 and Lot4
+
+        pass
diff --git a/src/SAMConverter/SAMConverter_msg_fr.ts b/src/SAMConverter/SAMConverter_msg_fr.ts
new file mode 100644 (file)
index 0000000..10b7aea
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0" language="fr_FR">
+  <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>
+    </message>
+  </context>
+</TS>
diff --git a/src/SAMConverter/Test/CMakeLists.txt b/src/SAMConverter/Test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..affb127
--- /dev/null
@@ -0,0 +1,42 @@
+# Copyright (C) 2021-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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+include(tests.set)
+
+ADD_UNIT_TESTS(${TEST_NAMES})
+
+if(${HAVE_SALOME})
+  enable_testing()
+  set(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/SAMConverter")
+
+  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})
+
+  # tests which require SHAPER_SUGGESTION_GENERATOR
+  install(DIRECTORY data DESTINATION ${TEST_INSTALL_DIRECTORY})
+
+  install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY})
+endif(${HAVE_SALOME})
diff --git a/src/SAMConverter/Test/CTestTestfileInstall.cmake b/src/SAMConverter/Test/CTestTestfileInstall.cmake
new file mode 100644 (file)
index 0000000..fd3d285
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright (C) 2021-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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+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()
diff --git a/src/SAMConverter/Test/TestSAMConverter_Constraints.py b/src/SAMConverter/Test/TestSAMConverter_Constraints.py
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/src/SAMConverter/Test/TestSAMConverter_Primitives.py b/src/SAMConverter/Test/TestSAMConverter_Primitives.py
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/src/SAMConverter/Test/TestSAMConverter_Sketch.py b/src/SAMConverter/Test/TestSAMConverter_Sketch.py
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/src/SAMConverter/Test/tests.set b/src/SAMConverter/Test/tests.set
new file mode 100644 (file)
index 0000000..93fe4b6
--- /dev/null
@@ -0,0 +1,24 @@
+# Copyright (C) 2021-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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+SET(TEST_NAMES
+               TestSAMConverter_Primitives.py
+               TestSAMConverter_Constraints.py
+               TestSAMConverter_Sketch.py
+)
diff --git a/src/SAMConverter/doc/SAMConverter.rst b/src/SAMConverter/doc/SAMConverter.rst
new file mode 100644 (file)
index 0000000..b31249d
--- /dev/null
@@ -0,0 +1,14 @@
+
+.. _sAMPlugin:
+
+SAM plug-in
+================
+
+SAM plug-in implements features for Sketch conversion to SAM format and to call Suggest Constraints macro.
+It provides the following features:
+
+.. toctree::
+   :titlesonly:
+   :maxdepth: 1
+
+   suggestConstraintsFeature.rst
diff --git a/src/SAMConverter/doc/images/suggest_dialog.png b/src/SAMConverter/doc/images/suggest_dialog.png
new file mode 100644 (file)
index 0000000..02c810b
Binary files /dev/null and b/src/SAMConverter/doc/images/suggest_dialog.png differ
diff --git a/src/SAMConverter/icons/suggest_constraints.png b/src/SAMConverter/icons/suggest_constraints.png
new file mode 100644 (file)
index 0000000..196cf55
Binary files /dev/null and b/src/SAMConverter/icons/suggest_constraints.png differ
diff --git a/src/SAMConverter/plugin-SAM.xml b/src/SAMConverter/plugin-SAM.xml
new file mode 100644 (file)
index 0000000..d25fdfd
--- /dev/null
@@ -0,0 +1,12 @@
+<plugin>
+  <workbench id="Sketch">
+    <group id="Automatic constraints">
+      <feature
+        id="SuggestConstraints"
+        title="Suggest constraints"
+        tooltip="Suggest constraints using a Machine Learning model"
+        icon="icons/SAM/suggest_constraints.png"
+        helpfile="SAMConverter/SAMPlugin.html"/>
+    </group>
+  </workbench>
+</plugin>
diff --git a/src/SAMConverterAPI/CMakeLists.txt b/src/SAMConverterAPI/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c1ddd4a
--- /dev/null
@@ -0,0 +1,97 @@
+# 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+INCLUDE(Common)
+
+SET(PROJECT_HEADERS
+  SAMConverterAPI.h
+  SAMConverterAPI_SAMConverter.h
+)
+
+SET(PROJECT_SOURCES
+  SAMConverterAPI_SAMConverter.cpp
+)
+
+SET(PROJECT_LIBRARIES
+  ModelAPI
+  ModelHighAPI
+)
+
+INCLUDE_DIRECTORIES(
+  ${PROJECT_SOURCE_DIR}/src/Events
+  ${PROJECT_SOURCE_DIR}/src/ModelAPI
+  ${PROJECT_SOURCE_DIR}/src/ModelHighAPI
+)
+
+# Plugin headers dependency
+INCLUDE_DIRECTORIES(
+  # TODO(spo): modify ConnectorPlugin headers to remove dependency on GeomAPI headers
+  ${PROJECT_SOURCE_DIR}/src/GeomAPI
+  # TODO(spo): it is for *_swig.h files. Can we eliminate it?
+  ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+  ${PROJECT_SOURCE_DIR}/src/SAMConverter
+)
+
+#TODO(spo): is ${OpenCASCADE_DEFINITIONS} necessary?
+ADD_DEFINITIONS(-DCONNECTORAPI_EXPORTS ${OpenCASCADE_DEFINITIONS})
+ADD_LIBRARY(SAMConverterAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+TARGET_LINK_LIBRARIES(SAMConverterAPI ${PROJECT_LIBRARIES})
+
+# SWIG wrapper
+
+INCLUDE(PythonAPI)
+
+SET_SOURCE_FILES_PROPERTIES(SAMConverterAPI.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(SAMConverterAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+
+#TODO(spo): is ModelAPI necessary or it could be received by INTERFACE_ (may require modern CMake)?
+SET(SWIG_LINK_LIBRARIES
+  SAMConverterAPI
+  ModelHighAPI
+  ModelAPI
+  ${PYTHON_LIBRARIES}
+)
+
+SET(SWIG_MODULE_SAMConverterAPI_EXTRA_DEPS ${SWIG_MODULE_SAMConverterAPI_EXTRA_DEPS}
+  ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i
+  doxyhelp.i
+  ${PROJECT_HEADERS}
+)
+SET(CMAKE_SWIG_FLAGS -threads -w325,321,302,362,322,383,403)
+
+IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0")
+  SWIG_ADD_LIBRARY(SAMConverterAPI LANGUAGE python SOURCES SAMConverterAPI.i ${PROJECT_HEADERS})
+ELSE()
+  SWIG_ADD_MODULE(SAMConverterAPI python SAMConverterAPI.i ${PROJECT_HEADERS})
+ENDIF()
+SWIG_LINK_LIBRARIES(SAMConverterAPI ${SWIG_LINK_LIBRARIES})
+
+IF(WIN32)
+  SET_TARGET_PROPERTIES(_SAMConverterAPI PROPERTIES DEBUG_OUTPUT_NAME _SAMConverterAPI_d)
+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})
diff --git a/src/SAMConverterAPI/SAMConverterAPI.h b/src/SAMConverterAPI/SAMConverterAPI.h
new file mode 100644 (file)
index 0000000..84f91fd
--- /dev/null
@@ -0,0 +1,37 @@
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SAMCONVERTERAPI_H
+#define SAMCONVERTERAPI_H
+
+#if defined SAMCONVERTERAPI_EXPORTS
+#if defined WIN32
+#define SAMCONVERTERAPI_EXPORT __declspec( dllexport )
+#else
+#define SAMCONVERTERAPI_EXPORT
+#endif
+#else
+#if defined WIN32
+#define SAMCONVERTERAPI_EXPORT __declspec( dllimport )
+#else
+#define SAMCONVERTERAPI_EXPORT
+#endif
+#endif
+
+#endif
diff --git a/src/SAMConverterAPI/SAMConverterAPI.i b/src/SAMConverterAPI/SAMConverterAPI.i
new file mode 100644 (file)
index 0000000..a61cdf6
--- /dev/null
@@ -0,0 +1,41 @@
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+/* SAMConverterAPI.i */
+
+%module SAMConverterAPI
+
+%{
+  #include "SAMConverterAPI_swig.h"
+%}
+
+%include "doxyhelp.i"
+
+// import other modules
+%import "ModelHighAPI.i"
+
+// to avoid error on this
+#define SAMCONVERTERAPI_EXPORT
+
+// standard definitions
+%include "typemaps.i"
+%include "std_shared_ptr.i"
+
+// all supported interfaces
+%include "SAMConverterAPI_SAMConverter.h"
diff --git a/src/SAMConverterAPI/SAMConverterAPI_SAMConverter.cpp b/src/SAMConverterAPI/SAMConverterAPI_SAMConverter.cpp
new file mode 100644 (file)
index 0000000..5ea46c7
--- /dev/null
@@ -0,0 +1,29 @@
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SAMConverterAPI_SAMConverter.h"
+//--------------------------------------------------------------------------------------
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+//--------------------------------------------------------------------------------------
+void suggestConstraints(const std::shared_ptr<ModelAPI_Document> & thePart)
+{
+  // TODO(spo): check that thePart is not empty
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature("SuggestConstraints");
+}
diff --git a/src/SAMConverterAPI/SAMConverterAPI_SAMConverter.h b/src/SAMConverterAPI/SAMConverterAPI_SAMConverter.h
new file mode 100644 (file)
index 0000000..a4955af
--- /dev/null
@@ -0,0 +1,38 @@
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SRC_SAMCONVERTERAPI_SAMCONVERTERAPI_PART_H_
+#define SRC_SAMCONVERTERAPI_SAMCONVERTERAPI_PART_H_
+
+//--------------------------------------------------------------------------------------
+#include "SAMConverterAPI.h"
+//--------------------------------------------------------------------------------------
+#include <memory>
+//--------------------------------------------------------------------------------------
+class ModelAPI_Document;
+//--------------------------------------------------------------------------------------
+/**\ingroup CPPHighAPI
+ * \brief Export to GEOM
+ */
+SAMCONVERTERAPI_EXPORT
+void suggestConstraints(const std::shared_ptr<ModelAPI_Document> & thePart);
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SAMCONVERTERAPI_SAMCONVERTERAPI_PART_H_ */
diff --git a/src/SAMConverterAPI/SAMConverterAPI_swig.h b/src/SAMConverterAPI/SAMConverterAPI_swig.h
new file mode 100644 (file)
index 0000000..d9c4ee6
--- /dev/null
@@ -0,0 +1,27 @@
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SRC_SAMCONVERTERAPI_SAMCONVERTERAPI_SWIG_H_
+#define SRC_SAMCONVERTERAPI_SAMCONVERTERAPI_SWIG_H_
+
+  #include <ModelHighAPI_swig.h>
+
+  #include "SAMConverterAPI_SAMConverter.h"
+
+#endif /* SRC_SAMCONVERTERAPI_SAMCONVERTERAPI_SWIG_H_ */
diff --git a/src/SAMConverterAPI/Test/data/cube_ascii.stl b/src/SAMConverterAPI/Test/data/cube_ascii.stl
new file mode 100644 (file)
index 0000000..125cfe1
--- /dev/null
@@ -0,0 +1,86 @@
+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
new file mode 100644 (file)
index 0000000..12ba5f1
Binary files /dev/null and b/src/SAMConverterAPI/Test/data/cube_binary.stl differ
index 86b234c51909ff957f29cf0a18559ff0a77ab21a..aaecd91f88ab58a28d18c53852e1f724d007a8ff 100644 (file)
@@ -19,7 +19,7 @@
                 SketchConstraintMirror SketchConstraintAngle
                 SketchMultiRotation SketchMultiTranslation
                 SketchOffset
-                SketchConstraintCollinear SketchConstraintMiddle"
+                SketchConstraintCollinear SketchConstraintMiddle SuggestConstraints"
         when_nested="accept abort"
         title="Sketch"
         tooltip="Create sketch"