#include <TopoDS_Iterator.hxx>
#include <TNaming_Iterator.hxx>
#include <BRep_Builder.hxx>
+#include <ModelAPI_Session.h>
+
using namespace std;
//#define DEB_NAMING 1
#ifdef DEB_NAMING
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());
}
TNaming_Builder aBuilder(aLab);
aBuilder.Generated(theShape);
std::stringstream aName;
+ // add the part name if the selected object is located in other part
+ if (theDoc != theContextFeature->document()) {
+ if (theContextFeature->document() == ModelAPI_Session::get()->moduleDocument()) {
+ aName<<theContextFeature->document()->kind()<<"/";
+ } else {
+ ResultPtr aDocRes = ModelAPI_Tools::findPartResult(
+ ModelAPI_Session::get()->moduleDocument(), theContextFeature->document());
+ if (aDocRes.get()) {
+ aName<<aDocRes->data()->name()<<"/";
+ }
+ }
+ }
aName<<theContextFeature->name();
if (theShape.ShapeType() != TopAbs_COMPOUND) { // compound means the whole result for construction
aName<<"/";
// 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;
+}