WIP. Moving to other machine.
This commit is contained in:
committed by
Yorik van Havre
parent
504e75d441
commit
0fb8306380
@@ -84,6 +84,8 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/UnitsSchema.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Document.h>
|
||||
@@ -2750,25 +2752,66 @@ QString ViewProviderSketch::getPresentationString(const Constraint *constraint)
|
||||
Base::Reference<ParameterGrp> hGrpSketcher; // param group that includes HideUnits option
|
||||
bool iHideUnits;
|
||||
QString userStr; // final return string
|
||||
QString dummy; // not used but required
|
||||
double factor; // unit scaling factor
|
||||
|
||||
QString unitStr; // the actual unit string
|
||||
QString baseUnitStr; // the expected base unit string
|
||||
double factor; // unit scaling factor, currently not used
|
||||
Base::UnitSystem unitSys; // current unit system
|
||||
|
||||
// Get value of HideUnits option. Default is false.
|
||||
hGrpSketcher = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Sketcher");
|
||||
iHideUnits = hGrpSketcher->GetBool("HideUnits", 0l);
|
||||
|
||||
// Get the current display string including units
|
||||
userStr = constraint->getPresentationValue().getUserString(factor, dummy);
|
||||
userStr = constraint->getPresentationValue().getUserString(factor, unitStr);
|
||||
|
||||
// Hide units if user has requested it and is being displayed in the base
|
||||
// units. Otherwise, display units.
|
||||
// Hide units if user has requested it, is being displayed in the base
|
||||
// units, and the schema being used has a clear base unit in the first
|
||||
// place. Otherwise, display units.
|
||||
if( iHideUnits )
|
||||
{
|
||||
Base::Quantity quat;
|
||||
double baseFactor;
|
||||
// Only hide the default length unit. Right now there is not an easy way
|
||||
// to get that from the Unit system so we have to manually add it here.
|
||||
// Hopfully this can be added in the future so this code won't have to
|
||||
// be updated if a new units schema is added.
|
||||
unitSys = Base::UnitsApi::getSchema();
|
||||
|
||||
quat.setValue(1);
|
||||
quat.setUnit(Base::Unit::Length);
|
||||
// If this is a supported unit system then define what the base unit is.
|
||||
switch (unitSys)
|
||||
{
|
||||
case Base::SI1:
|
||||
case Base::MmMin:
|
||||
baseUnitStr = QString::fromLatin1("mm");
|
||||
break;
|
||||
|
||||
case Base::SI2:
|
||||
baseUnitStr = QString::fromLatin1("m");
|
||||
break;
|
||||
|
||||
case Base::ImperialDecimal:
|
||||
baseUnitStr = QString::fromLatin1("in");
|
||||
break;
|
||||
|
||||
case Base::Centimeters:
|
||||
baseUnitStr = QString::fromLatin1("cm");
|
||||
break;
|
||||
|
||||
default:
|
||||
// Nothing to do
|
||||
break;
|
||||
}
|
||||
|
||||
if( !baseUnitStr.isEmpty() )
|
||||
{
|
||||
cout << baseUnitStr.toAscii().data() << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Base::Quantity quat;
|
||||
//double baseFactor;
|
||||
|
||||
//quat.setValue(1);
|
||||
//quat.setUnit(Base::Unit::Length);
|
||||
|
||||
|
||||
// QString getUserString (double &factor, QString &unitString) const
|
||||
@@ -2777,16 +2820,21 @@ QString ViewProviderSketch::getPresentationString(const Constraint *constraint)
|
||||
// and not centimeters)
|
||||
|
||||
// render string with a unity valued quanity to get base factor
|
||||
quat.getUserString(baseFactor, dummy);
|
||||
//quat.getUserString(baseFactor, dummy);
|
||||
|
||||
// if factors are different, userStr is not in base units. Do not omit.
|
||||
if( baseFactor == factor )
|
||||
{
|
||||
// rendered in base units, strip them out
|
||||
// Example code from: Mod/TechDraw/App/DrawViewDimension.cpp:372
|
||||
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
|
||||
userStr.remove(rxUnits); //getUserString(defaultDecimals) without units
|
||||
}
|
||||
//cout << "Value of constraint: " << constraint->getValue() << endl
|
||||
// << "factor " << factor << endl
|
||||
// << "baseFactor " << baseFactor << endl
|
||||
// << "Unit string: " << unitStr.toAscii().data() << endl;
|
||||
|
||||
//// if factors are different, userStr is not in base units. Do not omit.
|
||||
//if( baseFactor == factor )
|
||||
//{
|
||||
// // rendered in base units, strip them out
|
||||
// // Example code from: Mod/TechDraw/App/DrawViewDimension.cpp:372
|
||||
// QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
|
||||
// userStr.remove(rxUnits); //getUserString(defaultDecimals) without units
|
||||
//}
|
||||
}
|
||||
|
||||
return userStr;
|
||||
|
||||
Reference in New Issue
Block a user