From 247fc0bd6c6e04ce1f7a6e67f8d3c80ce17acab0 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 11 Mar 2015 17:42:26 +0300 Subject: [PATCH] Change color for construction/body/group. The default custom presentation to customize the AIS object color if there is no a customizer realized with the feature of the object. --- .../ConstructionPlugin_Axis.cpp | 14 +-- .../ConstructionPlugin_Axis.h | 10 +-- .../ConstructionPlugin_Plane.cpp | 29 +++++-- .../ConstructionPlugin_Plane.h | 4 +- .../ConstructionPlugin_Plugin.cpp | 4 - .../ConstructionPlugin_Point.cpp | 8 -- .../ConstructionPlugin_Point.h | 15 +--- .../ExchangePlugin_ImportFeature.cpp | 8 -- .../ExchangePlugin_ImportFeature.h | 10 +-- src/ExchangePlugin/ExchangePlugin_Plugin.cpp | 8 +- src/GeomAPI/GeomAPI_AISObject.cpp | 86 +++++++++++++------ src/GeomAPI/GeomAPI_AISObject.h | 22 +++-- src/GeomAPI/GeomAPI_ICustomPrs.h | 7 +- src/Model/Model_ResultBody.cpp | 17 ++-- src/Model/Model_ResultBody.h | 4 + src/Model/Model_ResultConstruction.cpp | 17 ++-- src/Model/Model_ResultConstruction.h | 4 + src/Model/Model_ResultGroup.cpp | 17 ++-- src/Model/Model_ResultGroup.h | 4 + src/ModelAPI/ModelAPI_Result.h | 3 + src/ModuleBase/ModuleBase_Preferences.cpp | 3 + .../SketchPlugin_SketchEntity.cpp | 1 + src/SketchPlugin/SketchPlugin_SketchEntity.h | 44 +++++----- src/XGUI/CMakeLists.txt | 2 + src/XGUI/XGUI_CustomPrs.cpp | 55 ++++++++++++ src/XGUI/XGUI_CustomPrs.h | 29 +++++++ src/XGUI/XGUI_Displayer.cpp | 43 ++++++---- src/XGUI/XGUI_Displayer.h | 8 +- src/XGUI/XGUI_Workshop.cpp | 26 +++--- 29 files changed, 323 insertions(+), 179 deletions(-) create mode 100644 src/XGUI/XGUI_CustomPrs.cpp create mode 100644 src/XGUI/XGUI_CustomPrs.h diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 258ed85e9..7678b51a4 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -55,11 +55,13 @@ void ConstructionPlugin_Axis::execute() } } -void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs) +bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) { - std::vector aRGB = Config_PropManager::color("Visualization", "construction_axis_color", - ConstructionPlugin_Axis::DEFAULT_COLOR()); - thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]); - thePrs->setLineStyle(3); - thePrs->redisplay(); + bool isCustomized = theDefaultPrs.get() != NULL && + theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + + isCustomized = thePrs->setLineStyle(3); + + return isCustomized; } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index 473d3e352..b92e0842c 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -9,6 +9,7 @@ #include "ConstructionPlugin.h" #include +#include #include /**\class ConstructionPlugin_Axis @@ -56,12 +57,6 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace"); return CYLINDRICAL_FACE_ATTR; } - /// default color for an axis - inline static const std::string& DEFAULT_COLOR() - { - static const std::string CONSTRUCTION_AXIS_COLOR("#000000"); - return CONSTRUCTION_AXIS_COLOR; - } inline static const double MINIMAL_LENGTH() { return 1.e-5; } @@ -78,7 +73,8 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP ConstructionPlugin_Axis(); /// Customize presentation of the feature - virtual void customisePresentation(AISObjectPtr thePrs); + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs); }; diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index d0ecc4d7e..501d9664e 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -73,10 +74,28 @@ void ConstructionPlugin_Plane::execute() } } -void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs) +bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) { - std::vector aRGB = Config_PropManager::color("Visualization", "construction_plane_color", - ConstructionPlugin_Plane::DEFAULT_COLOR()); - thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]); - thePrs->setTransparensy(0.6); + std::vector aColor; + // get color from the attribute of the result + if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { + AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); + if (aColorAttr.get() && aColorAttr->size()) { + aColor.push_back(aColorAttr->value(0)); + aColor.push_back(aColorAttr->value(1)); + aColor.push_back(aColorAttr->value(2)); + } + } + if (aColor.empty()) + aColor = Config_PropManager::color("Visualization", "construction_plane_color", + ConstructionPlugin_Plane::DEFAULT_COLOR()); + + bool isCustomized = false; + if (aColor.size() == 3) + isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); + + isCustomized = thePrs->setTransparensy(0.6) || isCustomized; + + return isCustomized; } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.h b/src/ConstructionPlugin/ConstructionPlugin_Plane.h index f57ff1eb1..2ff71979a 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.h @@ -9,6 +9,7 @@ #include "ConstructionPlugin.h" #include +#include #include @@ -91,7 +92,8 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom ConstructionPlugin_Plane(); /// Customize presentation of the feature - virtual void customisePresentation(AISObjectPtr thePrs); + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs); }; #endif diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 4731cc4c8..c60c022b4 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -21,10 +21,6 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() ModelAPI_Session::get()->registerPlugin(this); // register construction properties - Config_PropManager::registerProp("Visualization", "construction_point_color", "Construction point color", - Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "construction_axis_color", "Construction axis color", - Config_Prop::Color, ConstructionPlugin_Axis::DEFAULT_COLOR()); Config_PropManager::registerProp("Visualization", "construction_plane_color", "Construction plane color", Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR()); } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 231e54fb2..671a38cd7 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -45,11 +45,3 @@ void ConstructionPlugin_Point::execute() aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt)); setResult(aConstr); } - -void ConstructionPlugin_Point::customisePresentation(AISObjectPtr thePrs) -{ - std::vector aRGB = Config_PropManager::color("Visualization", "construction_point_color", - ConstructionPlugin_Point::DEFAULT_COLOR()); - thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]); - thePrs->redisplay(); -} diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index f4bf39a11..84cb35cb3 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -9,13 +9,13 @@ #include "ConstructionPlugin.h" #include -#include +#include /**\class ConstructionPlugin_Point * \ingroup Plugins * \brief Feature for creation of the new part in PartSet. */ -class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustomPrs +class ConstructionPlugin_Point : public ModelAPI_Feature { public: /// Returns the kind of a feature @@ -27,13 +27,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustom return CONSTRUCTION_POINT_KIND; } - /// default color for a point - inline static const std::string& DEFAULT_COLOR() - { - static const std::string CONSTRUCTION_POINT_COLOR("#ffff00"); - return CONSTRUCTION_POINT_COLOR; - } - /// attribute name for X coordinate inline static const std::string& X() { @@ -64,10 +57,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustom /// Use plugin manager for features creation ConstructionPlugin_Point(); - - /// Modifies the given presentation in the custom way. - virtual void customisePresentation(AISObjectPtr thePrs); - }; #endif diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 11d45e785..7fe93e090 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -70,14 +70,6 @@ void ExchangePlugin_ImportFeature::execute() importFile(aFilePath); } -void ExchangePlugin_ImportFeature::customisePresentation(AISObjectPtr thePrs) -{ - std::vector aRGB = Config_PropManager::color("Visualization", "import_feature_color", - IMPORTED_FEATURE_COLOR); - thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]); - thePrs->redisplay(); -} - bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) { // retrieve the file and plugin library names diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h index 54ed71521..673a6d950 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h @@ -5,20 +5,17 @@ #include #include - -#include +#include #include -#define IMPORTED_FEATURE_COLOR "#E0A01B" - /**\class ExchangePlugin_ImportFeature * \ingroup Plugins * \brief Feature for import shapes from the external files in CAD formats. * * The set of supported formats is defined in the configuration file. */ -class ExchangePlugin_ImportFeature : public ModelAPI_Feature, public GeomAPI_ICustomPrs +class ExchangePlugin_ImportFeature : public ModelAPI_Feature { public: /// Extrusion kind @@ -52,9 +49,6 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature, public GeomAPI_ICu return true; } - /// Modifies the given presentation in the custom way. - virtual void customisePresentation(AISObjectPtr thePrs); - protected: /// POerforms the import of the file EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName); diff --git a/src/ExchangePlugin/ExchangePlugin_Plugin.cpp b/src/ExchangePlugin/ExchangePlugin_Plugin.cpp index e2b1ee20f..58b214b47 100644 --- a/src/ExchangePlugin/ExchangePlugin_Plugin.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Plugin.cpp @@ -30,12 +30,8 @@ ExchangePlugin_Plugin::ExchangePlugin_Plugin() new ExchangePlugin_ImportFormatValidator); // register construction properties - Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color", - Config_Prop::Color, IMPORTED_FEATURE_COLOR); - - // register random result color properties - Config_PropManager::registerProp("Visualization", "random_result_color", "Use random color for results", - Config_Prop::Bool, "true"); + //Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color", + // Config_Prop::Color, ExchangePlugin_ImportFeature::DEFAULT_COLOR()); } FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID) diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 5e0c21b44..fb90ceccb 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -29,6 +29,8 @@ #include #include +#include + const double tolerance = 1e-7; const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint @@ -253,16 +255,6 @@ void GeomAPI_AISObject::createFixed(std::shared_ptr theShape, } } -void GeomAPI_AISObject::redisplay() -{ - Handle(AIS_InteractiveObject) anAIS = impl(); - if (!anAIS.IsNull()) { - Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - aContext->Redisplay(anAIS, false); - } -} - - void GeomAPI_AISObject::setColor(const int& theColor) { Handle(AIS_InteractiveObject) anAIS = impl(); @@ -278,21 +270,30 @@ void GeomAPI_AISObject::setColor(const int& theColor) aContext->SetColor(anAIS, aColor, false); } -void GeomAPI_AISObject::setWidth(const double& theWidth) +bool GeomAPI_AISObject::setWidth(const double& theWidth) { + bool isChanged = false; Handle(AIS_InteractiveObject) anAIS = impl(); - if (anAIS.IsNull()) - return; - anAIS->SetWidth(theWidth); - anAIS->Redisplay(); + if (!anAIS.IsNull()) { + isChanged = anAIS->Width() != theWidth; + if (isChanged) + anAIS->SetWidth(theWidth); + } + return isChanged; } -void GeomAPI_AISObject::setColor(int theR, int theG, int theB) +bool GeomAPI_AISObject::setColor(int theR, int theG, int theB) { Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) - return; + return false; Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB); + Quantity_Color aCurrentColor; + anAIS->Color(aCurrentColor); + // do not set the same color to the presentation + if (aColor.IsEqual(aCurrentColor)) + return false; + anAIS->SetColor(aColor); Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { @@ -300,6 +301,19 @@ void GeomAPI_AISObject::setColor(int theR, int theG, int theB) } Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); aContext->SetColor(anAIS, aColor, false); + return true; +} + +void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (anAIS.IsNull()) + return; + + Quantity_Color aColor = anAIS->Color(); + theR = aColor.Red()*255.; + theG = aColor.Green()*255.; + theB = aColor.Blue()*255.; } bool GeomAPI_AISObject::empty() const @@ -340,26 +354,46 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale) } } - -void GeomAPI_AISObject::setLineStyle(int theStyle) +bool GeomAPI_AISObject::setLineStyle(int theStyle) { + bool isChanged = false; Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { Handle(AIS_Drawer) aDrawer = anAIS->Attributes(); - if (aDrawer->HasLineAspect()) - aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle); - if (aDrawer->HasWireAspect()) - aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle); + Handle(Prs3d_LineAspect) aLineAspect; + + Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle; + if (aDrawer->HasLineAspect()) { + aLineAspect = aDrawer->LineAspect(); + } + if (aDrawer->HasWireAspect()) { + aLineAspect = aDrawer->WireAspect(); + } + Quantity_Color aCurrentColor; + Aspect_TypeOfLine aCurrentType; + Standard_Real aCurrentWidth; + aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth); + isChanged = aType != aCurrentType; + if (isChanged) { + aLineAspect->SetTypeOfLine(aType); + } } + return isChanged; } -void GeomAPI_AISObject::setTransparensy(double theVal) +bool GeomAPI_AISObject::setTransparensy(double theVal) { + bool isChanged = false; Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - if (!aContext.IsNull()) - aContext->SetTransparency(anAIS, theVal, false); + if (!aContext.IsNull()) { + double aCurrentValue = anAIS->Transparency(); + isChanged = aCurrentValue != theVal; + if (isChanged) + aContext->SetTransparency(anAIS, theVal, false); + } } + return isChanged; } diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index c916320c0..ad879d1db 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -78,24 +78,28 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface void createFixed(std::shared_ptr theShape, std::shared_ptr thePlane); - /** \brief Redisplays the current AIS object in the context - */ - void redisplay(); - /** \brief Assigns the color for the shape * \param[in] theColor index of the color */ void setColor(const int& theColor); /** \brief Assigns the color for the shape + * \param[in] theR value of the red component + * \param[in] theG value of the green component + * \param[in] theB value of the blue component + * \returns true if the presentation color is changed + */ + bool setColor(int theR, int theG, int theB); + + /** \brief Returns the color for the shape * \param[in] theR value of the red component * \param[in] theG value of the green component * \param[in] theB value of the blue component */ - void setColor(int theR, int theG, int theB); + void getColor(int& theR, int& theG, int& theB); /// \brief Assigns the width of the lines of shape - void setWidth(const double& theWidth); + bool setWidth(const double& theWidth); /// \brief Checks if the object is empty bool empty() const; @@ -110,10 +114,12 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface /// Set line type of edges /// Has to be defined according to Aspect_TypeOfLine - void setLineStyle(int theStyle); + /// \returns true if the object value differs from the current + bool setLineStyle(int theStyle); /// Set transparency of the presentation (theVal = 0 ... 1) - void setTransparensy(double theVal); + /// \returns true if the object value differs from the current + bool setTransparensy(double theVal); }; //! Pointer on attribute object diff --git a/src/GeomAPI/GeomAPI_ICustomPrs.h b/src/GeomAPI/GeomAPI_ICustomPrs.h index 72c362d65..de9c6d299 100644 --- a/src/GeomAPI/GeomAPI_ICustomPrs.h +++ b/src/GeomAPI/GeomAPI_ICustomPrs.h @@ -9,18 +9,23 @@ #include "GeomAPI.h" #include "GeomAPI_AISObject.h" +#include "GeomAPI_AISObject.h" +#include /** * Interface of a class which can provide specific customization of * object presentation */ +class ModelAPI_Result; + class GeomAPI_ICustomPrs { public: GEOMAPI_EXPORT virtual ~GeomAPI_ICustomPrs(); /// Modifies the given presentation in the custom way. - virtual void customisePresentation(AISObjectPtr thePrs) = 0; + virtual bool customisePresentation(std::shared_ptr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) = 0; }; typedef std::shared_ptr GeomCustomPrsPtr; diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 784eff153..2bdea7f5f 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -44,16 +44,17 @@ Model_ResultBody::Model_ResultBody() void Model_ResultBody::initAttributes() { - // append the color attribute + // append the color attribute. It is empty, the attribute will be filled by a request DataPtr aData = data(); aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type()); - AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID()); - std::vector aRGB; - aRGB = Config_PropManager::color("Visualization", "result_body_color", DEFAULT_COLOR()); - aColorAttr->setSize(3); - aColorAttr->setValue(0, aRGB[0]); - aColorAttr->setValue(1, aRGB[1]); - aColorAttr->setValue(2, aRGB[2]); +} + +void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "result_body_color"; + theDefault = DEFAULT_COLOR(); } void Model_ResultBody::store(const std::shared_ptr& theShape) diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index e7fdcb5ca..a5ffd8302 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -39,6 +39,10 @@ public: /// Request for initialization of data model of the result: adding all attributes virtual void initAttributes(); + // Retuns the parameters of color definition in the resources config manager + MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + /// Stores the shape (called by the execution method). MODEL_EXPORT virtual void store(const std::shared_ptr& theShape); diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index 97f2b4fcd..a0f3b9306 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -11,16 +11,17 @@ void Model_ResultConstruction::initAttributes() { - // append the color attribute + // append the color attribute. It is empty, the attribute will be filled by a request DataPtr aData = data(); aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type()); - AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID()); - std::vector aRGB; - aRGB = Config_PropManager::color("Visualization", "result_construction_color", DEFAULT_COLOR()); - aColorAttr->setSize(3); - aColorAttr->setValue(0, aRGB[0]); - aColorAttr->setValue(1, aRGB[1]); - aColorAttr->setValue(2, aRGB[2]); +} + +void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "result_construction_color"; + theDefault = DEFAULT_COLOR(); } void Model_ResultConstruction::setShape(std::shared_ptr theShape) diff --git a/src/Model/Model_ResultConstruction.h b/src/Model/Model_ResultConstruction.h index 2fb81219d..8292e09bc 100644 --- a/src/Model/Model_ResultConstruction.h +++ b/src/Model/Model_ResultConstruction.h @@ -33,6 +33,10 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction /// Request for initialization of data model of the result: adding all attributes virtual void initAttributes(); + // Retuns the parameters of color definition in the resources config manager + MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + /// By default object is displayed in the object browser. MODEL_EXPORT virtual bool isInHistory() { diff --git a/src/Model/Model_ResultGroup.cpp b/src/Model/Model_ResultGroup.cpp index a0a5922cd..dd4ee732b 100644 --- a/src/Model/Model_ResultGroup.cpp +++ b/src/Model/Model_ResultGroup.cpp @@ -20,16 +20,17 @@ Model_ResultGroup::Model_ResultGroup(std::shared_ptr theOwnerData void Model_ResultGroup::initAttributes() { - // append the color attribute + // append the color attribute. It is empty, the attribute will be filled by a request DataPtr aData = data(); aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type()); - AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID()); - std::vector aRGB; - aRGB = Config_PropManager::color("Visualization", "result_group_color", DEFAULT_COLOR()); - aColorAttr->setSize(3); - aColorAttr->setValue(0, aRGB[0]); - aColorAttr->setValue(1, aRGB[1]); - aColorAttr->setValue(2, aRGB[2]); +} + +void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "result_group_color"; + theDefault = DEFAULT_COLOR(); } std::shared_ptr Model_ResultGroup::shape() diff --git a/src/Model/Model_ResultGroup.h b/src/Model/Model_ResultGroup.h index 33c0e17a7..7bfa79694 100644 --- a/src/Model/Model_ResultGroup.h +++ b/src/Model/Model_ResultGroup.h @@ -29,6 +29,10 @@ public: /// Request for initialization of data model of the result: adding all attributes virtual void initAttributes(); + // Retuns the parameters of color definition in the resources config manager + MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + /// Returns the compound of selected entities MODEL_EXPORT virtual std::shared_ptr shape(); diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index 776a28391..c02abf608 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -42,6 +42,9 @@ class ModelAPI_Result : public ModelAPI_Object myIsConcealed = theValue; } + // Retuns 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_Preferences.cpp b/src/ModuleBase/ModuleBase_Preferences.cpp index 4d4d1c78d..f97a9ed7f 100644 --- a/src/ModuleBase/ModuleBase_Preferences.cpp +++ b/src/ModuleBase/ModuleBase_Preferences.cpp @@ -261,6 +261,9 @@ void ModuleBase_PreferencesDlg::createViewerPage(int thePageId) myPreferences->setItemProperty("custom_enabled", false, bgId); myPreferences->setItemProperty("image_formats", aImgFiles, bgId); + //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color", + // Config_Prop::Color, "#ffffff"); + Config_PropManager::registerProp("Visualization", "result_body_color", "Body color", Config_Prop::Color, Model_ResultBody::DEFAULT_COLOR()); Config_PropManager::registerProp("Visualization", "result_group_color", "Group color", diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp index 1e7c4de3b..0737eb899 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp @@ -4,6 +4,7 @@ #include #include +#include SketchPlugin_SketchEntity::SketchPlugin_SketchEntity() : SketchPlugin_Feature() diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index c0c092563..11bc85e62 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -60,48 +60,52 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC } /// Customize presentation of the feature - virtual void customisePresentation(AISObjectPtr thePrs) + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) { - std::vector aRGB; - + bool isCustomized = false; int aShapeType = thePrs->getShapeType(); if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/) - return; + return false; + std::vector aColor; std::shared_ptr aConstructionAttr = - data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID()); + data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID()); bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value(); if (aShapeType == 6) { // if this is an edge if (isConstruction) { - thePrs->setWidth(1); - thePrs->setLineStyle(3); - aRGB = Config_PropManager::color("Visualization", "sketch_construction_color", - SKETCH_CONSTRUCTION_COLOR); + isCustomized = thePrs->setWidth(1) || isCustomized; + isCustomized = thePrs->setLineStyle(3) || isCustomized; + + aColor = Config_PropManager::color("Visualization", "sketch_construction_color", + SKETCH_CONSTRUCTION_COLOR); } else { - thePrs->setWidth(3); - thePrs->setLineStyle(0); + isCustomized = thePrs->setWidth(3) || isCustomized; + isCustomized = thePrs->setLineStyle(0) || isCustomized; + if (isExternal()) { // Set color from preferences - aRGB = Config_PropManager::color("Visualization", "sketch_external_color", - SKETCH_EXTERNAL_EDGE_COLOR); + aColor = Config_PropManager::color("Visualization", "sketch_external_color", + SKETCH_EXTERNAL_EDGE_COLOR); } else { // Set color from preferences - aRGB = Config_PropManager::color("Visualization", "sketch_edge_color", - SKETCH_EDGE_COLOR); + aColor = Config_PropManager::color("Visualization", "sketch_edge_color", + SKETCH_EDGE_COLOR); } } } else if (aShapeType == 7) { // otherwise this is a vertex // thePrs->setPointMarker(6, 2.); - // Set color from preferences - aRGB = Config_PropManager::color("Visualization", "sketch_point_color", - SKETCH_POINT_COLOR); + aColor = Config_PropManager::color("Visualization", "sketch_point_color", + SKETCH_POINT_COLOR); } - if (!aRGB.empty()) - thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]); + if (!aColor.empty()) { + isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized; + } + return isCustomized; } protected: diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index c7a27c716..bd843caa9 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -7,6 +7,7 @@ SET(PROJECT_HEADERS XGUI.h XGUI_ActionsMgr.h XGUI_ContextMenuMgr.h + XGUI_CustomPrs.h XGUI_DataTreeModel.h XGUI_Displayer.h XGUI_DocumentDataModel.h @@ -33,6 +34,7 @@ SET(PROJECT_AUTOMOC SET(PROJECT_SOURCES XGUI_ActionsMgr.cpp XGUI_ContextMenuMgr.cpp + XGUI_CustomPrs.cpp XGUI_Displayer.cpp XGUI_DocumentDataModel.cpp XGUI_ErrorDialog.cpp diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp new file mode 100644 index 000000000..8584bc554 --- /dev/null +++ b/src/XGUI/XGUI_CustomPrs.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: XGUI_CustomPrs.cpp +// Created: 10 Mar 2015 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include + +#include + + +void getColor(ResultPtr theResult, std::vector& theColor) +{ + theColor.clear(); + // get color from the attribute of the result + if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { + AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); + if (aColorAttr.get() && aColorAttr->size()) { + theColor.push_back(aColorAttr->value(0)); + theColor.push_back(aColorAttr->value(1)); + theColor.push_back(aColorAttr->value(2)); + } + } +} + +void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector& theColor) +{ + 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); + if (!aSection.empty() && !aName.empty()) { + theColor = Config_PropManager::color(aSection, aName, aDefault); + } + } + if (theColor.empty()) // all AIS objects, where the color is not set, a white. + // The color should be defined in XML or set in the attribute + theColor = Config_PropManager::color("Visualization", "object_default_color", "#ffffff"); +} + +bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theCustomPrs) +{ + std::vector aColor; + + getColor(theResult, aColor); + if (aColor.empty()) + getDefaultColor(theResult, thePrs, aColor); + + return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); +} diff --git a/src/XGUI/XGUI_CustomPrs.h b/src/XGUI/XGUI_CustomPrs.h new file mode 100644 index 000000000..97bc89133 --- /dev/null +++ b/src/XGUI/XGUI_CustomPrs.h @@ -0,0 +1,29 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: XGUI_CustomPrs.hxx +// Created: 10 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef XGUI_CustomPrs_H +#define XGUI_CustomPrs_H + +#include "XGUI.h" +#include +#include +#include + +/** +* Interface of a class which can provide specific customization of +* object presentation +*/ +class XGUI_CustomPrs : public GeomAPI_ICustomPrs +{ +public: + XGUI_EXPORT virtual ~XGUI_CustomPrs() {}; + + /// Modifies the given presentation in the custom way. + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theCustomPrs); +}; + +#endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 9d6884b92..1acdc22ea 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -9,6 +9,7 @@ #include "XGUI_ViewerProxy.h" #include "XGUI_SelectionMgr.h" #include "XGUI_Selection.h" +#include "XGUI_CustomPrs.h" #include @@ -72,6 +73,7 @@ XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) : myWorkshop(theWorkshop) { enableUpdateViewer(true); + myCustomPrs = std::shared_ptr(new XGUI_CustomPrs()); } XGUI_Displayer::~XGUI_Displayer() @@ -159,7 +161,10 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false); - customizeObject(theObject); + bool isCustomized = customizeObject(theObject); + if (isCustomized) + aContext->Redisplay(anAISIO, false); + if (aCanBeShaded) { openLocalContext(); activateObjects(myActiveSelectionModes); @@ -223,6 +228,7 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) // before and after the values modification. // Moreother, this check avoids customize and redisplay presentation if the presentable // parameter is changed. + bool isEqualShapes = false; ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (aResult.get() != NULL) { Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO); @@ -233,17 +239,17 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) std::shared_ptr anAISShapePtr(new GeomAPI_Shape()); anAISShapePtr->setImpl(new TopoDS_Shape(aShape)); - if (aShapePtr->isEqual(anAISShapePtr)) - return; + isEqualShapes = aShapePtr->isEqual(anAISShapePtr); } } } // Customization of presentation - customizeObject(theObject); - - aContext->Redisplay(aAISIO, false); - if (isUpdateViewer) - updateViewer(); + bool isCustomized = customizeObject(theObject); + if (!isEqualShapes || isCustomized) { + aContext->Redisplay(aAISIO, false); + if (isUpdateViewer) + updateViewer(); + } } } @@ -758,25 +764,24 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, } } -void XGUI_Displayer::customizeObject(ObjectPtr theObject) +bool XGUI_Displayer::customizeObject(ObjectPtr theObject) { + // we need not customize presentable objects + GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); + if (aPrs.get() != NULL) + return false; + AISObjectPtr anAISObj = getAISObject(theObject); // correct the result's color it it has the attribute ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get() != NULL && aResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { - AttributeIntArrayPtr aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID()); - if (aColorAttr.get() && aColorAttr->size()) { - int aRed = aColorAttr->value(0); - int aGreen = aColorAttr->value(1); - int aBlue = aColorAttr->value(2); - anAISObj->setColor(aRed, aGreen, aBlue); - } - } + // Customization of presentation + GeomCustomPrsPtr aCustomPrs = myCustomPrs; FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (aFeature.get() != NULL) { GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); if (aCustPrs.get() != NULL) - aCustPrs->customisePresentation(anAISObj); + aCustomPrs = aCustPrs; } + return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); } diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index e5ea6fd05..da11c4d8e 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -20,6 +20,8 @@ #include #include +#include + #include #include @@ -218,8 +220,9 @@ class XGUI_EXPORT XGUI_Displayer * 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 * \param theObject an object instance + * \return the true state if there is changes and the presentation is customized */ - void customizeObject(ObjectPtr theObject); + bool customizeObject(ObjectPtr theObject); protected: /// Reference to workshop @@ -228,6 +231,9 @@ class XGUI_EXPORT XGUI_Displayer /// A container for selection filters Handle(SelectMgr_AndFilter) myAndFilter; + /// A default custom presentation, which is used if the displayed feature is not a custom presentation + GeomCustomPrsPtr myCustomPrs; + /// Definition of a type of map which defines correspondance between objects and presentations typedef QMap ResultToAISMap; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 45f12d0d5..dc5436749 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1411,20 +1411,17 @@ bool XGUI_Workshop::canChangeColor() const //************************************************************** void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) { - // 1. find the initial value of the color - AttributeIntArrayPtr aColorAttr; - foreach(ObjectPtr anObj, theObjects) { - ResultPtr aResult = std::dynamic_pointer_cast(anObj); - if (aResult.get() != NULL) { - aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID()); - } + std::vector aColor; + foreach(ObjectPtr anObject, theObjects) { + + AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject); + aColor.resize(3); + anAISObj->getColor(aColor[0], aColor[1], aColor[2]); + if (!aColor.empty()) + break; } - // there is no object with the color attribute - if (aColorAttr.get() == NULL || aColorAttr->size() == 0) + if (aColor.size() != 3) return; - int aRed = aColorAttr->value(0); - int aGreen = aColorAttr->value(1); - int aBlue = aColorAttr->value(2); // 2. show the dialog to change the value QDialog* aDlg = new QDialog(); @@ -1434,7 +1431,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); aLay->addWidget(aColorBtn); - aColorBtn->setColor(QColor(aRed, aGreen, aBlue)); + aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2])); QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aDlg); @@ -1452,7 +1449,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) aGreenResult = aColorResult.green(), aBlueResult = aColorResult.blue(); - if (aRedResult == aRed && aGreenResult == aGreen && aBlueResult == aBlue) + if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2]) return; // 3. abort the previous operation and start a new one @@ -1465,6 +1462,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) // 4. set the value to all results static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); + AttributeIntArrayPtr aColorAttr; foreach(ObjectPtr anObj, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObj); if (aResult.get() != NULL) { -- 2.39.2