2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vtoolsplinepath.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-09 08:49:34 +02:00
|
|
|
#include "vtoolsplinepath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QDomElement>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QFlags>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QList>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QUndoStack>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../dialogs/tools/dialogtool.h"
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../../../dialogs/tools/dialogsplinepath.h"
|
|
|
|
#include "../../../undocommands/movesplinepath.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../undocommands/vundocommand.h"
|
|
|
|
#include "../../../visualization/visualization.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../../visualization/path/vistoolsplinepath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
|
|
|
#include "../ifc/xml/vdomdocument.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-03-04 17:08:29 +01:00
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcubicbezierpath.h"
|
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
|
|
|
#include "../vgeometry/vsplinepoint.h"
|
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vwidgets/../vgeometry/vsplinepath.h"
|
|
|
|
#include "../vwidgets/vcontrolpointspline.h"
|
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../vabstracttool.h"
|
|
|
|
#include "../vdrawtool.h"
|
|
|
|
#include "vabstractspline.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
const QString VToolSplinePath::ToolType = QStringLiteral("pathInteractive");
|
|
|
|
const QString VToolSplinePath::OldToolType = QStringLiteral("path");
|
2013-10-29 14:45:07 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolSplinePath constructor.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2016-05-19 12:11:50 +02:00
|
|
|
VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
|
|
|
|
QGraphicsItem *parent)
|
2016-03-05 22:06:54 +01:00
|
|
|
: VAbstractSpline(doc, data, id, parent),
|
|
|
|
oldPosition(),
|
|
|
|
splIndex(-1)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-17 17:50:33 +02:00
|
|
|
sceneType = SceneObject::SplinePath;
|
|
|
|
|
2015-02-12 16:42:44 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
2016-05-08 17:04:18 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(id);
|
2016-03-16 19:07:50 +01:00
|
|
|
for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
const VSpline spl = splPath->GetSpline(i);
|
|
|
|
|
|
|
|
const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl.GetStartAngleFormula());
|
|
|
|
const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl.GetC1LengthFormula());
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
auto *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint,
|
|
|
|
static_cast<QPointF>(spl.GetP2()),
|
2017-06-16 13:53:08 +02:00
|
|
|
static_cast<QPointF>(spl.GetP1()),
|
2017-03-31 16:04:11 +02:00
|
|
|
freeAngle1, freeLength1, this);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
|
2015-04-22 15:13:13 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint);
|
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl.GetEndAngleFormula());
|
|
|
|
const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl.GetC2LengthFormula());
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, static_cast<QPointF>(spl.GetP3()),
|
2017-06-16 13:53:08 +02:00
|
|
|
static_cast<QPointF>(spl.GetP4()), freeAngle2, freeLength2, this);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
|
2015-04-22 15:13:13 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint);
|
|
|
|
}
|
2014-09-07 18:51:22 +02:00
|
|
|
|
2015-04-23 17:06:17 +02:00
|
|
|
ShowHandles(false);
|
2014-09-07 18:51:22 +02:00
|
|
|
|
2015-05-28 12:16:59 +02:00
|
|
|
ToolCreation(typeCreation);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-29 19:02:03 +02:00
|
|
|
VToolSplinePath::~VToolSplinePath()
|
|
|
|
{
|
|
|
|
//Disable cursor-arrow-openhand
|
2015-06-15 15:47:44 +02:00
|
|
|
RestoreOverrideCursor(cursorArrowOpenHand);
|
2015-04-29 19:02:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief setDialog set dialog when user want change tool option.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::setDialog()
|
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not m_dialog.isNull())
|
|
|
|
QSharedPointer<DialogSplinePath> dialogTool = m_dialog.objectCast<DialogSplinePath>();
|
|
|
|
SCASSERT(not dialogTool.isNull())
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
2014-02-06 14:57:23 +01:00
|
|
|
dialogTool->SetPath(*splPath);
|
2016-05-19 12:11:50 +02:00
|
|
|
dialogTool->SetColor(splPath->GetColor());
|
2017-05-16 12:07:53 +02:00
|
|
|
dialogTool->SetPenStyle(splPath->GetPenStyle());
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool from GUI.
|
|
|
|
* @param dialog dialog.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
*/
|
2017-04-15 16:39:59 +02:00
|
|
|
VToolSplinePath* VToolSplinePath::Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
|
|
|
|
VAbstractPattern *doc, VContainer *data)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not dialog.isNull())
|
|
|
|
QSharedPointer<DialogSplinePath> dialogTool = dialog.objectCast<DialogSplinePath>();
|
|
|
|
SCASSERT(not dialogTool.isNull())
|
2014-02-06 14:57:23 +01:00
|
|
|
VSplinePath *path = new VSplinePath(dialogTool->GetPath());
|
2016-03-16 19:07:50 +01:00
|
|
|
for (qint32 i = 0; i < path->CountPoints(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-02-02 14:38:30 +01:00
|
|
|
doc->IncrementReferens((*path)[i].P().getIdTool());
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
2017-05-16 12:07:53 +02:00
|
|
|
|
|
|
|
path->SetColor(dialogTool->GetColor());
|
|
|
|
path->SetPenStyle(dialogTool->GetPenStyle());
|
|
|
|
|
|
|
|
VToolSplinePath* spl = Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui);
|
2014-08-30 21:58:31 +02:00
|
|
|
if (spl != nullptr)
|
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
spl->m_dialog = dialogTool;
|
2014-08-30 21:58:31 +02:00
|
|
|
}
|
|
|
|
return spl;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool.
|
|
|
|
* @param _id tool id, 0 if tool doesn't exist yet.
|
|
|
|
* @param path spline path.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
*/
|
2017-05-16 12:07:53 +02:00
|
|
|
VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene,
|
|
|
|
VAbstractPattern *doc, VContainer *data, const Document &parse,
|
|
|
|
const Source &typeCreation)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = _id;
|
2017-05-16 12:07:53 +02:00
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
id = data->AddGObject(path);
|
2016-04-01 23:15:04 +02:00
|
|
|
data->AddCurveWithSegments(data->GeometricObject<VAbstractCubicBezierPath>(id), id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
data->UpdateGObject(id, path);
|
2016-04-01 23:15:04 +02:00
|
|
|
data->AddCurveWithSegments(data->GeometricObject<VAbstractCubicBezierPath>(id), id);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
2017-02-13 07:55:42 +01:00
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2017-02-13 07:55:42 +01:00
|
|
|
VDrawTool::AddRecord(id, Tool::SplinePath, doc);
|
2016-05-19 12:11:50 +02:00
|
|
|
VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation);
|
2013-08-13 18:48:36 +02:00
|
|
|
scene->addItem(spl);
|
2016-03-31 16:01:41 +02:00
|
|
|
InitSplinePathToolConnections(scene, spl);
|
2017-03-23 09:25:46 +01:00
|
|
|
VAbstractPattern::AddTool(id, spl);
|
2014-08-30 21:58:31 +02:00
|
|
|
return spl;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
2014-08-30 21:58:31 +02:00
|
|
|
return nullptr;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolSplinePath *VToolSplinePath::Create(const quint32 _id, const QVector<quint32> &points, QVector<QString> &a1,
|
|
|
|
QVector<QString> &a2, QVector<QString> &l1, QVector<QString> &l2,
|
2017-05-16 12:07:53 +02:00
|
|
|
const QString &color, const QString &penStyle, quint32 duplicate,
|
|
|
|
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
|
|
|
|
const Document &parse, const Source &typeCreation)
|
2016-03-04 17:08:29 +01:00
|
|
|
{
|
|
|
|
auto path = new VSplinePath();
|
|
|
|
|
2017-03-22 16:04:32 +01:00
|
|
|
if (duplicate > 0)
|
|
|
|
{
|
|
|
|
path->SetDuplicate(duplicate);
|
|
|
|
}
|
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
for (int i = 0; i < points.size(); ++i)
|
|
|
|
{
|
|
|
|
const qreal calcAngle1 = CheckFormula(_id, a1[i], data);
|
|
|
|
const qreal calcAngle2 = CheckFormula(_id, a2[i], data);
|
|
|
|
|
|
|
|
const qreal calcLength1 = qApp->toPixel(CheckFormula(_id, l1[i], data));
|
|
|
|
const qreal calcLength2 = qApp->toPixel(CheckFormula(_id, l2[i], data));
|
|
|
|
|
|
|
|
const auto p = *data->GeometricObject<VPointF>(points.at(i));
|
|
|
|
|
|
|
|
path->append(VSplinePoint(p, calcAngle1, a1.at(i), calcAngle2, a2.at(i), calcLength1, l1.at(i), calcLength2,
|
|
|
|
l2.at(i)));
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
path->SetColor(color);
|
|
|
|
path->SetPenStyle(penStyle);
|
|
|
|
|
|
|
|
return VToolSplinePath::Create(_id, path, scene, doc, data, parse, typeCreation);
|
2016-03-04 17:08:29 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief ControlPointChangePosition handle change position control point.
|
|
|
|
* @param indexSpline position spline in spline list.
|
|
|
|
* @param position position point in spline.
|
|
|
|
* @param pos new position.
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePointPosition &position,
|
2013-11-07 15:40:39 +01:00
|
|
|
const QPointF &pos)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
const VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
2014-06-11 16:18:50 +02:00
|
|
|
VSplinePath newSplPath = oldSplPath;
|
2016-03-04 17:08:29 +01:00
|
|
|
const VSpline spl = CorrectedSpline(newSplPath.GetSpline(indexSpline), position, pos);
|
2014-06-11 16:18:50 +02:00
|
|
|
UpdateControlPoints(spl, newSplPath, indexSpline);
|
|
|
|
|
2016-05-20 14:20:08 +02:00
|
|
|
MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id);
|
2015-06-16 17:01:17 +02:00
|
|
|
connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
2014-06-11 16:18:50 +02:00
|
|
|
qApp->getUndoStack()->push(moveSplPath);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2015-02-12 17:10:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::EnableToolMove(bool move)
|
|
|
|
{
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, move);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief UpdateControlPoints update position points control points in file.
|
|
|
|
* @param spl spline what was changed.
|
|
|
|
* @param splPath spline path.
|
|
|
|
* @param indexSpline index spline in spline path.
|
|
|
|
*/
|
2014-06-11 16:25:38 +02:00
|
|
|
void VToolSplinePath::UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePointPosition::FirstPoint);
|
2016-03-04 17:08:29 +01:00
|
|
|
p.SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula());
|
2016-03-05 22:06:54 +01:00
|
|
|
p.SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula());
|
2014-06-12 09:22:29 +02:00
|
|
|
splPath.UpdatePoint(indexSpline, SplinePointPosition::FirstPoint, p);
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
p = splPath.GetSplinePoint(indexSpline, SplinePointPosition::LastPoint);
|
2016-03-04 17:08:29 +01:00
|
|
|
p.SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula());
|
|
|
|
p.SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula());
|
2014-06-12 09:22:29 +02:00
|
|
|
splPath.UpdatePoint(indexSpline, SplinePointPosition::LastPoint, p);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
void VToolSplinePath::SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path)
|
2014-03-04 13:55:57 +01:00
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
doc->SetAttribute(domElement, AttrType, ToolType);
|
2014-08-09 10:43:01 +02:00
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
if (path.GetDuplicate() > 0)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domElement, AttrDuplicate, path.GetDuplicate());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (domElement.hasAttribute(AttrDuplicate))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrDuplicate);
|
|
|
|
}
|
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
if (domElement.hasAttribute(AttrKCurve))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrKCurve);
|
2014-03-04 13:55:57 +01:00
|
|
|
}
|
2016-03-04 17:08:29 +01:00
|
|
|
|
|
|
|
UpdatePathPoints(doc, domElement, path);
|
2014-03-04 13:55:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
2016-03-04 17:08:29 +01:00
|
|
|
* @brief UpdatePathPoints update spline path in pattern file.
|
2014-09-11 18:52:02 +02:00
|
|
|
* @param doc dom document container.
|
2016-05-03 18:50:37 +02:00
|
|
|
* @param element tag in file.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param path spline path.
|
|
|
|
*/
|
2016-03-04 17:08:29 +01:00
|
|
|
void VToolSplinePath::UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
VDomDocument::RemoveAllChildren(element);
|
2016-03-16 19:07:50 +01:00
|
|
|
for (qint32 i = 0; i < path.CountPoints(); ++i)
|
2015-01-27 14:56:44 +01:00
|
|
|
{
|
|
|
|
AddPathPoint(doc, element, path.at(i));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-01 18:39:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSplinePath VToolSplinePath::getSplinePath() const
|
|
|
|
{
|
|
|
|
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
return *splPath.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::setSplinePath(const VSplinePath &splPath)
|
|
|
|
{
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
QSharedPointer<VSplinePath> splinePath = qSharedPointerDynamicCast<VSplinePath>(obj);
|
|
|
|
*splinePath.data() = splPath;
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
2014-09-03 15:52:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::ShowVisualization(bool show)
|
|
|
|
{
|
2015-05-23 15:10:08 +02:00
|
|
|
ShowToolVisualization<VisToolSplinePath>(show);
|
2014-09-03 15:52:16 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief contextMenuEvent handle context menu events.
|
|
|
|
* @param event context menu event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ContextMenu<DialogSplinePath>(this, event);
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(e)
|
2015-11-02 17:25:29 +01:00
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief AddPathPoint write path point to pattern file.
|
|
|
|
* @param domElement dom element.
|
|
|
|
* @param splPoint spline path point.
|
|
|
|
*/
|
2015-06-16 10:30:25 +02:00
|
|
|
void VToolSplinePath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(doc != nullptr)
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement pathPoint = doc->createElement(AttrPathPoint);
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(pathPoint, AttrPSpline, splPoint.P().id());
|
2016-03-04 17:08:29 +01:00
|
|
|
doc->SetAttribute(pathPoint, AttrLength1, splPoint.Length1Formula());
|
|
|
|
doc->SetAttribute(pathPoint, AttrLength2, splPoint.Length2Formula());
|
|
|
|
doc->SetAttribute(pathPoint, AttrAngle1, splPoint.Angle1Formula());
|
|
|
|
doc->SetAttribute(pathPoint, AttrAngle2, splPoint.Angle2Formula());
|
|
|
|
|
|
|
|
if (domElement.hasAttribute(AttrKAsm1))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrKAsm1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (domElement.hasAttribute(AttrKAsm2))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrKAsm2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (domElement.hasAttribute(AttrAngle))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrAngle);
|
|
|
|
}
|
2013-08-09 08:49:34 +02:00
|
|
|
|
|
|
|
domElement.appendChild(pathPoint);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief RemoveReferens decrement value of reference.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::RemoveReferens()
|
|
|
|
{
|
2016-03-18 22:11:14 +01:00
|
|
|
const QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
for (qint32 i = 0; i < splPath->CountSubSpl(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-18 22:11:14 +01:00
|
|
|
doc->DecrementReferens(splPath->at(i).P().getIdTool());
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief SaveDialog save options into file after change in dialog.
|
|
|
|
*/
|
2014-02-06 14:57:23 +01:00
|
|
|
void VToolSplinePath::SaveDialog(QDomElement &domElement)
|
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not m_dialog.isNull())
|
|
|
|
QSharedPointer<DialogSplinePath> dialogTool = m_dialog.objectCast<DialogSplinePath>();
|
|
|
|
SCASSERT(not dialogTool.isNull())
|
2014-02-06 14:57:23 +01:00
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
const VSplinePath splPath = dialogTool->GetPath();
|
2016-03-16 19:07:50 +01:00
|
|
|
for (qint32 i = 1; i <= splPath.CountSubSpl(); ++i)
|
2016-03-04 17:08:29 +01:00
|
|
|
{
|
|
|
|
VSpline spl = splPath.GetSpline(i);
|
|
|
|
qint32 j = i*2;
|
|
|
|
|
|
|
|
controlPoints[j-2]->blockSignals(true);
|
|
|
|
controlPoints[j-1]->blockSignals(true);
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
controlPoints[j-2]->setPos(static_cast<QPointF>(spl.GetP2()));
|
|
|
|
controlPoints[j-1]->setPos(static_cast<QPointF>(spl.GetP3()));
|
2016-03-04 17:08:29 +01:00
|
|
|
|
|
|
|
controlPoints[j-2]->blockSignals(false);
|
|
|
|
controlPoints[j-1]->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
2015-02-06 18:50:33 +01:00
|
|
|
doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor());
|
2017-05-16 12:07:53 +02:00
|
|
|
doc->SetAttribute(domElement, AttrPenStyle, dialogTool->GetPenStyle());
|
2016-03-04 17:08:29 +01:00
|
|
|
SetSplinePathAttributes(domElement, splPath);
|
2014-02-06 14:57:23 +01:00
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
2015-05-28 14:13:37 +02:00
|
|
|
VAbstractSpline::SaveOptions(tag, obj);
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
QSharedPointer<VSplinePath> splPath = qSharedPointerDynamicCast<VSplinePath>(obj);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(splPath.isNull() == false)
|
2014-08-30 21:58:31 +02:00
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
SetSplinePathAttributes(tag, *splPath);
|
2014-08-30 21:58:31 +02:00
|
|
|
}
|
|
|
|
|
2015-02-12 16:42:44 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
|
|
|
oldPosition = event->scenePos();
|
2016-03-05 22:06:54 +01:00
|
|
|
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
splIndex = splPath->Segment(oldPosition);
|
|
|
|
if (IsMovable(splIndex))
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
|
|
|
|
event->accept();
|
|
|
|
}
|
2015-02-12 16:42:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VAbstractSpline::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
oldPosition = event->scenePos();
|
2015-02-12 16:42:44 +01:00
|
|
|
//Disable cursor-arrow-closehand
|
2015-06-15 15:47:44 +02:00
|
|
|
RestoreOverrideCursor(cursorArrowCloseHand);
|
2015-02-12 16:42:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VAbstractSpline::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
// Don't need to check if left mouse button was pressed. According to the Qt documentation "If you do receive this
|
2015-02-12 16:42:44 +01:00
|
|
|
// event, you can be certain that this item also received a mouse press event, and that this item is the current
|
|
|
|
// mouse grabber.".
|
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
if (IsMovable(splIndex))
|
2015-02-12 16:42:44 +01:00
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
VSplinePath newSplPath = oldSplPath;
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
VSpline spline = newSplPath.GetSpline(splIndex);
|
|
|
|
const qreal t = spline.ParamT(oldPosition);
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
if (qFloor(t) == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
// Magic Bezier Drag Equations follow!
|
|
|
|
// "weight" describes how the influence of the drag should be distributed
|
|
|
|
// among the handles; 0 = front handle only, 1 = back handle only.
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
double weight;
|
|
|
|
if (t <= 1.0 / 6.0)
|
|
|
|
{
|
|
|
|
weight = 0;
|
|
|
|
}
|
|
|
|
else if (t <= 0.5)
|
|
|
|
{
|
|
|
|
weight = (pow((6 * t - 1) / 2.0, 3)) / 2;
|
|
|
|
}
|
|
|
|
else if (t <= 5.0 / 6.0)
|
|
|
|
{
|
|
|
|
weight = (1 - pow((6 * (1-t) - 1) / 2.0, 3)) / 2 + 0.5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
weight = 1;
|
|
|
|
}
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
const QPointF delta = event->scenePos() - oldPosition;
|
|
|
|
const QPointF offset0 = ((1-weight)/(3*t*(1-t)*(1-t))) * delta;
|
|
|
|
const QPointF offset1 = (weight/(3*t*t*(1-t))) * delta;
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p2 = static_cast<QPointF>(spline.GetP2()) + offset0;
|
|
|
|
const QPointF p3 = static_cast<QPointF>(spline.GetP3()) + offset1;
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
oldPosition = event->scenePos(); // Now mouse here
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
const VSpline spl = VSpline(spline.GetP1(), p2, p3, spline.GetP4());
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
UpdateControlPoints(spl, newSplPath, splIndex);
|
2015-02-12 16:42:44 +01:00
|
|
|
|
2016-05-20 14:20:08 +02:00
|
|
|
MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id);
|
2016-03-05 22:06:54 +01:00
|
|
|
connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveSplPath);
|
2016-01-15 13:57:23 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
// Each time we move something we call recalculation scene rect. In some cases this can cause moving
|
|
|
|
// objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move.
|
|
|
|
static bool changeFinished = true;
|
|
|
|
if (changeFinished)
|
|
|
|
{
|
|
|
|
changeFinished = false;
|
2016-01-15 13:57:23 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
const QList<QGraphicsView *> viewList = scene()->views();
|
|
|
|
if (not viewList.isEmpty())
|
2016-01-15 13:57:23 +01:00
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
if (QGraphicsView *view = viewList.at(0))
|
|
|
|
{
|
|
|
|
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(currentScene)
|
2016-03-05 22:06:54 +01:00
|
|
|
const QPointF cursorPosition = currentScene->getScenePos();
|
|
|
|
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
|
|
|
|
}
|
2016-01-15 13:57:23 +01:00
|
|
|
}
|
2016-03-05 22:06:54 +01:00
|
|
|
changeFinished = true;
|
|
|
|
}
|
2016-01-15 13:57:23 +01:00
|
|
|
}
|
2015-02-12 16:42:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
oldPosition = event->scenePos();
|
|
|
|
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
splIndex = splPath->Segment(oldPosition);
|
|
|
|
if (IsMovable(splIndex))
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
|
|
|
|
}
|
2015-02-12 16:42:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VAbstractSpline::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
oldPosition = event->scenePos();
|
2015-02-12 16:42:44 +01:00
|
|
|
//Disable cursor-arrow-openhand
|
2015-06-15 15:47:44 +02:00
|
|
|
RestoreOverrideCursor(cursorArrowOpenHand);
|
2015-02-12 16:42:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VAbstractSpline::hoverLeaveEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:40:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::SetVisualization()
|
|
|
|
{
|
2016-09-24 15:09:09 +02:00
|
|
|
if (not vis.isNull())
|
2015-05-23 13:40:43 +02:00
|
|
|
{
|
|
|
|
VisToolSplinePath *visual = qobject_cast<VisToolSplinePath *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(visual != nullptr)
|
2015-05-23 13:40:43 +02:00
|
|
|
|
|
|
|
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
visual->setPath(*splPath.data());
|
2017-05-16 12:07:53 +02:00
|
|
|
visual->setLineStyle(LineStyleToPenStyle(splPath->GetPenStyle()));
|
2016-02-12 19:10:01 +01:00
|
|
|
visual->SetMode(Mode::Show);
|
2015-05-23 13:40:43 +02:00
|
|
|
visual->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VToolSplinePath::IsMovable(int index) const
|
|
|
|
{
|
|
|
|
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
|
|
|
|
//index == -1 - can delete, but decided to left
|
2016-03-16 19:07:50 +01:00
|
|
|
if (index == -1 || index < 1 || index > splPath->CountSubSpl())
|
2016-03-05 22:06:54 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VSplinePoint p1 = splPath->GetSplinePoint(index, SplinePointPosition::FirstPoint);
|
|
|
|
const VSplinePoint p2 = splPath->GetSplinePoint(index, SplinePointPosition::LastPoint);
|
|
|
|
|
|
|
|
return p1.IsMovable() && p2.IsMovable();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-16 13:53:08 +02:00
|
|
|
void VToolSplinePath::RefreshCtrlPoints()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-01-15 13:57:09 +01:00
|
|
|
// Very important to disable control points. Without it the pogram can't move the curve.
|
2016-02-12 19:10:01 +01:00
|
|
|
foreach (auto *point, controlPoints)
|
2016-01-15 13:57:09 +01:00
|
|
|
{
|
|
|
|
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:11:50 +02:00
|
|
|
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2016-03-16 19:07:50 +01:00
|
|
|
for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-02-12 19:10:01 +01:00
|
|
|
const qint32 j = i*2;
|
2014-08-09 10:43:01 +02:00
|
|
|
|
|
|
|
controlPoints[j-2]->blockSignals(true);
|
|
|
|
controlPoints[j-1]->blockSignals(true);
|
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
const auto spl = splPath->GetSpline(i);
|
|
|
|
|
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl.GetStartAngleFormula());
|
|
|
|
const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl.GetC1LengthFormula());
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
const auto splinePoint = spl.GetP1();
|
2017-03-31 16:04:11 +02:00
|
|
|
controlPoints[j-2]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, static_cast<QPointF>(spl.GetP2()),
|
|
|
|
static_cast<QPointF>(splinePoint), freeAngle1, freeLength1);
|
2016-02-12 19:10:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl.GetEndAngleFormula());
|
|
|
|
const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl.GetC2LengthFormula());
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
const auto splinePoint = spl.GetP4();
|
2017-03-31 16:04:11 +02:00
|
|
|
controlPoints[j-1]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, static_cast<QPointF>(spl.GetP3()),
|
|
|
|
static_cast<QPointF>(splinePoint), freeAngle2, freeLength2);
|
2016-02-12 19:10:01 +01:00
|
|
|
}
|
2014-08-09 10:43:01 +02:00
|
|
|
|
|
|
|
controlPoints[j-2]->blockSignals(false);
|
|
|
|
controlPoints[j-1]->blockSignals(false);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
2014-09-07 18:51:22 +02:00
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
foreach (auto *point, controlPoints)
|
2016-01-15 13:57:09 +01:00
|
|
|
{
|
|
|
|
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
}
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|