X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OverconstraintListener.cpp;h=b8924b8a27bc59237d8b7a931efaa3dfede4de3a;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=a7480b35a8a1078888d5397ea677861cf6f6a477;hpb=d4b0a5cb916f4eccf4a0bce02e43a54c7a67cb93;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp old mode 100755 new mode 100644 index a7480b35a..b8924b8a2 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2024 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,21 +12,23 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include #include +// Attention: keep the next include here, +// otherwise it causes compilation errors at least on Debian 8 +#include + #include "PartSet_OverconstraintListener.h" #include #include #include -#include "XGUI_CustomPrs.h" #include "XGUI_Displayer.h" #include "XGUI_ModuleConnector.h" #include "XGUI_OperationMgr.h" @@ -37,6 +39,10 @@ #include "SketchPlugin_SketchEntity.h" #include "SketchPlugin_MacroArcReentrantMessage.h" #include "SketchPlugin_Sketch.h" +#include "SketchPlugin_ConstraintHorizontal.h" +#include "SketchPlugin_ConstraintVertical.h" + +#include #include "Events_Loop.h" @@ -46,6 +52,7 @@ #include #include +#include //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER @@ -61,6 +68,7 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks aLoop->registerListener(this, ModelAPI_EventReentrantMessage::eventId()); aLoop->registerListener(this, SketchPlugin_MacroArcReentrantMessage::eventId()); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_REMOVE_CONSTRAINTS)); } void PartSet_OverconstraintListener::setActive(const bool& theActive) @@ -75,8 +83,13 @@ void PartSet_OverconstraintListener::setActive(const bool& theActive) PartSet_Module* aModule = module(); CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); if (aSketch.get()) { - std::string aDOFMessage = aSketch->string(SketchPlugin_Sketch::SOLVER_DOF())->value(); - myIsFullyConstrained = QString(aDOFMessage.c_str()).contains("DoF = 0"); + QString aDOFMessage(aSketch->string(SketchPlugin_Sketch::SOLVER_DOF())->value().c_str()); + if (aDOFMessage.contains('=')) { + // to support old data + aDOFMessage = + aDOFMessage.right(aDOFMessage.length() - aDOFMessage.lastIndexOf('=')).trimmed(); + } + myIsFullyConstrained = (aDOFMessage == "0"); } } } @@ -88,13 +101,11 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, return; FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - std::string aFeatureName = aFeature->data()->name(); if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) { theColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color"); } if (myIsFullyConstrained) { - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); // only entity features has custom color when sketch is fully constrained if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind()) && !PartSet_SketcherMgr::isExternalFeature(aFeature)) { @@ -107,8 +118,7 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, } } -void PartSet_OverconstraintListener::processEvent( - const std::shared_ptr& theMessage) +void PartSet_OverconstraintListener::processEvent(const std::shared_ptr& theMessage) { // #2271 open document: if sketch has confilcting elements, solver sends message with the // elements by opening the document. Sketch is not active, but an internal container should @@ -143,13 +153,12 @@ void PartSet_OverconstraintListener::processEvent( anEventID == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)) { std::shared_ptr anErrorMsg = std::dynamic_pointer_cast(theMessage); - bool anUpdated = false; if (anErrorMsg.get()) { const std::set& aConflictingObjects = anErrorMsg->objects(); if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED)) - anUpdated = appendConflictingObjects(aConflictingObjects); + appendConflictingObjects(aConflictingObjects); else - anUpdated = repairConflictingObjects(aConflictingObjects); + repairConflictingObjects(aConflictingObjects); } } else if (anEventID == Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED) || @@ -196,7 +205,7 @@ void PartSet_OverconstraintListener::processEvent( // This Line's message should not be processed, as the reentrant operation is not for Line // It is not enoght of kind, the name should be used, e.g. restarted Lines on auxiliary // cirlce sometimes causes previous line change, kind the same, but feature line is different - std::string aCurrentFeatureName; + std::wstring aCurrentFeatureName; ModuleBase_Operation* anOperation = XGUI_Tools::workshop(myWorkshop)->operationMgr()->currentOperation(); if (anOperation) { @@ -223,7 +232,35 @@ void PartSet_OverconstraintListener::processEvent( } } } + else if (anEventID == Events_Loop::eventByName(EVENT_REMOVE_CONSTRAINTS)) { + std::shared_ptr aConstraintsMsg = + std::dynamic_pointer_cast(theMessage); + if (aConstraintsMsg.get()) { + myObjectsToRemove = aConstraintsMsg->constraints(); + + std::set::const_iterator anIt = myObjectsToRemove.begin(); + + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + + for (; anIt != myObjectsToRemove.end(); ) + { + ObjectPtr anObject = *anIt; + FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); + std::string aType = aFeature->getKind(); + if ((aType == SketchPlugin_ConstraintHorizontal::ID() || + aType == SketchPlugin_ConstraintVertical::ID()) && + !aModule->sketchReentranceMgr()->isLastAutoConstraint(*anIt)) + anIt = myObjectsToRemove.erase(anIt); + else + anIt++; + } + if (myObjectsToRemove.empty()) + return; + + QTimer::singleShot(5, aModule, SLOT(onRemoveConflictingConstraints())); + } + } #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER aCurrentInfoStr = getObjectsInfo(myConflictingObjects); qDebug(QString("RESULT: current objects count = %1:%2\n") @@ -234,23 +271,43 @@ void PartSet_OverconstraintListener::processEvent( bool PartSet_OverconstraintListener::appendConflictingObjects( const std::set& theConflictingObjects) { - std::set aModifiedObjects; - - // set error state for new objects and append them in the internal map of objects - std::set::const_iterator - anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end(); - for (; anIt != aLast; anIt++) { - ObjectPtr anObject = *anIt; - if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found - aModifiedObjects.insert(anObject); - myConflictingObjects.insert(anObject); + bool isAllowToChange = ModuleBase_Preferences::resourceMgr()->booleanValue(SKETCH_TAB_NAME, + "allow_change_constraint"); + if (isAllowToChange) { + std::set aModifiedObjects; + + // set error state for new objects and append them in the internal map of objects + std::set::const_iterator + anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end(); + + int aCountOfSimilarConstraints = 0; + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found + aModifiedObjects.insert(anObject); + myConflictingObjects.insert(anObject); + } + else + ++aCountOfSimilarConstraints; } - } - bool isUpdated = !aModifiedObjects.empty(); - if (isUpdated) - redisplayObjects(aModifiedObjects); - return isUpdated; + if (theConflictingObjects.size() == aCountOfSimilarConstraints) + return false; + + std::shared_ptr aMessage = + std::shared_ptr( + new ModelAPI_CheckConstraintsMessage( + Events_Loop::eventByName(EVENT_CHECK_CONSTRAINTS))); + aMessage->setConstraints(theConflictingObjects); + Events_Loop::loop()->send(aMessage); + + bool isUpdated = !aModifiedObjects.empty(); + if (isUpdated) + redisplayObjects(aModifiedObjects); + return isUpdated; + } + else + return false; } bool PartSet_OverconstraintListener::repairConflictingObjects( @@ -264,7 +321,6 @@ bool PartSet_OverconstraintListener::repairConflictingObjects( ObjectPtr anObject = *anIt; if (theConflictingObjects.find(anObject) != theConflictingObjects.end()) { // it is found myConflictingObjects.erase(anObject); - aModifiedObjects.insert(anObject); } } @@ -280,14 +336,18 @@ void PartSet_OverconstraintListener::redisplayObjects( { static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_VISUAL_ATTRIBUTES); + static Events_ID EVENT_REDISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); std::set::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); - for (; anIt != aLast; anIt++) - aECreator->sendUpdated(*anIt, EVENT_DISP); - + for (; anIt != aLast; anIt++) { + ObjectPtr aObj = *anIt; + aECreator->sendUpdated(aObj, EVENT_DISP); + aECreator->sendUpdated(aObj, EVENT_REDISP); + } aLoop->flush(EVENT_DISP); + aLoop->flush(EVENT_REDISP); } PartSet_Module* PartSet_OverconstraintListener::module() const