]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Initial implementation of support of any level of hierarchy in Result Bodies.
authormpv <mpv@opencascade.com>
Tue, 31 Jul 2018 14:11:05 +0000 (17:11 +0300)
committermpv <mpv@opencascade.com>
Tue, 31 Jul 2018 14:11:05 +0000 (17:11 +0300)
Removed ResultCompSolid class. Instead ResultBody may have any number of subs, or not.

44 files changed:
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp
src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp
src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp
src/FeaturesPlugin/FeaturesPlugin_Union.cpp
src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/GeomValidators/GeomValidators_BodyShapes.cpp
src/Model/CMakeLists.txt
src/Model/Model_AttributeSelection.cpp
src/Model/Model_Data.cpp
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_Objects.cpp
src/Model/Model_Objects.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultCompSolid.cpp [deleted file]
src/Model/Model_ResultCompSolid.h [deleted file]
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_ResultBody.cpp
src/ModelAPI/ModelAPI_ResultBody.h
src/ModelAPI/ModelAPI_ResultCompSolid.cpp [deleted file]
src/ModelAPI/ModelAPI_ResultCompSolid.h [deleted file]
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModelAPI/ModelAPI_swig.h
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/PartSet/PartSet_OperationPrs.cpp
src/PartSet/PartSet_ResultSketchPrs.cpp
src/PartSet/PartSet_TreeNodes.cpp
src/PartSet/PartSet_Validators.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_WorkshopListener.cpp

index 9104486c1b0b337fe615068d27f25e6b1178f2e9..99afc6e8dbf6d78c1c37838d639f26fad7caf9f4 100644 (file)
@@ -24,7 +24,6 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Session.h>
@@ -100,7 +99,7 @@ void FeaturesPlugin_Boolean::execute()
       return;
     }
     ResultPtr aContext = anObjectAttr->context();
-    ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
     if(aResCompSolidPtr.get()
         && aResCompSolidPtr->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) {
       std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
index f54449b36ed98d0e6939561bcfea1eebfab2ef8f..9cdf2b7ccd45eafe2de8dcb2a7a4975c838dc6a1 100644 (file)
@@ -21,7 +21,6 @@
 #include "FeaturesPlugin_CompositeBoolean.h"
 
 #include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Tools.h>
 
 #include <GeomAlgoAPI_Boolean.h>
@@ -123,7 +122,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools,
       return false;
     }
     ResultPtr aContext = anObjectAttr->context();
-    ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
     if(aResCompSolidPtr.get()) {
       GeomShapePtr aContextShape = aResCompSolidPtr->shape();
       std::map<GeomShapePtr, ListOfShape>::iterator anIt = aCompSolidsObjects.begin();
index 30f922aa8be2b236e159f6a3eefbe698a2f7cfbb..eab8b03ca8c4721d6ae00316736b76c321fb6076 100644 (file)
@@ -25,7 +25,6 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_Validator.h>
@@ -113,7 +112,7 @@ void FeaturesPlugin_Fillet::execute()
       return;
 
     ResultPtr aContext = anObjectAttr->context();
-    ResultCompSolidPtr aCtxOwner = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aCtxOwner = ModelAPI_Tools::bodyOwner(aContext);
     GeomShapePtr aParent = aCtxOwner ? aCtxOwner->shape() : aContext->shape();
     if (!aParent)
       return;
index a63ac8af06c5bfabb3c44626d260b84cb2052eaf..75b1d9c09dceec344b4969a45518951d7d32f82e 100644 (file)
@@ -23,7 +23,6 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
@@ -72,14 +71,14 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
   }
 
   ResultPtr aContext = aShapeAttrSelection->context();
