1 // File: Model_AttributeSelection.h
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeSelection.h"
6 #include "Model_Application.h"
7 #include "Model_Events.h"
8 #include "Model_Data.h"
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_ResultBody.h>
11 #include <ModelAPI_ResultConstruction.h>
12 #include <GeomAPI_Shape.h>
14 #include <TNaming_Selector.hxx>
15 #include <TNaming_NamedShape.hxx>
16 #include <TopoDS_Shape.hxx>
20 void Model_AttributeSelection::setValue(const ResultPtr& theContext,
21 const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
23 const boost::shared_ptr<GeomAPI_Shape>& anOldShape = value();
25 (theSubShape == anOldShape || (theSubShape && anOldShape && theSubShape->isEqual(anOldShape)));
26 if (isOldShape) return; // shape is the same, so context is also unchanged
27 // update the referenced object if needed
28 bool isOldContext = theContext == myRef.value();
30 myRef.setValue(theContext);
32 // perform the selection
33 TNaming_Selector aSel(myRef.myRef->Label());
34 TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
35 TopoDS_Shape aContext;
37 ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
39 aContext = aBody->shape()->impl<TopoDS_Shape>();
41 ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
43 aContext = aConstr->shape()->impl<TopoDS_Shape>();
45 throw std::invalid_argument("a result with shape is expected");
47 aSel.Select(aNewShape, aContext);
48 myIsInitialized = true;
50 owner()->data()->sendAttributeUpdated(this);
53 boost::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
55 boost::shared_ptr<GeomAPI_Shape> aResult;
56 if (myIsInitialized) {
57 Handle(TNaming_NamedShape) aSelection;
58 if (myRef.myRef->Label().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
59 TopoDS_Shape aSelShape = aSelection->Get();
60 aResult->setImpl(&aSelShape);
66 Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
69 myIsInitialized = myRef.isInitialized();
72 ResultPtr Model_AttributeSelection::context() {
73 return boost::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
77 void Model_AttributeSelection::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
79 myRef.setObject(theObject);