diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index b035b0f93..41372dee9 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -64,28 +64,17 @@ VAbstractCubicBezierPath::~VAbstractCubicBezierPath() { } -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VAbstractCubicBezierPath::GetDirectionPath() const -{ - QPainterPath painterPath; - for (qint32 i = 1; i <= CountSubSpl(); ++i) - { - painterPath.addPath(GetSpline(i).GetDirectionPath()); - } - return painterPath; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetPath return QPainterPath which reprezent spline path. * @return path. */ -QPainterPath VAbstractCubicBezierPath::GetPath(PathDirection direction) const +QPainterPath VAbstractCubicBezierPath::GetPath() const { QPainterPath painterPath; for (qint32 i = 1; i <= CountSubSpl(); ++i) { - painterPath.addPath(GetSpline(i).GetPath(direction)); + painterPath.addPath(GetSpline(i).GetPath()); } return painterPath; } @@ -120,6 +109,17 @@ qreal VAbstractCubicBezierPath::GetLength() const return length; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractCubicBezierPath::DirectionArrows() const +{ + QVector arrows; + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + arrows += GetSpline(i).DirectionArrows(); + } + return arrows; +} + //--------------------------------------------------------------------------------------------------------------------- int VAbstractCubicBezierPath::Segment(const QPointF &p) const { diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.h b/src/libs/vgeometry/vabstractcubicbezierpath.h index a070929b2..9efdb186e 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.h +++ b/src/libs/vgeometry/vabstractcubicbezierpath.h @@ -59,11 +59,12 @@ public: virtual VSpline GetSpline(qint32 index) const =0; virtual QVector GetSplinePath() const =0; - virtual QPainterPath GetDirectionPath() const Q_DECL_OVERRIDE; - virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const Q_DECL_OVERRIDE; + virtual QPainterPath GetPath() const Q_DECL_OVERRIDE; virtual QVector GetPoints() const Q_DECL_OVERRIDE; virtual qreal GetLength() const Q_DECL_OVERRIDE; + virtual QVector DirectionArrows() const Q_DECL_OVERRIDE; + int Segment(const QPointF &p) const; QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index 4ac60943f..dbf0d93a8 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -37,6 +37,8 @@ #include "vabstractcurve_p.h" +const qreal VAbstractCurve::lengthCurveDirectionArrow = 14; + VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode) :VGObject(type, idObject, mode), d (new VAbstractCurveData()) {} @@ -169,13 +171,7 @@ QVector VAbstractCurve::ToEnd(const QVector &points, const QPo } //--------------------------------------------------------------------------------------------------------------------- -QPainterPath VAbstractCurve::GetDirectionPath() const -{ - return ShowDirection(GetPoints()); -} - -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VAbstractCurve::GetPath(PathDirection direction) const +QPainterPath VAbstractCurve::GetPath() const { QPainterPath path; @@ -183,12 +179,6 @@ QPainterPath VAbstractCurve::GetPath(PathDirection direction) const if (points.count() >= 2) { path.addPolygon(QPolygonF(points)); - - if (direction == PathDirection::Show) - { - path.addPath(ShowDirection(points)); - } - path.setFillRule(Qt::WindingFill); } else { @@ -323,10 +313,11 @@ QVector VAbstractCurve::CurveIntersectLine(const QVector &poin } //--------------------------------------------------------------------------------------------------------------------- -QPainterPath VAbstractCurve::ShowDirection(const QVector &points) const +QVector VAbstractCurve::DirectionArrows() const { - QPainterPath path; + QVector arrows; + const QVector points = GetPoints(); if (points.count() >= 2) { /*Need find coordinate midle of curve. @@ -350,15 +341,45 @@ QPainterPath VAbstractCurve::ShowDirection(const QVector &points) const //Reverse line because we want start arrow from this point arrow = QLineF(arrow.p2(), arrow.p1()); const qreal angle = arrow.angle();//we each time change line angle, better save original angle value - arrow.setLength(14);//arrow length in pixels + arrow.setLength(lengthCurveDirectionArrow);//arrow length in pixels + + DirectionArrow dArrow; arrow.setAngle(angle-35); - path.moveTo(arrow.p1()); - path.lineTo(arrow.p2()); + dArrow.first = arrow; arrow.setAngle(angle+35); - path.moveTo(arrow.p1()); - path.lineTo(arrow.p2()); + dArrow.second = arrow; + + arrows.append(dArrow); + } + return arrows; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VAbstractCurve::ShowDirection(const QVector &arrows, qreal width) +{ + QPainterPath path; + + for (int i = 0; i < arrows.size(); ++i) + { + const DirectionArrow arrow = arrows.at(i); + if (not arrow.first.isNull() && not arrow.second.isNull()) + { + QPainterPath arrowPath; + + QLineF line = arrow.first; + line.setLength(width); + arrowPath.moveTo(line.p1()); + arrowPath.lineTo(line.p2()); + + line = arrow.second; + line.setLength(width); + arrowPath.moveTo(line.p1()); + arrowPath.lineTo(line.p2()); + + path.addPath(arrowPath); + } } return path; } diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index af743ad72..6a045beb3 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -42,7 +42,7 @@ #include "vgeometrydef.h" #include "vgobject.h" -enum class PathDirection : char { Hide, Show }; +typedef QPair DirectionArrow; class QPainterPath; class VAbstractCurveData; @@ -68,8 +68,7 @@ public: bool reverse = false); QVector GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse = false) const; - virtual QPainterPath GetDirectionPath() const; - virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const; + virtual QPainterPath GetPath() const; virtual qreal GetLength() const =0; qreal GetLengthByPoint(const QPointF &point) const; virtual QVector IntersectLine(const QLineF &line) const; @@ -95,7 +94,10 @@ public: static QVector CurveIntersectLine(const QVector &points, const QLineF &line); virtual QString NameForHistory(const QString &toolName) const=0; - QPainterPath ShowDirection(const QVector &points) const; + virtual QVector DirectionArrows() const; + static QPainterPath ShowDirection(const QVector &arrows, qreal width); + + static const qreal lengthCurveDirectionArrow; protected: virtual void CreateName() =0; private: diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index f1cab38eb..9a8dbbc28 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -81,7 +81,9 @@ QPainterPath VAbstractSpline::shape() const if (m_isHovered || detailsMode) { - path.addPath(curve->GetDirectionPath()); + path.addPath(VAbstractCurve::ShowDirection(curve->DirectionArrows(), + ScaleWidth(VAbstractCurve::lengthCurveDirectionArrow, + SceneScale(scene())))); } path.setFillRule(Qt::WindingFill); @@ -131,7 +133,9 @@ void VAbstractSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen(arrowPen); painter->setBrush(brush()); - painter->drawPath(curve->GetDirectionPath()); + painter->drawPath(VAbstractCurve::ShowDirection(curve->DirectionArrows(), + ScaleWidth(VAbstractCurve::lengthCurveDirectionArrow, + SceneScale(scene())))); painter->restore(); } diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h index d13ae01b7..83ffbb06e 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.h +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -72,14 +72,14 @@ int VisOperation::AddFlippedCurve(const QPointF &firstPoint, const QPointF &seco ++i; VCurvePathItem *path = GetCurve(static_cast(i), supportColor2); - DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + DrawPath(path, curve->GetPath(), curve->DirectionArrows(), supportColor2, Qt::SolidLine, Qt::RoundCap); ++i; path = GetCurve(static_cast(i), supportColor); if (object1Id != NULL_ID) { const Item flipped = curve->Flip(QLineF(firstPoint, secondPoint)); - DrawPath(path, flipped.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(path, flipped.GetPath(), flipped.DirectionArrows(), supportColor, Qt::SolidLine, Qt::RoundCap); } return i; diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp index 79210ddbb..05e008b7f 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp @@ -166,7 +166,7 @@ QGraphicsPathItem *VisToolMove::AddOriginCurve(quint32 id, int &i) ++i; VCurvePathItem *path = GetCurve(static_cast(i), supportColor2); - DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + DrawPath(path, curve->GetPath(), curve->DirectionArrows(), supportColor2, Qt::SolidLine, Qt::RoundCap); return path; } @@ -180,7 +180,7 @@ int VisToolMove::AddMovedCurve(qreal angle, qreal length, quint32 id, int i) ++i; VCurvePathItem *path = GetCurve(static_cast(i), supportColor); const Item moved = curve->Move(length, angle); - DrawPath(path, moved.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(path, moved.GetPath(), moved.DirectionArrows(), supportColor, Qt::SolidLine, Qt::RoundCap); return i; } diff --git a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp index 971e351bb..8393bf5c3 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp @@ -117,7 +117,7 @@ void VisToolRotation::RefreshGeometry() Qt::DashLine); VArc arc(*origin, defPointRadiusPixel*2, 0, tempAngle); - DrawPath(angleArc, arc.GetPath(PathDirection::Hide), supportColor2, Qt::SolidLine, Qt::RoundCap); + DrawPath(angleArc, arc.GetPath(), supportColor2, Qt::SolidLine, Qt::RoundCap); Visualization::toolTip = tr("Rotating angle = %1°, Shift - sticking angle, " "Mouse click - finish creation").arg(tempAngle); @@ -216,14 +216,14 @@ int VisToolRotation::AddCurve(qreal angle, const QPointF &origin, quint32 id, in ++i; VCurvePathItem *path = GetCurve(static_cast(i), supportColor2); - DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + DrawPath(path, curve->GetPath(), curve->DirectionArrows(), supportColor2, Qt::SolidLine, Qt::RoundCap); ++i; path = GetCurve(static_cast(i), supportColor); if (object1Id != NULL_ID) { const Item rotated = curve->Rotate(origin, angle); - DrawPath(path, rotated.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(path, rotated.GetPath(), rotated.DirectionArrows(), supportColor, Qt::SolidLine, Qt::RoundCap); } return i; diff --git a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp index 41a194439..fdc0ee213 100644 --- a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp @@ -66,7 +66,7 @@ void VisToolCurveIntersectAxis::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer curve = Visualization::data->GeometricObject(object1Id); - DrawPath(visCurve, curve->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(visCurve, curve->GetPath(), curve->DirectionArrows(), supportColor, Qt::SolidLine, Qt::RoundCap); if (axisPointId > NULL_ID) { diff --git a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp index 4e19cd387..02ac6a2d5 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp @@ -68,7 +68,7 @@ void VisToolPointFromArcAndTangent::RefreshGeometry() if (arcId > NULL_ID)// circle center { const QSharedPointer arc = Visualization::data->GeometricObject(arcId); - DrawPath(arcPath, arc->GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(arcPath, arc->GetPath(), arc->DirectionArrows(), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); FindRays(static_cast(*tan), arc.data()); diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp index 1ad0fce0f..9b772f186 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp @@ -71,12 +71,12 @@ void VisToolPointOfIntersectionArcs::RefreshGeometry() if (arc1Id > NULL_ID) { const QSharedPointer arc1 = Visualization::data->GeometricObject(arc1Id); - DrawPath(arc1Path, arc1->GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(arc1Path, arc1->GetPath(), arc1->DirectionArrows(), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); if (arc2Id > NULL_ID) { const QSharedPointer arc2 = Visualization::data->GeometricObject(arc2Id); - DrawPath(arc2Path, arc2->GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + DrawPath(arc2Path, arc2->GetPath(), arc2->DirectionArrows(), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); const QPointF fPoint = VToolPointOfIntersectionArcs::FindPoint(arc1.data(), arc2.data(), crossPoint); DrawPoint(point, fPoint, mainColor); diff --git a/src/libs/vtools/visualization/path/vistoolarc.cpp b/src/libs/vtools/visualization/path/vistoolarc.cpp index bb0499b99..e9ac816c5 100644 --- a/src/libs/vtools/visualization/path/vistoolarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolarc.cpp @@ -61,7 +61,7 @@ void VisToolArc::RefreshGeometry() if (not qFuzzyIsNull(radius) && f1 >= 0 && f2 >= 0) { VArc arc = VArc (*first, radius, f1, f2); - DrawPath(this, arc.GetPath(), arc.GetDirectionPath(), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, arc.GetPath(), arc.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); } } } diff --git a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp index becb6a7ce..bf975ab5c 100644 --- a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp +++ b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp @@ -60,7 +60,7 @@ void VisToolArcWithLength::RefreshGeometry() if (not qFuzzyIsNull(radius) && f1 >= 0 && not qFuzzyIsNull(length)) { VArc arc = VArc (length, *first, radius, f1); - DrawPath(this, arc.GetPath(), arc.GetDirectionPath(), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, arc.GetPath(), arc.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); } } } diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp index 950365181..950fb77bf 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp @@ -90,7 +90,7 @@ void VisToolCubicBezier::RefreshGeometry() { VCubicBezier spline(*first, *second, VPointF(Visualization::scenePos), VPointF(Visualization::scenePos)); - DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, spline.GetPath(), mainColor, lineStyle, Qt::RoundCap); } else { @@ -100,7 +100,7 @@ void VisToolCubicBezier::RefreshGeometry() if (object4Id <= NULL_ID) { VCubicBezier spline(*first, *second, *third, VPointF(Visualization::scenePos)); - DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, spline.GetPath(), mainColor, lineStyle, Qt::RoundCap); DrawLine(helpLine2, QLineF(static_cast(*third), Visualization::scenePos), mainColor, Qt::DashLine); } @@ -112,7 +112,7 @@ void VisToolCubicBezier::RefreshGeometry() Qt::DashLine); VCubicBezier spline(*first, *second, *third, *fourth); - DrawPath(this, spline.GetPath(), spline.GetDirectionPath(), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, spline.GetPath(), spline.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); } } } diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp index 304804129..1843e2cf9 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp @@ -97,8 +97,7 @@ void VisToolCubicBezierPath::RefreshGeometry() if (countSubSpl >= 1) { - DrawPath(this, path.GetPath(), mainColor, lineStyle, Qt::RoundCap); - DrawPath(this, path.GetDirectionPath(), mainColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(this, path.GetPath(), path.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); for (qint32 i = 1; i<=countSubSpl; ++i) { @@ -203,7 +202,7 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po const QPointF p2 = p1p2.p2(); VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos)); - DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(newCurveSegment, spline.GetPath(), mainColor, Qt::SolidLine, Qt::RoundCap); DrawLine(helpLine1, p1p2, mainColor, Qt::DashLine); @@ -234,7 +233,7 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po DrawLine(helpLine1, QLineF(static_cast(p1), p2), mainColor, Qt::DashLine); VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos)); - DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(newCurveSegment, spline.GetPath(), mainColor, Qt::SolidLine, Qt::RoundCap); const int preLastPoint = subSplCount * 2; VScaledEllipse *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); @@ -260,7 +259,7 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po DrawLine(helpLine2, QLineF(p3, Visualization::scenePos), mainColor, Qt::DashLine); VSpline spline(p1, p2, p3, VPointF(Visualization::scenePos)); - DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(newCurveSegment, spline.GetPath(), mainColor, Qt::SolidLine, Qt::RoundCap); const int preLastPoint = subSplCount * 2; VScaledEllipse *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); diff --git a/src/libs/vtools/visualization/path/vistoolcutarc.cpp b/src/libs/vtools/visualization/path/vistoolcutarc.cpp index 9061df301..aefcc26e6 100644 --- a/src/libs/vtools/visualization/path/vistoolcutarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutarc.cpp @@ -64,7 +64,7 @@ void VisToolCutArc::RefreshGeometry() if (object1Id > NULL_ID) { const QSharedPointer arc = Visualization::data->GeometricObject(object1Id); - DrawPath(this, arc->GetPath(), arc->GetDirectionPath(), supportColor, lineStyle, Qt::RoundCap); + DrawPath(this, arc->GetPath(), arc->DirectionArrows(), supportColor, lineStyle, Qt::RoundCap); if (not qFuzzyIsNull(length)) { @@ -73,8 +73,8 @@ void VisToolCutArc::RefreshGeometry() QPointF p = arc->CutArc(length, ar1, ar2); DrawPoint(point, p, mainColor); - DrawPath(arc1, ar1.GetPath(), ar1.GetDirectionPath(), Qt::darkGreen, lineStyle, Qt::RoundCap); - DrawPath(arc2, ar2.GetPath(), ar2.GetDirectionPath(), Qt::darkRed, lineStyle, Qt::RoundCap); + DrawPath(arc1, ar1.GetPath(), ar1.DirectionArrows(), Qt::darkGreen, lineStyle, Qt::RoundCap); + DrawPath(arc2, ar2.GetPath(), ar2.DirectionArrows(), Qt::darkRed, lineStyle, Qt::RoundCap); } } } diff --git a/src/libs/vtools/visualization/path/vistoolcutspline.cpp b/src/libs/vtools/visualization/path/vistoolcutspline.cpp index 114a1327e..818190292 100644 --- a/src/libs/vtools/visualization/path/vistoolcutspline.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutspline.cpp @@ -66,7 +66,7 @@ void VisToolCutSpline::RefreshGeometry() if (object1Id > NULL_ID) { const auto spl = Visualization::data->GeometricObject(object1Id); - DrawPath(this, spl->GetPath(), spl->GetDirectionPath(), supportColor, lineStyle, Qt::RoundCap); + DrawPath(this, spl->GetPath(), spl->DirectionArrows(), supportColor, lineStyle, Qt::RoundCap); if (not qFuzzyIsNull(length)) { @@ -81,8 +81,8 @@ void VisToolCutSpline::RefreshGeometry() DrawPoint(point, p, mainColor); - DrawPath(spl1, sp1.GetPath(), sp1.GetDirectionPath(), Qt::darkGreen, lineStyle, Qt::RoundCap); - DrawPath(spl2, sp2.GetPath(), sp2.GetDirectionPath(), Qt::darkRed, lineStyle, Qt::RoundCap); + DrawPath(spl1, sp1.GetPath(), sp1.DirectionArrows(), Qt::darkGreen, lineStyle, Qt::RoundCap); + DrawPath(spl2, sp2.GetPath(), sp2.DirectionArrows(), Qt::darkRed, lineStyle, Qt::RoundCap); } } } diff --git a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp index 200310c6b..5722aef32 100644 --- a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp @@ -65,7 +65,7 @@ void VisToolCutSplinePath::RefreshGeometry() if (object1Id > NULL_ID) { const auto splPath = Visualization::data->GeometricObject(object1Id); - DrawPath(this, splPath->GetPath(), splPath->GetDirectionPath(), supportColor, lineStyle, Qt::RoundCap); + DrawPath(this, splPath->GetPath(), splPath->DirectionArrows(), supportColor, lineStyle, Qt::RoundCap); if (not qFuzzyIsNull(length)) { @@ -79,8 +79,8 @@ void VisToolCutSplinePath::RefreshGeometry() DrawPoint(point, static_cast(*p), mainColor); delete p; - DrawPath(splPath1, spPath1->GetPath(), spPath1->GetDirectionPath(), Qt::darkGreen, lineStyle, Qt::RoundCap); - DrawPath(splPath2, spPath2->GetPath(), spPath2->GetDirectionPath(), Qt::darkRed, lineStyle, Qt::RoundCap); + DrawPath(splPath1, spPath1->GetPath(), spPath1->DirectionArrows(), Qt::darkGreen, lineStyle, Qt::RoundCap); + DrawPath(splPath2, spPath2->GetPath(), spPath2->DirectionArrows(), Qt::darkRed, lineStyle, Qt::RoundCap); delete spPath1; delete spPath2; diff --git a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp index 612b39b2a..3f07a4d50 100644 --- a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp @@ -57,7 +57,7 @@ void VisToolEllipticalArc::RefreshGeometry() if (not qFuzzyIsNull(radius1) && not qFuzzyIsNull(radius2) && f1 >= 0 && f2 >= 0 && rotationAngle >= 0) { VEllipticalArc elArc = VEllipticalArc(*first, radius1, radius2, f1, f2, rotationAngle); - DrawPath(this, elArc.GetPath(), elArc.GetDirectionPath(), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, elArc.GetPath(), elArc.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); } } } diff --git a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp index 525f356a5..42df9bd0c 100644 --- a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp +++ b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp @@ -63,12 +63,13 @@ void VisToolPointOfIntersectionCurves::RefreshGeometry() if (object1Id > NULL_ID) { auto curve1 = Visualization::data->GeometricObject(object1Id); - DrawPath(this, curve1->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(this, curve1->GetPath(), curve1->DirectionArrows(), supportColor, Qt::SolidLine, Qt::RoundCap); if (object2Id > NULL_ID) { auto curve2 = Visualization::data->GeometricObject(object2Id); - DrawPath(visCurve2, curve2->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(visCurve2, curve2->GetPath(), curve2->DirectionArrows(), supportColor, Qt::SolidLine, + Qt::RoundCap); auto p = VToolPointOfIntersectionCurves::FindPoint(curve1->GetPoints(), curve2->GetPoints(), vCrossPoint, hCrossPoint); diff --git a/src/libs/vtools/visualization/path/vistoolspline.cpp b/src/libs/vtools/visualization/path/vistoolspline.cpp index 2c57da5f3..e746e0043 100644 --- a/src/libs/vtools/visualization/path/vistoolspline.cpp +++ b/src/libs/vtools/visualization/path/vistoolspline.cpp @@ -122,7 +122,7 @@ void VisToolSpline::RefreshGeometry() if (object4Id <= NULL_ID) { VSpline spline(*first, p2, Visualization::scenePos, VPointF(Visualization::scenePos)); - DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, spline.GetPath(), mainColor, lineStyle, Qt::RoundCap); } else { @@ -160,12 +160,12 @@ void VisToolSpline::RefreshGeometry() if (VFuzzyComparePossibleNulls(angle1, EMPTY_ANGLE) || VFuzzyComparePossibleNulls(angle2, EMPTY_ANGLE)) { VSpline spline(*first, p2, p3, *second); - DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, spline.GetPath(), mainColor, lineStyle, Qt::RoundCap); } else { VSpline spline(*first, *second, angle1, angle2, kAsm1, kAsm2, kCurve); - DrawPath(this, spline.GetPath(), spline.GetDirectionPath(), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, spline.GetPath(), spline.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); Visualization::toolTip = tr("Use Shift for sticking angle!"); emit ToolTip(Visualization::toolTip); } diff --git a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp index 62e8f1deb..de4820c66 100644 --- a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp @@ -104,7 +104,7 @@ void VisToolSplinePath::RefreshGeometry() if (size > 1) { - DrawPath(this, path.GetPath(), path.GetDirectionPath(), mainColor, lineStyle, Qt::RoundCap); + DrawPath(this, path.GetPath(), path.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap); } if (path.CountPoints() < 3) @@ -296,6 +296,6 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) } emit PathChanged(path); - DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + DrawPath(newCurveSegment, spline.GetPath(), mainColor, Qt::SolidLine, Qt::RoundCap); } } diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index a80db6025..031025a24 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -218,12 +218,13 @@ void Visualization::DrawLine(VScaledLine *lineItem, const QLineF &line, const QC void Visualization::DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style, Qt::PenCapStyle cap) { - DrawPath(pathItem, path, QPainterPath(), color, style, cap); + DrawPath(pathItem, path, QVector(), color, style, cap); } //--------------------------------------------------------------------------------------------------------------------- -void Visualization::DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QPainterPath &direction, - const QColor &color, Qt::PenStyle style, Qt::PenCapStyle cap) +void Visualization::DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, + const QVector &directionArrows, const QColor &color, Qt::PenStyle style, + Qt::PenCapStyle cap) { SCASSERT (pathItem != nullptr) @@ -234,7 +235,7 @@ void Visualization::DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, pathItem->setPen(visPen); pathItem->setPath(path); - pathItem->SetDirectionPath(direction); + pathItem->SetDirectionArrows(directionArrows); pathItem->setVisible(true); } diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index d2530cbcb..db88ae295 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -96,8 +96,9 @@ protected: Qt::PenStyle style = Qt::SolidLine); void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap); - void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QPainterPath &direction, - const QColor &color, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap); + void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, + const QVector &directionArrows, const QColor &color, + Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap); template void AddItem(Item *item); diff --git a/src/libs/vwidgets/vcurvepathitem.cpp b/src/libs/vwidgets/vcurvepathitem.cpp index dd7304269..8891af042 100644 --- a/src/libs/vwidgets/vcurvepathitem.cpp +++ b/src/libs/vwidgets/vcurvepathitem.cpp @@ -28,13 +28,14 @@ #include "vcurvepathitem.h" #include "../vwidgets/global.h" +#include "../vgeometry/vabstractcurve.h" #include //--------------------------------------------------------------------------------------------------------------------- VCurvePathItem::VCurvePathItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), - m_direction() + m_directionArrows() { } @@ -43,13 +44,15 @@ QPainterPath VCurvePathItem::shape() const { QPainterPath itemPath = path(); - if (m_direction != QPainterPath()) + const QPainterPath arrowsPath = VAbstractCurve::ShowDirection(m_directionArrows, + ScaleWidth(VAbstractCurve::lengthCurveDirectionArrow, + SceneScale(scene()))); + if (arrowsPath != QPainterPath()) { - itemPath.addPath(m_direction); + itemPath.addPath(arrowsPath); + itemPath.setFillRule(Qt::WindingFill); } - itemPath.setFillRule(Qt::WindingFill); - // We unfortunately need this hack as QPainterPathStroker will set a width of 1.0 // if we pass a value of 0.0 to QPainterPathStroker::setWidth() const qreal penWidthZero = qreal(0.00000001); @@ -81,7 +84,11 @@ void VCurvePathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op { ScalePenWidth(); - if (m_direction != QPainterPath()) + const QPainterPath arrowsPath = VAbstractCurve::ShowDirection(m_directionArrows, + ScaleWidth(VAbstractCurve::lengthCurveDirectionArrow, + SceneScale(scene()))); + + if (arrowsPath != QPainterPath()) { painter->save(); @@ -90,7 +97,7 @@ void VCurvePathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op painter->setPen(arrowPen); painter->setBrush(brush()); - painter->drawPath(m_direction); + painter->drawPath(arrowsPath); painter->restore(); } @@ -99,9 +106,9 @@ void VCurvePathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op } //--------------------------------------------------------------------------------------------------------------------- -void VCurvePathItem::SetDirectionPath(const QPainterPath &path) +void VCurvePathItem::SetDirectionArrows(const QVector > &arrows) { - m_direction = path; + m_directionArrows = arrows; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vcurvepathitem.h b/src/libs/vwidgets/vcurvepathitem.h index b78db80f4..b33b245c3 100644 --- a/src/libs/vwidgets/vcurvepathitem.h +++ b/src/libs/vwidgets/vcurvepathitem.h @@ -48,13 +48,13 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::CurvePathItem)}; - void SetDirectionPath(const QPainterPath &path); + void SetDirectionArrows(const QVector> &arrows); protected: virtual void ScalePenWidth(); private: Q_DISABLE_COPY(VCurvePathItem) - QPainterPath m_direction; + QVector> m_directionArrows; }; #endif // VCURVEPATHITEM_H diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp index 3c47fa7a7..3aa2f08bb 100644 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -64,7 +64,7 @@ void VSimpleCurve::RefreshGeometry(const QSharedPointer &curve) if (not m_curve.isNull()) { - m_isHovered ? SetDirectionPath(m_curve->GetDirectionPath()) : SetDirectionPath(QPainterPath()); + m_isHovered ? SetDirectionArrows(m_curve->DirectionArrows()) : SetDirectionArrows(QVector()); setPath(m_curve->GetPath()); } else