From 9fadaebe6d57d0836c7997ee60eb4cfdb67e2ffb Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 16 Aug 2018 16:48:35 +0300 Subject: [PATCH] Make tests working on new results structure and selection of feature as argument --- .../FeaturesPlugin_BooleanCut.cpp | 4 +- .../FeaturesPlugin_Validators.cpp | 12 + src/FeaturesPlugin/Test/Test1922.py | 2 +- .../Test/TestBooleanCompSolids.py | 4 +- .../Test/TestCompositeFeaturesOnCompSolids.py | 4 +- .../Test/TestRemoveSubShapes.py | 4 +- src/FeaturesPlugin/Test/TestUnion.py | 4 +- src/GeomAPI/GeomAPI_Interface.cpp | 36 +++ src/Model/Model_AttributeSelection.cpp | 38 ++- src/Model/Model_AttributeSelection.h | 2 + src/Model/Model_BodyBuilder.cpp | 4 +- src/Model/Model_Data.cpp | 2 +- src/Model/Model_Objects.cpp | 3 +- src/Model/Model_ResultBody.cpp | 7 +- src/Model/Model_SelectionNaming.cpp | 4 +- src/ModelAPI/ModelAPI_AttributeSelection.h | 2 + src/ModelAPI/ModelAPI_ResultBody.cpp | 2 - src/ModelAPI/ModelAPI_Tools.cpp | 49 ++-- src/ModelAPI/ModelAPI_Tools.h | 5 +- .../ModuleBase_WidgetMultiSelector.cpp | 4 +- src/PartSet/PartSet_TreeNodes.cpp | 251 ++++++++++++------ src/PythonAPI/model/tests/tests.py | 27 +- .../Transformations/TestTranslation_3.py | 38 ++- 23 files changed, 348 insertions(+), 160 deletions(-) create mode 100644 src/GeomAPI/GeomAPI_Interface.cpp diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp index eebff3615..c4c4914e5 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp @@ -20,7 +20,7 @@ #include "FeaturesPlugin_BooleanCut.h" -#include +#include #include #include @@ -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 aContextShape = aResCompSolidPtr->shape(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 5400cbd3f..605f9b919 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -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::const_iterator aFRes = aResultFeature->results().cbegin(); + for(; aFRes != aResultFeature->results().cend() && !aOkRes; aFRes++) { + ResultBodyPtr aBody = std::dynamic_pointer_cast(*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; diff --git a/src/FeaturesPlugin/Test/Test1922.py b/src/FeaturesPlugin/Test/Test1922.py index a9224658b..8b1fc660b 100644 --- a/src/FeaturesPlugin/Test/Test1922.py +++ b/src/FeaturesPlugin/Test/Test1922.py @@ -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()) diff --git a/src/FeaturesPlugin/Test/TestBooleanCompSolids.py b/src/FeaturesPlugin/Test/TestBooleanCompSolids.py index aad16ba71..44d44c760 100644 --- a/src/FeaturesPlugin/Test/TestBooleanCompSolids.py +++ b/src/FeaturesPlugin/Test/TestBooleanCompSolids.py @@ -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() diff --git a/src/FeaturesPlugin/Test/TestCompositeFeaturesOnCompSolids.py b/src/FeaturesPlugin/Test/TestCompositeFeaturesOnCompSolids.py index c885ab270..47caabb1d 100644 --- a/src/FeaturesPlugin/Test/TestCompositeFeaturesOnCompSolids.py +++ b/src/FeaturesPlugin/Test/TestCompositeFeaturesOnCompSolids.py @@ -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() diff --git a/src/FeaturesPlugin/Test/TestRemoveSubShapes.py b/src/FeaturesPlugin/Test/TestRemoveSubShapes.py index 9a10cfab5..7926781a6 100644 --- a/src/FeaturesPlugin/Test/TestRemoveSubShapes.py +++ b/src/FeaturesPlugin/Test/TestRemoveSubShapes.py @@ -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 diff --git a/src/FeaturesPlugin/Test/TestUnion.py b/src/FeaturesPlugin/Test/TestUnion.py index fa540f7f2..541ad7344 100644 --- a/src/FeaturesPlugin/Test/TestUnion.py +++ b/src/FeaturesPlugin/Test/TestUnion.py @@ -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 index 000000000..025a4d4f9 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Interface.cpp @@ -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 +// + +#include + +GeomAPI_Interface::GeomAPI_Interface() +{ + +} + +GeomAPI_Interface::~GeomAPI_Interface() +{ + +} + +bool GeomAPI_Interface::empty() const +{ + return myImpl.get() == 0; +} diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index b76998d85..1be7f53ee 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -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(myRef.value()); - } - +ObjectPtr Model_AttributeSelection::contextObject() { + ResultPtr aRes = context(); + if (aRes.get()) + return aRes; + return contextFeature(); +} void Model_AttributeSelection::setObject(const std::shared_ptr& 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(anObj); if (aRes) @@ -944,10 +954,11 @@ void Model_AttributeSelection::selectSubShape( if (aComp && aComp->numberOfSubs()) { std::list allSubs; ModelAPI_Tools::allSubs(aComp, allSubs); - std::list::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::iterator aS = allSubs.begin(); + for(; aS != allSubs.end(); aS++) { + ResultBodyPtr aSub = std::dynamic_pointer_cast(*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 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::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) { ResultPtr aResCont = *aSub; + ResultBodyPtr aResBody = std::dynamic_pointer_cast(aResCont); + // only lower and higher level subs are counted + if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext) + continue; const std::set& aRefs = aResCont->data()->refsToMe(); std::set::const_iterator aRef = aRefs.begin(); for(; !aFindNewContext && aRef != aRefs.end(); aRef++) { diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 357691377..9267748a7 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -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 contextObject(); /// Sets the feature object MODEL_EXPORT virtual void setObject(const std::shared_ptr& theObject); diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index ab2c1dec6..c301d0694 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -129,7 +129,7 @@ static void evolutionToSelectionRec(TDF_Label theLab, const bool theFlag) { void Model_BodyBuilder::evolutionToSelection(const bool theFlag) { std::shared_ptr aData = std::dynamic_pointer_cast(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 std::shared_ptr Model_BodyBuilder::shape() { std::shared_ptr aData = std::dynamic_pointer_cast(data()); - if (aData) { + if (aData && aData->isValid()) { TDF_Label aShapeLab = aData->shapeLab(); Handle(TDF_Reference) aRef; if (aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) { diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 697bfedd9..74f19ec71 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -138,7 +138,7 @@ void Model_Data::setName(const std::string& theName) bool isUserDefined = true; ResultPtr aResult = std::dynamic_pointer_cast(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) { diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index f02468717..4c44977c4 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -576,7 +576,8 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel) if (aSub.get()) { std::shared_ptr aSubData = std::dynamic_pointer_cast( aSub->data()); - if (aSubData->label().Father().IsEqual(aSubLab.ChangeValue())) { + const TDF_Label& aSubLabVal = aSubLab.ChangeValue(); + if (aSubData->label().Father().IsEqual(aSubLabVal)) { aCurrentResult = aSub; break; } diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index e22a0f38e..e168c6c1a 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -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); } } diff --git a/src/Model/Model_SelectionNaming.cpp b/src/Model/Model_SelectionNaming.cpp index be25462d9..1b1c51e9e 100644 --- a/src/Model/Model_SelectionNaming.cpp +++ b/src/Model/Model_SelectionNaming.cpp @@ -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); } diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 22d1f8a54..5343ecfbd 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -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 contextFeature() = 0; + /// Returns the context of the selection : result or feature + virtual std::shared_ptr contextObject() = 0; /// Updates the underlied selection due to the changes in the referenced objects /// \returns false if update is failed diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index bc8089991..ba28f8b90 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -32,8 +32,6 @@ ModelAPI_ResultBody::ModelAPI_ResultBody() ModelAPI_ResultBody::~ModelAPI_ResultBody() { - if (myBuilder) - delete myBuilder; } std::string ModelAPI_ResultBody::groupName() diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 35b7e36da..a1f4ef064 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -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(aParent); + ResultBodyPtr aGrandParent = bodyOwner(aResultParent, true); + if (aGrandParent.get()) + aParent = aGrandParent; + } return std::dynamic_pointer_cast(aParent); } } @@ -598,7 +604,8 @@ void getConcealedResults(const FeaturePtr& theFeature, } } -std::pair getDefaultName(const std::shared_ptr& theResult) +std::pair getDefaultName(const std::shared_ptr& theResult, + const bool theInherited) { typedef std::list< std::pair < std::string, std::list > > ListOfReferences; @@ -619,26 +626,28 @@ std::pair getDefaultName(const std::shared_ptrdata(); 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 diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 0646e23eb..e302d19a0 100755 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -103,10 +103,11 @@ MODELAPI_EXPORT std::shared_ptr 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 - bodyOwner(const std::shared_ptr& theSub); + bodyOwner(const std::shared_ptr& 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 * (means that concealing result has user-defined name). */ MODELAPI_EXPORT std::pair getDefaultName( - const std::shared_ptr& theResult); + const std::shared_ptr& theResult, const bool theInherited = true); } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index d2e98f068..2a60ec774 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -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); } diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index 6219084db..5e642c691 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -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 aResultsList; + ModelAPI_Tools::allSubs(aCompRes, aResultsList); + + std::list::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(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(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(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(theObj); - if (aCompRes.get()) - return new PartSet_CompsolidNode(theObj, this); + //ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(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(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(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(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(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(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(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 diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 921abf09a..e2ba9dfe4 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -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 diff --git a/test.API/SHAPER/Transformations/TestTranslation_3.py b/test.API/SHAPER/Transformations/TestTranslation_3.py index dadc9d953..bf8617124 100644 --- a/test.API/SHAPER/Transformations/TestTranslation_3.py +++ b/test.API/SHAPER/Transformations/TestTranslation_3.py @@ -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.') -- 2.39.2