Fix #3623 Display of Ft/In Dimensions

This commit is contained in:
wandererfan
2018-10-09 20:31:58 -04:00
committed by wmayer
parent bc9ffa5b41
commit 4bcfb4a1cd
3 changed files with 77 additions and 65 deletions

View File

@@ -364,7 +364,6 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
m_arcPoints = pts;
m_hasGeometry = true;
} else if(Type.isValue("Angle")){
//TODO: do we need to distinguish inner vs outer angle? -wf
if (getRefType() != twoEdge) {
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
return App::DocumentObject::StdReturn;
@@ -449,12 +448,23 @@ std::string DrawViewDimension::getFormatedValue(bool obtuse)
return FormatSpec.getStrValue();
}
//units api: get schema to figure out if this is multi-value schema(Imperial1, ImperialBuilding)
//if it is multi-unit schema, don't even try to use Alt Decimals or format per format spec
bool multiValueUnits = false;
Base::UnitSystem uniSys = Base::UnitsApi::getSchema();
if ( (uniSys == Base::UnitSystem::Imperial1) ||
(uniSys == Base::UnitSystem::ImperialBuilding) ) {
multiValueUnits = true;
}
QString specStr = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size());
double val = std::abs(getDimValue()); //internal units!
bool angularMeasure = false;
Base::Quantity qVal;
qVal.setValue(val);
if (Type.isValue("Angle")) {
if ( (Type.isValue("Angle")) ||
(Type.isValue("Angle3Pt")) ) {
angularMeasure = true;
qVal.setUnit(Base::Unit::Angle);
if (obtuse) {
qVal.setValue(fabs(360.0 - val));
@@ -463,58 +473,66 @@ std::string DrawViewDimension::getFormatedValue(bool obtuse)
qVal.setUnit(Base::Unit::Length);
}
QString userStr = qVal.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!!
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
QString userStr = qVal.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!!
QString userVal = userStr;
userVal.remove(rxUnits); //getUserString(defaultDecimals) without units
QLocale loc;
double userValNum = loc.toDouble(userVal);
QString userUnits;
int pos = 0;
if ((pos = rxUnits.indexIn(userStr, 0)) != -1) {
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
}
//find the %x.y tag in FormatSpec
QRegExp rxFormat(QString::fromUtf8("%[0-9]*\\.*[0-9]*[aefgAEFG]")); //printf double format spec
QString match;
QString specVal = userVal; //sensible default
pos = 0;
if ((pos = rxFormat.indexIn(specStr, 0)) != -1) {
match = rxFormat.cap(0); //entire capture of rx
#if QT_VERSION >= 0x050000
specVal = QString::asprintf(Base::Tools::toStdString(match).c_str(),userValNum);
#else
QString qs2;
specVal = qs2.sprintf(Base::Tools::toStdString(match).c_str(),userValNum);
#endif
}
QString repl = userVal;
if (useDecimals()) {
if (showUnits()) {
repl = userStr;
} else {
repl = userVal;
}
if (multiValueUnits &&
!angularMeasure) {
specStr = userStr;
} else {
if (showUnits()) {
repl = specVal + userUnits;
} else {
repl = specVal;
}
}
//should be able to handle angular Measures even in ft-in systems
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
specStr.replace(match,repl);
//this next bit is so inelegant!!!
QChar dp = QChar::fromLatin1('.');
if (loc.decimalPoint() != dp) {
specStr.replace(dp,loc.decimalPoint());
QString userVal = userStr;
userVal.remove(rxUnits); //getUserString(defaultDecimals) without units
QLocale loc;
double userValNum = loc.toDouble(userVal);
QString userUnits;
int pos = 0;
if ((pos = rxUnits.indexIn(userStr, 0)) != -1) {
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
}
//find the %x.y tag in FormatSpec
QRegExp rxFormat(QString::fromUtf8("%[0-9]*\\.*[0-9]*[aefgAEFG]")); //printf double format spec
QString match;
QString specVal = userVal; //sensible default
pos = 0;
if ((pos = rxFormat.indexIn(specStr, 0)) != -1) {
match = rxFormat.cap(0); //entire capture of rx
#if QT_VERSION >= 0x050000
specVal = QString::asprintf(Base::Tools::toStdString(match).c_str(),userValNum);
#else
QString qs2;
specVal = qs2.sprintf(Base::Tools::toStdString(match).c_str(),userValNum);
#endif
}
QString repl = userVal;
if (useDecimals()) {
if (showUnits()) {
repl = userStr;
} else {
repl = userVal;
}
} else {
if (showUnits()) {
repl = specVal + userUnits;
} else {
repl = specVal;
}
}
repl = Base::Tools::fromStdString(getPrefix()) + repl;
specStr.replace(match,repl);
//this next bit is so inelegant!!!
QChar dp = QChar::fromLatin1('.');
if (loc.decimalPoint() != dp) {
specStr.replace(dp,loc.decimalPoint());
}
}
return specStr.toUtf8().constData();

View File

@@ -225,8 +225,7 @@ void QGIDatumLabel::setTolString()
QString html = QString::fromUtf8("<div>%1 <br/>%2 </div>");
html = html.arg(overFormat).arg(underFormat);
m_tolText->setHtml(html); //<<< sometimes seg fault here in FT_Outline_Decompose ()
//<<< only angle measures with degree symbol shown??
m_tolText->setHtml(html);
return;
}
@@ -277,7 +276,8 @@ void QGIDatumLabel::setPrettyNormal(void)
//**************************************************************
QGIViewDimension::QGIViewDimension() :
hasHover(false),
m_lineWidth(0.0)
m_lineWidth(0.0),
m_obtuse(false)
{
setHandlesChildEvents(false);
setFlag(QGraphicsItem::ItemIsMovable, false);
@@ -369,7 +369,6 @@ void QGIViewDimension::updateView(bool update)
return;
}
// Identify what changed to prevent complete redraw
if (update||
dim->X.isTouched() ||
dim->Y.isTouched()) {
@@ -397,6 +396,7 @@ void QGIViewDimension::updateView(bool update)
void QGIViewDimension::updateDim(bool obtuse)
{
(void) obtuse;
const auto dim( dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()) );
if( dim == nullptr ) {
return;
@@ -406,7 +406,7 @@ void QGIViewDimension::updateDim(bool obtuse)
return;
}
QString labelText = QString::fromUtf8(dim->getFormatedValue(obtuse).c_str());
QString labelText = QString::fromUtf8(dim->getFormatedValue(m_obtuse).c_str());
QFont font = datumLabel->getFont();
font.setPointSizeF(Rez::guiX(vp->Fontsize.getValue()));
@@ -484,7 +484,6 @@ void QGIViewDimension::draw()
m_lineWidth = Rez::guiX(vp->LineWidth.getValue());
float margin = Rez::guiX(5.f);
// QString labelText = datumLabel->toPlainText();
QString labelText = getLabelText();
Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0); //already Qt gui coords
@@ -1166,7 +1165,6 @@ void QGIViewDimension::draw()
// }
} else if( (strcmp(dimType, "Angle") == 0) ||
(strcmp(dimType, "Angel3Pt")) ) {
// Only use two straight line edeges for angle
anglePoints pts = dim->getAnglePoints();
Base::Vector3d X(1.0,0.0,0.0);
Base::Vector3d vertex = Rez::guiX(pts.vertex);
@@ -1206,11 +1204,6 @@ void QGIViewDimension::draw()
double textOffset = textHeight/2.0 + offsetFudge;
double radius = labelVec.Length() - textOffset;
double labelangle = atan2(-labelVec.y, labelVec.x); //angle with +X axis on [-PI,+PI] (iso)
if (labelangle < 0) { //map to [0,2PI) (asme angle = 0.0)
labelangle += 2.0 * M_PI;
}
QRectF arcRect(vertex.x - radius, vertex.y - radius, 2. * radius, 2. * radius);
Base::Vector3d ar0Pos = vertex + d0 * radius;
Base::Vector3d ar1Pos = vertex + d1 * radius;
@@ -1264,15 +1257,15 @@ void QGIViewDimension::draw()
path.arcMoveTo(arcRect, startangle * 180 / M_PI);
double actualSweep = 0.0;
m_obtuse = false;
if(isOutside) {
updateDim(true);
m_obtuse = true;
if (ccwInner) { //inner is ccw so outer is cw and sweep is -ve
actualSweep = -outsideAngle;
} else { //inner is cw so outer is ccw and sweep is +ve
actualSweep = outsideAngle;
}
} else {
updateDim(false);
if (ccwInner) { //inner is ccw and sweep is +ve
actualSweep = insideAngle;
} else { //inner is cw and sweep is -ve

View File

@@ -156,6 +156,7 @@ protected:
QGIArrow* aHead2;
//QGICMark* centerMark
double m_lineWidth;
bool m_obtuse;
};
} // namespace MDIViewPageGui