From: mpv Date: Tue, 31 Jul 2018 14:11:05 +0000 (+0300) Subject: Initial implementation of support of any level of hierarchy in Result Bodies. X-Git-Tag: SHAPER_V9_1_0RC1~73^2~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5a82acff74697623112b76b67c0200945a3e9976;p=modules%2Fshaper.git Initial implementation of support of any level of hierarchy in Result Bodies. Removed ResultCompSolid class. Instead ResultBody may have any number of subs, or not. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 9104486c1..99afc6e8d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -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 aContextShape = aResCompSolidPtr->shape(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index f54449b36..9cdf2b7cc 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -21,7 +21,6 @@ #include "FeaturesPlugin_CompositeBoolean.h" #include -#include #include #include @@ -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::iterator anIt = aCompSolidsObjects.begin(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp index 30f922aa8..eab8b03ca 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -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; diff --git a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp index a63ac8af0..75b1d9c09 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -72,14 +71,14 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) } ResultPtr aContext = aShapeAttrSelection->context(); - ResultCompSolidPtr aResultCompSolid = - std::dynamic_pointer_cast(aContext); - if(!aResultCompSolid.get()) { + ResultBodyPtr aResultBody = + std::dynamic_pointer_cast(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; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Union.cpp b/src/FeaturesPlugin/FeaturesPlugin_Union.cpp index 76683a26f..33bd7450b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Union.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Union.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include //================================================================================================= @@ -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 aContextShape = aResCompSolidPtr->shape(); std::map, ListOfShape>::iterator diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp index 41dd47afb..13a0292e0 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp @@ -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(aResult); + ResultBodyPtr aComp = std::dynamic_pointer_cast(aResult); aValid = aComp.get() != NULL; } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 0a85e1ab4..4c558d925 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -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(aContext); - if(aResultCompsolid.get()) { + ResultBodyPtr aResultBody = std::dynamic_pointer_cast(aContext); + if(aResultBody.get()) { continue; } @@ -888,8 +887,8 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr return false; } - ResultCompSolidPtr aResult = - std::dynamic_pointer_cast(aContext); + ResultBodyPtr aResult = + std::dynamic_pointer_cast(aContext); if(!aResult.get()) { continue; } @@ -1036,7 +1035,7 @@ bool FeaturesPlugin_ValidatorBooleanArguments::isValid( std::list::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()) diff --git a/src/GeomValidators/GeomValidators_BodyShapes.cpp b/src/GeomValidators/GeomValidators_BodyShapes.cpp index bcfae3eff..8faa007ec 100644 --- a/src/GeomValidators/GeomValidators_BodyShapes.cpp +++ b/src/GeomValidators/GeomValidators_BodyShapes.cpp @@ -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; } diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 37dfcb274..cacba22ce 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -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 diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index d2456c85e..985bd4b12 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -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(aCont); + ResultBodyPtr aComp = std::dynamic_pointer_cast(aCont); if (aComp && aComp->numberOfSubs()) { - for(int aSubNum = 0; aSubNum < aComp->numberOfSubs(); aSubNum++) { - ResultPtr aSub = aComp->subResult(aSubNum); + 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)) { 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 allRes; + if (aCompContext.get()) + ModelAPI_Tools::allSubs(aCompContext, allRes); + allRes.push_back(aCont); + for(std::list::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) { + ResultPtr aResCont = *aSub; const std::set& aRefs = aResCont->data()->refsToMe(); std::set::const_iterator aRef = aRefs.begin(); for(; !aFindNewContext && aRef != aRefs.end(); aRef++) { @@ -922,20 +924,13 @@ void Model_AttributeSelection::selectSubShape( std::list > aResults; // take all sub-results or one result - const std::list >& aFResults = aRefFeat->results(); - std::list >::const_iterator aRIter = aFResults.begin(); - for (; aRIter != aFResults.cend(); aRIter++) { - // iterate sub-bodies of compsolid - ResultCompSolidPtr aComp = - std::dynamic_pointer_cast(*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 aRefFeatResults; + ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults); + std::list::iterator aRefResIter = aRefFeatResults.begin(); + for(; aRefResIter != aRefFeatResults.end(); aRefResIter++) { + ResultBodyPtr aBody = std::dynamic_pointer_cast(*aRefResIter); + if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs + aResults.push_back(aBody); } std::list >::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 aSelection = value(); - std::shared_ptr 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 aContext = aContextRes->shape(); TopoDS_Shape aMainShape = aContext->impl(); const TopoDS_Shape& aSubShape = aSelection->impl(); // searching for the latest main shape - if (aSelection && !aSelection->isNull() && - aContext && !aContext->isNull()) + if (aSelection && !aSelection->isNull() && aContext && !aContext->isNull()) { std::shared_ptr aDoc = std::dynamic_pointer_cast(context()->document()); @@ -1006,21 +1000,21 @@ int Model_AttributeSelection::Id() void Model_AttributeSelection::setId(int theID) { - const ResultPtr& aContext = context(); std::shared_ptr aSelection; - std::shared_ptr 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 aContext = aContextRes->shape(); - TopoDS_Shape aMainShape = aContextShape->impl(); + TopoDS_Shape aMainShape = aContext->impl(); // searching for the latest main shape - if (theID > 0 && - aContextShape && !aContextShape->isNull()) + if (theID > 0 && aContext && !aContext->isNull()) { std::shared_ptr aDoc = - std::dynamic_pointer_cast(aContext->document()); + std::dynamic_pointer_cast(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 aNewToIterate; aNewToIterate.push_back(theNewContext); - ResultCompSolidPtr aComp = std::dynamic_pointer_cast(theNewContext); + ResultBodyPtr aComp = std::dynamic_pointer_cast(theNewContext); if (aComp.get()) { - for(int a = 0; a < aComp->numberOfSubs(); a++) - aNewToIterate.push_back(aComp->subResult(a, false)); + std::list allNewContextSubs; + ModelAPI_Tools::allSubs(aComp, allNewContextSubs); + std::list::iterator aSub = allNewContextSubs.begin(); + for(; aSub != allNewContextSubs.end(); aSub++) { + ResultBodyPtr aBody = std::dynamic_pointer_cast(*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 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()); } diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index a863d55dd..6a7af0170 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include @@ -139,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); + std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult).first; isUserDefined = aDefaultName != theName; } if (isUserDefined) { diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index ae27c2af2..caba9de13 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -1055,6 +1054,14 @@ int Model_Document::size(const std::string& theGroupID, const bool theAllowFolde return myObjs->size(theGroupID, theAllowFolder); } +std::shared_ptr Model_Document::parent( + const std::shared_ptr theChild) +{ + if(myObjs == 0) // may be on close + return ObjectPtr(); + return myObjs->parent(theChild); +} + std::shared_ptr 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( object(ModelAPI_Feature::group(), a)); if (aFeature.get() && aFeature->data()->isValid()) { - const std::list >& aResList = aFeature->results(); - std::list >::const_iterator aRes = aResList.begin(); - for(; aRes != aResList.end(); aRes++) { + std::list aResults; + ModelAPI_Tools::allResults(aFeature, aResults); + for (std::list::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(*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 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) diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 0f6b32ed6..98c44ea64 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -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 parent( + const std::shared_ptr 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; diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index b4e516cd6..199b249c3 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -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 >& aResults = aFeature->results(); - std::list >::const_iterator aRIter = aResults.cbegin(); - for (; aRIter != aResults.cend(); aRIter++) { - if (isSubResult) { - ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(*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 aSubData = std::dynamic_pointer_cast( - 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(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 aSubData = std::dynamic_pointer_cast( + aSub->data()); + if (aSubData->label().Father().IsEqual(aSubLab.ChangeValue())) { + aCurrentResult = aSub; + break; } } } - } else { - std::shared_ptr aResData = std::dynamic_pointer_cast( - (*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& aResults = aFeature->results(); + std::list >::const_iterator aRIter = aResults.cbegin(); + for(; aRIter != aResults.cend(); aRIter++) { + std::shared_ptr aResData = std::dynamic_pointer_cast((*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 Model_Objects::objectByName( std::list > allObjs = allFeatures(); std::list >::iterator anObjIter = allObjs.begin(); for(; anObjIter != allObjs.end(); anObjIter++) { - const std::list >& aResults = (*anObjIter)->results(); - std::list >::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(*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 allRes; + ModelAPI_Tools::allResults(*anObjIter, allRes); + for(std::list::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 Model_Objects::parent( + const std::shared_ptr theChild) +{ + if (theChild.get()) { + std::shared_ptr aData = std::dynamic_pointer_cast(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& 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(theFeatureData->owner()); - if (aCompSolidRes) { - FeaturePtr anOwner = ModelAPI_Feature::feature(theResult->data()->owner()); + ResultBodyPtr aBodyRes = std::dynamic_pointer_cast(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& aResults = anOwner->results(); - for (std::list::const_iterator anIt = aResults.begin(); - anIt != aResults.end(); ++anIt, ++aCompSolidResultIndex) - if (aCompSolidRes == *anIt) + std::list::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 aName = ModelAPI_Tools::getDefaultName(theResult, theResultIndex); + std::pair aName = ModelAPI_Tools::getDefaultName(theResult); if (aName.second) theParentName = aName.first; return aName.second; @@ -1242,27 +1254,14 @@ std::shared_ptr Model_Objects::createBody( const std::shared_ptr& 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(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 aResult; if (anOldObject.get()) { aResult = std::dynamic_pointer_cast(anOldObject); } if (!aResult.get()) { - // create compsolid anyway; if it is compsolid, it will create sub-bodies internally - if (aResultOwner.get()) { - aResult = std::shared_ptr(new Model_ResultBody); - } else { - aResult = std::shared_ptr(new Model_ResultCompSolid); - } + aResult = std::shared_ptr(new Model_ResultBody); storeResult(theFeatureData, aResult, theIndex); } return aResult; @@ -1790,7 +1789,7 @@ std::shared_ptr 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& 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 aNewP = createPart(theFeature->data(), aResIndex); diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index d6f3d383f..0991cf210 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -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 parent(const std::shared_ptr theChild); + //! Returns all (and disabled) results of the given type. //! Not fast method (iterates all features). void allResults(const std::string& theGroupID, std::list& theResults); diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 731a520de..2a82cc445 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -19,21 +19,90 @@ // #include + +#include +#include #include -#include -#include -#include +#include +#include #include -// DEB -//#include -//#include -//#define DEB_IMPORT 1 +#include +#include + +#include +#include -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()); // erase sub-results + delete myBuilder; +} + +void Model_ResultBody::loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS, + std::shared_ptr 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::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 aWholeIn = theShapeIn->impl(); + for(TopExp_Explorer anExp(aWholeIn, aSubShape.ShapeType()); anExp.More(); anExp.Next()) { + ListOfShape aHistory; + std::shared_ptr aSubIn(new GeomAPI_Shape()); + aSubIn->setImpl((new TopoDS_Shape(anExp.Current()))); + theMS->modified(aSubIn, aHistory); + std::list >::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::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 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& 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(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(data()->owner()); + std::shared_ptr aParent = std::dynamic_pointer_cast( + 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::const_iterator aSubIter = mySubs.cbegin(); + for (; aSubIter != mySubs.cend(); aSubIter++) { + std::dynamic_pointer_cast(*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::const_iterator aSubIter = mySubs.cbegin(); + for (; aSubIter != mySubs.cend(); aSubIter++) { + std::dynamic_pointer_cast(*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::const_iterator aSubIter = mySubs.cbegin(); + for (; aSubIter != mySubs.cend(); aSubIter++) { + std::dynamic_pointer_cast(*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& 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(); + if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID || + aThisShape.ShapeType() == TopAbs_COMPOUND)) { + bool aWasEmpty = mySubs.empty(); + Model_Objects* anObjects = std::dynamic_pointer_cast(document())->objects(); + unsigned int aSubIndex = 0; + TopoDS_Iterator aShapesIter(aThisShape); + for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) { + std::shared_ptr 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(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(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& theShape) +{ + if (myBuilder->isLatestEqual(theShape)) + return true; + // also check that it is asked for sub-elements + std::vector::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_ResultBody.h b/src/Model/Model_ResultBody.h index 02f55cbdc..ad5f1c531 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -23,55 +23,80 @@ #include "Model.h" #include -//#include -//#include -//#include - -//class TNaming_Builder; +#include +#include /**\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 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 mySubs; + /// Also keep map of result to index in mySubs to facilitate speed of access from OB + std::map 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 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 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& 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& 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 index 8cde4b9c4..000000000 --- a/src/Model/Model_ResultCompSolid.cpp +++ /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 -// - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -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()); // erase sub-results -} - -void Model_ResultCompSolid::store(const std::shared_ptr& theShape, - const bool theIsStoreSameShapes) -{ - ModelAPI_ResultCompSolid::store(theShape, theIsStoreSameShapes); - updateSubs(theShape); -} - -void Model_ResultCompSolid::storeGenerated(const std::shared_ptr& theFromShape, - const std::shared_ptr& theToShape) -{ - ModelAPI_ResultCompSolid::storeGenerated(theFromShape, theToShape); - updateSubs(theToShape); -} - -void Model_ResultCompSolid::storeModified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag) -{ - ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag); - updateSubs(theNewShape); -} - -void Model_ResultCompSolid::loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS, - std::shared_ptr 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 >::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 aWholeIn = theShapeIn->impl(); - for(TopExp_Explorer anExp(aWholeIn, aSubShape.ShapeType()); anExp.More(); anExp.Next()) { - ListOfShape aHistory; - std::shared_ptr aSubIn(new GeomAPI_Shape()); - aSubIn->setImpl((new TopoDS_Shape(anExp.Current()))); - theMS->modified(aSubIn, aHistory); - std::list >::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 Model_ResultCompSolid::subResult(const int theIndex, - bool forTree) const -{ - return mySubs.at(theIndex); -} - -bool Model_ResultCompSolid::isSub(ObjectPtr theObject, int& theIndex) const -{ - std::map::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 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 >::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 >::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 >::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& 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(); - if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID || - aThisShape.ShapeType() == TopAbs_COMPOUND)) { - bool aWasEmpty = mySubs.empty(); - Model_Objects* anObjects = std::dynamic_pointer_cast(document())->objects(); - unsigned int aSubIndex = 0; - TopoDS_Iterator aShapesIter(aThisShape); - for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) { - std::shared_ptr 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& theShape) -{ - if (myBuilder->isLatestEqual(theShape)) - return true; - // also check that it is asked for sub-elements - std::vector >::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 index c748aeeae..000000000 --- a/src/Model/Model_ResultCompSolid.h +++ /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 -// - -#ifndef Model_ResultCompSolid_H_ -#define Model_ResultCompSolid_H_ - -#include "Model.h" -#include -#include -#include - -/**\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 > mySubs; - /// Also keep map of result to index in mySubs to facilitate speed of access from OB - std::map 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& theShape, - const bool theIsStoreSameShapes = true); - - /// Stores the generated shape. Creates sub-results for compsolid. - MODEL_EXPORT virtual void storeGenerated(const std::shared_ptr& theFromShape, - const std::shared_ptr& theToShape); - - /// Stores the modified shape. Creates sub-results for compsolid. - MODEL_EXPORT virtual void storeModified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag = 0); - - /// load and orient modified shapes for sub-objects - MODEL_EXPORT virtual void loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS, - std::shared_ptr 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 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 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& 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& theThisShape); - - friend class Model_Objects; -}; - -#endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index fbcb4a777..9fde2d5ab 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -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 diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 61403edf6..6199cb72a 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -154,7 +154,6 @@ %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 std::shared_ptr shared_ptr_cast(std::shared_ptr %template(modelAPI_ResultParameter) shared_ptr_cast; %template(modelAPI_ResultGroup) shared_ptr_cast; %template(modelAPI_ResultField) shared_ptr_cast; -%template(modelAPI_ResultCompSolid) shared_ptr_cast; // Attribute casts %template(modelAPI_AttributeDocRef) shared_ptr_cast; diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index e234aefe5..be23056ae 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -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 parent( + const std::shared_ptr 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 diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index 4025d17b7..bc8089991 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -19,12 +19,13 @@ // #include "ModelAPI_ResultBody.h" + #include #include #include 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& 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& 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& theFromShape, - const std::shared_ptr& theToShape) + const std::shared_ptr& theToShape) { myBuilder->storeGenerated(theFromShape, theToShape); myConnect = ConnectionNotComputed; @@ -62,11 +65,13 @@ void ModelAPI_ResultBody::storeGenerated(const std::shared_ptr& 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& theOldShape, - const std::shared_ptr& theNewShape, - const int theDecomposeSolidsTag) + const std::shared_ptr& theNewShape, + const int theDecomposeSolidsTag) { myBuilder->storeModified(theOldShape, theNewShape, theDecomposeSolidsTag); myConnect = ConnectionNotComputed; @@ -75,6 +80,8 @@ void ModelAPI_ResultBody::storeModified(const std::shared_ptr& 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& theShape) @@ -94,74 +101,74 @@ std::shared_ptr ModelAPI_ResultBody::shape() } void ModelAPI_ResultBody::generated(const std::shared_ptr& 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& theOldShape, - const std::shared_ptr& theNewShape, const std::string& theName, - const int theTag) + const std::shared_ptr& theNewShape, const std::string& theName, + const int theTag) { myBuilder->generated(theOldShape, theNewShape, theName, theTag); } void ModelAPI_ResultBody::modified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const std::string& theName, - const int theTag) + const std::shared_ptr& theNewShape, const std::string& theName, + const int theTag) { myBuilder->modified(theOldShape, theNewShape, theName, theTag); } void ModelAPI_ResultBody::deleted( - const std::shared_ptr& theOldShape, const int theTag) + const std::shared_ptr& theOldShape, const int theTag) { myBuilder->deleted(theOldShape, theTag); } -void ModelAPI_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS, - std::shared_ptr theShapeIn, - const int theKindOfShape, - const int theTag) +void ModelAPI_ResultBody::loadDeletedShapes(GeomAlgoAPI_MakeShape* theMS, + std::shared_ptr theShapeIn, + const int theKindOfShape, + const int theTag) { myBuilder->loadDeletedShapes(theMS, theShapeIn, theKindOfShape, theTag); } -void ModelAPI_ResultBody::loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS, - std::shared_ptr 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 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 theShapeIn, const int theKindOfShape, - const int theTag, const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes) +void ModelAPI_ResultBody::loadAndOrientGeneratedShapes(GeomAlgoAPI_MakeShape* theMS, + std::shared_ptr 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 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 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 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); +} diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 98a4b6a29..0ffb2422a 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -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 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& 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& theFromShape, @@ -119,19 +137,20 @@ public: const std::shared_ptr& theOldShape, const int theTag = 1); /// load deleted shapes - MODELAPI_EXPORT virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS, - std::shared_ptr theShapeIn, - const int theKindOfShape, - const int theTag); + MODELAPI_EXPORT virtual void loadDeletedShapes(GeomAlgoAPI_MakeShape* theMS, + std::shared_ptr 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 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 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 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& theThisShape) = 0; }; //! Pointer on feature object diff --git a/src/ModelAPI/ModelAPI_ResultCompSolid.cpp b/src/ModelAPI/ModelAPI_ResultCompSolid.cpp deleted file mode 100755 index e1fa26332..000000000 --- a/src/ModelAPI/ModelAPI_ResultCompSolid.cpp +++ /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 -// - -#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 index 70abc72d0..000000000 --- a/src/ModelAPI/ModelAPI_ResultCompSolid.h +++ /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 -// - -#ifndef ModelAPI_ResultCompSolid_H_ -#define ModelAPI_ResultCompSolid_H_ - -#include "ModelAPI_Result.h" -#include "ModelAPI_ResultBody.h" -#include - -/**\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 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 ResultCompSolidPtr; - -#endif diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index b656c3fb7..35b7e36da 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -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(theSub); - if (aBody.get()) { - FeaturePtr aFeatureOwner = aBody->document()->feature(aBody); - if (aFeatureOwner.get()) { - std::list >::const_iterator aResIter = - aFeatureOwner->results().cbegin(); - for(; aResIter != aFeatureOwner->results().cend(); aResIter++) { - ResultCompSolidPtr aComp = std::dynamic_pointer_cast(*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(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(theSub); - if (aBody.get()) { - FeaturePtr aFeatureOwner = aBody->document()->feature(aBody); - if (aFeatureOwner.get()) { - std::list >::const_iterator aResIter = - aFeatureOwner->results().cbegin(); - for(; aResIter != aFeatureOwner->results().cend(); aResIter++) { - ResultCompSolidPtr aComp = std::dynamic_pointer_cast(*aResIter); - if (aComp && aComp->isSub(aBody, anIndex)) - return anIndex; - } - } + ResultBodyPtr aParent = bodyOwner(theSub); + if (aParent.get()) { + ResultBodyPtr aBody = std::dynamic_pointer_cast(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(theResult); + ResultBodyPtr aCompSolid = std::dynamic_pointer_cast(theResult); return aCompSolid.get() && aCompSolid->numberOfSubs() > 0; } +void allSubs(const ResultBodyPtr& theResult, std::list& theResults) { + // iterate sub-bodies of compsolid + ResultBodyPtr aComp = std::dynamic_pointer_cast(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& theResults) { if (!theFeature.get()) // safety: for empty feature no results return; const std::list >& aResults = theFeature->results(); - std::list >::const_iterator aRIter = aResults.begin(); + std::list::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(*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(*aRIter); + allSubs(aResult, theResults); } } @@ -606,33 +598,24 @@ void getConcealedResults(const FeaturePtr& theFeature, } } -std::pair getDefaultName( - const std::shared_ptr& theResult, - const int theResultIndex) +std::pair getDefaultName(const std::shared_ptr& theResult) { typedef std::list< std::pair < std::string, std::list > > 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& aResults = anOwner->results(); - for (std::list::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(aDefaultName.str(), false); } + FeaturePtr anOwner = ModelAPI_Feature::feature(theResult->data()->owner()); DataPtr aData = anOwner->data(); ListOfReferences aReferences; @@ -658,6 +641,15 @@ std::pair getDefaultName( break; } } + // get the result number in the feature + int anIndexInOwner = 0; + const std::list& anOwnerResults = anOwner->results(); + std::list::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 getDefaultName( std::map aNbRefToObject; // search the object by result index std::list::const_iterator anObjIt = aFoundRef->second.begin(); - int aResultIndex = theResultIndex; + int aResultIndex = anIndexInOwner; while (--aResultIndex >= 0) { ResultPtr aCurRes = std::dynamic_pointer_cast(*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 getDefaultName( if ((*anObjIt)->groupName() == ModelAPI_ResultBody::group()) { // check the result is part of CompSolid ResultPtr anObjRes = std::dynamic_pointer_cast(*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 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(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& aResults = anOwner->results(); - for (std::list::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 diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 907cc7b97..0646e23eb 100755 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -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 compositeOwner( const std::shared_ptr& 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 compSolidOwner( - const std::shared_ptr& theSub); +MODELAPI_EXPORT std::shared_ptr + bodyOwner(const std::shared_ptr& 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& theSub); +MODELAPI_EXPORT int bodyIndex(const std::shared_ptr& 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& theSu */ MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr& theResult); +/*! +* collects recursively all subs of the given result +*/ +MODELAPI_EXPORT void allSubs(const std::shared_ptr& theResult, + std::list >& 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& theFeature, std::list >& 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 getDefaultName( - const std::shared_ptr& 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& theResult); + const std::shared_ptr& theResult); } #endif diff --git a/src/ModelAPI/ModelAPI_swig.h b/src/ModelAPI/ModelAPI_swig.h index e9d740ce0..320d3771a 100644 --- a/src/ModelAPI/ModelAPI_swig.h +++ b/src/ModelAPI/ModelAPI_swig.h @@ -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 diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 985e6761e..5142efc31 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include #include @@ -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& aResults = theFeature->results(); - std::list::const_iterator aResIt = aResults.begin(); - for (int i = 0; aResIt != aResults.end(); ++aResIt, ++i) { - std::pair aName = ModelAPI_Tools::getDefaultName(*aResIt, i); + std::list allRes; + ModelAPI_Tools::allResults(theFeature, allRes); + for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + std::pair 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(*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 aResultsWithNameOrColor; - const std::list& aResults = theEntity->results(); - std::list::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(*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 allRes; + ModelAPI_Tools::allResults(theEntity, allRes); + for(std::list::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 aResults = aFeature->results(); - for(std::list::const_iterator - anIt = aResults.cbegin(); anIt != aResults.cend(); ++anIt, ++anIndex) { - if(theResult->isSame(*anIt)) { - break; - } - - ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast(*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 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::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; } diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index ca9422c18..c87b99fe9 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -25,7 +25,8 @@ #include #include #include -#include +#include + //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- @@ -181,12 +182,11 @@ int ModelHighAPI_Selection::numberOfSubs() const if (myVariantType != VT_ResultSubShapePair) return 0; - ResultCompSolidPtr aCompSolid = - std::dynamic_pointer_cast(myResultSubShapePair.first); - if (!aCompSolid) + ResultBodyPtr aBody = std::dynamic_pointer_cast(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(myResultSubShapePair.first); - if (!aCompSolid) + ResultBodyPtr aBody = std::dynamic_pointer_cast(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()); } diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 1646edc0d..cf141d592 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #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(); diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 73d877e8d..996f4b181 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -45,7 +45,6 @@ #include #include -#include #include #include #include diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index e60685b0c..4d8b47998 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -415,7 +415,7 @@ void ModuleBase_WidgetValidated::filterPresentations(QList& theValues) { - std::set aCompSolids; + std::set aCompSolids; QList aValidatedValues; // Collect compsolids. @@ -423,9 +423,9 @@ void ModuleBase_WidgetValidated::filterCompSolids(QList for (; anIt != aLast; anIt++) { const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt; ObjectPtr anObject = aViewerPrs->object(); - ResultCompSolidPtr aResultCompSolid = - std::dynamic_pointer_cast(anObject); - if(aResultCompSolid.get()) { + ResultBodyPtr aResultCompSolid = + std::dynamic_pointer_cast(anObject); + if(aResultCompSolid.get() && aResultCompSolid->numberOfSubs() > 0) { aCompSolids.insert(aResultCompSolid); } } @@ -436,7 +436,7 @@ void ModuleBase_WidgetValidated::filterCompSolids(QList const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt; ObjectPtr anObject = aViewerPrs->object(); ResultPtr aResult = std::dynamic_pointer_cast(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; diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index 1781e96ae..445c4ad8c 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include @@ -189,12 +189,12 @@ void PartSet_OperationPrs::addValue(const ObjectPtr& theObject, const GeomShapeP if (theObject.get()) { ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (aResult.get()) { - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(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(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); diff --git a/src/PartSet/PartSet_ResultSketchPrs.cpp b/src/PartSet/PartSet_ResultSketchPrs.cpp index 7e62e4b9f..eec581b67 100755 --- a/src/PartSet/PartSet_ResultSketchPrs.cpp +++ b/src/PartSet/PartSet_ResultSketchPrs.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -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); } diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index 574e89ad3..6219084db 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -157,7 +157,7 @@ PartSet_ObjectNode::VisibilityState PartSet_ObjectNode::visibilityState() const ResultPtr aResObj = std::dynamic_pointer_cast(myObject); if (aResObj.get()) { ModuleBase_IWorkshop* aWork = workshop(); - ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(aResObj); + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(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(theObj); + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(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(myObject); + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(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(myObject); + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(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(myObject); + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(myObject); int aNb = aCompRes->numberOfSubs(true); ModuleBase_ITreeNode* aNode; // Delete extra objects diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 49f89d9c0..32fea8398 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include @@ -558,7 +558,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute for(int i = 0; i < aCurSelList->size(); i++) { std::shared_ptr aCurSel = aCurSelList->value(i); ResultPtr aCurSelContext = aCurSel->context(); - ResultCompSolidPtr aCurSelCompSolidPtr = ModelAPI_Tools::compSolidOwner(aCurSelContext); + ResultBodyPtr aCurSelCompSolidPtr = ModelAPI_Tools::bodyOwner(aCurSelContext); std::shared_ptr 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 aRefSel = aRefSelList->value(j); ResultPtr aRefSelContext = aRefSel->context(); - ResultCompSolidPtr aRefSelCompSolidPtr = - ModelAPI_Tools::compSolidOwner(aRefSelContext); + ResultBodyPtr aRefSelCompSolidPtr = + ModelAPI_Tools::bodyOwner(aRefSelContext); std::shared_ptr aRefSelCompSolid; if(aRefSelCompSolidPtr.get()) { aRefSelCompSolid = aRefSelCompSolidPtr->shape(); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 9df154d64..5c3654aca 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include @@ -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(aResult); + if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) { + ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast(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(aResult); + ResultBodyPtr aCompSolid = std::dynamic_pointer_cast(aResult); if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) { aAISObj = getAISObject(aCompSolid->subResult(0)); } diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index ab86347b5..ff78af48c 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index ed54a60a2..b3815aa53 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -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(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())) { diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index bece087dc..405c1979e 100755 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -38,7 +38,8 @@ #include #include #include -#include +#include +#include #include #include @@ -107,22 +108,11 @@ void XGUI_SelectionMgr::onObjectBrowserSelection() if (aObject.get()) { aFeature = std::dynamic_pointer_cast(aObject); if (aFeature.get()) { - const std::list> aResList = aFeature->results(); - ResultPtr aResult; - ResultCompSolidPtr aCompSolid; - std::list::const_iterator aIt; - for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { - aResult = (*aIt); + std::list allRes; + ModelAPI_Tools::allResults(aFeature, allRes); + for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { aSelectedPrs.append(std::shared_ptr( - new ModuleBase_ViewerPrs(aResult, GeomShapePtr(), NULL))); - aCompSolid = std::dynamic_pointer_cast(aResult); - if (aCompSolid.get()) { - for (int i = 0; i < aCompSolid->numberOfSubs(); i++) { - ResultBodyPtr aResult = aCompSolid->subResult(i); - aSelectedPrs.append(std::shared_ptr( - new ModuleBase_ViewerPrs(aResult, aResult->shape(), NULL))); - } - } + new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL))); } } } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 9fe73219f..6b079cdc3 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -72,7 +72,6 @@ #include #include #include -#include #include #include #include @@ -1636,18 +1635,20 @@ bool XGUI_Workshop::prepareForDisplay(const std::set& theObjects) con for (std::set::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) { ObjectPtr anObject = *anObjectsIt; - ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast(anObject); + ResultBodyPtr aCompRes = std::dynamic_pointer_cast(anObject); if (aCompRes.get()) { - if (aCompRes->numberOfSubs(true) == 0) + std::list 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::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + ResultBodyPtr aBody = std::dynamic_pointer_cast(*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(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(theObject); + if (aCompRes.get() != NULL) { // change colors for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aCompRes, allRes); + std::list::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(anObj); if (aResult.get() != NULL) { - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(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(aResult); + if (aBodyResult.get() != NULL) { // change colors for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + for(std::list::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(anObj); if (aResult.get() != NULL) { - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(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(aResult); + if (aBodyResult.get() != NULL) { // change property for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + for(std::list::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(anObj); if (aResult.get() != NULL) { - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(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(aResult); + if (aBodyResult.get() != NULL) { // change property for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + for(std::list::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(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(anObj); + if (aBodyResult.get() != NULL) { // change display mode for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false); } } } diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index 4b3546211..f7720512d 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include