From: nds Date: Thu, 30 Mar 2017 06:02:34 +0000 (+0300) Subject: Issue #2029 Change the color of the Sketch when fully constrained X-Git-Tag: V_2.7.0~136 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=791a0ecc4adf1672feadb268205ae23b82bf1b95;p=modules%2Fshaper.git Issue #2029 Change the color of the Sketch when fully constrained --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index b57291d26..f72ad02fd 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -229,6 +229,11 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject AISObjectPtr thePrs, GeomCustomPrsPtr theCustomPrs) { return false; }; + /// Modifies the given presentation in the custom way after usual customize is performed. + virtual bool afterCustomisePresentation(std::shared_ptr theResult, + AISObjectPtr thePrs, + GeomCustomPrsPtr theCustomPrs) { return false; }; + /// Update the object presentable properties such as color, lines width and other /// If the object is result with the color attribute value set, it is used, /// otherwise the customize is applyed to the object's feature if it is a custom prs diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 139801633..2d4bc1579 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1015,10 +1015,10 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the return aCustomized; std::vector aColor; - bool aCustomColor = myOverconstraintListener->hasCustomColor(anObject, aColor); + //bool aCustomColor = myOverconstraintListener->hasCustomColor(anObject, aColor); if (!theResult.get()) { - // customize sketch symbol presentation + /*// customize sketch symbol presentation if (thePrs.get()) { Handle(AIS_InteractiveObject) anAISIO = thePrs->impl(); if (!anAISIO.IsNull()) { @@ -1036,19 +1036,76 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the } } } + }*/ + // customize sketch dimension constraint presentation + //if (!aCustomized) { + // if (!aCustomColor) + XGUI_CustomPrs::getDefaultColor(anObject, true, aColor); + if (!aColor.empty()) { + aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); + // } } + } + // customize dimentional constrains + sketchMgr()->customizePresentation(anObject); + + return aCustomized; +} + +bool PartSet_Module::afterCustomisePresentation(std::shared_ptr theResult, + AISObjectPtr thePrs, + GeomCustomPrsPtr theCustomPrs) +{ + bool aCustomized = false; + + XGUI_Workshop* aWorkshop = getWorkshop(); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + ObjectPtr anObject = aDisplayer->getObject(thePrs); + if (!anObject) + return aCustomized; + + std::vector aColor; + bool aCustomColorChanged = myOverconstraintListener->isNeedUpdateCustomColor(); + if (aCustomColorChanged) { + bool aUseCustomColor = true; + // do not use fully constrained color if create operation is started + /*if (aWorkshop->operationMgr()->hasOperation()) { + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (aWorkshop->operationMgr()->currentOperation()); + if (aFOperation && !aFOperation->isEditOperation()) + aUseCustomColor = false; + }*/ + if (aUseCustomColor) + myOverconstraintListener->getCustomColor(anObject, aColor); + //if (!theResult.get()) { + // customize sketch symbol presentation + //if (thePrs.get()) { + Handle(AIS_InteractiveObject) anAISIO = thePrs->impl(); + if (!anAISIO.IsNull()) { + if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) { + Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO); + if (!aPrs.IsNull()) { + aPrs->SetCustomColor(aColor); + aCustomized = true; + } + } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) { + Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO); + if (!aPrs.IsNull()) { + aPrs->SetCustomColor(aColor); + aCustomized = true; + } + } + } + //} // customize sketch dimension constraint presentation if (!aCustomized) { - if (!aCustomColor) - XGUI_CustomPrs::getDefaultColor(anObject, true, aColor); - if (!aColor.empty()) { + //if (!aCustomColor) + // XGUI_CustomPrs::getDefaultColor(anObject, true, aColor); + if (!aColor.empty()) { // otherwise presentation has the default color aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); } } } - // customize dimentional constrains - sketchMgr()->customizePresentation(anObject); - return aCustomized; } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 3c7316458..2795d2965 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -252,6 +252,11 @@ public: AISObjectPtr thePrs, std::shared_ptr theCustomPrs); + /// Modifies the given presentation in the custom way after usual customize is performed. + virtual bool afterCustomisePresentation(std::shared_ptr theResult, + AISObjectPtr thePrs, + GeomCustomPrsPtr theCustomPrs); + /// Update the object presentable properties such as color, lines width and other /// If the object is result with the color attribute value set, it is used, /// otherwise the customize is applyed to the object's feature if it is a custom prs diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 40ec725ce..8dd5af2eb 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -29,7 +29,7 @@ //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop) -: myWorkshop(theWorkshop), myIsFullyConstrained(false) +: myWorkshop(theWorkshop), myIsFullyConstrained(false), myIsNeedUpdateCustomColor(false) { Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); @@ -39,7 +39,7 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)); } -bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject, +void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, std::vector& theColor) { if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) { @@ -48,7 +48,6 @@ bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject, theColor.push_back(aColor.Red()*255.); theColor.push_back(aColor.Green()*255.); theColor.push_back(aColor.Blue()*255.); - return true; } if (myIsFullyConstrained) { FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); @@ -59,14 +58,12 @@ bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject, if (ModelAPI_Tools::compositeOwner(aFeature) == aCompositeFeature) { Quantity_Color aColor = ModuleBase_Tools::color("Visualization", "sketch_fully_constrained_color"); - theColor.push_back(aColor.Red()*255.); + theColor.push_back(aColor.Red()*0.); theColor.push_back(aColor.Green()*255.); - theColor.push_back(aColor.Blue()*255.); - return true; + theColor.push_back(aColor.Blue()*0.); } } } - return false; } void PartSet_OverconstraintListener::processEvent( @@ -114,6 +111,7 @@ void PartSet_OverconstraintListener::processEvent( myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED); if (aPrevFullyConstrained != myIsFullyConstrained) { + myIsNeedUpdateCustomColor = true; std::set aModifiedObjects; PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); @@ -127,6 +125,7 @@ void PartSet_OverconstraintListener::processEvent( } } redisplayObjects(aModifiedObjects); + myIsNeedUpdateCustomColor = false; } } diff --git a/src/PartSet/PartSet_OverconstraintListener.h b/src/PartSet/PartSet_OverconstraintListener.h index 4eaf5c805..4051c0c95 100755 --- a/src/PartSet/PartSet_OverconstraintListener.h +++ b/src/PartSet/PartSet_OverconstraintListener.h @@ -42,7 +42,11 @@ public: /// \param theObject an object to be checked /// \param theColor the output container to be filled in [red, green, blue] values /// \return boolean result - bool hasCustomColor(const ObjectPtr& theObject, std::vector& theColor); + void getCustomColor(const ObjectPtr& theObject, std::vector& theColor); + + /// Returns true if custom color of presentations is changed and it should be redisplayed + /// \return boolean value + bool isNeedUpdateCustomColor() const { return true;/*myIsNeedUpdateCustomColor;*/ } /// Redefinition of Events_Listener method virtual void processEvent(const std::shared_ptr& theMessage); @@ -77,6 +81,7 @@ private: std::set myConflictingObjects; ModuleBase_IWorkshop* myWorkshop; bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0 + bool myIsNeedUpdateCustomColor; }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 3970d8b32..5d879f42a 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -1351,6 +1351,7 @@ bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, return isActivationChanged; } +//#define DEBUG_FULLY_CONSTRAINED bool XGUI_Displayer::customizeObject(ObjectPtr theObject) { AISObjectPtr anAISObj = getAISObject(theObject); @@ -1373,6 +1374,9 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject) } bool isCustomized = aCustomPrs.get() && aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); +#ifdef DEBUG_FULLY_CONSTRAINED + isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs) || isCustomized; +#endif return isCustomized; }