#include "Model_Events.h"
#include "Model_Data.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Session.h>
+
+#include <TDataStd_Comment.hxx>
+#include <TDataStd_AsciiString.hxx>
+#include <TDF_Tool.hxx>
using namespace std;
if(!theObject)
return;
if (!myIsInitialized || value() != theObject) {
- std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
- theObject->data());
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+ theObject->data());
+ TDF_Label anObjLab = aData->label().Father(); // object label
- std::shared_ptr<Model_Document> aDoc =
- std::dynamic_pointer_cast<Model_Document>(owner()->document());
- myRef->Set(aData->label().Father()); // references to the feature label
+ if (owner()->document() == theObject->document()) { // same document, use reference attribute
+
+ std::shared_ptr<Model_Document> aDoc =
+ std::dynamic_pointer_cast<Model_Document>(owner()->document());
+ myRef->Set(anObjLab); // references to the object label
+ // remove external link attributes (if any)
+ anObjLab.ForgetAttribute(TDataStd_Comment::GetID());
+ anObjLab.ForgetAttribute(TDataStd_AsciiString::GetID());
+ } else { // different document: store the document name (comment) and entry (string): external
+ // if these attributes exist, the link is external: keep reference to access the label
+ TDataStd_Comment::Set(myRef->Label(), theObject->document()->id().c_str());
+ TCollection_AsciiString anEntry;
+ TDF_Tool::Entry(anObjLab, anEntry);
+ TDataStd_AsciiString::Set(myRef->Label(), anEntry);
+ }
owner()->data()->sendAttributeUpdated(this);
}
ObjectPtr Model_AttributeReference::value()
{
if (myIsInitialized) {
- std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
- owner()->document());
- if (aDoc) {
- TDF_Label aRefLab = myRef->Get();
- return aDoc->object(aRefLab);
+ Handle(TDataStd_Comment) aDocID;
+ if (myRef->Label().FindAttribute(TDataStd_Comment::GetID(), aDocID)) { // external ref
+ DocumentPtr aRefDoc =
+ ModelAPI_Session::get()->document(TCollection_AsciiString(aDocID->Get()).ToCString());
+ if (aRefDoc) {
+ Handle(TDataStd_AsciiString) anEntry;
+ if (myRef->Label().FindAttribute(TDataStd_AsciiString::GetID(), anEntry)) {
+ std::shared_ptr<Model_Document> aDR = std::dynamic_pointer_cast<Model_Document>(aRefDoc);
+ TDF_Label aRefLab;
+ TDF_Tool::Label(aDR->featuresLabel().Data(), anEntry->Get().ToCString(), aRefLab);
+ if (!aRefLab.IsNull()) {
+ return aDR->object(aRefLab);
+ }
+ }
+ }
+ } else { // internal ref
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+ owner()->document());
+ if (aDoc) {
+ TDF_Label aRefLab = myRef->Get();
+ return aDoc->object(aRefLab);
+ }
}
}
// not initialized
bool aNoIndexes =
!aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0;
// for now working only with composite features
- FeaturePtr aContextFeature = owner()->document()->feature(aContext);
+ FeaturePtr aContextFeature = aContext->document()->feature(aContext);
CompositeFeaturePtr aComposite =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
if (!aComposite || aComposite->numberOfSubs() == 0) {
void Model_AttributeSelection::selectConstruction(
const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
{
- FeaturePtr aContextFeature = owner()->document()->feature(theContext);
+ FeaturePtr aContextFeature = theContext->document()->feature(theContext);
CompositeFeaturePtr aComposite =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
if (!aComposite || aComposite->numberOfSubs() == 0) {