#include "Model_Events.h"
#include "Model_Data.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <GeomAPI_Shape.h>
#include <TNaming_Selector.hxx>
#include <TNaming_NamedShape.hxx>
using namespace std;
-void Model_AttributeSelection::setValue(const ResultBodyPtr& theContext,
+void Model_AttributeSelection::setValue(const ResultPtr& theContext,
const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
{
const boost::shared_ptr<GeomAPI_Shape>& anOldShape = value();
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();
- TopoDS_Shape aContext = theContext->shape()->impl<TopoDS_Shape>();
+ TopoDS_Shape aContext;
+
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+ if (aBody)
+ aContext = aBody->shape()->impl<TopoDS_Shape>();
+ else {
+ ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
+ if (aConstr)
+ aContext = aConstr->shape()->impl<TopoDS_Shape>();
+ else
+ throw std::invalid_argument("a result with shape is expected");
+ }
aSel.Select(aNewShape, aContext);
myIsInitialized = true;
myIsInitialized = myRef.isInitialized();
}
-ResultBodyPtr Model_AttributeSelection::context() {
- return boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+ResultPtr Model_AttributeSelection::context() {
+ return boost::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
+}
+
+
+void Model_AttributeSelection::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+ myRef.setObject(theObject);
}
public:
/// Defines the result and its selected sub-shape
MODEL_EXPORT virtual void setValue(
- const ResultBodyPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
/// Returns the selected subshape
MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> 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<ModelAPI_Object>& theObject);
protected:
/// Objects are created for features automatically
#define ModelAPI_AttributeSelection_H_
#include "ModelAPI_Attribute.h"
-#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_Result.h>
/**\class ModelAPI_AttributeSelection
* \ingroup DataModel
public:
/// Defines the result and its selected sub-shape
virtual void setValue(
- const ResultBodyPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
/// Returns the selected subshape
virtual boost::shared_ptr<GeomAPI_Shape> 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()