The default custom presentation to customize the AIS object color if there is no a customizer realized with the feature of the object.
}
}
-void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
- std::vector<int> 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;
}
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <GeomAPI_ICustomPrs.h>
/**\class ConstructionPlugin_Axis
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; }
ConstructionPlugin_Axis();
/// Customize presentation of the feature
- virtual void customisePresentation(AISObjectPtr thePrs);
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
};
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAPI_Pnt2d.h>
}
}
-void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
- std::vector<int> 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<int> 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;
}
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <GeomAPI_ICustomPrs.h>
ConstructionPlugin_Plane();
/// Customize presentation of the feature
- virtual void customisePresentation(AISObjectPtr thePrs);
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
};
#endif
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());
}
aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
setResult(aConstr);
}
-
-void ConstructionPlugin_Point::customisePresentation(AISObjectPtr thePrs)
-{
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_point_color",
- ConstructionPlugin_Point::DEFAULT_COLOR());
- thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
- thePrs->redisplay();
-}
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
/**\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
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()
{
/// Use plugin manager for features creation
ConstructionPlugin_Point();
-
- /// Modifies the given presentation in the custom way.
- virtual void customisePresentation(AISObjectPtr thePrs);
-
};
#endif
importFile(aFilePath);
}
-void ExchangePlugin_ImportFeature::customisePresentation(AISObjectPtr thePrs)
-{
- std::vector<int> 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
#include <ExchangePlugin.h>
#include <ModelAPI_Feature.h>
-
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
#include <map>
-#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
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);
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)
#include <AIS_FixRelation.hxx>
#include <Prs3d_PointAspect.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+
const double tolerance = 1e-7;
const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint
}
}
-void GeomAPI_AISObject::redisplay()
-{
- Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
- 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<Handle(AIS_InteractiveObject)>();
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<Handle(AIS_InteractiveObject)>();
- 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<Handle(AIS_InteractiveObject)>();
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()) {
}
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<Handle(AIS_InteractiveObject)>();
+ 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
}
}
-
-void GeomAPI_AISObject::setLineStyle(int theStyle)
+bool GeomAPI_AISObject::setLineStyle(int theStyle)
{
+ bool isChanged = false;
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
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<Handle(AIS_InteractiveObject)>();
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;
}
void createFixed(std::shared_ptr<GeomAPI_Shape> theShape,
std::shared_ptr<GeomAPI_Pln> 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;
/// 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
#include "GeomAPI.h"
#include "GeomAPI_AISObject.h"
+#include "GeomAPI_AISObject.h"
+#include <vector>
/**
* 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<ModelAPI_Result> theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs) = 0;
};
typedef std::shared_ptr<GeomAPI_ICustomPrs> GeomCustomPrsPtr;
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<int> 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<GeomAPI_Shape>& theShape)
/// 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<GeomAPI_Shape>& theShape);
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<int> 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<GeomAPI_Shape> theShape)
/// 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()
{
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<int> 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<GeomAPI_Shape> Model_ResultGroup::shape()
/// 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<GeomAPI_Shape> shape();
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() {};
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",
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeIntArray.h>
SketchPlugin_SketchEntity::SketchPlugin_SketchEntity()
: SketchPlugin_Feature()
}
/// Customize presentation of the feature
- virtual void customisePresentation(AISObjectPtr thePrs)
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
- std::vector<int> aRGB;
-
+ bool isCustomized = false;
int aShapeType = thePrs->getShapeType();
if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
- return;
+ return false;
+ std::vector<int> aColor;
std::shared_ptr<ModelAPI_AttributeBoolean> 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:
XGUI.h
XGUI_ActionsMgr.h
XGUI_ContextMenuMgr.h
+ XGUI_CustomPrs.h
XGUI_DataTreeModel.h
XGUI_Displayer.h
XGUI_DocumentDataModel.h
SET(PROJECT_SOURCES
XGUI_ActionsMgr.cpp
XGUI_ContextMenuMgr.cpp
+ XGUI_CustomPrs.cpp
XGUI_Displayer.cpp
XGUI_DocumentDataModel.cpp
XGUI_ErrorDialog.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: XGUI_CustomPrs.cpp
+// Created: 10 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <XGUI_CustomPrs.h>
+
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+#include <vector>
+
+
+void getColor(ResultPtr theResult, std::vector<int>& 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<int>& 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<GeomAPI_ICustomPrs> theCustomPrs)
+{
+ std::vector<int> aColor;
+
+ getColor(theResult, aColor);
+ if (aColor.empty())
+ getDefaultColor(theResult, thePrs, aColor);
+
+ return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+}
--- /dev/null
+// 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 <GeomAPI_ICustomPrs.h>
+#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Result.h>
+
+/**
+* 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<GeomAPI_ICustomPrs> theCustomPrs);
+};
+
+#endif
#include "XGUI_ViewerProxy.h"
#include "XGUI_SelectionMgr.h"
#include "XGUI_Selection.h"
+#include "XGUI_CustomPrs.h"
#include <AppElements_Viewer.h>
: myWorkshop(theWorkshop)
{
enableUpdateViewer(true);
+ myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
}
XGUI_Displayer::~XGUI_Displayer()
aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
- customizeObject(theObject);
+ bool isCustomized = customizeObject(theObject);
+ if (isCustomized)
+ aContext->Redisplay(anAISIO, false);
+
if (aCanBeShaded) {
openLocalContext();
activateObjects(myActiveSelectionModes);
// 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<ModelAPI_Result>(theObject);
if (aResult.get() != NULL) {
Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
std::shared_ptr<GeomAPI_Shape> 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();
+ }
}
}
}
}
-void XGUI_Displayer::customizeObject(ObjectPtr theObject)
+bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
{
+ // we need not customize presentable objects
+ GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(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<ModelAPI_Result>(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<GeomAPI_ICustomPrs>(aFeature);
if (aCustPrs.get() != NULL)
- aCustPrs->customisePresentation(anAISObj);
+ aCustomPrs = aCustPrs;
}
+ return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
}
#include <ModuleBase_Definitions.h>
#include <ModuleBase_ViewerPrs.h>
+#include <GeomAPI_ICustomPrs.h>
+
#include <SelectMgr_AndFilter.hxx>
#include <QString>
* 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
/// 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<ObjectPtr, AISObjectPtr> ResultToAISMap;
//**************************************************************
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<ModelAPI_Result>(anObj);
- if (aResult.get() != NULL) {
- aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
- }
+ std::vector<int> 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();
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);
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
// 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<ModelAPI_Result>(anObj);
if (aResult.get() != NULL) {