From: nds Date: Mon, 3 Apr 2017 12:04:31 +0000 (+0300) Subject: Issue #2029: Change the color of the Sketch when fully constrained. X-Git-Tag: V_2.7.0~91 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=21761d34d2e6c32fb4c9d57628bee7bf15b2db65;p=modules%2Fshaper.git Issue #2029: Change the color of the Sketch when fully constrained. Case: create two sketches, 2nd is fully defined, Edit 1st sketch. Result was that it was in green. --- diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 768dff3c7..1eff37835 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -5,6 +5,7 @@ // Author: Vitaly SMETANNIKOV #include +#include #include "PartSet_OverconstraintListener.h" #include @@ -19,6 +20,7 @@ #include "SketcherPrs_SymbolPrs.h" #include "SketchPlugin_SketchEntity.h" #include "SketchPlugin_MacroArcReentrantMessage.h" +#include "SketchPlugin_Sketch.h" #include "Events_Loop.h" @@ -32,7 +34,7 @@ //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop) -: myWorkshop(theWorkshop), myIsFullyConstrained(false) +: myWorkshop(theWorkshop), myIsActive(false), myIsFullyConstrained(false) { Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); @@ -45,9 +47,30 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks aLoop->registerListener(this, SketchPlugin_MacroArcReentrantMessage::eventId()); } +void PartSet_OverconstraintListener::setActive(const bool& theActive) +{ + if (myIsActive == theActive) + return; + + myIsActive = theActive; + myIsFullyConstrained = false; /// returned to default state, no custom color for it + + if (myIsActive) { + 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"); + } + } +} + void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, std::vector& theColor) { + if (!myIsActive) + return; + if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) { theColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color"); } @@ -55,10 +78,10 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, 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_Module* aModule = dynamic_cast(myWorkshop->module()); - CompositeFeaturePtr aCompositeFeature = aModule->sketchMgr()->activeSketch(); + PartSet_Module* aModule = module(); + CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); // the given object is sub feature of the current sketch(created or edited) - if (ModelAPI_Tools::compositeOwner(aFeature) == aCompositeFeature) + if (ModelAPI_Tools::compositeOwner(aFeature) == aSketch) theColor = Config_PropManager::color("Visualization", "sketch_fully_constrained_color"); } } @@ -67,6 +90,9 @@ void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, void PartSet_OverconstraintListener::processEvent( const std::shared_ptr& theMessage) { + if (!myIsActive) + return; + #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED); int aCount = 0; @@ -199,10 +225,9 @@ void PartSet_OverconstraintListener::redisplayObjects( aLoop->flush(EVENT_DISP); } -XGUI_Workshop* PartSet_OverconstraintListener::workshop() const +PartSet_Module* PartSet_OverconstraintListener::module() const { - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - return aConnector->workshop(); + return dynamic_cast(myWorkshop->module()); } #ifdef _DEBUG diff --git a/src/PartSet/PartSet_OverconstraintListener.h b/src/PartSet/PartSet_OverconstraintListener.h index 9ce9a4e4c..0721d41d7 100755 --- a/src/PartSet/PartSet_OverconstraintListener.h +++ b/src/PartSet/PartSet_OverconstraintListener.h @@ -12,7 +12,7 @@ #include class ModuleBase_IWorkshop; -class XGUI_Workshop; +class PartSet_Module; #include @@ -33,10 +33,9 @@ public: virtual ~PartSet_OverconstraintListener() {}; - // Set erroneous color for the presentation of object if the object is in the conflicting list - // \param theObject an object to be settled - // \param theUpdateViewer a boolean state whether the current viewer should be updated - //bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer); + /// If active state is changed, update fully defined state and sketch sub-entities color + /// \param theActive a state + void setActive(const bool& theActive); /// Returns true if the object belongs to internal container of conflicting objects /// \param theObject an object to be checked @@ -63,8 +62,8 @@ protected: void redisplayObjects(const std::set& theObjects); private: - /// Returns workshop - XGUI_Workshop* workshop() const; + /// Returns module + PartSet_Module* module() const; #ifdef _DEBUG /// Unite objects in one string information @@ -74,8 +73,9 @@ private: #endif private: - std::set myConflictingObjects; ModuleBase_IWorkshop* myWorkshop; + bool myIsActive; /// state if sketch is active + std::set myConflictingObjects; bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0 }; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 05378d4a5..a63586cef 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -905,6 +905,9 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) } } + // update state of overconstraint listener should be done before sketch features/results + // display (as the display will ask custom color from the listener) + myModule->overconstraintListener()->setActive(true); // Display sketcher objects QStringList anInfo; Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); @@ -1018,6 +1021,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) Events_Loop::loop()->flush(aDispEvent); } + myModule->overconstraintListener()->setActive(false); // restore the module selection modes, which were changed on startSketch aConnector->activateModuleSelectionModes(); } diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index fb82f2cde..05840ba95 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -250,6 +250,8 @@ void SketchSolver_Group::computeDoF() { std::ostringstream aDoFMsg; int aDoF = mySketchSolver->dof(); + /// "DoF = 0" content of string value is used in PartSet by Sketch edit + /// If it is changed, it should be corrected also there if (aDoF == 0) aDoFMsg << "Sketch is fully fixed (DoF = 0)"; else