From f8ae7ba7224495dfe692a1e6a6c57f58b4a87bf0 Mon Sep 17 00:00:00 2001 From: Ronny Standtke Date: Sat, 29 Apr 2023 19:53:48 +0200 Subject: [PATCH] Origin axis: use same colors as axis cross and make bigger than planes for easier selection and visualization --- src/Gui/ViewProviderOrigin.cpp | 6 +++--- src/Gui/ViewProviderOrigin.h | 3 +++ src/Gui/ViewProviderOriginFeature.cpp | 20 +++++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Gui/ViewProviderOrigin.cpp b/src/Gui/ViewProviderOrigin.cpp index ff4056e944..251528fa29 100644 --- a/src/Gui/ViewProviderOrigin.cpp +++ b/src/Gui/ViewProviderOrigin.cpp @@ -182,9 +182,9 @@ void ViewProviderOrigin::onChanged(const App::Property* prop) { if (vpPlaneXY) { vpPlaneXY->Size.setValue ( szXY ); } if (vpPlaneXZ) { vpPlaneXZ->Size.setValue ( szXZ ); } if (vpPlaneYZ) { vpPlaneYZ->Size.setValue ( szYZ ); } - if (vpLineX) { vpLineX->Size.setValue ( szX ); } - if (vpLineY) { vpLineY->Size.setValue ( szY ); } - if (vpLineZ) { vpLineZ->Size.setValue ( szZ ); } + if (vpLineX) { vpLineX->Size.setValue ( szX * axesScaling ); } + if (vpLineY) { vpLineY->Size.setValue ( szY * axesScaling ); } + if (vpLineZ) { vpLineZ->Size.setValue ( szZ * axesScaling ); } } catch (const Base::Exception &ex) { // While restoring a document don't report errors if one of the lines or planes diff --git a/src/Gui/ViewProviderOrigin.h b/src/Gui/ViewProviderOrigin.h index 7d69046947..4a7640951d 100644 --- a/src/Gui/ViewProviderOrigin.h +++ b/src/Gui/ViewProviderOrigin.h @@ -77,6 +77,9 @@ public: /// Returns default size. Use this if it is not possible to determine appropriate size by other means static double defaultSize(); + // the factor by which the axes are longer than the planes + static constexpr float axesScaling = 1.5f; + // default color for origini: light-blue (50, 150, 250, 255 stored as 0xRRGGBBAA) static const uint32_t defaultColor = 0x3296faff; protected: diff --git a/src/Gui/ViewProviderOriginFeature.cpp b/src/Gui/ViewProviderOriginFeature.cpp index 79718c7326..1693e8948c 100644 --- a/src/Gui/ViewProviderOriginFeature.cpp +++ b/src/Gui/ViewProviderOriginFeature.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "ViewProviderOriginFeature.h" #include "SoFCSelection.h" @@ -98,7 +99,24 @@ void ViewProviderOriginFeature::attach(App::DocumentObject* pcObject) // Setup font size auto font = new SoFont (); - font->size.setValue ( defaultSz/10.); + float fontRatio = 10.0f; + if ( pcObject->getTypeId() == App::Line::getClassTypeId() ) { + // keep font size on axes equal to font size on planes + fontRatio *= ViewProviderOrigin::axesScaling; + const char* axisName = pcObject->getNameInDocument(); + auto axisRoles = App::Origin::AxisRoles; + if ( strncmp(axisName, axisRoles[0], strlen(axisRoles[0]) ) == 0 ) { + // X-axis: red + ShapeColor.setValue ( 0xFF0000FF ); + } else if ( strncmp(axisName, axisRoles[1], strlen(axisRoles[1]) ) == 0 ) { + // Y-axis: green + ShapeColor.setValue ( 0x00FF00FF ); + } else if ( strncmp(axisName, axisRoles[2], strlen(axisRoles[2]) ) == 0 ) { + // Z-axis: blue + ShapeColor.setValue ( 0x0000FFFF ); + } + } + font->size.setValue ( defaultSz / fontRatio ); sep->addChild ( font ); // Create the selection node