/// 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);
/// 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() {};
#include <QMap>\r
\r
#include <string>\r
+#include <vector>\r
#include <map>\r
\r
class QAction;\r
virtual AttributePtr findAttribute(const ObjectPtr& theObject,\r
const GeomShapePtr& theGeomShape) = 0;\r
\r
+ /// Returns color of the object\r
+ /// \param theObject a result of a feature object\r
+ /// \param theColor a vector of three values in [0, 255] range\r
+ virtual void getColor(const ObjectPtr& theObject, std::vector<int>& theColor) {}\r
+\r
/// Returns XML information by the feature index\r
/// \param theFeatureId a feature id\r
/// \param theXmlCfg XML configuration\r
PartSet_ExternalObjectsMgr.h
PartSet_Module.h
PartSet_OperationPrs.h
+ PartSet_OverconstraintListener.h
PartSet_Tools.h
PartSet_WidgetSketchLabel.h
PartSet_Validators.h
PartSet_ExternalObjectsMgr.cpp
PartSet_Module.cpp
PartSet_OperationPrs.cpp
+ PartSet_OverconstraintListener.cpp
PartSet_Tools.cpp
PartSet_WidgetSketchLabel.cpp
PartSet_Validators.cpp
#include <PartSet_CustomPrs.h>
#include <PartSet_Module.h>
#include "PartSet_OperationPrs.h"
+#include "PartSet_OverconstraintListener.h"
#include <XGUI_ModuleConnector.h>
#include <XGUI_Workshop.h>
#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
return false;
#endif
- return displayPresentation(theFlag, theUpdateViewer);
+ bool aRedisplayed = displayPresentation(theFlag, theUpdateViewer);
+
+ return aRedisplayed;
}
void PartSet_CustomPrs::clearPrs()
#include "PartSet_CustomPrs.h"
#include "PartSet_IconFactory.h"
#include "PartSet_WidgetChoice.h"
+#include "PartSet_OverconstraintListener.h"
#include "PartSet_Filters.h"
#include "PartSet_FilterInfinite.h"
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));
aFilter.Nullify();
}
delete myCustomPrs;
+ delete myOverconstraintListener;
}
void PartSet_Module::activateSelectionFilters()
return anAttribute;
}
+//******************************************************
+void PartSet_Module::getColor(const ObjectPtr& theObject, std::vector<int>& theColor)
+{
+ if (myOverconstraintListener->isConflictingObject(theObject)) {
+ myOverconstraintListener->getConflictingColor(theColor);
+ }
+}
+
//******************************************************
void PartSet_Module::onBooleanOperationChange(int theOperation)
{
#include "PartSet.h"
#include "PartSet_Tools.h"
+#include "PartSet_OverconstraintListener.h"
#include <ModuleBase_IModule.h>
#include <ModuleBase_Definitions.h>
/// 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();
/// \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<int>& 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,
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
--- /dev/null
+// 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 <GeomAPI_IPresentable.h>
+#include <ModelAPI_Events.h>
+#include <ModuleBase_Tools.h>
+
+#include <QString>
+
+#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<int>& 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<Events_Message>& 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<ModelAPI_SolverFailedMessage> anErrorMsg =
+ std::dynamic_pointer_cast<ModelAPI_SolverFailedMessage>(theMessage);
+ bool anUpdated = false;
+ if (anErrorMsg.get()) {
+ const std::set<ObjectPtr>& aConflictingObjects = anErrorMsg->objects();
+ anUpdated = updateConflictingObjects(aConflictingObjects);
+ }
+ else
+ anUpdated = updateConflictingObjects(std::set<ObjectPtr>());
+ }
+}
+
+bool PartSet_OverconstraintListener::updateConflictingObjects(
+ const std::set<ObjectPtr>& theConflictingObjects)
+{
+ std::set<ObjectPtr>::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<ObjectPtr> 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<ObjectPtr>& 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<ObjectPtr>::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<ObjectPtr>::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<GeomAPI_IPresentable>(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<Handle(AIS_InteractiveObject)>();
+ 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<XGUI_ModuleConnector*>(myWorkshop);
+ return aConnector->workshop();
+}
+
--- /dev/null
+// 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 <Events_Listener.h>
+#include <ModelAPI_Object.h>
+
+class ModuleBase_IWorkshop;
+class XGUI_Workshop;
+
+#include <vector>
+#include <set>
+
+/**
+* \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<int>& theColor);
+
+ /// Redefinition of Events_Listener method
+ virtual void processEvent(const std::shared_ptr<Events_Message>& 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<ObjectPtr>& 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<ObjectPtr>& theObjects);
+
+private:
+ //! Returns workshop
+ XGUI_Workshop* workshop() const;
+
+private:
+ std::set<ObjectPtr> myConflictingObjects;
+ ModuleBase_IWorkshop* myWorkshop;
+};
+
+#endif
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<ModelAPI_Data> aData = data();
if (!anAIS) {
anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane());
}
-
- // Set color from preferences
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
- SKETCH_DIMENSION_COLOR);
- anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
/// \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);
#include <ModelAPI_AttributeRefAttr.h>
#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_ICustomPrs.h>
#include <list>
* 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
/// \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<GeomAPI_ICustomPrs> theDefaultPrs)
+ {
+ return theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+ }
+
protected:
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintBase()
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()
{
if (!anAIS) {
anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane());
}
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
- SKETCH_DIMENSION_COLOR);
- anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
/// \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);
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<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
if (!anAIS) {
anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane());
}
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
- SKETCH_DIMENSION_COLOR);
- anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
/// \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);
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<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
if (!anAIS) {
anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane());
}
-
- // Set color from preferences
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
- SKETCH_DIMENSION_COLOR);
- anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
/// \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);
// Author: Natalia ERMOLAEVA
#include <XGUI_CustomPrs.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
+#include <ModuleBase_IModule.h>
#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Session.h>
}
}
-void getDefaultColor(ResultPtr theResult, std::vector<int>& theColor)
+void getDefaultColor(ObjectPtr theObject, std::vector<int>& 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");
}
}
+XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
+: myWorkshop(theWorkshop)
+{
+}
+
void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& 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<GeomAPI_ICustomPrs> theCustomPrs)
{
- std::vector<int> aColor;
+ bool aCustomized = false;
+ if (theResult.get()) {
+ std::vector<int> 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<int> 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;
}
#include <GeomAPI_AISObject.h>
#include <ModelAPI_Result.h>
+class XGUI_Workshop;
+
/**
* Interface of a class which can provide specific customization of
* object presentation
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.
/// \param theResult a result object
/// \param theColor a color in form of RGB vector
static void getResultColor(ResultPtr theResult, std::vector<int>& theColor);
+
+protected:
+ XGUI_Workshop* myWorkshop; /// the current workshop
};
#endif
myIsTrihedronActive(false)
{
enableUpdateViewer(true);
- myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
+ myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs(theWorkshop));
}
XGUI_Displayer::~XGUI_Displayer()