From 59d7c196ce4f5ed43cb550ee5caecd68676abfb3 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 15 Oct 2019 15:33:31 +0300 Subject: [PATCH] A new event Visual Attributes Changed is defined for performance sake. --- src/Config/Config_Keywords.h | 1 + src/Model/Model_AttributeIntArray.cpp | 6 +- src/Model/Model_AttributeIntArray.h | 3 +- src/ModelAPI/ModelAPI_AttributeIntArray.h | 3 +- src/ModelAPI/ModelAPI_Events.h | 3 + src/ModelAPI/ModelAPI_Tools.cpp | 47 ++++ src/ModelAPI/ModelAPI_Tools.h | 20 ++ src/ModuleBase/ModuleBase_IModule.cpp | 11 +- src/ModuleBase/ModuleBase_IModule.h | 30 +- src/ModuleBase/ModuleBase_ModelWidget.cpp | 20 +- src/ModuleBase/ModuleBase_ModelWidget.h | 2 + src/ModuleBase/ModuleBase_Tools.cpp | 1 + .../ModuleBase_WidgetMultiSelector.cpp | 10 +- src/PartSet/PartSet_CustomPrs.cpp | 24 +- src/PartSet/PartSet_Module.cpp | 260 ++++++++++++------ src/PartSet/PartSet_Module.h | 25 +- .../PartSet_OverconstraintListener.cpp | 3 +- src/PartSet/PartSet_OverconstraintListener.h | 8 + src/PartSet/PartSet_SketcherMgr.cpp | 190 +++++++++++-- src/PartSet/PartSet_SketcherMgr.h | 12 +- src/PartSet/PartSet_Tools.cpp | 57 ++++ src/PartSet/PartSet_Tools.h | 21 +- .../SketchPlugin_ConstraintAngle.cpp | 3 + .../SketchPlugin_ConstraintDistance.cpp | 3 + ...ketchPlugin_ConstraintDistanceAlongDir.cpp | 3 + .../SketchPlugin_ConstraintLength.cpp | 3 + .../SketchPlugin_ConstraintRadius.cpp | 3 + src/SketchPlugin/SketchPlugin_Fillet.cpp | 5 + src/SketchPlugin/SketchPlugin_MacroArc.cpp | 1 + src/SketchPlugin/SketchPlugin_MacroCircle.cpp | 4 + .../SketchPlugin_MacroEllipse.cpp | 4 + .../SketchPlugin_MacroEllipticArc.cpp | 1 + src/SketchPlugin/SketchPlugin_Projection.cpp | 7 + src/SketchPlugin/SketchPlugin_Sketch.h | 26 +- src/SketchPlugin/SketchPlugin_SketchEntity.h | 198 ++++++------- src/SketchPlugin/SketchPlugin_Tools.cpp | 26 ++ src/SketchPlugin/SketchPlugin_Tools.h | 10 +- src/SketchPlugin/plugin-Sketch.xml | 31 ++- src/XGUI/CMakeLists.txt | 2 - src/XGUI/XGUI_CustomPrs.cpp | 193 ------------- src/XGUI/XGUI_CustomPrs.h | 80 ------ src/XGUI/XGUI_Displayer.cpp | 174 ++++++------ src/XGUI/XGUI_Displayer.h | 5 - src/XGUI/XGUI_ObjectsBrowser.cpp | 3 + src/XGUI/XGUI_Workshop.cpp | 23 +- src/XGUI/XGUI_WorkshopListener.cpp | 39 ++- src/XGUI/XGUI_WorkshopListener.h | 2 +- 47 files changed, 916 insertions(+), 690 deletions(-) delete mode 100644 src/XGUI/XGUI_CustomPrs.cpp delete mode 100644 src/XGUI/XGUI_CustomPrs.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 0a8f4aba4..32132a196 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -104,6 +104,7 @@ const static char* ATTR_GREED = "greed"; const static char* ATTR_MODIFIED_IN_EDIT = "modified_in_edit"; const static char* ATTR_MAIN_ARG = "main_argument"; const static char* ATTR_GEOMETRICAL_SELECTION = "geometrical_selection"; +const static char* ATTR_VISUAL_CHANGED = "change_visual_attributes"; // WDG_INFO properties diff --git a/src/Model/Model_AttributeIntArray.cpp b/src/Model/Model_AttributeIntArray.cpp index 3ee99ee6a..b8da16945 100644 --- a/src/Model/Model_AttributeIntArray.cpp +++ b/src/Model/Model_AttributeIntArray.cpp @@ -68,11 +68,13 @@ void Model_AttributeIntArray::setSize(const int theSize) } void Model_AttributeIntArray::setValue(const int theIndex, - const int theValue) + const int theValue, + bool sendUpdated) { if (myArray->Value(theIndex) != theValue) { myArray->SetValue(theIndex, theValue); - owner()->data()->sendAttributeUpdated(this); + if (sendUpdated) + owner()->data()->sendAttributeUpdated(this); } } diff --git a/src/Model/Model_AttributeIntArray.h b/src/Model/Model_AttributeIntArray.h index 1243a14ce..1c7d10166 100644 --- a/src/Model/Model_AttributeIntArray.h +++ b/src/Model/Model_AttributeIntArray.h @@ -51,7 +51,8 @@ class Model_AttributeIntArray : public ModelAPI_AttributeIntArray /// Defines the value of the array by index [0; size-1] MODEL_EXPORT virtual void setValue(const int theIndex, - const int theValue); + const int theValue, + bool sendUpdated = true); /// Returns the value by the index MODEL_EXPORT virtual int value(const int theIndex); diff --git a/src/ModelAPI/ModelAPI_AttributeIntArray.h b/src/ModelAPI/ModelAPI_AttributeIntArray.h index d0fd38c50..b8b146ff2 100644 --- a/src/ModelAPI/ModelAPI_AttributeIntArray.h +++ b/src/ModelAPI/ModelAPI_AttributeIntArray.h @@ -44,7 +44,8 @@ class ModelAPI_AttributeIntArray : public ModelAPI_Attribute /// Defines the value of the array by index [0; size-1] MODELAPI_EXPORT virtual void setValue(const int theIndex, - const int theValue) = 0; + const int theValue, + bool sendUpdated = true) = 0; /// Returns the value by the index MODELAPI_EXPORT virtual int value(const int theIndex) = 0; diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index f424d4214..0b250ebd5 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -107,6 +107,9 @@ static const char * EVENT_GET_DOF_OBJECTS = "GetDoFObjects"; /// Event ID that provides a request for list of non-fixed objects necessary for DoF = 0 static const char * EVENT_DOF_OBJECTS = "DoFObjects"; +/// Event ID that requests updates visual attributes for presentations +static const char * EVENT_VISUAL_ATTRIBUTES = "UpdateVisualAttributes"; + /// Message that feature was changed (used for Object Browser update): moved, updated and deleted class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup { diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index c6b8a6f72..728c00951 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -784,4 +785,50 @@ void removeResults(const std::list& theResults) } } +double getDeflection(const std::shared_ptr& theResult) +{ + double aDeflection = -1; + // get deflection from the attribute of the result + if (theResult.get() != NULL && + theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) { + AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); + if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) { + double aValue = aDoubleAttr->value(); + if (aValue > 0) /// zero value should not be used as a deflection(previous studies) + aDeflection = aDoubleAttr->value(); + } + } + return aDeflection; +} + + +void getColor(const std::shared_ptr& 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)); + } + } +} + +double getTransparency(const std::shared_ptr& theResult) +{ + double aTransparency = -1; + // get transparency from the attribute of the result + if (theResult.get() != NULL && + theResult->data()->attribute(ModelAPI_Result::TRANSPARENCY_ID()).get() != NULL) { + AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID()); + if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) { + aTransparency = aDoubleAttr->value(); + } + } + return aTransparency; +} + } // namespace ModelAPI_Tools diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 6b4d31f84..83fbdb888 100644 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -209,6 +209,26 @@ MODELAPI_EXPORT std::set > /*! Creates a remove result features with the given results */ MODELAPI_EXPORT void removeResults(const std::list >& theResults); + +/*! Returns current deflection in the given result +* \param theResult a result object +* \return a deflection value or -1 if it was not defined +*/ +MODELAPI_EXPORT double getDeflection(const std::shared_ptr& theResult); + +/*! Returns current color of the current result +* \param[in] theResult a result object +* \param[out] theColor a color values if it is defined +*/ +MODELAPI_EXPORT void getColor(const std::shared_ptr& theResult, + std::vector& theColor); + +/*! Returns current transparency in the given result +* \param theResult a result object +* \return a transparency value or -1 if it was not defined +*/ +MODELAPI_EXPORT double getTransparency(const std::shared_ptr& theResult); + } #endif diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 03abb8233..f3314ca2a 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -159,9 +159,9 @@ void ModuleBase_IModule::launchOperation(const QString& theCmdId, } } -Handle(AIS_InteractiveObject) ModuleBase_IModule::createPresentation(const ObjectPtr& theResult) +AISObjectPtr ModuleBase_IModule::createPresentation(const ObjectPtr& theResult) { - return Handle(AIS_InteractiveObject)(); + return AISObjectPtr(); } bool ModuleBase_IModule::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const @@ -186,13 +186,6 @@ ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& the return new ModuleBase_OperationFeature(theFeatureId.c_str(), this); } -bool ModuleBase_IModule::customizeObject(ObjectPtr theObject, - const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag, - const bool theUpdateViewer) -{ - return false; -} - ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId) { ModuleBase_OperationFeature* aFOperation = dynamic_cast diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index b748d6a14..d2ce9c4a9 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -277,14 +277,14 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject const bool theUpdateViewer) {} /// Modifies the given presentation in the custom way. - virtual bool customisePresentation(std::shared_ptr theResult, - AISObjectPtr thePrs, - GeomCustomPrsPtr theCustomPrs) { return false; }; + //virtual bool customisePresentation(std::shared_ptr theResult, + // AISObjectPtr thePrs, + // GeomCustomPrsPtr theCustomPrs) { return false; }; - /// Modifies the given presentation in the custom way after usual customize is performed. - virtual bool afterCustomisePresentation(std::shared_ptr theResult, - AISObjectPtr thePrs, - GeomCustomPrsPtr theCustomPrs) { return false; }; + ///// Modifies the given presentation in the custom way after usual customize is performed. + //virtual bool afterCustomisePresentation(std::shared_ptr theResult, + // AISObjectPtr thePrs, + // GeomCustomPrsPtr theCustomPrs) { return false; }; /// 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, @@ -294,8 +294,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// should be updated(e.g. only highlighted elements) /// \param theUpdateViewer the parameter whether the viewer should be update immediately /// \returns true if the object is modified - virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag, - const bool theUpdateViewer); + virtual bool customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer) { + return false; + } /// Disable displaying of custom mode /// \param theMode a mode to disable @@ -312,10 +314,16 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theCmdId the operation name virtual ModuleBase_Operation* createOperation(const std::string& theCmdId); - /// Create specific for the module presentation + /// Create specific for the module presentation. The presentation has to be + /// customized accordingly to the object. /// \param theResult an object for presentation /// \return created presentation or NULL(default value) - virtual Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult); + virtual AISObjectPtr createPresentation(const ObjectPtr& theResult); + + /// Customize presentation according to objects attributes + /// \param theObject an object for presentation + /// \param thePrs a presentation object + virtual void customizePresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const {} //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 89546edfd..a563c2779 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -50,13 +50,13 @@ //************************************************************** ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, - const Config_WidgetAPI* theData) - : QWidget(theParent), - myIsEditing(false), - myState(Stored), - myIsValueStateBlocked(false), - myFlushUpdateBlocked(false), - myWidgetValidator(0) + const Config_WidgetAPI* theData) + : QWidget(theParent), + myIsEditing(false), + myState(Stored), + myIsValueStateBlocked(false), + myFlushUpdateBlocked(false), + myWidgetValidator(0) { #ifdef DEBUG_WIDGET_INSTANCE qDebug("ModuleBase_ModelWidget::ModuleBase_ModelWidget"); @@ -68,6 +68,8 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, myIsModifiedInEdit = theData->getProperty(ATTR_MODIFIED_IN_EDIT); + myUpdateVisualAttributes = theData->getBooleanAttribute(ATTR_VISUAL_CHANGED, false); + myDefaultValue = theData->getProperty(ATTR_DEFAULT); myUseReset = theData->getBooleanAttribute(ATTR_USE_RESET, true); myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED; @@ -437,6 +439,10 @@ void ModuleBase_ModelWidget::updateObject(ObjectPtr theObject) #ifdef DEBUG_WIDGET_INSTANCE qDebug("ModuleBase_ModelWidget::updateObject"); #endif + if (myFeature.get() && myUpdateVisualAttributes) { + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES); + ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent); + } ModuleBase_Tools::flushUpdated(theObject); emit objectUpdated(); } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index fdd467481..4fb4ad552 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -445,6 +445,8 @@ private: bool myIsValueStateBlocked; /// do not flush updated signal bool myFlushUpdateBlocked; + + bool myUpdateVisualAttributes; }; #endif diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 2d6e80670..b8f595cb3 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -760,6 +760,7 @@ void flushUpdated(ObjectPtr theObject) // (for the sketch result) to start processing of the sketch in the solver. // TODO: these flushes should be moved in a separate method provided by Model Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES)); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 43b380cf7..bb68bed95 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -409,7 +409,7 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList theValues.append(anInvalidValues); if (isDone) // may be the feature's result is not displayed, but attributes should be - myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments, + myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, true);/// hope that something is redisplayed by object updated return isDone; @@ -553,7 +553,7 @@ bool ModuleBase_WidgetMultiSelector::processDelete() myWorkshop->setSelected(getAttributeSelection()); // may be the feature's result is not displayed, but attributes should be - myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments, + myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, true); /// hope that something is redisplayed by object updated } @@ -616,7 +616,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() restoreValue(); myWorkshop->setSelected(getAttributeSelection()); // may be the feature's result is not displayed, but attributes should be - myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments, + myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, true); /// hope that something is redisplayed by object updated // clear history should follow after set selected to do not increase history by setSelected clearSelectedHistory(); @@ -853,8 +853,8 @@ void ModuleBase_WidgetMultiSelector::onDeleteItem() //******************************************************************** void ModuleBase_WidgetMultiSelector::onListSelection() { - myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects, - true); + myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects, + true); } //******************************************************************** diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index 21465eb1c..e18ca5bb0 100644 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -17,10 +17,11 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include -#include +#include "PartSet_CustomPrs.h" +#include "PartSet_Module.h" #include "PartSet_OperationPrs.h" #include "PartSet_OverconstraintListener.h" +#include "PartSet_SketcherMgr.h" #include #include @@ -30,6 +31,9 @@ #include #include +#include +#include + #include #include #include @@ -68,12 +72,22 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION return false; #endif + bool isModified = false; - myIsActive[theFlag] = true; - myFeature = theFeature; + // Do not call customisation for sketcher and all its sub-objects + if (theFeature->getKind() == SketchPlugin_Sketch::ID()) + return isModified; + + FeaturePtr aParent = ModelAPI_Tools::compositeOwner(theFeature); + if (aParent.get()) { + std::string aType = aParent->getKind(); + if (aType == SketchPlugin_Sketch::ID()) + return isModified; + } - bool isModified = false; if (theFeature.get()) { + myIsActive[theFlag] = true; + myFeature = theFeature; displayPresentation(theFlag, theUpdateViewer); isModified = true; } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 0ad3ce8f2..5245438e5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -67,8 +67,9 @@ #include #include #include -#include +#include +#include #include #include #include @@ -80,6 +81,7 @@ #include #include #include +#include #include #include @@ -89,7 +91,6 @@ #include #include #include -#include #include #include #include @@ -191,6 +192,26 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) setDefaultConstraintShown(); + //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color", + // Config_Prop::Color, "225,225,225"); + + Config_PropManager::registerProp("Visualization", "result_body_color", "Result color", + Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR()); + + Config_PropManager::registerProp("Visualization", "result_group_color", "Group color", + Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR()); + + Config_PropManager::registerProp("Visualization", "result_construction_color", + "Construction color", + Config_Prop::Color, + ModelAPI_ResultConstruction::DEFAULT_COLOR()); + + Config_PropManager::registerProp("Visualization", "result_part_color", "Part color", + Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR()); + + Config_PropManager::registerProp("Visualization", "result_field_color", "Field color", + Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR()); + Config_PropManager::registerProp("Visualization", "operation_parameter_color", "Reference shape wireframe color in operation", Config_Prop::Color, PartSet_CustomPrs::OPERATION_PARAMETER_COLOR()); @@ -1166,75 +1187,75 @@ void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag } //****************************************************** -bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theCustomPrs) -{ - bool aCustomized = false; - - XGUI_Workshop* aWorkshop = getWorkshop(); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - ObjectPtr anObject = aDisplayer->getObject(thePrs); - if (!anObject) - return aCustomized; - - if (!theResult.get()) { - std::vector aColor; - XGUI_CustomPrs::getDefaultColor(anObject, true, aColor); - if (!aColor.empty()) { - aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); - } - } - // customize dimentional constrains - sketchMgr()->customizePresentation(anObject); - - return aCustomized; -} - -//****************************************************** -bool PartSet_Module::afterCustomisePresentation(std::shared_ptr theResult, - AISObjectPtr thePrs, - GeomCustomPrsPtr theCustomPrs) -{ - bool aCustomized = false; - - XGUI_Workshop* aWorkshop = getWorkshop(); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - ObjectPtr anObject = aDisplayer->getObject(thePrs); - if (!anObject) - return aCustomized; - - std::vector aColor; - bool aUseCustomColor = true; - if (aUseCustomColor) - myOverconstraintListener->getCustomColor(anObject, aColor); - // customize sketch symbol presentation - Handle(AIS_InteractiveObject) anAISIO = thePrs->impl(); - if (!anAISIO.IsNull()) { - if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) { - Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO); - if (!aPrs.IsNull()) { - aPrs->SetCustomColor(aColor); - aCustomized = true; - } - } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) { - Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO); - if (!aPrs.IsNull()) { - aPrs->SetCustomColor(aColor); - aCustomized = true; - } - } - } - // customize sketch dimension constraint presentation - if (!aCustomized) { - if (!aColor.empty()) { // otherwise presentation has the default color - aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); - } - } - return aCustomized; -} - -//****************************************************** -bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag, +//bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, +// std::shared_ptr theCustomPrs) +//{ +// bool aCustomized = false; +// +// XGUI_Workshop* aWorkshop = getWorkshop(); +// XGUI_Displayer* aDisplayer = aWorkshop->displayer(); +// ObjectPtr anObject = aDisplayer->getObject(thePrs); +// if (!anObject) +// return aCustomized; +// +// if (!theResult.get()) { +// std::vector aColor; +// XGUI_CustomPrs::getDefaultColor(anObject, true, aColor); +// if (!aColor.empty()) { +// aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); +// } +// } +// // customize dimentional constrains +// sketchMgr()->customisePresentation(anObject); +// +// return aCustomized; +//} +// +////****************************************************** +//bool PartSet_Module::afterCustomisePresentation(std::shared_ptr theResult, +// AISObjectPtr thePrs, +// GeomCustomPrsPtr theCustomPrs) +//{ +// bool aCustomized = false; +// +// XGUI_Workshop* aWorkshop = getWorkshop(); +// XGUI_Displayer* aDisplayer = aWorkshop->displayer(); +// ObjectPtr anObject = aDisplayer->getObject(thePrs); +// if (!anObject) +// return aCustomized; +// +// std::vector aColor; +// bool aUseCustomColor = true; +// if (aUseCustomColor) +// myOverconstraintListener->getCustomColor(anObject, aColor); +// // customize sketch symbol presentation +// Handle(AIS_InteractiveObject) anAISIO = thePrs->impl(); +// if (!anAISIO.IsNull()) { +// if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) { +// Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO); +// if (!aPrs.IsNull()) { +// aPrs->SetCustomColor(aColor); +// aCustomized = true; +// } +// } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) { +// Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO); +// if (!aPrs.IsNull()) { +// aPrs->SetCustomColor(aColor); +// aCustomized = true; +// } +// } +// } +// // customize sketch dimension constraint presentation +// if (!aCustomized) { +// if (!aColor.empty()) { // otherwise presentation has the default color +// aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); +// } +// } +// return aCustomized; +//} + +//****************************************************** +bool PartSet_Module::customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag, const bool theUpdateViewer) { bool isRedisplayed = false; @@ -1279,21 +1300,100 @@ void PartSet_Module::onActiveDocPopup(const QPoint& thePnt) } //****************************************************** -Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject) +AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject) +{ + Handle(AIS_InteractiveObject) anAISPrs = mySketchMgr->createPresentation(theObject); + if (anAISPrs.IsNull()) { + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); + if (aShapePtr.get() != NULL) + anAISPrs = new ModuleBase_ResultPrs(aResult); + } + else { + FieldStepPtr aStep = + std::dynamic_pointer_cast(theObject); + if (aStep.get()) { + anAISPrs = new PartSet_FieldStepPrs(aStep); + } + } + } + AISObjectPtr anAIS; + if (!anAISPrs.IsNull()) { + Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs); + if (!aShapePrs.IsNull()) + ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get()); + + anAIS = AISObjectPtr(new GeomAPI_AISObject()); + anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); + customizePresentation(theObject, anAIS); + } + return anAIS; +} + +//****************************************************** +void getResultColor(const ResultPtr& theResult, std::vector& theColor) { - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get()) - return mySketchMgr->createPresentation(aResult); + ModelAPI_Tools::getColor(theResult, theColor); + if (theColor.empty()) + PartSet_Tools::getDefaultColor(theResult, false, theColor); +} + +//****************************************************** +double getResultDeflection(const ResultPtr& theResult) +{ + double aDeflection = ModelAPI_Tools::getDeflection(theResult); + if (aDeflection < 0) + aDeflection = PartSet_Tools::getDefaultDeflection(theResult); + return aDeflection; +} + +//****************************************************** +double getResultTransparency(const ResultPtr& theResult) +{ + double aTransparency = ModelAPI_Tools::getTransparency(theResult); + if (aTransparency < 0) + aTransparency = PartSet_Tools::getDefaultTransparency(); + return aTransparency; +} + + +//****************************************************** +void PartSet_Module::customizePresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const +{ + if (mySketchMgr->isSketchStarted()) { + mySketchMgr->customizeSketchPresentation(theObject, thePrs); + } else { - FieldStepPtr aStep = - std::dynamic_pointer_cast(theObject); - if (aStep.get()) { - return new PartSet_FieldStepPrs(aStep); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + std::vector aColor; + getResultColor(aResult, aColor); + + SessionPtr aMgr = ModelAPI_Session::get(); + if (aMgr->activeDocument() != aResult->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(); + } + thePrs->setColor(aColor[0], aColor[1], aColor[2]); + + thePrs->setDeflection(getResultDeflection(aResult)); + + thePrs->setTransparency(getResultTransparency(aResult)); + } + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get()) { + if (aFeature->getKind() == SketchPlugin_Sketch::ID()) + thePrs->setWidth(2); } } - return Handle(AIS_InteractiveObject)(); } + //****************************************************** ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index bcd16ee17..5a6d25cc7 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -290,14 +290,14 @@ public: const bool theUpdateViewer); /// Modifies the given presentation in the custom way. - virtual bool customisePresentation(std::shared_ptr theResult, - AISObjectPtr thePrs, - std::shared_ptr theCustomPrs); + //virtual bool customisePresentation(std::shared_ptr theResult, + // AISObjectPtr thePrs, + // std::shared_ptr theCustomPrs); - /// Modifies the given presentation in the custom way after usual customize is performed. - virtual bool afterCustomisePresentation(std::shared_ptr theResult, - AISObjectPtr thePrs, - GeomCustomPrsPtr theCustomPrs); + ///// Modifies the given presentation in the custom way after usual customize is performed. + //virtual bool afterCustomisePresentation(std::shared_ptr theResult, + // AISObjectPtr thePrs, + // GeomCustomPrsPtr theCustomPrs); /// 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, @@ -307,8 +307,8 @@ public: /// should be updated(e.g. only highlighted elements) /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly /// \returns true if the object is modified - virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag, - const bool theUpdateViewer); + virtual bool customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag, + const bool theUpdateViewer); /// Disable displaying of custom mode /// \param theMode a mode to disable @@ -327,7 +327,12 @@ public: /// Create specific for the module presentation /// \param theResult an object for presentation /// \return created presentation or NULL(default value) - virtual Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult); + virtual AISObjectPtr createPresentation(const ObjectPtr& theResult); + + /// Customize presentation according to objects attributes + /// \param theObject an object for presentation + /// \param thePrs a presentation object + virtual void customizePresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const; //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const; diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 59fbfa96e..70c19725c 100644 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -25,7 +25,6 @@ #include #include -#include "XGUI_CustomPrs.h" #include "XGUI_Displayer.h" #include "XGUI_ModuleConnector.h" #include "XGUI_OperationMgr.h" @@ -284,7 +283,7 @@ void PartSet_OverconstraintListener::redisplayObjects( { static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_VISUAL_ATTRIBUTES); static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); std::set::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); diff --git a/src/PartSet/PartSet_OverconstraintListener.h b/src/PartSet/PartSet_OverconstraintListener.h index 5481f9d94..a02dee98e 100644 --- a/src/PartSet/PartSet_OverconstraintListener.h +++ b/src/PartSet/PartSet_OverconstraintListener.h @@ -58,6 +58,14 @@ public: /// Redefinition of Events_Listener method virtual void processEvent(const std::shared_ptr& theMessage); + + bool isConflictingObject(const ObjectPtr& theObject) const + { + return (myConflictingObjects.find(theObject) != myConflictingObjects.end()); + } + + bool isFullyConstrained() const { return myIsFullyConstrained; } + protected: /// Append objects to the internal container of conflicting object, redisplay necessary objects /// \param theObjects a list of new conflicting objects diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index aa639e247..ea764c531 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -172,7 +172,8 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false), myDragDone(false), myIsMouseOverWindow(false), myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true), - myIsPopupMenuActive(false), myExternalPointsMgr(0), myNoDragMoving(false) + myIsPopupMenuActive(false), myExternalPointsMgr(0), myNoDragMoving(false), + myIsSketchStarted(false) { ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); ModuleBase_IViewer* aViewer = anIWorkshop->viewer(); @@ -470,8 +471,9 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); + ModuleBase_IViewer* aViewer = aWorkshop->viewer(); if (myIsDragging) - aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled); + aViewer->enableDrawMode(myPreviousDrawModeEnabled); bool aWasDragging = myIsDragging; myIsDragging = false; @@ -483,11 +485,10 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse if (!myIsMouseOverViewProcessed) { return; } - ModuleBase_IViewer* aViewer = aWorkshop->viewer(); //if (!aViewer->canDragByMouse()) // return; ModuleBase_OperationFeature* aOp = - dynamic_cast(getCurrentOperation()); + dynamic_cast(getCurrentOperation()); if (aOp) { bool aStartNoDragOperation = !aViewer->canDragByMouse() && aOp->isEditOperation(); if (aStartNoDragOperation || myNoDragMoving) { @@ -887,13 +888,15 @@ void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSke theModes.append(TopAbs_EDGE); } -Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult) +Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ObjectPtr& theObj) { Handle(AIS_InteractiveObject) aPrs; - FeaturePtr aFeature = ModelAPI_Feature::feature(theResult); + FeaturePtr aFeature = ModelAPI_Feature::feature(theObj); if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) { - aPrs = new PartSet_ResultSketchPrs(theResult); + ResultPtr aResult = std::dynamic_pointer_cast(theObj); + if (aResult.get()) + aPrs = new PartSet_ResultSketchPrs(aResult); } return aPrs; } @@ -995,11 +998,15 @@ bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind) void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) { + static Events_ID EVENT_ATTR = Events_Loop::loop()->eventByName(EVENT_VISUAL_ATTRIBUTES); + static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + ModuleBase_OperationFeature* aFOperation = dynamic_cast (getCurrentOperation()); if (!aFOperation) return; + myIsSketchStarted = true; SketcherPrs_Tools::setPixelRatio(ModuleBase_Tools::currentPixelRatio()); myModule->onViewTransformed(); @@ -1067,7 +1074,6 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) myModule->overconstraintListener()->setActive(true); // Display sketcher objects QStringList anInfo; - Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); aNumberOfSubs = myCurrentSketch->numberOfSubs(); for (int i = 0; i < aNumberOfSubs; i++) { @@ -1088,6 +1094,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) aECreator->sendUpdated(aFeature, EVENT_DISP); else aFeature->setDisplayed(true); + aECreator->sendUpdated(aFeature, EVENT_ATTR); } #ifdef DEBUG_SKETCHER_ENTITIES QString anInfoStr = anInfo.join(";\t"); @@ -1104,7 +1111,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) workshop()->selectionActivate()->updateSelectionFilters(); workshop()->selectionActivate()->updateSelectionModes(); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + Events_Loop::loop()->flush(EVENT_DISP); + Events_Loop::loop()->flush(EVENT_ATTR); myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch); @@ -1121,6 +1129,8 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) myModule->workshop()->viewer()->setFitter(0); delete aFitter; + myIsSketchStarted = false; + myIsMouseOverWindow = false; myIsConstraintsShown[PartSet_Tools::Geometrical] = true; myIsConstraintsShown[PartSet_Tools::Dimensional] = true; @@ -1779,26 +1789,26 @@ void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState) } } -void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject) -{ - ModuleBase_OperationFeature* aFOperation = dynamic_cast - (getCurrentOperation()); - if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) || - isNestedSketchOperation(aFOperation))) - SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]); - - // update entities selection priorities - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) { - // update priority for feature - updateSelectionPriority(aFeature, aFeature); - // update priority for results of the feature - std::list aResults = aFeature->results(); - std::list::const_iterator anIt = aResults.begin(), aLastIt = aResults.end(); - for (; anIt != aLastIt; anIt++) - updateSelectionPriority(*anIt, aFeature); - } -} +//void PartSet_SketcherMgr::customisePresentation(const ObjectPtr& theObject) +//{ +// ModuleBase_OperationFeature* aFOperation = dynamic_cast +// (getCurrentOperation()); +// if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) || +// isNestedSketchOperation(aFOperation))) +// SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]); +// +// // update entities selection priorities +// FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); +// if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) { +// // update priority for feature +// updateSelectionPriority(aFeature, aFeature); +// // update priority for results of the feature +// std::list aResults = aFeature->results(); +// std::list::const_iterator anIt = aResults.begin(), aLastIt = aResults.end(); +// for (; anIt != aLastIt; anIt++) +// updateSelectionPriority(*anIt, aFeature); +// } +//} ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const { @@ -2142,6 +2152,128 @@ void PartSet_SketcherMgr::processEvent(const std::shared_ptr& th } } +bool isExternal(const ObjectPtr& theObject) +{ + AttributeSelectionPtr aAttr = + theObject->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); + if (aAttr) + return aAttr->context().get() != NULL && !aAttr->isInvalid(); + return false; +} + +bool isCopy(const ObjectPtr& theObject) +{ + AttributeBooleanPtr anAttr = theObject->data()->boolean(SketchPlugin_SketchEntity::COPY_ID()); + if (anAttr.get()) + return anAttr->value(); + return false; +} + +bool isIncludeToResult(const ObjectPtr& theObject) +{ + AttributeBooleanPtr anAttr; + std::set aRefsToMe = theObject->data()->refsToMe(); + std::set::const_iterator aIt; + for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) { + if ((*aIt)->id() == SketchPlugin_Projection::PROJECTED_FEATURE_ID()) { + FeaturePtr aFeature = std::dynamic_pointer_cast((*aIt)->owner()); + if (aFeature.get()) { + anAttr = aFeature->data()->boolean(SketchPlugin_Projection::INCLUDE_INTO_RESULT()); + if (anAttr.get()) + return anAttr->value(); + } + } + } + return true; +} + + +void PartSet_SketcherMgr::customizeSketchPresentation(const ObjectPtr& theObject, + const AISObjectPtr& thePrs) const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + PartSet_OverconstraintListener* aOCListener = myModule->overconstraintListener(); + + // Check constraints objects + const QStringList& aConstrIds = constraintsIdList(); + std::string aKind = aFeature->getKind(); + if (aConstrIds.contains(QString(aKind.c_str()))) { + std::vector aColor; + if (aOCListener->isConflictingObject(theObject)) + aColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color"); + else if (isDistanceKind(aKind)) + aColor = Config_PropManager::color("Visualization", "sketch_dimension_color"); + + if (!aColor.empty()) + thePrs->setColor(aColor[0], aColor[1], aColor[2]); + return; + } + int aShapeType = thePrs->getShapeType(); + // a compound is processed like the edge because the + // arc feature uses the compound for presentable AIS + if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/) + return; + + // set color from preferences + std::shared_ptr anAuxiliaryAttr = + aFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID()); + bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value(); + + std::vector aColor; + if (aOCListener->isFullyConstrained()) + aColor = Config_PropManager::color("Visualization", "sketch_fully_constrained_color"); + else if (aOCListener->isConflictingObject(theObject)) + aColor = Config_PropManager::color("Visualization", "sketch_overconstraint_color"); + else { + if (isConstruction) + aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color"); + else if (isExternal(aFeature)) + aColor = Config_PropManager::color("Visualization", "sketch_external_color"); + else + aColor = Config_PropManager::color("Visualization", "sketch_entity_color"); + } + if (!aColor.empty()) { + // The code below causes redisplay again + if (ModelAPI_Session::get()->isOperation()) { + AttributeIntArrayPtr aColorAttr = theObject->data()->intArray(ModelAPI_Result::COLOR_ID()); + if (aColorAttr.get()) { + aColorAttr->setSize(3); + // Set the color attribute in order do not use default colors in the presentation object + for (int i = 0; i < 3; i++) + aColorAttr->setValue(i, aColor[i], false); + } + } + thePrs->setColor(aColor[0], aColor[1], aColor[2]); + } + + if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound + if (isConstruction) { + // Set axilliary line + thePrs->setWidth(SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY()); + thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY()); + } + else { + int aWidth = Config_PropManager::integer("Visualization", "sketch_line_width"); + thePrs->setWidth(aWidth); + thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE()); + } + } + else if (aShapeType == 7) { // otherwise this is a vertex + // The width value do not have effect on the point presentation. + // It is defined in order to extend selection area of the object. + thePrs->setWidth(17); + // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol + } + if (isCopy(aFeature) && !isIncludeToResult(aFeature)) { + double aWidth = thePrs->width(); + thePrs->setWidth(aWidth / 2.5); + } + + double aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); + thePrs->setDeflection(aDeflection); +} + +//************************************************************************************* void PartSet_Fitter::fitAll(Handle(V3d_View) theView) { CompositeFeaturePtr aSketch = mySketchMgr->activeSketch(); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 24e6347d1..9336fdbf2 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -36,6 +36,7 @@ #include #include +#include #ifdef HAVE_SALOME #include @@ -344,7 +345,7 @@ public: /// Create specific for the module presentation /// \param theResult an object for presentation /// \return created presentation or NULL(default value) - virtual Handle(AIS_InteractiveObject) createPresentation(const ResultPtr& theResult); + Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult); /// Connects or disconnects to the value changed signal of the property panel widgets /// \param theWidget a property contol widget @@ -358,7 +359,9 @@ public: /// If the current operation is a dimention one, the style of dimension visualization is send for /// the current object /// \param theObject an object to be customized - void customizePresentation(const ObjectPtr& theObject); + //void customisePresentation(const ObjectPtr& theObject); + + void customizeSketchPresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const; /// Update sketch presentations according to the the state /// \param theType a type of sketch visualization style @@ -377,6 +380,9 @@ public: */ virtual void processEvent(const std::shared_ptr& theMessage); + bool isSketchStarted() const { return myIsSketchStarted; } + + public slots: /// Process sketch plane selected event void onPlaneSelected(const std::shared_ptr& thePln); @@ -502,6 +508,8 @@ private: QMap myPointsHighlight; bool myNoDragMoving; + + bool myIsSketchStarted; }; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 3ef5b735f..376bce7ce 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -36,6 +36,7 @@ #include #include +#include #include @@ -53,6 +54,7 @@ #include #include #include +#include #include #include @@ -790,3 +792,58 @@ void PartSet_Tools::getFirstAndLastIndexInFolder(const ObjectPtr& theFolder, theFirst = aDoc->index(aFirstFeatureInFolder); theLast = aDoc->index(aLastFeatureInFolder); } + + +void PartSet_Tools::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, + std::vector& theColor) +{ + theColor.clear(); + // get default color from the preferences manager for the given result + if (theColor.empty()) { + std::string aSection, aName, aDefault; + theObject->colorConfigInfo(aSection, aName, aDefault); + if (!aSection.empty() && !aName.empty()) { + theColor = Config_PropManager::color(aSection, aName); + } + } + 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"); + Events_InfoMessage("PartSet_Tools", + "A default color is not defined in the preferences for this result type").send(); + } +} + +double PartSet_Tools::getDefaultDeflection(const ObjectPtr& theObject) +{ + double aDeflection = -1; + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + bool isConstruction = false; + + std::string aResultGroup = aResult->groupName(); + if (aResultGroup == ModelAPI_ResultConstruction::group()) + isConstruction = true; + else if (aResultGroup == ModelAPI_ResultBody::group()) { + GeomShapePtr aGeomShape = aResult->shape(); + if (aGeomShape.get()) { + // if the shape could not be exploded on faces, it contains only wires, edges, and vertices + // correction of deviation for them should not influence to the application performance + GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE); + isConstruction = !anExp.more(); + } + } + if (isConstruction) + aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); + else + aDeflection = Config_PropManager::real("Visualization", "body_deflection"); + } + return aDeflection; +} + + +double PartSet_Tools::getDefaultTransparency() +{ + return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.; +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 0de36c1e2..7f1c236ab 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -297,7 +297,26 @@ public: FeaturePtr& theCreatedFeature); - static void getFirstAndLastIndexInFolder(const ObjectPtr& theFolder, int& theFirst, int& theLast); + static void getFirstAndLastIndexInFolder(const ObjectPtr& theFolder, + int& theFirst, int& theLast); + + + /** + * Returns default color value for the given object + */ + static void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, + std::vector& theColor); + + /** + * Returns default deflection value for the given object + */ + static double getDefaultDeflection(const ObjectPtr& theObject); + + + /** + * Returns default transparency value + */ + static double getDefaultTransparency(); }; #endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 2bfd5c34b..e769c019c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -19,6 +19,7 @@ #include "SketchPlugin_ConstraintAngle.h" #include +#include #include #include @@ -117,6 +118,8 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious AISObjectPtr anAIS = SketcherPrs_Factory::angleConstraint(this, sketch(), thePrevious); + if (anAIS.get() && !thePrevious.get()) + SketchPlugin_Tools::setDimensionColor(anAIS); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 16a0451d4..391c10162 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,8 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch(), thePrevious); + if (anAIS.get() && !thePrevious.get()) + SketchPlugin_Tools::setDimensionColor(anAIS); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp index 3357d5819..bd45029ba 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp @@ -22,6 +22,7 @@ // Author: Artem ZHIDKOV #include +#include #include #include @@ -84,6 +85,8 @@ AISObjectPtr SketchPlugin_ConstraintDistanceAlongDir::getAISObject(AISObjectPtr AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch(), thePrevious); + if (anAIS.get() && !thePrevious.get()) + SketchPlugin_Tools::setDimensionColor(anAIS); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 1ba4aa081..ad6ee92b5 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -19,6 +19,7 @@ #include "SketchPlugin_ConstraintLength.h" #include +#include #include @@ -171,6 +172,8 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch(), thePrevious); + if (anAIS.get() && !thePrevious.get()) + SketchPlugin_Tools::setDimensionColor(anAIS); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index b27190e0a..a58609b2d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -177,6 +178,8 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou AISObjectPtr anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch(), thePrevious); + if (anAIS.get() && !thePrevious.get()) + SketchPlugin_Tools::setDimensionColor(anAIS); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_Fillet.cpp b/src/SketchPlugin/SketchPlugin_Fillet.cpp index e076f47c2..9507cad1a 100644 --- a/src/SketchPlugin/SketchPlugin_Fillet.cpp +++ b/src/SketchPlugin/SketchPlugin_Fillet.cpp @@ -193,6 +193,11 @@ AISObjectPtr SketchPlugin_Fillet::getAISObject(AISObjectPtr thePrevious) anAISObject = AISObjectPtr(new GeomAPI_AISObject); } anAISObject->createShape(anArcShape); + bool isAxiliary = false; + AttributeBooleanPtr aAttr = boolean(AUXILIARY_ID()); + if (aAttr.get()) + isAxiliary = aAttr->value(); + SketchPlugin_Tools::customizeFeaturePrs(anAISObject, isAxiliary); return anAISObject; } diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.cpp b/src/SketchPlugin/SketchPlugin_MacroArc.cpp index f0379c461..eab082403 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroArc.cpp @@ -297,6 +297,7 @@ AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious) anAIS.reset(new GeomAPI_AISObject()); } anAIS->createShape(aCompound); + SketchPlugin_Tools::customizeFeaturePrs(anAIS, boolean(AUXILIARY_ID())->value()); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_MacroCircle.cpp b/src/SketchPlugin/SketchPlugin_MacroCircle.cpp index 0bcabf4ff..7a0572702 100644 --- a/src/SketchPlugin/SketchPlugin_MacroCircle.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroCircle.cpp @@ -389,6 +389,10 @@ AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious) anAIS.reset(new GeomAPI_AISObject()); } anAIS->createShape(aCompound); + + // Modify attributes + SketchPlugin_Tools::customizeFeaturePrs(anAIS, boolean(AUXILIARY_ID())->value()); + return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp index e1e79e3ae..2cf1cbc7f 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp @@ -380,5 +380,9 @@ AISObjectPtr SketchPlugin_MacroEllipse::getAISObject(AISObjectPtr thePrevious) if (!anAIS) anAIS.reset(new GeomAPI_AISObject()); anAIS->createShape(aCompound); + + // Modify attributes + SketchPlugin_Tools::customizeFeaturePrs(anAIS, boolean(AUXILIARY_ID())->value()); + return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipticArc.cpp b/src/SketchPlugin/SketchPlugin_MacroEllipticArc.cpp index 984a75926..bd8290c0c 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipticArc.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroEllipticArc.cpp @@ -350,6 +350,7 @@ AISObjectPtr SketchPlugin_MacroEllipticArc::getAISObject(AISObjectPtr thePreviou if (!anAIS) anAIS.reset(new GeomAPI_AISObject()); anAIS->createShape(aCompound); + SketchPlugin_Tools::customizeFeaturePrs(anAIS, boolean(AUXILIARY_ID())->value()); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index 79eb675ca..e04031fee 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -35,6 +35,9 @@ #include #include #include +#include + +#include #include #include @@ -51,6 +54,7 @@ static const double tolerance = 1.e-7; + SketchPlugin_Projection::SketchPlugin_Projection() : SketchPlugin_SketchEntity(), myIsComputing(false) @@ -371,6 +375,9 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) setResult(aResult); GeomShapePtr anEmptyVal; aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), anEmptyVal); + + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES); + ModelAPI_EventCreator::get()->sendUpdated(aProjection, anEvent, false); } } } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 7f63c5bb2..6feda008d 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -43,7 +43,7 @@ * \ingroup Plugins * \brief Feature for creation of the new part in PartSet. */ -class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICustomPrs +class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_ICustomPrs { public: /// Sketch feature kind @@ -257,18 +257,18 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu static std::shared_ptr plane(SketchPlugin_Sketch* theSketch); /// Customize presentation of the feature - virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) - { - bool isCustomized = false; - // apply the color of the result to the presentation - if (theDefaultPrs.get()) - isCustomized = theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); - // set the sketch presentation bold - isCustomized = thePrs->setWidth(2) || isCustomized; - - return isCustomized; - } + //virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + // std::shared_ptr theDefaultPrs) + //{ + // bool isCustomized = false; + // // apply the color of the result to the presentation + // if (theDefaultPrs.get()) + // isCustomized = theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + // // set the sketch presentation bold + // isCustomized = thePrs->setWidth(2) || isCustomized; + + // return isCustomized; + //} private: /// Substitute all links to external objects by newly created features. diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index b915d8540..cae07149d 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -41,7 +41,7 @@ * This is an abstract class to give * an interface to create the entity features such as line, circle, arc and point. */ -class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs +class SketchPlugin_SketchEntity : public SketchPlugin_Feature //, public GeomAPI_ICustomPrs { public: /// Reference to the construction type of the feature @@ -66,13 +66,13 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC } /// Width of the auxiliary line - inline static const double SKETCH_LINE_WIDTH_AUXILIARY() + inline static const int SKETCH_LINE_WIDTH_AUXILIARY() { return 2; } /// Width of the line - inline static const double SKETCH_LINE_WIDTH() + inline static const int SKETCH_LINE_WIDTH() { return Config_PropManager::integer("Visualization", "sketch_line_width"); } @@ -111,105 +111,105 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC return false; } - virtual bool isIncludeToResult() const - { - AttributeBooleanPtr anAttr; - std::set aRefsToMe = data()->refsToMe(); - std::set::const_iterator aIt; - for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) { - if ((*aIt)->id() == "ProjectedFeature") { - FeaturePtr aFeature = std::dynamic_pointer_cast((*aIt)->owner()); - if (aFeature.get()) { - anAttr = aFeature->data()->boolean("IncludeToResult"); - if (anAttr.get()) - return anAttr->value(); - } - } - } - return true; - } + //virtual bool isIncludeToResult() const + //{ + // AttributeBooleanPtr anAttr; + // std::set aRefsToMe = data()->refsToMe(); + // std::set::const_iterator aIt; + // for (aIt = aRefsToMe.cbegin(); aIt != aRefsToMe.cend(); ++aIt) { + // if ((*aIt)->id() == "ProjectedFeature") { + // FeaturePtr aFeature = std::dynamic_pointer_cast((*aIt)->owner()); + // if (aFeature.get()) { + // anAttr = aFeature->data()->boolean("IncludeToResult"); + // if (anAttr.get()) + // return anAttr->value(); + // } + // } + // } + // return true; + //} // LCOV_EXCL_START /// Customize presentation of the feature - virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) - { - /// Store previous color values of the presentation to check it after setting specific entity - /// color. Default color is set into presentation to have not modified isCustomized state - /// after default customize prs is completed. - std::vector aPrevColor; - aPrevColor.resize(3); - thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]); - if (theResult.get()) { - std::string aSection, aName, aDefault; - theResult->colorConfigInfo(aSection, aName, aDefault); - std::vector aColor; - aColor = Config_PropManager::color(aSection, aName); - thePrs->setColor(aColor[0], aColor[1], aColor[2]); - } - - bool isCustomized = theDefaultPrs.get() != NULL && - theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); - int aShapeType = thePrs->getShapeType(); - // a compound is processed like the edge because the - // arc feature uses the compound for presentable AIS - if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/) - return false; - - // set color from preferences - std::vector aColor; - std::shared_ptr anAuxiliaryAttr = - data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID()); - bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value(); - if (isConstruction) { - aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color"); - } - else if (isExternal()) { - aColor = Config_PropManager::color("Visualization", "sketch_external_color"); - } - else { - aColor = Config_PropManager::color("Visualization", "sketch_entity_color"); - } - if (!aColor.empty()) { - if (theResult.get() && ModelAPI_Session::get()->isOperation()) { - AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); - aColorAttr->setSize(3); - // Set the color attribute in order do not use default colors in the presentation object - for (int i = 0; i < 3; i++) - aColorAttr->setValue(i, aColor[i]); - } - thePrs->setColor(aColor[0], aColor[1], aColor[2]); - for (int i = 0; i < 3 && !isCustomized; i++) - isCustomized = aColor[i] != aPrevColor[i]; - } - - if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound - if (isConstruction) { - isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized; - isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized; - } - else { - isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized; - isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized; - } - } - else if (aShapeType == 7) { // otherwise this is a vertex - // The width value do not have effect on the point presentation. - // It is defined in order to extend selection area of the object. - thePrs->setWidth(17); - // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol - } - if(isCopy() && !isIncludeToResult()) { - double aWidth = thePrs->width(); - isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized; - } - - if (!theResult.get()) { - double aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); - thePrs->setDeflection(aDeflection); - } - return isCustomized; - } + //virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + // std::shared_ptr theDefaultPrs) + //{ + // /// Store previous color values of the presentation to check it after setting specific entity + // /// color. Default color is set into presentation to have not modified isCustomized state + // /// after default customize prs is completed. + // std::vector aPrevColor; + // aPrevColor.resize(3); + // thePrs->getColor(aPrevColor[0], aPrevColor[1], aPrevColor[2]); + // if (theResult.get()) { + // std::string aSection, aName, aDefault; + // theResult->colorConfigInfo(aSection, aName, aDefault); + // std::vector aColor; + // aColor = Config_PropManager::color(aSection, aName); + // thePrs->setColor(aColor[0], aColor[1], aColor[2]); + // } + + // bool isCustomized = theDefaultPrs.get() != NULL && + // theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + // int aShapeType = thePrs->getShapeType(); + // // a compound is processed like the edge because the + // // arc feature uses the compound for presentable AIS + // if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/) + // return false; + + // // set color from preferences + // std::vector aColor; + // std::shared_ptr anAuxiliaryAttr = + // data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID()); + // bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value(); + // if (isConstruction) { + // aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color"); + // } + // else if (isExternal()) { + // aColor = Config_PropManager::color("Visualization", "sketch_external_color"); + // } + // else { + // aColor = Config_PropManager::color("Visualization", "sketch_entity_color"); + // } + // if (!aColor.empty()) { + // if (theResult.get() && ModelAPI_Session::get()->isOperation()) { + // AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); + // aColorAttr->setSize(3); + // // Set the color attribute in order do not use default colors in the presentation object + // for (int i = 0; i < 3; i++) + // aColorAttr->setValue(i, aColor[i]); + // } + // thePrs->setColor(aColor[0], aColor[1], aColor[2]); + // for (int i = 0; i < 3 && !isCustomized; i++) + // isCustomized = aColor[i] != aPrevColor[i]; + // } + + // if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound + // if (isConstruction) { + // isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH_AUXILIARY()) || isCustomized; + // isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE_AUXILIARY()) || isCustomized; + // } + // else { + // isCustomized = thePrs->setWidth(SKETCH_LINE_WIDTH()) || isCustomized; + // isCustomized = thePrs->setLineStyle(SKETCH_LINE_STYLE()) || isCustomized; + // } + // } + // else if (aShapeType == 7) { // otherwise this is a vertex + // // The width value do not have effect on the point presentation. + // // It is defined in order to extend selection area of the object. + // thePrs->setWidth(17); + // // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol + // } + // if(isCopy() && !isIncludeToResult()) { + // double aWidth = thePrs->width(); + // isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized; + // } + + // if (!theResult.get()) { + // double aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); + // thePrs->setDeflection(aDeflection); + // } + // return isCustomized; + //} // LCOV_EXCL_STOP protected: diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index a285ea243..0147ba521 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -537,6 +537,32 @@ GeomPnt2dPtr flyoutPointCoordinates(const ConstraintPtr& theConstraint) return GeomPnt2dPtr(new GeomAPI_Pnt2d(X, Y)); } + +void customizeFeaturePrs(const AISObjectPtr& thePrs, bool isAxiliary) +{ + std::vector aColor; + int aWidth = 1; + if (isAxiliary) { + thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY()); + aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color"); + aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY(); + } + else { + thePrs->setLineStyle(SketchPlugin_SketchEntity::SKETCH_LINE_STYLE()); + aColor = Config_PropManager::color("Visualization", "sketch_entity_color"); + aWidth = Config_PropManager::integer("Visualization", "sketch_line_width"); + } + thePrs->setWidth(aWidth); + thePrs->setColor(aColor[0], aColor[1], aColor[2]); +} + +void setDimensionColor(const AISObjectPtr& theDimPrs) +{ + std::vector aColor = Config_PropManager::color("Visualization", "sketch_dimension_color"); + if (aColor.size() == 3) + theDimPrs->setColor(aColor[0], aColor[1], aColor[2]); +} + } // namespace SketchPlugin_Tools diff --git a/src/SketchPlugin/SketchPlugin_Tools.h b/src/SketchPlugin/SketchPlugin_Tools.h index f29e192df..a45ecf05a 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.h +++ b/src/SketchPlugin/SketchPlugin_Tools.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -135,9 +136,16 @@ void convertRefAttrToPointOrTangentCurve(const AttributeRefAttrPtr& theRefA std::shared_ptr& theTangentCurve, std::shared_ptr& thePassingPoint); - /// Calculate global coordinates for flyout point of Length constraint GeomPnt2dPtr flyoutPointCoordinates(const std::shared_ptr& theConstraint); + +/// Sets attributes of feature presentation +/// \param[in] thePrs a presentation +/// \param[in] isAxiliary is axiliary flag +void customizeFeaturePrs(const AISObjectPtr& thePrs, bool isAxiliary); + +void setDimensionColor(const AISObjectPtr& theDimPrs); + }; // namespace SketchPlugin_Tools namespace SketchPlugin_SegmentationTools diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 1476a1492..69f43adf8 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -35,7 +35,7 @@ helpfile="pointFeature.html"> - + @@ -47,7 +47,7 @@ enable_value="enable_by_preferences"/> - + @@ -71,7 +71,7 @@ accept_expressions="0" enable_value="enable_by_preferences"> - + + obligatory="0" + change_visual_attributes="true"/> @@ -188,7 +189,8 @@ label="Auxiliary" tooltip="Construction element" default="false" - obligatory="0"/> + obligatory="0" + change_visual_attributes="true"/> @@ -313,7 +315,8 @@ label="Auxiliary" tooltip="Construction element" default="false" - obligatory="0"/> + obligatory="0" + change_visual_attributes="true"/> @@ -388,7 +391,7 @@ accept_expressions="0" enable_value="enable_by_preferences"> - + + obligatory="0" + change_visual_attributes="true"/> @@ -534,7 +538,7 @@ accept_expressions="0" enable_value="enable_by_preferences"> - + + obligatory="0" + change_visual_attributes="true"/> @@ -645,7 +650,8 @@ use_sketch_plane="false"> - + @@ -666,7 +672,8 @@ use_sketch_plane="false"> - + diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 28eda1784..2d9b66911 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -36,7 +36,6 @@ SET(PROJECT_HEADERS XGUI_ActiveControlSelector.h XGUI_ColorDialog.h XGUI_ContextMenuMgr.h - XGUI_CustomPrs.h XGUI_DataModel.h XGUI_DeflectionDialog.h XGUI_Displayer.h @@ -104,7 +103,6 @@ SET(PROJECT_SOURCES XGUI_ActiveControlMgr.cpp XGUI_ColorDialog.cpp XGUI_ContextMenuMgr.cpp - XGUI_CustomPrs.cpp XGUI_DataModel.cpp XGUI_DeflectionDialog.cpp XGUI_Displayer.cpp diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp deleted file mode 100644 index f3bd68300..000000000 --- a/src/XGUI/XGUI_CustomPrs.cpp +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#include -#include - -double getDeflection(const ResultPtr& theResult) -{ - double aDeflection = -1; - // get deflection from the attribute of the result - if (theResult.get() != NULL && - theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) { - AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); - if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) { - double aValue = aDoubleAttr->value(); - if (aValue > 0) /// zero value should not be used as a deflection(previous studies) - aDeflection = aDoubleAttr->value(); - } - } - return aDeflection; -} - -void getColor(const 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 XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, - std::vector& theColor) -{ - theColor.clear(); - // get default color from the preferences manager for the given result - if (theColor.empty()) { - std::string aSection, aName, aDefault; - theObject->colorConfigInfo(aSection, aName, aDefault); - if (!aSection.empty() && !aName.empty()) { - theColor = Config_PropManager::color(aSection, aName); - } - } - 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"); - Events_InfoMessage("XGUI_CustomPrs", - "A default color is not defined in the preferences for this kind of result").send(); - } -} - -double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject) -{ - double aDeflection = -1; - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get()) { - bool isConstruction = false; - - std::string aResultGroup = aResult->groupName(); - if (aResultGroup == ModelAPI_ResultConstruction::group()) - isConstruction = true; - else if (aResultGroup == ModelAPI_ResultBody::group()) { - GeomShapePtr aGeomShape = aResult->shape(); - if (aGeomShape.get()) { - // if the shape could not be exploded on faces, it contains only wires, edges, and vertices - // correction of deviation for them should not influence to the application performance - GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE); - isConstruction = !anExp.more(); - } - } - if (isConstruction) - aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); - else - aDeflection = Config_PropManager::real("Visualization", "body_deflection"); - } - return aDeflection; -} - -double getTransparency(const ResultPtr& theResult) -{ - double aTransparency = -1; - // get transparency from the attribute of the result - if (theResult.get() != NULL && - theResult->data()->attribute(ModelAPI_Result::TRANSPARENCY_ID()).get() != NULL) { - AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID()); - if (aDoubleAttr.get() && aDoubleAttr->isInitialized()) { - aTransparency = aDoubleAttr->value(); - } - } - return aTransparency; -} - -double getDefaultTransparency(const ResultPtr& theResult) -{ - return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.; -} - -XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop) -: myWorkshop(theWorkshop) -{ -} - -void XGUI_CustomPrs::getResultColor(const ResultPtr& theResult, std::vector& theColor) -{ - getColor(theResult, theColor); - if (theColor.empty()) - getDefaultColor(theResult, false, theColor); -} - -double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult) -{ - double aDeflection = getDeflection(theResult); - if (aDeflection < 0) - aDeflection = getDefaultDeflection(theResult); - return aDeflection; -} - -double XGUI_CustomPrs::getResultTransparency(const ResultPtr& theResult) -{ - double aTransparency = getTransparency(theResult); - if (aTransparency < 0) - aTransparency = getDefaultTransparency(theResult); - return aTransparency; -} - -bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theCustomPrs) -{ - bool aCustomized = false; - if (theResult.get()) { - std::vector 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(); - } - aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]); - - aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized; - - aCustomized = thePrs->setTransparency(getResultTransparency(theResult)) | aCustomized; - } - ModuleBase_IModule* aModule = myWorkshop->module(); - aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized; - return aCustomized; -} diff --git a/src/XGUI/XGUI_CustomPrs.h b/src/XGUI/XGUI_CustomPrs.h deleted file mode 100644 index 62d18d335..000000000 --- a/src/XGUI/XGUI_CustomPrs.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef XGUI_CustomPrs_H -#define XGUI_CustomPrs_H - -#include "XGUI.h" -#include -#include -#include - -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. - virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theCustomPrs); - - /// Returns color of a result object - /// \param theResult a result object - /// \param theColor a color in form of RGB vector - static void getResultColor(const ResultPtr& theResult, std::vector& theColor); - - /// Returns deflection of a result object - /// \param theResult a result object - /// \return theDeflection a real value - static double getResultDeflection(const ResultPtr& theResult); - - /// Returns transparency of a result object - /// \param theResult a result object - /// \return theTransparency a real value - static double getResultTransparency(const ResultPtr& theResult); - - /// Returns the default object color. It obtains colorConfigInfo of the object - /// and find it in preferences. If there are no this color in preference and an empty - /// color is interpreted as invalid, it shows error message - /// \param theObject an investigated object - /// \param isEmptyColorValid boolean state about interpretation of empty color - /// \param theColor the result color - static void XGUI_EXPORT getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, - std::vector& theColor); - - /// Returns the default deflection value. The value is obtained from the application preferences - /// \param theObject an investigated object - /// \return deflection value - static double XGUI_EXPORT getDefaultDeflection(const ObjectPtr& theObject); - -protected: - XGUI_Workshop* myWorkshop; ///< the current workshop -}; - -#endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index ccad93e0e..c96dd3e7c 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -19,7 +19,6 @@ #include "XGUI_Displayer.h" -#include "XGUI_CustomPrs.h" #include "XGUI_FacesPanel.h" #include "XGUI_Selection.h" #include "XGUI_SelectionActivate.h" @@ -42,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -125,7 +123,6 @@ XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) : myWorkshop(theWorkshop), myNeedUpdate(false), myViewerBlockedRecursiveCount(0), myIsFirstAISContextUse(true) { - myCustomPrs = std::shared_ptr(new XGUI_CustomPrs(theWorkshop)); } //************************************************************** @@ -157,25 +154,10 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) } anAIS = aPrs->getAISObject(anAIS); } else { - Handle(AIS_InteractiveObject) anAISPrs = - myWorkshop->module()->createPresentation(theObject); - if (anAISPrs.IsNull()) { - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get() != NULL) { - std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - if (aShapePtr.get() != NULL) { - anAISPrs = new ModuleBase_ResultPrs(aResult); - } - } - } - Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs); - if (!aShapePrs.IsNull()) - ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get()); - anAIS = AISObjectPtr(new GeomAPI_AISObject()); - anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs)); + anAIS = myWorkshop->module()->createPresentation(theObject); isShading = true; } - if (anAIS) + if (anAIS.get()) aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer); } return aDisplayed; @@ -215,7 +197,7 @@ bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, if (!anAISIO.IsNull()) { appendResultObject(theObject, theAIS); - bool isCustomized = customizeObject(theObject); + //bool isCustomized = customizeObject(theObject); int aDispMode = isShading? Shading : Wireframe; if (isShading) @@ -278,11 +260,15 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer) bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) { bool aRedisplayed = false; + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return aRedisplayed; + if (!isVisible(theObject)) return aRedisplayed; AISObjectPtr aAISObj = getAISObject(theObject); - Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl(); + Handle(AIS_InteractiveObject) aAISIO; GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); if (aPrs) { @@ -302,9 +288,11 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) } aAISIO = aAIS_Obj->impl(); } + else { + aAISIO = aAISObj->impl(); + } - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull() && !aAISIO.IsNull()) { + if (!aAISIO.IsNull()) { // Check that the visualized shape is the same and the redisplay is not necessary // Redisplay of AIS object leads to this object selection compute and the selection // in the browser is lost @@ -312,54 +300,56 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) // 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); - if (!aShapePrs.IsNull()) { - std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - if (aShapePtr.get()) { - const TopoDS_Shape& aOldShape = aShapePrs->Shape(); - if (!aOldShape.IsNull()) - isEqualShapes = aOldShape.IsEqual(aShapePtr->impl()); - } - } - } + //bool isEqualShapes = false; + //ResultPtr aResult = std::dynamic_pointer_cast(theObject); + //if (aResult.get() != NULL) { + // Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO); + // if (!aShapePrs.IsNull()) { + // std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); + // if (aShapePtr.get()) { + // const TopoDS_Shape& aOldShape = aShapePrs->Shape(); + // if (!aOldShape.IsNull()) + // isEqualShapes = aOldShape.IsEqual(aShapePtr->impl()); + // } + // } + //} // Customization of presentation - bool isCustomized = customizeObject(theObject); + //bool isCustomized = customizeObject(theObject); #ifdef DEBUG_FEATURE_REDISPLAY - qDebug(QString("Redisplay: %1, isEqualShapes=%2, isCustomized=%3"). - arg(!isEqualShapes || isCustomized).arg(isEqualShapes) - .arg(isCustomized).toStdString().c_str()); + qDebug(QString("Redisplay: %1, isEqualShapes=%2"). + arg(!isEqualShapes/* || isCustomized*/).arg(isEqualShapes) + .toStdString().c_str()); #endif - if (!isEqualShapes || isCustomized) { - /// if shapes are equal and presentation are customized, selection should be restored - bool aNeedToRestoreSelection = isEqualShapes && isCustomized; - if (aNeedToRestoreSelection) - myWorkshop->module()->storeSelection(); + //if (!isEqualShapes/* || isCustomized*/) { + // /// if shapes are equal and presentation are customized, selection should be restored + // bool aNeedToRestoreSelection = isEqualShapes/* && isCustomized*/; + // if (aNeedToRestoreSelection) + if (aAISObj.get() && myWorkshop->facesPanel()) + myWorkshop->facesPanel()->customizeObject(theObject, aAISObj); + + myWorkshop->module()->storeSelection(); #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY - myWorkshop->selector()->deselectPresentation(aAISIO); + myWorkshop->selector()->deselectPresentation(aAISIO); #endif - if (aContext->IsDisplayed(aAISIO)) - aContext->Redisplay(aAISIO, false); - else - aContext->Display(aAISIO, false); - + if (aContext->IsDisplayed(aAISIO)) + aContext->Redisplay(aAISIO, false); + else { + aContext->Display(aAISIO, false); + } #ifdef TINSPECTOR if (getCallBack()) getCallBack()->Redisplay(aAISIO); #endif - if (aNeedToRestoreSelection) - myWorkshop->module()->restoreSelection(); + //if (aNeedToRestoreSelection) + myWorkshop->module()->restoreSelection(); - aRedisplayed = true; - #ifdef DEBUG_FEATURE_REDISPLAY - qDebug(" Redisplay happens"); - #endif - if (theUpdateViewer) - updateViewer(); - } + aRedisplayed = true; + #ifdef DEBUG_FEATURE_REDISPLAY + qDebug(" Redisplay happens"); + #endif + if (theUpdateViewer) + updateViewer(); } return aRedisplayed; } @@ -886,37 +876,37 @@ bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const } //************************************************************** -bool 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); - - // Customization of presentation - GeomCustomPrsPtr aCustomPrs; - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get() != NULL) { - GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); - if (aCustPrs.get() != NULL) - aCustomPrs = aCustPrs; - } - if (aCustomPrs.get() == NULL) { - GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); - // we ignore presentable not customized objects - if (aPrs.get() == NULL) - aCustomPrs = myCustomPrs; - } - bool isCustomized = aCustomPrs.get() && - aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); - isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs) - || isCustomized; - - // update presentation state if faces panel is active - if (anAISObj.get() && myWorkshop->facesPanel()) - isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized; - - return isCustomized; -} +//bool 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); +// +// // Customization of presentation +// GeomCustomPrsPtr aCustomPrs; +// FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); +// if (aFeature.get() != NULL) { +// GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); +// if (aCustPrs.get() != NULL) +// aCustomPrs = aCustPrs; +// } +// if (aCustomPrs.get() == NULL) { +// GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); +// // we ignore presentable not customized objects +// if (aPrs.get() == NULL) +// aCustomPrs = myCustomPrs; +// } +// bool isCustomized = aCustomPrs.get() && +// aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); +// isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs) +// || isCustomized; +// +// // update presentation state if faces panel is active +// if (anAISObj.get() && myWorkshop->facesPanel()) +// isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized; +// +// return isCustomized; +//} //************************************************************** QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 45ea2eecb..b9d13642c 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -23,7 +23,6 @@ #include "XGUI.h" #include -#include #include #include @@ -453,10 +452,6 @@ private: #endif Handle(SelectMgr_AndFilter) myAndFilter; ///< A container for selection filters - /// 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 #ifdef OPTIMIZE_PRS XGUI_TwoSidePresentationMap myResult2AISObjectMap; ///< A map of displayed objects diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index df92b7e2a..75543ff5c 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -227,6 +228,8 @@ void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex) update(aModel->index(i, 1, aParent)); update(aModel->index(i, 2, aParent)); } + XGUI_ObjectsBrowser* aObjBrowser = qobject_cast(parent()); + aObjBrowser->workshop()->displayer()->updateViewer(); } void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex) diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 2c6787a19..ed0e8c950 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -45,7 +45,6 @@ #include "XGUI_Tools.h" #include "XGUI_ViewerProxy.h" #include "XGUI_WorkshopListener.h" -#include #include #include #include @@ -279,22 +278,6 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr)), myErrorDlg, SLOT(addError(std::shared_ptr))); - //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color", - // Config_Prop::Color, "225,225,225"); - - Config_PropManager::registerProp("Visualization", "result_body_color", "Result color", - Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "result_group_color", "Group color", - Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "result_construction_color", - "Construction color", - Config_Prop::Color, - ModelAPI_ResultConstruction::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "result_part_color", "Part color", - Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "result_field_color", "Field color", - Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR()); - if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true)) myViewerSelMode.append(TopAbs_FACE); if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true)) @@ -2299,7 +2282,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) foreach(ObjectPtr anObject, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { - XGUI_CustomPrs::getResultColor(aResult, aColor); + ModelAPI_Tools::getColor(aResult, aColor); } else { // TODO: remove the obtaining a color from the AIS object @@ -2412,7 +2395,7 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) foreach(ObjectPtr anObject, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { - aDeflection = XGUI_CustomPrs::getResultDeflection(aResult); + aDeflection = ModelAPI_Tools::getDeflection(aResult); } else { // TODO: remove the obtaining a property from the AIS object @@ -2475,7 +2458,7 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects) foreach(ObjectPtr anObject, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { - aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult); + aCurrentValue = ModelAPI_Tools::getTransparency(aResult); } if (aCurrentValue > 0) break; diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index e420a5aec..6ec62aba9 100644 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -103,6 +103,7 @@ void XGUI_WorkshopListener::initializeEventListening() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES)); aLoop->registerListener(this, Events_LongOp::eventID()); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED)); @@ -149,8 +150,32 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr& // Redisplay feature else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) { std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(theMessage); onFeatureRedisplayMsg(aUpdMsg); + } + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_VISUAL_ATTRIBUTES)) { + std::shared_ptr aUpdMsg = + std::dynamic_pointer_cast(theMessage); + std::set aObjList = aUpdMsg->objects(); + std::set::const_iterator aIt; + std::list::const_iterator aResIt; + XGUI_Displayer* aDisplayer = workshop()->displayer(); + AISObjectPtr aAIS; + for (aIt = aObjList.begin(); aIt != aObjList.end(); ++aIt) { + FeaturePtr aFeature = std::dynamic_pointer_cast(*aIt); + if (aFeature) { + aAIS = aDisplayer->getAISObject(aFeature); + if (aAIS.get()) + workshop()->module()->customizePresentation(aFeature, aAIS); + + std::list aResults = aFeature->results(); + for (aResIt = aResults.begin(); aResIt != aResults.end(); ++aResIt) { + aAIS = aDisplayer->getAISObject(*aResIt); + if (aAIS.get()) + workshop()->module()->customizePresentation(*aResIt, aAIS); + } + } + } } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION)) { std::shared_ptr aUpdMsg = std::dynamic_pointer_cast(theMessage); @@ -354,7 +379,7 @@ void XGUI_WorkshopListener:: //if (aHiddenObjects.size() > 0) // myWorkshop->module()->processHiddenObject(aHiddenObjects); - bool isCustomized = customizeCurrentObject(anObjects, aRedisplayed); + bool isCustomized = customizeFeature(anObjects, aRedisplayed); if (aRedisplayed || isCustomized) { Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION)); @@ -423,7 +448,7 @@ void XGUI_WorkshopListener:: } } - bool isCustomized = customizeCurrentObject(anObjects, aDisplayed); + bool isCustomized = customizeFeature(anObjects, aDisplayed); //if (myObjectBrowser) // myObjectBrowser->processEvent(theMsg); @@ -501,7 +526,7 @@ bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj) return aDisplayer->display(theObj, false); } -bool XGUI_WorkshopListener::customizeCurrentObject(const std::set& theObjects, +bool XGUI_WorkshopListener::customizeFeature(const std::set& theObjects, bool theForceRedisplay) { XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr(); @@ -521,11 +546,11 @@ bool XGUI_WorkshopListener::customizeCurrentObject(const std::set& th // the feature is hidden, but arguments of the feature are modified // e.g. extrusion is hidden(h=0) but sketch is chosen if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) { - aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, + aCustomized = myWorkshop->module()->customizeFeature(aCurrentFeature, ModuleBase_IModule::CustomizeArguments, false) || aCustomized; - aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, + aCustomized = myWorkshop->module()->customizeFeature(aCurrentFeature, ModuleBase_IModule::CustomizeResults, false) || aCustomized; - aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, + aCustomized = myWorkshop->module()->customizeFeature(aCurrentFeature, ModuleBase_IModule::CustomizeHighlightedObjects, false) || aCustomized; } } diff --git a/src/XGUI/XGUI_WorkshopListener.h b/src/XGUI/XGUI_WorkshopListener.h index f6ab5a6ef..e2d548c46 100644 --- a/src/XGUI/XGUI_WorkshopListener.h +++ b/src/XGUI/XGUI_WorkshopListener.h @@ -97,7 +97,7 @@ protected: /// if forced redisplay is false /// \param theForceRedisplay a flag to customize object even always /// \return true if the object is modified - bool customizeCurrentObject(const std::set& theObjects, bool theForceRedisplay); + bool customizeFeature(const std::set& theObjects, bool theForceRedisplay); /// Returns the workshop XGUI_Workshop* workshop() const; -- 2.39.2