-  ResultCompSolidPtr aResultCompSolid =
-    std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
-  if(!aResultCompSolid.get()) {
+  ResultBodyPtr aResultBody =
+    std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
+  if (!aResultBody.get()) {
     aSubShapesToKeepAttrList->clear();
     aSubShapesToRemoveAttrList->clear();
     return;
   }
-  const int aNumOfSubs = aResultCompSolid->numberOfSubs();
+  const int aNumOfSubs = aResultBody->numberOfSubs();
 
   GeomShapePtr aBaseShape = aShapeAttrSelection->value();
   if(!aBaseShape.get()) {
@@ -101,8 +100,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
       if(aNumOfSubs == 0) {
         aSubShapesToKeepAttrList->append(aContext, aSubShape);
       } else {
-        for(int anIndex = 0; anIndex < aResultCompSolid->numberOfSubs(); ++anIndex) {
-          ResultBodyPtr aSubResult = aResultCompSolid->subResult(anIndex);
+        for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
+          ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
           if(aSubResult->shape()->isEqual(aSubShape)) {
             aSubShapesToKeepAttrList->append(aSubResult, aSubShape);
             break;
@@ -135,8 +134,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
         if(aNumOfSubs == 0) {
           aSubShapesToRemoveAttrList->append(aContext, aSubShape);
         } else {
-          for(int anIndex = 0; anIndex < aResultCompSolid->numberOfSubs(); ++anIndex) {
-            ResultBodyPtr aSubResult = aResultCompSolid->subResult(anIndex);
+          for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
+            ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
             if(aSubResult->shape()->isEqual(aSubShape)) {
               aSubShapesToRemoveAttrList->append(aSubResult, aSubShape);
               break;
@@ -170,8 +169,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
         if(aNumOfSubs == 0) {
           aSubShapesToKeepAttrList->append(aContext, aSubShape);
         } else {
-          for(int anIndex = 0; anIndex < aResultCompSolid->numberOfSubs(); ++anIndex) {
-            ResultBodyPtr aSubResult = aResultCompSolid->subResult(anIndex);
+          for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
+            ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
             if(aSubResult->shape()->isEqual(aSubShape)) {
               aSubShapesToKeepAttrList->append(aSubResult, aSubShape);
               break;
index 76683a26fa5a866c2e57a40affcf19d468a82cdd..33bd7450b473240a9628247f6af01064b41909b8 100644 (file)
@@ -29,7 +29,7 @@
 #include <GeomAPI_ShapeIterator.h>
 
 #include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
 
 //=================================================================================================
@@ -59,7 +59,7 @@ void FeaturesPlugin_Union::execute()
       return;
     }
     ResultPtr aContext = anObjectAttr->context();
-    ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
     if(aResCompSolidPtr.get()) {
       std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
       std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape>::iterator
index 41dd47afb9751f5bb55b8d04786caf88f0460ebb..13a0292e0d0bdb60f2576c569ddb7b5b59cb0833 100755 (executable)
@@ -25,7 +25,6 @@
 #include "ModelAPI_AttributeSelectionList.h"
 #include "ModelAPI_ResultPart.h"
 #include "ModelAPI_ResultBody.h"
-#include "ModelAPI_ResultCompSolid.h"
 #include "ModelAPI_Session.h"
 
 bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute,
@@ -59,7 +58,7 @@ bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute
     else { // Part document: Result CompSolid is valid
       aValid = aResult->groupName() == ModelAPI_ResultBody::group();
       if (aValid) {
-        ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+        ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
         aValid = aComp.get() != NULL;
       }
     }
index 0a85e1ab4418858699d50ece0707a7faac41a408..4c558d9259be52b2727919250f0f9fbae051bcae 100644 (file)
@@ -32,7 +32,7 @@
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Tools.h>
 
@@ -671,7 +671,7 @@ bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAtt
       return false;
     }
 
-    ResultCompSolidPtr aContextOwner = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext);
     GeomShapePtr anOwner = aContextOwner.get() ? aContextOwner->shape() : aContext->shape();
 
     if (anOwner->shapeType() != GeomAPI_Shape::SOLID &&
@@ -724,9 +724,8 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
       return false;
     }
 
-    ResultCompSolidPtr aResultCompsolid =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
-    if(aResultCompsolid.get()) {
+    ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
+    if(aResultBody.get()) {
       continue;
     }
 
@@ -888,8 +887,8 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr
       return false;
     }
 
-    ResultCompSolidPtr aResult =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
+    ResultBodyPtr aResult =
+      std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
     if(!aResult.get()) {
       continue;
     }
@@ -1036,7 +1035,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
 
   bool isAllInSameCompSolid = true;
-  ResultCompSolidPtr aCompSolid;
+  ResultBodyPtr aCompSolid;
 
   AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
   if (anAttrSelList)
@@ -1046,7 +1045,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
     {
       AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
       ResultPtr aContext = anAttr->context();
-      ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+      ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
       if (aResCompSolidPtr.get())
       {
         if (aCompSolid.get())
@@ -1078,7 +1077,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid(
       {
         AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
         ResultPtr aContext = anAttr->context();
-        ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+        ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
         if (aResCompSolidPtr.get())
         {
           if (aCompSolid.get())
index bcfae3effe85aa00701b7cf8094d295dba1dc549..8faa007ecb1942156b8ceac9d09421cedd65a845 100644 (file)
@@ -49,7 +49,7 @@ bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute,
     }
     // additional check that the selected object is top-level result
     if (theArguments.size() > 0 && *(theArguments.rbegin()) == "toplevel") {
-      if (ModelAPI_Tools::compSolidOwner(aContext).get()) {
+      if (ModelAPI_Tools::bodyOwner(aContext).get()) {
         theError = "Error: Only higher level shape allowed.";
         return false;
       }
index 37dfcb27424d05e826b24dacfaca1fde0304ef0d..cacba22ced29ee99dcdf0d44bbaada591ef5c69c 100644 (file)
@@ -48,7 +48,6 @@ SET(PROJECT_HEADERS
     Model_Update.h
     Model_Validator.h
     Model_ResultBody.h
-    Model_ResultCompSolid.h
     Model_ResultConstruction.h
     Model_ResultPart.h
     Model_ResultField.h
@@ -86,7 +85,6 @@ SET(PROJECT_SOURCES
     Model_Update.cpp
     Model_Validator.cpp
     Model_ResultBody.cpp
-    Model_ResultCompSolid.cpp
     Model_ResultConstruction.cpp
     Model_ResultPart.cpp
     Model_ResultField.cpp
index d2456c85e199fa4bb5f7838cf14d78549250d2a8..985bd4b1200550616219b658a1a4dae4b4174efc 100644 (file)
@@ -29,7 +29,7 @@
 #include <Model_ResultConstruction.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_CompositeFeature.h>
@@ -409,10 +409,8 @@ void Model_AttributeSelection::setID(const std::string theID)
 }
 
 ResultPtr Model_AttributeSelection::context() {
-  /*
   if (!ModelAPI_AttributeSelection::isInitialized() && !myTmpContext.get() && !myTmpSubShape.get())
     return ResultPtr();
-  */
 
   if (myTmpContext.get() || myTmpSubShape.get()) {
     return myTmpContext;
@@ -682,8 +680,10 @@ void Model_AttributeSelection::selectBody(
     }
     if (!isFound) { // sub-shape is not found in the up-to-date instance of the context shape
       // if context is sub-result of compound/compsolid, selection of sub-shape better propagate to
-      // the main result (which is may be modified), case is in 1799
-      ResultCompSolidPtr aMain = ModelAPI_Tools::compSolidOwner(theContext);
+      // the main result (which is may be modified); the case is in 1799
+      ResultBodyPtr aMain = ModelAPI_Tools::bodyOwner(theContext);
+      while(ModelAPI_Tools::bodyOwner(aMain).get())
+        aMain = ModelAPI_Tools::bodyOwner(theContext);
       if (aMain.get()) {
         selectBody(aMain, theSubShape);
         return;
@@ -883,10 +883,13 @@ void Model_AttributeSelection::selectSubShape(
       }
       // if compsolid is context, try to take sub-solid as context: like in GUI and scripts
       if (aCont.get() && aShapeToBeSelected.get()) {
-        ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aCont);
+        ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aCont);
         if (aComp && aComp->numberOfSubs()) {
-          for(int aSubNum = 0; aSubNum < aComp->numberOfSubs(); aSubNum++) {
-            ResultPtr aSub = aComp->subResult(aSubNum);
+          std::list<ResultPtr> allSubs;
+          ModelAPI_Tools::allSubs(aComp, allSubs);
+          std::list<ResultPtr>::reverse_iterator aS = allSubs.rbegin(); // iterate from lower level
+          for(; aS != allSubs.rend(); aS++) {
+            ResultPtr aSub = *aS;
             if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aShapeToBeSelected)) {
               aCont = aSub;
               break;
@@ -900,14 +903,13 @@ void Model_AttributeSelection::selectSubShape(
       while(aFindNewContext && aCont.get()) {
         aFindNewContext = false;
         // take references to all results: root one, any sub
-        ResultCompSolidPtr aCompContext = ModelAPI_Tools::compSolidOwner(aCont);
-        int aSubsSize = (aCompContext.get() ? aCompContext->numberOfSubs() : 0) + 1;
-        for(int aResultNum = 0; aResultNum < aSubsSize; aResultNum++) {
-          ResultPtr aResCont = aCont;
-          if (aCompContext.get())
-            if (aResultNum == aSubsSize - 1)
-              aResCont = aCompContext;
-            else aResCont = aCompContext->subResult(aResultNum);
+        ResultBodyPtr aCompContext = ModelAPI_Tools::bodyOwner(aCont);
+        std::list<ResultPtr> allRes;
+        if (aCompContext.get())
+          ModelAPI_Tools::allSubs(aCompContext, allRes);
+        allRes.push_back(aCont);
+        for(std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
+          ResultPtr aResCont = *aSub;
           const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
           std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
           for(; !aFindNewContext && aRef != aRefs.end(); aRef++) {
@@ -922,20 +924,13 @@ void Model_AttributeSelection::selectSubShape(
             std::list<std::shared_ptr<ModelAPI_Result> > aResults;
 
             // take all sub-results or one result
-            const std::list<std::shared_ptr<ModelAPI_Result> >& aFResults = aRefFeat->results();
-            std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aFResults.begin();
-            for (; aRIter != aFResults.cend(); aRIter++) {
-              // iterate sub-bodies of compsolid
-              ResultCompSolidPtr aComp =
-                std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRIter);
-              if (aComp.get() && aComp->numberOfSubs() > 0) {
-                int aNumSub = aComp->numberOfSubs();
-                for(int a = 0; a < aNumSub; a++) {
-                  aResults.push_back(aComp->subResult(a));
-                }
-              } else {
-                aResults.push_back(*aRIter);
-              }
+            std::list<ResultPtr> aRefFeatResults;
+            ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults);
+            std::list<ResultPtr>::iterator aRefResIter = aRefFeatResults.begin();
+            for(; aRefResIter != aRefFeatResults.end(); aRefResIter++) {
+              ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRefResIter);
+              if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs
+                aResults.push_back(aBody);
             }
             std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = aResults.begin();
             for(; aResIter != aResults.end(); aResIter++) {
@@ -946,8 +941,6 @@ void Model_AttributeSelection::selectSubShape(
                 aShapeToBeSelected.get() ? aShapeToBeSelected : aCont->shape();
               if (aShape.get() && aShape->isSubShape(aSelectedShape, false)) {
                 aCont = *aResIter; // found new context (produced from this) with same subshape
-                //if (!aShape->isSubShape(aShapeToBeSelected, true)) // take context orientation
-                //  aShapeToBeSelected->setOrientation();
                 aFindNewContext = true; // continue searching futher
                 break;
               }
@@ -976,17 +969,18 @@ int Model_AttributeSelection::Id()
 {
   int anID = 0;
   std::shared_ptr<GeomAPI_Shape> aSelection = value();
-  std::shared_ptr<GeomAPI_Shape> aContext = context()->shape();
+  ResultPtr aContextRes = context();
   // support for compsolids:
-  if (context().get() && ModelAPI_Tools::compSolidOwner(context()).get())
-    aContext = ModelAPI_Tools::compSolidOwner(context())->shape();
+  while(ModelAPI_Tools::bodyOwner(aContextRes).get()) {
+    aContextRes = ModelAPI_Tools::bodyOwner(aContextRes);
+  }
+  std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
 
 
   TopoDS_Shape aMainShape = aContext->impl<TopoDS_Shape>();
   const TopoDS_Shape& aSubShape = aSelection->impl<TopoDS_Shape>();
   // searching for the latest main shape
-  if (aSelection && !aSelection->isNull() &&
-    aContext   && !aContext->isNull())
+  if (aSelection && !aSelection->isNull() && aContext && !aContext->isNull())
   {
     std::shared_ptr<Model_Document> aDoc =
       std::dynamic_pointer_cast<Model_Document>(context()->document());
@@ -1006,21 +1000,21 @@ int Model_AttributeSelection::Id()
 
 void Model_AttributeSelection::setId(int theID)
 {
-  const ResultPtr& aContext = context();
   std::shared_ptr<GeomAPI_Shape> aSelection;
 
-  std::shared_ptr<GeomAPI_Shape> aContextShape = aContext->shape();
+  ResultPtr aContextRes = context();
   // support for compsolids:
-  if (aContext.get() && ModelAPI_Tools::compSolidOwner(aContext).get())
-    aContextShape = ModelAPI_Tools::compSolidOwner(aContext)->shape();
+  while(ModelAPI_Tools::bodyOwner(aContextRes).get()) {
+    aContextRes = ModelAPI_Tools::bodyOwner(aContextRes);
+  }
+  std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
 
-  TopoDS_Shape aMainShape = aContextShape->impl<TopoDS_Shape>();
+  TopoDS_Shape aMainShape = aContext->impl<TopoDS_Shape>();
   // searching for the latest main shape
-  if (theID > 0 &&
-      aContextShape && !aContextShape->isNull())
+  if (theID > 0 && aContext && !aContext->isNull())
   {
     std::shared_ptr<Model_Document> aDoc =
-      std::dynamic_pointer_cast<Model_Document>(aContext->document());
+      std::dynamic_pointer_cast<Model_Document>(aContextRes->document());
     if (aDoc.get()) {
       Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel());
       if (!aNS.IsNull()) {
@@ -1038,7 +1032,7 @@ void Model_AttributeSelection::setId(int theID)
     aSelection = aResult;
   }
 
-  setValue(aContext, aSelection);
+  setValue(aContextRes, aSelection);
 }
 
 std::string Model_AttributeSelection::contextName(const ResultPtr& theContext) const
@@ -1086,10 +1080,16 @@ void Model_AttributeSelection::computeValues(
   // if new context becomes compsolid, the resulting sub may be in sub-solids
   std::list<ResultPtr> aNewToIterate;
   aNewToIterate.push_back(theNewContext);
-  ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theNewContext);
+  ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theNewContext);
   if (aComp.get()) {
-    for(int a = 0; a < aComp->numberOfSubs(); a++)
-      aNewToIterate.push_back(aComp->subResult(a, false));
+    std::list<ResultPtr> allNewContextSubs;
+    ModelAPI_Tools::allSubs(aComp, allNewContextSubs);
+    std::list<ResultPtr>::iterator aSub = allNewContextSubs.begin();
+    for(; aSub != allNewContextSubs.end(); aSub++) {
+      ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSub);
+      if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs
+        aNewToIterate.push_back(aBody);
+    }
   }
 
   // first iteration: searching for the whole shape appearance (like face of the box)
@@ -1174,7 +1174,7 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr<Model_Document>
   TopTools_ListOfShape aContextList;
   aContextList.Append(theContShape);
   if (theContext.get()) {
-    ResultPtr aComposite = ModelAPI_Tools::compSolidOwner(theContext);
+    ResultPtr aComposite = ModelAPI_Tools::bodyOwner(theContext);
     if (aComposite.get() && aComposite->shape().get() && !aComposite->shape()->isNull())
       aContextList.Append(aComposite->shape()->impl<TopoDS_Shape>());
   }
index a863d55dd6a961c44a7277cd50ca3923c512b15f..6a7af0170458fb67cf02bc27b49d5e5738fa599a 100644 (file)
@@ -42,7 +42,6 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultPart.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Tools.h>
 #include <Model_Validator.h>
 
@@ -139,7 +138,7 @@ void Model_Data::setName(const std::string& theName)
       bool isUserDefined = true;
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
       if (aResult) {
-        std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult);
+        std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult).first;
         isUserDefined = aDefaultName != theName;
       }
       if (isUserDefined) {
index ae27c2af263a9105cc5e04dfca96e5f0b7994a5c..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>
 
@@ -1055,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
@@ -1567,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);
-              }
-            }
-          }
         }
       }
     }
@@ -1755,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)
index 0f6b32ed6e8093863a453ecf130ee42d200155d7..98c44ea64b94944a02f6559399926036b3305220 100644 (file)
@@ -149,6 +149,11 @@ class Model_Document : public ModelAPI_Document
   //! \param theAllowFolder take into account grouping feature by folders
   MODEL_EXPORT virtual int size(const std::string& theGroupID, const bool theAllowFolder = false);
 
+  //! Returns the parent object of this child. This may be result or feature, parent of a
+  //! top result. Fast method, that uses internal data structure specifics.
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Object> parent(
+    const std::shared_ptr<ModelAPI_Object> theChild);
+
   //! Returns the feature that is currently edited in this document, normally
   //! this is the latest created feature
   //! \param theVisible use visible features only: flag is true for Object Browser functionality
@@ -383,7 +388,7 @@ class Model_Document : public ModelAPI_Document
   friend class Model_AttributeRefAttrList;
   friend class Model_AttributeSelection;
   friend class Model_ResultPart;
-  friend class Model_ResultCompSolid;
+  friend class Model_ResultBody;
   friend class Model_ResultConstruction;
   friend class Model_SelectionNaming;
   friend class DFBrowser;
index b4e516cd64e75305d523ad0c750635d14376c1f0..199b249c34ce234e396e11a4670ec7960bfe3fa7 100644 (file)
@@ -26,7 +26,6 @@
 #include <Model_ResultPart.h>
 #include <Model_ResultConstruction.h>
 #include <Model_ResultBody.h>
-#include <Model_ResultCompSolid.h>
 #include <Model_ResultGroup.h>
 #include <Model_ResultField.h>
 #include <Model_ResultParameter.h>
@@ -556,41 +555,52 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel)
   FeaturePtr aFeature = feature(theLabel);
   if (aFeature.get())
     return feature(theLabel);
-  TDF_Label aFeatureLabel = theLabel.Father().Father();  // let's suppose it is result
-  aFeature = feature(aFeatureLabel);
-  bool isSubResult = false;
-  if (!aFeature.get() && aFeatureLabel.Depth() > 1) { // let's suppose this is sub-result of result
+  TDF_Label aFeatureLabel = theLabel;  // let's suppose it is result of this feature
+  TDF_LabelList aSubLabs; // sub - labels from higher level to lower level of result
+  while(!aFeature.get() && aFeatureLabel.Depth() > 1) {
+    aSubLabs.Prepend(aFeatureLabel);
     aFeatureLabel = aFeatureLabel.Father().Father();
     aFeature = feature(aFeatureLabel);
-    isSubResult = true;
   }
   if (aFeature.get()) {
-    const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
-    std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
-    for (; aRIter != aResults.cend(); aRIter++) {
-      if (isSubResult) {
-        ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRIter);
-        if (aCompRes.get()) {
-          int aNumSubs = aCompRes->numberOfSubs();
-          for(int a = 0; a < aNumSubs; a++) {
-            ResultPtr aSub = aCompRes->subResult(a);
-            if (aSub.get()) {
-              std::shared_ptr<Model_Data> aSubData = std::dynamic_pointer_cast<Model_Data>(
-                  aSub->data());
-              if (aSubData->label().Father().IsEqual(theLabel))
-                return aSub;
+    ResultPtr aCurrentResult;
+    // searching for results then sub-results label by label
+    for(TDF_ListIteratorOfLabelList aSubLab(aSubLabs); aSubLab.More(); aSubLab.Next()) {
+      if (aCurrentResult.get()) { // iterate sub-results of result
+        ResultBodyPtr anOwner = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aCurrentResult);
+        if (!anOwner)
+          return ObjectPtr(); // only Body can have sub-results
+        int a, aNumSubs = anOwner->numberOfSubs();
+        for(a = 0; a < aNumSubs; a++) {
+          ResultPtr aSub = anOwner->subResult(a);
+          if (aSub.get()) {
+            std::shared_ptr<Model_Data> aSubData = std::dynamic_pointer_cast<Model_Data>(
+              aSub->data());
+            if (aSubData->label().Father().IsEqual(aSubLab.ChangeValue())) {
+              aCurrentResult = aSub;
+              break;
             }
           }
         }
-      } else {
-        std::shared_ptr<Model_Data> aResData = std::dynamic_pointer_cast<Model_Data>(
-            (*aRIter)->data());
-        if (aResData->label().Father().IsEqual(theLabel))
-          return *aRIter;
+        if (a == aNumSubs) // not found an appropriate sub-result of result
+          return ObjectPtr();
+      } else { // iterate results of feature
+        const std::list<ResultPtr>& aResults = aFeature->results();
+        std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
+        for(; aRIter != aResults.cend(); aRIter++) {
+          std::shared_ptr<Model_Data> aResData = std::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
+          if (aResData->label().Father().IsEqual(aSubLab.ChangeValue())) {
+            aCurrentResult = *aRIter;
+            break;
+          }
+        }
+        if (aRIter == aResults.cend()) // not found an appropriate result of feature
+          return ObjectPtr();
       }
     }
+    return aCurrentResult;
   }
-  return FeaturePtr();  // not found
+  return ObjectPtr();  // not found
 }
 
 ObjectPtr Model_Objects::object(const std::string& theGroupID,
@@ -622,24 +632,12 @@ std::shared_ptr<ModelAPI_Object> Model_Objects::objectByName(
     std::list<std::shared_ptr<ModelAPI_Feature> > allObjs = allFeatures();
     std::list<std::shared_ptr<ModelAPI_Feature> >::iterator anObjIter = allObjs.begin();
     for(; anObjIter != allObjs.end(); anObjIter++) {
-      const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = (*anObjIter)->results();
-      std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
-      for (; aRIter != aResults.cend(); aRIter++) {
-        if (aRIter->get() && (*aRIter)->groupName() == theGroupID) {
-          if ((*aRIter)->data()->name() == theName)
-            return *aRIter;
-          ResultCompSolidPtr aCompRes =
-            std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRIter);
-          if (aCompRes.get()) {
-            int aNumSubs = aCompRes->numberOfSubs();
-            for(int a = 0; a < aNumSubs; a++) {
-              ResultPtr aSub = aCompRes->subResult(a);
-              if (aSub.get() && aSub->groupName() == theGroupID) {
-                if (aSub->data()->name() == theName)
-                  return aSub;
-              }
-            }
-          }
+      std::list<ResultPtr> allRes;
+      ModelAPI_Tools::allResults(*anObjIter, allRes);
+      for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+        if (aRes->get() && (*aRes)->groupName() == theGroupID) {
+          if ((*aRes)->data()->name() == theName)
+            return *aRes;
         }
       }
     }
@@ -678,6 +676,21 @@ int Model_Objects::size(const std::string& theGroupID, const bool theAllowFolder
   return aGroupID.empty() ? int(myHistory[theGroupID].size()) : int(myHistory[aGroupID].size());
 }
 
+std::shared_ptr<ModelAPI_Object> Model_Objects::parent(
+  const std::shared_ptr<ModelAPI_Object> theChild)
+{
+  if (theChild.get()) {
+    std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theChild->data());
+    TDF_Label aLab = aData->label();
+    if (!aLab.IsNull() && aLab.Depth() > 1) {
+      ObjectPtr anObj = object(aLab.Father().Father());
+      return anObj;
+    }
+  }
+  return ObjectPtr();
+}
+
+
 void Model_Objects::allResults(const std::string& theGroupID, std::list<ResultPtr>& theResults)
 {
   // iterate the array of references and get feature by feature from the array
@@ -1166,10 +1179,9 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   int theResultIndex,
                                   std::string& theParentName) const
 {
-  ResultCompSolidPtr aCompSolidRes =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theFeatureData->owner());
-  if (aCompSolidRes) {
-    FeaturePtr anOwner = ModelAPI_Feature::feature(theResult->data()->owner());
+  ResultBodyPtr aBodyRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theFeatureData->owner());
+  if(aBodyRes) {
+    FeaturePtr anOwner = ModelAPI_Feature::feature(theResult);
 
     // 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',
@@ -1177,18 +1189,18 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
     std::ostringstream aDefaultName;
     aDefaultName << anOwner->name();
     // compute default name of CompSolid (name of feature + index of CompSolid's result)
-    int aCompSolidResultIndex = 0;
+    int aBodyResultIndex = 0;
     const std::list<ResultPtr>& aResults = anOwner->results();
-    for (std::list<ResultPtr>::const_iterator anIt = aResults.begin();
-         anIt != aResults.end(); ++anIt, ++aCompSolidResultIndex)
-      if (aCompSolidRes == *anIt)
+    std::list<ResultPtr>::const_iterator anIt = aResults.begin();
+    for(; anIt != aResults.end(); ++anIt, ++aBodyResultIndex)
+      if(aBodyRes == *anIt)
         break;
-    aDefaultName << "_" << (aCompSolidResultIndex + 1);
+    aDefaultName << "_" << (aBodyResultIndex + 1);
     theParentName = aDefaultName.str();
     return false;
   }
 
-  std::pair<std::string, bool> aName = ModelAPI_Tools::getDefaultName(theResult, theResultIndex);
+  std::pair<std::string, bool> aName = ModelAPI_Tools::getDefaultName(theResult);
   if (aName.second)
     theParentName = aName.first;
   return aName.second;
@@ -1242,27 +1254,14 @@ std::shared_ptr<ModelAPI_ResultBody> Model_Objects::createBody(
     const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
-  // for feature create compsolid, but for result sub create body:
-  // only one level of recursion is supported now
-  ResultPtr aResultOwner = std::dynamic_pointer_cast<ModelAPI_Result>(theFeatureData->owner());
-  ObjectPtr anOldObject;
-  if (aResultOwner.get()) {
-    TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
-  } else { // in compsolid (higher level result) old object probably may be found
-    TDataStd_Comment::Set(aLab, ModelAPI_ResultCompSolid::group().c_str());
-    anOldObject = object(aLab);
-  }
+  TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
+  ObjectPtr anOldObject = object(aLab);
   std::shared_ptr<ModelAPI_ResultBody> aResult;
   if (anOldObject.get()) {
     aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anOldObject);
   }
   if (!aResult.get()) {
-    // create compsolid anyway; if it is compsolid, it will create sub-bodies internally
-    if (aResultOwner.get()) {
-      aResult = std::shared_ptr<ModelAPI_ResultBody>(new Model_ResultBody);
-    } else {
-      aResult = std::shared_ptr<ModelAPI_ResultBody>(new Model_ResultCompSolid);
-    }
+    aResult = std::shared_ptr<ModelAPI_ResultBody>(new Model_ResultBody);
     storeResult(theFeatureData, aResult, theIndex);
   }
   return aResult;
@@ -1790,7 +1789,7 @@ std::shared_ptr<ModelAPI_Feature> Model_Objects::feature(
   if (aData.get()) {
     TDF_Label aFeatureLab = aData->label().Father().Father().Father();
     FeaturePtr aFeature = feature(aFeatureLab);
-    if (!aFeature.get() && aFeatureLab.Depth() > 1) { // this may be sub-result of result
+    while(!aFeature.get() && aFeatureLab.Depth() > 1) { // this may be sub-result of result
       aFeatureLab = aFeatureLab.Father().Father();
       aFeature = feature(aFeatureLab);
     }
@@ -1863,8 +1862,7 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
       TDF_Label anArgLab = aLabIter.Value();
       Handle(TDataStd_Comment) aGroup;
       if (anArgLab.FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
-        if (aGroup->Get() == ModelAPI_ResultBody::group().c_str() ||
-            aGroup->Get() == ModelAPI_ResultCompSolid::group().c_str()) {
+        if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
           aNewBody = createBody(theFeature->data(), aResIndex);
         } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
           std::shared_ptr<ModelAPI_ResultPart> aNewP = createPart(theFeature->data(), aResIndex);
index d6f3d383f741867d3258b2947d2011fa034f2052..0991cf21077dba0fe2b3bcc38a0caafd91f4ebbf 100644 (file)
@@ -109,6 +109,10 @@ class Model_Objects
   //! \param theAllowFolder take into account grouping feature by folders
   int size(const std::string& theGroupID, const bool theAllowFolder = false);
 
+  //! Returns the parent object of this child. This may be result or feature, parent of a
+  //! top result. Fast method, that uses internal data structure specifics.
+  std::shared_ptr<ModelAPI_Object> parent(const std::shared_ptr<ModelAPI_Object> theChild);
+
   //! Returns all (and disabled) results of the given type.
   //! Not fast method (iterates all features).
   void allResults(const std::string& theGroupID, std::list<ResultPtr>& theResults);
index 731a520de0bb6fcff6f1d14a725b60612737cb04..2a82cc445e47b129595ced1a6212f4c6b9b1acd7 100644 (file)
 //
 
 #include <Model_ResultBody.h>
+
+#include <Model_Document.h>
+#include <Model_Objects.h>
 #include <Model_BodyBuilder.h>
-#include <ModelAPI_ResultCompSolid.h>
-#include <ModelAPI_Tools.h>
-#include <Config_PropManager.h>
+#include <Model_Document.h>
+#include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
-// DEB
-//#include <TCollection_AsciiString.hxx>
-//#include <TDF_Tool.hxx>
-//#define DEB_IMPORT 1
+#include <ModelAPI_Tools.h>
+#include <Events_Loop.h>
+
+#include <TopoDS_Shape.hxx>
+#include <TopExp_Explorer.hxx>
 
-Model_ResultBody::Model_ResultBody()
+
+Model_ResultBody::Model_ResultBody() : ModelAPI_ResultBody()
 {
   myBuilder = new Model_BodyBuilder(this);
-  myWasConcealed = false;
-  myConnect = ConnectionNotComputed;
+  myLastConcealed = false;
+  updateSubs(shape()); // in case of open, etc.
+}
+
+Model_ResultBody::~Model_ResultBody()
+{
+  updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
+  delete myBuilder;
+}
+
+void Model_ResultBody::loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS,
+    std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
+    const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
+    const bool theIsStoreSeparate,
+    const bool theIsStoreAsGenerated,
+    const bool theSplitInSubs)
+{
+  if (theSplitInSubs && mySubs.size()) { // consists of subs
+    std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
+    for(; aSubIter != mySubs.cend(); aSubIter++) {
+      // check that sub-shape was also created as modification of ShapeIn
+      /* to find when it is needed later to enable: to store modification of sub-bodies not only as primitives
+      GeomShapePtr aSubGeomShape = (*aSubIter)->shape();
+      if (!theIsStoreAsGenerated && aSubGeomShape.get() && !aSubGeomShape->isNull()) {
+        TopoDS_Shape aSubShape = aSubGeomShape->impl<TopoDS_Shape>();
+        TopoDS_Shape aWholeIn = theShapeIn->impl<TopoDS_Shape>();
+        for(TopExp_Explorer anExp(aWholeIn, aSubShape.ShapeType()); anExp.More(); anExp.Next()) {
+          ListOfShape aHistory;
+          std::shared_ptr<GeomAPI_Shape> aSubIn(new GeomAPI_Shape());
+          aSubIn->setImpl((new TopoDS_Shape(anExp.Current())));
+          theMS->modified(aSubIn, aHistory);
+          std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aHistory.begin();
+          for (; anIt != aHistory.end(); anIt++) {
+            if ((*anIt)->isSame(aSubGeomShape)) {
+              (*aSubIter)->storeModified(aSubIn, aSubGeomShape, -2); // -2 is to avoid clearing
+            }
+          }
+        }
+      }*/
+      (*aSubIter)->loadAndOrientModifiedShapes(
+        theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes, theIsStoreSeparate,
+        theIsStoreAsGenerated);
+    }
+  } else { // do for this directly
+    myBuilder->loadAndOrientGeneratedShapes(
+      theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes);
+  }
+}
+
+int Model_ResultBody::numberOfSubs(bool forTree) const
+{
+  return int(mySubs.size());
+}
+
+ResultBodyPtr Model_ResultBody::subResult(const int theIndex, bool forTree) const
+{
+  return mySubs.at(theIndex);
+}
+
+bool Model_ResultBody::isSub(ObjectPtr theObject, int& theIndex) const
+{
+  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theObject);
+  if (aFound != mySubsMap.end()) {
+    theIndex = aFound->second;
+    return true;
+  }
+  return false;
 }
 
 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
@@ -47,45 +116,153 @@ void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& the
 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
 {
   bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
-  if (aChanged && data()->isValid()) { // state is changed, so modifications are needed
+  if (aChanged) { // state is changed, so modifications are needed
     myBuilder->evolutionToSelection(theFlag);
+    updateSubs(shape()); // to set disabled/enabled
   }
   return aChanged;
 }
 
-bool Model_ResultBody::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
+bool Model_ResultBody::isConcealed()
 {
-  return myBuilder->isLatestEqual(theShape);
+  return myLastConcealed;
 }
 
-bool Model_ResultBody::isConcealed()
+void Model_ResultBody::setIsConcealed(const bool theValue)
 {
-  bool aResult = false;
-  if (ModelAPI_ResultBody::isConcealed()) {
-    aResult = true;
-  } else {
-    ResultPtr aThis = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
-    if (aThis.get()) {
-      ResultCompSolidPtr aParent = ModelAPI_Tools::compSolidOwner(aThis);
-      if (aParent.get()) {
-        if (aParent->isConcealed())
-          aResult = true;
-      }
-    }
+  if (ModelAPI_ResultBody::isConcealed() != theValue) {
+    ModelAPI_ResultBody::setIsConcealed(theValue);
+    updateConcealment();
   }
-  if (myWasConcealed != aResult) {
-    myWasConcealed = aResult;
-    if (aResult) { // hidden unit must be redisplayed (hidden)
-      ModelAPI_EventCreator::get()->sendDeleted(document(), this->groupName());
-      // redisplay for the viewer (it must be disappeared also)
+}
+
+void Model_ResultBody::updateConcealment()
+{
+  if (myLastConcealed != ModelAPI_ResultBody::isConcealed()) {
+    ResultPtr anOwner = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
+    std::shared_ptr<Model_ResultBody> aParent = std::dynamic_pointer_cast<Model_ResultBody>(
+      ModelAPI_Tools::bodyOwner(anOwner));
+
+    myLastConcealed = ModelAPI_ResultBody::isConcealed(); // set new value and check parent
+    if (myLastConcealed) { // this becomes concealed, so, update all: parent and children
+      if (aParent.get())
+        aParent->updateConcealment();
       static Events_ID EVENT_DISP =
         Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+      ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
       ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), EVENT_DISP);
-    } else { // was not concealed become concealed => delete event
-      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-      ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
+      std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
+      for (; aSubIter != mySubs.cend(); aSubIter++) {
+        std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
+      }
+    } else {
+      // ask parent: if it is still concealed, nothing is changed
+      if (aParent.get()) {
+        aParent->updateConcealment();
+        if (aParent->isConcealed()) {
+          myLastConcealed = true;
+          return;
+        }
+      }
+      // iterate children: if they are concealed, nothing is changed
+      bool aChildConcealed = false;
+      std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
+      for (; aSubIter != mySubs.cend(); aSubIter++) {
+        std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
+        if ((*aSubIter)->isConcealed()) {
+          aChildConcealed = true;
+          break;
+        }
+      }
+      if (aChildConcealed) { // some child is concealed, so, update back
+        myLastConcealed = true;
+        if (aParent.get())
+          aParent->updateConcealment();
+        std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
+        for (; aSubIter != mySubs.cend(); aSubIter++) {
+          std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
+        }
+      } else { // so, it becomes unconcealed
+        static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+        ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
+        static Events_ID EVENT_DISP =
+          Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+        ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), EVENT_DISP);
+      }
+    }
+  }
+}
+
+void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape)
+{
+  static Events_Loop* aLoop = Events_Loop::loop();
+  static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
+  static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+  // iterate all sub-solids of compsolid to make sub-results synchronized with them
+  TopoDS_Shape aThisShape;
+  if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
+  if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID ||
+       aThisShape.ShapeType() == TopAbs_COMPOUND)) {
+    bool aWasEmpty = mySubs.empty();
+    Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+    unsigned int aSubIndex = 0;
+    TopoDS_Iterator aShapesIter(aThisShape);
+    for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) {
+      std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+      aShape->setImpl(new TopoDS_Shape(aShapesIter.Value()));
+      ResultBodyPtr aSub;
+      if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
+        aSub = anObjects->createBody(this->data(), aSubIndex);
+        mySubs.push_back(aSub);
+        mySubsMap[aSub] = int(mySubs.size() - 1);
+      } else { // just update shape of this result
+        aSub = mySubs[aSubIndex];
+      }
+      if (!aShape->isEqual(aSub->shape())) {
+        aSub->store(aShape, false);
+        aECreator->sendUpdated(aSub, EVENT_DISP);
+        aECreator->sendUpdated(aSub, EVENT_UPD);
+      }
+      aSub->setDisabled(aSub, isDisabled());
+    }
+    // erase left, unused results
+    while(mySubs.size() > aSubIndex) {
+      ResultBodyPtr anErased = *(mySubs.rbegin());
+      if (anErased->ModelAPI_ResultBody::isConcealed())
+        std::dynamic_pointer_cast<Model_ResultBody>(anErased)->updateConcealment();
+      anErased->setDisabled(anErased, true);
+      mySubsMap.erase(anErased);
+      mySubs.pop_back();
+    }
+    if (aWasEmpty) { // erase all subs
+      // redisplay this because result with and without subs are displayed differently
+      aECreator->sendUpdated(data()->owner(), EVENT_DISP);
     }
+  } else if (!mySubs.empty()) { // erase all subs
+    while(!mySubs.empty()) {
+      ResultBodyPtr anErased = *(mySubs.rbegin());
+      if (anErased->ModelAPI_ResultBody::isConcealed())
+        std::dynamic_pointer_cast<Model_ResultBody>(anErased)->updateConcealment();
+      anErased->setDisabled(anErased, true); // even if it is invalid (to erase subs on abort/undo)
+      mySubs.pop_back();
+    }
+    mySubsMap.clear();
+    // redisplay this because result with and without subs are displayed differently
+    aECreator->sendUpdated(data()->owner(), EVENT_DISP);
   }
+}
 
-  return aResult;
+bool Model_ResultBody::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
+{
+  if (myBuilder->isLatestEqual(theShape))
+    return true;
+  // also check that it is asked for sub-elements
+  std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
+  for(; aSubIter != mySubs.cend(); aSubIter++) {
+    if (aSubIter->get() && (*aSubIter)->isLatestEqual(theShape)) {
+      return true;
+    }
+  }
+  return false;
 }
index 02f55cbdc99b08bee68a3e3f65139c64af2a377e..ad5f1c53136a25ca5a985f834ea5e400823a229f 100644 (file)
 
 #include "Model.h"
 #include <ModelAPI_ResultBody.h>
-//#include <GeomAlgoAPI_MakeShape.h>
-//#include <GeomAPI_DataMapOfShapeShape.h>
-//#include <vector>
-
-//class TNaming_Builder;
+#include <vector>
+#include <map>
 
 /**\class Model_ResultBody
- * \ingroup DataModel
- * \brief The body (shape) result of a feature.
- *
- * Provides a shape that may be displayed in the viewer.
- * May provide really huge results, so, working with this kind
- * of result must be optimized.
- */
+* \ingroup DataModel
+* \brief The body (shape) result of a feature.
+*
+* Provides a shape that may be displayed in the viewer.
+* May provide really huge results, so, working with this kind
+* of result must be optimized.
+* Also provides a conainer of sub-body result in case it is compound or compsolid.
+*/
 class Model_ResultBody : public ModelAPI_ResultBody
 {
-  /// builders that tores the naming history: one per label to allow store several shapes to one
-  /// label; index in vector corresponds to the label tag
-  //std::vector<TNaming_Builder*> myBuilders;
-
-  /// Flag that stores the previous state of "concealed": if it is changed,
-  /// The event is used to redisplay the body.
-  bool myWasConcealed;
+  /// Sub-bodies if this is compsolid or compound: zero-based index to subs
+  std::vector<ResultBodyPtr> mySubs;
+  /// Also keep map of result to index in mySubs to facilitate speed of access from OB
+  std::map<ObjectPtr, int> mySubsMap;
+  /// Keeps the last state of the concealment flag in order to update it when needed.
+  bool myLastConcealed;
 
 public:
+
+  /// Removes the stored builders
+  MODEL_EXPORT virtual ~Model_ResultBody();
+
+  /// load and orient modified shapes for sub-objects
+  MODEL_EXPORT virtual void loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS,
+    std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
+    const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
+    const bool theIsStoreSeparate = false, const bool theIsStoreAsGenerated = false,
+    const bool theSplitInSubs = false);
+
+
+  /// Returns the number of sub-elements
+  MODEL_EXPORT virtual int numberOfSubs(bool forTree = false) const;
+
+  /// Returns the sub-result by zero-base index
+  MODEL_EXPORT virtual ResultBodyPtr subResult(const int theIndex,
+    bool forTree = false) const;
+
+  /// Returns true if feature or reuslt belong to this composite feature as subs
+  /// Returns theIndex - zero based index of sub if found
+  MODEL_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const;
+
   /// Returns the parameters of color definition in the resources config manager
   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
                                             std::string& theDefault);
 
   /// Disables the result body: keeps the resulting shape as selection, but erases the underlaying
-  /// naming data structure if theFlag if false. Or restores everything on theFlag is true.
+  /// naming data structure if theFlag if false. Or restores every  thing on theFlag is true.
   MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
     const bool theFlag);
 
-  /// The compsolid is concealed if at least one of the sub is concealed,
-  /// so, sub is Concealed if at least one sub is concealed
+  /// The compsolid is concealed if at least one of the sub is concealed
   MODEL_EXPORT virtual bool isConcealed();
 
+  /// Sets all subs as concealed in the data tree (referenced by other objects)
+  MODEL_EXPORT virtual void setIsConcealed(const bool theValue);
+
   /// Returns true if the latest modification of this body in the naming history
   // is equal to the given shape
   MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
-  /// Removes the stored builders
-  MODEL_EXPORT virtual ~Model_ResultBody() {};
-
 protected:
   /// Makes a body on the given feature
   Model_ResultBody();
 
+  /// Updates the sub-bodies if shape of this object is composite-solid
+  void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape);
+
+  // Checks the state of children and partents to send events of creation/erase when needed
+  void updateConcealment();
+
   friend class Model_Objects;
 };
 
diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp
deleted file mode 100755 (executable)
index 8cde4b9..0000000
+++ /dev/null
@@ -1,282 +0,0 @@
-// Copyright (C) 2014-2017  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
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
-//
-
-#include <Model_ResultCompSolid.h>
-
-#include <Model_Document.h>
-#include <Model_Objects.h>
-#include <Model_BodyBuilder.h>
-#include <Model_Document.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Events.h>
-#include <Events_Loop.h>
-
-#include <TopoDS_Shape.hxx>
-#include <TopExp_Explorer.hxx>
-
-
-Model_ResultCompSolid::Model_ResultCompSolid()
-{
-  myBuilder = new Model_BodyBuilder(this);
-  myLastConcealed = false;
-  updateSubs(shape()); // in case of open, etc.
-}
-
-Model_ResultCompSolid::~Model_ResultCompSolid()
-{
-  updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
-}
-
-void Model_ResultCompSolid::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                                  const bool theIsStoreSameShapes)
-{
-  ModelAPI_ResultCompSolid::store(theShape, theIsStoreSameShapes);
-  updateSubs(theShape);
-}
-
-void Model_ResultCompSolid::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
-    const std::shared_ptr<GeomAPI_Shape>& theToShape)
-{
-  ModelAPI_ResultCompSolid::storeGenerated(theFromShape, theToShape);
-  updateSubs(theToShape);
-}
-
-void Model_ResultCompSolid::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
-    const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
-{
-  ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag);
-  updateSubs(theNewShape);
-}
-
-void Model_ResultCompSolid::loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS,
-    std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
-    const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
-    const bool theIsStoreSeparate,
-    const bool theIsStoreAsGenerated,
-    const bool theSplitInSubs)
-{
-  if (theSplitInSubs && mySubs.size()) { // consists of subs
-    std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
-    for(; aSubIter != mySubs.cend(); aSubIter++) {
-      // check that sub-shape was also created as modification of ShapeIn
-      /* to find when it is needed later to enable: to store modification of sub-bodies not only as primitives
-      GeomShapePtr aSubGeomShape = (*aSubIter)->shape();
-      if (!theIsStoreAsGenerated && aSubGeomShape.get() && !aSubGeomShape->isNull()) {
-        TopoDS_Shape aSubShape = aSubGeomShape->impl<TopoDS_Shape>();
-        TopoDS_Shape aWholeIn = theShapeIn->impl<TopoDS_Shape>();
-        for(TopExp_Explorer anExp(aWholeIn, aSubShape.ShapeType()); anExp.More(); anExp.Next()) {
-          ListOfShape aHistory;
-          std::shared_ptr<GeomAPI_Shape> aSubIn(new GeomAPI_Shape());
-          aSubIn->setImpl((new TopoDS_Shape(anExp.Current())));
-          theMS->modified(aSubIn, aHistory);
-          std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aHistory.begin();
-          for (; anIt != aHistory.end(); anIt++) {
-            if ((*anIt)->isSame(aSubGeomShape)) {
-              (*aSubIter)->storeModified(aSubIn, aSubGeomShape, -2); // -2 is to avoid clearing
-            }
-          }
-        }
-      }*/
-      (*aSubIter)->loadAndOrientModifiedShapes(
-        theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes, theIsStoreSeparate,
-        theIsStoreAsGenerated);
-    }
-  } else { // do for this directly
-    ModelAPI_ResultCompSolid::loadAndOrientModifiedShapes(
-    theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes, theIsStoreSeparate,
-    theIsStoreAsGenerated);
-  }
-}
-
-int Model_ResultCompSolid::numberOfSubs(bool forTree) const
-{
-  return int(mySubs.size());
-}
-
-std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
-                                                                      bool forTree) const
-{
-  return mySubs.at(theIndex);
-}
-
-bool Model_ResultCompSolid::isSub(ObjectPtr theObject, int& theIndex) const
-{
-  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theObject);
-  if (aFound != mySubsMap.end()) {
-    theIndex = aFound->second;
-    return true;
-  }
-  return false;
-}
-
-void Model_ResultCompSolid::colorConfigInfo(std::string& theSection, std::string& theName,
-  std::string& theDefault)
-{
-  theSection = "Visualization";
-  theName = "result_body_color";
-  theDefault = DEFAULT_COLOR();
-}
-
-bool Model_ResultCompSolid::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
-                                        const bool theFlag)
-{
-  bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
-  if (aChanged) { // state is changed, so modifications are needed
-    myBuilder->evolutionToSelection(theFlag);
-    updateSubs(shape()); // to set disabled/enabled
-  }
-  return aChanged;
-}
-
-bool Model_ResultCompSolid::isConcealed()
-{
-  bool aResult = false;;
-  if (ModelAPI_ResultCompSolid::isConcealed()) {
-    aResult = true;
-  } else {
-    std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
-    for(; aSubIter != mySubs.cend(); aSubIter++) {
-      if ((*aSubIter)->ModelAPI_ResultBody::isConcealed()) {
-        aResult = true;
-        break;
-      }
-    }
-  }
-  if (myLastConcealed != aResult) {
-    myLastConcealed = aResult;
-    //setIsConcealed(aResult); // set for all subs the same result
-    std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
-    for(; aSubIter != mySubs.cend(); aSubIter++) { // update the visualization status of each sub
-      if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != aResult) {
-        if (aResult) { // hidden unit must be redisplayed (hidden)
-          ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
-          // redisplay for the viewer (it must be disappeared also)
-          static Events_ID EVENT_DISP =
-            Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-          ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
-        } else { // was not concealed become concealed => delete event
-          static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-          ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
-        }
-      }
-    }
-    // update the display state of the subs: explicitly call Model_ResultBody::isConcealed
-    for(aSubIter = mySubs.cbegin(); aSubIter != mySubs.cend(); aSubIter++) {
-      (*aSubIter)->isConcealed();
-    }
-  }
-  return aResult;
-}
-
-void Model_ResultCompSolid::setIsConcealed(const bool theValue)
-{
-  if (theValue != ModelAPI_ResultCompSolid::isConcealed()) {
-    std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
-    for(; aSubIter != mySubs.cend(); aSubIter++) {
-      if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != theValue) {
-        if (theValue) { // hidden unit must be redisplayed (hidden)
-          ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
-          // redisplay for the viewer (it must be disappeared also)
-          static Events_ID EVENT_DISP =
-            Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-          ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
-        } else { // was not concealed become concealed => delete event
-          static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-          ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
-        }
-      }
-    }
-    ModelAPI_ResultCompSolid::setIsConcealed(theValue);
-    // to set correct myLastConcealed
-    isConcealed();
-  }
-  //myLastConcealed = theValue;
-}
-
-void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape)
-{
-  static Events_Loop* aLoop = Events_Loop::loop();
-  static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
-  static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-  // iterate all sub-solids of compsolid to make sub-results synchronized with them
-  TopoDS_Shape aThisShape;
-  if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
-  if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID ||
-       aThisShape.ShapeType() == TopAbs_COMPOUND)) {
-    bool aWasEmpty = mySubs.empty();
-    Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
-    unsigned int aSubIndex = 0;
-    TopoDS_Iterator aShapesIter(aThisShape);
-    for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) {
-      std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
-      aShape->setImpl(new TopoDS_Shape(aShapesIter.Value()));
-      ResultBodyPtr aSub;
-      if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
-        aSub = anObjects->createBody(this->data(), aSubIndex);
-        mySubs.push_back(aSub);
-        mySubsMap[aSub] = int(mySubs.size() - 1);
-      } else { // just update shape of this result
-        aSub = mySubs[aSubIndex];
-      }
-      if (!aShape->isEqual(aSub->shape())) {
-        aSub->store(aShape, false);
-        aECreator->sendUpdated(aSub, EVENT_DISP);
-        aECreator->sendUpdated(aSub, EVENT_UPD);
-      }
-      aSub->setDisabled(aSub, isDisabled());
-      aSub->setIsConcealed(myLastConcealed);
-    }
-    // erase left, unused results
-    while(mySubs.size() > aSubIndex) {
-      ResultBodyPtr anErased = *(mySubs.rbegin());
-      anErased->setDisabled(anErased, true);
-      mySubsMap.erase(anErased);
-      mySubs.pop_back();
-    }
-    if (aWasEmpty) { // erase all subs
-      // redisplay this because result with and without subs are displayed differently
-      aECreator->sendUpdated(data()->owner(), EVENT_DISP);
-    }
-  } else if (!mySubs.empty()) { // erase all subs
-    while(!mySubs.empty()) {
-      ResultBodyPtr anErased = *(mySubs.rbegin());
-      anErased->setDisabled(anErased, true); // even if it is invalid (to erase subs on abort/undo)
-      mySubs.pop_back();
-    }
-    mySubsMap.clear();
-    // redisplay this because result with and without subs are displayed differently
-    aECreator->sendUpdated(data()->owner(), EVENT_DISP);
-  }
-}
-
-bool Model_ResultCompSolid::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
-{
-  if (myBuilder->isLatestEqual(theShape))
-    return true;
-  // also check that it is asked for sub-elements
-  std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
-  for(; aSubIter != mySubs.cend(); aSubIter++) {
-    if (aSubIter->get() && (*aSubIter)->isLatestEqual(theShape)) {
-      return true;
-    }
-  }
-  return false;
-}
diff --git a/src/Model/Model_ResultCompSolid.h b/src/Model/Model_ResultCompSolid.h
deleted file mode 100755 (executable)
index c748aee..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright (C) 2014-2017  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
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
-//
-
-#ifndef Model_ResultCompSolid_H_
-#define Model_ResultCompSolid_H_
-
-#include "Model.h"
-#include <ModelAPI_ResultCompSolid.h>
-#include <vector>
-#include <map>
-
-/**\class Model_ResultCompSolid
-* \ingroup DataModel
-* \brief The compsolid (container of body results) result of a feature.
-*
-* Provides a container of shapes that may be displayed in the viewer.
-*/
-class Model_ResultCompSolid : public ModelAPI_ResultCompSolid
-{
-  /// Sub-bodies if this is compsolid: zero base index to subs
-  std::vector<std::shared_ptr<ModelAPI_ResultBody> > mySubs;
-  /// Also keep map of result to index in mySubs to facilitate speed of access from OB
-  std::map<ObjectPtr, int> mySubsMap;
-  /// Flag that stores the previous state of "concealed": if it is changed,
-  /// The event must be generated to redisplay this and all subs.
-  bool myLastConcealed;
-
-
-public:
-
-  /// Removes the stored builders
-  MODEL_EXPORT virtual ~Model_ResultCompSolid();
-
-  /// Stores the shape (called by the execution method). Creates sub-results for compsolid.
-  MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                                  const bool theIsStoreSameShapes = true);
-
-  /// Stores the generated shape.  Creates sub-results for compsolid.
-  MODEL_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
-    const std::shared_ptr<GeomAPI_Shape>& theToShape);
-
-  /// Stores the modified shape.  Creates sub-results for compsolid.
-  MODEL_EXPORT virtual void storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
-    const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag = 0);
-
-  /// load and orient modified shapes for sub-objects
-  MODEL_EXPORT virtual void loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS,
-    std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
-    const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
-    const bool theIsStoreSeparate = false,
-    const bool theIsStoreAsGenerated = false,
-    const bool theSplitInSubs = false);
-
-
-  /// Returns the number of sub-elements
-  MODEL_EXPORT virtual int numberOfSubs(bool forTree = false) const;
-
-  /// Returns the sub-result by zero-base index
-  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultBody> subResult(const int theIndex,
-    bool forTree = false) const;
-
-  /// Returns true if feature or reuslt belong to this composite feature as subs
-  /// Returns theIndex - zero based index of sub if found
-  MODEL_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const;
-
-  /// Returns the parameters of color definition in the resources config manager
-  MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
-                                            std::string& theDefault);
-
-  /// Disables the result body: keeps the resulting shape as selection, but erases the underlaying
-  /// naming data structure if theFlag if false. Or restores everything on theFlag is true.
-  MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
-    const bool theFlag);
-
-  /// The compsolid is concealed if at least one of the sub is concealed
-  MODEL_EXPORT virtual bool isConcealed();
-
-  /// Sets all subs as concealed in the data tree (referenced by other objects)
-  MODEL_EXPORT virtual void setIsConcealed(const bool theValue);
-
-  /// Returns true if the latest modification of this body in the naming history
-  // is equal to the given shape
-  MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape);
-
-protected:
-  /// Makes a body on the given feature
-  Model_ResultCompSolid();
-
-  /// Updates the sub-bodies if shape of this object is composite-solid
-  void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape);
-
-  friend class Model_Objects;
-};
-
-#endif
index fbcb4a777d82158507d8a7c255f368f86522c4ae..9fde2d5abd040caf5bf8740c6f14e3fe4fe75a22 100644 (file)
@@ -57,7 +57,6 @@ SET(PROJECT_HEADERS
     ModelAPI_Plugin.h
     ModelAPI_Result.h
     ModelAPI_ResultBody.h
-    ModelAPI_ResultCompSolid.h
     ModelAPI_ResultConstruction.h
     ModelAPI_ResultField.h
     ModelAPI_ResultGroup.h
@@ -101,7 +100,6 @@ SET(PROJECT_SOURCES
     ModelAPI_Plugin.cpp
     ModelAPI_Result.cpp
     ModelAPI_ResultBody.cpp
-    ModelAPI_ResultCompSolid.cpp
     ModelAPI_ResultConstruction.cpp
     ModelAPI_ResultField.cpp
     ModelAPI_ResultGroup.cpp
index 61403edf66643f8052bee4eda00678c645211761..6199cb72ad2089ce9df65ba35b596c7ed031c740 100644 (file)
 %include "ModelAPI_ResultField.h"
 %include "ModelAPI_ResultParameter.h"
 %include "ModelAPI_Tools.h"
-%include "ModelAPI_ResultCompSolid.h"
 %include "ModelAPI_Folder.h"
 
 // std::list -> []
@@ -182,7 +181,6 @@ template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr
 %template(modelAPI_ResultParameter) shared_ptr_cast<ModelAPI_ResultParameter, ModelAPI_Result>;
 %template(modelAPI_ResultGroup) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_ResultGroup>;
 %template(modelAPI_ResultField) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_ResultField>;
-%template(modelAPI_ResultCompSolid) shared_ptr_cast<ModelAPI_ResultCompSolid, ModelAPI_ResultBody>;
 
 // Attribute casts
 %template(modelAPI_AttributeDocRef)        shared_ptr_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;
index e234aefe5a45721b42e061dde2a01a58b0e4702b..be23056ae6cae47231bd735fdae8a451234b2757 100644 (file)
@@ -114,6 +114,11 @@ public:
   //! \param theAllowFolder take into account grouping feature by folders
   virtual int size(const std::string& theGroupID, const bool theAllowFolder = false) = 0;
 
+  //! Returns the parent object of this child. This may be result or feature, parent of a
+  //! top result. Fast method, that uses internal data structure specifics.
+  virtual std::shared_ptr<ModelAPI_Object> parent(
+    const std::shared_ptr<ModelAPI_Object> theChild) = 0;
+
   //! Returns the feature that is currently edited in this document, normally
   //! this is the latest created feature
   //! \param theVisible use visible features only: flag is true for Object Browser functionality
index 4025d17b769b0a4e744586473d1c764982a9026e..bc8089991bf6c9c1bd84184b624819de90ea77f0 100644 (file)
 //
 
 #include "ModelAPI_ResultBody.h"
+
 #include <ModelAPI_BodyBuilder.h>
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
 
 ModelAPI_ResultBody::ModelAPI_ResultBody()
-: myBuilder(0)
+  : myBuilder(0)
 {
   myConnect = ConnectionNotComputed;
 }
@@ -32,7 +33,7 @@ ModelAPI_ResultBody::ModelAPI_ResultBody()
 ModelAPI_ResultBody::~ModelAPI_ResultBody()
 {
   if (myBuilder)
-  delete myBuilder;
+    delete myBuilder;
 }
 
 std::string ModelAPI_ResultBody::groupName()
@@ -41,7 +42,7 @@ std::string ModelAPI_ResultBody::groupName()
 }
 
 void ModelAPI_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                                const bool theIsStoreSameShapes)
