X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OverconstraintListener.cpp;h=52d84913e823221a05a3b20edcace7f9c4041780;hb=33c5fdce3cd63dd95a738439a0399dd982abcd73;hp=e03a667f9aac2ee4eb9194b68bf7de3747d14939;hpb=72a191eb97b744b33d735c8d14f2693dbf3b13c2;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index e03a667f9..52d84913e 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -11,6 +11,7 @@ #include "XGUI_Displayer.h" #include "SketcherPrs_SymbolPrs.h" +#include "SketchPlugin_SketchEntity.h" #include "Events_Loop.h" @@ -20,7 +21,7 @@ #include -#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER +//#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop) : myWorkshop(theWorkshop) @@ -37,8 +38,8 @@ bool PartSet_OverconstraintListener::isConflictingObject(const ObjectPtr& theObj void PartSet_OverconstraintListener::getConflictingColor(std::vector& theColor) { - Quantity_Color aColor = Quantity_Color(Quantity_NameOfColor::Quantity_NOC_RED); - + 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.); @@ -47,80 +48,97 @@ 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); + 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); + } - /* - anIt = theConflictingObjects.begin(); - aLast = theConflictingObjects.end(); + QString aCurrentInfoStr = getObjectsInfo(myConflictingObjects); - QStringList anInfo; - for (; anIt != aLast; ++anIt) { - anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); - } - QString anInfoStr = anInfo.join(";\n");*/ - bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED); - qDebug(QString("PartSet_OverconstraintListener::processEvent:\n %1").arg(isRepaired ? "REPAIRED" : "FAILED").toStdString().c_str()); + 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++) { + std::vector aColor; + getConflictingColor(aColor); + + // 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 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 + myConflictingObjects.erase(anObject); + aModifiedObjects.insert(anObject); - myConflictingObjects.insert(anObject); } } - isUpdated = !aModifiedObjects.empty(); + bool isUpdated = !aModifiedObjects.empty(); if (isUpdated) redisplayObjects(aModifiedObjects); @@ -130,62 +148,16 @@ bool PartSet_OverconstraintListener::updateConflictingObjects( void PartSet_OverconstraintListener::redisplayObjects( const std::set& theObjects) { -/*static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_UPDATED); + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID EVENT_DISP = 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++) { + for (; anIt != aLast; anIt++) aECreator->sendUpdated(*anIt, EVENT_DISP); - //#ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER - // QString anInfoStr = ModuleBase_Tools::objectInfo(*anIt); - // qDebug(QString("PartSet_OverconstraintListener::SEND UPDATED: %1").arg(anInfoStr).toStdString().c_str()); - //#endif - } - aLoop->flush(EVENT_DISP);*/ - - XGUI_Displayer* aDisplayer = workshop()->displayer(); - //QObjectPtrList aObjects = aDisplayer->displayedObjects(); - bool aHidden; - std::set::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); - for (; anIt != aLast; anIt++) { - ObjectPtr anObject = *anIt; - //foreach(ObjectPtr aObj, aObjects) { - //TODO: replace by redisplay event. - aHidden = !anObject->data() || !anObject->data()->isValid() || - anObject->isDisabled() || (!anObject->isDisplayed()); - if (!aHidden) - aDisplayer->redisplay(anObject, false); - } - aDisplayer->updateViewer(); -} - -void PartSet_OverconstraintListener::setConflictingObject(const ObjectPtr& theObject, - const bool theConflicting) -{ - return; - - AISObjectPtr anAISObject; - GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); - - if (aPrs.get() != NULL) { - XGUI_Workshop* aWorkshop = workshop(); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - - anAISObject = aPrs->getAISObject(aDisplayer->getAISObject(theObject)); - if (anAISObject.get()) { - Handle(AIS_InteractiveObject) anAISIO = anAISObject->impl(); - if (!anAISIO.IsNull()) { - if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) { - Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO); - //if (!aPrs.IsNull()) - // aPrs->setConflictingConstraint(theConflicting); - } - } - } - } + aLoop->flush(EVENT_DISP); } XGUI_Workshop* PartSet_OverconstraintListener::workshop() const @@ -194,3 +166,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"); +}