2 # ExportFeature class definition
3 # Copyright (C) 2014-20xx CEA/DEN, EDF R&D
9 from salome.geom import geomBuilder
13 # Feature to export all shapes and groups into the GEOM module
14 class ExportFeature(ModelAPI.ModelAPI_Feature):
18 ModelAPI.ModelAPI_Feature.__init__(self)
21 ## Export kind. Static.
25 ## Returns the kind of a feature.
27 return ExportFeature.ID()
29 ## This feature is action: has no property pannel and executes immideately.
33 # The action is not placed into the history anyway
34 #def isInHistory(self):
37 ## This feature has no attributes, as it is action.
38 def initAttributes(self):
42 def exportBodies(self):
43 kResultBodyType = "Bodies"
44 aPartSize = self.Part.size(kResultBodyType)
46 EventsAPI.Events_Error_send("No results in the active document")
49 anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
50 for idx, anObject in enumerate(anObjList):
51 aResult = ModelAPI.modelAPI_Result(anObject)
52 aBodyResult = ModelAPI.modelAPI_ResultBody(aResult)
55 aShape = aBodyResult.shape()
56 aDump = aShape.getShapeStream()
57 # Load shape to SALOME Geom
58 aBrep = self.geompy.RestoreShape(aDump)
59 self.geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx + 1))
60 self.geomObjects.append([aShape, aBrep])
63 def exportGroups(self):
64 # iterate all features to find groups
65 aFeaturesNum = self.Part.size("Features")
67 for anIndex in range(0, aFeaturesNum):
68 aFeature = self.Part.object("Features", anIndex)
69 aSelectionList = aFeature.data().selectionList("group_list")
70 # if a group has been found
72 groupIndex = groupIndex + 1
73 self.createGroupFromList(aSelectionList, "NewGeomGroup_{0}".format(groupIndex))
75 ## Creates a group by given list of selected objects and the name
76 # @param theSelectionList: list of selected objects
77 # @param theGroupName: name of the group to create
78 def createGroupFromList(self, theSelectionList, theGroupName):
79 # iterate on all selected entities of the group
80 # and get the corresponding ID
81 aSelectionNum = theSelectionList.size()
83 for aSelIndex in range(0, aSelectionNum):
84 aSelection = theSelectionList.value(aSelIndex)
85 aSelectionContext = aSelection.context()
86 anID = aSelection.Id()
88 if aSelection.value().isVertex():
90 elif aSelection.value().isEdge():
92 elif aSelection.value().isFace():
97 # iterate on exported objects and check if the current
98 # group refers to this object
99 for obj in self.geomObjects:
100 if aSelectionContext.shape().isEqual(obj[0]):
101 aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType])
102 self.geompy.UnionIDs(aGroup,Ids)
103 self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName)
105 ## Exports all shapes and groups into the GEOM module.
107 aSession = ModelAPI.ModelAPI_Session.get()
108 ## Get active document
109 self.Part = aSession.activeDocument()
110 ## List of objects created in the old geom for later use
111 self.geomObjects = []
113 self.geompy = geomBuilder.New(salome.myStudy)
115 # Export bodies and groups