Skip to content

Commit

Permalink
Fix overlap of line ends and arrowheads
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Jun 4, 2019
1 parent 3a988ba commit 8e6dd25
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 115 deletions.
37 changes: 32 additions & 5 deletions src/Mod/TechDraw/Gui/QGEPath.cpp
Expand Up @@ -29,6 +29,7 @@
#include <QPainter>
#include <QPainterPathStroker>
#include <QStyleOptionGraphicsItem>
#include <QVector2D>
#endif

#include <App/Application.h>
Expand Down Expand Up @@ -173,7 +174,9 @@ QGEPath::QGEPath() :
m_attach(QPointF(0.0,0.0)),
m_scale(1.0),
m_inEdit(false),
m_parentItem(nullptr)
m_parentItem(nullptr),
m_startAdj(0.0),
m_endAdj(0.0)
{
setHandlesChildEvents(false);
setAcceptHoverEvents(true);
Expand Down Expand Up @@ -384,12 +387,26 @@ void QGEPath::updatePath(void)
}
QPainterPath result;
prepareGeometryChange();
QPointF startAdjVec(0.0,0.0);
QPointF endAdjVec(0.0,0.0);
if (m_deltas.size() > 1) {
result.moveTo(m_deltas.front()); //(0,0)
for (int i = 1; i < (int)m_deltas.size(); i++) {
result.lineTo(m_deltas.at(i) * m_scale);
startAdjVec = m_deltas.at(1) - m_deltas.front();
endAdjVec = (*(m_deltas.end() - 2))- m_deltas.back();
//this next bit is ugly.
QVector2D startTemp(startAdjVec);
QVector2D endTemp(endAdjVec);
startTemp.normalize();
endTemp.normalize();
startAdjVec = startTemp.toPointF() * m_startAdj;
endAdjVec = endTemp.toPointF() * m_endAdj;
std::vector<QPointF> tempDeltas = m_deltas;
tempDeltas.front() += startAdjVec;
tempDeltas.back() += endAdjVec;
result.moveTo(tempDeltas.front());
for (int i = 1; i < (int)tempDeltas.size(); i++) {
result.lineTo(tempDeltas.at(i) * m_scale);
}
}
}
setPath(result);
}

Expand Down Expand Up @@ -445,6 +462,16 @@ void QGEPath::drawGhost(void)
m_ghost->show();
}

void QGEPath::setStartAdjust(double adj)
{
m_startAdj = Rez::guiX(adj);
}

void QGEPath::setEndAdjust(double adj)
{
m_endAdj = Rez::guiX(adj);
}

QRectF QGEPath::boundingRect() const
{
return shape().controlPointRect();
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/TechDraw/Gui/QGEPath.h
Expand Up @@ -122,6 +122,8 @@ class TechDrawGuiExport QGEPath : public QObject, public QGIPrimPath
void dumpPoints(char* text);
void dumpMarkerPos(char* text);
void restoreState(void);
void setStartAdjust(double adjust);
void setEndAdjust(double adjust);

public Q_SLOTS:
void onDragFinished(QPointF pos, int index);
Expand Down Expand Up @@ -153,6 +155,9 @@ public Q_SLOTS:

QGIView* m_parentItem;
QGIPrimPath* m_ghost;

double m_startAdj;
double m_endAdj;
};

}
Expand Down
34 changes: 33 additions & 1 deletion src/Mod/TechDraw/Gui/QGIArrow.cpp
Expand Up @@ -277,7 +277,39 @@ double QGIArrow::getPrefArrowSize()
return style;
}


double QGIArrow::getOverlapAdjust(int style, double size)
{
// adjustment required depends on arrow size and type! :(
// ex for fork and tick, adjustment sb zero. 0.25 is good for filled triangle, 0.1 for open arrow.
// open circle sb = radius
// NOTE: this may need to be adjusted to account for line thickness too.
// Base::Console().Message("QGIA::getOverlapAdjust(%d, %.3f) \n",style, size);
double result = 1.0;
switch(style) {
case 0: //filled triangle
result = 0.50 * size;
break;
case 1: //open arrow
result = 0.10 * size;
break;
case 2: //hash mark
result = 0.0;
break;
case 3: //dot
result = 0.0;
break;
case 4: //open circle
//diameter is size/2 so radius is size/4
result = 0.25 * size;
break;
case 5: //fork
result = 0.0;
break;
default: //unknown
result = 1.0;
}
return result;
}

void QGIArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGIArrow.h
Expand Up @@ -57,6 +57,7 @@ class TechDrawGuiExport QGIArrow : public QGIPrimPath
void setDirection(Base::Vector3d v) { m_dir = v; }
static int getPrefArrowStyle();
static double getPrefArrowSize();
static double getOverlapAdjust(int style, double size);

virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );

Expand Down
9 changes: 9 additions & 0 deletions src/Mod/TechDraw/Gui/QGILeaderLine.cpp
Expand Up @@ -375,6 +375,15 @@ void QGILeaderLine::draw()
m_line->setNormalColor(m_lineColor);
scale = getScale();
m_line->setScale(scale);
if (leadFeat->StartSymbol.getValue() > -1) {
m_line->setStartAdjust(QGIArrow::getOverlapAdjust(leadFeat->StartSymbol.getValue(),
QGIArrow::getPrefArrowSize()));
}
if (leadFeat->EndSymbol.getValue() > -1) {
m_line->setEndAdjust(QGIArrow::getOverlapAdjust(leadFeat->EndSymbol.getValue(),
QGIArrow::getPrefArrowSize()));
}

