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>
11 #include <TNaming_Selector.hxx>
12 #include <TNaming_NamedShape.hxx>
13 #include <TopoDS_Shape.hxx>
17 void Model_AttributeSelection::setValue(const ResultBodyPtr& theContext,
18 const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
20 const boost::shared_ptr<GeomAPI_Shape>& anOldShape = value();
22 (theSubShape == anOldShape || (theSubShape && anOldShape && theSubShape->isEqual(anOldShape)));
23 if (isOldShape) return; // shape is the same, so context is also unchanged
24 // update the referenced object if needed
25 bool isOldContext = theContext == myRef.value();
27 myRef.setValue(theContext);
29 // perform the selection
30 TNaming_Selector aSel(myRef.myRef->Label());
31 TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
32 TopoDS_Shape aContext = theContext->shape()->impl<TopoDS_Shape>();
33 aSel.Select(aNewShape, aContext);
34 myIsInitialized = true;
36 owner()->data()->sendAttributeUpdated(this);
39 boost::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
41 boost::shared_ptr<GeomAPI_Shape> aResult;
42 if (myIsInitialized) {
43 Handle(TNaming_NamedShape) aSelection;
44 if (myRef.myRef->Label().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
45 TopoDS_Shape aSelShape = aSelection->Get();
46 aResult->setImpl(&aSelShape);
52 Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
55 myIsInitialized = myRef.isInitialized();
58 ResultBodyPtr Model_AttributeSelection::context() {
59 return boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());