From: spo Date: Wed, 25 Nov 2015 10:41:24 +0000 (+0300) Subject: Add Model_AttributeSelection::setId() X-Git-Tag: V_2.4.0~65 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=690012a1c13c51062fc01656ee18dd8edb947e02;p=modules%2Fshaper.git Add Model_AttributeSelection::setId() --- diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index c672ed47e..92b91327c 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -977,3 +977,41 @@ int Model_AttributeSelection::Id() } return anID; } + +void Model_AttributeSelection::setId(int theID) +{ + const ResultPtr& aContext = context(); + std::shared_ptr aSelection; + + std::shared_ptr aContextShape = aContext->shape(); + // support for compsolids: + if (aContext.get() && ModelAPI_Tools::compSolidOwner(aContext).get()) + aContextShape = ModelAPI_Tools::compSolidOwner(aContext)->shape(); + + TopoDS_Shape aMainShape = aContextShape->impl(); + // searching for the latest main shape + if (theID > 0 && + aContextShape && !aContextShape->isNull()) + { + std::shared_ptr aDoc = + std::dynamic_pointer_cast(aContext->document()); + if (aDoc.get()) { + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel()); + if (!aNS.IsNull()) { + aMainShape = TNaming_Tool::CurrentShape(aNS); + } + } + + TopTools_IndexedMapOfShape aSubShapesMap; + TopExp::MapShapes(aMainShape, aSubShapesMap); + const TopoDS_Shape& aSelShape = aSubShapesMap.FindKey(theID); + + std::shared_ptr aResult(new GeomAPI_Shape); + aResult->setImpl(new TopoDS_Shape(aSelShape)); + + aSelection = aResult; + } + + setValue(aContext, aSelection); +} + diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 5c7d3c358..1f3c45945 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -58,6 +58,10 @@ public: /// will be possible from SMESH module of SALOME. MODEL_EXPORT virtual int Id(); + /// Defines the sub-shape by Id + /// NOTE: This method is opposite to Id() method. + MODEL_EXPORT virtual void setId(int theID); + /// 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);