[TD]oblique section lines
This commit is contained in:
@@ -75,6 +75,13 @@ QGISectionLine::QGISectionLine()
|
||||
void QGISectionLine::draw()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
int format = getPrefSectionStandard();
|
||||
if (format == ANSISTANDARD) { //"ASME"/"ANSI"
|
||||
extensionEndsTrad();
|
||||
} else {
|
||||
extensionEndsISO();
|
||||
}
|
||||
|
||||
makeLine();
|
||||
makeArrows();
|
||||
makeSymbols();
|
||||
@@ -84,37 +91,15 @@ void QGISectionLine::draw()
|
||||
void QGISectionLine::makeLine()
|
||||
{
|
||||
QPainterPath pp;
|
||||
QPointF beginExtLine1,beginExtLine2; //ext line start pts for measure Start side and measure End side
|
||||
QPointF endExtLine1, endExtLine2;
|
||||
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y);
|
||||
int format = getPrefSectionStandard();
|
||||
if (format == ANSISTANDARD) { //"ASME"/"ANSI"
|
||||
//draw from section line endpoint
|
||||
QPointF offsetBegin = m_extLen * offsetDir;
|
||||
beginExtLine1 = m_start; //from
|
||||
beginExtLine2 = m_end; //to
|
||||
endExtLine1 = m_start + offsetBegin;
|
||||
endExtLine2 = m_end + offsetBegin;
|
||||
pp.moveTo(beginExtLine1);
|
||||
pp.lineTo(endExtLine1);
|
||||
pp.moveTo(beginExtLine2);
|
||||
pp.lineTo(endExtLine2);
|
||||
} else { //"ISO"
|
||||
//draw from just short of section line away from section line
|
||||
QPointF offsetBegin = Rez::guiX(QGIArrow::getOverlapAdjust(0,QGIArrow::getPrefArrowSize())) * offsetDir;
|
||||
QPointF offsetEnd = offsetBegin + (m_extLen * offsetDir);
|
||||
beginExtLine1 = m_start - offsetBegin;
|
||||
beginExtLine2 = m_end - offsetBegin;
|
||||
endExtLine1 = m_start - offsetEnd;
|
||||
endExtLine2 = m_end - offsetEnd;
|
||||
pp.moveTo(beginExtLine1);
|
||||
pp.lineTo(endExtLine1);
|
||||
pp.moveTo(beginExtLine2);
|
||||
pp.lineTo(endExtLine2);
|
||||
}
|
||||
|
||||
pp.moveTo(m_end);
|
||||
pp.lineTo(m_start); //sectionLine
|
||||
pp.moveTo(m_beginExt1);
|
||||
pp.lineTo(m_endExt1);
|
||||
|
||||
pp.moveTo(m_beginExt2);
|
||||
pp.lineTo(m_endExt2);
|
||||
|
||||
pp.moveTo(m_start);
|
||||
pp.lineTo(m_end);
|
||||
m_line->setPath(pp);
|
||||
}
|
||||
|
||||
@@ -165,8 +150,14 @@ void QGISectionLine::makeArrowsTrad()
|
||||
|
||||
QPointF posArrow1,posArrow2;
|
||||
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y); //remember Y dir is flipped
|
||||
double offsetLength = m_extLen + Rez::guiX(QGIArrow::getOverlapAdjust(0,QGIArrow::getPrefArrowSize()));
|
||||
|
||||
double oblique = 1.0;
|
||||
if ( !DrawUtil::fpCompare((m_arrowDir.x + m_arrowDir.y), 1.0) ) {
|
||||
oblique = 1.25;
|
||||
}
|
||||
double offsetLength = (m_extLen * oblique) + Rez::guiX(QGIArrow::getPrefArrowSize());
|
||||
QPointF offsetVec = offsetLength * offsetDir;
|
||||
|
||||
posArrow1 = m_start + offsetVec;
|
||||
posArrow2 = m_end + offsetVec;
|
||||
|
||||
@@ -195,58 +186,114 @@ void QGISectionLine::makeSymbols()
|
||||
|
||||
void QGISectionLine::makeSymbolsTrad()
|
||||
{
|
||||
QPointF extLineStart,extLineEnd;
|
||||
QPointF offset(m_arrowDir.x,-m_arrowDir.y);
|
||||
offset = 1.5 * m_extLen * offset;
|
||||
extLineStart = m_start + offset;
|
||||
extLineEnd = m_end + offset;
|
||||
prepareGeometryChange();
|
||||
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
|
||||
m_symbol1->setFont(m_symFont);
|
||||
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
|
||||
m_symbol2->setFont(m_symFont);
|
||||
m_symbol2->setPlainText(QString::fromUtf8(m_symbol));
|
||||
|
||||
QRectF symRect = m_symbol1->boundingRect();
|
||||
double symWidth = symRect.width();
|
||||
double symHeight = symRect.height();
|
||||
double symbolFudge = 1.0;
|
||||
double symbolFudge = 0.75;
|
||||
double angle = atan2f(m_arrowDir.y,m_arrowDir.x);
|
||||
if (angle < 0.0) {
|
||||
angle = 2 * M_PI + angle;
|
||||
}
|
||||
Base::Vector3d adjustVector(cos(angle) * symWidth, sin(angle) * symHeight, 0.0);
|
||||
adjustVector = (DrawUtil::invertY(adjustVector) / 2.0) * symbolFudge;
|
||||
adjustVector = DrawUtil::invertY(adjustVector) * symbolFudge;
|
||||
QPointF qAdjust(adjustVector.x, adjustVector.y);
|
||||
|
||||
extLineStart += qAdjust;
|
||||
m_symbol1->centerAt(extLineStart);
|
||||
QPointF posSymbol1 = m_arrow1->pos() + qAdjust;
|
||||
m_symbol1->centerAt(posSymbol1);
|
||||
|
||||
m_symbol2->setFont(m_symFont);
|
||||
m_symbol2->setPlainText(QString::fromUtf8(m_symbol));
|
||||
extLineEnd += qAdjust;
|
||||
m_symbol2->centerAt(extLineEnd);
|
||||
QPointF posSymbol2 = m_arrow2->pos() + qAdjust;
|
||||
m_symbol2->centerAt(posSymbol2);
|
||||
}
|
||||
|
||||
void QGISectionLine::makeSymbolsISO()
|
||||
{
|
||||
QPointF symPosStart, symPosEnd;
|
||||
QPointF dist = (m_start - m_end);
|
||||
double lenDist = sqrt(dist.x()*dist.x() + dist.y()*dist.y());
|
||||
QPointF distDir = dist / lenDist;
|
||||
|
||||
QPointF offset = m_extLen * distDir;
|
||||
symPosStart = m_start + offset;
|
||||
symPosEnd = m_end - offset;
|
||||
|
||||
prepareGeometryChange();
|
||||
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
|
||||
m_symbol1->setFont(m_symFont);
|
||||
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
|
||||
m_symbol1->centerAt(symPosStart);
|
||||
|
||||
m_symbol2->setFont(m_symFont);
|
||||
m_symbol2->setPlainText(QString::fromUtf8(m_symbol));
|
||||
m_symbol2->centerAt(symPosEnd);
|
||||
|
||||
QPointF symPosStart, symPosEnd;
|
||||
//no normalize() for QPointF
|
||||
QPointF dist = (m_start - m_end);
|
||||
double lenDist = sqrt(dist.x()*dist.x() + dist.y()*dist.y());
|
||||
QPointF offsetDir = dist / lenDist;
|
||||
|
||||
QRectF symRect = m_symbol1->boundingRect();
|
||||
double symWidth = symRect.width();
|
||||
double symHeight = symRect.height();
|
||||
|
||||
double symbolFudge = 0.75;
|
||||
double angle = atan2f(offsetDir.y(), offsetDir.x());
|
||||
if (angle < 0.0) {
|
||||
angle = 2.0 * M_PI + angle;
|
||||
}
|
||||
Base::Vector3d adjustVector(cos(angle) * symWidth, sin(angle) * symHeight, 0.0);
|
||||
adjustVector = adjustVector * symbolFudge;
|
||||
QPointF qAdjust(adjustVector.x, adjustVector.y);
|
||||
|
||||
symPosStart = m_start + qAdjust;
|
||||
symPosEnd = m_end - qAdjust;
|
||||
|
||||
m_symbol1->centerAt(symPosStart);
|
||||
m_symbol2->centerAt(symPosEnd);
|
||||
}
|
||||
|
||||
void QGISectionLine::extensionEndsTrad()
|
||||
{
|
||||
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y);
|
||||
|
||||
//extensions for oblique section line needs to be a bit longer
|
||||
double oblique = 1.0;
|
||||
if ( !DrawUtil::fpCompare((m_arrowDir.x + m_arrowDir.y), 1.0) ) {
|
||||
oblique = 1.25;
|
||||
}
|
||||
|
||||
//draw from section line endpoint
|
||||
QPointF offsetEnd = oblique * m_extLen * offsetDir;
|
||||
m_beginExt1 = m_start;
|
||||
m_endExt1 = m_start + offsetEnd;
|
||||
m_beginExt2 = m_end;
|
||||
m_endExt2 = m_end + offsetEnd;
|
||||
}
|
||||
|
||||
void QGISectionLine::extensionEndsISO()
|
||||
{
|
||||
//lines are offset to other side of section line!
|
||||
QPointF offsetDir(m_arrowDir.x,-m_arrowDir.y);
|
||||
offsetDir = offsetDir * -1.0;
|
||||
|
||||
//extensions for oblique section line needs to be a bit longer?
|
||||
//this is just esthetics
|
||||
double oblique = 1.0;
|
||||
if ( !DrawUtil::fpCompare((m_arrowDir.x + m_arrowDir.y), 1.0) ) {
|
||||
oblique = 1.10;
|
||||
}
|
||||
|
||||
//draw from section line endpoint less arrow length
|
||||
QPointF offsetStart = offsetDir * Rez::guiX(QGIArrow::getPrefArrowSize());
|
||||
QPointF offsetEnd = oblique * m_extLen * offsetDir;
|
||||
|
||||
m_beginExt1 = m_start + offsetStart;
|
||||
m_endExt1 = m_start + offsetStart + offsetEnd;
|
||||
m_beginExt2 = m_end + offsetStart;
|
||||
m_endExt2 = m_end + offsetStart + offsetEnd;
|
||||
}
|
||||
|
||||
void QGISectionLine::setEnds(Base::Vector3d l1, Base::Vector3d l2)
|
||||
{
|
||||
m_l1 = l1;
|
||||
m_start = QPointF(l1.x, l1.y);
|
||||
m_l2 = l2;
|
||||
m_end = QPointF(l2.x, l2.y);
|
||||
}
|
||||
|
||||
void QGISectionLine::setBounds(double x1,double y1,double x2,double y2)
|
||||
@@ -269,6 +316,7 @@ void QGISectionLine::setDirection(double xDir,double yDir)
|
||||
void QGISectionLine::setDirection(Base::Vector3d dir)
|
||||
{
|
||||
m_arrowDir = dir;
|
||||
m_arrowDir.Normalize();
|
||||
}
|
||||
|
||||
void QGISectionLine::setFont(QFont f, double fsize)
|
||||
|
||||
Reference in New Issue
Block a user