+  const bool theIsStoreSameShapes)
 {
   myBuilder->store(theShape, theIsStoreSameShapes);
   myConnect = ConnectionNotComputed;
@@ -50,10 +51,12 @@ void ModelAPI_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
   aECreator->sendUpdated(data()->owner(), aRedispEvent);
+
+  updateSubs(theShape);
 }
 
 void ModelAPI_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
-                                 const std::shared_ptr<GeomAPI_Shape>& theToShape)
+  const std::shared_ptr<GeomAPI_Shape>& theToShape)
 {
   myBuilder->storeGenerated(theFromShape, theToShape);
   myConnect = ConnectionNotComputed;
@@ -62,11 +65,13 @@ void ModelAPI_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& t
   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
   aECreator->sendUpdated(data()->owner(), aRedispEvent);
+
+  updateSubs(theToShape);
 }
 
 void ModelAPI_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
-                                 const std::shared_ptr<GeomAPI_Shape>& theNewShape,
-                            const int theDecomposeSolidsTag)
+  const std::shared_ptr<GeomAPI_Shape>& theNewShape,
+  const int theDecomposeSolidsTag)
 {
   myBuilder->storeModified(theOldShape, theNewShape, theDecomposeSolidsTag);
   myConnect = ConnectionNotComputed;
@@ -75,6 +80,8 @@ void ModelAPI_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& th
   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
   aECreator->sendUpdated(data()->owner(), aRedispEvent);
+
+  updateSubs(theNewShape);
 }
 
 void ModelAPI_ResultBody::storeWithoutNaming(const std::shared_ptr<GeomAPI_Shape>& theShape)
