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 aName = aFeature.data().name()
88 # if a group has been found
90 groupIndex = groupIndex + 1
91 self.createGroupFromList(aSelectionList, aName)
93 ## Creates a group by given list of selected objects and the name
94 # @param theSelectionList: list of selected objects
95 # @param theGroupName: name of the group to create
96 def createGroupFromList(self, theSelectionList, theGroupName):
97 # iterate on all selected entities of the group
98 # and get the corresponding ID
99 aSelectionNum = theSelectionList.size()
101 for aSelIndex in range(0, aSelectionNum):
102 aSelection = theSelectionList.value(aSelIndex)
103 aSelectionContext = aSelection.context()
104 anID = aSelection.Id()
106 if aSelection.value().isVertex():
108 elif aSelection.value().isEdge():
110 elif aSelection.value().isFace():
115 # iterate on exported objects and check if the current
116 # group refers to this object
117 for obj in self.geomObjects:
118 if aSelectionContext.shape().isEqual(obj[0]):
119 aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType])
120 self.geompy.UnionIDs(aGroup,Ids)
121 self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName)
123 ## Exports all shapes and groups into the GEOM module.
125 aSession = ModelAPI.ModelAPI_Session.get()
126 ## Get active document
127 self.Part = aSession.activeDocument()
128 ## List of objects created in the old geom for later use
129 self.geomObjects = []
131 self.geompy = geomBuilder.New(salome.myStudy)
133 # Export bodies and groups