Skip to content

Commit

Permalink
Gui: remove code duplication of printing preselection
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer authored and chennes committed Nov 21, 2023
1 parent 632d5e8 commit d792727
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
60 changes: 42 additions & 18 deletions src/Gui/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
26 changes: 9 additions & 17 deletions src/Gui/SoFCSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 6 additions & 17 deletions src/Gui/SoFCUnifiedSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d792727

Please sign in to comment.