@@ -94,74 +101,74 @@ std::shared_ptr<GeomAPI_Shape> ModelAPI_ResultBody::shape()
 }
 
 void ModelAPI_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theNewShape,
-    const std::string& theName, const int theTag)
+  const std::string& theName, const int theTag)
 {
   myBuilder->generated(theNewShape, theName, theTag);
 }
 
 void ModelAPI_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
-    const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
-    const int theTag)
+  const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
+  const int theTag)
 {
   myBuilder->generated(theOldShape, theNewShape, theName, theTag);
 }
 
 void ModelAPI_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
-    const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
-    const int theTag)
+  const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
+  const int theTag)
 {
   myBuilder->modified(theOldShape, theNewShape, theName, theTag);
 }
 
 
 void ModelAPI_ResultBody::deleted(
-    const std::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag)
+  const std::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag)
 {
   myBuilder->deleted(theOldShape, theTag);
 }
 
-void ModelAPI_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
-                                  std::shared_ptr<GeomAPI_Shape>  theShapeIn,
-                                  const int  theKindOfShape,
-                                  const int  theTag)
+void ModelAPI_ResultBody::loadDeletedShapes(GeomAlgoAPI_MakeShape* theMS,
+  std::shared_ptr<GeomAPI_Shape>  theShapeIn,
+  const int  theKindOfShape,
+  const int  theTag)
 {
   myBuilder->loadDeletedShapes(theMS, theShapeIn, theKindOfShape, theTag);
 }
 
