The first implementation for tool Spline.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-02-12 20:10:01 +02:00
parent 791d874c9a
commit 0f747ede7e
21 changed files with 323 additions and 143 deletions

View File

@ -42,6 +42,7 @@
#include "../vmisc/vsettings.h" #include "../vmisc/vsettings.h"
#include "../qmuparser/qmuparsererror.h" #include "../qmuparser/qmuparsererror.h"
#include "../vgeometry/varc.h" #include "../vgeometry/varc.h"
#include "../vgeometry/vsplinepath.h"
#include "../core/vapplication.h" #include "../core/vapplication.h"
#include "../vpatterndb/calculator.h" #include "../vpatterndb/calculator.h"

View File

@ -30,8 +30,10 @@
#include "ui_dialogspline.h" #include "ui_dialogspline.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vgeometry/vspline.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../../visualization/vistoolspline.h" #include "../../visualization/vistoolspline.h"
#include <QDebug> #include <QDebug>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -41,8 +43,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) 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), :DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1)
kCurve(1)
{ {
ui->setupUi(this); ui->setupUi(this);
InitOkCancelApply(ui); InitOkCancelApply(ui);
@ -57,6 +58,13 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
this, &DialogSpline::PointNameChanged); this, &DialogSpline::PointNameChanged);
vis = new VisToolSpline(data); 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) if (type == SceneObject::Point)
{ {
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis); auto *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr); SCASSERT(path != nullptr);
switch (number) switch (number)
@ -96,7 +104,7 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
case 0: case 0:
if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve"))) if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve")))
{ {
number++; ++number;
path->VisualMode(id); path->VisualMode(id);
} }
break; break;
@ -104,29 +112,13 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (getCurrentObjectId(ui->comboBoxP1) != id) if (getCurrentObjectId(ui->comboBoxP1) != id)
{ {
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(id); if (SetObject(id, ui->comboBoxP4, ""))
qint32 index = ui->comboBoxP4->findText(point->name()); {
if ( index != -1 ) ++number;
{ // -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()));
path->setObject4Id(id); path->setObject4Id(id);
path->RefreshGeometry(); path->RefreshGeometry();
prepare = true; prepare = true;
DialogAccepted();
}
else
{
qWarning()<<"Can't find object by name"<<point->name();
} }
} }
break; break;
@ -183,6 +175,32 @@ void DialogSpline::PointNameChanged()
CheckState(); 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() void DialogSpline::ShowVisualization()
{ {

View File

@ -72,6 +72,7 @@ public:
public slots: public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE;
virtual void PointNameChanged() Q_DECL_OVERRIDE; virtual void PointNameChanged() Q_DECL_OVERRIDE;
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE;
protected: protected:
virtual void ShowVisualization() Q_DECL_OVERRIDE; virtual void ShowVisualization() Q_DECL_OVERRIDE;
/** /**

View File

@ -271,19 +271,7 @@ void DialogSplinePath::PathUpdated(const VSplinePath &path)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::ShowVisualization() void DialogSplinePath::ShowVisualization()
{ {
if (prepare == false) AddVisualization<VisToolSplinePath>();
{
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();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -349,6 +349,7 @@ inline void DialogTool::AddVisualization()
scene->addItem(toolVis); scene->addItem(toolVis);
} }
toolVis->SetMode(Mode::Show);
toolVis->RefreshGeometry(); toolVis->RefreshGeometry();
} }
} }

View File

@ -27,6 +27,8 @@
*************************************************************************/ *************************************************************************/
#include "vabstractspline.h" #include "vabstractspline.h"
#include "../vwidgets/vcontrolpointspline.h"
#include <QKeyEvent> #include <QKeyEvent>
const QString VAbstractSpline::TagName = QStringLiteral("spline"); const QString VAbstractSpline::TagName = QStringLiteral("spline");

View File

@ -30,10 +30,11 @@
#define VABSTRACTSPLINE_H #define VABSTRACTSPLINE_H
#include "../vdrawtool.h" #include "../vdrawtool.h"
#include "../vwidgets/vcontrolpointspline.h"
#include <QGraphicsPathItem> #include <QGraphicsPathItem>
class VControlPointSpline;
class VAbstractSpline:public VDrawTool, public QGraphicsPathItem class VAbstractSpline:public VDrawTool, public QGraphicsPathItem
{ {
Q_OBJECT Q_OBJECT
@ -56,15 +57,6 @@ public slots:
virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE;
void DetailsMode(bool mode); void DetailsMode(bool mode);
signals: 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. * @brief setEnabledPoint disable control points.
* @param enable enable or diasable points. * @param enable enable or diasable points.

View File

@ -31,6 +31,7 @@
#include "../../../dialogs/tools/dialogspline.h" #include "../../../dialogs/tools/dialogspline.h"
#include "../../../undocommands/movespline.h" #include "../../../undocommands/movespline.h"
#include "../../../visualization/vistoolspline.h" #include "../../../visualization/vistoolspline.h"
#include "../vwidgets/vcontrolpointspline.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
# include "../vmisc/vmath.h" # include "../vmisc/vmath.h"
@ -64,23 +65,20 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
this->setPath(ToolPath()); this->setPath(ToolPath());
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id); const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
spl->GetP1().toQPointF(), *data->GetPatternUnit(), auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
this); spl->GetP1().toQPointF(), *data->GetPatternUnit(), this);
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition); &VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint); connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint);
connect(controlPoint1, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); connect(controlPoint1, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
controlPoints.append(controlPoint1); controlPoints.append(controlPoint1);
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(), auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(),
spl->GetP4().toQPointF(), *data->GetPatternUnit(), spl->GetP4().toQPointF(), *data->GetPatternUnit(), this);
this);
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition); &VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine);
connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint);
connect(controlPoint2, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); connect(controlPoint2, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
controlPoints.append(controlPoint2); controlPoints.append(controlPoint2);
@ -488,6 +486,7 @@ void VToolSpline::SetVisualization()
visual->SetKAsm1(spl->GetKasm1()); visual->SetKAsm1(spl->GetKasm1());
visual->SetKAsm2(spl->GetKasm2()); visual->SetKAsm2(spl->GetKasm2());
visual->SetKCurve(spl->GetKcurve()); visual->SetKCurve(spl->GetKcurve());
visual->SetMode(Mode::Show);
visual->RefreshGeometry(); visual->RefreshGeometry();
} }
} }
@ -499,7 +498,7 @@ void VToolSpline::SetVisualization()
void VToolSpline::RefreshGeometry() void VToolSpline::RefreshGeometry()
{ {
// Very important to disable control points. Without it the pogram can't move the curve. // 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); point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
} }
@ -515,26 +514,27 @@ void VToolSpline::RefreshGeometry()
this->setPath(ToolPath()); 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[0]->blockSignals(true);
controlPoints[1]->blockSignals(true); controlPoints[1]->blockSignals(true);
controlPoints[0]->setPos(spl->GetP2()); const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
controlPoints[1]->setPos(spl->GetP3());
{
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[0]->blockSignals(false);
controlPoints[1]->blockSignals(false); controlPoints[1]->blockSignals(false);
SetVisualization(); SetVisualization();
foreach (VControlPointSpline *point, controlPoints) foreach (auto *point, controlPoints)
{ {
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
} }

View File

@ -31,6 +31,8 @@
#include "vabstractspline.h" #include "vabstractspline.h"
class VSpline;
/** /**
* @brief The VToolSpline class tool for creation spline. I mean bezier curve. * @brief The VToolSpline class tool for creation spline. I mean bezier curve.
*/ */

View File

@ -30,6 +30,7 @@
#include "../../../dialogs/tools/dialogsplinepath.h" #include "../../../dialogs/tools/dialogsplinepath.h"
#include "../../../undocommands/movesplinepath.h" #include "../../../undocommands/movesplinepath.h"
#include "../../../visualization/vistoolsplinepath.h" #include "../../../visualization/vistoolsplinepath.h"
#include "../vwidgets/vcontrolpointspline.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
# include "../vmisc/vmath.h" # include "../vmisc/vmath.h"
@ -66,12 +67,10 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
for (qint32 i = 1; i<=splPath->Count(); ++i) for (qint32 i = 1; i<=splPath->Count(); ++i)
{ {
VSpline spl = splPath->GetSpline(i); VSpline spl = splPath->GetSpline(i);
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(), auto *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(),
spl.GetP1().toQPointF(), *data->GetPatternUnit(), spl.GetP1().toQPointF(), *data->GetPatternUnit(), this);
this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition); &VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
controlPoints.append(controlPoint); controlPoints.append(controlPoint);
@ -80,7 +79,6 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
*data->GetPatternUnit(), this); *data->GetPatternUnit(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition); &VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
controlPoints.append(controlPoint); controlPoints.append(controlPoint);
@ -559,7 +557,7 @@ void VToolSplinePath::SetVisualization()
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id); QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
visual->setPath(*splPath.data()); visual->setPath(*splPath.data());
visual->setMode(Mode::Show); visual->SetMode(Mode::Show);
visual->RefreshGeometry(); visual->RefreshGeometry();
} }
} }
@ -571,7 +569,7 @@ void VToolSplinePath::SetVisualization()
void VToolSplinePath::RefreshGeometry() void VToolSplinePath::RefreshGeometry()
{ {
// Very important to disable control points. Without it the pogram can't move the curve. // 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); point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
} }
@ -584,26 +582,29 @@ void VToolSplinePath::RefreshGeometry()
{ {
this->setPath(ToolPath()); this->setPath(ToolPath());
} }
this->setPen(QPen(CorrectColor(lineColor), this->setPen(QPen(CorrectColor(lineColor),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); 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) for (qint32 i = 1; i<=splPath->Count(); ++i)
{ {
VSpline spl = splPath->GetSpline(i); const qint32 j = i*2;
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;
controlPoints[j-2]->blockSignals(true); controlPoints[j-2]->blockSignals(true);
controlPoints[j-1]->blockSignals(true); controlPoints[j-1]->blockSignals(true);
controlPoints[j-2]->setPos(spl.GetP2()); const auto spl = splPath->GetSpline(i);
controlPoints[j-1]->setPos(spl.GetP3());
{
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-2]->blockSignals(false);
controlPoints[j-1]->blockSignals(false); controlPoints[j-1]->blockSignals(false);
@ -611,7 +612,7 @@ void VToolSplinePath::RefreshGeometry()
SetVisualization(); SetVisualization();
foreach (VControlPointSpline *point, controlPoints) foreach (auto *point, controlPoints)
{ {
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
} }

View File

@ -31,6 +31,10 @@
#include "vabstractspline.h" #include "vabstractspline.h"
class VSplinePath;
class VSplinePoint;
class VSpline;
/** /**
* @brief The VToolSplinePath class tool for creation spline path. * @brief The VToolSplinePath class tool for creation spline path.
*/ */

View File

@ -30,17 +30,40 @@
#include "../../vgeometry/vpointf.h" #include "../../vgeometry/vpointf.h"
#include "../../vgeometry/vspline.h" #include "../../vgeometry/vspline.h"
#include "../../vpatterndb/vcontainer.h" #include "../../vpatterndb/vcontainer.h"
#include "../vwidgets/vcontrolpointspline.h"
const int EMPTY_ANGLE = -1; const int EMPTY_ANGLE = -1;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent) VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent), object4Id(NULL_ID), lineP1(nullptr), lineP4(nullptr), line(nullptr), angle1(EMPTY_ANGLE), : VisPath(data, parent),
angle2(EMPTY_ANGLE), kAsm1(1), kAsm2(1), kCurve(1) 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); lineP1 = InitPoint(supportColor, this);
lineP4 = InitPoint(supportColor, this); //-V656 lineP4 = InitPoint(supportColor, this); //-V656
line = InitItem<QGraphicsLineItem>(mainColor, this); 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) 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); 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) 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 else
{ {
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(object4Id); const auto second = Visualization::data->GeometricObject<VPointF>(object4Id);
DrawPoint(lineP4, second->toQPointF(), supportColor); 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)) 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 else
{ {
@ -112,3 +168,34 @@ void VisToolSpline::SetKCurve(const qreal &value)
{ {
kCurve = 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();
}
}

View File

@ -31,6 +31,8 @@
#include "vispath.h" #include "vispath.h"
class VControlPointSpline;
class VisToolSpline : public VisPath class VisToolSpline : public VisPath
{ {
Q_OBJECT Q_OBJECT
@ -47,8 +49,16 @@ public:
void SetKAsm2(const qreal &value); void SetKAsm2(const qreal &value);
void SetKCurve(const qreal &value); void SetKCurve(const qreal &value);
QPointF GetP2() const;
QPointF GetP3() const;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolSpline)}; enum { Type = UserType + static_cast<int>(Vis::ToolSpline)};
public slots:
void MouseLeftPressed();
void MouseLeftReleased();
protected: protected:
Q_DISABLE_COPY(VisToolSpline) Q_DISABLE_COPY(VisToolSpline)
quint32 object4Id; quint32 object4Id;
@ -60,6 +70,15 @@ protected:
qreal kAsm1; qreal kAsm1;
qreal kAsm2; qreal kAsm2;
qreal kCurve; qreal kCurve;
bool isLeftMousePressed;
bool p2Selected;
bool p3Selected;
QPointF p2;
QPointF p3;
QVector<VControlPointSpline *> controlPoints;
}; };
#endif // VISTOOLSPLINE_H #endif // VISTOOLSPLINE_H

