From caaadee0fcf3253bff5b0489ecedec4951ee2913 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sun, 19 Nov 2023 21:50:33 +0100 Subject: [PATCH] Status bar message : reduce number of decimals to use system preference. --- src/Gui/Selection.cpp | 29 +++++++++++++++++------------ src/Gui/SoFCSelection.cpp | 24 ++++++++++++++++-------- src/Gui/SoFCUnifiedSelection.cpp | 23 ++++++++++++++++------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index 654614526a..ba66c6ef22 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -720,8 +720,6 @@ std::array, 3> schemaTranslatePoint(double x, dou void SelectionSingleton::setPreselectCoord( float x, float y, float z) { - static char buf[513]; - // if nothing is in preselect ignore if(CurrentPreselection.Object.getObjectName().empty()) return; @@ -730,17 +728,24 @@ void SelectionSingleton::setPreselectCoord( float x, float y, float z) CurrentPreselection.y = y; CurrentPreselection.z = z; - auto pts = schemaTranslatePoint(x, y, z, 0.0); - snprintf(buf,512,"Preselected: %s.%s.%s (%f %s,%f %s,%f %s)" - ,CurrentPreselection.pDocName - ,CurrentPreselection.pObjectName - ,CurrentPreselection.pSubName - ,pts[0].first, pts[0].second.c_str() - ,pts[1].first, pts[1].second.c_str() - ,pts[2].first, pts[2].second.c_str()); + if (getMainWindow()) { + auto pts = schemaTranslatePoint(x, y, z, 0.0); - if (getMainWindow()) - getMainWindow()->showMessage(QString::fromUtf8(buf)); + int numberDecimals = std::min(6, Base::UnitsApi::getDecimals()); + + QString message = QStringLiteral("Preselected: %1.%2.%3 (%4 %5, %6 %7, %8 %9)") + .arg(QString::fromUtf8(CurrentPreselection.pDocName)) + .arg(QString::fromUtf8(CurrentPreselection.pObjectName)) + .arg(QString::fromUtf8(CurrentPreselection.pSubName)) + .arg(QString::number(pts[0].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[0].second)) + .arg(QString::number(pts[1].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[1].second)) + .arg(QString::number(pts[2].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[2].second)); + + getMainWindow()->showMessage(message); + } } void SelectionSingleton::rmvPreselect(bool signal) diff --git a/src/Gui/SoFCSelection.cpp b/src/Gui/SoFCSelection.cpp index c7073a56dd..e5e511e648 100644 --- a/src/Gui/SoFCSelection.cpp +++ b/src/Gui/SoFCSelection.cpp @@ -40,6 +40,8 @@ # include #endif +#include + #include "SoFCSelection.h" #include "MainWindow.h" #include "SoFCSelectionAction.h" @@ -383,15 +385,21 @@ SoFCSelection::handleEvent(SoHandleEventAction * action) const auto &pt = pp->getPoint(); auto pts = schemaTranslatePoint(pt[0], pt[1], pt[2], 1e-7); - snprintf(buf,512,"Preselected: %s.%s.%s (%f %s, %f %s, %f %s)" - ,documentName.getValue().getString() - ,objectName.getValue().getString() - ,subElementName.getValue().getString() - ,pts[0].first, pts[0].second.c_str() - ,pts[1].first, pts[1].second.c_str() - ,pts[2].first, pts[2].second.c_str()); - getMainWindow()->showMessage(QString::fromUtf8(buf)); + int numberDecimals = std::min(6, Base::UnitsApi::getDecimals()); + + QString message = QStringLiteral("Preselected: %1.%2.%3 (%4 %5, %6 %7, %8 %9)") + .arg(QString::fromUtf8(documentName.getValue().getString())) + .arg(QString::fromUtf8(objectName.getValue().getString())) + .arg(QString::fromUtf8(subElementName.getValue().getString())) + .arg(QString::number(pts[0].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[0].second)) + .arg(QString::number(pts[1].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[1].second)) + .arg(QString::number(pts[2].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[2].second)); + + getMainWindow()->showMessage(message); } else { // picked point if (highlighted) { diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index ac62828796..0a95d96dc3 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -73,6 +73,7 @@ #include #include #include +#include #include "SoFCUnifiedSelection.h" #include "Application.h" @@ -494,16 +495,24 @@ bool SoFCUnifiedSelection::setHighlight(SoFullPath *path, const SoDetail *det, const char *objname = vpd->getObject()->getNameInDocument(); this->preSelection = 1; - static char buf[513]; auto pts = schemaTranslatePoint(x, y, z, 1e-7); - snprintf(buf,512,"Preselected: %s.%s.%s (%f %s, %f %s, %f %s)" - ,docname,objname,element - ,pts[0].first,pts[0].second.c_str() - ,pts[1].first,pts[1].second.c_str() - ,pts[2].first,pts[2].second.c_str()); - getMainWindow()->showMessage(QString::fromUtf8(buf)); + int numberDecimals = std::min(6, Base::UnitsApi::getDecimals()); + + QString message = QStringLiteral("Preselected: %1.%2.%3 (%4 %5, %6 %7, %8 %9)") + .arg(QString::fromUtf8(docname)) + .arg(QString::fromUtf8(objname)) + .arg(QString::fromUtf8(element)) + .arg(QString::number(pts[0].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[0].second)) + .arg(QString::number(pts[1].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[1].second)) + .arg(QString::number(pts[2].first, 'f', numberDecimals)) + .arg(QString::fromStdString(pts[2].second)); + + getMainWindow()->showMessage(message); + int ret = Gui::Selection().setPreselect(docname,objname,element,x,y,z); if(ret<0 && currenthighlight)