Fixed issue 107.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-17 17:22:30 +03:00
parent 2e5d7cdb38
commit 036979a68c
23 changed files with 136 additions and 60 deletions

View File

@ -29,6 +29,7 @@
#include "vabstractcurve.h"
#include <QPainterPath>
#include <QtMath>
//---------------------------------------------------------------------------------------------------------------------
VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode)
@ -52,7 +53,7 @@ VAbstractCurve &VAbstractCurve::operator=(const VAbstractCurve &curve)
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VAbstractCurve::GetPath() const
QPainterPath VAbstractCurve::GetPath(PathDirection direction) const
{
QPainterPath path;
@ -64,6 +65,11 @@ QPainterPath VAbstractCurve::GetPath() const
path.moveTo(points.at(i));
path.lineTo(points.at(i+1));
}
if (direction == PathDirection::Show && points.count() >= 3)
{
path.addPath(ShowDirection(points));
}
}
else
{
@ -71,3 +77,44 @@ QPainterPath VAbstractCurve::GetPath() const
}
return path;
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VAbstractCurve::ShowDirection(const QVector<QPointF> &points) const
{
QPainterPath path;
if (points.count() >= 2)
{
/*Need find coordinate midle of curve.
Universal way is take all points and find sum.*/
const qreal seek_length = GetLength()/2.0;
qreal found_length = 0;
QLineF arrow;
for (qint32 i = 1; i <= points.size()-1; ++i)
{
arrow = QLineF(points.at(i-1), points.at(i));
found_length += arrow.length();//Length that we aready find
if (seek_length <= found_length)// if have found more that need stop.
{
//subtract length in last line and you will find position of the middle point.
arrow.setLength(arrow.length() - (found_length - seek_length));
break;
}
}
//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.setAngle(angle-35);
path.moveTo(arrow.p1());
path.lineTo(arrow.p2());
arrow.setAngle(angle+35);
path.moveTo(arrow.p1());
path.lineTo(arrow.p2());
}
return path;
}

View File

@ -32,6 +32,8 @@
#include "vgobject.h"
#include <QPointF>
enum class PathDirection : char { Hide, Show };
class QPainterPath;
class VAbstractCurve :public VGObject
@ -41,9 +43,11 @@ public:
VAbstractCurve(const VAbstractCurve &curve);
VAbstractCurve& operator= (const VAbstractCurve &curve);
virtual QVector<QPointF> GetPoints() const =0;
virtual QPainterPath GetPath() const;
virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const;
virtual QString name() const;
virtual qreal GetLength() const =0;
protected:
QPainterPath ShowDirection(const QVector<QPointF> &points) const;
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -83,14 +83,14 @@ VSpline VSplinePath::GetSpline(qint32 index) const
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VSplinePath::GetPath() const
QPainterPath VSplinePath::GetPath(PathDirection direction) const
{
QPainterPath painterPath;
for (qint32 i = 1; i <= Count(); ++i)
{
VSpline spl(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(),
path.at(i-1).KAsm2(), path.at(i).KAsm1(), this->kCurve);
painterPath.addPath(spl.GetPath());
painterPath.addPath(spl.GetPath(direction));
}
return painterPath;
}

View File

