Gui: remove code duplication of printing preselection

This commit is contained in:
wmayer
2023-11-21 01:44:49 +01:00
committed by Chris Hennes
parent c556af673a
commit 6132d8ee63
3 changed files with 57 additions and 52 deletions

View File

@@ -716,6 +716,44 @@ std::array<std::pair<double, std::string>, 3> schemaTranslatePoint(double x, dou
std::make_pair(zuser, zunit.toUtf8().constBegin())};
return ret;
}
QString getPreselectionInfo(const char* documentName,
const char* objectName,
const char* subElementName,
float x, float y, float z,
double precision)
{
auto pts = schemaTranslatePoint(x, y, z, precision);
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))
.arg(QString::fromUtf8(objectName))
.arg(QString::fromUtf8(subElementName))
.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));
return message;
}
void printPreselectionInfo(const char* documentName,
const char* objectName,
const char* subElementName,
float x, float y, float z,
double precision)
{
if (getMainWindow()) {
QString message = getPreselectionInfo(documentName,
objectName,
subElementName,
x, y, z, precision);
getMainWindow()->showMessage(message);
}
}
}
void SelectionSingleton::setPreselectCoord( float x, float y, float z)
@@ -728,24 +766,10 @@ void SelectionSingleton::setPreselectCoord( float x, float y, float z)
CurrentPreselection.y = y;
CurrentPreselection.z = z;
if (getMainWindow()) {
auto pts = schemaTranslatePoint(x, y, z, 0.0);
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);
}
printPreselectionInfo(CurrentPreselection.pDocName,
CurrentPreselection.pObjectName,
CurrentPreselection.pSubName,
x, y, z, 0.0);
}
void SelectionSingleton::rmvPreselect(bool signal)

View File

@@ -55,7 +55,11 @@
using namespace Gui;
namespace Gui {
std::array<std::pair<double, std::string>,3 > schemaTranslatePoint(double x, double y, double z, double precision);
void printPreselectionInfo(const char* documentName,
const char* objectName,
const char* subElementName,
float x, float y, float z,
double precision);
}
SoFullPath * Gui::SoFCSelection::currenthighlight = nullptr;
@@ -384,22 +388,10 @@ SoFCSelection::handleEvent(SoHandleEventAction * action)
const auto &pt = pp->getPoint();
auto pts = schemaTranslatePoint(pt[0], pt[1], pt[2], 1e-7);
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);
printPreselectionInfo(documentName.getValue().getString(),
objectName.getValue().getString(),
subElementName.getValue().getString(),
pt[0], pt[1], pt[2], 1e-7);
}
else { // picked point
if (highlighted) {

View File

@@ -91,7 +91,11 @@ FC_LOG_LEVEL_INIT("SoFCUnifiedSelection",false,true,true)
using namespace Gui;
namespace Gui {
std::array<std::pair<double, std::string>,3 > schemaTranslatePoint(double x, double y, double z, double precision);
void printPreselectionInfo(const char* documentName,
const char* objectName,
const char* subElementName,
float x, float y, float z,
double precision);
}
SoFullPath * Gui::SoFCUnifiedSelection::currenthighlight = nullptr;
@@ -496,22 +500,7 @@ bool SoFCUnifiedSelection::setHighlight(SoFullPath *path, const SoDetail *det,
this->preSelection = 1;
auto pts = schemaTranslatePoint(x, y, z, 1e-7);
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);
printPreselectionInfo(docname, objname, element, x, y, z, 1e-7);
int ret = Gui::Selection().setPreselect(docname,objname,element,x,y,z);