View File

@ -30,8 +30,7 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent) VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent), points(QVector<QGraphicsEllipseItem *>()), line(nullptr), path(VSplinePath()), : VisPath(data, parent), points(QVector<QGraphicsEllipseItem *>()), line(nullptr), path(VSplinePath())
mode(Mode::Creation)
{ {
line = InitItem<QGraphicsLineItem>(mainColor, this); line = InitItem<QGraphicsLineItem>(mainColor, this);
} }
@ -107,18 +106,6 @@ VSplinePath VisToolSplinePath::getPath()
return path; return path;
} }
//---------------------------------------------------------------------------------------------------------------------
Mode VisToolSplinePath::getMode() const
{
return mode;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSplinePath::setMode(const Mode &value)
{
mode = value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i)
{ {

View File

@ -32,8 +32,6 @@
#include "vispath.h" #include "vispath.h"
#include "../../vgeometry/vsplinepath.h" #include "../../vgeometry/vsplinepath.h"
enum class Mode : char {Creation, Show};
class VisToolSplinePath : public VisPath class VisToolSplinePath : public VisPath
{ {
Q_OBJECT Q_OBJECT
@ -49,8 +47,6 @@ public:
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolSplinePath)}; enum { Type = UserType + static_cast<int>(Vis::ToolSplinePath)};
Mode getMode() const;
void setMode(const Mode &value);
signals: signals:
void PathChanged(const VSplinePath &path); void PathChanged(const VSplinePath &path);
@ -59,7 +55,6 @@ protected:
QVector<QGraphicsEllipseItem *> points; QVector<QGraphicsEllipseItem *> points;
QGraphicsLineItem *line; QGraphicsLineItem *line;
VSplinePath path; VSplinePath path;
Mode mode;
QGraphicsEllipseItem * getPoint(quint32 i); QGraphicsEllipseItem * getPoint(quint32 i);
}; };

View File

@ -37,8 +37,16 @@ Q_LOGGING_CATEGORY(vVis, "v.visualization")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Visualization::Visualization(const VContainer *data) Visualization::Visualization(const VContainer *data)
:QObject(), data(data), factor(VDrawTool::factor), scenePos(QPointF()), :QObject(),
mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), object1Id(NULL_ID), toolTip(QString()) 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->setPath(path);
pathItem->setVisible(true); pathItem->setVisible(true);
} }
//---------------------------------------------------------------------------------------------------------------------
Mode Visualization::GetMode() const
{
return mode;
}
//---------------------------------------------------------------------------------------------------------------------
void Visualization::SetMode(const Mode &value)
{
mode = value;
}

