From: nds Date: Tue, 9 Feb 2016 06:30:10 +0000 (+0300) Subject: 2.17. Improved management of overconstraint situation: dimension constraints are... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cba6e1969e3c09c2ce5d36f840da554682955159;p=modules%2Fshaper.git 2.17. Improved management of overconstraint situation: dimension constraints are in red color --- diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index a2d840901..0d9c067d6 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -57,6 +57,10 @@ class ModelAPI_Object: public ModelAPI_Entity /// Returns the feature is disabled or not. virtual bool isDisabled() = 0; + /// Returns the parameters of color definition in the resources config manager + virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) {} + /// Called on change of any argument-attribute of this object /// \param theID identifier of changed attribute MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID); diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index 14f69a32f..bf15dfeec 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -52,10 +52,6 @@ class ModelAPI_Result : public ModelAPI_Object /// Returns the result is disabled or not. MODELAPI_EXPORT virtual bool isDisabled(); - /// Returns the parameters of color definition in the resources config manager - virtual void colorConfigInfo(std::string& theSection, std::string& theName, - std::string& theDefault) {} - /// Request for initialization of data model of the result: adding all attributes virtual void initAttributes() {}; diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 6c034a798..a37a49c8c 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -16,6 +16,7 @@ #include #include +#include #include class QAction; @@ -256,6 +257,11 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape) = 0; + /// Returns color of the object + /// \param theObject a result of a feature object + /// \param theColor a vector of three values in [0, 255] range + virtual void getColor(const ObjectPtr& theObject, std::vector& theColor) {} + /// Returns XML information by the feature index /// \param theFeatureId a feature id /// \param theXmlCfg XML configuration diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index b18a8308d..b8c6121cd 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -11,6 +11,7 @@ SET(PROJECT_HEADERS PartSet_ExternalObjectsMgr.h PartSet_Module.h PartSet_OperationPrs.h + PartSet_OverconstraintListener.h PartSet_Tools.h PartSet_WidgetSketchLabel.h PartSet_Validators.h @@ -36,6 +37,7 @@ SET(PROJECT_SOURCES PartSet_ExternalObjectsMgr.cpp PartSet_Module.cpp PartSet_OperationPrs.cpp + PartSet_OverconstraintListener.cpp PartSet_Tools.cpp PartSet_WidgetSketchLabel.cpp PartSet_Validators.cpp diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index fdb2a0f3b..3a0a054c7 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -7,6 +7,7 @@ #include #include #include "PartSet_OperationPrs.h" +#include "PartSet_OverconstraintListener.h" #include #include @@ -173,7 +174,9 @@ bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION return false; #endif - return displayPresentation(theFlag, theUpdateViewer); + bool aRedisplayed = displayPresentation(theFlag, theUpdateViewer); + + return aRedisplayed; } void PartSet_CustomPrs::clearPrs() diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 35a077041..7067a7819 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -18,6 +18,7 @@ #include "PartSet_CustomPrs.h" #include "PartSet_IconFactory.h" #include "PartSet_WidgetChoice.h" +#include "PartSet_OverconstraintListener.h" #include "PartSet_Filters.h" #include "PartSet_FilterInfinite.h" @@ -134,6 +135,8 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) myMenuMgr = new PartSet_MenuMgr(this); myCustomPrs = new PartSet_CustomPrs(theWshop); + myOverconstraintListener = new PartSet_OverconstraintListener(theWshop); + Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); @@ -163,6 +166,7 @@ PartSet_Module::~PartSet_Module() aFilter.Nullify(); } delete myCustomPrs; + delete myOverconstraintListener; } void PartSet_Module::activateSelectionFilters() @@ -1074,6 +1078,14 @@ AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject, return anAttribute; } +//****************************************************** +void PartSet_Module::getColor(const ObjectPtr& theObject, std::vector& theColor) +{ + if (myOverconstraintListener->isConflictingObject(theObject)) { + myOverconstraintListener->getConflictingColor(theColor); + } +} + //****************************************************** void PartSet_Module::onBooleanOperationChange(int theOperation) { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 6c5a5e0b6..cf65860f7 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -5,6 +5,7 @@ #include "PartSet.h" #include "PartSet_Tools.h" +#include "PartSet_OverconstraintListener.h" #include #include @@ -171,6 +172,10 @@ public: /// Returns sketch reentrant manager PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; } + /// Returns listener of overconstraint signal + /// \return the listener + PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; } + /// Performs functionality on closing document virtual void closeDocument(); @@ -259,6 +264,11 @@ public: /// \return theAttribute virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape); + /// Returns color of the object + /// \param theObject a result of a feature object + /// \param theColor a vector of three values in [0, 255] range + virtual void getColor(const ObjectPtr& theObject, std::vector& theColor); + public slots: /// Redefines the parent method in order to customize the next case: /// If the sketch nested operation is active and the presentation is not visualized in the viewer, @@ -332,6 +342,7 @@ protected: PartSet_MenuMgr* myMenuMgr; /// A default custom presentation, which is used for references objects of started operation PartSet_CustomPrs* myCustomPrs; + PartSet_OverconstraintListener* myOverconstraintListener; int myVisualLayerId; /// backup of the visible state to restore them by operation stop diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp new file mode 100755 index 000000000..e03a667f9 --- /dev/null +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -0,0 +1,196 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Angle.cpp +// Created: 20 August 2015 +// Author: Vitaly SMETANNIKOV + +#include "PartSet_OverconstraintListener.h" + +#include "XGUI_ModuleConnector.h" +#include "XGUI_Workshop.h" +#include "XGUI_Displayer.h" + +#include "SketcherPrs_SymbolPrs.h" + +#include "Events_Loop.h" + +#include +#include +#include + +#include + +#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER + +PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop) +: myWorkshop(theWorkshop) +{ + 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(); +} + +void PartSet_OverconstraintListener::getConflictingColor(std::vector& theColor) +{ + Quantity_Color aColor = Quantity_Color(Quantity_NameOfColor::Quantity_NOC_RED); + + theColor.push_back(aColor.Red()*255.); + theColor.push_back(aColor.Green()*255.); + theColor.push_back(aColor.Blue()*255.); +} + +void PartSet_OverconstraintListener::processEvent( + const std::shared_ptr& theMessage) +{ + +#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");*/ + bool isRepaired = theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_REPAIRED); + qDebug(QString("PartSet_OverconstraintListener::processEvent:\n %1").arg(isRepaired ? "REPAIRED" : "FAILED").toStdString().c_str()); +#endif + + if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SOLVER_FAILED) || + 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 = updateConflictingObjects(aConflictingObjects); + } + 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()); +#endif + + bool isUpdated = false; + std::set aModifiedObjects; + // erase error state of absent current objects in the parameter list + for (anIt = myConflictingObjects.begin(), aLast = myConflictingObjects.end() ; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (theConflictingObjects.find(anObject) == theConflictingObjects.end()) { // it is not found + //setConflictingObject(anObject, false); + aModifiedObjects.insert(anObject); + } + } + + // erase absent objects from the internal container + for (anIt = aModifiedObjects.begin(), aLast = aModifiedObjects.end(); anIt != aLast; anIt++) { + myConflictingObjects.erase(*anIt); + } + + // set error state for new objects and append them in the internal map of objects + 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); + aModifiedObjects.insert(anObject); + myConflictingObjects.insert(anObject); + } + } + isUpdated = !aModifiedObjects.empty(); + if (isUpdated) + redisplayObjects(aModifiedObjects); + + return isUpdated; +} + +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 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + + std::set::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); + 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); + } + } + } + } +} + +XGUI_Workshop* PartSet_OverconstraintListener::workshop() const +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + return aConnector->workshop(); +} + diff --git a/src/PartSet/PartSet_OverconstraintListener.h b/src/PartSet/PartSet_OverconstraintListener.h new file mode 100755 index 000000000..fc771a824 --- /dev/null +++ b/src/PartSet/PartSet_OverconstraintListener.h @@ -0,0 +1,75 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_OverconstraintListener.h +// Created: 8 Feb 2016 +// Author: Natalia ERMOLAEVA + + +#ifndef PartSet_OverconstraintListener_H +#define PartSet_OverconstraintListener_H + +#include +#include + +class ModuleBase_IWorkshop; +class XGUI_Workshop; + +#include +#include + +/** +* \ingroup GUI +* A class for processing overconstraint situation. It contains is a list of sketch constraints with +* conflicts. +*/ +class PartSet_OverconstraintListener : public Events_Listener +{ +public: + /// Constructor + /// \param theWorkshop a current workshop to obtain AIS presentation from displayer + PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop); + + 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); + + /// 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); + + /// Redefinition of Events_Listener method + virtual void processEvent(const std::shared_ptr& theMessage); + +protected: + /// Updates 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); + + /// Obtains the object custom AIS presentation and change conflicting state if it exists + /// \param theObject the object which presentation error state should be changed + /// \param theConflicting if true, the object state is erroneous, else correct + void setConflictingObject(const ObjectPtr& theObject, const bool theConflicting); + + /// Sends update object signal for each object in the container and flush it. + /// \param theObjects a list of object to be redisplayed + void redisplayObjects(const std::set& theObjects); + +private: + //! Returns workshop + XGUI_Workshop* workshop() const; + +private: + std::set myConflictingObjects; + ModuleBase_IWorkshop* myWorkshop; +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index c73ae7d17..646e4b800 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -40,6 +40,14 @@ void SketchPlugin_ConstraintAngle::initAttributes() data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); } +void SketchPlugin_ConstraintAngle::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "sketch_dimension_color"; + theDefault = SKETCH_DIMENSION_COLOR; +} + void SketchPlugin_ConstraintAngle::execute() { std::shared_ptr aData = data(); @@ -74,11 +82,6 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious if (!anAIS) { anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane()); } - - // Set color from preferences - std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", - SKETCH_DIMENSION_COLOR); - anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h index ef3c478be..edc5209a3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h @@ -45,6 +45,10 @@ class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); + /// Retuns the parameters of color definition in the resources config manager + SKETCHPLUGIN_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + /// Called on change of any argument-attribute of this object /// \param theID identifier of changed attribute SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintBase.h b/src/SketchPlugin/SketchPlugin_ConstraintBase.h index dffeed1a3..508980aa8 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintBase.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintBase.h @@ -14,6 +14,7 @@ #include #include +#include #include @@ -38,7 +39,8 @@ * Some feature's methods implemented here as dummy to * Base class for all constraints. */ -class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable +class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable, + public GeomAPI_ICustomPrs { public: /// Returns the AIS preview @@ -53,6 +55,13 @@ class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomA /// \param theDeltaY the delta for Y coordinate is moved SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); + /// Customize presentation of the feature + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) + { + return theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + } + protected: /// \brief Use plugin manager for features creation SketchPlugin_ConstraintBase() diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 7eeee4267..583477a02 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -42,6 +42,14 @@ void SketchPlugin_ConstraintDistance::initAttributes() data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); } +void SketchPlugin_ConstraintDistance::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "sketch_dimension_color"; + theDefault = SKETCH_DIMENSION_COLOR; +} + //************************************************************************************* void SketchPlugin_ConstraintDistance::execute() { @@ -134,9 +142,6 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi if (!anAIS) { anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane()); } - std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", - SKETCH_DIMENSION_COLOR); - anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index cbd6ccf37..4edc829a4 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -55,6 +55,10 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); + /// Retuns the parameters of color definition in the resources config manager + SKETCHPLUGIN_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 575c0f10a..e97b82141 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -40,6 +40,14 @@ void SketchPlugin_ConstraintLength::initAttributes() data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); } +void SketchPlugin_ConstraintLength::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "sketch_dimension_color"; + theDefault = SKETCH_DIMENSION_COLOR; +} + void SketchPlugin_ConstraintLength::execute() { std::shared_ptr aRef = std::dynamic_pointer_cast< @@ -128,9 +136,6 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou if (!anAIS) { anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane()); } - std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", - SKETCH_DIMENSION_COLOR); - anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index dd16d1a3a..662e276ee 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -52,6 +52,10 @@ class SketchPlugin_ConstraintLength : public SketchPlugin_ConstraintBase /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); + /// Retuns the parameters of color definition in the resources config manager + SKETCHPLUGIN_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 03854444b..e9ce8ae6a 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -40,6 +40,14 @@ void SketchPlugin_ConstraintRadius::initAttributes() data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); } +void SketchPlugin_ConstraintRadius::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "sketch_dimension_color"; + theDefault = SKETCH_DIMENSION_COLOR; +} + void SketchPlugin_ConstraintRadius::execute() { std::shared_ptr aRef = std::dynamic_pointer_cast< @@ -148,11 +156,6 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou if (!anAIS) { anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane()); } - - // Set color from preferences - std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", - SKETCH_DIMENSION_COLOR); - anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index cc2c96eb2..697a4db8d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -46,6 +46,10 @@ class SketchPlugin_ConstraintRadius : public SketchPlugin_ConstraintBase /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); + /// Retuns the parameters of color definition in the resources config manager + SKETCHPLUGIN_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp index 10125e574..395c7288b 100644 --- a/src/XGUI/XGUI_CustomPrs.cpp +++ b/src/XGUI/XGUI_CustomPrs.cpp @@ -5,6 +5,10 @@ // Author: Natalia ERMOLAEVA #include +#include +#include + +#include #include #include @@ -30,18 +34,18 @@ void getColor(ResultPtr theResult, std::vector& theColor) } } -void getDefaultColor(ResultPtr theResult, std::vector& theColor) +void getDefaultColor(ObjectPtr theObject, std::vector& theColor, const bool isEmptyColorValid) { theColor.clear(); // get default color from the preferences manager for the given result if (theColor.empty()) { std::string aSection, aName, aDefault; - theResult->colorConfigInfo(aSection, aName, aDefault); + theObject->colorConfigInfo(aSection, aName, aDefault); if (!aSection.empty() && !aName.empty()) { theColor = Config_PropManager::color(aSection, aName, aDefault); } } - if (theColor.empty()) { + if (!isEmptyColorValid && theColor.empty()) { // all AIS objects, where the color is not set, are in black. // The color should be defined in XML or set in the attribute theColor = Config_PropManager::color("Visualization", "object_default_color", "#000000"); @@ -49,27 +53,48 @@ void getDefaultColor(ResultPtr theResult, std::vector& theColor) } } +XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop) +: myWorkshop(theWorkshop) +{ +} + void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector& theColor) { getColor(theResult, theColor); if (theColor.empty()) - getDefaultColor(theResult, theColor); + getDefaultColor(theResult, theColor, false); } bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theCustomPrs) { - std::vector aColor; + bool aCustomized = false; + if (theResult.get()) { + std::vector aColor; + getResultColor(theResult, aColor); - getResultColor(theResult, aColor); - - SessionPtr aMgr = ModelAPI_Session::get(); - if (aMgr->activeDocument() != theResult->document()) { - QColor aQColor(aColor[0], aColor[1], aColor[2]); - QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF()); - aColor[0] = aNewColor.red(); - aColor[1] = aNewColor.green(); - aColor[2] = aNewColor.blue(); + SessionPtr aMgr = ModelAPI_Session::get(); + if (aMgr->activeDocument() != theResult->document()) { + QColor aQColor(aColor[0], aColor[1], aColor[2]); + QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF()); + aColor[0] = aNewColor.red(); + aColor[1] = aNewColor.green(); + aColor[2] = aNewColor.blue(); + } + aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); + } + else { + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + ObjectPtr anObject = aDisplayer->getObject(thePrs); + if (anObject.get()) { + std::vector aColor; + ModuleBase_IModule* aModule = myWorkshop->module(); + aModule->getColor(anObject, aColor); + if (aColor.empty()) + getDefaultColor(anObject, aColor, true); + if (!aColor.empty()) + thePrs->setColor(aColor[0], aColor[1], aColor[2]); + } } - return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); + return aCustomized; } diff --git a/src/XGUI/XGUI_CustomPrs.h b/src/XGUI/XGUI_CustomPrs.h index 36014cfec..83b1b951e 100644 --- a/src/XGUI/XGUI_CustomPrs.h +++ b/src/XGUI/XGUI_CustomPrs.h @@ -12,6 +12,8 @@ #include #include +class XGUI_Workshop; + /** * Interface of a class which can provide specific customization of * object presentation @@ -19,6 +21,10 @@ class XGUI_CustomPrs : public GeomAPI_ICustomPrs { public: + /// Constructor + /// \param theWorkshop the current workshop instance + XGUI_EXPORT XGUI_CustomPrs(XGUI_Workshop* theWorkshop); + XGUI_EXPORT virtual ~XGUI_CustomPrs() {}; /// Modifies the given presentation in the custom way. @@ -29,6 +35,9 @@ public: /// \param theResult a result object /// \param theColor a color in form of RGB vector static void getResultColor(ResultPtr theResult, std::vector& theColor); + +protected: + XGUI_Workshop* myWorkshop; /// the current workshop }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 29b8b997b..96f63fe2b 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -107,7 +107,7 @@ XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) myIsTrihedronActive(false) { enableUpdateViewer(true); - myCustomPrs = std::shared_ptr(new XGUI_CustomPrs()); + myCustomPrs = std::shared_ptr(new XGUI_CustomPrs(theWorkshop)); } XGUI_Displayer::~XGUI_Displayer()