2 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
9 from salome.geom import geomBuilder
12 class ExportFeature(ModelAPI.ModelAPI_Feature):
14 "Feature to create a box by drawing a sketch and extruding it"
17 ModelAPI.ModelAPI_Feature.__init__(self)
24 return ExportFeature.ID()
26 # This feature is action: has no property pannel and executes immideately
30 def isInHistory(self):
33 def initAttributes(self):
34 # This feature has no attributes, but should perform some actions on initialization
35 aSession = ModelAPI.ModelAPI_Session.get()
36 self.Part = aSession.activeDocument()
38 self.geompy = geomBuilder.New(salome.myStudy)
40 # Export bodies and groups
44 def exportBodies(self):
46 kResultBodyType = "Bodies"
47 aPartSize = self.Part.size(kResultBodyType)
49 EventsAPI.Events_Error_send("No results in the active document")
52 anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
53 for idx, anObject in enumerate(anObjList):
54 aResult = ModelAPI.modelAPI_Result(anObject)
55 aBodyResult = ModelAPI.modelAPI_ResultBody(aResult)
58 aShape = aBodyResult.shape()
59 aDump = aShape.getShapeStream()
60 # Load shape to SALOME Geom
61 aBrep = self.geompy.RestoreShape(aDump)
62 self.geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx + 1))
63 self.geomObjects.append([aShape, aBrep])
65 def exportGroups(self):
66 # iterate all features to find groups
67 aFeaturesNum = self.Part.size("Features")
69 for anIndex in range(0, aFeaturesNum):
70 aFeature = self.Part.object("Features", anIndex)
71 aSelectionList = aFeature.data().selectionList("group_list")
72 # if a group has been found
74 groupIndex = groupIndex + 1
75 self.createGroupFromList(aSelectionList, "NewGeomGroup_{0}".format(groupIndex))
77 def createGroupFromList(self, theSelectionList, theGroupName):
78 # iterate on all selected entities of the group
79 # and get the corresponding ID
80 aSelectionNum = theSelectionList.size()
82 for aSelIndex in range(0, aSelectionNum):
83 aSelection = theSelectionList.value(aSelIndex)
84 aSelectionContext = aSelection.context()
85 anID = aSelection.Id()
87 if aSelection.value().isVertex():
89 elif aSelection.value().isEdge():
91 elif aSelection.value().isFace():
96 # iterate on exported objects and check if the current
97 # group refers to this object
98 for obj in self.geomObjects:
99 if aSelectionContext.shape().isEqual(obj[0]):
100 aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType])
101 self.geompy.UnionIDs(aGroup,Ids)
102 self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName)
105 # Nothing to execute: all logic would be in the initAttributes