]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #271: referencing between documents is implemented (the issue for filtering...
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 24 Nov 2014 11:12:16 +0000 (14:12 +0300)
committersbh <sergey.belash@opencascade.com>
Tue, 25 Nov 2014 08:41:58 +0000 (11:41 +0300)
src/Model/Model_AttributeReference.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_Session.cpp
src/Model/Model_Session.h
src/ModelAPI/ModelAPI_Session.h
src/ModuleBase/ModuleBase_ViewerFilters.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp

index e209eb0e12ef43ac33786ce9bbf025e7e8cb3554..e65cb91c2e2f6a32cf6537c128c3f62a430992f0 100644 (file)
@@ -7,6 +7,11 @@
 #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;
 
@@ -15,12 +20,25 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
   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);
   }
@@ -29,11 +47,28 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
 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
index 0ae4bf6a844fe2a337497a37b429684e3de6546c..4f95dc83fa93813defbf8631de18c7c4309d05cb 100644 (file)
@@ -127,7 +127,7 @@ bool Model_AttributeSelection::update()
       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) {
@@ -296,7 +296,7 @@ void Model_AttributeSelection::selectBody(
 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) {
index d8e5166986f5a7cfb9329ccf7747ba2e0993dfde..88f87b73e0e54e028cc0ab7ca28f9f2c6ff41c75 100644 (file)
@@ -141,6 +141,12 @@ std::shared_ptr<ModelAPI_Document> Model_Session::moduleDocument()
       Model_Application::getApplication()->getDocument("root"));
 }
 
+std::shared_ptr<ModelAPI_Document> Model_Session::document(std::string theDocID)
+{
+  return std::shared_ptr<ModelAPI_Document>(
+      Model_Application::getApplication()->getDocument(theDocID));
+}
+
 bool Model_Session::hasModuleDocument()
 {
   return Model_Application::getApplication()->hasDocument("root");
index 72977752ad95671df6004834cc35e92f1007b8ea..41d62e4f9162fb0124ff7f969e271eb9da524583 100644 (file)
@@ -69,6 +69,9 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   /// Returns the root document of the application (that may contains sub-documents)
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
 
+  /// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document(std::string theDocID);
+
   /// Return true if root document has been already created
   MODEL_EXPORT virtual bool hasModuleDocument();
 
index 811174e7c235b4614f323824b07cacaba0a7c116..67186674da8390529428312c309fa1030071003f 100644 (file)
@@ -71,6 +71,9 @@ class MODELAPI_EXPORT ModelAPI_Session
   /// Returns the root document of the application (that may contains sub-documents)
   virtual std::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
 
+  /// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
+  virtual std::shared_ptr<ModelAPI_Document> document(std::string theDocID) = 0;
+
   /// Return true if root document has been already created
   virtual bool hasModuleDocument() = 0;
 
index a7e2cd3f7b383a80988a86f2f1d8ab396fb37274..e7309ca072b2ee7fb3bdaaf82070f5bef50156ec 100644 (file)
@@ -37,7 +37,7 @@ Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_Ent
       if (aObj) {
         DocumentPtr aDoc = aObj->document();
         SessionPtr aMgr = ModelAPI_Session::get();
-        return (aDoc == aMgr->activeDocument() /* MPV: for the current moment selection in other document is not possible || (aDoc == aMgr->moduleDocument()*/);
+        return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
       }
     }
   }
index 146e62efb02f475cb9703dc233c69c7264f0895d..2ec2248e42e4ce38c60c68ad3bd2eb97e58ec1c0 100644 (file)
@@ -205,7 +205,7 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
     // Check that object belongs to active document or PartSet
     DocumentPtr aDoc = aRes->document();
     SessionPtr aMgr = ModelAPI_Session::get();
-    if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
+    if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument()))
       return;
 
     // Check that the result has a shape