@ -82,7 +82,7 @@ public:
* @brief GetPath return QPainterPath which reprezent spline path.
* @return path.
*/
QPainterPath GetPath() const;
QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const;
/**
* @brief GetPathPoints return list of points what located on path.
* @return list.

View File

@ -123,7 +123,8 @@ void VAbstractSpline::SetFactor(qreal factor)
void VAbstractSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor));
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, Qt::SolidLine, Qt::RoundCap));
this->setPath(ToolPath(PathDirection::Show));
}
//---------------------------------------------------------------------------------------------------------------------
@ -136,6 +137,7 @@ void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
this->setPath(ToolPath());
}
//---------------------------------------------------------------------------------------------------------------------
@ -180,3 +182,13 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event)
}
QGraphicsItem::keyReleaseEvent ( event );
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VAbstractSpline::ToolPath(PathDirection direction) const
{
const VAbstractCurve *curve = VAbstractTool::data.GeometricObject<const VAbstractCurve *>(id);
QPainterPath path;
path.addPath(curve->GetPath(direction));
path.setFillRule( Qt::WindingFill );
return path;
}

View File

@ -74,6 +74,7 @@ protected:
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void keyReleaseEvent(QKeyEvent * event);
QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const;
};
#endif // VABSTRACTSPLINE_H

View File

@ -47,11 +47,7 @@ const QString VToolArc::ToolType = QStringLiteral("simple");
VToolArc::VToolArc(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{
const VArc *arc = data->GeometricObject<const VArc *>(id);
QPainterPath path;
path.addPath(arc->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
this->setPath(ToolPath());
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
@ -267,9 +263,5 @@ void VToolArc::SaveDialog(QDomElement &domElement)
void VToolArc::RefreshGeometry()
{
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(id);
QPainterPath path;
path.addPath(arc->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
this->setPath(ToolPath());
}

View File

@ -40,13 +40,15 @@ VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QSt
Q_ASSERT_X(curve1id > 0, Q_FUNC_INFO, "curve1id <= 0");
Q_ASSERT_X(curve2id > 0, Q_FUNC_INFO, "curve2id <= 0");
firstCurve = new VSimpleCurve(curve1id, &currentColor, &factor);
firstCurve = new VSimpleCurve(curve1id, &currentColor, SimpleCurvePoint::ForthPoint, &factor);
firstCurve->setParentItem(this);
connect(firstCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
connect(firstCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath);
secondCurve = new VSimpleCurve(curve2id, &currentColor, &factor);
secondCurve = new VSimpleCurve(curve2id, &currentColor, SimpleCurvePoint::FirstPoint, &factor);
secondCurve->setParentItem(this);
connect(secondCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
connect(secondCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath);
}
//---------------------------------------------------------------------------------------------------------------------
@ -72,6 +74,16 @@ void VToolCut::ChangedActivDraw(const QString &newName)
VToolPoint::ChangedActivDraw(newName);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolCut::HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirection direction)
{
VSimpleCurve* simpleCurve = qobject_cast<VSimpleCurve*>(sender());
if (simpleCurve)
{
RefreshCurve(simpleCurve, id, curvePosition, direction);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.

View File

@ -41,6 +41,7 @@ public:
public slots:
virtual void ChangedActivDraw(const QString &newName);
virtual void CurveChoosed(quint32 id)=0;
void HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirection direction);
protected:
/** @brief formula keep formula of length */
QString formula;
@ -55,7 +56,8 @@ protected:
quint32 curve1id;
quint32 curve2id;
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)=0;
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction = PathDirection::Hide)=0;
void RefreshGeometry();
virtual void RemoveReferens();
void FullUpdateCurveFromFile(const QString &attrCurve);

View File

@ -148,7 +148,6 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS
else
{
data->UpdateGObject(id, new VPointF(point, pointName, mx, my));
arc1id = id + 1;
arc2id = id + 2;
@ -280,13 +279,14 @@ void VToolCutArc::SaveDialog(QDomElement &domElement)
* @param curveId curve id.
* @param tr point type.
*/
void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)
void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction)
{
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(curveId);
QPainterPath path;
path.addPath(arc->GetPath());
path.addPath(arc->GetPath(direction));
path.setFillRule( Qt::WindingFill );
if (tr == SimpleCurvePoint::FirstPoint)
if (curvePosition == SimpleCurvePoint::FirstPoint)
{
path.translate(-arc->GetP1().x(), -arc->GetP1().y());
}

View File

@ -57,7 +57,8 @@ protected:
virtual void AddToFile();
virtual void RefreshDataInFile();
virtual void SaveDialog(QDomElement &domElement);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction = PathDirection::Hide);
private:
Q_DISABLE_COPY(VToolCutArc)
};

View File

@ -277,13 +277,14 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement)
* @param curveId curve id.
* @param tr point type.
*/
void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)
void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction)
{
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(curveId);
QPainterPath path;
path.addPath(spl->GetPath());
path.addPath(spl->GetPath(direction));
path.setFillRule( Qt::WindingFill );
if (tr == SimpleCurvePoint::FirstPoint)
if (curvePosition == SimpleCurvePoint::FirstPoint)
{
path.translate(-spl->GetP1().toQPointF().x(), -spl->GetP1().toQPointF().y());
}

View File

@ -58,7 +58,8 @@ protected:
virtual void AddToFile();
virtual void RefreshDataInFile();
virtual void SaveDialog(QDomElement &domElement);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction = PathDirection::Hide);
private:
Q_DISABLE_COPY(VToolCutSpline)
};

View File

@ -332,13 +332,14 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement)
* @param curveId curve id.
* @param tr point type.
*/
void VToolCutSplinePath::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr)
void VToolCutSplinePath::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction)
{
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(curveId);
QPainterPath path;
path.addPath(splPath->GetPath());
path.addPath(splPath->GetPath(direction));
path.setFillRule( Qt::WindingFill );
if (tr == SimpleCurvePoint::FirstPoint)
if (curvePosition == SimpleCurvePoint::FirstPoint)
{
VSpline spl = splPath->GetSpline(1);
path.translate(-spl.GetP1().toQPointF().x(), -spl.GetP1().toQPointF().y());

View File

@ -59,7 +59,8 @@ protected:
virtual void AddToFile();
virtual void RefreshDataInFile();
virtual void SaveDialog(QDomElement &domElement);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint tr);
virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction = PathDirection::Hide);
private:
Q_DISABLE_COPY(VToolCutSplinePath)
};

View File

