From 25dfb208da4168e8570f0cfefab02b950c9113c4 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 9 Feb 2016 16:40:44 +0300 Subject: [PATCH] 2.17. Improved management of overconstraint situation: Processing added arguments of repaired signal. --- .../PartSet_OverconstraintListener.cpp | 116 ++++++++++++------ src/PartSet/PartSet_OverconstraintListener.h | 18 ++- 2 files changed, 92 insertions(+), 42 deletions(-) diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 5e6aefc74..721c2d54a 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -21,7 +21,7 @@ #include -//#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER +#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop) : myWorkshop(theWorkshop) @@ -40,7 +40,6 @@ void PartSet_OverconstraintListener::getConflictingColor(std::vector& theCo { Quantity_Color aColor = ModuleBase_Tools::color("Visualization", "sketch_overconstraint_color", SKETCH_OVERCONSTRAINT_COLOR); - theColor.push_back(aColor.Red()*255.); theColor.push_back(aColor.Green()*255.); theColor.push_back(aColor.Blue()*255.); @@ -49,70 +48,96 @@ void PartSet_OverconstraintListener::getConflictingColor(std::vector& theCo void PartSet_OverconstraintListener::processEvent( const std::shared_ptr& theMessage) { - #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED); - qDebug(QString("PartSet_OverconstraintListener::processEvent:\n %1").arg(isRepaired ? "REPAIRED" : "FAILED").toStdString().c_str()); + int aCount = 0; + + std::shared_ptr anErrorMsg = + std::dynamic_pointer_cast(theMessage); + QString anInfoStr; + if (anErrorMsg.get()) { + const std::set& aConflictingObjects = anErrorMsg->objects(); + aCount = aConflictingObjects.size(); + anInfoStr = getObjectsInfo(aConflictingObjects); + } + + QString aCurrentInfoStr = getObjectsInfo(myConflictingObjects); + + qDebug(QString("PartSet_OverconstraintListener::processEvent: %1,\nobjects count = %2:%3\ncurrent objects count = %4:%5") + .arg(isRepaired ? "REPAIRED" : "FAILED") + .arg(aCount).arg(anInfoStr).arg(myConflictingObjects.size()).arg(aCurrentInfoStr).toStdString().c_str()); #endif - if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_FAILED) || - theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)) { + if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_FAILED)) { std::shared_ptr anErrorMsg = std::dynamic_pointer_cast(theMessage); bool anUpdated = false; if (anErrorMsg.get()) { const std::set& aConflictingObjects = anErrorMsg->objects(); - anUpdated = updateConflictingObjects(aConflictingObjects); + anUpdated = appendConflictingObjects(aConflictingObjects); + } + else { + // there is a crash in the solver. All objects are invalid + //anUpdated = appendConflictingObjects(std::set()); + } + } + if (theMessage->eventID() == 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(); + anUpdated = repairConflictingObjects(aConflictingObjects); + } + else { + // there is no repaired objects, do nothing } - else - anUpdated = updateConflictingObjects(std::set()); } -} - -bool PartSet_OverconstraintListener::updateConflictingObjects( - const std::set& theConflictingObjects) -{ - std::set::const_iterator anIt, aLast; #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER - anIt = theConflictingObjects.begin(); - aLast = theConflictingObjects.end(); - - QStringList anInfo; - for (; anIt != aLast; ++anIt) { - anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); - } - QString anInfoStr = anInfo.join(";\n"); - qDebug(QString("PartSet_OverconstraintListener::updateConflictingObjects: %1: \n%2").arg(theConflictingObjects.size()) - .arg(anInfoStr).toStdString().c_str()); + aCurrentInfoStr = getObjectsInfo(myConflictingObjects); + qDebug(QString("RESULT: current objects count = %1:%2\n") + .arg(myConflictingObjects.size()).arg(aCurrentInfoStr).toStdString().c_str()); #endif +} - bool isUpdated = false; +bool PartSet_OverconstraintListener::appendConflictingObjects( + const std::set& theConflictingObjects) +{ std::set aModifiedObjects; - // erase error state of absent current objects in the parameter list - for (anIt = myConflictingObjects.begin(), aLast = myConflictingObjects.end() ; anIt != aLast; anIt++) { + // 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 (theConflictingObjects.find(anObject) == theConflictingObjects.end()) { // it is not found - setConflictingObject(anObject, false); + if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found + setConflictingObject(anObject, true); aModifiedObjects.insert(anObject); + myConflictingObjects.insert(anObject); } } + bool isUpdated = !aModifiedObjects.empty(); + if (isUpdated) + redisplayObjects(aModifiedObjects); - // erase absent objects from the internal container - for (anIt = aModifiedObjects.begin(), aLast = aModifiedObjects.end(); anIt != aLast; anIt++) { - myConflictingObjects.erase(*anIt); - } + return isUpdated; +} - // set error state for new objects and append them in the internal map of objects +bool PartSet_OverconstraintListener::repairConflictingObjects( + const std::set& theConflictingObjects) +{ + std::set aModifiedObjects; + // erase error state of absent current objects in the parameter list + std::set::const_iterator anIt, aLast; for (anIt = theConflictingObjects.begin(), aLast = theConflictingObjects.end() ; anIt != aLast; anIt++) { ObjectPtr anObject = *anIt; - if (myConflictingObjects.find(anObject) == myConflictingObjects.end()) { // it is not found - setConflictingObject(anObject, true); + if (theConflictingObjects.find(anObject) != theConflictingObjects.end()) { // it is found + setConflictingObject(anObject, false); + myConflictingObjects.erase(anObject); + aModifiedObjects.insert(anObject); - myConflictingObjects.insert(anObject); } } - isUpdated = !aModifiedObjects.empty(); + bool isUpdated = !aModifiedObjects.empty(); if (isUpdated) redisplayObjects(aModifiedObjects); @@ -154,6 +179,9 @@ void PartSet_OverconstraintListener::redisplayObjects( void PartSet_OverconstraintListener::setConflictingObject(const ObjectPtr& theObject, const bool theConflicting) { + if (!theObject.get() || !theObject->data()->isValid()) + return; + AISObjectPtr anAISObject; GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); @@ -181,3 +209,13 @@ XGUI_Workshop* PartSet_OverconstraintListener::workshop() const return aConnector->workshop(); } +QString PartSet_OverconstraintListener::getObjectsInfo(const std::set& theObjects) +{ + std::set::const_iterator anIt = theObjects.begin(), + aLast = theObjects.end(); + QStringList anInfo; + for (; anIt != aLast; ++anIt) + anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); + + return anInfo.join(";\n"); +} diff --git a/src/PartSet/PartSet_OverconstraintListener.h b/src/PartSet/PartSet_OverconstraintListener.h index fc771a824..772d00987 100755 --- a/src/PartSet/PartSet_OverconstraintListener.h +++ b/src/PartSet/PartSet_OverconstraintListener.h @@ -14,6 +14,8 @@ class ModuleBase_IWorkshop; class XGUI_Workshop; +#include + #include #include @@ -49,10 +51,15 @@ public: virtual void processEvent(const std::shared_ptr& theMessage); protected: - /// Updates the internal container of conflicting object, redisplay necessary objects + /// Append objects to the internal container of conflicting object, redisplay necessary objects /// \param theObjects a list of new conflicting objects /// \return boolean value whether the list differs from the internal list - bool updateConflictingObjects(const std::set& theObjects); + bool appendConflictingObjects(const std::set& theObjects); + + /// Removes objects from internal container of conflicting object, redisplay necessary objects + /// \param theObjects a list of repaired objects + /// \return boolean value whether the list differs from the internal list + bool repairConflictingObjects(const std::set& theObjects); /// Obtains the object custom AIS presentation and change conflicting state if it exists /// \param theObject the object which presentation error state should be changed @@ -64,9 +71,14 @@ protected: void redisplayObjects(const std::set& theObjects); private: - //! Returns workshop + /// Returns workshop XGUI_Workshop* workshop() const; + /// Unite objects in one string information + /// \param theObjects a list of objects + /// \return a string info + static QString getObjectsInfo(const std::set& theObjects); + private: std::set myConflictingObjects; ModuleBase_IWorkshop* myWorkshop; -- 2.39.2