Skip to content

Commit

Permalink
Gui: let each coordinate use its own unit to avoid that the displayed…
Browse files Browse the repository at this point in the history
… values can become very huge
  • Loading branch information
wwmayer committed May 30, 2020
1 parent 0821649 commit 08dca73
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
45 changes: 16 additions & 29 deletions src/Gui/Selection.cpp
Expand Up @@ -845,7 +845,7 @@ int SelectionSingleton::setPreselect(const char* pDocName, const char* pObjectNa
}

namespace Gui {
std::array<std::pair<double, std::string>,3 > schemaTranslatePoint(double x, double y, double z, double precision)
std::array<std::pair<double, std::string>, 3> schemaTranslatePoint(double x, double y, double z, double precision)
{
Base::Quantity mmx(Base::Quantity::MilliMetre);
mmx.setValue(fabs(x) > precision ? x : 0.0);
Expand All @@ -854,33 +854,20 @@ std::array<std::pair<double, std::string>,3 > schemaTranslatePoint(double x, dou
Base::Quantity mmz(Base::Quantity::MilliMetre);
mmz.setValue(fabs(z) > precision ? z : 0.0);

double xfactor, yfactor, zfactor, factor;
QString xunit, yunit, zunit, unit;
double xfactor, yfactor, zfactor;
QString xunit, yunit, zunit;

Base::UnitsApi::schemaTranslate(mmx, xfactor, xunit);
Base::UnitsApi::schemaTranslate(mmy, yfactor, yunit);
Base::UnitsApi::schemaTranslate(mmz, zfactor, zunit);

if (xfactor <= yfactor && xfactor <= zfactor) {
factor = xfactor;
unit = xunit;
}
else if (yfactor <= xfactor && yfactor <= zfactor) {
factor = yfactor;
unit = yunit;
}
else {
factor = zfactor;
unit = zunit;
}

double xuser = fabs(x) > precision ? x / factor : 0.0;
double yuser = fabs(y) > precision ? y / factor : 0.0;
double zuser = fabs(z) > precision ? z / factor : 0.0;
double xuser = fabs(x) > precision ? x / xfactor : 0.0;
double yuser = fabs(y) > precision ? y / yfactor : 0.0;
double zuser = fabs(z) > precision ? z / zfactor : 0.0;

std::array<std::pair<double, std::string>, 3> ret = {std::make_pair(xuser, unit.toStdString()),
std::make_pair(yuser, unit.toStdString()),
std::make_pair(zuser, unit.toStdString())};
std::array<std::pair<double, std::string>, 3> ret = {std::make_pair(xuser, xunit.toStdString()),
std::make_pair(yuser, yunit.toStdString()),
std::make_pair(zuser, zunit.toStdString())};
return ret;
}
}
Expand All @@ -897,13 +884,13 @@ void SelectionSingleton::setPreselectCoord( float x, float y, float z)
CurrentPreselection.z = z;

auto pts = schemaTranslatePoint(x, y, z, 0.0);
snprintf(buf,512,"Preselected: %s.%s.%s (%f,%f,%f) %s",CurrentPreselection.pDocName
,CurrentPreselection.pObjectName
,CurrentPreselection.pSubName
,pts[0].first
,pts[1].first
,pts[2].first
,pts[0].second.c_str());
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())
getMainWindow()->showMessage(QString::fromLatin1(buf));
Expand Down
9 changes: 4 additions & 5 deletions src/Gui/SoFCSelection.cpp
Expand Up @@ -407,14 +407,13 @@ 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, %f, %f) %s"
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[1].first
,pts[2].first
,pts[0].second.c_str());
,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::fromLatin1(buf));
}
Expand Down
6 changes: 4 additions & 2 deletions src/Gui/SoFCUnifiedSelection.cpp
Expand Up @@ -488,9 +488,11 @@ bool SoFCUnifiedSelection::setHighlight(SoFullPath *path, const SoDetail *det,
static char buf[513];

auto pts = schemaTranslatePoint(x, y, z, 1e-7);
snprintf(buf,512,"Preselected: %s.%s.%s (%f, %f, %f) %s"
snprintf(buf,512,"Preselected: %s.%s.%s (%f %s, %f %s, %f %s)"
,docname,objname,element
,pts[0].first,pts[1].first,pts[2].first,pts[0].second.c_str());
,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::fromLatin1(buf));

Expand Down

0 comments on commit 08dca73

Please sign in to comment.