From: nds Date: Fri, 6 Mar 2015 17:38:22 +0000 (+0300) Subject: Change color action for a body object X-Git-Tag: V_1.1.0~145^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d4d711626f3e49ad0fa0af3efef0945b04ebfd2;p=modules%2Fshaper.git Change color action for a body object Customize object correction in order to take into account the color of the result if it has been set. --- diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 6135ea32d..88e8d599c 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -157,13 +158,8 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, aContext->Display(anAISIO, false); aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false); - // Customization of presentation - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get() != NULL) { - GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); - if (aCustPrs.get() != NULL) - aCustPrs->customisePresentation(theAIS); - } + + customizeObject(theObject); if (aCanBeShaded) { openLocalContext(); activateObjects(myActiveSelectionModes); @@ -243,12 +239,7 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) } } // Customization of presentation - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get() != NULL) { - GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); - if (aCustPrs.get() != NULL) - aCustPrs->customisePresentation(aAISObj); - } + customizeObject(theObject); aContext->Redisplay(aAISIO, false); if (isUpdateViewer) @@ -766,3 +757,27 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, } } } + +void XGUI_Displayer::customizeObject(ObjectPtr theObject) +{ + 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) { + int aRed, aGreen, aBlue; + + AttributeColorPtr aColorAttr = std::dynamic_pointer_cast( + aResult->data()->attribute(ModelAPI_Result::COLOR_ID())); + aColorAttr->values(aRed, aGreen, aBlue); + anAISObj->setColor(aRed, aGreen, aBlue); + } + else { + // Customization of presentation + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get() != NULL) { + GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); + if (aCustPrs.get() != NULL) + aCustPrs->customisePresentation(anAISObj); + } + } +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 85900ddb3..e5ea6fd05 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -214,6 +214,13 @@ class XGUI_EXPORT XGUI_Displayer /// Opens local context. Does nothing if it is already opened. void openLocalContext(); + /** 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 + * \param theObject an object instance + */ + void customizeObject(ObjectPtr theObject); + protected: /// Reference to workshop XGUI_Workshop* myWorkshop;