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 # The action is not placed into the histiry anyway
31 #def isInHistory(self):
34 def initAttributes(self):
35 # This feature has no attributes, it is action
38 def exportBodies(self):
40 kResultBodyType = "Bodies"
41 aPartSize = self.Part.size(kResultBodyType)
43 EventsAPI.Events_Error_send("No results in the active document")
46 anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
47 for idx, anObject in enumerate(anObjList):
48 aResult = ModelAPI.modelAPI_Result(anObject)
49 aBodyResult = ModelAPI.modelAPI_ResultBody(aResult)
52 aShape = aBodyResult.shape()
53 aDump = aShape.getShapeStream()
54 # Load shape to SALOME Geom
55 aBrep = self.geompy.RestoreShape(aDump)
56 self.geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx + 1))
57 self.geomObjects.append([aShape, aBrep])
59 def exportGroups(self):
60 # iterate all features to find groups
61 aFeaturesNum = self.Part.size("Features")
63 for anIndex in range(0, aFeaturesNum):
64 aFeature = self.Part.object("Features", anIndex)
65 aSelectionList = aFeature.data().selectionList("group_list")
66 # if a group has been found
68 groupIndex = groupIndex + 1
69 self.createGroupFromList(aSelectionList, "NewGeomGroup_{0}".format(groupIndex))
71 def createGroupFromList(self, theSelectionList, theGroupName):
72 # iterate on all selected entities of the group
73 # and get the corresponding ID
74 aSelectionNum = theSelectionList.size()
76 for aSelIndex in range(0, aSelectionNum):
77 aSelection = theSelectionList.value(aSelIndex)
78 aSelectionContext = aSelection.context()
79 anID = aSelection.Id()
81 if aSelection.value().isVertex():
83 elif aSelection.value().isEdge():
85 elif aSelection.value().isFace():
90 # iterate on exported objects and check if the current
91 # group refers to this object
92 for obj in self.geomObjects:
93 if aSelectionContext.shape().isEqual(obj[0]):
94 aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType])
95 self.geompy.UnionIDs(aGroup,Ids)
96 self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName)
99 aSession = ModelAPI.ModelAPI_Session.get()
100 self.Part = aSession.activeDocument()
101 self.geomObjects = []
102 self.geompy = geomBuilder.New(salome.myStudy)
104 # Export bodies and groups