From d02f806ebd103f7cbf18ad6befda9b0f185b4e83 Mon Sep 17 00:00:00 2001 From: asozinov Date: Wed, 15 Feb 2023 01:21:55 +0100 Subject: [PATCH] Fix problem --- .../SAMConverter_ConvertSketch.py | 20 +++++++++++++++++-- .../SAMConverter_SuggestConstraintsFeature.py | 15 ++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/SAMConverter/SAMConverter_ConvertSketch.py b/src/SAMConverter/SAMConverter_ConvertSketch.py index 3713a6110..5bdd43b69 100644 --- a/src/SAMConverter/SAMConverter_ConvertSketch.py +++ b/src/SAMConverter/SAMConverter_ConvertSketch.py @@ -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 diff --git a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py index 9f7f61ad2..d44b76048 100644 --- a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py +++ b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py @@ -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'])) -- 2.39.2