]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/Model/Model_Objects.cpp
Salome HOME
Task 2.1. Management of result names
[modules/shaper.git] / src / Model / Model_Objects.cpp
index 373e5ff1457f85861e2794f173db347e0977cd06..e1636118df3e9d6362dd4cb5ec205a567287bcc4 100644 (file)
@@ -933,35 +933,16 @@ TDF_Label Model_Objects::resultLabel(
   return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1);
 }
 
-
-// Obtain an index of result in the CompSolid (return 0 if the indexing is not necessary)
-static int subResultIndex(const FeaturePtr& theFeature, const ResultPtr& theResult)
-{
-  int anIndex = 0;
-  const std::list<ResultPtr>& aResults = theFeature->results();
-  for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
-       aResIt != aResults.end(); ++aResIt) {
-    ResultCompSolidPtr aCompSolidRes =
-        std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIt);
-    if (aCompSolidRes && aCompSolidRes->isSub(theResult, anIndex))
-      break;
-  }
-  return anIndex;
-}
-
 bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   ResultPtr theResult,
                                   int theResultIndex,
                                   std::string& theParentName) const
 {
-  typedef std::list< std::pair < std::string, std::list<ObjectPtr> > > ListOfReferences;
-
-  SessionPtr aSession = ModelAPI_Session::get();
-  FeaturePtr anOwner = ModelAPI_Feature::feature(theResult->data()->owner());
-
   ResultCompSolidPtr aCompSolidRes =
       std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theFeatureData->owner());
   if (aCompSolidRes) {
+    FeaturePtr anOwner = ModelAPI_Feature::feature(theResult->data()->owner());
+
     // names of sub-solids in CompSolid should be default (for example,
     // result of boolean operation 'Boolean_1' is a CompSolid which is renamed to 'MyBOOL',
     // however, sub-elements of 'MyBOOL' should be named 'Boolean_1_1', 'Boolean_1_2' etc.)
@@ -979,49 +960,8 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
     return false;
   }
 
-  std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(anOwner->data());
-
-  ListOfReferences aReferences;
-  aData->referencesToObjects(aReferences);
-
-  // find first result with user-defined name
-  ListOfReferences::const_iterator aFoundRef = aReferences.end();
-  for (ListOfReferences::const_iterator aRefIt = aReferences.begin();
-       aRefIt != aReferences.end(); ++aRefIt) {
-    if (aSession->validators()->isConcealed(anOwner->getKind(), aRefIt->first)) {
-      // check the referred object is a Body
-      // (for example, ExtrusionCut has a sketch as a first attribute which is concealing)
-      bool isBody = aRefIt->second.size() > 1 || (aRefIt->second.size() == 1 &&
-                    aRefIt->second.front()->groupName() == ModelAPI_ResultBody::group());
-      if (isBody && (aFoundRef == aReferences.end() ||
-          aData->isEarlierAttribute(aRefIt->first, aFoundRef->first)))
-        aFoundRef = aRefIt;
-    }
-  }
-
-  // find an object which is concealed by theResult
-  if (aFoundRef != aReferences.end() && !aFoundRef->second.empty()) {
-    std::list<ObjectPtr>::const_iterator anObjIt = aFoundRef->second.begin();
-    while (--theResultIndex >= 0) {
-      ++anObjIt;
-      if (anObjIt == aFoundRef->second.end()) {
-        anObjIt = aFoundRef->second.begin();
-        break;
-      }
-    }
-    // check the result is a Body
-    if ((*anObjIt)->groupName() == ModelAPI_ResultBody::group()) {
-      // check the result is part of CompSolid
-      ResultPtr anObjRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anObjIt);
-      ResultCompSolidPtr aParentCompSolid = ModelAPI_Tools::compSolidOwner(anObjRes);
-      if (aParentCompSolid)
-        anObjRes = aParentCompSolid;
-      theParentName = anObjRes->data()->name();
-      return true;
-    }
-  }
-
-  return false;
+  theParentName = ModelAPI_Tools::getDefaultName(theResult, theResultIndex);
+  return true;
 }
 
 void Model_Objects::storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,