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));
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include "View3DInventorViewer.h"
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include "SoFCSelection.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Selection.h"
|
||||
@@ -75,6 +74,10 @@
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
namespace Gui {
|
||||
std::array<std::pair<double, std::string>,3 > schemaTranslatePoint(double x, double y, double z, double precision);
|
||||
}
|
||||
|
||||
SoFullPath * Gui::SoFCSelection::currenthighlight = NULL;
|
||||
|
||||
|
||||
@@ -403,44 +406,15 @@ SoFCSelection::handleEvent(SoHandleEventAction * action)
|
||||
|
||||
const auto &pt = pp->getPoint();
|
||||
|
||||
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()
|
||||
,xuser,yuser,zuser,unit.toLatin1().data());
|
||||
auto pts = schemaTranslatePoint(pt[0], pt[1], pt[2], 1e-7);
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%f, %f, %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());
|
||||
|
||||
getMainWindow()->showMessage(QString::fromLatin1(buf));
|
||||
}
|
||||
|
||||
@@ -79,7 +79,6 @@
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Gui/Document.h>
|
||||
@@ -101,6 +100,10 @@ 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);
|
||||
}
|
||||
|
||||
SoFullPath * Gui::SoFCUnifiedSelection::currenthighlight = NULL;
|
||||
|
||||
// *************************************************************************
|
||||
@@ -480,46 +483,14 @@ 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];
|
||||
|
||||
auto pts = schemaTranslatePoint(x, y, z, 1e-7);
|
||||
snprintf(buf,512,"Preselected: %s.%s.%s (%f, %f, %f) %s"
|
||||
,docname,objname,element
|
||||
,xuser,yuser,zuser,unit.toLatin1().data());
|
||||
,pts[0].first,pts[1].first,pts[2].first,pts[0].second.c_str());
|
||||
|
||||
getMainWindow()->showMessage(QString::fromLatin1(buf));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user