From 7c14fff8f3b1848b5903a451a8f3e2fc071e7f30 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 25 Aug 2015 12:27:27 +0300 Subject: [PATCH] Make Boolean operation conceal the selected argument: sub-body of compsolid or the whole compsolid. And these arguments are erased in the viewer on "Apply" --- src/Model/Model_ResultCompSolid.cpp | 21 ++++ src/Model/Model_ResultCompSolid.h | 4 + src/ModelAPI/ModelAPI_Result.h | 4 +- .../SketchSolver_ConstraintManager.cpp | 112 +++++++++--------- 4 files changed, 83 insertions(+), 58 deletions(-) diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index 4747d6511..16fda2569 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -108,6 +108,27 @@ bool Model_ResultCompSolid::isConcealed() return false; } +void Model_ResultCompSolid::setIsConcealed(const bool theValue) +{ + ModelAPI_ResultCompSolid::setIsConcealed(theValue); + std::vector >::const_iterator aSubIter = mySubs.cbegin(); + for(; aSubIter != mySubs.cend(); aSubIter++) { + if ((*aSubIter)->isConcealed() != theValue) { + (*aSubIter)->setIsConcealed(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); + } + } + } +} + void Model_ResultCompSolid::updateSubs(const std::shared_ptr& theThisShape) { static Events_Loop* aLoop = Events_Loop::loop(); diff --git a/src/Model/Model_ResultCompSolid.h b/src/Model/Model_ResultCompSolid.h index 152ef4bba..3f228b388 100755 --- a/src/Model/Model_ResultCompSolid.h +++ b/src/Model/Model_ResultCompSolid.h @@ -62,6 +62,10 @@ public: /// 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); + protected: /// Makes a body on the given feature Model_ResultCompSolid(); diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index 97359e5ad..5508f4273 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -37,8 +37,8 @@ class ModelAPI_Result : public ModelAPI_Object /// Returns true if the result is concealed from the data tree (referenced by other objects) MODELAPI_EXPORT virtual bool isConcealed(); - /// Returns true if the result is concealed from the data tree (referenced by other objects) - MODELAPI_EXPORT void setIsConcealed(const bool theValue); + /// Sets the result as concealed in the data tree (referenced by other objects) + MODELAPI_EXPORT virtual void setIsConcealed(const bool theValue); /// Enables/disables the result. The disabled result does not participate in any calculation /// and visualization: like it was removed. But it keeps the general parameters: colors, diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 4034c0b7e..b06db8d96 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -76,81 +76,81 @@ void SketchSolver_ConstraintManager::processEvent( if (myIsComputed) return; if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED) - || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED) - || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) { - std::shared_ptr anUpdateMsg = + || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED) + || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) { + std::shared_ptr anUpdateMsg = std::dynamic_pointer_cast(theMessage); - std::set aFeatures = anUpdateMsg->objects(); + std::set aFeatures = anUpdateMsg->objects(); - // Shows the message has at least one feature applicable for solver - bool hasProperFeature = false; + // Shows the message has at least one feature applicable for solver + bool hasProperFeature = false; - bool isMovedEvt = theMessage->eventID() + bool isMovedEvt = theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED); - if (isMovedEvt) { - std::set::iterator aFeatIter; - for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { - std::shared_ptr aSFeature = + if (isMovedEvt) { + std::set::iterator aFeatIter; + for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { + std::shared_ptr aSFeature = std::dynamic_pointer_cast(*aFeatIter); - if (aSFeature) { - moveEntity(aSFeature); - hasProperFeature = true; + if (aSFeature) { + moveEntity(aSFeature); + hasProperFeature = true; + } } - } - } else { - std::set::iterator aFeatIter; - // iterate sketchers fisrt to create all sketches before (on load may exist several sketches) - for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { - FeaturePtr aFeature = std::dynamic_pointer_cast(*aFeatIter); - if (!aFeature) - continue; - const std::string& aFeatureKind = aFeature->getKind(); - if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) { - std::shared_ptr aSketch = std::dynamic_pointer_cast< + } else { + std::set::iterator aFeatIter; + // iterate sketchers fisrt to create all sketches before (on load may exist several sketches) + for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { + FeaturePtr aFeature = std::dynamic_pointer_cast(*aFeatIter); + if (!aFeature) + continue; + const std::string& aFeatureKind = aFeature->getKind(); + if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) { + std::shared_ptr aSketch = std::dynamic_pointer_cast< ModelAPI_CompositeFeature>(aFeature); - hasProperFeature = changeWorkplane(aSketch) || hasProperFeature; + hasProperFeature = changeWorkplane(aSketch) || hasProperFeature; + } } - } - // then get anything but not the sketch - std::set aComplexConstraints; - // fillet and mirror an tangency constraints will be processed later - for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { - std::shared_ptr aFeature = - std::dynamic_pointer_cast(*aFeatIter); - if (!aFeature) - continue; - if (aFeature->getKind() == SketchPlugin_ConstraintFillet::ID()) - continue; // skip Fillet features - if (SketchSolver_Group::isComplexConstraint(aFeature)) { - aComplexConstraints.insert(aFeature); - continue; + // then get anything but not the sketch + std::set aComplexConstraints; + // fillet and mirror an tangency constraints will be processed later + for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { + std::shared_ptr aFeature = + std::dynamic_pointer_cast(*aFeatIter); + if (!aFeature) + continue; + if (aFeature->getKind() == SketchPlugin_ConstraintFillet::ID()) + continue; // skip Fillet features + if (SketchSolver_Group::isComplexConstraint(aFeature)) { + aComplexConstraints.insert(aFeature); + continue; + } + hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature; + } + // processing remain constraints + aFeatIter = aComplexConstraints.begin(); + for (; aFeatIter != aComplexConstraints.end(); aFeatIter++) { + std::shared_ptr aFeature = + std::dynamic_pointer_cast(*aFeatIter); + if (!aFeature) + continue; + hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature; } - hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature; - } - // processing remain constraints - aFeatIter = aComplexConstraints.begin(); - for (; aFeatIter != aComplexConstraints.end(); aFeatIter++) { - std::shared_ptr aFeature = - std::dynamic_pointer_cast(*aFeatIter); - if (!aFeature) - continue; - hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature; } - } - // Solve the set of constraints - if (hasProperFeature) - resolveConstraints(isMovedEvt); // send update for movement in any case + // Solve the set of constraints + if (hasProperFeature) + resolveConstraints(isMovedEvt); // send update for movement in any case } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aDeleteMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(theMessage); const std::set& aFeatureGroups = aDeleteMsg->groups(); // Find SketchPlugin_Sketch::ID() in groups. The constraint groups should be updated when an object removed from Sketch std::set::const_iterator aFGrIter; for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++) if (aFGrIter->compare(ModelAPI_ResultConstruction::group()) == 0 || - aFGrIter->compare(ModelAPI_Feature::group()) == 0) + aFGrIter->compare(ModelAPI_Feature::group()) == 0) break; if (aFGrIter != aFeatureGroups.end()) { -- 2.39.2