Salome HOME
Creation of producedByFeature initial implementation neede for the issue #1306
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 5a211a7525ce117fd401c2fc471041ed82820b94..6462c7b8489c8009ca151f2f5cbc5f598fe26bdd 100644 (file)
@@ -182,7 +182,7 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
 std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
 {
   if (myTmpContext.get() || myTmpSubShape.get()) {
-    return myTmpSubShape;
+    return myTmpSubShape.get() ? myTmpSubShape : myTmpContext->shape();
   }
 
   std::shared_ptr<GeomAPI_Shape> aResult;
@@ -416,13 +416,27 @@ bool Model_AttributeSelection::update()
       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
       aShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aComp));
       selectConstruction(aContext, aShape);
+    } else {
+      // For correct naming selection, put the shape into the naming structure.
+      // It seems sub-shapes are not needed: only this shape is (and can be ) selected.
+      TNaming_Builder aBuilder(aSelLab);
+      aBuilder.Generated(aContext->shape()->impl<TopoDS_Shape>());
+      std::shared_ptr<Model_Document> aMyDoc = 
+        std::dynamic_pointer_cast<Model_Document>(owner()->document());
+      std::string aName = aContext->data()->name();
+      aMyDoc->addNamingName(aSelLab, aName);
+      TDataStd_Name::Set(aSelLab, aName.c_str());
     }
     return setInvalidIfFalse(aSelLab, aContext->shape() && !aContext->shape()->isNull());
   }
 
   if (aSelLab.IsAttribute(kPART_REF_ID)) { // it is reference to the part object
     std::shared_ptr<GeomAPI_Shape> aNoSelection;
-    return setInvalidIfFalse(aSelLab, selectPart(aContext, aNoSelection, true));
+    bool aResult = selectPart(aContext, aNoSelection, true);
+    if (aResult) {
+      owner()->data()->sendAttributeUpdated(this);
+    }
+    return setInvalidIfFalse(aSelLab, aResult);
   }
 
   if (aContext->groupName() == ModelAPI_ResultBody::group()) {
@@ -460,7 +474,7 @@ bool Model_AttributeSelection::update()
         return setInvalidIfFalse(aSelLab, false);
       }
 
-      if (aShapeType == TopAbs_FACE) { // compound is for the whole sketch selection
+      if (aShapeType == TopAbs_FACE || aShapeType == TopAbs_WIRE) { // compound is for the whole sketch selection
         // If this is a wire with plane defined thin it is a sketch-like object
         if (!aConstructionContext->facesNum()) // no faces, update can not work correctly
           return setInvalidIfFalse(aSelLab, false);
@@ -538,6 +552,13 @@ bool Model_AttributeSelection::update()
           }
         }
         if (aNewSelected) { // store this new selection
+          if (aShapeType == TopAbs_WIRE) { // just get a wire from face to have wire
+            TopExp_Explorer aWireExp(aNewSelected->impl<TopoDS_Shape>(), TopAbs_WIRE);
+            if (aWireExp.More()) {
+              aNewSelected.reset(new GeomAPI_Shape);
+              aNewSelected->setImpl<TopoDS_Shape>(new TopoDS_Shape(aWireExp.Current()));
+            }
+          }
           selectConstruction(aContext, aNewSelected);
           owner()->data()->sendAttributeUpdated(this);
           return setInvalidIfFalse(aSelLab, true);
@@ -672,6 +693,7 @@ static void registerSubShape(TDF_Label theMainLabel, TopoDS_Shape theShape,
   if (!theAdditionalName.empty())
     aName<<theAdditionalName<<"/";
   if (theShape.ShapeType() == TopAbs_FACE) aName<<"Face";
+  else if (theShape.ShapeType() == TopAbs_WIRE) aName<<"Wire";
   else if (theShape.ShapeType() == TopAbs_EDGE) aName<<"Edge";
   else if (theShape.ShapeType() == TopAbs_VERTEX) aName<<"Vertex";