-void ModelAPI_ResultBody::loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS,
-    std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
-    const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
-    const bool theIsStoreSeparate,
-    const bool theIsStoreAsGenerated,
-    const bool /*theSplitInSubs*/)
+void ModelAPI_ResultBody::loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS,
+  std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
+  const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
+  const bool theIsStoreSeparate,
+  const bool theIsStoreAsGenerated,
+  const bool /*theSplitInSubs*/)
 {
   myBuilder->loadAndOrientModifiedShapes(
     theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes, theIsStoreSeparate,
     theIsStoreAsGenerated);
 }
 
-void ModelAPI_ResultBody::loadAndOrientGeneratedShapes (GeomAlgoAPI_MakeShape* theMS,
-    std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape,
-    const int  theTag, const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes)
+void ModelAPI_ResultBody::loadAndOrientGeneratedShapes(GeomAlgoAPI_MakeShape* theMS,
+  std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape,
+  const int  theTag, const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes)
 {
   myBuilder->loadAndOrientGeneratedShapes(
     theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes);
 }
 
 void ModelAPI_ResultBody::loadFirstLevel(std::shared_ptr<GeomAPI_Shape> theShape,
-    const std::string& theName, int&  theTag)
+  const std::string& theName, int&  theTag)
 {
   myBuilder->loadFirstLevel(theShape, theName, theTag);
 }
 
 void ModelAPI_ResultBody::loadDisconnectedEdges(std::shared_ptr<GeomAPI_Shape> theShape,
-    const std::string& theName, int&  theTag)
+  const std::string& theName, int&  theTag)
 {
   myBuilder->loadDisconnectedEdges(theShape, theName, theTag);
 }
 
 void ModelAPI_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape,
-    const std::string& theName,int&  theTag)
+  const std::string& theName, int&  theTag)
 {
   myBuilder->loadDisconnectedVertexes(theShape, theName, theTag);
 }
@@ -173,3 +180,10 @@ bool ModelAPI_ResultBody::isConnectedTopology()
   }
   return myConnect == IsConnected;
 }
+
+void ModelAPI_ResultBody::setDisplayed(const bool theDisplay)
+{
+  ModelAPI_Result::setDisplayed(theDisplay);
+  for (int i = 0; i < numberOfSubs(); i++)
+    subResult(i)->setDisplayed(theDisplay);
+}
index 98a4b6a290c53f76da28f7e60c94c1f3d8597b3f..0ffb2422a3e9c67f7c68e462ec679f1fde22466d 100644 (file)
@@ -36,11 +36,27 @@ class GeomAlgoAPI_MakeShape;
 * Provides a shape that may be displayed in the viewer.
 * May provide really huge results, so, working with this kind
 * of result must be optimized.
