The first implementation for tool Spline.
--HG-- branch : feature
This commit is contained in:
parent
791d874c9a
commit
0f747ede7e
|
@ -42,6 +42,7 @@
|
|||
#include "../vmisc/vsettings.h"
|
||||
#include "../qmuparser/qmuparsererror.h"
|
||||
#include "../vgeometry/varc.h"
|
||||
#include "../vgeometry/vsplinepath.h"
|
||||
#include "../core/vapplication.h"
|
||||
#include "../vpatterndb/calculator.h"
|
||||
|
||||
|
|
|
@ -30,8 +30,10 @@
|
|||
#include "ui_dialogspline.h"
|
||||
|
||||
#include "../vgeometry/vpointf.h"
|
||||
#include "../vgeometry/vspline.h"
|
||||
#include "../vpatterndb/vcontainer.h"
|
||||
#include "../../visualization/vistoolspline.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -41,8 +43,7 @@
|
|||
* @param parent parent widget
|
||||
*/
|
||||
DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
||||
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1),
|
||||
kCurve(1)
|
||||
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
InitOkCancelApply(ui);
|
||||
|
@ -57,6 +58,13 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
|
|||
this, &DialogSpline::PointNameChanged);
|
||||
|
||||
vis = new VisToolSpline(data);
|
||||
auto path = qobject_cast<VisToolSpline *>(vis);
|
||||
SCASSERT(path != nullptr);
|
||||
|
||||
auto scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
||||
SCASSERT(scene != nullptr);
|
||||
connect(scene, &VMainGraphicsScene::MouseLeftPressed, path, &VisToolSpline::MouseLeftPressed);
|
||||
connect(scene, &VMainGraphicsScene::MouseLeftReleased, path, &VisToolSpline::MouseLeftReleased);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -88,7 +96,7 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
|
|||
{
|
||||
if (type == SceneObject::Point)
|
||||
{
|
||||
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
|
||||
auto *path = qobject_cast<VisToolSpline *>(vis);
|
||||
SCASSERT(path != nullptr);
|
||||
|
||||
switch (number)
|
||||
|
@ -96,7 +104,7 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
|
|||
case 0:
|
||||
if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve")))
|
||||
{
|
||||
number++;
|
||||
++number;
|
||||
path->VisualMode(id);
|
||||
}
|
||||
break;
|
||||
|
@ -104,29 +112,13 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
|
|||
{
|
||||
if (getCurrentObjectId(ui->comboBoxP1) != id)
|
||||
{
|
||||
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(id);
|
||||
qint32 index = ui->comboBoxP4->findText(point->name());
|
||||
if ( index != -1 )
|
||||
{ // -1 for not found
|
||||
ui->comboBoxP4->setCurrentIndex(index);
|
||||
emit ToolTip("");
|
||||
index = ui->comboBoxP1->currentIndex();
|
||||
quint32 p1Id = qvariant_cast<quint32>(ui->comboBoxP1->itemData(index));
|
||||
|
||||
QPointF p1 = data->GeometricObject<VPointF>(p1Id)->toQPointF();
|
||||
QPointF p4 = data->GeometricObject<VPointF>(id)->toQPointF();
|
||||
|
||||
ui->spinBoxAngle1->setValue(static_cast<qint32>(QLineF(p1, p4).angle()));
|
||||
ui->spinBoxAngle2->setValue(static_cast<qint32>(QLineF(p4, p1).angle()));
|
||||
if (SetObject(id, ui->comboBoxP4, ""))
|
||||
{
|
||||
++number;
|
||||
|
||||
path->setObject4Id(id);
|
||||
path->RefreshGeometry();
|
||||
prepare = true;
|
||||
DialogAccepted();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning()<<"Can't find object by name"<<point->name();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -183,6 +175,32 @@ void DialogSpline::PointNameChanged()
|
|||
CheckState();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogSpline::ShowDialog(bool click)
|
||||
{
|
||||
if (prepare && click)
|
||||
{
|
||||
const auto p1 = data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP1));
|
||||
const auto p4 = data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP4));
|
||||
|
||||
auto *path = qobject_cast<VisToolSpline *>(vis);
|
||||
SCASSERT(path != nullptr);
|
||||
|
||||
const QPointF p2 = path->GetP2();
|
||||
const QPointF p3 = path->GetP3();
|
||||
|
||||
VSpline spline(*p1, p2, p3, *p4, kCurve);
|
||||
|
||||
ui->spinBoxAngle1->setValue(static_cast<qint32>(spline.GetStartAngle()));
|
||||
ui->spinBoxAngle2->setValue(static_cast<qint32>(spline.GetEndAngle()));
|
||||
|
||||
ui->doubleSpinBoxKasm1->setValue(spline.GetKasm1());
|
||||
ui->doubleSpinBoxKasm2->setValue(spline.GetKasm2());
|
||||
|
||||
DialogAccepted();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogSpline::ShowVisualization()
|
||||
{
|
||||
|
|
|
@ -72,6 +72,7 @@ public:
|
|||
public slots:
|
||||
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE;
|
||||
virtual void PointNameChanged() Q_DECL_OVERRIDE;
|
||||
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE;
|
||||
protected:
|
||||
virtual void ShowVisualization() Q_DECL_OVERRIDE;
|
||||
/**
|
||||
|
|
|
@ -271,19 +271,7 @@ void DialogSplinePath::PathUpdated(const VSplinePath &path)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogSplinePath::ShowVisualization()
|
||||
{
|
||||
if (prepare == false)
|
||||
{
|
||||
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
||||
SCASSERT(scene != nullptr);
|
||||
|
||||
VisToolSplinePath *visPath = qobject_cast<VisToolSplinePath *>(vis);
|
||||
SCASSERT(visPath != nullptr);
|
||||
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor);
|
||||
scene->addItem(visPath);
|
||||
visPath->setMode(Mode::Show);
|
||||
visPath->RefreshGeometry();
|
||||
}
|
||||
AddVisualization<VisToolSplinePath>();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -349,6 +349,7 @@ inline void DialogTool::AddVisualization()
|
|||
scene->addItem(toolVis);
|
||||
}
|
||||
|
||||
toolVis->SetMode(Mode::Show);
|
||||
toolVis->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "vabstractspline.h"
|
||||
#include "../vwidgets/vcontrolpointspline.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
|
||||
const QString VAbstractSpline::TagName = QStringLiteral("spline");
|
||||
|
|
|
@ -30,10 +30,11 @@
|
|||
#define VABSTRACTSPLINE_H
|
||||
|
||||
#include "../vdrawtool.h"
|
||||
#include "../vwidgets/vcontrolpointspline.h"
|
||||
|
||||
#include <QGraphicsPathItem>
|
||||
|
||||
class VControlPointSpline;
|
||||
|
||||
class VAbstractSpline:public VDrawTool, public QGraphicsPathItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -56,15 +57,6 @@ public slots:
|
|||
virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE;
|
||||
void DetailsMode(bool mode);
|
||||
signals:
|
||||
/**
|
||||
* @brief RefreshLine refresh control line.
|
||||
* @param indexSpline position spline in spline list.
|
||||
* @param pos position point in spline.
|
||||
* @param controlPoint new position control point.
|
||||
* @param splinePoint new position spline point.
|
||||
*/
|
||||
void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos,
|
||||
const QPointF &controlPoint, const QPointF &splinePoint);
|
||||
/**
|
||||
* @brief setEnabledPoint disable control points.
|
||||
* @param enable enable or diasable points.
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "../../../dialogs/tools/dialogspline.h"
|
||||
#include "../../../undocommands/movespline.h"
|
||||
#include "../../../visualization/vistoolspline.h"
|
||||
#include "../vwidgets/vcontrolpointspline.h"
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
||||
# include "../vmisc/vmath.h"
|
||||
|
@ -64,23 +65,20 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co
|
|||
this->setAcceptHoverEvents(true);
|
||||
this->setPath(ToolPath());
|
||||
|
||||
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
||||
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
|
||||
spl->GetP1().toQPointF(), *data->GetPatternUnit(),
|
||||
this);
|
||||
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
||||
|
||||
auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
|
||||
spl->GetP1().toQPointF(), *data->GetPatternUnit(), this);
|
||||
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
|
||||
&VToolSpline::ControlPointChangePosition);
|
||||
connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
|
||||
connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint);
|
||||
connect(controlPoint1, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
|
||||
controlPoints.append(controlPoint1);
|
||||
|
||||
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(),
|
||||
spl->GetP4().toQPointF(), *data->GetPatternUnit(),
|
||||
this);
|
||||
auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(),
|
||||
spl->GetP4().toQPointF(), *data->GetPatternUnit(), this);
|
||||
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
|
||||
&VToolSpline::ControlPointChangePosition);
|
||||
connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine);
|
||||
connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint);
|
||||
connect(controlPoint2, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
|
||||
controlPoints.append(controlPoint2);
|
||||
|
@ -488,6 +486,7 @@ void VToolSpline::SetVisualization()
|
|||
visual->SetKAsm1(spl->GetKasm1());
|
||||
visual->SetKAsm2(spl->GetKasm2());
|
||||
visual->SetKCurve(spl->GetKcurve());
|
||||
visual->SetMode(Mode::Show);
|
||||
visual->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
@ -499,7 +498,7 @@ void VToolSpline::SetVisualization()
|
|||
void VToolSpline::RefreshGeometry()
|
||||
{
|
||||
// Very important to disable control points. Without it the pogram can't move the curve.
|
||||
foreach (VControlPointSpline *point, controlPoints)
|
||||
foreach (auto *point, controlPoints)
|
||||
{
|
||||
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
||||
}
|
||||
|
@ -515,26 +514,27 @@ void VToolSpline::RefreshGeometry()
|
|||
this->setPath(ToolPath());
|
||||
}
|
||||
|
||||
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
||||
QPointF splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP1().id())->toQPointF();
|
||||
QPointF controlPoint = spl->GetP2();
|
||||
emit RefreshLine(1, SplinePointPosition::FirstPoint, controlPoint, splinePoint);
|
||||
splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP4().id())->toQPointF();
|
||||
controlPoint = spl->GetP3();
|
||||
emit RefreshLine(1, SplinePointPosition::LastPoint, controlPoint, splinePoint);
|
||||
|
||||
controlPoints[0]->blockSignals(true);
|
||||
controlPoints[1]->blockSignals(true);
|
||||
|
||||
controlPoints[0]->setPos(spl->GetP2());
|
||||
controlPoints[1]->setPos(spl->GetP3());
|
||||
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
||||
|
||||
{
|
||||
const QPointF splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP1().id())->toQPointF();
|
||||
controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, spl->GetP2(), splinePoint);
|
||||
}
|
||||
|
||||
{
|
||||
const QPointF splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP4().id())->toQPointF();
|
||||
controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, spl->GetP3(), splinePoint);
|
||||
}
|
||||
|
||||
controlPoints[0]->blockSignals(false);
|
||||
controlPoints[1]->blockSignals(false);
|
||||
|
||||
SetVisualization();
|
||||
|
||||
foreach (VControlPointSpline *point, controlPoints)
|
||||
foreach (auto *point, controlPoints)
|
||||
{
|
||||
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include "vabstractspline.h"
|
||||
|
||||
class VSpline;
|
||||
|
||||
/**
|
||||
* @brief The VToolSpline class tool for creation spline. I mean bezier curve.
|
||||
*/
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "../../../dialogs/tools/dialogsplinepath.h"
|
||||
#include "../../../undocommands/movesplinepath.h"
|
||||
#include "../../../visualization/vistoolsplinepath.h"
|
||||
#include "../vwidgets/vcontrolpointspline.h"
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
||||
# include "../vmisc/vmath.h"
|
||||
|
@ -66,12 +67,10 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
|
|||
for (qint32 i = 1; i<=splPath->Count(); ++i)
|
||||
{
|
||||
VSpline spl = splPath->GetSpline(i);
|
||||
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(),
|
||||
spl.GetP1().toQPointF(), *data->GetPatternUnit(),
|
||||
this);
|
||||
auto *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(),
|
||||
spl.GetP1().toQPointF(), *data->GetPatternUnit(), this);
|
||||
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
||||
&VToolSplinePath::ControlPointChangePosition);
|
||||
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
|
||||
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
|
||||
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
|
||||
controlPoints.append(controlPoint);
|
||||
|
@ -80,7 +79,6 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
|
|||
*data->GetPatternUnit(), this);
|
||||
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
||||
&VToolSplinePath::ControlPointChangePosition);
|
||||
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
|
||||
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
|
||||
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
|
||||
controlPoints.append(controlPoint);
|
||||
|
@ -559,7 +557,7 @@ void VToolSplinePath::SetVisualization()
|
|||
|
||||
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
||||
visual->setPath(*splPath.data());
|
||||
visual->setMode(Mode::Show);
|
||||
visual->SetMode(Mode::Show);
|
||||
visual->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
@ -571,7 +569,7 @@ void VToolSplinePath::SetVisualization()
|
|||
void VToolSplinePath::RefreshGeometry()
|
||||
{
|
||||
// Very important to disable control points. Without it the pogram can't move the curve.
|
||||
foreach (VControlPointSpline *point, controlPoints)
|
||||
foreach (auto *point, controlPoints)
|
||||
{
|
||||
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
||||
}
|
||||
|
@ -584,26 +582,29 @@ void VToolSplinePath::RefreshGeometry()
|
|||
{
|
||||
this->setPath(ToolPath());
|
||||
}
|
||||
|
||||
this->setPen(QPen(CorrectColor(lineColor),
|
||||
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
||||
const QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
||||
|
||||
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
||||
for (qint32 i = 1; i<=splPath->Count(); ++i)
|
||||
{
|
||||
VSpline spl = splPath->GetSpline(i);
|
||||
QPointF splinePoint = spl.GetP1().toQPointF();
|
||||
QPointF controlPoint = spl.GetP2();
|
||||
emit RefreshLine(i, SplinePointPosition::FirstPoint, controlPoint, splinePoint);
|
||||
splinePoint = spl.GetP4().toQPointF();
|
||||
controlPoint = spl.GetP3();
|
||||
emit RefreshLine(i, SplinePointPosition::LastPoint, controlPoint, splinePoint);
|
||||
|
||||
qint32 j = i*2;
|
||||
const qint32 j = i*2;
|
||||
|
||||
controlPoints[j-2]->blockSignals(true);
|
||||
controlPoints[j-1]->blockSignals(true);
|
||||
|
||||
controlPoints[j-2]->setPos(spl.GetP2());
|
||||
controlPoints[j-1]->setPos(spl.GetP3());
|
||||
const auto spl = splPath->GetSpline(i);
|
||||
|
||||
{
|
||||
const auto splinePoint = spl.GetP1().toQPointF();
|
||||
controlPoints[j-2]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(), splinePoint);
|
||||
}
|
||||
|
||||
{
|
||||
const auto splinePoint = spl.GetP4().toQPointF();
|
||||
controlPoints[j-1]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(), splinePoint);
|
||||
}
|
||||
|
||||
controlPoints[j-2]->blockSignals(false);
|
||||
controlPoints[j-1]->blockSignals(false);
|
||||
|
@ -611,7 +612,7 @@ void VToolSplinePath::RefreshGeometry()
|
|||
|
||||
SetVisualization();
|
||||
|
||||
foreach (VControlPointSpline *point, controlPoints)
|
||||
foreach (auto *point, controlPoints)
|
||||
{
|
||||
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
|
||||
#include "vabstractspline.h"
|
||||
|
||||
class VSplinePath;
|
||||
class VSplinePoint;
|
||||
class VSpline;
|
||||
|
||||
/**
|
||||
* @brief The VToolSplinePath class tool for creation spline path.
|
||||
*/
|
||||
|
|
|
@ -30,17 +30,40 @@
|
|||
#include "../../vgeometry/vpointf.h"
|
||||
#include "../../vgeometry/vspline.h"
|
||||
#include "../../vpatterndb/vcontainer.h"
|
||||
#include "../vwidgets/vcontrolpointspline.h"
|
||||
|
||||
const int EMPTY_ANGLE = -1;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent)
|
||||
: VisPath(data, parent), object4Id(NULL_ID), lineP1(nullptr), lineP4(nullptr), line(nullptr), angle1(EMPTY_ANGLE),
|
||||
angle2(EMPTY_ANGLE), kAsm1(1), kAsm2(1), kCurve(1)
|
||||
: VisPath(data, parent),
|
||||
object4Id(NULL_ID),
|
||||
lineP1(nullptr),
|
||||
lineP4(nullptr),
|
||||
line(nullptr),
|
||||
angle1(EMPTY_ANGLE),
|
||||
angle2(EMPTY_ANGLE),
|
||||
kAsm1(1),
|
||||
kAsm2(1),
|
||||
kCurve(1),
|
||||
isLeftMousePressed(false),
|
||||
p2Selected(false),
|
||||
p3Selected(false),
|
||||
p2(),
|
||||
p3(),
|
||||
controlPoints()
|
||||
{
|
||||
lineP1 = InitPoint(supportColor, this);
|
||||
lineP4 = InitPoint(supportColor, this); //-V656
|
||||
line = InitItem<QGraphicsLineItem>(mainColor, this);
|
||||
|
||||
auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, *data->GetPatternUnit(), this);
|
||||
controlPoint1->hide();
|
||||
controlPoints.append(controlPoint1);
|
||||
|
||||
auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, *data->GetPatternUnit(), this);
|
||||
controlPoint2->hide();
|
||||
controlPoints.append(controlPoint2);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -52,21 +75,54 @@ void VisToolSpline::RefreshGeometry()
|
|||
{
|
||||
if (object1Id > NULL_ID)
|
||||
{
|
||||
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
||||
const auto first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
||||
DrawPoint(lineP1, first->toQPointF(), supportColor);
|
||||
|
||||
if (mode == Mode::Creation)
|
||||
{
|
||||
if (isLeftMousePressed && not p2Selected)
|
||||
{
|
||||
p2 = Visualization::scenePos;
|
||||
controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, p2, first->toQPointF());
|
||||
controlPoints[0]->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
p2Selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (object4Id <= NULL_ID)
|
||||
{
|
||||
DrawLine(line, QLineF(first->toQPointF(), Visualization::scenePos), mainColor);
|
||||
VSpline spline(*first, p2, Visualization::scenePos, VPointF(Visualization::scenePos), kCurve);
|
||||
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(object4Id);
|
||||
const auto second = Visualization::data->GeometricObject<VPointF>(object4Id);
|
||||
DrawPoint(lineP4, second->toQPointF(), supportColor);
|
||||
|
||||
if (mode == Mode::Creation)
|
||||
{
|
||||
if (isLeftMousePressed && not p3Selected)
|
||||
{
|
||||
QLineF ctrlLine (second->toQPointF(), Visualization::scenePos);
|
||||
ctrlLine.setAngle(ctrlLine.angle()+180);
|
||||
p3 = ctrlLine.p2();
|
||||
|
||||
controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, p3, second->toQPointF());
|
||||
controlPoints[1]->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
p3Selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (qFuzzyCompare(angle1, EMPTY_ANGLE) || qFuzzyCompare(angle2, EMPTY_ANGLE))
|
||||
{
|
||||
DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), mainColor);
|
||||
VSpline spline(*first, p2, p3, *second, kCurve);
|
||||
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -112,3 +168,34 @@ void VisToolSpline::SetKCurve(const qreal &value)
|
|||
{
|
||||
kCurve = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPointF VisToolSpline::GetP2() const
|
||||
{
|
||||
return p2;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPointF VisToolSpline::GetP3() const
|
||||
{
|
||||
return p3;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolSpline::MouseLeftPressed()
|
||||
{
|
||||
if (mode == Mode::Creation)
|
||||
{
|
||||
isLeftMousePressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolSpline::MouseLeftReleased()
|
||||
{
|
||||
if (mode == Mode::Creation)
|
||||
{
|
||||
isLeftMousePressed = false;
|
||||
RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include "vispath.h"
|
||||
|
||||
class VControlPointSpline;
|
||||
|
||||
class VisToolSpline : public VisPath
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -47,8 +49,16 @@ public:
|
|||
void SetKAsm2(const qreal &value);
|
||||
void SetKCurve(const qreal &value);
|
||||
|
||||
QPointF GetP2() const;
|
||||
QPointF GetP3() const;
|
||||
|
||||
virtual int type() const Q_DECL_OVERRIDE {return Type;}
|
||||
enum { Type = UserType + static_cast<int>(Vis::ToolSpline)};
|
||||
|
||||
public slots:
|
||||
void MouseLeftPressed();
|
||||
void MouseLeftReleased();
|
||||
|
||||
protected:
|
||||
Q_DISABLE_COPY(VisToolSpline)
|
||||
quint32 object4Id;
|
||||
|
@ -60,6 +70,15 @@ protected:
|
|||
qreal kAsm1;
|
||||
qreal kAsm2;
|
||||
qreal kCurve;
|
||||
|
||||
bool isLeftMousePressed;
|
||||
bool p2Selected;
|
||||
bool p3Selected;
|
||||
|
||||
QPointF p2;
|
||||
QPointF p3;
|
||||
|
||||
QVector<VControlPointSpline *> controlPoints;
|
||||
};
|
||||
|
||||
#endif // VISTOOLSPLINE_H
|
||||
|
|
|
@ -30,8 +30,7 @@
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent)
|
||||
: VisPath(data, parent), points(QVector<QGraphicsEllipseItem *>()), line(nullptr), path(VSplinePath()),
|
||||
mode(Mode::Creation)
|
||||
: VisPath(data, parent), points(QVector<QGraphicsEllipseItem *>()), line(nullptr), path(VSplinePath())
|
||||
{
|
||||
line = InitItem<QGraphicsLineItem>(mainColor, this);
|
||||
}
|
||||
|
@ -107,18 +106,6 @@ VSplinePath VisToolSplinePath::getPath()
|
|||
return path;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Mode VisToolSplinePath::getMode() const
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolSplinePath::setMode(const Mode &value)
|
||||
{
|
||||
mode = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i)
|
||||
{
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
#include "vispath.h"
|
||||
#include "../../vgeometry/vsplinepath.h"
|
||||
|
||||
enum class Mode : char {Creation, Show};
|
||||
|
||||
class VisToolSplinePath : public VisPath
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -49,8 +47,6 @@ public:
|
|||
virtual int type() const Q_DECL_OVERRIDE {return Type;}
|
||||
enum { Type = UserType + static_cast<int>(Vis::ToolSplinePath)};
|
||||
|
||||
Mode getMode() const;
|
||||
void setMode(const Mode &value);
|
||||
signals:
|
||||
void PathChanged(const VSplinePath &path);
|
||||
|
||||
|
@ -59,7 +55,6 @@ protected:
|
|||
QVector<QGraphicsEllipseItem *> points;
|
||||
QGraphicsLineItem *line;
|
||||
VSplinePath path;
|
||||
Mode mode;
|
||||
|
||||
QGraphicsEllipseItem * getPoint(quint32 i);
|
||||
};
|
||||
|
|
|
@ -37,8 +37,16 @@ Q_LOGGING_CATEGORY(vVis, "v.visualization")
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Visualization::Visualization(const VContainer *data)
|
||||
:QObject(), data(data), factor(VDrawTool::factor), scenePos(QPointF()),
|
||||
mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), object1Id(NULL_ID), toolTip(QString())
|
||||
:QObject(),
|
||||
data(data),
|
||||
factor(VDrawTool::factor),
|
||||
scenePos(QPointF()),
|
||||
mainColor(Qt::red),
|
||||
supportColor(Qt::magenta),
|
||||
lineStyle(Qt::SolidLine),
|
||||
object1Id(NULL_ID),
|
||||
toolTip(QString()),
|
||||
mode(Mode::Creation)
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -196,3 +204,16 @@ void Visualization::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &pa
|
|||
pathItem->setPath(path);
|
||||
pathItem->setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Mode Visualization::GetMode() const
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void Visualization::SetMode(const Mode &value)
|
||||
{
|
||||
mode = value;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
|
||||
Q_DECLARE_LOGGING_CATEGORY(vVis)
|
||||
|
||||
enum class Mode : char {Creation, Show};
|
||||
|
||||
class Visualization : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -53,6 +55,9 @@ public:
|
|||
void setScenePos(const QPointF &value);
|
||||
virtual void VisualMode(const quint32 &pointId);
|
||||
void setMainColor(const QColor &value);
|
||||
|
||||
Mode GetMode() const;
|
||||
void SetMode(const Mode &value);
|
||||
signals:
|
||||
void ToolTip(const QString &toolTip);
|
||||
public slots:
|
||||
|
@ -67,6 +72,7 @@ protected:
|
|||
Qt::PenStyle lineStyle;
|
||||
quint32 object1Id;
|
||||
QString toolTip;
|
||||
Mode mode;
|
||||
|
||||
virtual void InitPen()=0;
|
||||
virtual void AddOnScene()=0;
|
||||
|
|
|
@ -36,6 +36,19 @@
|
|||
#include "vmaingraphicsview.h"
|
||||
#include "vmaingraphicsscene.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit,
|
||||
QGraphicsItem *parent)
|
||||
:QGraphicsEllipseItem(parent),
|
||||
radius(CircleRadius()),
|
||||
controlLine(nullptr),
|
||||
indexSpline(indexSpline),
|
||||
position(position),
|
||||
patternUnit(patternUnit)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief VControlPointSpline constructor.
|
||||
|
@ -48,28 +61,22 @@
|
|||
VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position,
|
||||
const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit,
|
||||
QGraphicsItem *parent)
|
||||
:QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position),
|
||||
:QGraphicsEllipseItem(parent),
|
||||
radius(CircleRadius()),
|
||||
controlLine(nullptr),
|
||||
indexSpline(indexSpline),
|
||||
position(position),
|
||||
patternUnit(patternUnit)
|
||||
{
|
||||
//create circle
|
||||
radius = (1.5/*mm*/ / 25.4) * PrintDPI;
|
||||
QRectF rec = QRectF(0, 0, radius*2, radius*2);
|
||||
rec.translate(-rec.center().x(), -rec.center().y());
|
||||
this->setRect(rec);
|
||||
this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit)));
|
||||
this->setBrush(QBrush(Qt::NoBrush));
|
||||
Init();
|
||||
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
this->setAcceptHoverEvents(true);
|
||||
this->setPos(controlPoint);
|
||||
this->setZValue(100);
|
||||
|
||||
QPointF p1, p2;
|
||||
VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2);
|
||||
controlLine = new QGraphicsLineItem(QLineF(splinePoint-controlPoint, p1), this);
|
||||
controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit)));
|
||||
controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
|
||||
SetCtrlLine(controlPoint, splinePoint);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -196,22 +203,44 @@ void VControlPointSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event
|
|||
emit ShowContextMenu(event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VControlPointSpline::Init()
|
||||
{
|
||||
auto rec = QRectF(0, 0, radius*2, radius*2);
|
||||
rec.translate(-rec.center().x(), -rec.center().y());
|
||||
this->setRect(rec);
|
||||
this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit)));
|
||||
this->setBrush(QBrush(Qt::NoBrush));
|
||||
this->setZValue(100);
|
||||
|
||||
controlLine = new QGraphicsLineItem(this);
|
||||
controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit)));
|
||||
controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VControlPointSpline::SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint)
|
||||
{
|
||||
QPointF p1, p2;
|
||||
VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2);
|
||||
controlLine->setLine(QLineF(splinePoint-controlPoint, p1));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief RefreshLine refresh line control point.
|
||||
* @brief RefreshCtrlPoint refresh the control point.
|
||||
* @param indexSpline index spline in list.
|
||||
* @param pos position point in spline.
|
||||
* @param controlPoint control point.
|
||||
* @param splinePoint spline point.
|
||||
*/
|
||||
void VControlPointSpline::RefreshLine(const qint32 &indexSpline, SplinePointPosition pos,
|
||||
const QPointF &controlPoint, const QPointF &splinePoint)
|
||||
void VControlPointSpline::RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos,
|
||||
const QPointF &controlPoint, const QPointF &splinePoint)
|
||||
{
|
||||
if (this->indexSpline == indexSpline && this->position == pos)
|
||||
{
|
||||
QPointF p1, p2;
|
||||
VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2);
|
||||
controlLine->setLine(QLineF(splinePoint-controlPoint, p1));
|
||||
this->setPos(controlPoint);
|
||||
SetCtrlLine(controlPoint, splinePoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ class VControlPointSpline : public QObject, public QGraphicsEllipseItem
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit,
|
||||
QGraphicsItem * parent = nullptr);
|
||||
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint,
|
||||
const QPointF &splinePoint, Unit patternUnit, QGraphicsItem * parent = nullptr);
|
||||
virtual ~VControlPointSpline() Q_DECL_OVERRIDE;
|
||||
|
@ -63,12 +65,12 @@ signals:
|
|||
*/
|
||||
void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
|
||||
public slots:
|
||||
void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
|
||||
const QPointF &splinePoint);
|
||||
void RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
|
||||
const QPointF &splinePoint);
|
||||
void setEnabledPoint(bool enable);
|
||||
protected:
|
||||
/** @brief radius radius circle. */
|
||||
qreal radius;
|
||||
const qreal radius;
|
||||
|
||||
/** @brief controlLine pointer to line control point. */
|
||||
QGraphicsLineItem *controlLine;
|
||||
|
@ -88,6 +90,16 @@ private:
|
|||
SplinePointPosition position;
|
||||
|
||||
Unit patternUnit;
|
||||
|
||||
inline qreal CircleRadius() const;
|
||||
void Init();
|
||||
void SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint);
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VControlPointSpline::CircleRadius() const
|
||||
{
|
||||
return (1.5/*mm*/ / 25.4) * PrintDPI;
|
||||
}
|
||||
|
||||
#endif // VCONTROLPOINTSPLINE_H
|
||||
|
|
|
@ -74,7 +74,11 @@ void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
|
|||
*/
|
||||
void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
emit mousePress(event->scenePos());
|
||||
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
||||
{
|
||||
emit MouseLeftPressed();
|
||||
}
|
||||
|
||||
QGraphicsScene::mousePressEvent(event);
|
||||
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier)
|
||||
{
|
||||
|
@ -86,6 +90,16 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VMainGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
||||
{
|
||||
emit MouseLeftReleased();
|
||||
}
|
||||
QGraphicsScene::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VMainGraphicsScene::InitOrigins()
|
||||
{
|
||||
|
|
|
@ -61,17 +61,17 @@ public slots:
|
|||
protected:
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
signals:
|
||||
/**
|
||||
* @brief mouseMove send new mouse position.
|
||||
* @param scenePos new mouse position.
|
||||
*/
|
||||
void mouseMove(const QPointF &scenePos);
|
||||
/**
|
||||
* @brief mousePress send new mouse press position.
|
||||
* @param scenePos new mouse press position.
|
||||
*/
|
||||
void mousePress(QPointF scenePos);
|
||||
|
||||
void MouseLeftPressed();
|
||||
void MouseLeftReleased();
|
||||
|
||||
/**
|
||||
* @brief ChoosedObject send option choosed object.
|
||||
* @param id object id.
|
||||
|
|
Loading…
Reference in New Issue
Block a user