[TD] Add tolerance format specifiers and arbitrary tolerances.

This commit is contained in:
Aapo
2020-11-27 20:59:18 +02:00
committed by wwmayer
parent eb22a14a3b
commit 40bd4b806f
3 changed files with 42 additions and 32 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -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;
}