m_line->makeDeltasFromPoints(qPoints);
m_line->setPos(0,0);
m_line->updatePath();
Expand Down
74 changes: 33 additions & 41 deletions src/Mod/TechDraw/Gui/QGISectionLine.cpp
Expand Up @@ -78,39 +78,35 @@ void QGISectionLine::draw()
void QGISectionLine::makeLine()
{
QPainterPath pp;
QPointF beginExtLineStart,beginExtLineEnd; //ext line start pts for measure Start side and measure End side
QPointF endExtLineStart, endExtLineEnd;
QPointF offset(m_arrowDir.x,-m_arrowDir.y);
double arrowLen2 = 2.0 * Rez::guiX(QGIArrow::getPrefArrowSize());
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 = getPrefSectionFormat();
if (format == 0) { //"ASME"
//draw from section line endpoint to just short of arrow tip
QPointF offsetBegin = m_extLen * offset;
beginExtLineStart = m_start;
beginExtLineEnd = m_end;
endExtLineStart = m_start + offsetBegin;
endExtLineEnd = m_end + offsetBegin;
pp.moveTo(beginExtLineStart);
pp.lineTo(endExtLineStart);
pp.moveTo(beginExtLineEnd);
pp.lineTo(endExtLineEnd);
//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 extension line end to just short of section line
QPointF offsetBegin = arrowLen2 * offset;
QPointF offsetEnd = (arrowLen2 - m_extLen) * offset;
beginExtLineStart = m_start - offsetBegin;
beginExtLineEnd = m_end - offsetBegin;
endExtLineStart = m_start - offsetEnd;
endExtLineEnd = m_end - offsetEnd;
pp.moveTo(beginExtLineStart);
pp.lineTo(endExtLineStart);
pp.moveTo(beginExtLineEnd);
pp.lineTo(endExtLineEnd);
//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(beginExtLineStart);
// pp.lineTo(m_start); //arrow line
// pp.moveTo(beginExtLineEnd);
pp.moveTo(m_end);
pp.lineTo(m_start); //sectionLine
m_line->setPath(pp);
Expand All @@ -125,6 +121,7 @@ void QGISectionLine::makeArrows()
makeArrowsISO();
}
}

//make Euro (ISO) Arrows
void QGISectionLine::makeArrowsISO()
{
Expand All @@ -136,12 +133,6 @@ void QGISectionLine::makeArrowsISO()
}
arrowRotation = 360.0 - angle * (180.0/M_PI); //convert to Qt rotation (clockwise degrees)

QPointF extLineStart,extLineEnd;
QPointF offset(m_arrowDir.x,-m_arrowDir.y); //remember Y dir is flipped
offset = (m_extLen + (2.0 * QGIArrow::getPrefArrowSize())) * offset * -1.0;
extLineStart = m_start + offset;
extLineEnd = m_end + offset;

m_arrow1->setStyle(0);
m_arrow1->setSize(QGIArrow::getPrefArrowSize());
m_arrow1->setPos(m_start);
Expand All @@ -166,21 +157,22 @@ void QGISectionLine::makeArrowsTrad()
}
arrowRotation = 360.0 - angle * (180.0/M_PI); //convert to Qt rotation (clockwise degrees)

QPointF extLineStart,extLineEnd;
QPointF offset(m_arrowDir.x,-m_arrowDir.y); //remember Y dir is flipped
offset = (m_extLen + (2.0 * QGIArrow::getPrefArrowSize())) * offset;
extLineStart = m_start + offset;
extLineEnd = m_end + offset;
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()));
QPointF offsetVec = offsetLength * offsetDir;
posArrow1 = m_start + offsetVec;
posArrow2 = m_end + offsetVec;

m_arrow1->setStyle(0);
m_arrow1->setSize(QGIArrow::getPrefArrowSize());
m_arrow1->setPos(extLineStart);
m_arrow1->setPos(posArrow1);
m_arrow1->draw();
m_arrow1->setRotation(arrowRotation); //rotation = 0 ==> -> horizontal, pointing right

m_arrow2->setStyle(0);
m_arrow2->setSize(QGIArrow::getPrefArrowSize());
m_arrow2->setPos(extLineEnd);
m_arrow2->setPos(posArrow2);
m_arrow2->draw();
m_arrow2->setRotation(arrowRotation);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/TechDraw/Gui/QGISectionLine.h
Expand Up @@ -76,8 +76,8 @@ class TechDrawGuiExport QGISectionLine : public QGIDecoration
QGIArrow* m_arrow2;
QGCustomText* m_symbol1;
QGCustomText* m_symbol2;
QPointF m_start;
QPointF m_end;
QPointF m_start; //start of section line
QPointF m_end; //end of section line
Base::Vector3d m_arrowDir;
std::string m_symFontName;
QFont m_symFont;
Expand Down
7 changes: 7 additions & 0 deletions src/Mod/TechDraw/Gui/QGIView.cpp
Expand Up @@ -681,6 +681,13 @@ double QGIView::getPrefFontSize()
return hGrp->GetFloat("LabelSize", DefaultFontSizeInMM);
}

double QGIView::getDimFontSize()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
return hGrp->GetFloat("FontSize", DefaultFontSizeInMM);
}

double QGIView::calculateFontPointSizeF(const QGraphicsItem *item, double sizeInMillimetres)
{
const QWidget *widget = MDIViewPage::getFromScene(item->scene());
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGIView.h
Expand Up @@ -137,6 +137,7 @@ public Q_SLOTS:

QString getPrefFont(void);
double getPrefFontSize(void);
double getDimFontSize(void);
double calculateFontPointSizeF(double sizeInMillimetres) const;

Base::Reference<ParameterGrp> getParmGroupCol(void);
Expand Down

0 comments on commit 8e6dd25

Please sign in to comment.