- aName = TCollection_AsciiString(anAttr->Get()).ToCString();
- if(!aName.empty()) {
- const TDF_Label& aLabel = theDoc->findNamingName(aName);
- static const std::string aPostFix("_");
- TNaming_Iterator anItL(aNS);
- for(int i = 1; anItL.More(); anItL.Next(), i++) {
- if(anItL.NewShape() == theShape) {
- aName += aPostFix;
- aName += TCollection_AsciiString (i).ToCString();
- break;
+ std::shared_ptr<Model_Data> aData =
+ std::dynamic_pointer_cast<Model_Data>(theContext->data());
+ if (isNeedContextName && aData && aData->label().IsEqual(aNS->Label())) {
+ // do nothing because this context name will be added later in this method
+ } else {
+ aName = TCollection_AsciiString(anAttr->Get()).ToCString();
+ // indexes are added to sub-shapes not primitives
+ // (primitives must not be located at the same label)
+ if(!aName.empty() && aNS->Evolution() != TNaming_PRIMITIVE && isNeedContextName) {
+ const TDF_Label& aLabel = aNS->Label();//theDoc->findNamingName(aName);
+ static const std::string aPostFix("_");
+ TNaming_Iterator anItL(aNS);
+ for(int i = 1; anItL.More(); anItL.Next(), i++) {
+ // in #1766 IsEqual produced no index of the face
+ if(anItL.NewShape().IsSame(theShape)) {
+ aName += aPostFix;
+ aName += TCollection_AsciiString (i).ToCString();
+ break;
+ }
+ }
+ }
+ // if a shape is under another context, use this name, not theContext
+ std::shared_ptr<Model_Data> aContextData =
+ std::dynamic_pointer_cast<Model_Data>(theContext->data());
+ // for constructions the naming is in arguments and has no evolution, so, apply this only
+ // for bodies
+ if (isNeedContextName && theContext->groupName() == ModelAPI_ResultBody::group() &&
+ !aNS->Label().IsDescendant(aContextData->label())) {
+ isNeedContextName = false;
+ TDF_Label aNSDataLab = aNS->Label();
+ while(aNSDataLab.Depth() != 7 && aNSDataLab.Depth() > 5)
+ aNSDataLab = aNSDataLab.Father();
+ ObjectPtr aNewContext = theDoc->objects()->object(aNSDataLab);
+ if (!aNewContext.get() && aNSDataLab.Depth() == 7) {
+ aNSDataLab = aNSDataLab.Father().Father();
+ aNewContext = theDoc->objects()->object(aNSDataLab);
+ }
+ if (aNewContext.get()) {
+ aName = aNewContext->data()->name() + "/" + aName;