Gui: implement a static function schemaTranslatePoint to avoid code duplication
This commit is contained in:
@@ -844,6 +844,47 @@ int SelectionSingleton::setPreselect(const char* pDocName, const char* pObjectNa
|
||||
return DocName.empty()?0:1;
|
||||
}
|
||||
|
||||
namespace Gui {
|
||||
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);
|
||||
Base::Quantity mmy(Base::Quantity::MilliMetre);
|
||||
mmy.setValue(fabs(y) > precision ? y : 0.0);
|
||||
Base::Quantity mmz(Base::Quantity::MilliMetre);
|
||||
mmz.setValue(fabs(z) > precision ? z : 0.0);
|
||||
|
||||
double xfactor, yfactor, zfactor, factor;
|
||||
QString xunit, yunit, zunit, unit;
|
||||
|
||||
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;
|
||||
|
||||
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())};
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionSingleton::setPreselectCoord( float x, float y, float z)
|
||||
{
|
||||
static char buf[513];
|
||||
@@ -854,45 +895,15 @@ void SelectionSingleton::setPreselectCoord( float x, float y, float z)
|
||||
CurrentPreselection.x = x;
|
||||
CurrentPreselection.y = y;
|
||||
CurrentPreselection.z = z;
|
||||
|
||||
Base::Quantity mmx(Base::Quantity::MilliMetre);
|
||||
mmx.setValue((double)x);
|
||||
Base::Quantity mmy(Base::Quantity::MilliMetre);
|
||||
mmy.setValue((double)y);
|
||||
Base::Quantity mmz(Base::Quantity::MilliMetre);
|
||||
mmz.setValue((double)z);
|
||||
|
||||
double xfactor, yfactor, zfactor, factor;
|
||||
QString xunit, yunit, zunit, unit;
|
||||
|
||||
QString xval = Base::UnitsApi::schemaTranslate(mmx, xfactor, xunit);
|
||||
QString yval = Base::UnitsApi::schemaTranslate(mmy, yfactor, yunit);
|
||||
QString zval = 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;
|
||||
}
|
||||
|
||||
float xuser = x / factor;
|
||||
float yuser = y / factor;
|
||||
float zuser = z / factor;
|
||||
|
||||
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
|
||||
,xuser,yuser,zuser,unit.toLatin1().data());
|
||||
,CurrentPreselection.pObjectName
|
||||
,CurrentPreselection.pSubName
|
||||
,pts[0].first
|
||||
,pts[1].first
|
||||
,pts[2].first
|
||||
,pts[0].second.c_str());
|
||||
|
||||
if (getMainWindow())
|
||||
getMainWindow()->showMessage(QString::fromLatin1(buf));
|
||||
|
||||
Reference in New Issue
Block a user