Skip to content

Commit

Permalink
[TD] fix bug with angular and small values
Browse files Browse the repository at this point in the history
* angular as reported here: https://forum.freecadweb.org/viewtopic.php?f=35&t=53473&start=10#p461507
* small values: since we convert to e.g. mm, we must then not output e.g. 'µm'
* also a code optimization, fix a typo, removal of a meanwhile misleading comment
  • Loading branch information
donovaly authored and wwmayer committed Dec 30, 2020
1 parent 81a5ec5 commit 30fcdda
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Mod/TechDraw/App/DrawViewDimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
}
m_arcPoints = pts;
m_hasGeometry = true;
} else if(Type.isValue("Angle")){
} else if (Type.isValue("Angle")){
if (getRefType() != twoEdge) {
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
return App::DocumentObject::StdReturn;
Expand Down Expand Up @@ -529,7 +529,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
pts.vertex = apex;
m_anglePoints = pts;
m_hasGeometry = true;
} else if(Type.isValue("Angle3Pt")){
} else if (Type.isValue("Angle3Pt")){
if (getRefType() != threeVertex) {
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
return App::DocumentObject::StdReturn;
Expand Down Expand Up @@ -629,8 +629,6 @@ std::string DrawViewDimension::formatValue(qreal value, QString qFormatSpec, int
QString qUserString = asQuantity.getUserString(); // this handles mm to inch/km/parsec etc
// and decimal positions but won't give more than
// Global_Decimals precision
// really should be able to ask units for value
// in appropriate UoM!!

//units api: get schema to figure out if this is multi-value schema(Imperial1, ImperialBuilding, etc)
//if it is multi-unit schema, don't even try to use Alt Decimals
Expand Down Expand Up @@ -664,7 +662,7 @@ std::string DrawViewDimension::formatValue(qreal value, QString qFormatSpec, int
formattedValue = qMultiValueStr;
} else {
if (formatSpecifier.isEmpty()) {
Base::Console().Warning("Warning - no numeric format in formatSpec %s - %s\n",
Base::Console().Warning("Warning - no numeric format in Format Spec %s - %s\n",
qPrintable(qFormatSpec), getNameInDocument());
return Base::Tools::toStdString(qFormatSpec);
}
Expand Down Expand Up @@ -693,7 +691,16 @@ std::string DrawViewDimension::formatValue(qreal value, QString qFormatSpec, int
// get the conversion factor for the unit
double convertValue = Base::Quantity::parse(QString::fromLatin1("1") + QString::fromStdString(BaseLengthUnit)).getValue();
// the result is now just val / convertValue because val is always in the base unit
double userVal = asQuantity.getValue() / convertValue;
// don't do this for angular values since they are not in the BaseLengthUnit
double userVal;
if (!angularMeasure) {
userVal = asQuantity.getValue() / convertValue;
// since we converted to the BaseLengthUnit we must assure it is also used for qUserStringUnits
qUserStringUnits = QChar::fromLatin1(' ') + QString::fromStdString(BaseLengthUnit);
}
else {
userVal = asQuantity.getValue();
}

// we reformat the value
// the user can overwrite the decimal settings, so we must in every case use the formatSpecifier
Expand Down Expand Up @@ -751,7 +758,7 @@ std::string DrawViewDimension::formatValue(qreal value, QString qFormatSpec, int
Base::Tools::toStdString(formatSuffix);
}
else if (partial == 2) { // just the unit
if ((Type.isValue("Angle")) || (Type.isValue("Angle3Pt"))) {
if (angularMeasure) {
// remove space between dimension and unit if unit is not "deg"
if ( !qUserStringUnits.contains(QString::fromLatin1("deg")) ) {
QRegExp space(QString::fromUtf8("\\s"));
Expand Down

0 comments on commit 30fcdda

Please sign in to comment.