Scale curve direction arrows.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-06-23 14:18:31 +03:00
parent ffa86a708a
commit a1f4207621
27 changed files with 134 additions and 97 deletions

View File

@ -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<DirectionArrow> VAbstractCubicBezierPath::DirectionArrows() const
{
QVector<DirectionArrow> arrows;
for (qint32 i = 1; i <= CountSubSpl(); ++i)
{
arrows += GetSpline(i).DirectionArrows();
}
return arrows;
}
//---------------------------------------------------------------------------------------------------------------------
int VAbstractCubicBezierPath::Segment(const QPointF &p) const
{

View File

@ -59,11 +59,12 @@ public:
virtual VSpline GetSpline(qint32 index) const =0;
virtual QVector<VSplinePoint> 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<QPointF> GetPoints() const Q_DECL_OVERRIDE;
virtual qreal GetLength() const Q_DECL_OVERRIDE;
virtual QVector<DirectionArrow> 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,

View File

@ -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<QPointF> VAbstractCurve::ToEnd(const QVector<QPointF> &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<QPointF> VAbstractCurve::CurveIntersectLine(const QVector<QPointF> &poin
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VAbstractCurve::ShowDirection(const QVector<QPointF> &points) const
QVector<DirectionArrow> VAbstractCurve::DirectionArrows() const
{
QPainterPath path;
QVector<DirectionArrow> arrows;
const QVector<QPointF> points = GetPoints();
if (points.count() >= 2)
{
/*Need find coordinate midle of curve.
@ -350,15 +341,45 @@ QPainterPath VAbstractCurve::ShowDirection(const QVector<QPointF> &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<DirectionArrow> &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;
}

View File

@ -42,7 +42,7 @@
#include "vgeometrydef.h"
#include "vgobject.h"
enum class PathDirection : char { Hide, Show };
typedef QPair<QLineF, QLineF> DirectionArrow;
class QPainterPath;
class VAbstractCurveData;
@ -68,8 +68,7 @@ public:
bool reverse = false);
QVector<QPointF> 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<QPointF> IntersectLine(const QLineF &line) const;
@ -95,7 +94,10 @@ public:
static QVector<QPointF> CurveIntersectLine(const QVector<QPointF> &points, const QLineF &line);
virtual QString NameForHistory(const QString &toolName) const=0;
QPainterPath ShowDirection(const QVector<QPointF> &points) const;
virtual QVector<DirectionArrow> DirectionArrows() const;
static QPainterPath ShowDirection(const QVector<DirectionArrow> &arrows, qreal width);
static const qreal lengthCurveDirectionArrow;
protected:
virtual void CreateName() =0;
private:

View File

@ -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();
}

View File

@ -72,14 +72,14 @@ int VisOperation::AddFlippedCurve(const QPointF &firstPoint, const QPointF &seco
++i;
VCurvePathItem *path = GetCurve(static_cast<quint32>(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<quint32>(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;

View File

@ -166,7 +166,7 @@ QGraphicsPathItem *VisToolMove::AddOriginCurve(quint32 id, int &i)
++i;
VCurvePathItem *path = GetCurve(static_cast<quint32>(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<quint32>(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;
}

View File

@ -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°, <b>Shift</b> - sticking angle, "
"<b>Mouse click</b> - 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<quint32>(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<quint32>(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;

View File

@ -66,7 +66,7 @@ void VisToolCurveIntersectAxis::RefreshGeometry()
if (object1Id > NULL_ID)
{
const QSharedPointer<VAbstractCurve> curve = Visualization::data->GeometricObject<VAbstractCurve>(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)
{

View File

@ -68,7 +68,7 @@ void VisToolPointFromArcAndTangent::RefreshGeometry()
if (arcId > NULL_ID)// circle center
{
const QSharedPointer<VArc> arc = Visualization::data->GeometricObject<VArc>(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<QPointF>(*tan), arc.data());

View File

@ -71,12 +71,12 @@ void VisToolPointOfIntersectionArcs::RefreshGeometry()
if (arc1Id > NULL_ID)
{
const QSharedPointer<VArc> arc1 = Visualization::data->GeometricObject<VArc>(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<VArc> arc2 = Visualization::data->GeometricObject<VArc>(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);

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<QPointF>(*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);
}
}
}

View File

@ -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<VPointF> &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<VPointF> &pathPoints, int po
DrawLine(helpLine1, QLineF(static_cast<QPointF>(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<unsigned>(preLastPoint));
@ -260,7 +259,7 @@ void VisToolCubicBezierPath::Creating(const QVector<VPointF> &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<unsigned>(preLastPoint));

View File

@ -64,7 +64,7 @@ void VisToolCutArc::RefreshGeometry()
if (object1Id > NULL_ID)
{
const QSharedPointer<VArc> arc = Visualization::data->GeometricObject<VArc>(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);
}
}
}

View File

@ -66,7 +66,7 @@ void VisToolCutSpline::RefreshGeometry()
if (object1Id > NULL_ID)
{
const auto spl = Visualization::data->GeometricObject<VAbstractCubicBezier>(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);
}
}
}

View File

@ -65,7 +65,7 @@ void VisToolCutSplinePath::RefreshGeometry()
if (object1Id > NULL_ID)
{
const auto splPath = Visualization::data->GeometricObject<VAbstractCubicBezierPath>(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<QPointF>(*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;

View File

@ -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);
}
}
}

View File

@ -63,12 +63,13 @@ void VisToolPointOfIntersectionCurves::RefreshGeometry()
if (object1Id > NULL_ID)
{
auto curve1 = Visualization::data->GeometricObject<VAbstractCurve>(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<VAbstractCurve>(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);

View File

@ -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 <b>Shift</b> for sticking angle!");
emit ToolTip(Visualization::toolTip);
}

View File

@ -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);
}
}

View File

@ -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<DirectionArrow>(), 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<DirectionArrow> &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);
}

View File

@ -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<DirectionArrow> &directionArrows, const QColor &color,
Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap);
template <typename Item>
void AddItem(Item *item);

View File

@ -28,13 +28,14 @@
#include "vcurvepathitem.h"
#include "../vwidgets/global.h"
#include "../vgeometry/vabstractcurve.h"
#include <QPainter>
//---------------------------------------------------------------------------------------------------------------------
VCurvePathItem::VCurvePathItem(QGraphicsItem *parent)
: QGraphicsPathItem(parent),
m_direction()
m_directionArrows()
{
}
@ -43,12 +44,14 @@ 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);
}
// 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()
@ -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<QPair<QLineF, QLineF> > &arrows)
{
m_direction = path;
m_directionArrows = arrows;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -48,13 +48,13 @@ public:
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::CurvePathItem)};
void SetDirectionPath(const QPainterPath &path);
void SetDirectionArrows(const QVector<QPair<QLineF, QLineF>> &arrows);
protected:
virtual void ScalePenWidth();
private:
Q_DISABLE_COPY(VCurvePathItem)
QPainterPath m_direction;
QVector<QPair<QLineF, QLineF>> m_directionArrows;
};
#endif // VCURVEPATHITEM_H

View File

@ -64,7 +64,7 @@ void VSimpleCurve::RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve)
if (not m_curve.isNull())
{
m_isHovered ? SetDirectionPath(m_curve->GetDirectionPath()) : SetDirectionPath(QPainterPath());
m_isHovered ? SetDirectionArrows(m_curve->DirectionArrows()) : SetDirectionArrows(QVector<DirectionArrow>());
setPath(m_curve->GetPath());
}
else