aBuilder.Generated(theContext->shape()->impl<TopoDS_Shape>());
std::shared_ptr<Model_Document> aMyDoc =
std::dynamic_pointer_cast<Model_Document>(owner()->document());
- std::string aName = theContext->data()->name();
+ std::string aName = contextName(theContext);
+ // for selection in different document, add the document name
aMyDoc->addNamingName(aSelLab, aName);
TDataStd_Name::Set(aSelLab, aName.c_str());
} else { // for sketch the naming is needed in DS
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();
+ std::string aName = contextName(aContext);
aMyDoc->addNamingName(aSelLab, aName);
TDataStd_Name::Set(aSelLab, aName.c_str());
}
// saving of context is enough: result construction contains exactly the needed shape
TNaming_Builder aBuilder(selectionLabel());
aBuilder.Generated(aSubShape);
- aMyDoc->addNamingName(selectionLabel(), theContext->data()->name());
- TDataStd_Name::Set(selectionLabel(), theContext->data()->name().c_str());
+ std::string aName = contextName(theContext);
+ aMyDoc->addNamingName(selectionLabel(), aName);
+ TDataStd_Name::Set(selectionLabel(), aName.c_str());
return;
}
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(owner()->data());
setValue(aContext, aSelection);
}
+std::string Model_AttributeSelection::contextName(const ResultPtr& theContext) const
+{
+ std::string aResult;
+ if (owner()->document() != theContext->document()) {
+ if (theContext->document() == ModelAPI_Session::get()->moduleDocument()) {
+ aResult = theContext->document()->kind() + "/";
+ } else {
+ ResultPtr aDocRes = ModelAPI_Tools::findPartResult(
+ ModelAPI_Session::get()->moduleDocument(), theContext->document());
+ if (aDocRes.get()) {
+ aResult = aDocRes->data()->name() + "/";
+ }
+ }
+ }
+ aResult += theContext->data()->name();
+ return aResult;
+}
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_ResultBody.h>
#include <TopoDS_Iterator.hxx>
#include <TopoDS.hxx>
ResultPtr aCont = aDoc->findByName(aContName);
// possible this is body where postfix is added to distinguish several shapes on the same label
int aSubShapeId = -1; // -1 means sub shape not found
- if (!aCont.get() && aContName == aSubShapeName) {
+ // for result body the name wihtout "_" has higher priority than with it: it is always added
+ if ((!aCont.get() || (aCont->groupName() == ModelAPI_ResultBody::group())) &&
+ aContName == aSubShapeName) {
size_t aPostIndex = aContName.rfind('_');
if (aPostIndex != std::string::npos) {
std::string aSubContName = aContName.substr(0, aPostIndex);
- aCont = aDoc->findByName(aSubContName);
- if (aCont.get()) {
+ ResultPtr aSubCont = aDoc->findByName(aSubContName);
+ if (aSubCont.get()) {
try {
std::string aNum = aContName.substr(aPostIndex + 1);
aSubShapeId = std::stoi(aNum);
} catch (std::invalid_argument&) {
aSubShapeId = -1;
}
- if (aSubShapeId > 0)
+ if (aSubShapeId > 0) {
aContName = aSubContName;
+ aCont = aSubCont;
+ }
}
}
}