From: vsv Date: Mon, 13 Oct 2014 13:06:52 +0000 (+0400) Subject: Set value for Attribute Selection X-Git-Tag: V_0.5~98 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8170985e13476f171bb839474ffaf2cce5d0546d;p=modules%2Fshaper.git Set value for Attribute Selection --- diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 8c344e2b3..62659de6c 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -7,6 +7,9 @@ #include "Model_Events.h" #include "Model_Data.h" #include +#include +#include +#include #include #include @@ -14,7 +17,7 @@ using namespace std; -void Model_AttributeSelection::setValue(const ResultBodyPtr& theContext, +void Model_AttributeSelection::setValue(const ResultPtr& theContext, const boost::shared_ptr& theSubShape) { const boost::shared_ptr& anOldShape = value(); @@ -25,11 +28,22 @@ void Model_AttributeSelection::setValue(const ResultBodyPtr& theContext, bool isOldContext = theContext == myRef.value(); if (!isOldContext) myRef.setValue(theContext); - + // perform the selection TNaming_Selector aSel(myRef.myRef->Label()); TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl() : TopoDS_Shape(); - TopoDS_Shape aContext = theContext->shape()->impl(); + TopoDS_Shape aContext; + + ResultBodyPtr aBody = boost::dynamic_pointer_cast(myRef.value()); + if (aBody) + aContext = aBody->shape()->impl(); + else { + ResultConstructionPtr aConstr = boost::dynamic_pointer_cast(myRef.value()); + if (aConstr) + aContext = aConstr->shape()->impl(); + else + throw std::invalid_argument("a result with shape is expected"); + } aSel.Select(aNewShape, aContext); myIsInitialized = true; @@ -55,6 +69,12 @@ Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel) myIsInitialized = myRef.isInitialized(); } -ResultBodyPtr Model_AttributeSelection::context() { - return boost::dynamic_pointer_cast(myRef.value()); +ResultPtr Model_AttributeSelection::context() { + return boost::dynamic_pointer_cast(myRef.value()); +} + + +void Model_AttributeSelection::setObject(const boost::shared_ptr& theObject) +{ + myRef.setObject(theObject); } diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index d8e8a54a7..b380fef83 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -20,13 +20,15 @@ class Model_AttributeSelection : public ModelAPI_AttributeSelection public: /// Defines the result and its selected sub-shape MODEL_EXPORT virtual void setValue( - const ResultBodyPtr& theContext, const boost::shared_ptr& theSubShape); + const ResultPtr& theContext, const boost::shared_ptr& theSubShape); /// Returns the selected subshape MODEL_EXPORT virtual boost::shared_ptr value(); /// Returns the context of the selection (the whole shape owner) - MODEL_EXPORT virtual ResultBodyPtr context(); + MODEL_EXPORT virtual ResultPtr context(); + + MODEL_EXPORT virtual void setObject(const boost::shared_ptr& theObject); protected: /// Objects are created for features automatically diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 9b4970c12..98d4af7d6 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -6,7 +6,7 @@ #define ModelAPI_AttributeSelection_H_ #include "ModelAPI_Attribute.h" -#include +#include /**\class ModelAPI_AttributeSelection * \ingroup DataModel @@ -18,13 +18,13 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute public: /// Defines the result and its selected sub-shape virtual void setValue( - const ResultBodyPtr& theContext, const boost::shared_ptr& theSubShape) = 0; + const ResultPtr& theContext, const boost::shared_ptr& theSubShape) = 0; /// Returns the selected subshape virtual boost::shared_ptr value() = 0; /// Returns the context of the selection (the whole shape owner) - virtual ResultBodyPtr context() = 0; + virtual ResultPtr context() = 0; /// Returns the type of this class of attributes static std::string type() diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index f07c339ca..84cfee206 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -129,7 +129,7 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const boost::shared_ptr aSelect = boost::dynamic_pointer_cast(aData->attribute(attributeID())); - ResultBodyPtr aBody = boost::dynamic_pointer_cast(mySelectedObject); + ResultPtr aBody = boost::dynamic_pointer_cast(mySelectedObject); if (aBody) aSelect->setValue(aBody, myShape); } else {