X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelection.cpp;h=852bba22736a200a04c2c042783a8d150a887270;hb=443d4d24432c8bb907c28b23bf8db67dad263886;hp=b522b90a14129a9ab8c084943d5a69adce963db2;hpb=91540e31cc99e5f1eef3296b570b65abf580ca85;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index b522b90a1..852bba227 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -98,12 +98,15 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, // 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()) { // 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 { @@ -121,6 +124,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,7 +136,6 @@ 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 Model_AttributeSelection::value() @@ -165,6 +169,35 @@ std::shared_ptr Model_AttributeSelection::value() return aResult; } +bool Model_AttributeSelection::isInitialized() +{ + if (ModelAPI_AttributeSelection::isInitialized()) { // additional checkings if it is initialized + std::shared_ptr 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(context()); + if (aConstr.get()) { + return aConstr->shape().get(); + } + } + } + } + return false; +} + Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel) : myRef(theLabel) { @@ -401,28 +434,31 @@ void Model_AttributeSelection::selectBody( { // perform the selection TNaming_Selector aSel(selectionLabel()); - TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl() : TopoDS_Shape(); TopoDS_Shape aContext; ResultBodyPtr aBody = std::dynamic_pointer_cast(myRef.value()); if (aBody) { aContext = aBody->shape()->impl(); } else { - ResultConstructionPtr aConstr = - std::dynamic_pointer_cast(myRef.value()); - if (aConstr) { - aContext = aConstr->shape()->impl(); + ResultPtr aResult = + std::dynamic_pointer_cast(myRef.value()); + if (aResult) { + aContext = aResult->shape()->impl(); } else { Events_Error::send("A result with shape is expected"); return; } } + TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl() : aContext; /// fix for issue 411: result modified shapes must not participate in this selection mechanism + /* FeaturePtr aFeatureOwner = std::dynamic_pointer_cast(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) @@ -647,10 +683,11 @@ bool isTrivial (const TopTools_ListOfShape& theAncestors, TopTools_IndexedMapOfS if(aNumber > 1) return false; return true; } -std::string Model_AttributeSelection::namingName() +std::string Model_AttributeSelection::namingName(const std::string& theDefaultName) { std::string aName(""); - if(!this->isInitialized()) return aName; + if(!this->isInitialized()) + return !theDefaultName.empty() ? theDefaultName : aName; Handle(TDataStd_Name) anAtt; if(selectionLabel().FindAttribute(TDataStd_Name::GetID(), anAtt)) { aName = TCollection_AsciiString(anAtt->Get()).ToCString(); @@ -661,7 +698,7 @@ std::string Model_AttributeSelection::namingName() ResultPtr aCont = context(); aName = "Undefined name"; if(!aCont.get() || aCont->shape()->isNull()) - return aName; + return !theDefaultName.empty() ? theDefaultName : aName; if (!aSubSh.get() || aSubSh->isNull()) { // no subshape, so just the whole feature name return aCont->data()->name(); }