Salome HOME
Update to use the latest version of TInspector (OCCT 7.5.3)
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 369fb52a7f78c23a034f2379bea34703c5b4f3c6..432c6f1c2e7740d37293b040c46aafd89823e727 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -604,6 +604,8 @@ bool Model_AttributeSelection::update()
     aResult = aSelector.restore(aContextShape);
     bool aWasInvalid = aSelLab.IsAttribute(kINVALID_SELECTION);
     setInvalidIfFalse(aSelLab, aResult);
+    if (!aResult)
+      aWasInvalid = false;
 
     TopoDS_Shape aNewShape;
     if (aSelLab.FindAttribute(TNaming_NamedShape::GetID(), aNS))
@@ -1055,7 +1057,22 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
   // collect features from PartSet and the current part
   SessionPtr aSession = ModelAPI_Session::get();
   std::list<FeaturePtr> aFeatures = aSession->moduleDocument()->allFeatures();
-  if (aSession->moduleDocument() != owner()->document()) {
+  if (anOwner->getKind() == "ImportResult") {
+    // special case: feature "ImportResult" refers to the results from another parts,
+    // thus, it is necessary to go through the features of these parts too.
+    std::list<FeaturePtr> aPartSetFeatures = aFeatures;
+    aFeatures.clear();
+    for (std::list<FeaturePtr>::iterator it = aPartSetFeatures.begin();
+         it != aPartSetFeatures.end(); ++it) {
+      aFeatures.push_back(*it);
+      if ((*it)->firstResult()->groupName() == ModelAPI_ResultPart::group()) {
+        ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>((*it)->firstResult());
+        std::list<FeaturePtr> aPartFeatures = aPart->partDoc()->allFeatures();
+        aFeatures.insert(aFeatures.end(), aPartFeatures.begin(), aPartFeatures.end());
+      }
+    }
+  }
+  else if (aSession->moduleDocument() != owner()->document()) {
     std::list<FeaturePtr> aPartFeatures = owner()->document()->allFeatures();
     aFeatures.insert(aFeatures.end(), aPartFeatures.begin(), aPartFeatures.end());
   }
@@ -2052,24 +2069,28 @@ ResultPtr Model_AttributeSelection::newestContext(
     //if (aResult->groupName() == ModelAPI_ResultBody::group()) {
       // try to search newer context by the concealment references
       // take references to all results: root one, any sub
-    std::list<ResultPtr> allRes;
+    std::list<DataPtr> allRes;
     ResultPtr aCompContext;
     ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aResult, true);
     if (aCompBody.get()) {
-      ModelAPI_Tools::allSubs(aCompBody, allRes);
-      allRes.push_back(aCompBody);
+      std::list<ResultPtr> allSub;
+      ModelAPI_Tools::allSubs(aCompBody, allSub);
+      for(std::list<ResultPtr>::iterator anIt = allSub.begin(); anIt != allSub.end(); anIt++)
+        allRes.push_back((*anIt)->data());
+      allRes.push_back(aCompBody->data());
       aCompContext = aCompBody;
     }
     if (allRes.empty())
-      allRes.push_back(aResult);
+      allRes.push_back(aResult->data());
+    allRes.push_back(aResult->document()->feature(aResult)->data());
 
     bool aFoundReferernce = false;
-    for (std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
-      ResultPtr aResCont = *aSub;
-      ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResCont);
+    for (std::list<DataPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
+      DataPtr aResCont = *aSub;
+      ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResCont->owner());
       if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext)
         continue; // only lower and higher level subs are counted
-      const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
+      const std::set<AttributePtr>& aRefs = aResCont->refsToMe();
       std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
       for (; !aFindNewContext && aRef != aRefs.end(); aRef++) {
         if (!aRef->get() || !(*aRef)->owner().get())