From: mpv Date: Thu, 22 Jan 2015 09:07:11 +0000 (+0300) Subject: Apply patch of Renaud Nedelec for exportation of groups to GEOM X-Git-Tag: V_1.0.0~26^2~4^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5e5364156f2004894dd3366914a2095a468b3679;p=modules%2Fshaper.git Apply patch of Renaud Nedelec for exportation of groups to GEOM --- diff --git a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py index 8b3163426..ea030b363 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py @@ -31,17 +31,25 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): return False def initAttributes(self): - # This feature has no attributes, but should perfore some actions on initialization + # This feature has no attributes, but should perform some actions on initialization aSession = ModelAPI.ModelAPI_Session.get() - aPart = aSession.activeDocument() + self.Part = aSession.activeDocument() + self.geomObjects = [] + self.geompy = geomBuilder.New(salome.myStudy) + + # Export bodies and groups + self.exportBodies() + self.exportGroups() + + def exportBodies(self): # Get all bodies kResultBodyType = "Bodies" - aPartSize = aPart.size(kResultBodyType) + aPartSize = self.Part.size(kResultBodyType) if aPartSize == 0: EventsAPI.Events_Error_send("No results in the active document") return - - anObjList = [aPart.object(kResultBodyType, idx) for idx in xrange(aPartSize)] + + anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)] for idx, anObject in enumerate(anObjList): aResult = ModelAPI.modelAPI_Result(anObject) aBodyResult = ModelAPI.modelAPI_ResultBody(aResult) @@ -50,10 +58,49 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): aShape = aBodyResult.shape() aDump = aShape.getShapeStream() # Load shape to SALOME Geom - geompy = geomBuilder.New(salome.myStudy) - aBrep = geompy.RestoreShape(aDump) - geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx)) + aBrep = self.geompy.RestoreShape(aDump) + self.geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx + 1)) + self.geomObjects.append([aShape, aBrep]) + + def exportGroups(self): + # iterate all features to find groups + aFeaturesNum = self.Part.size("Features") + groupIndex = 0 + for anIndex in range(0, aFeaturesNum): + aFeature = self.Part.object("Features", anIndex) + aSelectionList = aFeature.data().selectionList("group_list") + # if a group has been found + if aSelectionList: + groupIndex = groupIndex + 1 + self.createGroupFromList(aSelectionList, "NewGeomGroup_{0}".format(groupIndex)) + + def createGroupFromList(self, theSelectionList, theGroupName): + # iterate on all selected entities of the group + # and get the corresponding ID + aSelectionNum = theSelectionList.size() + Ids = [] + for aSelIndex in range(0, aSelectionNum): + aSelection = theSelectionList.value(aSelIndex) + aSelectionContext = aSelection.context() + anID = aSelection.Id() + Ids.append(anID) + if aSelection.value().isVertex(): + groupType = "VERTEX" + elif aSelection.value().isEdge(): + groupType = "EDGE" + elif aSelection.value().isFace(): + groupType = "FACE" + 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) + def execute(self): # Nothing to execute: all logic would be in the initAttributes pass diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index ab3768d06..cab45489b 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1006,3 +1006,20 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType, const } } + +int Model_AttributeSelection::Id() +{ + std::shared_ptr aSelection = value(); + std::shared_ptr aContext = context()->shape(); + const TopoDS_Shape& aMainShape = aContext->impl(); + const TopoDS_Shape& aSubShape = aSelection->impl(); + int anID = 0; + if (aSelection && !aSelection->isNull() && + aContext && !aContext->isNull()) + { + TopTools_IndexedMapOfShape aSubShapesMap; + TopExp::MapShapes(aMainShape, aSubShapesMap); + anID = aSubShapesMap.FindIndex(aSubShape); + } + return anID; +} diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 4ca2ef3db..8708c136d 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -41,6 +41,12 @@ public: /// Returns a textual string of the selection MODEL_EXPORT virtual std::string namingName(); + + /// Returns an Id of the selection + /// NOTE: This method has been added for temporary export of groups towards old GEOM + /// It should then be removed when a direct use of objects from NewGeom + /// will be possible from SMESH module of SALOME. + MODEL_EXPORT virtual int Id(); /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName); diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 3778ecdd4..fc7675f48 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -46,6 +46,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute /// Returns a textual string of the selection virtual std::string namingName() = 0; + + /// Returns an id of the selection + virtual int Id() = 0; /// Selects sub-shape by the textual Name