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):
44 kResultBodyType = "Bodies"
45 aPartSize = self.Part.size(kResultBodyType)
47 EventsAPI.Events_Error_send("No results in the active document")
50 anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
51 for idx, anObject in enumerate(anObjList):
52 aResult = ModelAPI.modelAPI_Result(anObject)
53 aBodyResult = ModelAPI.modelAPI_ResultBody(aResult)
56 aShape = aBodyResult.shape()
57 aDump = aShape.getShapeStream()
58 # Load shape to SALOME Geom
59 aBrep = self.geompy.RestoreShape(aDump)
60 self.geompy.addToStudy(aBrep, aBodyResult.data().name())
61 self.geomObjects.append([aShape, aBrep])
64 def exportGroups(self):
65 # iterate all features to find groups
66 aFeaturesNum = self.Part.size("Features")
68 for anIndex in range(0, aFeaturesNum):
69 aFeature = self.Part.object("Features", anIndex)
70 aSelectionList = aFeature.data().selectionList("group_list")
71 # if a group has been found
73 groupIndex = groupIndex + 1
74 self.createGroupFromList(aSelectionList, "NewGeomGroup_{0}".format(groupIndex))
76 ## Creates a group by given list of selected objects and the name
77 # @param theSelectionList: list of selected objects
78 # @param theGroupName: name of the group to create
79 def createGroupFromList(self, theSelectionList, theGroupName):
80 # iterate on all selected entities of the group
81 # and get the corresponding ID
82 aSelectionNum = theSelectionList.size()
84 for aSelIndex in range(0, aSelectionNum):
85 aSelection = theSelectionList.value(aSelIndex)
86 aSelectionContext = aSelection.context()
87 anID = aSelection.Id()
89 if aSelection.value().isVertex():
91 elif aSelection.value().isEdge():
93 elif aSelection.value().isFace():
98 # iterate on exported objects and check if the current
99 # group refers to this object
100 for obj in self.geomObjects:
101 if aSelectionContext.shape().isEqual(obj[0]):
102 aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType])
103 self.geompy.UnionIDs(aGroup,Ids)
104 self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName)
106 ## Exports all shapes and groups into the GEOM module.
108 aSession = ModelAPI.ModelAPI_Session.get()
109 ## Get active document
110 self.Part = aSession.activeDocument()
111 ## List of objects created in the old geom for later use
112 self.geomObjects = []
114 self.geompy = geomBuilder.New(salome.myStudy)
116 # Export bodies and groups