+* Also provides a conainer of sub-body result in case it is compound or compsolid.
 */
 class ModelAPI_ResultBody : public ModelAPI_Result
 {
+public:
+  /// Iternal enumeration for storage the information of connected topology flag
+  enum ConnectedTopologyFlag {
+    ConnectionNotComputed, ///< not yet computed
+    IsConnected,           ///< the topology is connected
+    IsNotConnected         ///< the topology is connected
+  };
+
+protected:
+  /// Keeps (not persistently) the connected topology flag
+  ConnectedTopologyFlag myConnect;
+
+  ModelAPI_BodyBuilder* myBuilder; ///< provides the body processing in naming shape
+
 public:
   MODELAPI_EXPORT virtual ~ModelAPI_ResultBody();
+
   /// Returns the group identifier of this result
   MODELAPI_EXPORT virtual std::string groupName();
 
@@ -64,21 +80,23 @@ public:
     return "0.0001";
   }
 
-  /// Iternal enumeration for storage the information of connected topology flag
-  enum ConnectedTopologyFlag {
-    ConnectionNotComputed, ///< not yet computed
-    IsConnected,           ///< the topology is connected
-    IsNotConnected         ///< the topology is connected
-  };
-  /// Keeps (not persistently) the connected topology flag
-  ConnectedTopologyFlag myConnect;
+  /// Returns the number of sub-elements
+  MODELAPI_EXPORT virtual int numberOfSubs(bool forTree = false) const = 0;
+
+  /// Returns the sub-result by zero-base index
+  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_ResultBody> subResult(
+    const int theIndex, bool forTree = false) const = 0;
+
+  /// Returns true if feature or reuslt belong to this composite feature as subs
+  /// Returns theIndex - zero based index of sub if found
+  MODELAPI_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const = 0;
 
   /// \brief Stores the shape (called by the execution method).
   /// param[in] theShape shape to store.
   /// param[in] theIsStoreSameShapes if false stores reference to the same shape
   ///                                if it is already in document.
   MODELAPI_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                                     const bool theIsStoreSameShapes = true);
+    const bool theIsStoreSameShapes = true);
 
   /// Stores the generated shape (called by the execution method).
   MODELAPI_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
@@ -119,19 +137,20 @@ public:
     const std::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag = 1);
 
   /// load deleted shapes
-  MODELAPI_EXPORT virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
-                                  std::shared_ptr<GeomAPI_Shape>  theShapeIn,
-                                  const int  theKindOfShape,
-                                  const int  theTag);
+  MODELAPI_EXPORT virtual void loadDeletedShapes(GeomAlgoAPI_MakeShape* theMS,
+    std::shared_ptr<GeomAPI_Shape>  theShapeIn,
+    const int  theKindOfShape,
+    const int  theTag);
+
   /// load and orient modified shapes
-  MODELAPI_EXPORT virtual void loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS,
+  MODELAPI_EXPORT virtual void loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS,
     std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
     const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
-    const bool theIsStoreSeparate = false,
-    const bool theIsStoreAsGenerated = false,
+    const bool theIsStoreSeparate = false, const bool theIsStoreAsGenerated = false,
     const bool theSplitInSubs = false);
+
   /// load and orient generated shapes
-  MODELAPI_EXPORT virtual void loadAndOrientGeneratedShapes (GeomAlgoAPI_MakeShape* theMS,
+  MODELAPI_EXPORT virtual void loadAndOrientGeneratedShapes(GeomAlgoAPI_MakeShape* theMS,
     std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape,
     const int  theTag, const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes);
 
@@ -145,7 +164,7 @@ public:
 
   /// load disconnected vetexes
   MODELAPI_EXPORT virtual void loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape,
-    const std::string& theName,int&  theTag);
+    const std::string& theName, int&  theTag);
 
   /// Returns true if the latest modification of this body in the naming history
   // is equal to the given shape
@@ -155,11 +174,16 @@ public:
   /// so it is more effective to use this method than directly GeomAPI_Shape.
   MODELAPI_EXPORT virtual bool isConnectedTopology();
 
+  /// Set displayed flag to the result and all sub results
+  /// \param theDisplay a boolean value
+  MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
+
 protected:
   /// Default constructor accessible only from Model_Objects
   MODELAPI_EXPORT ModelAPI_ResultBody();
 
-  ModelAPI_BodyBuilder* myBuilder; ///< provides the body processing in naming shape
+  /// Updates the sub-bodies if shape of this object is compsolid or compound
+  virtual void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape) = 0;
 };
 
 //! Pointer on feature object
diff --git a/src/ModelAPI/ModelAPI_ResultCompSolid.cpp b/src/ModelAPI/ModelAPI_ResultCompSolid.cpp
deleted file mode 100755 (executable)
index e1fa263..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2014-2017  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
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
-//
-
-#include "ModelAPI_ResultCompSolid.h"
-
-ModelAPI_ResultCompSolid::~ModelAPI_ResultCompSolid()
-{
-}
-
-void ModelAPI_ResultCompSolid::setDisplayed(const bool theDisplay)
-{
-  ModelAPI_ResultBody::setDisplayed(theDisplay);
-  for (int i = 0; i < numberOfSubs(); i++)
-    subResult(i)->setDisplayed(theDisplay);
-}
diff --git a/src/ModelAPI/ModelAPI_ResultCompSolid.h b/src/ModelAPI/ModelAPI_ResultCompSolid.h
deleted file mode 100755 (executable)
index 70abc72..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (C) 2014-2017  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
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
-//
-
-#ifndef ModelAPI_ResultCompSolid_H_
-#define ModelAPI_ResultCompSolid_H_
-
-#include "ModelAPI_Result.h"
-#include "ModelAPI_ResultBody.h"
-#include <string>
-
-/**\class ModelAPI_ResultCompSolid
-* \ingroup DataModel
-* \brief The comp solid (container of results) result of a feature.
-*
-* Provides a conainer of body result that may be displayed in the viewer.
-*/
-class ModelAPI_ResultCompSolid : public ModelAPI_ResultBody
-{
-public:
-  MODELAPI_EXPORT virtual ~ModelAPI_ResultCompSolid();
-  /// Returns the group identifier of this result
-
-  /// Returns the number of sub-elements
-  virtual int numberOfSubs(bool forTree = false) const = 0;
-
-  /// Returns the sub-result by zero-base index
-  virtual std::shared_ptr<ModelAPI_ResultBody> subResult(const int theIndex,
-                                                         bool forTree = false) const = 0;
-
-  /// Returns true if feature or reuslt belong to this composite feature as subs
-  /// Returns theIndex - zero based index of sub if found
-  virtual bool isSub(ObjectPtr theObject, int& theIndex) const = 0;
-
-  /// Set displayed flag to the result and all sub results
-  /// \param theDisplay a boolean value
-  MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
-
-protected:
-};
-
-//! Pointer on feature object
-typedef std::shared_ptr<ModelAPI_ResultCompSolid> ResultCompSolidPtr;
-
-#endif
index b656c3fb7902d413adcd659f8bcab83c821d7e18..35b7e36daf38831f164ac9da5d564c292fb20e42 100755 (executable)
@@ -24,7 +24,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_AttributeDocRef.h>
@@ -265,66 +265,58 @@ CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
   return CompositeFeaturePtr(); // not found
 }
 
-ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
+ResultBodyPtr bodyOwner(const ResultPtr& theSub)
 {
-  int anIndex;
-  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
-  if (aBody.get()) {
-    FeaturePtr aFeatureOwner = aBody->document()->feature(aBody);
-    if (aFeatureOwner.get()) {
-      std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
-        aFeatureOwner->results().cbegin();
-      for(; aResIter != aFeatureOwner->results().cend(); aResIter++) {
-        ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIter);
-        if (aComp && aComp->isSub(aBody, anIndex))
-          return aComp;
-      }
+  if (theSub.get()) {
+    ObjectPtr aParent = theSub->document()->parent(theSub);
+    if (aParent.get()) {
+      return std::dynamic_pointer_cast<ModelAPI_ResultBody>(aParent);
     }
   }
-  return ResultCompSolidPtr(); // not found
+  return ResultBodyPtr(); // not found
 }
 
-int compSolidIndex(const ResultPtr& theSub)
+int bodyIndex(const ResultPtr& theSub)
 {
   int anIndex = -1;
-  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
-  if (aBody.get()) {
-    FeaturePtr aFeatureOwner = aBody->document()->feature(aBody);
-    if (aFeatureOwner.get()) {
-      std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
-        aFeatureOwner->results().cbegin();
-      for(; aResIter != aFeatureOwner->results().cend(); aResIter++) {
-        ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIter);
-        if (aComp && aComp->isSub(aBody, anIndex))
-          return anIndex;
-      }
-    }
+  ResultBodyPtr aParent = bodyOwner(theSub);
+  if (aParent.get()) {
+    ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
+    if (aBody.get() && aParent->isSub(aBody, anIndex))
+      return anIndex;
   }
   return anIndex; // not found
 }
 
 bool hasSubResults(const ResultPtr& theResult)
 {
-  ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theResult);
+  ResultBodyPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
   return aCompSolid.get() && aCompSolid->numberOfSubs() > 0;
 }
 
+void allSubs(const ResultBodyPtr& theResult, std::list<ResultPtr>& theResults) {
+  // iterate sub-bodies of compsolid
+  ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+  if (aComp.get()) {
+    int aNumSub = aComp->numberOfSubs();
+    for (int a = 0; a < aNumSub; a++) {
+      ResultBodyPtr aSub = aComp->subResult(a);
+      theResults.push_back(aSub);
+      allSubs(aSub, theResults);
+    }
+  }
+}
+
 void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults)
 {
   if (!theFeature.get()) // safety: for empty feature no results
     return;
   const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
-  std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+  std::list<ResultPtr>::const_iterator aRIter = aResults.begin();
   for (; aRIter != aResults.cend(); aRIter++) {
     theResults.push_back(*aRIter);
-    // iterate sub-bodies of compsolid
-    ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRIter);
-    if (aComp.get()) {
-      int aNumSub = aComp->numberOfSubs();
-      for(int a = 0; a < aNumSub; a++) {
-        theResults.push_back(aComp->subResult(a));
-      }
-    }
+    ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRIter);
+    allSubs(aResult, theResults);
   }
 }
 
@@ -606,33 +598,24 @@ void getConcealedResults(const FeaturePtr& theFeature,
   }
 }
 
