X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OverconstraintListener.cpp;fp=src%2FPartSet%2FPartSet_OverconstraintListener.cpp;h=5db78193f6a92f367f127386aa3415f9668404ea;hb=536461be8f9286797d416753e6bf137ea4d97f1c;hp=656593d9b5348f6c29fc554627f6d406c2002872;hpb=b75fbaee34f661f219f901aa89f72d1d2e906425;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 656593d9b..5db78193f 100644 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -20,6 +20,10 @@ #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 @@ -38,6 +42,8 @@ #include "SketchPlugin_ConstraintHorizontal.h" #include "SketchPlugin_ConstraintVertical.h" +#include + #include "Events_Loop.h" #include @@ -62,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) @@ -225,7 +232,34 @@ void PartSet_OverconstraintListener::processEvent(const std::shared_ptr aConstraintsMsg = + std::dynamic_pointer_cast(theMessage); + if (aConstraintsMsg.get()) { + myObjectsToRemove = aConstraintsMsg->constraints(); + + std::set::const_iterator + anIt = myObjectsToRemove.begin(), aLast = myObjectsToRemove.end(); + + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + + for (; anIt != aLast; anIt++) + { + 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)) + myObjectsToRemove.erase(*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") @@ -236,40 +270,43 @@ void PartSet_OverconstraintListener::processEvent(const std::shared_ptr& 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(); - FeaturePtr aFeature; - bool isHVConstraint = false; - for (; anIt != aLast; anIt++) { - ObjectPtr anObject = *anIt; - if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found - aModifiedObjects.insert(anObject); - myConflictingObjects.insert(anObject); - } - if (!isHVConstraint) { - aFeature = std::dynamic_pointer_cast(anObject); - if (aFeature) { - std::string aType = aFeature->getKind(); - isHVConstraint = (aType == SketchPlugin_ConstraintHorizontal::ID()) || - (aType == SketchPlugin_ConstraintVertical::ID()); + 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); - // If the conflicting object is an automatic constraint caused the conflict - // then it has to be deleted - if (isHVConstraint) { - PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - QTimer::singleShot(5, aModule, SLOT(onConflictingConstraints())); - } + if (theConflictingObjects.size() == aCountOfSimilarConstraints) + return false; - return isUpdated; + 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(