// 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()) {
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)
{
{
// 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)
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();
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();
}