2 # ExportFeature class definition
3 # Copyright (C) 2014-20xx CEA/DEN, EDF R&D
9 from salome.geom import geomBuilder
11 def getObjectIndex(theName):
12 aStudy = salome.myStudy
14 aObj = aStudy.FindObjectByName(theName, "GEOM")
17 aName = theName + '_' + str(aId)
18 aObj = aStudy.FindObjectByName(aName, "GEOM")
22 # Feature to export all shapes and groups into the GEOM module
23 class ExportFeature(ModelAPI.ModelAPI_Feature):
27 ModelAPI.ModelAPI_Feature.__init__(self)
30 ## Export kind. Static.
34 ## Returns the kind of a feature.
36 return ExportFeature.ID()
38 ## This feature is action: has no property pannel and executes immideately.
42 # The action is not placed into the history anyway
43 #def isInHistory(self):
46 ## This feature has no attributes, as it is action.
47 def initAttributes(self):
51 def exportBodies(self):
53 kResultBodyType = "Bodies"
54 aPartSize = self.Part.size(kResultBodyType)
56 EventsAPI.Events_Error_send("No results in the active document")
59 anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
60 for idx, anObject in enumerate(anObjList):
61 aResult = ModelAPI.modelAPI_Result(anObject)
62 aBodyResult = ModelAPI.modelAPI_ResultBody(aResult)
65 aShape = aBodyResult.shape()
66 aDump = aShape.getShapeStream()
67 # Load shape to SALOME Geom
68 aBrep = self.geompy.RestoreShape(aDump)
69 aName = aBodyResult.data().name()
72 aId = getObjectIndex(aName)
74 aName = aName + '_' + str(aId)
76 self.geompy.addToStudy(aBrep, aName)
77 self.geomObjects.append([aShape, aBrep])
80 def exportGroups(self):
81 # iterate all features to find groups
82 aFeaturesNum = self.Part.size("Features")
84 for anIndex in range(0, aFeaturesNum):
85 aFeature = self.Part.object("Features", anIndex)
86 aSelectionList = aFeature.data().selectionList("group_list")
87 # if a group has been found
89 aFeature = ModelAPI.objectToFeature(aFeature)
90 if aFeature.firstResult() is not None:
91 aName = aFeature.firstResult().data().name()
92 groupIndex = groupIndex + 1
93 self.createGroupFromList(aSelectionList, aName)
95 ## Creates a group by given list of selected objects and the name
96 # @param theSelectionList: list of selected objects
97 # @param theGroupName: name of the group to create
98 def createGroupFromList(self, theSelectionList, theGroupName):
99 # iterate on all selected entities of the group
100 # and get the corresponding ID
101 aSelectionNum = theSelectionList.size()
103 for aSelIndex in range(0, aSelectionNum):
104 aSelection = theSelectionList.value(aSelIndex)
105 aSelectionContext = aSelection.context()
106 anID = aSelection.Id()
108 if aSelection.value().isVertex():
110 elif aSelection.value().isEdge():
112 elif aSelection.value().isFace():
117 # iterate on exported objects and check if the current
118 # group refers to this object
119 for obj in self.geomObjects:
120 if aSelectionContext.shape().isEqual(obj[0]):
121 aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType])
122 self.geompy.UnionIDs(aGroup,Ids)
123 self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName)
125 ## Exports all shapes and groups into the GEOM module.
127 aSession = ModelAPI.ModelAPI_Session.get()
128 ## Get active document
129 self.Part = aSession.activeDocument()
130 ## List of objects created in the old geom for later use
131 self.geomObjects = []
133 self.geompy = geomBuilder.New(salome.myStudy)
135 # Export bodies and groups