From 0bbc862db48081f4ff407177716e6fb8c16e930f Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 29 Mar 2017 14:47:27 +0300 Subject: [PATCH] Issue #2029 Change the color of the Sketch when fully constrained --- src/PartSet/PartSet_Module.cpp | 17 ++--- .../PartSet_OverconstraintListener.cpp | 74 ++++++++++++------- src/PartSet/PartSet_OverconstraintListener.h | 8 +- src/SketchPlugin/SketchPlugin_Plugin.cpp | 10 +++ src/SketchPlugin/SketchPlugin_SketchEntity.h | 5 -- src/SketcherPrs/SketcherPrs_Coincident.cpp | 22 +++--- src/SketcherPrs/SketcherPrs_Coincident.h | 14 ++-- src/SketcherPrs/SketcherPrs_SymbolPrs.cpp | 30 +++----- src/SketcherPrs/SketcherPrs_SymbolPrs.h | 11 +-- 9 files changed, 98 insertions(+), 93 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e7e7e8fa4..fb64f4a7f 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1015,7 +1015,8 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the return aCustomized; if (!theResult.get()) { - bool isConflicting = myOverconstraintListener->isConflictingObject(anObject); + std::vector aColor; + bool isConflicting = myOverconstraintListener->hasCustomColor(anObject, aColor); // customize sketch symbol presentation if (thePrs.get()) { Handle(AIS_InteractiveObject) anAISIO = thePrs->impl(); @@ -1023,17 +1024,13 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) { Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO); if (!aPrs.IsNull()) { - std::vector aColor; - myOverconstraintListener->getConflictingColor(aColor); - aPrs->SetConflictingConstraint(isConflicting, aColor); + 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()) { - std::vector aColor; - myOverconstraintListener->getConflictingColor(aColor); - aPrs->SetConflictingConstraint(isConflicting, aColor); + aPrs->SetCustomColor(aColor); aCustomized = true; } } @@ -1041,11 +1038,7 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the } // customize sketch dimension constraint presentation if (!aCustomized) { - std::vector aColor; - if (isConflicting) { - myOverconstraintListener->getConflictingColor(aColor); - } - if (aColor.empty()) + if (!isConflicting) XGUI_CustomPrs::getDefaultColor(anObject, true, aColor); if (!aColor.empty()) { aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 876130044..fa20c5490 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -4,11 +4,16 @@ // Created: 20 August 2015 // Author: Vitaly SMETANNIKOV +#include + #include "PartSet_OverconstraintListener.h" +#include +#include #include "XGUI_ModuleConnector.h" #include "XGUI_Workshop.h" #include "XGUI_Displayer.h" +#include "XGUI_CustomPrs.h" #include "SketcherPrs_SymbolPrs.h" #include "SketchPlugin_SketchEntity.h" @@ -29,19 +34,39 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)); -} -bool PartSet_OverconstraintListener::isConflictingObject(const ObjectPtr& theObject) -{ - return myConflictingObjects.find(theObject) != myConflictingObjects.end(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)); } -void PartSet_OverconstraintListener::getConflictingColor(std::vector& theColor) +bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject, + std::vector& theColor) { - Quantity_Color aColor = ModuleBase_Tools::color("Visualization", "sketch_overconstraint_color"); - theColor.push_back(aColor.Red()*255.); - theColor.push_back(aColor.Green()*255.); - theColor.push_back(aColor.Blue()*255.); + if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) { + Quantity_Color aColor = ModuleBase_Tools::color("Visualization", + "sketch_overconstraint_color"); + 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); + if (aFeature.get()) { + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + CompositeFeaturePtr aCompositeFeature = aModule->sketchMgr()->activeSketch(); + // the given object is sub feature of the current sketch(created or edited) + 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.Green()*255.); + theColor.push_back(aColor.Blue()*255.); + return true; + } + } + } + return false; } void PartSet_OverconstraintListener::processEvent( @@ -69,30 +94,23 @@ void PartSet_OverconstraintListener::processEvent( .arg(aCurrentInfoStr).toStdString().c_str()); #endif - if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_FAILED)) { + Events_ID anEventID = theMessage->eventID(); + if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED) || + anEventID == 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 = appendConflictingObjects(aConflictingObjects); - } - else { - // there is a crash in the solver. All objects are invalid - //anUpdated = appendConflictingObjects(std::set()); + if (anEventID == Events_Loop::eventByName(EVENT_SOLVER_FAILED)) + anUpdated = appendConflictingObjects(aConflictingObjects); + else + anUpdated = repairConflictingObjects(aConflictingObjects); } } - 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 if (anEventID == Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED) || + anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)) { + myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED); } #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER @@ -106,8 +124,8 @@ bool PartSet_OverconstraintListener::appendConflictingObjects( const std::set& theConflictingObjects) { std::set aModifiedObjects; - std::vector aColor; - getConflictingColor(aColor); + //std::vector aColor; + //getConflictingColor(aColor); // set error state for new objects and append them in the internal map of objects std::set::const_iterator diff --git a/src/PartSet/PartSet_OverconstraintListener.h b/src/PartSet/PartSet_OverconstraintListener.h index 1f0e8f01c..4eaf5c805 100755 --- a/src/PartSet/PartSet_OverconstraintListener.h +++ b/src/PartSet/PartSet_OverconstraintListener.h @@ -40,12 +40,9 @@ public: /// Returns true if the object belongs to internal container of conflicting objects /// \param theObject an object to be checked - /// \return boolean result - bool isConflictingObject(const ObjectPtr& theObject); - - /// Returns values of conflicting color /// \param theColor the output container to be filled in [red, green, blue] values - void getConflictingColor(std::vector& theColor); + /// \return boolean result + bool hasCustomColor(const ObjectPtr& theObject, std::vector& theColor); /// Redefinition of Events_Listener method virtual void processEvent(const std::shared_ptr& theMessage); @@ -79,6 +76,7 @@ private: private: std::set myConflictingObjects; ModuleBase_IWorkshop* myWorkshop; + bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0 }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 05ba4c501..774a961b9 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -49,6 +49,12 @@ #include #endif +#define SKETCH_ENTITY_COLOR "225,0,0" +#define SKETCH_EXTERNAL_COLOR "170,0,225" +#define SKETCH_AUXILIARY_COLOR "0,85,0" +#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0" +#define SKETCH_FULLY_CONSTRAINED_COLOR "150,150,150" + //#define SET_PLANES_COLOR_IN_PREFERENCES // the only created instance of this plugin @@ -124,6 +130,10 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() "Sketch overconstraint color", Config_Prop::Color, SKETCH_OVERCONSTRAINT_COLOR); + Config_PropManager::registerProp("Visualization", "sketch_fully_constrained_color", + "Sketch fully constrained color", + Config_Prop::Color, SKETCH_FULLY_CONSTRAINED_COLOR); + // register sketcher properties #ifdef SET_PLANES_COLOR_IN_PREFERENCES Config_PropManager::registerProp("Visualization", "yz_plane_color", "YZ plane color", diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index 54f9399c8..1af4d28bb 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -20,11 +20,6 @@ #include -#define SKETCH_ENTITY_COLOR "225,0,0" -#define SKETCH_EXTERNAL_COLOR "170,0,225" -#define SKETCH_AUXILIARY_COLOR "0,85,0" -#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0" - /**\class SketchPlugin_SketchEntity * \ingroup Plugins * \brief Sketch Entity for creation of the new feature in PartSet. diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 84e6b130f..13ffbee74 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -34,7 +34,7 @@ IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject); SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane) : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane), - myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsConflicting(false) + myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsCustomColor(false) { } @@ -76,12 +76,12 @@ void SketcherPrs_Coincident::Compute( myPoint = aPoint; // Create the presentation as a combination of standard point markers - bool aValid = !myIsConflicting; + bool aCustomColor = myIsCustomColor; // The external yellow contour Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d(); aPtA->SetType(Aspect_TOM_RING3); aPtA->SetScale(2.); - aPtA->SetColor(aValid ? Quantity_NOC_YELLOW : myConflictingColor); + aPtA->SetColor(!aCustomColor ? Quantity_NOC_YELLOW : myCustomColor); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); aGroup->SetPrimitivesAspect(aPtA); @@ -93,7 +93,7 @@ void SketcherPrs_Coincident::Compute( aPtA = new Graphic3d_AspectMarker3d(); aPtA->SetType(Aspect_TOM_RING1); aPtA->SetScale(1.); - aPtA->SetColor(aValid ? Quantity_NOC_BLACK : myConflictingColor); + aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor); aGroup->SetPrimitivesAspect(aPtA); aGroup->AddPrimitiveArray (aPntArray); @@ -101,7 +101,7 @@ void SketcherPrs_Coincident::Compute( aPtA = new Graphic3d_AspectMarker3d(); aPtA->SetType(Aspect_TOM_POINT); aPtA->SetScale(5.); - aPtA->SetColor(aValid ? Quantity_NOC_BLACK : myConflictingColor); + aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor); aGroup->SetPrimitivesAspect(aPtA); aGroup->AddPrimitiveArray (aPntArray); @@ -128,10 +128,12 @@ void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol) myOwnColor=aCol; } -void SketcherPrs_Coincident::SetConflictingConstraint(const bool& theConflicting, - const std::vector& theColor) +void SketcherPrs_Coincident::SetCustomColor(const std::vector& theColor) { - myIsConflicting = theConflicting; - myConflictingColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255., theColor[2] / 255., - Quantity_TOC_RGB); + myIsCustomColor = !theColor.empty(); + if (myIsCustomColor) + myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255., + theColor[2] / 255., Quantity_TOC_RGB); + else + myCustomColor = Quantity_Color(); } diff --git a/src/SketcherPrs/SketcherPrs_Coincident.h b/src/SketcherPrs/SketcherPrs_Coincident.h index 773a9c5ea..f77aa8d9b 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.h +++ b/src/SketcherPrs/SketcherPrs_Coincident.h @@ -38,14 +38,10 @@ public: /// \param aColor a color name Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor); - /// Set state of the presentation, in case of conflicting state, the icon of the presentation is + /// Set state of the presentation, in case of custom color, the icon of the presentation is /// visualized in error color. - /// The state is stored in an internal field, so should be changed when - /// constraint become not conflicting - /// \param theConflicting a state - /// \param theColor a color for conflicting object - Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting, - const std::vector& theColor); + /// \param theColor a custom color for object presentation + Standard_EXPORT void SetCustomColor(const std::vector& theColor); /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation /// \param theConstraint a constraint feature @@ -74,8 +70,8 @@ private: ModelAPI_Feature* myConstraint; std::shared_ptr mySketcherPlane; gp_Pnt myPoint; - bool myIsConflicting; /// state if the presentation is visualized in error state - Quantity_Color myConflictingColor; /// the color of mid ring if there is a conflict + bool myIsCustomColor; /// state if the presentation is visualized in custom color + Quantity_Color myCustomColor; /// the color of mid ring if there is a conflict }; diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index 48a0256e2..cc56dd55d 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -103,7 +103,7 @@ std::map SketcherPrs_SymbolPrs::myIconsM SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane) - : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane), myIsConflicting(false) + : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane), myIsCustomColor(false) { SetAutoHilight(Standard_False); myPntArray = new Graphic3d_ArrayOfPoints(1); @@ -166,7 +166,7 @@ void SketcherPrs_SymbolPrs::prepareAspect() else myAspect = new Graphic3d_AspectMarker3d(aIcon); - myAspect->SetColor(myColor); + myAspect->SetColor(myCustomColor); } } @@ -294,25 +294,17 @@ void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& } //********************************************************************************* -void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting, - const std::vector& theColor) +void SketcherPrs_SymbolPrs::SetCustomColor(const std::vector& theColor) { - if (theConflicting) - { - myColor = Quantity_Color (theColor[0] / 255., theColor[1] / 255., - theColor[2] / 255., Quantity_TOC_RGB); - //if (!myAspect.IsNull()) - // myAspect->SetColor (Quantity_Color (theColor[0] / 255., theColor[1] / 255., - // theColor[2] / 255., Quantity_TOC_RGB)); - //myIsConflicting = true; - } + myIsCustomColor = !theColor.empty(); + if (myIsCustomColor) + myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255., + theColor[2] / 255., Quantity_TOC_RGB); else - { - myColor = Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB); - //if (!myAspect.IsNull()) - // myAspect->SetColor (Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB)); - //myIsConflicting = false; - } + myCustomColor = Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB); + + if (!myAspect.IsNull()) + myAspect->SetColor (myCustomColor); } //********************************************************************************* diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.h b/src/SketcherPrs/SketcherPrs_SymbolPrs.h index 4c852d5a4..8bbae4dda 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.h +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.h @@ -68,10 +68,8 @@ public: /// Set state of the presentation, in case of conflicting state, the icon of the presentation is /// visualized in error color. The state is stored in an internal field, so should be changed /// when constraint become not conflicting - /// \param theConflicting a state /// \param theColor a color for conflicting object - Standard_EXPORT void SetConflictingConstraint(const bool& theConflicting, - const std::vector& theColor); + Standard_EXPORT void SetCustomColor(const std::vector& theColor); /// Add a bounding box of the presentation to common bounding box /// \param theBndBox the common bounding box to update @@ -149,8 +147,11 @@ private: Select3D_EntitySequence mySPoints; - Quantity_Color myColor; - bool myIsConflicting; /// state if the presentation is visualized in error state + bool myIsCustomColor; /// state if the presentation is visualized in custom color + Quantity_Color myCustomColor; /// the color of mid ring if there is a conflict + + //Quantity_Color myIsCustomColor; + //bool myIsConflicting; /// state if the presentation is visualized in error state Handle(Image_AlienPixMap) myErrorIcon; Handle(Graphic3d_MarkerImage) myErrorImage; -- 2.30.2