Salome HOME
Issue #637: Create visualization properties at Workshop constructor
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 6ff60d02e363dde45d66a62466e116f72c006518..852bba22736a200a04c2c042783a8d150a887270 100644 (file)
@@ -103,7 +103,10 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   }
   if (theContext->groupName() == ModelAPI_ResultBody::group()) {
     // do not select the whole shape for body:it is already must be in the data framework
-    if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
+    // equal and null selected objects mean the same: object is equal to context,
+    // TODO: synchronize with GUI later that it must be null always
+    if (theContext->shape().get() && 
+        (theContext->shape()->isEqual(theSubShape) || !theSubShape.get())) {
       aSelLab.ForgetAllAttributes(true);
       TDataStd_UAttribute::Set(aSelLab, kSIMPLE_REF_ID);
     } else {
@@ -166,6 +169,35 @@ std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
   return aResult;
 }
 
+bool Model_AttributeSelection::isInitialized()
+{
+  if (ModelAPI_AttributeSelection::isInitialized()) { // additional checkings if it is initialized
+    std::shared_ptr<GeomAPI_Shape> aResult;
+    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();
+        return aContext.get();
+      }
+      if (aSelLab.IsAttribute(kCONSTUCTION_SIMPLE_REF_ID)) { // it is just reference to construction, nothing is in value
+          return true;
+      }
+
+      Handle(TNaming_NamedShape) aSelection;
+      if (selectionLabel().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
+        return !aSelection->Get().IsNull();
+      } else { // for simple construction element: just shape of this construction element
+        ResultConstructionPtr aConstr = 
+          std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(context());
+        if (aConstr.get()) {
+          return aConstr->shape().get();
+        }
+      }
+    }
+  }
+  return false;
+}
+
 Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
   : myRef(theLabel)
 {
@@ -419,9 +451,11 @@ void Model_AttributeSelection::selectBody(
   }
   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();
+    */
   if (!aContext.IsNull()) {
     aSel.Select(aNewShape, aContext); 
   }