Gui: let each coordinate use its own unit to avoid that the displayed values can become very huge

This commit is contained in:
wmayer
2020-05-30 17:16:32 +02:00
parent 0821649a7f
commit 08dca736e3
3 changed files with 24 additions and 36 deletions

View File

@@ -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);
@@ -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 / xfactor : 0.0;
double yuser = fabs(y) > precision ? y / yfactor : 0.0;
double zuser = fabs(z) > precision ? z / zfactor : 0.0;
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;
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;
}
}
@@ -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));

View File

@@ -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));
}

View File

@@ -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));