Skip to content

Commit

Permalink
[TD] Add tolerance format specifiers and arbitrary tolerances.
Browse files Browse the repository at this point in the history
  • Loading branch information
aapo-aapo authored and wwmayer committed Dec 2, 2020
1 parent 768a2b1 commit 3f62357
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
26 changes: 25 additions & 1 deletion src/Mod/TechDraw/App/DrawViewDimension.cpp
Expand Up @@ -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");

This comment has been minimized.

Copy link
@donovaly

donovaly Dec 2, 2020

Member

Why is %+g hardcoded? I think the tolerances should have the same precision than the dimension.

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));
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/TechDraw/App/DrawViewDimension.h
Expand Up @@ -101,7 +101,10 @@ class TechDrawExport DrawViewDimension : public TechDraw::DrawView
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;

Expand Down Expand Up @@ -133,6 +136,7 @@ class TechDrawExport DrawViewDimension : public TechDraw::DrawView
//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);

Expand Down
44 changes: 13 additions & 31 deletions src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3f62357

Please sign in to comment.