]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make part documents loaded only by activation
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 8 Sep 2014 15:07:41 +0000 (19:07 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Mon, 8 Sep 2014 15:07:41 +0000 (19:07 +0400)
src/Model/Model_AttributeDocRef.cpp
src/Model/Model_AttributeDocRef.h
src/Model/Model_Document.cpp

index 806408d3332b570279e5c0e930cdc44a7a1a3b5a..67486266c1089c44e8e419e5b97472149cd53b98 100644 (file)
@@ -11,6 +11,7 @@ using namespace std;
 
 void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
 {
+  myDoc = theDoc;
   TCollection_ExtendedString aNewID(theDoc->id().c_str());
   if (!myIsInitialized || myComment->Get() != aNewID) {
     myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
@@ -20,11 +21,7 @@ void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc
 
 boost::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
 {
-  if (myComment->Get().Length())
-    return Model_Application::getApplication()->getDocument(
-        TCollection_AsciiString(myComment->Get()).ToCString());
-  // not initialized
-  return boost::shared_ptr<ModelAPI_Document>();
+  return myDoc;
 }
 
 Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
index dc731701d86451c17889f99d3d7c2a454ace7138..6290e05a41c23c25e999de9d0ab45cd94dd2d61f 100644 (file)
@@ -18,6 +18,7 @@
 class Model_AttributeDocRef : public ModelAPI_AttributeDocRef
 {
   Handle_TDataStd_Comment myComment;  ///< reference to document is identified as string-id
+  boost::shared_ptr<ModelAPI_Document> myDoc; ///< document referenced by this attribute (if already loaded)
  public:
   /// Defines the document referenced from this attribute
   MODEL_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Document> theDoc);
index 55c0fa57faebc798ad55ece6cd46a5ed92f88cb7..cfe40d5f72dd3f48f3a713c047023e6a8d36bf1f 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_Comment.hxx>
+#include <TDataStd_UAttribute.hxx>
 #include <TDF_ChildIDIterator.hxx>
 #include <TDataStd_ReferenceArray.hxx>
 #include <TDataStd_HLabelArray1.hxx>
@@ -763,10 +764,16 @@ void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData
   }
 }
 
+static const Standard_GUID ID_CONSTRUCTION("b59fa408-8ab1-42b8-980c-af5adeebe7e4");
+static const Standard_GUID ID_BODY("c1148e9a-9b17-4e9c-9160-18e918fd0013");
+static const Standard_GUID ID_PART("1b3319b9-3e0a-4298-a1dc-3fb5aaf9be59");
+
 boost::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
-  ObjectPtr anOldObject = object(resultLabel(theFeatureData, theIndex));
+  TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+  TDataStd_UAttribute::Set(aLab, ID_CONSTRUCTION);
+  ObjectPtr anOldObject = object(aLab);
   boost::shared_ptr<ModelAPI_ResultConstruction> aResult;
   if (anOldObject) {
     aResult = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anOldObject);
@@ -781,7 +788,9 @@ boost::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstructio
 boost::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
-  ObjectPtr anOldObject = object(resultLabel(theFeatureData, theIndex));
+  TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+  TDataStd_UAttribute::Set(aLab, ID_BODY);
+  ObjectPtr anOldObject = object(aLab);
   boost::shared_ptr<ModelAPI_ResultBody> aResult;
   if (anOldObject) {
     aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(anOldObject);
@@ -796,7 +805,9 @@ boost::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
 boost::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
-  ObjectPtr anOldObject = object(resultLabel(theFeatureData, theIndex));
+  TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+  TDataStd_UAttribute::Set(aLab, ID_PART);
+  ObjectPtr anOldObject = object(aLab);
   boost::shared_ptr<ModelAPI_ResultPart> aResult;
   if (anOldObject) {
     aResult = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(anOldObject);
@@ -842,13 +853,21 @@ void Model_Document::updateResults(FeaturePtr theFeature)
   int aResSize = theFeature->results().size();
   TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father());
   for(; aLabIter.More(); aLabIter.Next()) {
-    // here must be at least Name
+    // here must be GUID of the feature
     int aResIndex = aLabIter.Value().Tag() - 1;
-    if (aLabIter.Value().FindChild(TAG_FEATURE_ARGUMENTS).HasAttribute() && 
-        aResSize <= aResIndex) 
-    {
-      ResultBodyPtr aNewBody = createBody(theFeature->data(), aResIndex);
-      theFeature->setResult(aNewBody, aResIndex);
+    ResultPtr aNewBody;
+    if (aResSize <= aResIndex) {
+      TDF_Label anArgLab = aLabIter.Value();
+      if (anArgLab.IsAttribute(ID_BODY)) {
+        aNewBody = createBody(theFeature->data(), aResIndex);
+      } else if (anArgLab.IsAttribute(ID_PART)) {
+        aNewBody = createPart(theFeature->data(), aResIndex);
+      } else if (!anArgLab.IsAttribute(ID_CONSTRUCTION)) {
+        Events_Error::send("Unknown type of result if found in the document");
+      }
+      if (aNewBody) {
+        theFeature->setResult(aNewBody, aResIndex);
+      }
     }
   }
 }