[FC] Status bar preselection coordinates are aware of user unit setting ; fixes #4148
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
@@ -853,11 +854,45 @@ 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;
|
||||
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%f,%f,%f)",CurrentPreselection.pDocName
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%f,%f,%f) %s",CurrentPreselection.pDocName
|
||||
,CurrentPreselection.pObjectName
|
||||
,CurrentPreselection.pSubName
|
||||
,x,y,z);
|
||||
,xuser,yuser,zuser,unit.toLatin1().data());
|
||||
|
||||
if (getMainWindow())
|
||||
getMainWindow()->showMessage(QString::fromLatin1(buf));
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "View3DInventorViewer.h"
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include "SoFCSelection.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Selection.h"
|
||||
@@ -401,13 +402,46 @@ SoFCSelection::handleEvent(SoHandleEventAction * action)
|
||||
}
|
||||
|
||||
const auto &pt = pp->getPoint();
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%g, %g, %g)",documentName.getValue().getString()
|
||||
|
||||
Base::Quantity mmx(Base::Quantity::MilliMetre);
|
||||
mmx.setValue(fabs(pt[0])>1e-7?(double)pt[0]:0.0);
|
||||
Base::Quantity mmy(Base::Quantity::MilliMetre);
|
||||
mmy.setValue(fabs(pt[1])>1e-7?(double)pt[1]:0.0);
|
||||
Base::Quantity mmz(Base::Quantity::MilliMetre);
|
||||
mmz.setValue(fabs(pt[2])>1e-7?(double)pt[2]:0.0);
|
||||
|
||||
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 = fabs(pt[0])>1e-7 ? pt[0] / factor : 0.0;
|
||||
float yuser = fabs(pt[1])>1e-7 ? pt[1] / factor : 0.0;
|
||||
float zuser = fabs(pt[2])>1e-7 ? pt[2] / factor : 0.0;
|
||||
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%f, %f, %f) %s",documentName.getValue().getString()
|
||||
,objectName.getValue().getString()
|
||||
,subElementName.getValue().getString()
|
||||
,fabs(pt[0])>1e-7?pt[0]:0.0
|
||||
,fabs(pt[1])>1e-7?pt[1]:0.0
|
||||
,fabs(pt[2])>1e-7?pt[2]:0.0);
|
||||
|
||||
,xuser,yuser,zuser,unit.toLatin1().data());
|
||||
|
||||
getMainWindow()->showMessage(QString::fromLatin1(buf));
|
||||
}
|
||||
else { // picked point
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Gui/Document.h>
|
||||
@@ -479,14 +480,46 @@ bool SoFCUnifiedSelection::setHighlight(SoFullPath *path, const SoDetail *det,
|
||||
{
|
||||
const char *docname = vpd->getObject()->getDocument()->getName();
|
||||
const char *objname = vpd->getObject()->getNameInDocument();
|
||||
|
||||
|
||||
Base::Quantity mmx(Base::Quantity::MilliMetre);
|
||||
mmx.setValue(fabs(x)>1e-7?(double)x:0.0);
|
||||
Base::Quantity mmy(Base::Quantity::MilliMetre);
|
||||
mmy.setValue(fabs(y)>1e-7?(double)y:0.0);
|
||||
Base::Quantity mmz(Base::Quantity::MilliMetre);
|
||||
mmz.setValue(fabs(z)>1e-7?(double)z:0.0);
|
||||
|
||||
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 = fabs(x)>1e-7 ? x / factor : 0.0;
|
||||
float yuser = fabs(y)>1e-7 ? y / factor : 0.0;
|
||||
float zuser = fabs(z)>1e-7 ? z / factor : 0.0;
|
||||
|
||||
this->preSelection = 1;
|
||||
static char buf[513];
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%g, %g, %g)"
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%f, %f, %f) %s"
|
||||
,docname,objname,element
|
||||
,fabs(x)>1e-7?x:0.0
|
||||
,fabs(y)>1e-7?y:0.0
|
||||
,fabs(z)>1e-7?z:0.0);
|
||||
,xuser,yuser,zuser,unit.toLatin1().data());
|
||||
|
||||
getMainWindow()->showMessage(QString::fromLatin1(buf));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user