]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make tests working on new results structure and selection of feature as argument Results_Hierarchy
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 16 Aug 2018 13:48:35 +0000 (16:48 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 16 Aug 2018 13:48:35 +0000 (16:48 +0300)
23 files changed:
src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/Test/Test1922.py
src/FeaturesPlugin/Test/TestBooleanCompSolids.py
src/FeaturesPlugin/Test/TestCompositeFeaturesOnCompSolids.py
src/FeaturesPlugin/Test/TestRemoveSubShapes.py
src/FeaturesPlugin/Test/TestUnion.py
src/GeomAPI/GeomAPI_Interface.cpp [new file with mode: 0644]
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_BodyBuilder.cpp
src/Model/Model_Data.cpp
src/Model/Model_Objects.cpp
src/Model/Model_ResultBody.cpp
src/Model/Model_SelectionNaming.cpp
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/ModelAPI_ResultBody.cpp
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/PartSet/PartSet_TreeNodes.cpp
src/PythonAPI/model/tests/tests.py
test.API/SHAPER/Transformations/TestTranslation_3.py

index eebff3615f35824001011694ce5f3dac715756c8..c4c4914e5f4f7f56d311bf3b16cdb5797004b205 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "FeaturesPlugin_BooleanCut.h"
 
-#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Tools.h>
 
@@ -54,7 +54,7 @@ void FeaturesPlugin_BooleanCut::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();
index 5400cbd3fa9886fc16062ef8edbe57865939fd39..605f9b919593425dbcb9138fba480a19e1b48ec4 100644 (file)
@@ -733,6 +733,18 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
     if(aResultBody.get()) {
       continue;
     }
+    FeaturePtr aResultFeature = aSelectAttr->contextFeature();
+    if(aResultFeature.get()) {
+      bool aOkRes = false;
+      std::list<ResultPtr>::const_iterator aFRes = aResultFeature->results().cbegin();
+      for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) {
+        ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aFRes);
+        if (aBody.get() && !aBody->isDisabled())
+          aOkRes = true;
+      }
+      if (aOkRes)
+        continue;
+    }
 
     theError = "Error: Only body shapes and construction planes are allowed for selection.";
     return false;
