Salome HOME
Fix for the issue #2020 : take into account not yet loaded documents to generate...
[modules/shaper.git] / src / Model / Model_Document.cpp
index 411f8bac7fd42540cc7b792f9c47d303b1cb9049..ce8386a2ef30547398597ecd3b3321697c0979bd 100755 (executable)
@@ -16,6 +16,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <Events_Loop.h>
 #include <Events_InfoMessage.h>
 
@@ -37,6 +38,8 @@
 #include <TDF_ListIteratorOfAttributeDeltaList.hxx>
 #include <TDF_ListIteratorOfLabelList.hxx>
 #include <TDF_LabelMap.hxx>
+#include <TDF_DeltaOnAddition.hxx>
+#include <TNaming_Builder.hxx>
 #include <TNaming_SameShapeIterator.hxx>
 #include <TNaming_Iterator.hxx>
 #include <TNaming_NamedShape.hxx>
@@ -71,12 +74,14 @@ static const int TAG_CURRENT_FEATURE = 1; ///< reference to the current feature
 static const int TAG_CURRENT_TRANSACTION = 2; ///< integer, index of the transaction
 static const int TAG_SELECTION_FEATURE = 3; ///< integer, tag of the selection feature label
 static const int TAG_NODES_STATE = 4; ///< array, tag of the Object Browser nodes states
+///< naming structures constructions selected from other document
+static const int TAG_EXTERNAL_CONSTRUCTIONS = 5;
 
 Model_Document::Model_Document(const int theID, const std::string theKind)
     : myID(theID), myKind(theKind), myIsActive(false),
       myDoc(new TDocStd_Document("BinOcaf"))  // binary OCAF format
 {
-#ifdef DFBROWSER
+#ifdef TINSPECTOR
   CDF_Session::CurrentSession()->Directory()->Add(myDoc);
 #endif
   myObjs = new Model_Objects(myDoc->Main());
@@ -195,6 +200,7 @@ bool Model_Document::load(const char* theDirName, const char* theFileName, Docum
   if (!isError) {
     myDoc = aLoaded;
     myDoc->SetUndoLimit(UNDO_LIMIT);
+
     // to avoid the problem that feature is created in the current, not this, document
     aSession->setActiveDocument(anApp->document(myID), false);
     aSession->setCheckTransactions(false);
@@ -216,7 +222,8 @@ bool Model_Document::load(const char* theDirName, const char* theFileName, Docum
     for(; aPartRes != aPartResults.end(); aPartRes++) {
       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aPartRes);
       if (aPart.get())
-        anApp->setLoadByDemand(aPart->data()->name());
+        anApp->setLoadByDemand(aPart->data()->name(),
+          aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->docId());
     }
 
   } else { // open failed, but new documnet was created to work with it: inform the model
@@ -679,7 +686,7 @@ void Model_Document::abortOperation()
   for (; aSubIter != aSubs.end(); aSubIter++)
     subDoc(*aSubIter)->abortOperation();
   // references may be changed because they are set in attributes on the fly
-  myObjs->synchronizeFeatures(aDeltaLabels, true, false, isRoot());
+  myObjs->synchronizeFeatures(aDeltaLabels, true, false, false, isRoot());
 }
 
 bool Model_Document::isOperation() const
@@ -746,7 +753,7 @@ void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchron
   }
   // after undo of all sub-documents to avoid updates on not-modified data (issue 370)
   if (theSynchronize) {
-    myObjs->synchronizeFeatures(aDeltaLabels, true, false, isRoot());
+    myObjs->synchronizeFeatures(aDeltaLabels, true, false, false, isRoot());
     // update the current features status
     setCurrentFeature(currentFeature(false), false);
   }
@@ -793,7 +800,7 @@ void Model_Document::redo()
     subDoc(*aSubIter)->redo();
 
   // after redo of all sub-documents to avoid updates on not-modified data (issue 370)
-  myObjs->synchronizeFeatures(aDeltaLabels, true, false, isRoot());
+  myObjs->synchronizeFeatures(aDeltaLabels, true, false, false, isRoot());
   // update the current features status
   setCurrentFeature(currentFeature(false), false);
 }
@@ -1238,6 +1245,20 @@ TDF_Label Model_Document::findNamingName(std::string theName)
         if (aName->Get() == aSubName)
           return aName->Label();
       }
+      // If not found child label with the exact sub-name, then try to find compound with
+      // such sub-name without suffix.
+      Standard_Integer aSuffixPos = aSubName.SearchFromEnd('_');
+      if (aSuffixPos != -1) {
+        TCollection_ExtendedString anIndexStr = aSubName.Split(aSuffixPos);
+        aSubName.Remove(aSuffixPos);
+        aNamesIter.Initialize(aFind->second, TDataStd_Name::GetID(), Standard_True);
+        for(; aNamesIter.More(); aNamesIter.Next()) {
+          Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
+          if (aName->Get() == aSubName) {
+            return aName->Label();
+          }
+        }
+      }
     }
   }
   return TDF_Label(); // not found
@@ -1312,6 +1333,11 @@ void Model_Document::decrementTransactionID()
   TDataStd_Integer::Set(generalLabel().FindChild(TAG_CURRENT_TRANSACTION), aNewVal);
 }
 
+TDF_Label Model_Document::extConstructionsLabel() const
+{
+  return myDoc->Main().FindChild(TAG_EXTERNAL_CONSTRUCTIONS);
+}
+
 bool Model_Document::isOpened()
 {
   return myObjs && !myDoc.IsNull();