diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
index 07f06c2483..85c95df3d9 100644
--- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
+++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
@@ -84,6 +84,8 @@
#include
#include
#include
+#include
+#include
#include
#include
#include
@@ -2750,25 +2752,66 @@ QString ViewProviderSketch::getPresentationString(const Constraint *constraint)
Base::Reference 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;