index a9224658b368932c2b511a233b3e0ce5ab92831a..8b1fc660b7715b59a850e78602b78790d4e0671c 100644 (file)
@@ -165,7 +165,7 @@ Partition_1 = model.addPartition(Part_1_doc, [model.selection("EDGE", "Extrusion
 model.end()
 PartitionFeature = Partition_1.feature()
 assert(len(PartitionFeature.results()) == 1)
-PartitionResult = modelAPI_ResultCompSolid(modelAPI_ResultBody(PartitionFeature.firstResult()))
+PartitionResult = modelAPI_ResultBody(PartitionFeature.firstResult())
 assert(PartitionResult.numberOfSubs() == 22)
 
 assert(model.checkPythonDump())
index aad16ba714d654c94eaffb02c514b836091c545f..44d44c76003a41cd31856dd22bd2b4426215a2d6 100644 (file)
@@ -118,7 +118,7 @@ aSession.finishOperation()
 #=========================================================================
 aSession.startOperation()
 aBooleanFt = aPart.addFeature("Cut")
-aBooleanFt.selectionList("main_objects").append(modelAPI_ResultCompSolid(extrudedObjects[0]).subResult(1), None)
+aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
 aBooleanFt.execute()
 aSession.finishOperation()
@@ -133,7 +133,7 @@ aSession.undo()
 #=========================================================================
 aSession.startOperation()
 aBooleanFt = aPart.addFeature("Fuse")
-aBooleanFt.selectionList("main_objects").append(modelAPI_ResultCompSolid(extrudedObjects[0]).subResult(1), None)
+aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
 aBooleanFt.execute()
 aSession.finishOperation()
index c885ab2704766e044e78f6c72830bf8620ba7ec6..47caabb1d0e461c8a09d5a53afdb49a66462d149 100644 (file)
@@ -158,7 +158,7 @@ aFromResult = aFromPlaneFeature.firstResult()
 aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
 anExtrusionCutFt.selection("from_object").setValue(aFromResult, aFromShape)
 anExtrusionCutFt.real("from_offset").setValue(0)
-anExtrusionCutFt.selectionList("main_objects").append(modelAPI_ResultCompSolid(anExtrusionResult).subResult(1), None)
+anExtrusionCutFt.selectionList("main_objects").append(anExtrusionResult.subResult(1), None)
 aSession.finishOperation()
 aSession.finishOperation()
 
@@ -232,7 +232,7 @@ anRevolutionFuseFt.selection("to_object").setValue(aToResult, None)
 anRevolutionFuseFt.real("to_offset").setValue(0)
 anRevolutionFuseFt.selection("from_object").setValue(None, None)
 anRevolutionFuseFt.real("from_offset").setValue(0)
-anRevolutionFuseFt.selectionList("main_objects").append(modelAPI_ResultCompSolid(anExtrusionResult).subResult(1), None)
+anRevolutionFuseFt.selectionList("main_objects").append(anExtrusionResult.subResult(1), None)
 aSession.finishOperation()
 aSession.finishOperation()
 
index 9a10cfab5d2b3a8fdf17d678fb9761f628e893a1..7926781a667b9032710db3da016238bb6820eb3f 100644 (file)
@@ -79,7 +79,7 @@ anExtrusionFeature.real("to_offset").setValue(0) #TODO: remove
 anExtrusionFeature.real("from_offset").setValue(0) #TODO: remove
 anExtrusionFeature.execute()
 aSession.finishOperation()
-anExtrusionResult = modelAPI_ResultCompSolid(modelAPI_ResultBody(anExtrusionFeature.firstResult()))
+anExtrusionResult = modelAPI_ResultBody(anExtrusionFeature.firstResult())
 
 #=========================================================================
 # Remove sub-shapes
@@ -91,7 +91,7 @@ aRemoveSubShapesFeature.string("creation_method").setValue("by_keep_subshapes")
 aRemoveSubShapesFeature.selectionList("subshapes_to_keep").removeLast();
 aSession.finishOperation()
 assert (len(aRemoveSubShapesFeature.results()) > 0)
-anUnionResult = modelAPI_ResultCompSolid(modelAPI_ResultBody(aRemoveSubShapesFeature.firstResult()))
+anUnionResult = modelAPI_ResultBody(aRemoveSubShapesFeature.firstResult())
 assert (anUnionResult.numberOfSubs() == 2)
 
 from salome.shaper import model
index fa540f7f2b018fbe2cdd9226656eeb5e1aa77716..541ad7344a0088c86295effa6699463e94e7246a 100644 (file)
@@ -79,7 +79,7 @@ anExtrusionFeature.real("to_offset").setValue(0) #TODO: remove
 anExtrusionFeature.real("from_offset").setValue(0) #TODO: remove
 anExtrusionFeature.execute()
 aSession.finishOperation()
-anExtrusionResult = modelAPI_ResultCompSolid(modelAPI_ResultBody(anExtrusionFeature.firstResult()))
+anExtrusionResult = modelAPI_ResultBody(anExtrusionFeature.firstResult())
 
 #=========================================================================
 # Make union on extrusion
@@ -91,7 +91,7 @@ aUnionFeature.selectionList("base_objects").append(anExtrusionResult.subResult(1
 aUnionFeature.selectionList("base_objects").append(anExtrusionResult.subResult(2), None);
 aSession.finishOperation()
 assert (len(aUnionFeature.results()) > 0)
-anUnionResult = modelAPI_ResultCompSolid(modelAPI_ResultBody(aUnionFeature.firstResult()))
+anUnionResult = modelAPI_ResultBody(aUnionFeature.firstResult())
 assert (anUnionResult.numberOfSubs() == 0)
 
 from salome.shaper import model
diff --git a/src/GeomAPI/GeomAPI_Interface.cpp b/src/GeomAPI/GeomAPI_Interface.cpp
new file mode 100644 (file)
index 0000000..025a4d4
--- /dev/null
@@ -0,0 +1,36 @@
+// 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 <GeomAPI_Interface.h>
+
+GeomAPI_Interface::GeomAPI_Interface()
+{
+
+}
+
+GeomAPI_Interface::~GeomAPI_Interface()
+{
+
+}
+
+bool GeomAPI_Interface::empty() const
+{
+  return myImpl.get() == 0;
+}
index b76998d854b0001c40180d39f0bfb1fafb0ca6e9..1be7f53ee6a44491185f482f3923fc695adca38d 100644 (file)
@@ -438,6 +438,7 @@ void Model_AttributeSelection::setID(const std::string theID)
 }
 
 ResultPtr Model_AttributeSelection::context()
+{
   if (!ModelAPI_AttributeSelection::isInitialized() && !myTmpContext.get() && !myTmpSubShape.get())
     return ResultPtr();
 
@@ -469,9 +470,13 @@ FeaturePtr Model_AttributeSelection::contextFeature() {
     return FeaturePtr(); // feature can not be selected temporarily
   }
   return std::dynamic_pointer_cast<ModelAPI_Feature>(myRef.value());
-
 }
-
+ObjectPtr Model_AttributeSelection::contextObject() {
+  ResultPtr aRes = context();
+  if (aRes.get())
+    return aRes;
+  return contextFeature();
+}
 
 
 void Model_AttributeSelection::setObject(const std::shared_ptr<ModelAPI_Object>& theObject)
@@ -926,9 +931,14 @@ void Model_AttributeSelection::selectSubShape(
             aNS = TNaming_Tool::CurrentNamedShape(aNS);
             if (!aNS.IsNull() && scope().Contains(aNS->Label())) { // scope check is for 2228
               TDF_Label aLab = aNS->Label();
-              while(aLab.Depth() != 7 && aLab.Depth() > 5)
+              if (aLab.Depth() % 2 == 0)
                 aLab = aLab.Father();
               ObjectPtr anObj = aDoc->objects()->object(aLab);
+              while(!anObj.get() && aLab.Depth() > 5) {
+                aLab = aLab.Father().Father();
+                anObj = aDoc->objects()->object(aLab);
+              }
+
               if (anObj.get()) {
                 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
                 if (aRes)
@@ -944,10 +954,11 @@ void Model_AttributeSelection::selectSubShape(
         if (aComp && aComp->numberOfSubs()) {
           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)) {
+          std::list<ResultPtr>::iterator aS = allSubs.begin();
+          for(; aS != allSubs.end(); aS++) {
+            ResultBodyPtr aSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aS);
+            if (aSub && aSub->numberOfSubs() == 0 && aSub->shape().get() &&
+                aSub->shape()->isSubShape(aShapeToBeSelected)) {
               aCont = aSub;
               break;
             }
@@ -960,13 +971,20 @@ void Model_AttributeSelection::selectSubShape(
       while(aFindNewContext && aCont.get()) {
         aFindNewContext = false;
         // take references to all results: root one, any sub
-        ResultBodyPtr aCompContext = ModelAPI_Tools::bodyOwner(aCont);
+        ResultBodyPtr aCompContext = ModelAPI_Tools::bodyOwner(aCont, true);
         std::list<ResultPtr> allRes;
-        if (aCompContext.get())
+        if (aCompContext.get()) {
           ModelAPI_Tools::allSubs(aCompContext, allRes);
-        allRes.push_back(aCont);
+          allRes.push_back(aCompContext);
+        } else {
+          allRes.push_back(aCont);
+        }
         for(std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
           ResultPtr aResCont = *aSub;
+          ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResCont);
+          // only lower and higher level subs are counted
+          if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext)
+            continue;
           const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
           std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
           for(; !aFindNewContext && aRef != aRefs.end(); aRef++) {
index 3576913777a966c88fe3a870a31451d3aa34c143..9267748a7d33a4e182726643cbb3d2404f94f320 100644 (file)
@@ -80,6 +80,8 @@ public:
 
   /// Returns the context of the selection if the whole feature was selected
   MODEL_EXPORT virtual FeaturePtr contextFeature();
+  /// Returns the context of the selection : result or feature
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Object> contextObject();
 
   /// Sets the feature object
   MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
index ab2c1dec6e37483221a8f54ac486cc68fd8cf729..c301d069454f987074caa7b9b4cc88d671837944 100755 (executable)
@@ -129,7 +129,7 @@ static void evolutionToSelectionRec(TDF_Label theLab, const bool theFlag) {
 void Model_BodyBuilder::evolutionToSelection(const bool theFlag)
 {
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
-  if (!aData) // unknown case
+  if (!aData || !aData->isValid()) // unknown case
     return;
   TDF_Label& aShapeLab = aData->shapeLab();
   evolutionToSelectionRec(aShapeLab, theFlag);
@@ -1107,7 +1107,7 @@ void Model_BodyBuilder::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape>
 std::shared_ptr<GeomAPI_Shape> Model_BodyBuilder::shape()
 {
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
-  if (aData) {
+  if (aData && aData->isValid()) {
     TDF_Label aShapeLab = aData->shapeLab();
     Handle(TDF_Reference) aRef;
     if (aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
index 697bfedd91724a9702dfeb8fe834f6aab255101e..74f19ec71f3b4bb90ba4b8ceaccb51e57392fb78 100644 (file)
@@ -138,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).first;
+        std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult, false).first;
         isUserDefined = aDefaultName != theName;
       }
       if (isUserDefined) {
index f02468717f2b816ba6396c2f185ede3d5af01d4b..4c44977c41b3d8f083148b17bb27b4a59bd204a7 100644 (file)
@@ -576,7 +576,8 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel)
           if (aSub.get()) {
             std::shared_ptr<Model_Data> aSubData = std::dynamic_pointer_cast<Model_Data>(
               aSub->data());
-            if (aSubData->label().Father().IsEqual(aSubLab.ChangeValue())) {
+            const TDF_Label& aSubLabVal = aSubLab.ChangeValue();
+            if (aSubData->label().Father().IsEqual(aSubLabVal)) {
               aCurrentResult = aSub;
               break;
             }
index e22a0f38e26e62c0c7bb96e078255bed22b150a1..e168c6c1a0f96cb09234afe9bc6fa4aeeb2848b5 100644 (file)
@@ -77,11 +77,12 @@ void Model_ResultBody::loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS,
       }*/
       (*aSubIter)->loadAndOrientModifiedShapes(
         theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes, theIsStoreSeparate,
-        theIsStoreAsGenerated);
+        theIsStoreAsGenerated, theSplitInSubs);
     }
   } else { // do for this directly
-    myBuilder->loadAndOrientGeneratedShapes(
-      theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes);
+    myBuilder->loadAndOrientModifiedShapes(
+      theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes, theIsStoreSeparate,
+        theIsStoreAsGenerated);
   }
 }
 
index be25462d976eb73e15897922f91a0b5c761da9d1..1b1c51e9ec70901a076e22a19d15503fb263dae5 100644 (file)
@@ -141,10 +141,10 @@ std::string Model_SelectionNaming::getShapeName(
             !aNS->Label().IsDescendant(aContextData->label())) {
           isNeedContextName = false;
           TDF_Label aNSDataLab = aNS->Label();
-          while(aNSDataLab.Depth() != 7 && aNSDataLab.Depth() > 5)
+          if (aNSDataLab.Depth() % 2 == 0)
             aNSDataLab = aNSDataLab.Father();
           ObjectPtr aNewContext = theDoc->objects()->object(aNSDataLab);
-          if (!aNewContext.get() && aNSDataLab.Depth() == 7) {
+          while(!aNewContext.get() && aNSDataLab.Depth() > 5) {
             aNSDataLab = aNSDataLab.Father().Father();
             aNewContext = theDoc->objects()->object(aNSDataLab);
           }
index 22d1f8a543cd80080f7645cb595c663a88d2a219..5343ecfbd6052b338771bccb2f2a443ae2f8e5e4 100644 (file)
@@ -74,6 +74,8 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
 
   /// Returns the context of the selection if the whole feature was selected
   virtual std::shared_ptr<ModelAPI_Feature> contextFeature() = 0;
+  /// Returns the context of the selection : result or feature
+  virtual std::shared_ptr<ModelAPI_Object> contextObject() = 0;
 
   /// Updates the underlied selection due to the changes in the referenced objects
   /// \returns false if update is failed
index bc8089991bf6c9c1bd84184b624819de90ea77f0..ba28f8b90cf9c1bbda60e646be1d94b26b9d09b3 100644 (file)
@@ -32,8 +32,6 @@ ModelAPI_ResultBody::ModelAPI_ResultBody()
 
 ModelAPI_ResultBody::~ModelAPI_ResultBody()
 {
-  if (myBuilder)
-    delete myBuilder;
 }
 
 std::string ModelAPI_ResultBody::groupName()
index 35b7e36daf38831f164ac9da5d564c292fb20e42..a1f4ef0640583075e4dd4eee980a3049f3309821 100755 (executable)
@@ -265,11 +265,17 @@ CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
   return CompositeFeaturePtr(); // not found
 }
 
-ResultBodyPtr bodyOwner(const ResultPtr& theSub)
+ResultBodyPtr bodyOwner(const ResultPtr& theSub, const bool theRoot)
 {
   if (theSub.get()) {
     ObjectPtr aParent = theSub->document()->parent(theSub);
     if (aParent.get()) {
+      if (theRoot) { // try to find parent of parent
+        ResultPtr aResultParent = std::dynamic_pointer_cast<ModelAPI_Result>(aParent);
+        ResultBodyPtr aGrandParent = bodyOwner(aResultParent, true);
+        if (aGrandParent.get())
+          aParent = aGrandParent;
+      }
       return std::dynamic_pointer_cast<ModelAPI_ResultBody>(aParent);
     }
   }
@@ -598,7 +604,8 @@ void getConcealedResults(const FeaturePtr& theFeature,
   }
 }
 
-std::pair<std::string, bool> getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult)
+std::pair<std::string, bool> getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult,
+                                            const bool theInherited)
 {
   typedef std::list< std::pair < std::string, std::list<ObjectPtr> > > ListOfReferences;
 
@@ -619,26 +626,28 @@ std::pair<std::string, bool> getDefaultName(const std::shared_ptr<ModelAPI_Resul
   DataPtr aData = anOwner->data();
 
   ListOfReferences aReferences;
-  aData->referencesToObjects(aReferences);
-
   // find first result with user-defined name
   ListOfReferences::const_iterator aFoundRef = aReferences.end();
-  for (ListOfReferences::const_iterator aRefIt = aReferences.begin();
-       aRefIt != aReferences.end(); ++aRefIt) {
-    bool isConcealed = aSession->validators()->isConcealed(anOwner->getKind(), aRefIt->first);
-    bool isMainArg = isConcealed &&
-                     aSession->validators()->isMainArgument(anOwner->getKind(), aRefIt->first);
-    if (isConcealed) {
-      // check the referred object is a Body
-      // (for example, ExtrusionCut has a sketch as a first attribute which is concealing)
-      bool isBody = aRefIt->second.size() > 1 || (aRefIt->second.size() == 1 &&
-                    aRefIt->second.front()->groupName() == ModelAPI_ResultBody::group());
-      if (isBody && (isMainArg || aFoundRef == aReferences.end() ||
-          aData->isPrecedingAttribute(aRefIt->first, aFoundRef->first)))
-        aFoundRef = aRefIt;
-
-      if (isMainArg)
-        break;
+  if (theInherited) {
+    aData->referencesToObjects(aReferences);
+
+    for (ListOfReferences::const_iterator aRefIt = aReferences.begin();
+         aRefIt != aReferences.end(); ++aRefIt) {
+      bool isConcealed = aSession->validators()->isConcealed(anOwner->getKind(), aRefIt->first);
+      bool isMainArg = isConcealed &&
+                       aSession->validators()->isMainArgument(anOwner->getKind(), aRefIt->first);
+      if (isConcealed) {
+        // check the referred object is a Body
+        // (for example, ExtrusionCut has a sketch as a first attribute which is concealing)
+        bool isBody = aRefIt->second.size() > 1 || (aRefIt->second.size() == 1 &&
+                      aRefIt->second.front()->groupName() == ModelAPI_ResultBody::group());
+        if (isBody && (isMainArg || aFoundRef == aReferences.end() ||
+            aData->isPrecedingAttribute(aRefIt->first, aFoundRef->first)))
+          aFoundRef = aRefIt;
+
+        if (isMainArg)
+          break;
+      }
     }
   }
   // get the result number in the feature
index 0646e23eb4865f7f3474f635f9f9e6e32f6f9781..e302d19a0634191fed1345f06ec8688ba64431ac 100755 (executable)
@@ -103,10 +103,11 @@ MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
 /*!
  * Returns the result - parent of this result.
  * \param theSub the sub-element of composit result
+ * \param theRoot if it is true, returns the root father
  * \returns null if it is not sub-element of composite
  */
 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
-  bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub);
+  bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
 /*!
  * Returns index of this result in parent (if parent exists, returned by bodyOwner)
  * \returns zero-base index, or -1 if not found
@@ -198,7 +199,7 @@ MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>
  *  (means that concealing result has user-defined name).
  */
 MODELAPI_EXPORT std::pair<std::string, bool> getDefaultName(
-  const std::shared_ptr<ModelAPI_Result>& theResult);
+  const std::shared_ptr<ModelAPI_Result>& theResult, const bool theInherited = true);
 }
 
 #endif
index d2e98f0683088ad3d016b1bec3ab4dfab6509e87..2a60ec774d664b8b78b12ca86a4eac6130dad609 100755 (executable)
@@ -836,8 +836,8 @@ bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
     for (int i = 0; i < aSelectionListAttr->size(); i++) {
       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
-      bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection,
-                                    myWorkshop);
+      bool aFound = findInSelection(
+        anAttr->contextObject(), anAttr->value(), aGeomSelection, myWorkshop);
       if (!aFound)
         anIndicesToBeRemoved.insert(i);
     }
index 6219084db71cee5d0b27985d645690a548806ed9..5e642c691aba56927ddd26dbe083d0db2579e517 100644 (file)
@@ -161,8 +161,13 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
     if (aCompRes.get()) {
       VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
         (aWork->isVisible(aCompRes) ? Visible : Hidden) : NoneState;
-      for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
-        ResultPtr aSubRes = aCompRes->subResult(i, true);
+      std::list<ResultPtr> aResultsList;
+      ModelAPI_Tools::allSubs(aCompRes, aResultsList);
+
+      std::list<ResultPtr>::const_iterator aIt;
+      //for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
+      for (aIt = aResultsList.cbegin(); aIt != aResultsList.cend(); aIt++) {
+        ResultPtr aSubRes = (*aIt); // aCompRes->subResult(i, true);
         VisibilityState aS = aWork->isVisible(aSubRes) ? Visible : Hidden;
         if (aState == NoneState)
           aState = aS;
@@ -182,7 +187,93 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const
   return NoneState;
 }
 
+void PartSet_ObjectNode::update()
+{
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
+  if (aCompRes.get()) {
+    int aNb = aCompRes->numberOfSubs(true);
+    ModuleBase_ITreeNode* aNode;
+    ResultBodyPtr aBody;
+    int i;
+    for (i = 0; i < aNb; i++) {
+      aBody = aCompRes->subResult(i, true);
+      if (i < myChildren.size()) {
+        aNode = myChildren.at(i);
+        if (aNode->object() != aBody) {
+          ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+        }
+      } else {
+        aNode = new PartSet_ObjectNode(aBody, this);
+        myChildren.append(aNode);
+      }
+    }
+    // Delete extra objects
+    while (myChildren.size() > aNb) {
+      aNode = myChildren.takeLast();
+      delete aNode;
+    }
+    foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+      aNode->update();
+    }
+  }
+}
+
+QTreeNodesList PartSet_ObjectNode::objectCreated(const QObjectPtrList& theObjects)
+{
+  QTreeNodesList aResult;
+
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
+  if (aCompRes.get()) {
+    int aNb = aCompRes->numberOfSubs(true);
+    ModuleBase_ITreeNode* aNode;
+    ResultBodyPtr aBody;
+    int i;
+    for (i = 0; i < aNb; i++) {
+      aBody = aCompRes->subResult(i, true);
+      if (i < myChildren.size()) {
+        aNode = myChildren.at(i);
+        if (aNode->object() != aBody) {
+          ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+          aResult.append(aNode);
+        }
+      } else {
+        aNode = new PartSet_ObjectNode(aBody, this);
+        myChildren.append(aNode);
+        aResult.append(aNode);
+      }
+    }
+    foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+      aResult.append(aNode->objectCreated(theObjects));
+    }
+  }
+  return aResult;
+}
 
+QTreeNodesList PartSet_ObjectNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
+{
+  QTreeNodesList aResult;
+  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
+  if (aCompRes.get()) {
+    int aNb = aCompRes->numberOfSubs(true);
+    ModuleBase_ITreeNode* aNode;
+    // Delete extra objects
+    bool isDeleted = false;
+    while (myChildren.size() > aNb) {
+      aNode = myChildren.takeLast();
+      delete aNode;
+      isDeleted = true;
+    }
+    if (isDeleted)
+      aResult.append(this);
+    int i = 0;
+    foreach(ModuleBase_ITreeNode* aNode, myChildren) {
+      ((PartSet_ObjectNode*)aNode)->setObject(aCompRes->subResult(i, true));
+      aResult.append(aNode->objectsDeleted(theDoc, theGroup));
+      i++;
+    }
+  }
+  return aResult;
+}
 //////////////////////////////////////////////////////////////////////////////////
 PartSet_FolderNode::PartSet_FolderNode(ModuleBase_ITreeNode* theParent,
   FolderType theType)
@@ -252,9 +343,9 @@ Qt::ItemFlags PartSet_FolderNode::flags(int theColumn) const
 
 ModuleBase_ITreeNode* PartSet_FolderNode::createNode(const ObjectPtr& theObj)
 {
-  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
-  if (aCompRes.get())
-    return new PartSet_CompsolidNode(theObj, this);
+  //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObj);
+  //if (aCompRes.get())
+  //  return new PartSet_CompsolidNode(theObj, this);
   return new PartSet_ObjectNode(theObj, this);
 }
 
@@ -922,78 +1013,78 @@ void PartSet_ObjectFolderNode::getFirstAndLastIndex(int& theFirst, int& theLast)
 
 
 //////////////////////////////////////////////////////////////////////////////////
-PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
-  ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
-{
-  update();
-}
-
-void PartSet_CompsolidNode::update()
-{
-  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
-  int aNb = aCompRes->numberOfSubs(true);
-  ModuleBase_ITreeNode* aNode;
-  ResultBodyPtr aBody;
-  int i;
-  for (i = 0; i < aNb; i++) {
-    aBody = aCompRes->subResult(i, true);
-    if (i < myChildren.size()) {
-      aNode = myChildren.at(i);
-      if (aNode->object() != aBody) {
-        ((PartSet_ObjectNode*)aNode)->setObject(aBody);
-      }
-    } else {
-      aNode = new PartSet_ObjectNode(aBody, this);
-      myChildren.append(aNode);
-    }
-  }
-  // Delete extra objects
-  while (myChildren.size() > aNb) {
-    aNode = myChildren.takeLast();
-    delete aNode;
-  }
-}
-
-QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
-{
-  QTreeNodesList aResult;
-
-  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
-  int aNb = aCompRes->numberOfSubs(true);
-  ModuleBase_ITreeNode* aNode;
-  ResultBodyPtr aBody;
-  int i;
-  for (i = 0; i < aNb; i++) {
-    aBody = aCompRes->subResult(i, true);
-    if (i < myChildren.size()) {
-      aNode = myChildren.at(i);
-      if (aNode->object() != aBody) {
-        ((PartSet_ObjectNode*)aNode)->setObject(aBody);
-        aResult.append(aNode);
-      }
-    } else {
-      aNode = new PartSet_ObjectNode(aBody, this);
-      myChildren.append(aNode);
-      aResult.append(aNode);
-    }
-  }
-  return aResult;
-}
-
-QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
-{
-  QTreeNodesList aResult;
-  ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
-  int aNb = aCompRes->numberOfSubs(true);
-  ModuleBase_ITreeNode* aNode;
-  // Delete extra objects
-  bool isDeleted = false;
-  while (myChildren.size() > aNb) {
-    aNode = myChildren.takeLast();
-    delete aNode;
-    isDeleted = true;
-  }
-  if (isDeleted)
-    aResult.append(this);
-  return aResult;
-}
\ No newline at end of file
+//PartSet_CompsolidNode::PartSet_CompsolidNode(const ObjectPtr& theObj,
+//  ModuleBase_ITreeNode* theParent) : PartSet_ObjectNode(theObj, theParent)
+//{
+//  update();
+//}
+
+//void PartSet_CompsolidNode::update()
+//{
+//  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+//  int aNb = aCompRes->numberOfSubs(true);
+//  ModuleBase_ITreeNode* aNode;
+//  ResultBodyPtr aBody;
+//  int i;
+//  for (i = 0; i < aNb; i++) {
+//    aBody = aCompRes->subResult(i, true);
+//    if (i < myChildren.size()) {
+//      aNode = myChildren.at(i);
+//      if (aNode->object() != aBody) {
+//        ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+//      }
+//    } else {
+//      aNode = new PartSet_ObjectNode(aBody, this);
+//      myChildren.append(aNode);
+//    }
+//  }
+//  // Delete extra objects
+//  while (myChildren.size() > aNb) {
+//    aNode = myChildren.takeLast();
+//    delete aNode;
+//  }
+//}
+//
+//QTreeNodesList PartSet_CompsolidNode::objectCreated(const QObjectPtrList& theObjects)
+//{
+//  QTreeNodesList aResult;
+//
+//  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+//  int aNb = aCompRes->numberOfSubs(true);
+//  ModuleBase_ITreeNode* aNode;
+//  ResultBodyPtr aBody;
+//  int i;
+//  for (i = 0; i < aNb; i++) {
+//    aBody = aCompRes->subResult(i, true);
+//    if (i < myChildren.size()) {
+//      aNode = myChildren.at(i);
+//      if (aNode->object() != aBody) {
+//        ((PartSet_ObjectNode*)aNode)->setObject(aBody);
+//        aResult.append(aNode);
+//      }
+//    } else {
+//      aNode = new PartSet_ObjectNode(aBody, this);
+//      myChildren.append(aNode);
+//      aResult.append(aNode);
+//    }
+//  }
+//  return aResult;
+//}
+//
+//QTreeNodesList PartSet_CompsolidNode::objectsDeleted(const DocumentPtr& theDoc, const QString& theGroup)
+//{
+//  QTreeNodesList aResult;
+//  ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(myObject);
+//  int aNb = aCompRes->numberOfSubs(true);
+//  ModuleBase_ITreeNode* aNode;
+//  // Delete extra objects
+//  bool isDeleted = false;
+//  while (myChildren.size() > aNb) {
+//    aNode = myChildren.takeLast();
+//    delete aNode;
+//    isDeleted = true;
+//  }
+//  if (isDeleted)
+//    aResult.append(this);
+//  return aResult;
+//}
\ No newline at end of file
index 921abf09a88dd17331ff83b9729f3050476881c3..e2ba9dfe41141aebb33d4bac25315eeb37ad3d89 100644 (file)
@@ -198,6 +198,17 @@ def testHaveNamingEdges(theFeature, theModel, thePartDoc) :
     assert(shape.isEdge())
     assert(name != ""), "String empty"
 
+def lowerLevelSubResults(theResult, theList):
+  """ Collects in a list all lover level sub-results (without children).
+  Auxiliary method for context correct definition.
+  """
+  nbSubs = theResult.numberOfSubs()
+  if nbSubs == 0:
+    theList.append(theResult)
+  else:
+    for sub in range(0, nbSubs):
+      lowerLevelSubResults(theResult.subResult(sub), theList)
+
 def testHaveNamingByType(theFeature, theModel, thePartDoc, theSubshapeType) :
   """ Tests if all sub-shapes of result have a unique name
   :param theFeature: feature to test.
@@ -206,22 +217,14 @@ def testHaveNamingByType(theFeature, theModel, thePartDoc, theSubshapeType) :
   if not theFeature.results():
     return
   aFirstRes = theFeature.results()[0]
-  # Get number of sub-results
-  hasSubs = True
-  nbSubs = aFirstRes.numberOfSubs()
-  if nbSubs == 0:
-    # no sub-results => treat current result as a sub
-    hasSubs = False
-    nbSubs = 1
+  aResList = []
+  lowerLevelSubResults(aFirstRes, aResList)
 
   selectionList = []
   shapesList = [] # to append only unique shapes (not isSame)
-  for sub in range(0, nbSubs):
+  for aR in aResList:
     # Get feature result/sub-result
-    if hasSubs:
-      aResult = aFirstRes.subResult(sub).resultSubShapePair()[0]
-    else:
-      aResult = aFirstRes.resultSubShapePair()[0]
+    aResult = aR.resultSubShapePair()[0]
     # Get result/sub-result shape
     shape = aResult.shape()
     # Create shape explorer with desired shape type
index dadc9d953e52076dc434e5f7b46891a5b3676173..bf8617124fa8aded48247d0aab88f09e69899a64 100644 (file)
@@ -163,21 +163,35 @@ Face_13 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_7/Wire-Sket
 # Shells
 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_10_1"), model.selection("FACE", "Face_11_1")])
 Shell_1.result().setName("Shell_1_1")
-Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_10_1"), model.selection("FACE", "Face_11_1")])
+model.addRecover(Part_1_doc, Shell_1, [Face_10.result()])
+model.addRecover(Part_1_doc, Shell_1, [Face_11.result()])
+Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_1_1"), model.selection("FACE", "Recover_2_1")])
 Shell_2.result().setName("Shell_2_1")
-Shell_3 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_10_1"), model.selection("FACE", "Face_11_1")])
+model.addRecover(Part_1_doc, Shell_1, [Face_10.result()])
+model.addRecover(Part_1_doc, Shell_1, [Face_11.result()])
+Shell_3 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_3_1"), model.selection("FACE", "Recover_4_1")])
 Shell_3.result().setName("Shell_3_1")
-Shell_4 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_10_1"), model.selection("FACE", "Face_11_1")])
+model.addRecover(Part_1_doc, Shell_1, [Face_10.result()])
+model.addRecover(Part_1_doc, Shell_1, [Face_11.result()])
+Shell_4 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_5_1"), model.selection("FACE", "Recover_6_1")])
 Shell_4.result().setName("Shell_4_1")
-Shell_5 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_10_1"), model.selection("FACE", "Face_11_1")])
+model.addRecover(Part_1_doc, Shell_1, [Face_10.result()])
+model.addRecover(Part_1_doc, Shell_1, [Face_11.result()])
+Shell_5 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_7_1"), model.selection("FACE", "Recover_8_1")])
 Shell_5.result().setName("Shell_5_1")
 Shell_6 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_12_1"), model.selection("FACE", "Face_13_1")])
 Shell_6.result().setName("Shell_6_1")
-Shell_7 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_12_1"), model.selection("FACE", "Face_13_1")])
+model.addRecover(Part_1_doc, Shell_1, [Face_12.result()])
+model.addRecover(Part_1_doc, Shell_1, [Face_13.result()])
+Shell_7 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_9_1"), model.selection("FACE", "Recover_10_1")])
 Shell_7.result().setName("Shell_7_1")
-Shell_8 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_10_1"), model.selection("FACE", "Face_11_1")])
+model.addRecover(Part_1_doc, Shell_1, [Face_10.result()])
+model.addRecover(Part_1_doc, Shell_1, [Face_11.result()])
+Shell_8 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_11_1"), model.selection("FACE", "Recover_12_1")])
 Shell_8.result().setName("Shell_8_1")
-Shell_9 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_10_1"), model.selection("FACE", "Face_11_1")])
+model.addRecover(Part_1_doc, Shell_1, [Face_10.result()])
+model.addRecover(Part_1_doc, Shell_1, [Face_11.result()])
+Shell_9 = model.addShell(Part_1_doc, [model.selection("FACE", "Recover_13_1"), model.selection("FACE", "Recover_14_1")])
 Shell_9.result().setName("Shell_9_1")
 
 # Parameters
@@ -516,16 +530,16 @@ model.testHaveNamingFaces(Translation_90, model, Part_1_doc)
 
 
 model.testNbResults(Translation_48, 0)
-assert(Translation_48.feature().error() == 'Attribute "axis_object" is not initialized.')
+assert(Translation_48.feature().error() == 'Translation axis is not selected.')
 
 model.testNbResults(Translation_57, 0)
-assert(Translation_57.feature().error() == 'Attribute "axis_object" is not initialized.')
+assert(Translation_57.feature().error() == 'Translation axis is not selected.')
 
 model.testNbResults(Translation_66, 0)
-assert(Translation_66.feature().error() == 'Attribute "axis_object" is not initialized.')
+assert(Translation_66.feature().error() == 'Translation axis is not selected.')
 
 model.testNbResults(Translation_75, 0)
-assert(Translation_75.feature().error() == 'Attribute "axis_object" is not initialized.')
+assert(Translation_75.feature().error() == 'Translation axis is not selected.')
 
 model.testNbResults(Translation_84, 0)
-assert(Translation_84.feature().error() == 'Attribute "axis_object" is not initialized.')
\ No newline at end of file
+assert(Translation_84.feature().error() == 'Translation axis is not selected.')