]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix problem
authorasozinov <alexey.sozinov@opencascade.com>
Wed, 15 Feb 2023 00:21:55 +0000 (01:21 +0100)
committerasozinov <alexey.sozinov@opencascade.com>
Wed, 15 Feb 2023 01:04:11 +0000 (02:04 +0100)
src/SAMConverter/SAMConverter_ConvertSketch.py
src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py

index 3713a6110ee328285c1b2a74f4bcfff9256efc76..5bdd43b690fe9cb46dea07827e56ec82a90a07de 100644 (file)
@@ -8,6 +8,23 @@ from ModelAPI import *
 from SketchAPI import *
 from GeomDataAPI import *
 
+def convert_subshape(entity, sam_entity, dictionary):
+    sketch_entity = SketchAPI_SketchEntity(entity)
+    entity_type = entity.getKind()
+
+    if entity_type == 'SketchArc':
+        feat = SketchAPI_Arc(entity)
+        dictionary.update({sam_entity.center : feat.center()})
+        dictionary.update({sam_entity.pnt1 : feat.startPoint()})
+        dictionary.update({sam_entity.pnt2 : feat.endPoint()})
+    if entity_type == 'SketchCircle':
+        feat = SketchAPI_Circle(entity)
+        dictionary.update({sam_entity.center : feat.center()})
+    if entity_type == 'SketchLine':
+        feat = SketchAPI_Line(entity)
+        dictionary.update({sam_entity.pnt1 : feat.startPoint()})
+        dictionary.update({sam_entity.pnt2 : feat.endPoint()})
+
 # Convert shaper sketch to SAM format
 def convert_sketch(sketch: object):
     dictionary = {} # dictionary: SAM object (key) : SHAPER object (value)
@@ -48,8 +65,6 @@ def convert_sketch(sketch: object):
 
             if feat is not None :
                 sketch_entity = SketchAPI_SketchEntity(entity)
-                entity_type = entity.getKind()
-                entity_name = entity.name()
 
                 convert, update_mapping = ShapertoSAMPrimitive.convert(sketch_entity)
                 if convert is not None:
@@ -63,5 +78,6 @@ def convert_sketch(sketch: object):
                 if convert is not None:
                     exchange_sketch.add(convert)
                     dictionary.update({convert : sketch_entity})
+                    convert_subshape(sketch_entity, convert, dictionary)
 
     return exchange_sketch, dictionary
index 9f7f61ad2ffb15f3606ba5855b500d12e125cfff..d44b760484750b34624f9d65338838078801c9a1 100644 (file)
@@ -253,6 +253,14 @@ class SuggestConstraintsFeature(ModelAPI.ModelAPI_Feature):
         exchange_elements, dictionary = convert_sketch(self.Sketch)
         return exchange_elements, dictionary
 
+    def generateName(self, primitive):
+        name = ""
+        if isinstance(primitive, GeomDataAPI_Point2D):
+            name = primitive.owner().data().name() + "/" + primitive.id()
+        else:
+            name = primitive.name()
+        return name
+
     # fill attributes for show predicted constraints to the user
     def fillAttributes(self, predicted_list):
         # example: "SUGGESTION_1":{'primitives':[line_1, line_4],
@@ -266,11 +274,14 @@ class SuggestConstraintsFeature(ModelAPI.ModelAPI_Feature):
         for key, value in predicted_list.items():
             self.data().stringArray(self.SUGGESTIONS_ID()).setValue(index, key)
             primitives = value['primitives']
-            self.data().stringArray(self.PRIMITIVES_ID()).setValue(2 * index, self.dictionary[primitives[0]].name())
+
+            name = self.generateName(self.dictionary[primitives[0]])
+            self.data().stringArray(self.PRIMITIVES_ID()).setValue(2 * index, name)
             if len(primitives) == 1:
                 self.data().stringArray(self.PRIMITIVES_ID()).setValue(2 * index + 1, '')
             else:
-                self.data().stringArray(self.PRIMITIVES_ID()).setValue(2 * index + 1, self.dictionary[primitives[1]].name())
+                name = self.generateName(self.dictionary[primitives[1]])
+                self.data().stringArray(self.PRIMITIVES_ID()).setValue(2 * index + 1, name)
 
             self.data().stringArray(self.CONSTRAINTS_ID()).setValue(index, value['suggested_constraint'])
             self.data().stringArray(self.SCORES_ID()).setValue(index, str(value['score']))