From 29ae5ac5706b94b3df50136a545649be524fd2a3 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 22 Mar 2021 16:59:34 +0300 Subject: [PATCH] 1. Manage color of construction point using preferences dialog box. 2. Get rid compilation link from ModuleBase to BuildPlugin. Provide the same filtering functionality using corresponded validators. --- src/BuildPlugin/BuildPlugin_Validators.cpp | 91 +++++++++++++++++++ .../ConstructionPlugin_Axis.cpp | 6 +- .../ConstructionPlugin_Axis.h | 3 +- .../ConstructionPlugin_Plane.cpp | 5 +- .../ConstructionPlugin_Plane.h | 10 +- .../ConstructionPlugin_Plugin.cpp | 8 +- .../ConstructionPlugin_Point.cpp | 28 ++++-- .../ConstructionPlugin_Point.h | 18 +++- src/GeomAPI/GeomAPI_ICustomPrs.h | 3 +- src/Model/Model_ResultConstruction.cpp | 4 +- src/ModelAPI/ModelAPI_ResultConstruction.cpp | 4 - src/ModelAPI/ModelAPI_ResultConstruction.h | 61 ++----------- src/ModuleBase/CMakeLists.txt | 1 - src/ModuleBase/ModuleBase_WidgetValidated.cpp | 59 ------------ src/PartSet/PartSet_Module.cpp | 64 ++++++------- src/PartSet/PartSet_Tools.cpp | 10 +- .../SketchPlugin_ConstraintBase.h | 11 +-- src/XGUI/XGUI_Workshop.cpp | 21 ++--- 18 files changed, 198 insertions(+), 209 deletions(-) diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index ac454e620..29bc897b7 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -123,6 +123,35 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr shapeTypes; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) + shapeTypes.insert(aShape->shapeType()); + } + + std::set aRemove; + if (shapeTypes.find(GeomAPI_Shape::WIRE) != shapeTypes.end()) + { + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) { + auto aType = aShape->shapeType(); + if (aType == GeomAPI_Shape::EDGE) + aRemove.insert(anIndex); + } + else + aRemove.insert(anIndex); + } + } + + if (aRemove.size() > 0) + aSelectionList->remove(aRemove); + GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::shapeTypeByStr(theArguments.back()); // Collect base shapes. @@ -194,6 +223,35 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr remove edges and wires + std::set shapeTypes; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) + shapeTypes.insert(aShape->shapeType()); + } + + std::set aRemove; + if (shapeTypes.find(GeomAPI_Shape::FACE) != shapeTypes.end()) + { + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) { + auto aType = aShape->shapeType(); + if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE) + aRemove.insert(anIndex); + } + else + aRemove.insert(anIndex); + } + } + if (aRemove.size() > 0) + aSelectionList->remove(aRemove); + bool hasEdgesOrWires = false; bool hasFaces = false; @@ -290,6 +348,39 @@ bool BuildPlugin_ValidatorBaseForSolids::isValid( return false; } + /// remove objects of sub-type if ojects of correct type is in List, in some cases : + /// Solid builder: faces and shapes shells or solids seleted + /// --> remove faces + + std::set shapeTypes; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) + shapeTypes.insert(aShape->shapeType()); + } + + std::set aRemove; + if (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() || + shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() || + shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end()) + { + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (aShape.get()) { + auto aType = aShape->shapeType(); + if (aType == GeomAPI_Shape::FACE) + aRemove.insert(anIndex); + } + else + aRemove.insert(anIndex); + } + } + + if (aRemove.size() > 0) + aSelectionList->remove(aRemove); + // Collect base shapes. ListOfShape anOriginalShapes; for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 697a0b441..3d14eda06 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -390,11 +390,9 @@ void ConstructionPlugin_Axis::execute() } } -bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) +bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs) { - bool isCustomized = theDefaultPrs.get() != NULL && - theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + bool isCustomized = false; isCustomized = thePrs->setLineStyle(3) || isCustomized; isCustomized = thePrs->setWidth(2) || isCustomized; diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index 43e1d483b..115abead1 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -250,8 +250,7 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP ConstructionPlugin_Axis(); /// Customize presentation of the feature - virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs); + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs); protected: /// Creates a new axis by two defined points diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 0b81fca65..5be399aa5 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -142,8 +142,7 @@ void ConstructionPlugin_Plane::execute() } //================================================================================================== -bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) +bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs) { std::vector aColor; // get color from the attribute of the result @@ -157,7 +156,7 @@ bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObj } } if (aColor.empty()) - aColor = Config_PropManager::color("Visualization", "construction_plane_color"); + aColor = Config_PropManager::color("Visualization", COLOR_NAME()); bool isCustomized = false; if (aColor.size() == 3) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.h b/src/ConstructionPlugin/ConstructionPlugin_Plane.h index 95fe72d86..9b2a3ba4e 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.h @@ -46,6 +46,13 @@ public: return CONSTRUCTION_PLANE_COLOR; } + /// Default color property name. + inline static const std::string& COLOR_NAME() + { + static const std::string PLANE_COLOR_NAME("construction_plane_color"); + return PLANE_COLOR_NAME; + } + /// Plane kind. inline static const std::string& ID() { @@ -255,8 +262,7 @@ public: ConstructionPlugin_Plane(); /// Customize presentation of the feature - virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs); + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs); protected: /// Creates a new plane by general equation. diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 69e900fdc..0beb51872 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -75,9 +75,11 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() ModelAPI_Session::get()->registerPlugin(this); // register construction properties - Config_PropManager::registerProp("Visualization", "construction_plane_color", - "Construction plane color", - Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR()); + Config_PropManager::registerProp("Visualization", ConstructionPlugin_Plane::COLOR_NAME(), + "Construction plane color", Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR()); + + Config_PropManager::registerProp("Visualization", ConstructionPlugin_Point::COLOR_NAME(), + "Construction point color", Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR()); } FeaturePtr ConstructionPlugin_Plugin::createFeature(std::string theFeatureID) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 91392151b..087cfd91d 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,8 @@ #include #include +#include + //================================================================================================== ConstructionPlugin_Point::ConstructionPlugin_Point() { @@ -145,19 +148,30 @@ void ConstructionPlugin_Point::execute() std::shared_ptr aConstr = document()->createConstruction(data()); aConstr->setInfinite(true); aConstr->setShape(aShape); - /// set point color - aConstr->setColor(ModelAPI_ResultConstruction::ModelApi_PointColor::DEFAULT_COLOR(), - ModelAPI_ResultConstruction::ModelApi_PointColor::COLOR_CONFIG_NAME()); setResult(aConstr); } //================================================================================================== bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, - AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) + AISObjectPtr thePrs) { - bool isCustomized = theDefaultPrs.get() != NULL && - theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + std::vector aColor; + // get color from the attribute of the result + if (theResult.get() != NULL && + theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { + AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); + if (aColorAttr.get() && aColorAttr->size()) { + aColor.push_back(aColorAttr->value(0)); + aColor.push_back(aColorAttr->value(1)); + aColor.push_back(aColorAttr->value(2)); + } + } + if (aColor.empty()) + aColor = Config_PropManager::color("Visualization", COLOR_NAME()); + + bool isCustomized = false; + if (aColor.size() == 3) + isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol return isCustomized; } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index ffbae6723..8470e048b 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -39,6 +39,21 @@ public: /// Returns the kind of a feature. CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind(); + /// Default color for a point. + inline static const std::string& DEFAULT_COLOR() + { + static const std::string POINT_COLOR("85,85,0"); + return POINT_COLOR; + } + + /// Default color property name. + inline static const std::string& COLOR_NAME() + { + static const std::string POINT_COLOR_NAME("construction_point_color"); + return POINT_COLOR_NAME; + } + + /// Point kind. inline static const std::string& ID() { @@ -328,8 +343,7 @@ public: ConstructionPlugin_Point(); /// Customize presentation of the feature - virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs); + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs); private: std::shared_ptr createByXYZ(); diff --git a/src/GeomAPI/GeomAPI_ICustomPrs.h b/src/GeomAPI/GeomAPI_ICustomPrs.h index 6908ca948..90d0af061 100644 --- a/src/GeomAPI/GeomAPI_ICustomPrs.h +++ b/src/GeomAPI/GeomAPI_ICustomPrs.h @@ -40,8 +40,7 @@ public: /// Modifies the given presentation in the custom way. virtual bool customisePresentation(std::shared_ptr theResult, - AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) = 0; + AISObjectPtr thePrs) = 0; }; typedef std::shared_ptr GeomCustomPrsPtr; diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index ff2689cb3..d782dbab3 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -100,8 +100,8 @@ void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::str std::string& theDefault) { theSection = "Visualization"; - theName = getColorConfigName(); - theDefault = getColor(); + theName = RESULT_COLOR_NAME(); + theDefault = DEFAULT_COLOR(); } void Model_ResultConstruction::setShape(std::shared_ptr theShape) diff --git a/src/ModelAPI/ModelAPI_ResultConstruction.cpp b/src/ModelAPI/ModelAPI_ResultConstruction.cpp index 773e71db3..7ae3f66a9 100644 --- a/src/ModelAPI/ModelAPI_ResultConstruction.cpp +++ b/src/ModelAPI/ModelAPI_ResultConstruction.cpp @@ -24,7 +24,3 @@ std::string ModelAPI_ResultConstruction::groupName() { return group(); } - -ModelAPI_ResultConstruction::ModelAPI_ResultConstruction(){ - setColor(DEFAULT_COLOR(), DEFAULT_COLOR_CONFIG_NAME()); -} diff --git a/src/ModelAPI/ModelAPI_ResultConstruction.h b/src/ModelAPI/ModelAPI_ResultConstruction.h index 9f4346246..98b22921c 100644 --- a/src/ModelAPI/ModelAPI_ResultConstruction.h +++ b/src/ModelAPI/ModelAPI_ResultConstruction.h @@ -33,11 +33,9 @@ * Provides a shape that may be displayed in the viewer. * Intermediate, light result that in many cases produces a result on the fly. */ -MODELAPI_EXPORT class ModelAPI_ResultConstruction : public ModelAPI_Result +class ModelAPI_ResultConstruction : public ModelAPI_Result { public: - MODELAPI_EXPORT ModelAPI_ResultConstruction(); - /// Returns the group identifier of this result MODELAPI_EXPORT virtual std::string groupName(); @@ -55,6 +53,13 @@ MODELAPI_EXPORT class ModelAPI_ResultConstruction : public ModelAPI_Result return RESULT_CONSTRUCTION_COLOR; } + /// default color for a result construction + inline static const std::string& RESULT_COLOR_NAME() + { + static const std::string COLOR_NAME("result_construction_color"); + return COLOR_NAME; + } + /// default deflection for a result construction inline static const std::string DEFAULT_DEFLECTION() { @@ -83,56 +88,6 @@ MODELAPI_EXPORT class ModelAPI_ResultConstruction : public ModelAPI_Result virtual bool isInfinite() = 0; /// Sets the flag that it is infinite virtual void setInfinite(const bool theInfinite) = 0; - - /*************************************************************************/ - /// Changes for custom point color - - inline static const std::string& DEFAULT_COLOR_CONFIG_NAME() - { - static const std::string RESULT_CONSTRUCTION_COLOR_CONFIG_NAME("result_construction_color"); - return RESULT_CONSTRUCTION_COLOR_CONFIG_NAME; - } - - inline void setColor(const std::string myColor, const std::string & myColorConfigName) - { - color = myColor; - colorConfigName = myColorConfigName; - } - - inline const std::string & getColor() const - { - return color; - } - - inline const std::string & getColorConfigName() const - { - return colorConfigName; - } - -private: - std::string color; - std::string colorConfigName; - -public: - - /// Specific properties for point - class ModelApi_PointColor - { - public: - /// default color for a point construction - inline static const std::string& DEFAULT_COLOR() - { - static const std::string POINT_CONSTRUCTION_COLOR("85,85,0"); - return POINT_CONSTRUCTION_COLOR; - } - - inline static const std::string COLOR_CONFIG_NAME() - { - static const std::string POINT_CONFIG_COLOR_NAME("result_point_color"); - return POINT_CONFIG_COLOR_NAME; - } - }; - /*************************************************************************/ }; //! Pointer on feature object diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index f64dfeed7..43b268aab 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -280,7 +280,6 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI ${PROJECT_SOURCE_DIR}/src/Locale - ${PROJECT_SOURCE_DIR}/src/BuildPlugin ${SUIT_INCLUDE} ) diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 90436988e..feb6a380a 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -35,10 +35,6 @@ #include #include -#include -#include -#include - #include #include #include @@ -484,61 +480,6 @@ QList ModuleBase_WidgetValidated::getFilteredSelected() filterCompSolids(aSelected); - if (myFeatureId == BuildPlugin_Face::ID() || myFeatureId == BuildPlugin_Wire::ID() || - myFeatureId == BuildPlugin_Solid::ID()) - { - /// remove objects of sub-type if ojects of correct type is in List, in some cases : - /// - Face builder: edges, faces and wires selected - /// --> remove edges and wires - /// Wire builder: wires and edges selected - /// --> remove egdes - /// Solid builder: faces and shapes shells or solids seleted - /// --> remove faces - - std::set shapeTypes; - for (auto aSelection: aSelected){ - auto aShape = aSelection->shape(); - if (aShape) - shapeTypes.insert(aShape->shapeType()); - } - - std::vector aRemove; - - if (myFeatureId == BuildPlugin_Face::ID() && shapeTypes.find(GeomAPI_Shape::FACE) - != shapeTypes.end()) - { - for(auto aSelection: aSelected){ - auto aType = aSelection->shape()->shapeType(); - if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE) - aRemove.push_back(aSelection); - } - } - else if (myFeatureId == BuildPlugin_Wire::ID() && shapeTypes.find(GeomAPI_Shape::WIRE) - != shapeTypes.end()) - { - for(auto aSelection: aSelected){ - auto aType = aSelection->shape()->shapeType(); - if (aType == GeomAPI_Shape::EDGE) - aRemove.push_back(aSelection); - } - } - else if (myFeatureId == BuildPlugin_Solid::ID() && - (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() || - shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() || - shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end()) ) - { - for(auto aSelection: aSelected){ - auto aType = aSelection->shape()->shapeType(); - if( aType == GeomAPI_Shape::FACE) - aRemove.push_back(aSelection); - } - } - - for(auto aSelection: aRemove){ - aSelected.removeOne(aSelection); - } - } - return aSelected; } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 5135f7161..22017e06e 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -196,26 +196,14 @@ 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", - ModelAPI_ResultConstruction::DEFAULT_COLOR_CONFIG_NAME(), - "Construction color", Config_Prop::Color, - ModelAPI_ResultConstruction::DEFAULT_COLOR()); - - Config_PropManager::registerProp( - "Visualization", - ModelAPI_ResultConstruction::ModelApi_PointColor::COLOR_CONFIG_NAME(), - "Construction point color", Config_Prop::Color, - ModelAPI_ResultConstruction::ModelApi_PointColor::DEFAULT_COLOR()); - + Config_PropManager::registerProp("Visualization", ModelAPI_ResultConstruction::RESULT_COLOR_NAME(), + "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()); @@ -1395,14 +1383,6 @@ AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject) return anAIS; } -//****************************************************** -void getResultColor(const ResultPtr& theResult, std::vector& theColor) -{ - ModelAPI_Tools::getColor(theResult, theColor); - if (theColor.empty()) - PartSet_Tools::getDefaultColor(theResult, false, theColor); -} - //****************************************************** double getResultDeflection(const ResultPtr& theResult) { @@ -1467,33 +1447,45 @@ void PartSet_Module::customizePresentation(const ObjectPtr& theObject, } else { ResultPtr aResult = std::dynamic_pointer_cast(theObject); + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (aResult.get()) { std::vector aColor; - getResultColor(aResult, aColor); - - SessionPtr aMgr = ModelAPI_Session::get(); - if (aMgr->activeDocument() != aResult->document()) { + bool isSameDoc = (ModelAPI_Session::get()->activeDocument() == aResult->document()); + // Get user defined color for the object + ModelAPI_Tools::getColor(aResult, aColor); + if (isSameDoc) { + bool isCustomized = false; + if (aColor.empty() && aFeature.get()) { + GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); + if (aCustPrs.get()) { + isCustomized = aCustPrs->customisePresentation(aResult, thePrs); + } + } + if (!isCustomized) { + if (aColor.empty()) { + PartSet_Tools::getDefaultColor(aResult, false, aColor); + } + thePrs->setColor(aColor[0], aColor[1], aColor[2]); + } + } + else { + if (aColor.empty()) { + PartSet_Tools::getDefaultColor(aResult, false, aColor); + } 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(aNewColor.red(), aNewColor.green(), aNewColor.blue()); } - thePrs->setColor(aColor[0], aColor[1], aColor[2]); - thePrs->setDeflection(getResultDeflection(aResult)); - thePrs->setTransparency(getResultTransparency(aResult)); /// set texture parameters - if(aResult->hasTextureFile()){ + if(aResult->hasTextureFile()) { setTexture(aResult->getTextureFile(), thePrs); } } - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get()) { - if (aFeature->getKind() == SketchPlugin_Sketch::ID()) + if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) { thePrs->setWidth(2); } } diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 169ea993d..fb0750e9d 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -859,12 +859,10 @@ void PartSet_Tools::getDefaultColor(ObjectPtr theObject, const bool isEmptyColor { 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); - } + 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. diff --git a/src/SketchPlugin/SketchPlugin_ConstraintBase.h b/src/SketchPlugin/SketchPlugin_ConstraintBase.h index ea015c6df..fcfedc192 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintBase.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintBase.h @@ -52,17 +52,8 @@ * Some feature's methods implemented here as dummy to * Base class for all constraints. */ -class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable, - public GeomAPI_ICustomPrs +class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable { - public: - /// Customize presentation of the feature - virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) - { - return theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); - } - protected: /// \brief Use plugin manager for features creation SketchPlugin_ConstraintBase() diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b78a019bc..f2cf058bd 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -2459,22 +2459,17 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { ModelAPI_Tools::getColor(aResult, aColor); - if (aColor.empty()) + if (aColor.empty()) { + AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject); + if (anAISObj.get()) { + aColor.resize(3); + anAISObj->getColor(aColor[0], aColor[1], aColor[2]); + } + } + if (aColor.empty()) { getDefaultColor(aResult, false, aColor); - } - else { - // TODO: remove the obtaining a color from the AIS object - // this does not happen never because: - // 1. The color can be changed only on results - // 2. The result can be not visualized in the viewer(e.g. Origin Construction) - AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject); - if (anAISObj.get()) { - aColor.resize(3); - anAISObj->getColor(aColor[0], aColor[1], aColor[2]); } } - if (!aColor.empty()) - break; } if (aColor.size() != 3) return; -- 2.39.2