Salome HOME
Initial implementation of support of any level of hierarchy in Result Bodies.
[modules/shaper.git] / src / Model / Model_Document.cpp
index 78afb82aac58214bc4d42c4b69288062cbc66b64..caba9de1337b13ec201b8b6032512169212f07d7 100755 (executable)
@@ -30,7 +30,6 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <Events_Loop.h>
 #include <Events_InfoMessage.h>
 
@@ -146,10 +145,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 +282,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);
@@ -1057,6 +1054,14 @@ int Model_Document::size(const std::string& theGroupID, const bool theAllowFolde
   return myObjs->size(theGroupID, theAllowFolder);
 }
 
+std::shared_ptr<ModelAPI_Object> Model_Document::parent(
+  const std::shared_ptr<ModelAPI_Object> theChild)
+{
+  if(myObjs == 0) // may be on close
+    return ObjectPtr();
+  return myObjs->parent(theChild);
+}
+
 std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature(const bool theVisible)
 {
   if (!myObjs) // on close document feature destruction it may call this method
@@ -1146,7 +1151,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") {
@@ -1413,35 +1419,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() == aSubName) {
+            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
@@ -1563,21 +1574,11 @@ void Model_Document::setActive(const bool theFlag)
       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
         object(ModelAPI_Feature::group(), a));
       if (aFeature.get() && aFeature->data()->isValid()) {
-        const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aFeature->results();
-        std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
-        for(; aRes != aResList.end(); aRes++) {
+        std::list<ResultPtr> aResults;
+        ModelAPI_Tools::allResults(aFeature, aResults);
+        for (std::list<ResultPtr>::iterator aRes = aResults.begin();
+                                                aRes != aResults.end(); aRes++) {
           ModelAPI_EventCreator::get()->sendUpdated(*aRes, aRedispEvent);
-          // #issue 1048: sub-compsolids also
-          ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRes);
-          if (aCompRes.get()) {
-            int aNumSubs = aCompRes->numberOfSubs();
-            for(int a = 0; a < aNumSubs; a++) {
-              ResultPtr aSub = aCompRes->subResult(a);
-              if (aSub.get()) {
-                ModelAPI_EventCreator::get()->sendUpdated(aSub, aRedispEvent);
-              }
-            }
-          }
         }
       }
     }
@@ -1751,9 +1752,15 @@ std::shared_ptr<ModelAPI_Feature> Model_Document::producedByFeature(
   if (aShape.IsNull())
     return FeaturePtr();
 
-  // for comsolids and compounds all the naming is located in the main object, so, try to use
+  // for compsolids and compounds all the naming is located in the main object, so, try to use
   // it first
-  ResultCompSolidPtr aMain = ModelAPI_Tools::compSolidOwner(theResult);
+  ResultBodyPtr aMain = ModelAPI_Tools::bodyOwner(theResult);
+  while (aMain.get()) { // get the top-most main
+    ResultBodyPtr aNextMain = ModelAPI_Tools::bodyOwner(aMain);
+    if (aNextMain.get())
+      aMain = aNextMain;
+    else break;
+  }
   if (aMain.get()) {
     FeaturePtr aMainRes = producedByFeature(aMain, theShape);
     if (aMainRes)