-std::pair<std::string, bool> getDefaultName(
-    const std::shared_ptr<ModelAPI_Result>& theResult,
-    const int theResultIndex)
+std::pair<std::string, bool> getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult)
 {
   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 = compSolidOwner(theResult);
-  if (aCompSolidRes) {
+  ResultBodyPtr anOwnerRes = bodyOwner(theResult);
+  if (anOwnerRes) {
     // names of sub-solids in CompSolid should be default (for example,
     // result of boolean operation 'Boolean_1_1' is a CompSolid which is renamed to 'MyBOOL',
     // however, sub-elements of 'MyBOOL' should be named 'Boolean_1_1_1', 'Boolean_1_1_2' etc.)
     std::ostringstream aDefaultName;
-    aDefaultName << anOwner->name();
-    // compute default name of CompSolid (name of feature + index of CompSolid's result)
-    int aCompSolidResultIndex = 0;
-    const std::list<ResultPtr>& aResults = anOwner->results();
-    for (std::list<ResultPtr>::const_iterator anIt = aResults.begin();
-         anIt != aResults.end(); ++anIt, ++aCompSolidResultIndex)
-      if (aCompSolidRes == *anIt)
-        break;
-    aDefaultName << "_" << (aCompSolidResultIndex + 1) << "_" << (theResultIndex + 1);
+    aDefaultName << getDefaultName(anOwnerRes).first;
+    aDefaultName << "_" << (bodyIndex(theResult) + 1);
     return std::pair<std::string, bool>(aDefaultName.str(), false);
   }
 
+  FeaturePtr anOwner = ModelAPI_Feature::feature(theResult->data()->owner());
   DataPtr aData = anOwner->data();
 
   ListOfReferences aReferences;
@@ -658,6 +641,15 @@ std::pair<std::string, bool> getDefaultName(
         break;
     }
   }
+  // get the result number in the feature
+  int anIndexInOwner = 0;
+  const std::list<ResultPtr>& anOwnerResults = anOwner->results();
+  std::list<ResultPtr>::const_iterator aResIt = anOwnerResults.cbegin();
+  for(; aResIt != anOwnerResults.cend(); aResIt++) {
+    if(*aResIt == theResult)
+      break;
+    anIndexInOwner++;
+  }
 
   // find an object which is concealed by theResult
   if (aFoundRef != aReferences.end() && !aFoundRef->second.empty()) {
@@ -665,12 +657,12 @@ std::pair<std::string, bool> getDefaultName(
     std::map<ResultPtr, int> aNbRefToObject;
     // search the object by result index
     std::list<ObjectPtr>::const_iterator anObjIt = aFoundRef->second.begin();
-    int aResultIndex = theResultIndex;
+    int aResultIndex = anIndexInOwner;
     while (--aResultIndex >= 0) {
       ResultPtr aCurRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anObjIt);
-      ResultCompSolidPtr aParentCompSolid = ModelAPI_Tools::compSolidOwner(aCurRes);
-      if (aParentCompSolid)
-        aCurRes = aParentCompSolid;
+      ResultBodyPtr aParentBody = ModelAPI_Tools::bodyOwner(aCurRes);
+      if (aParentBody)
+        aCurRes = aParentBody;
       if (aNbRefToObject.find(aCurRes) == aNbRefToObject.end())
         aNbRefToObject[aCurRes] = 1;
       else
@@ -686,9 +678,9 @@ std::pair<std::string, bool> getDefaultName(
     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;
+      ResultBodyPtr aParentBody = ModelAPI_Tools::bodyOwner(anObjRes);
+      if (aParentBody)
+        anObjRes = aParentBody;
 
       // return name of reference result only if it has been renamed by the user,
       // in other case compose a default name
@@ -711,48 +703,9 @@ std::pair<std::string, bool> getDefaultName(
   aDefaultName << anOwner->name();
   // if there are several results (issue #899: any number of result),
   // add unique prefix starting from second
-  if (theResultIndex > 0 || theResult->groupName() == ModelAPI_ResultBody::group())
-    aDefaultName << "_" << theResultIndex + 1;
+  if (anIndexInOwner > 0 || theResult->groupName() == ModelAPI_ResultBody::group())
+    aDefaultName << "_" << anIndexInOwner + 1;
   return std::pair<std::string, bool>(aDefaultName.str(), false);
 }
 
-std::string getDefaultName(const ResultPtr& theResult)
-{
-  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_1' is a CompSolid which is renamed to 'MyBOOL',
-  // however, sub-elements of 'MyBOOL' should be named 'Boolean_1_1_1', 'Boolean_1_1_2' etc.)
-  std::ostringstream aDefaultName;
-  aDefaultName << anOwner->name();
-
-  ResultPtr aResToSearch = theResult;
-  ResultCompSolidPtr aCompSolidRes = compSolidOwner(theResult);
-  if (aCompSolidRes)
-    aResToSearch = aCompSolidRes;
-
-  // obtain index of result
-  int aResIndex = 1;
-  const std::list<ResultPtr>& aResults = anOwner->results();
-  for (std::list<ResultPtr>::const_iterator anIt = aResults.begin();
-       anIt != aResults.end(); ++anIt, ++aResIndex)
-    if (aResToSearch == *anIt)
-      break;
-
-  // compute default name of CompSolid (name of feature + index of CompSolid's result)
-  aDefaultName << "_" << aResIndex;
-
-  if (aCompSolidRes) {
-    // obtain index of result in compsolid and compose a default name
-    int aNbSubs = aCompSolidRes->numberOfSubs();
-    for (int anIndex = 0; anIndex < aNbSubs; ++anIndex)
-      if (aCompSolidRes->subResult(anIndex) == theResult) {
-        aDefaultName << "_" << (anIndex + 1);
-        break;
-      }
-  }
-
-  return aDefaultName.str();
-}
-
 } // namespace ModelAPI_Tools
index 907cc7b974a9df0f996c51c699a4024566878418..0646e23eb4865f7f3474f635f9f9e6e32f6f9781 100755 (executable)
@@ -28,7 +28,7 @@ class ModelAPI_Document;
 class ModelAPI_Feature;
 class ModelAPI_Result;
 class ModelAPI_ResultParameter;
-class ModelAPI_ResultCompSolid;
+class ModelAPI_ResultBody;
 
 class GeomAPI_Shape;
 
@@ -101,17 +101,17 @@ MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
                                         const std::shared_ptr<ModelAPI_Feature>& theFeature);
 
 /*!
- * Returns the compsolid result - parent of this result.
- * \param theSub the sub-element of comp-solid
+ * Returns the result - parent of this result.
+ * \param theSub the sub-element of composit result
  * \returns null if it is not sub-element of composite
  */
-MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultCompSolid> compSolidOwner(
-                                            const std::shared_ptr<ModelAPI_Result>& theSub);
+MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
+  bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub);
 /*!
- * Returns index of this result in parent (if parent exists, returned by compSolidOwner)
+ * Returns index of this result in parent (if parent exists, returned by bodyOwner)
  * \returns zero-base index, or -1 if not found
  */
-MODELAPI_EXPORT int compSolidIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
+MODELAPI_EXPORT int bodyIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
 
 /*!
 * Returns true if the result contains a not empty list of sub results.
@@ -121,6 +121,12 @@ MODELAPI_EXPORT int compSolidIndex(const std::shared_ptr<ModelAPI_Result>& theSu
 */
 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
 
+/*!
+*  collects recursively all subs of the given result
+*/
+MODELAPI_EXPORT void allSubs(const std::shared_ptr<ModelAPI_ResultBody>& theResult,
+                             std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
+
 /*!
 * Adds the results of the given feature to theResults list: including disabled and sub-results
 */
@@ -187,17 +193,12 @@ MODELAPI_EXPORT void findRefsToFeatures(
 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                    std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
 
-/*! Return the default name of the result according the features it depends.
+/*! Return the default name of the result according the features it depends or name of the feature.
  *  Return also whether the name is get from the concealing result of parent object
  *  (means that concealing result has user-defined name).
  */
 MODELAPI_EXPORT std::pair<std::string, bool> getDefaultName(
-    const std::shared_ptr<ModelAPI_Result>& theResult,
-    const int theResultIndex);
-
-/*! Return the default name of the result according to name of the feature.
- */
-MODELAPI_EXPORT std::string getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult);
+  const std::shared_ptr<ModelAPI_Result>& theResult);
 }
 
 #endif
index e9d740ce076c8dedb9bd0c6e5a909c048cd52d8f..320d3771ae7c656321630ab8ef716c52a68c6f0f 100644 (file)
@@ -59,7 +59,6 @@
   #include "ModelAPI_ResultGroup.h"
   #include "ModelAPI_ResultField.h"
   #include "ModelAPI_Tools.h"
-  #include "ModelAPI_ResultCompSolid.h"
   #include "ModelAPI_Folder.h"
 
   #include <memory>
index 985e6761ea60da801a77c61a13e2fcb18134a133..5142efc3185f74979a58424b4479ad8196420c42 100644 (file)
@@ -49,7 +49,6 @@
 #include <ModelAPI_Folder.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Tools.h>
@@ -216,32 +215,15 @@ void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature)
 
   // Save only names of results which is not correspond to default feature name
   const std::list<ResultPtr>& aResults = theFeature->results();
-  std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
-  for (int i = 0; aResIt != aResults.end(); ++aResIt, ++i) {
-    std::pair<std::string, bool> aName = ModelAPI_Tools::getDefaultName(*aResIt, i);
+  std::list<ResultPtr> allRes;
+  ModelAPI_Tools::allResults(theFeature, allRes);
+  for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+    std::pair<std::string, bool> aName = ModelAPI_Tools::getDefaultName(*aRes);
     std::string aDefaultName = aName.first;
-    std::string aResName = (*aResIt)->data()->name();
-
+    std::string aResName = (*aRes)->data()->name();
     bool isUserDefined = !(isFeatureDefaultName && aDefaultName == aResName);
-
-    myNames[*aResIt] = EntityName(aResName,
-        (isUserDefined ? aResName : std::string()), !isUserDefined);
-
-    // check names of sub-results for CompSolid
-    ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIt);
-    if (aCompSolid) {
-      int aNbSubs = aCompSolid->numberOfSubs();
-      for (int j = 0; j < aNbSubs; ++j) {
-        ResultPtr aSub = aCompSolid->subResult(j);
-        std::string aSubName = aSub->data()->name();
-        aName = ModelAPI_Tools::getDefaultName(aSub, j);
-        aDefaultName = aName.first;
-
-        bool isUserDefinedSubName = isUserDefined || aDefaultName != aSubName;
-        myNames[aSub] = EntityName(aSubName,
-            (isUserDefinedSubName ? aSubName : std::string()), !isUserDefinedSubName);
-      }
-    }
+    myNames[*aRes] =
+      EntityName(aResName, (isUserDefined ? aResName : std::string()), !isUserDefined);
   }
 }
 
@@ -783,24 +765,12 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity
     bool isUserDefinedName = !myNames[theEntity].myIsDefault;
     // store results if they have user-defined names or colors
     std::list<ResultPtr> aResultsWithNameOrColor;
-    const std::list<ResultPtr>& aResults = theEntity->results();
-    std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
-    for (; aResIt != aResults.end(); ++aResIt) {
-      if (!myNames[*aResIt].myIsDefault || !isDefaultColor(*aResIt) ||
-          !isDefaultDeflection(*aResIt) || !isDefaultTransparency(*aResIt))
-        aResultsWithNameOrColor.push_back(*aResIt);
-
-      ResultCompSolidPtr aCompSolid =
-          std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIt);
-      if (aCompSolid) {
-        int aNbSubs = aCompSolid->numberOfSubs();
-        for (int i = 0; i < aNbSubs; ++i) {
-          ResultPtr aCurRes = aCompSolid->subResult(i);
-          if (!myNames[aCurRes].myIsDefault || !isDefaultColor(aCurRes) ||
-              !isDefaultDeflection(aCurRes) || !isDefaultTransparency(aCurRes))
-            aResultsWithNameOrColor.push_back(aCurRes);
-        }
-      }
+    std::list<ResultPtr> allRes;
+    ModelAPI_Tools::allResults(theEntity, allRes);
+    for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+      if(!myNames[*aRes].myIsDefault || !isDefaultColor(*aRes) ||
+         !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes))
+        aResultsWithNameOrColor.push_back(*aRes);
     }
     // store just dumped entity to stack
     if (myEntitiesStack.empty() || myEntitiesStack.top().myEntity != theEntity)
@@ -815,37 +785,32 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity
 
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult)
 {
-  FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
-  int anIndex = 0;
-  int aSubIndex = -1;
-  std::list<ResultPtr> aResults = aFeature->results();
-  for(std::list<ResultPtr>::const_iterator
-      anIt = aResults.cbegin(); anIt != aResults.cend(); ++anIt, ++anIndex) {
-    if(theResult->isSame(*anIt)) {
-      break;
-    }
-
-    ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*anIt);
-    if (aCompSolid) {
-      int aNbSubs = aCompSolid->numberOfSubs();
-      for (aSubIndex = 0; aSubIndex < aNbSubs; ++aSubIndex)
-        if (theResult->isSame(aCompSolid->subResult(aSubIndex)))
-          break;
-      if (aSubIndex < aNbSubs)
-        break;
-      aSubIndex = -1;
+  // iterate in the structure of sub-results to the parent
+  ResultPtr aCurRes = theResult;
+  std::list<int> anIndices; // indexes of results in the parent result, starting from topmost
+  while(aCurRes.get()) {
+    ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(aCurRes);
+    if (aParent) {
+      anIndices.push_front(ModelAPI_Tools::bodyIndex(aCurRes));
     }
+    aCurRes = aParent;
   }
 
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
   myDumpBuffer << name(aFeature);
-  if(anIndex == 0) {
-    myDumpBuffer << ".result()";
-  } else {
-    myDumpBuffer << ".results()[" << anIndex << "]";
-  }
-  if (aSubIndex >= 0) {
-    myDumpBuffer << ".subResult(" << aSubIndex << ")";
+  for (std::list<int>::iterator anI = anIndices.begin(); anI != anIndices.end(); anI++) {
+    if (anI == anIndices.begin()) {
+      if(*anI == 0) {
+        myDumpBuffer << ".result()";
+      }
+      else {
+        myDumpBuffer << ".results()[" << *anI << "]";
+      }
+    } else {
+      myDumpBuffer << ".subResult(" << *anI << ")";
+    }
   }
+
   return *this;
 }
 
index ca9422c18b1152224f2f8306c803dd29f06c62a8..c87b99fe9a078dd0e9c81a09ef52869521e35872 100644 (file)
@@ -25,7 +25,8 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
+
 //--------------------------------------------------------------------------------------
 
 //--------------------------------------------------------------------------------------
@@ -181,12 +182,11 @@ int ModelHighAPI_Selection::numberOfSubs() const
   if (myVariantType != VT_ResultSubShapePair)
     return 0;
 
-  ResultCompSolidPtr aCompSolid =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
-  if (!aCompSolid)
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myResultSubShapePair.first);
+  if (!aBody.get())
     return 0;
 
-  return aCompSolid->numberOfSubs();
+  return aBody->numberOfSubs();
 }
 
 ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
@@ -194,13 +194,12 @@ ModelHighAPI_Selection ModelHighAPI_Selection::subResult(int theIndex) const
   if (myVariantType != VT_ResultSubShapePair)
     return ModelHighAPI_Selection();
 
-  ResultCompSolidPtr aCompSolid =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myResultSubShapePair.first);
-  if (!aCompSolid)
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myResultSubShapePair.first);
+  if (!aBody)
     return ModelHighAPI_Selection();
-  if (theIndex >= aCompSolid->numberOfSubs())
+  if (theIndex >= aBody->numberOfSubs())
     return ModelHighAPI_Selection();
 
-  ResultBodyPtr aResult = aCompSolid->subResult(theIndex);
+  ResultBodyPtr aResult = aBody->subResult(theIndex);
   return ModelHighAPI_Selection(aResult, aResult->shape());
 }
index 1646edc0d2bc230e17cfa35dc4001a2ed21285c2..cf141d592387a9542c9933b9c284671cb628d841 100755 (executable)
@@ -25,7 +25,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeIntArray.h>
 
 #include "ModuleBase_Tools.h"
@@ -84,8 +84,8 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
     aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
 
   // Activate individual repaintng if this is a part of compsolid
-  ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
-  SetAutoHilight(aCompSolid.get() == NULL);
+  ResultBodyPtr aResOwner = ModelAPI_Tools::bodyOwner(myResult);
+  SetAutoHilight(aResOwner.get() == NULL);
 
   myHiddenSubShapesDrawer = new AIS_ColoredDrawer (myDrawer);
   Handle(Prs3d_ShadingAspect) aShadingAspect = new Prs3d_ShadingAspect();
