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)
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:
if convert is not None:
exchange_sketch.add(convert)
dictionary.update({convert : sketch_entity})
+ convert_subshape(sketch_entity, convert, dictionary)
return exchange_sketch, dictionary
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],
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']))