From 40bd4b806fc34ec192a1917a034ecffccd99340f Mon Sep 17 00:00:00 2001 From: Aapo Date: Fri, 27 Nov 2020 20:59:18 +0200 Subject: [PATCH] [TD] Add tolerance format specifiers and arbitrary tolerances. --- src/Mod/TechDraw/App/DrawViewDimension.cpp | 26 ++++++++++++- src/Mod/TechDraw/App/DrawViewDimension.h | 4 ++ src/Mod/TechDraw/Gui/QGIViewDimension.cpp | 44 +++++++--------------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index c0969743a7..a1b1a4b290 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -92,7 +92,10 @@ DrawViewDimension::DrawViewDimension(void) References3D.setScope(App::LinkScope::Global); ADD_PROPERTY_TYPE(FormatSpec,(getDefaultFormatSpec()) , "Format", App::Prop_Output,"Dimension Format"); + ADD_PROPERTY_TYPE(FormatSpecOverTolerance,("%+g") , "Format", App::Prop_Output,"Dimension Overtolerance Format"); + ADD_PROPERTY_TYPE(FormatSpecUnderTolerance,("%+g") , "Format", App::Prop_Output,"Dimension Undertolerance Format"); ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format", App::Prop_Output,"Value overridden by user"); + ADD_PROPERTY_TYPE(ArbitraryTolerances,(false) ,"Format", App::Prop_Output,"Tolerance values overridden by user"); Type.setEnums(TypeEnums); //dimension type: length, radius etc ADD_PROPERTY(Type,((long)0)); @@ -685,10 +688,31 @@ std::string DrawViewDimension::formatValue(qreal value, QString qFormatSpec, int } +QStringList DrawViewDimension::getFormattedToleranceValues(int partial) +{ + QString underFormatSpec = QString::fromUtf8(FormatSpecUnderTolerance.getStrValue().data()); + QString overFormatSpec = QString::fromUtf8(FormatSpecOverTolerance.getStrValue().data()); + QStringList tolerances; + QString underTolerance, overTolerance; + + if (ArbitraryTolerances.getValue()) { + underTolerance = underFormatSpec; + overTolerance = overFormatSpec; + } else { + underTolerance = QString::fromUtf8(formatValue(UnderTolerance.getValue(), underFormatSpec, partial).c_str()); + overTolerance = QString::fromUtf8(formatValue(OverTolerance.getValue(), overFormatSpec, partial).c_str()); + } + + tolerances << underTolerance << overTolerance; + + return tolerances; +} + + std::string DrawViewDimension::getFormattedDimensionValue(int partial) { // Base::Console().Message("DVD::getFormattedValue(%d)\n", partial); - QString qFormatSpec = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size()); + QString qFormatSpec = QString::fromUtf8(FormatSpec.getStrValue().data()); if (Arbitrary.getValue()) { return FormatSpec.getStrValue(); diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h index 0a34ff493a..ed739b29cd 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.h +++ b/src/Mod/TechDraw/App/DrawViewDimension.h @@ -101,7 +101,10 @@ public: App::PropertyBool TheoreticalExact; App::PropertyBool Inverted; App::PropertyString FormatSpec; + App::PropertyString FormatSpecUnderTolerance; + App::PropertyString FormatSpecOverTolerance; App::PropertyBool Arbitrary; + App::PropertyBool ArbitraryTolerances; App::PropertyFloat OverTolerance; App::PropertyFloat UnderTolerance; @@ -133,6 +136,7 @@ public: //return PyObject as DrawViewDimensionPy virtual PyObject *getPyObject(void) override; + virtual QStringList getFormattedToleranceValues(int partial = 0); virtual std::string getFormattedDimensionValue(int partial = 0); virtual std::string formatValue(qreal value, QString qFormatSpec, int partial = 0); diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp index f745c511d1..8ebb16ad13 100644 --- a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp @@ -328,46 +328,28 @@ void QGIDatumLabel::setTolString() m_tolTextOver->show(); m_tolTextUnder->show(); - double overTol = dim->OverTolerance.getValue(); - double underTol = dim->UnderTolerance.getValue(); - - int precision = getPrecision(); - QString qsPrecision = QString::number(precision); - QString qsFormatOver = QString::fromUtf8("%+.") + //show sign - qsPrecision + - QString::fromUtf8("g"); //trim trailing zeroes - if (DrawUtil::fpCompare(overTol, 0.0, pow(10.0, -precision))) { - qsFormatOver = QString::fromUtf8("%.") + //no sign - qsPrecision + - QString::fromUtf8("g"); - } - - QString qsFormatUnder = QString::fromUtf8("%+.") + //show sign - qsPrecision + - QString::fromUtf8("g"); //trim trailing zeroes - if (DrawUtil::fpCompare(underTol, 0.0, pow(10.0, -precision))) { - qsFormatUnder = QString::fromUtf8("%.") + //no sign - qsPrecision + - QString::fromUtf8("g"); //trim trailing zeroes - } QString tolSuffix; if ((dim->Type.isValue("Angle")) || (dim->Type.isValue("Angle3Pt"))) { tolSuffix = QString::fromUtf8(dim->getFormattedDimensionValue(2).c_str()); //just the unit } - QString overFormat; - QString underFormat; + QStringList labelTexts, unitTexts; - if (dim->isMultiValueSchema()) { - overFormat = QString::fromUtf8(dim->formatValue(overTol, qsFormatOver, 0).c_str()); - underFormat = QString::fromUtf8(dim->formatValue(underTol, qsFormatUnder, 0).c_str()); + if (dim->ArbitraryTolerances.getValue()) { + labelTexts = dim->getFormattedToleranceValues(1); //just the number pref/spec/suf + unitTexts << QString::fromLatin1("") << QString::fromLatin1(""); } else { - overFormat = QString::fromUtf8(dim->formatValue(overTol, qsFormatOver, 1).c_str()); - underFormat = QString::fromUtf8(dim->formatValue(underTol, qsFormatUnder, 1).c_str()); + if (dim->isMultiValueSchema()) { + labelTexts = dim->getFormattedToleranceValues(0); //don't format multis + unitTexts << QString::fromLatin1("") << QString::fromLatin1(""); + } else { + labelTexts = dim->getFormattedToleranceValues(1); //just the number pref/spec/suf + unitTexts = dim->getFormattedToleranceValues(2); //just the unit + } } - m_tolTextOver->setPlainText(overFormat + tolSuffix); - m_tolTextUnder->setPlainText(underFormat + tolSuffix); + m_tolTextUnder->setPlainText(labelTexts[0] + unitTexts[0]); + m_tolTextOver->setPlainText(labelTexts[1] + unitTexts[1]); return; }