index 73d877e8d914c6171e983f7fbeef0616412374aa..996f4b1810414d9ac0458fdc600198baf841ad07 100755 (executable)
@@ -45,7 +45,6 @@
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Result.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_Session.h>
index e60685b0cc5e2758cfd8b573ef25502d3aa1dc81..4d8b47998fb6ffa96187727ff3254461fc517678 100644 (file)
@@ -33,7 +33,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Events.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
@@ -415,7 +415,7 @@ void ModuleBase_WidgetValidated::filterPresentations(QList<ModuleBase_ViewerPrsP
 //********************************************************************
 void ModuleBase_WidgetValidated::filterCompSolids(QList<ModuleBase_ViewerPrsPtr>& theValues)
 {
-  std::set<ResultCompSolidPtr> aCompSolids;
+  std::set<ResultBodyPtr> aCompSolids;
   QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
 
   // Collect compsolids.
@@ -423,9 +423,9 @@ void ModuleBase_WidgetValidated::filterCompSolids(QList<ModuleBase_ViewerPrsPtr>
   for (; anIt != aLast; anIt++) {
     const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
     ObjectPtr anObject = aViewerPrs->object();
-    ResultCompSolidPtr aResultCompSolid =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
-    if(aResultCompSolid.get()) {
+    ResultBodyPtr aResultCompSolid =
+      std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
+    if(aResultCompSolid.get() && aResultCompSolid->numberOfSubs() > 0) {
       aCompSolids.insert(aResultCompSolid);
     }
   }
@@ -436,7 +436,7 @@ void ModuleBase_WidgetValidated::filterCompSolids(QList<ModuleBase_ViewerPrsPtr>
     const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
     ObjectPtr anObject = aViewerPrs->object();
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-    ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aResult);
+    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aResult);
     if(aResCompSolidPtr.get() && (aCompSolids.find(aResCompSolidPtr) != aCompSolids.end())) {
       // Skip sub-solid of compsolid.
       continue;
index 1781e96ae3fb8d8807883b5c3b0cfbdd5fefc5ee..445c4ad8c8500baaa4f99278c7018aba828bece0 100755 (executable)
@@ -42,7 +42,7 @@
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
 
 #include <Events_InfoMessage.h>
@@ -189,12 +189,12 @@ void PartSet_OperationPrs::addValue(const ObjectPtr& theObject, const GeomShapeP
   if (theObject.get()) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if (aResult.get()) {
-      ResultCompSolidPtr aCompsolidResult =
-        std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-      if (aCompsolidResult.get()) {
-        if (aCompsolidResult->numberOfSubs() > 0) {
-          for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-            ResultPtr aSubResult = aCompsolidResult->subResult(i);
+      ResultBodyPtr aBodyResult =
+        std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
+      if (aBodyResult.get()) {
+        if (aBodyResult->numberOfSubs() > 0) {
+          for(int i = 0; i < aBodyResult->numberOfSubs(); i++) {
+            ResultPtr aSubResult = aBodyResult->subResult(i);
             if (aSubResult.get()) {
               GeomShapePtr aShape;
               addValue(aSubResult, aShape, theFeature, theWorkshop, theObjectShapes);
index 7e62e4b9fb559cd2df26c16b49a6bb450d98a0bf..eec581b6729d57940fa1b29246b8983f4be87b2a 100755 (executable)
@@ -25,7 +25,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <GeomAPI_PlanarEdges.h>
 
 #include <Events_InfoMessage.h>
@@ -74,8 +74,8 @@ PartSet_ResultSketchPrs::PartSet_ResultSketchPrs(ResultPtr theResult)
     aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
 
   // Activate individual repaintng if this is a part of compsolid
-  ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
-  SetAutoHilight(aCompSolid.get() == NULL);
+  ResultBodyPtr anOwner = ModelAPI_Tools::bodyOwner(myResult);
+  SetAutoHilight(anOwner.get() == NULL);
 
   ModuleBase_Tools::setPointBallHighlighting(this);
 }
index 574e89ad39c44440362d05f361b1ac3f91fc019e..6219084db71cee5d0b27985d645690a548806ed9 100644 (file)
@@ -33,7 +33,7 @@
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Folder.h>
@@ -157,7 +157,7 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
   ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
   if (aResObj.get()) {
     ModuleBase_IWorkshop* aWork = workshop();
-    ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
+    ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResObj);
     if (aCompRes.get()) {
       VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
         (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
@@ -252,7 +252,7 @@ Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
 
 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
 {
-  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
   if (aCompRes.get())
     return new PartSet_CompsolidNode(theObj, this);
   return new PartSet_ObjectNode(theObj, this);
@@ -930,7 +930,7 @@ PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
 
 void PartSet_CompsolidNode::update()
 {
-  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
   int aNb = aCompRes->numberOfSubs(true);
   ModuleBase_ITreeNode* aNode;
   ResultBodyPtr aBody;
@@ -958,7 +958,7 @@ QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObj
 {
   QTreeNodesList aResult;
 
-  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
   int aNb = aCompRes->numberOfSubs(true);
   ModuleBase_ITreeNode* aNode;
   ResultBodyPtr aBody;
@@ -983,7 +983,7 @@ QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObj
 QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
 {
   QTreeNodesList aResult;
-  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
   int aNb = aCompRes->numberOfSubs(true);
   ModuleBase_ITreeNode* aNode;
   // Delete extra objects
index 49f89d9c033ac2a308aade1b1a558a10846ac122..32fea83989156974e215e1ba842a8fc613b67ce2 100755 (executable)
@@ -44,7 +44,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Object.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
 
@@ -558,7 +558,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
           for(int i = 0; i < aCurSelList->size(); i++) {
             std::shared_ptr<ModelAPI_AttributeSelection> aCurSel = aCurSelList->value(i);
             ResultPtr aCurSelContext = aCurSel->context();
-            ResultCompSolidPtr aCurSelCompSolidPtr = ModelAPI_Tools::compSolidOwner(aCurSelContext);
+            ResultBodyPtr aCurSelCompSolidPtr = ModelAPI_Tools::bodyOwner(aCurSelContext);
             std::shared_ptr<GeomAPI_Shape> aCurSelCompSolid;
             if(aCurSelCompSolidPtr.get()) {
               aCurSelCompSolid = aCurSelCompSolidPtr->shape();
@@ -566,8 +566,8 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
             for(int j = 0; j < aRefSelList->size(); j++) {
               std::shared_ptr<ModelAPI_AttributeSelection> aRefSel = aRefSelList->value(j);
               ResultPtr aRefSelContext = aRefSel->context();
-              ResultCompSolidPtr aRefSelCompSolidPtr =
-                ModelAPI_Tools::compSolidOwner(aRefSelContext);
+              ResultBodyPtr aRefSelCompSolidPtr =
+                ModelAPI_Tools::bodyOwner(aRefSelContext);
               std::shared_ptr<GeomAPI_Shape> aRefSelCompSolid;
               if(aRefSelCompSolidPtr.get()) {
                 aRefSelCompSolid = aRefSelCompSolidPtr->shape();
index 9df154d64edcc7f1e15b834a1cddb9c42f02552f..5c3654aca85b2b72b9aa02bda1128804ce81343d 100644 (file)
@@ -37,7 +37,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeIntArray.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 
 #include <ModuleBase_BRepOwner.h>
 #include <ModuleBase_IModule.h>
@@ -435,9 +435,8 @@ bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& th
     // compsolid is not visualized in the viewer,
     // but should have presentation when all sub solids are
     // visible. It is useful for highlight presentation where compsolid shape is selectable
-    if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
-      ResultCompSolidPtr aCompsolidResult =
-        std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+    if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) {
+      ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
         bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
         for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
@@ -967,7 +966,7 @@ void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
     if (aAISObj.get() == NULL) {
       // if result is a result of a composite feature, it is visualized by visualization of
       // composite children, so we should get one of this presentations
-      ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+      ResultBodyPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
       if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) {
         aAISObj = getAISObject(aCompSolid->subResult(0));
       }
index ab86347b5ce62bc98f1df65ce324a8eff8ad9770..ff78af48c690c2d2d75583af8521b41975f03f12 100644 (file)
@@ -25,7 +25,6 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Tools.h>
 
 #include <ModuleBase_Tools.h>
index ed54a60a27ab034ff8100903077474cb28b4320a..b3815aa530de635f45f26b1e7d8c8aab99d5abe1 100644 (file)
@@ -31,7 +31,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_Session.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 
 #include <AIS_InteractiveContext.hxx>
@@ -265,7 +265,7 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs,
     // is On and we have to use parent result which corresponds to the CompSolid shape
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aFeature);
     if (aResult.get()) {
-      ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(aResult);
+      ResultBodyPtr aCompSolid = ModelAPI_Tools::bodyOwner(aResult);
       if (aCompSolid.get()) {
         GeomShapePtr aShape = aCompSolid->shape();
         if (aShape.get() && aShape->isEqual(thePrs->shape())) {
index bece087dc5f4266476d175da5814030859875d1f..405c1979ed4689c646780c927584b7611e428e0d 100755 (executable)
@@ -38,7 +38,8 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Object.h>
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_Tools.h>
 
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_Tools.h>
@@ -107,22 +108,11 @@ void XGUI_SelectionMgr::onObjectBrowserSelection()
     if (aObject.get()) {
       aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
       if (aFeature.get()) {
-        const std::list<std::shared_ptr<ModelAPI_Result>> aResList = aFeature->results();
-        ResultPtr aResult;
-        ResultCompSolidPtr aCompSolid;
-        std::list<ResultPtr>::const_iterator aIt;
-        for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
-          aResult = (*aIt);
+        std::list<ResultPtr> allRes;
+        ModelAPI_Tools::allResults(aFeature, allRes);
+        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
           aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
-            new ModuleBase_ViewerPrs(aResult, GeomShapePtr(), NULL)));
-          aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
-          if (aCompSolid.get()) {
-            for (int i = 0; i < aCompSolid->numberOfSubs(); i++) {
-              ResultBodyPtr aResult = aCompSolid->subResult(i);
-              aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
-                new ModuleBase_ViewerPrs(aResult, aResult->shape(), NULL)));
-            }
-          }
+            new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL)));
         }
       }
     }
index 9fe73219f76fd987f92830dbf102151eb320d52f..6b079cdc30ccfeaa36522907c2055033059408ca 100755 (executable)
@@ -72,7 +72,6 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultGroup.h>
 #include <ModelAPI_ResultParameter.h>
@@ -1636,18 +1635,20 @@ bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) con
   for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
     anObjectsIt != theObjects.end(); anObjectsIt++) {
     ObjectPtr anObject = *anObjectsIt;
-    ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
+    ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
     if (aCompRes.get()) {
-      if (aCompRes->numberOfSubs(true) == 0)
+      std::list<ResultPtr> allRes;
+      ModelAPI_Tools::allSubs(aCompRes, allRes);
+      if (allRes.empty()) {
         anAllProcessedObjects.insert(anObject);
-      else {
-        for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
-          ResultPtr aSubRes = aCompRes->subResult(i, true);
-          anAllProcessedObjects.insert(aCompRes->subResult(i, true));
+      } else {
+        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+          ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
+          if (aBody.get() && aBody->numberOfSubs() == 0)
+            anAllProcessedObjects.insert(aBody);
         }
       }
-    }
-    else
+    } else
       anAllProcessedObjects.insert(anObject);
   }
 
@@ -2080,11 +2081,14 @@ bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
 {
   bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
   if (!aCanBeShaded) {
-    ResultCompSolidPtr aCompsolidResult =
-                std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-    if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
-      for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
-        aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
+    ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
+    if (aCompRes.get() != NULL) { // change colors for all sub-solids
+      std::list<ResultPtr> allRes;
+      ModelAPI_Tools::allSubs(aCompRes, allRes);
+      std::list<ResultPtr>::iterator aRes = allRes.begin();
+      for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
+        aCanBeShaded = myDisplayer->canBeShaded(*aRes);
+      }
     }
   }
   return aCanBeShaded;
@@ -2181,12 +2185,12 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
-      ResultCompSolidPtr aCompsolidResult =
-        std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
-      if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
-        for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-          setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
-                                                                    aDlg->getRandomColor());
+      ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+      if (aBodyResult.get() != NULL) { // change colors for all sub-solids
+        std::list<ResultPtr> allRes;
+        ModelAPI_Tools::allSubs(aBodyResult, allRes);
+        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+          setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
         }
       }
       setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
@@ -2224,11 +2228,12 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
-      ResultCompSolidPtr aCompsolidResult =
-        std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
-      if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
-        for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-          setTransparency(aCompsolidResult->subResult(i), theTransparency);
+      ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+      if (aBodyResult.get() != NULL) { // change property for all sub-solids
+        std::list<ResultPtr> allRes;
+        ModelAPI_Tools::allSubs(aBodyResult, allRes);
+        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+          setTransparency(*aRes, theTransparency);
         }
       }
       setTransparency(aResult, theTransparency);
@@ -2284,11 +2289,12 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
-      ResultCompSolidPtr aCompsolidResult =
-        std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
-      if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
-        for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-          setDeflection(aCompsolidResult->subResult(i), aDeflection);
+      ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+      if (aBodyResult.get() != NULL) { // change property for all sub-solids
+        std::list<ResultPtr> allRes;
+        ModelAPI_Tools::allSubs(aBodyResult, allRes);
+        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+          setDeflection(*aRes, aDeflection);
         }
       }
       setDeflection(aResult, aDeflection);
@@ -2471,14 +2477,15 @@ void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup
 //**************************************************************
 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
 {
-  foreach(ObjectPtr aObj, theList) {
-    myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
+  foreach(ObjectPtr anObj, theList) {
+    myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
 
-    ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
-    if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
-      for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-          myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
-                                      (XGUI_Displayer::DisplayMode)theMode, false);
+    ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
+    if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
+      std::list<ResultPtr> allRes;
+      ModelAPI_Tools::allSubs(aBodyResult, allRes);
+      for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+        myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
       }
     }
   }
index 4b3546211d2f1b4d540f3f01eb507b029daa91c2..f7720512d9fc73e38d1df1ff9d9458ab63063735 100755 (executable)
@@ -38,7 +38,6 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Tools.h>
 
 #include <ModuleBase_Events.h>