@ -46,16 +46,13 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Sour
QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{
const VSpline *spl = data->GeometricObject<const VSpline *>(id);
QPainterPath path;
path.addPath(spl->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
this->setAcceptHoverEvents(true);
this->setPath(ToolPath());
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
spl->GetP1().toQPointF(), this);
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
@ -325,11 +322,9 @@ void VToolSpline::SaveDialog(QDomElement &domElement)
void VToolSpline::RefreshGeometry()
{
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
this->setPath(ToolPath());
const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
QPainterPath path;
path.addPath(spl->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
QPointF splinePoint = VAbstractTool::data.GeometricObject<const VPointF *>(spl->GetP1().id())->toQPointF();
QPointF controlPoint = spl->GetP2();
emit RefreshLine(1, SplinePointPosition::FirstPoint, controlPoint, splinePoint);

View File

@ -45,16 +45,13 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co
QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
QPainterPath path;
path.addPath(splPath->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
this->setPath(ToolPath());
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
this->setAcceptHoverEvents(true);
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
for (qint32 i = 1; i<=splPath->Count(); ++i)
{
VSpline spl = splPath->GetSpline(i);
@ -374,11 +371,9 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement)
void VToolSplinePath::RefreshGeometry()
{
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
this->setPath(ToolPath());
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
QPainterPath path;
path.addPath(splPath->GetPath());
path.setFillRule( Qt::WindingFill );
this->setPath(path);
for (qint32 i = 1; i<=splPath->Count(); ++i)
{
VSpline spl = splPath->GetSpline(i);

View File

@ -53,10 +53,11 @@ void VisPath::AddOnScene()
}
//---------------------------------------------------------------------------------------------------------------------
void VisPath::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style)
void VisPath::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style,
Qt::PenCapStyle cap)
{
SCASSERT (pathItem != nullptr);
pathItem->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style));
pathItem->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style, cap));
pathItem->setPath(path);
}

View File

@ -44,7 +44,7 @@ protected:
virtual void AddOnScene();
void DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, const QColor &color,
Qt::PenStyle style = Qt::SolidLine);
Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap);
private:
Q_DISABLE_COPY(VisPath)
};

View File

@ -53,7 +53,7 @@ void VisToolArc::RefreshGeometry()
if (qFuzzyCompare(1 + radius, 1 + 0) == false && f1 >= 0 && f2 >= 0 && qFuzzyCompare(1 + f1, 1 + f2) == false)
{
VArc arc = VArc (*first, radius, f1, f2);
DrawPath(this, arc.GetPath(), mainColor);
DrawPath(this, arc.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
}
}
}

View File

@ -54,7 +54,7 @@ void VisToolCutArc::RefreshGeometry()
if (point1Id > 0)
{
const VArc *arc = Visualization::data->GeometricObject<const VArc *>(point1Id);
DrawPath(this, arc->GetPath(), supportColor);
DrawPath(this, arc->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap);
if (qFuzzyCompare(1 + length, 1 + 0) == false)
{
@ -63,8 +63,8 @@ void VisToolCutArc::RefreshGeometry()
QPointF p = arc->CutArc(length, ar1, ar2);
DrawPoint(point, p, mainColor);
DrawPath(arc1, ar1.GetPath(), Qt::darkGreen);
DrawPath(arc2, ar2.GetPath(), Qt::darkRed);
DrawPath(arc1, ar1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap);
DrawPath(arc2, ar2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap);
}
}
}

View File

@ -40,8 +40,10 @@
* @param currentColor current color.
* @param parent parent object.
*/
VSimpleCurve::VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, qreal *factor, QObject *parent)
:QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor)
VSimpleCurve::VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, SimpleCurvePoint pointPosition, qreal *factor,
QObject *parent)
:QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor),
curvePosition(pointPosition)
{
if (factor == nullptr)
{
@ -106,6 +108,7 @@ void VSimpleCurve::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor));
}
emit HoverPath(id, curvePosition, PathDirection::Show);
}
//---------------------------------------------------------------------------------------------------------------------
@ -124,4 +127,6 @@ void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor));
}
emit HoverPath(id, curvePosition, PathDirection::Hide);
}

View File

@ -30,6 +30,7 @@
#define VSIMPLECURVE_H
#include <QGraphicsPathItem>
#include "../geometry/vabstractcurve.h"
enum class SimpleCurvePoint : char { FirstPoint, ForthPoint };
@ -40,7 +41,8 @@ class VSimpleCurve : public QObject, public QGraphicsPathItem
{
Q_OBJECT
public:
VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, qreal *factor = nullptr, QObject *parent = 0);
VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, SimpleCurvePoint curvePosition,
qreal *factor = nullptr, QObject *parent = 0);
void ChangedActivDraw(const bool &flag);
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
signals:
@ -49,6 +51,7 @@ signals:
* @param id spline id.
*/
void Choosed(quint32 id);
void HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirection direction);
protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
@ -63,6 +66,8 @@ private:
/** @brief currentColor current color. */
Qt::GlobalColor *currentColor;
SimpleCurvePoint curvePosition;
};
#endif // VSIMPLECURVE_H