Salome HOME
Replace Display/Erase by setDisplayed
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index f31bba3f33005d37a9486aca9a6f79a4e179a96c..d6f9f869eb5fdf184b293bcd64e754a05bf03006 100644 (file)
@@ -92,13 +92,13 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
     const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
     if (aSubShape.ShapeType() == TopAbs_EDGE)
-      isDegeneratedEdge = BRep_Tool::Degenerated(TopoDS::Edge(aSubShape));
+      isDegeneratedEdge = BRep_Tool::Degenerated(TopoDS::Edge(aSubShape)) == Standard_True;
   }
   if (!theContext.get() || isDegeneratedEdge) {
     // to keep the reference attribute label
     TDF_Label aRefLab = myRef.myRef->Label();
     aSelLab.ForgetAllAttributes(true);
-    myRef.myRef = TDF_Reference::Set(aSelLab, aSelLab);
+    myRef.myRef = TDF_Reference::Set(aSelLab.Father(), aSelLab.Father());
     return;
   }
   if (theContext->groupName() == ModelAPI_ResultBody::group()) {
@@ -121,6 +121,8 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   //the attribute initialized state should be changed by sendAttributeUpdated only
   //myIsInitialized = true;
 
+  owner()->data()->sendAttributeUpdated(this);
+
   std::string aSelName = namingName();
   if(!aSelName.empty())
     TDataStd_Name::Set(selectionLabel(), aSelName.c_str()); //set name
@@ -131,13 +133,12 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   //selectSubShape("EDGE", "Extrusion_1/TopFace|Extrusion_1/LateralFace_1");
   //selectSubShape("EDGE", "Sketch_1/Edge_6");
 #endif
-  owner()->data()->sendAttributeUpdated(this);
 }
 
 std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
 {
   std::shared_ptr<GeomAPI_Shape> aResult;
-  if (myIsInitialized) {
+  if (myRef.isInitialized()) {
     TDF_Label aSelLab = selectionLabel();
     if (aSelLab.IsAttribute(kSIMPLE_REF_ID)) { // it is just reference to shape, not sub-shape
       ResultPtr aContext = context();
@@ -171,6 +172,12 @@ Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
   myIsInitialized = myRef.isInitialized();
 }
 
+void Model_AttributeSelection::setID(const std::string theID)
+{
+  myRef.setID(theID);
+  ModelAPI_AttributeSelection::setID(theID);
+}
+
 ResultPtr Model_AttributeSelection::context() {
   return std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
 }
@@ -395,28 +402,29 @@ void Model_AttributeSelection::selectBody(
 {
   // perform the selection
   TNaming_Selector aSel(selectionLabel());
-  TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
   TopoDS_Shape aContext;
 
   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
   if (aBody) {
     aContext = aBody->shape()->impl<TopoDS_Shape>();
   } else {
-    ResultConstructionPtr aConstr = 
-      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
-    if (aConstr) {
-      aContext = aConstr->shape()->impl<TopoDS_Shape>();
+    ResultPtr aResult = 
+      std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
+    if (aResult) {
+      aContext = aResult->shape()->impl<TopoDS_Shape>();
     } else {
       Events_Error::send("A result with shape is expected");
       return;
     }
   }
+  TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : aContext;
   /// fix for issue 411: result modified shapes must not participate in this selection mechanism
   FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
   if (aFeatureOwner.get())
     aFeatureOwner->eraseResults();
-
-  aSel.Select(aNewShape, aContext); 
+  if (!aContext.IsNull()) {
+    aSel.Select(aNewShape, aContext); 
+  }
 }
 
 /// registers the name of the shape in the label (theID == 0) of sub label (theID is a tag)