View File

@ -39,6 +39,8 @@
Q_DECLARE_LOGGING_CATEGORY(vVis) Q_DECLARE_LOGGING_CATEGORY(vVis)
enum class Mode : char {Creation, Show};
class Visualization : public QObject class Visualization : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -53,6 +55,9 @@ public:
void setScenePos(const QPointF &value); void setScenePos(const QPointF &value);
virtual void VisualMode(const quint32 &pointId); virtual void VisualMode(const quint32 &pointId);
void setMainColor(const QColor &value); void setMainColor(const QColor &value);
Mode GetMode() const;
void SetMode(const Mode &value);
signals: signals:
void ToolTip(const QString &toolTip); void ToolTip(const QString &toolTip);
public slots: public slots:
@ -67,6 +72,7 @@ protected:
Qt::PenStyle lineStyle; Qt::PenStyle lineStyle;
quint32 object1Id; quint32 object1Id;
QString toolTip; QString toolTip;
Mode mode;
virtual void InitPen()=0; virtual void InitPen()=0;
virtual void AddOnScene()=0; virtual void AddOnScene()=0;

View File

@ -36,6 +36,19 @@
#include "vmaingraphicsview.h" #include "vmaingraphicsview.h"
#include "vmaingraphicsscene.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. * @brief VControlPointSpline constructor.
@ -48,28 +61,22 @@
VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position,
const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit, const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit,
QGraphicsItem *parent) QGraphicsItem *parent)
:QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position), :QGraphicsEllipseItem(parent),
radius(CircleRadius()),
controlLine(nullptr),
indexSpline(indexSpline),
position(position),
patternUnit(patternUnit) patternUnit(patternUnit)
{ {
//create circle Init();
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));
this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
this->setPos(controlPoint); this->setPos(controlPoint);
this->setZValue(100);
QPointF p1, p2; SetCtrlLine(controlPoint, splinePoint);
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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -196,22 +203,44 @@ void VControlPointSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event
emit ShowContextMenu(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 indexSpline index spline in list.
* @param pos position point in spline. * @param pos position point in spline.
* @param controlPoint control point. * @param controlPoint control point.
* @param splinePoint spline point. * @param splinePoint spline point.
*/ */
void VControlPointSpline::RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, void VControlPointSpline::RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos,
const QPointF &controlPoint, const QPointF &splinePoint) const QPointF &controlPoint, const QPointF &splinePoint)
{ {
if (this->indexSpline == indexSpline && this->position == pos) if (this->indexSpline == indexSpline && this->position == pos)
{ {
QPointF p1, p2; this->setPos(controlPoint);
VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); SetCtrlLine(controlPoint, splinePoint);
controlLine->setLine(QLineF(splinePoint-controlPoint, p1));
} }
} }

