X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConnectorPlugin%2FConnectorPlugin_ExportFeature.py;h=30844b6744a29fb0c941fb4d783fe027fd5d6bb5;hb=8a57ef42e3538be4b96f796b8ee057c3f39e3053;hp=c4bf4a6ae239da7b1736a17d79125dbb6a98d0c2;hpb=9e10a25021a539ae9bb44e85e244a8e3fa8119ed;p=modules%2Fshaper.git diff --git a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py index c4bf4a6ae..30844b674 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py @@ -8,6 +8,15 @@ import ModelAPI import salome from salome.geom import geomBuilder +def getObjectIndex(theName): + aStudy = salome.myStudy + aId = 0 + aObj = aStudy.FindObjectByName(theName, "GEOM") + while len(aObj) != 0: + aId = aId + 1 + aName = theName + '_' + str(aId) + aObj = aStudy.FindObjectByName(aName, "GEOM") + return aId ## @ingroup Plugins # Feature to export all shapes and groups into the GEOM module @@ -57,7 +66,14 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): aDump = aShape.getShapeStream() # Load shape to SALOME Geom aBrep = self.geompy.RestoreShape(aDump) - self.geompy.addToStudy(aBrep, aBodyResult.data().name()) + aName = aBodyResult.data().name() + + # Make unique name + aId = getObjectIndex(aName) + if aId != 0: + aName = aName + '_' + str(aId) + + self.geompy.addToStudy(aBrep, aName) self.geomObjects.append([aShape, aBrep]) ## Exports all groups @@ -70,8 +86,11 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): aSelectionList = aFeature.data().selectionList("group_list") # if a group has been found if aSelectionList: + aFeature = ModelAPI.objectToFeature(aFeature) + if aFeature.firstResult() is not None: + aName = aFeature.firstResult().data().name() groupIndex = groupIndex + 1 - self.createGroupFromList(aSelectionList, "NewGeomGroup_{0}".format(groupIndex)) + self.createGroupFromList(aSelectionList, aName) ## Creates a group by given list of selected objects and the name # @param theSelectionList: list of selected objects @@ -95,13 +114,15 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): else: groupType = "SOLID" - # iterate on exported objects and check if the current - # group refers to this object - for obj in self.geomObjects: - if aSelectionContext.shape().isEqual(obj[0]): - aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType]) - self.geompy.UnionIDs(aGroup,Ids) - self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName) + aContextBody = ModelAPI.modelAPI_ResultBody(aSelectionContext) + if aContextBody is not None: + # iterate on exported objects and check if the current + # group refers to this object + for obj in self.geomObjects: + if aContextBody.isLatestEqual(obj[0]): + aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType]) + self.geompy.UnionIDs(aGroup,Ids) + self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName) ## Exports all shapes and groups into the GEOM module. def execute(self):