Salome HOME
Fix for sketcher plane selection in complex operations like ExtrusionCut
[modules/shaper.git] / src / Model / Model_Document.cpp
index 2be9514ca24746c6218041a740d7df0bca72d864..ae27c2af263a9105cc5e04dfca96e5f0b7994a5c 100755 (executable)
@@ -146,10 +146,9 @@ bool Model_Document::load(const char* theDirName, const char* theFileName, Docum
   Handle(TDocStd_Document) aLoaded;
   try {
     aStatus = anApp->Open(aPath, aLoaded);
-  } catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+  } catch (Standard_Failure const& anException) {
     Events_InfoMessage("Model_Document",
-        "Exception in opening of document: %1").arg(aFail->GetMessageString()).send();
+        "Exception in opening of document: %1").arg(anException.GetMessageString()).send();
     return false;
   }
   bool isError = aStatus != PCDM_RS_OK;
@@ -284,10 +283,9 @@ bool Model_Document::save(
   PCDM_StoreStatus aStatus;
   try {
     aStatus = anApp->SaveAs(myDoc, aPath);
-  } catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+  } catch (Standard_Failure const& anException) {
     Events_InfoMessage("Model_Document",
-        "Exception in saving of document: %1").arg(aFail->GetMessageString()).send();
+        "Exception in saving of document: %1").arg(anException.GetMessageString()).send();
     if (aWasCurrent.get()) { // return the current feature to the initial position
       setCurrentFeature(aWasCurrent, false);
       aSession->setCheckTransactions(true);
@@ -1146,7 +1144,8 @@ void Model_Document::setCurrentFeature(
         aDisabledFlag = false;
       else if (anOwners.find(anIter) != anOwners.end())
         // disable the higher-level feature if the nested is the current
-        aDisabledFlag = true;
+        if (aMain->getKind() != "Import") // exception for the import XAO feature with Group (2430)
+          aDisabledFlag = true;
     }
 
     if (anIter->getKind() == "Parameter") {
@@ -1282,6 +1281,13 @@ std::shared_ptr<ModelAPI_Folder> Model_Document::findFolderBelow(
   return myObjs->findFolder(theFeatures, true);
 }
 
+std::shared_ptr<ModelAPI_Folder> Model_Document::findContainingFolder(
+      const std::shared_ptr<ModelAPI_Feature>& theFeature,
+      int& theIndexInFolder)
+{
+  return myObjs->findContainingFolder(theFeature, theIndexInFolder);
+}
+
 bool Model_Document::moveToFolder(
       const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
       const std::shared_ptr<ModelAPI_Folder>& theFolder)
@@ -1299,6 +1305,8 @@ bool Model_Document::removeFromFolder(
 std::shared_ptr<ModelAPI_Feature> Model_Document::feature(
     const std::shared_ptr<ModelAPI_Result>& theResult)
 {
+  if (myObjs == 0) // may be on close
+    return std::shared_ptr<ModelAPI_Feature>();
   return myObjs->feature(theResult);
 }
 
@@ -1404,28 +1412,40 @@ TDF_Label Model_Document::findNamingName(std::string theName, ResultPtr theConte
           if (theContext != myObjs->object(aLabIter->Father()))
             continue;
         }
+        // copy aSubName to avoid incorrect further processing after its suffix cutting
+        TCollection_ExtendedString aSubNameCopy(aSubName);
         // searching sub-labels with this name
         TDF_ChildIDIterator aNamesIter(*aLabIter, TDataStd_Name::GetID(), Standard_True);
         for(; aNamesIter.More(); aNamesIter.Next()) {
           Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
-          if (aName->Get() == aSubName)
+          if (aName->Get() == aSubNameCopy)
             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 && aSuffixPos != aSubName.Length()) {
-          TCollection_ExtendedString anIndexStr = aSubName.Split(aSuffixPos);
-          aSubName.Remove(aSuffixPos);
+        Standard_Integer aSuffixPos = aSubNameCopy.SearchFromEnd('_');
+        if (aSuffixPos != -1 && aSuffixPos != aSubNameCopy.Length()) {
+          TCollection_ExtendedString anIndexStr = aSubNameCopy.Split(aSuffixPos);
+          aSubNameCopy.Remove(aSuffixPos);
           aNamesIter.Initialize(*aLabIter, TDataStd_Name::GetID(), Standard_True);
           for(; aNamesIter.More(); aNamesIter.Next()) {
             Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
-            if (aName->Get() == aSubName) {
+            if (aName->Get() == aSubNameCopy) {
+              return aName->Label();
+            }
+          }
+          // check also "this" label
+          Handle(TDataStd_Name) aName;
+          if (aLabIter->FindAttribute(TDataStd_Name::GetID(), aName)) {
+            if (aName->Get() == aSubNameCopy) {
               return aName->Label();
             }
           }
         }
       }
+      // verify context's name is same as sub-component's and use context's label
+      if (aSubName.IsEqual(anObjName.c_str()))
+        return *(aFind->second.rbegin());
     }
   }
   return TDF_Label(); // not found
@@ -1863,3 +1883,15 @@ void Model_Document::eraseAllFeatures()
   if (myObjs)
     myObjs->eraseAllFeatures();
 }
+
+void Model_Document::setExecuteFeatures(const bool theFlag)
+{
+  myExecuteFeatures = theFlag;
+  const std::set<int> aSubs = subDocuments();
+  std::set<int>::iterator aSubIter = aSubs.begin();
+  for (; aSubIter != aSubs.end(); aSubIter++) {
+    if (!subDoc(*aSubIter)->myObjs)
+      continue;
+    subDoc(*aSubIter)->setExecuteFeatures(theFlag);
+  }
+}