View File

@ -41,6 +41,8 @@ class VControlPointSpline : public QObject, public QGraphicsEllipseItem
{ {
Q_OBJECT Q_OBJECT
public: public:
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit,
QGraphicsItem * parent = nullptr);
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint,
const QPointF &splinePoint, Unit patternUnit, QGraphicsItem * parent = nullptr); const QPointF &splinePoint, Unit patternUnit, QGraphicsItem * parent = nullptr);
virtual ~VControlPointSpline() Q_DECL_OVERRIDE; virtual ~VControlPointSpline() Q_DECL_OVERRIDE;
@ -63,12 +65,12 @@ signals:
*/ */
void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
public slots: public slots:
void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, void RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
const QPointF &splinePoint); const QPointF &splinePoint);
void setEnabledPoint(bool enable); void setEnabledPoint(bool enable);
protected: protected:
/** @brief radius radius circle. */ /** @brief radius radius circle. */
qreal radius; const qreal radius;
/** @brief controlLine pointer to line control point. */ /** @brief controlLine pointer to line control point. */
QGraphicsLineItem *controlLine; QGraphicsLineItem *controlLine;
@ -88,6 +90,16 @@ private:
SplinePointPosition position; SplinePointPosition position;
Unit patternUnit; 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 #endif // VCONTROLPOINTSPLINE_H

View File

@ -74,7 +74,11 @@ void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
*/ */
void VMainGraphicsScene::mousePressEvent(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); QGraphicsScene::mousePressEvent(event);
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) 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() void VMainGraphicsScene::InitOrigins()
{ {

View File

@ -61,17 +61,17 @@ public slots:
protected: protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
signals: signals:
/** /**
* @brief mouseMove send new mouse position. * @brief mouseMove send new mouse position.
* @param scenePos new mouse position. * @param scenePos new mouse position.
*/ */
void mouseMove(const QPointF &scenePos); void mouseMove(const QPointF &scenePos);
/**
* @brief mousePress send new mouse press position. void MouseLeftPressed();
* @param scenePos new mouse press position. void MouseLeftReleased();
*/
void mousePress(QPointF scenePos);
/** /**
* @brief ChoosedObject send option choosed object. * @brief ChoosedObject send option choosed object.
* @param id object id. * @param id object id.