diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 1543a135e9..ce63a9fec2 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -1161,6 +1161,7 @@ SET(Inventor_SRCS Inventor/Draggers/SoRotationDraggerGeometry.h Inventor/Draggers/Gizmo.h Inventor/Draggers/GizmoHelper.h + Inventor/Draggers/GizmoStyleParameters.h SoFCColorBar.h SoFCColorBarNotifier.h SoFCColorGradient.h diff --git a/src/Gui/Inventor/Draggers/Gizmo.cpp b/src/Gui/Inventor/Draggers/Gizmo.cpp index 5e18462ea2..b8bf4e47d4 100644 --- a/src/Gui/Inventor/Draggers/Gizmo.cpp +++ b/src/Gui/Inventor/Draggers/Gizmo.cpp @@ -38,8 +38,10 @@ #include #include #include +#include "Base/ServiceProvider.h" #include #include +#include #include #include #include @@ -125,6 +127,8 @@ SoInteractionKit* LinearGizmo::initDragger() arrow->cylinderHeight = 3.5; arrow->cylinderRadius = 0.2; + updateColorTheme(); + return draggerContainer; } @@ -134,6 +138,20 @@ void LinearGizmo::uninitDragger() draggerContainer = nullptr; } +void LinearGizmo::updateColorTheme() +{ + auto* styleParameterManager = Base::provideService(); + Base::Color baseColor = styleParameterManager->resolve(StyleParameters::LinearGizmoBaseColor); + Base::Color activeColor = styleParameterManager->resolve(StyleParameters::LinearGizmoActiveColor); + + dragger->color = baseColor.asValue(); + dragger->activeColor = activeColor.asValue(); + + auto baseGeom = SO_GET_PART(dragger, "baseGeom", SoArrowBase); + Base::Color baseGeomColor = styleParameterManager->resolve(StyleParameters::DimensionVisualizerColor); + baseGeom->color = baseGeomColor.asValue(); +} + GizmoPlacement LinearGizmo::getDraggerPlacement() { assert(draggerContainer && "Forgot to call GizmoContainer::initGizmos?"); @@ -296,6 +314,8 @@ SoInteractionKit* RotationGizmo::initDragger() setRotAngle(property->value().getValue()); + updateColorTheme(); + return draggerContainer; } @@ -309,6 +329,16 @@ void RotationGizmo::uninitDragger() translationSensor.setFunction(nullptr); } +void RotationGizmo::updateColorTheme() +{ + auto* styleParameterManager = Base::provideService(); + Base::Color baseColor = styleParameterManager->resolve(StyleParameters::RotationGizmoBaseColor); + Base::Color activeColor = styleParameterManager->resolve(StyleParameters::RotationGizmoActiveColor); + + dragger->color = baseColor.asValue(); + dragger->activeColor = activeColor.asValue(); +} + GizmoPlacement RotationGizmo::getDraggerPlacement() { assert(draggerContainer && "Forgot to call GizmoContainer::initGizmos?"); @@ -506,6 +536,8 @@ SoInteractionKit* DirectedRotationGizmo::initDragger() rotator->rightArrowVisible = false; dragger->setPart("rotator", rotator); + updateColorTheme(); + return ret; } @@ -532,6 +564,8 @@ SoInteractionKit* RadialGizmo::initDragger() dragger->instantiateBaseGeometry(); + updateColorTheme(); + return ret; } @@ -552,6 +586,22 @@ void RadialGizmo::flipArrow() rotator->flipArrow(); } +void RadialGizmo::updateColorTheme() +{ + auto dragger = getDraggerContainer()->getDragger(); + + auto* styleParameterManager = Base::provideService(); + Base::Color baseColor = styleParameterManager->resolve(StyleParameters::RotationGizmoBaseColor); + Base::Color activeColor = styleParameterManager->resolve(StyleParameters::RotationGizmoActiveColor); + + dragger->color = baseColor.asValue(); + dragger->activeColor = activeColor.asValue(); + + auto baseGeom = SO_GET_PART(dragger, "baseGeom", SoRotatorBase); + Base::Color baseGeomColor = styleParameterManager->resolve(StyleParameters::DimensionVisualizerColor); + baseGeom->color = baseGeomColor.asValue(); +} + SO_KIT_SOURCE(GizmoContainer) void GizmoContainer::initClass() diff --git a/src/Gui/Inventor/Draggers/Gizmo.h b/src/Gui/Inventor/Draggers/Gizmo.h index 9a7dc8e5f1..67f6cedc35 100644 --- a/src/Gui/Inventor/Draggers/Gizmo.h +++ b/src/Gui/Inventor/Draggers/Gizmo.h @@ -96,6 +96,8 @@ public: SoInteractionKit* initDragger() override; void uninitDragger() override; + void updateColorTheme(); + // Returns the position and rotation of the base of the dragger GizmoPlacement getDraggerPlacement() override; void setDraggerPlacement(const SbVec3f& pos, const SbVec3f& dir) override; @@ -132,6 +134,8 @@ public: SoInteractionKit* initDragger() override; void uninitDragger() override; + void updateColorTheme(); + // Distance between the linear gizmo base and rotation gizmo double sepDistance = 0; @@ -190,6 +194,8 @@ public: SoInteractionKit* initDragger() override; + void updateColorTheme(); + void setRadius(float radius); void flipArrow(); diff --git a/src/Gui/Inventor/Draggers/GizmoStyleParameters.h b/src/Gui/Inventor/Draggers/GizmoStyleParameters.h new file mode 100644 index 0000000000..30ab6765ef --- /dev/null +++ b/src/Gui/Inventor/Draggers/GizmoStyleParameters.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 Sayantan Deb * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD 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. * + * * + * FreeCAD 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 FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ + +#ifndef GUI_GIZMO_STYLE_PARAMETERS_H +#define GUI_GIZMO_STYLE_PARAMETERS_H + +#include +#include + +namespace Gui::StyleParameters { + DEFINE_STYLE_PARAMETER(LinearGizmoBaseColor, Base::Color(1.0F, 0.0F, 0.0F)); + DEFINE_STYLE_PARAMETER(LinearGizmoActiveColor, Base::Color(1.0F, 1.0F, 0.0F)); + + DEFINE_STYLE_PARAMETER(RotationGizmoBaseColor, Base::Color(1.0F, 0.0F, 0.0F)); + DEFINE_STYLE_PARAMETER(RotationGizmoActiveColor, Base::Color(1.0F, 1.0F, 0.0F)); + + DEFINE_STYLE_PARAMETER(DimensionVisualizerColor, Base::Color(0.214F, 0.560F, 0.930F)); +} + +#endif /* GUI_GIZMO_STYLE_PARAMETERS_H */ diff --git a/src/Gui/Inventor/Draggers/SoLinearDraggerGeometry.cpp b/src/Gui/Inventor/Draggers/SoLinearDraggerGeometry.cpp index ec6fda42fb..e9b3f9bec8 100644 --- a/src/Gui/Inventor/Draggers/SoLinearDraggerGeometry.cpp +++ b/src/Gui/Inventor/Draggers/SoLinearDraggerGeometry.cpp @@ -151,7 +151,7 @@ SoArrowBase::SoArrowBase() SO_KIT_ADD_FIELD(cylinderHeight, (1.0)); SO_KIT_ADD_FIELD(cylinderRadius, (0.15)); - SO_KIT_ADD_FIELD(color, (0.214, 0.560, 0.930)); + SO_KIT_ADD_FIELD(color, (0, 0, 1)); SO_KIT_INIT_INSTANCE();