From 878d3cbcb1cf9a67f847dee65d503fb3006ab05c Mon Sep 17 00:00:00 2001 From: spo Date: Wed, 25 Nov 2015 13:41:24 +0300 Subject: [PATCH] Add Model_AttributeSelection::setId() --- src/Model/Model_AttributeSelection.cpp | 60 +++++++++++++++++++++----- src/Model/Model_AttributeSelection.h | 4 ++ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 76bfcb29e..c1cc85073 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -914,22 +914,22 @@ void Model_AttributeSelection::selectSubShape( int Model_AttributeSelection::Id() { - int anID = 0; - std::shared_ptr aSelection = value(); - std::shared_ptr aContext = context()->shape(); - // support for compsolids: - if (context().get() && ModelAPI_Tools::compSolidOwner(context()).get()) - aContext = ModelAPI_Tools::compSolidOwner(context())->shape(); + const ResultPtr& aContext = context(); + const std::shared_ptr& aSelection = value(); + 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 = aContext->impl(); + TopoDS_Shape aMainShape = aContextShape->impl(); const TopoDS_Shape& aSubShape = aSelection->impl(); // searching for the latest main shape if (aSelection && !aSelection->isNull() && - aContext && !aContext->isNull()) + aContextShape && !aContextShape->isNull()) { std::shared_ptr aDoc = - std::dynamic_pointer_cast(context()->document()); + std::dynamic_pointer_cast(aContext->document()); if (aDoc.get()) { Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel()); if (!aNS.IsNull()) { @@ -939,7 +939,45 @@ int Model_AttributeSelection::Id() TopTools_IndexedMapOfShape aSubShapesMap; TopExp::MapShapes(aMainShape, aSubShapesMap); - anID = aSubShapesMap.FindIndex(aSubShape); + return aSubShapesMap.FindIndex(aSubShape); } - return anID; + return 0; } + +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 a987fdf83..cbe717685 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 specified by textual name MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName); -- 2.39.2