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"
|
2014-02-21 14:04:39 +01:00
|
|
|
#include "../../dialogs/tools/dialogsplinepath.h"
|
2014-06-11 16:18:50 +02:00
|
|
|
#include "../../undocommands/movesplinepath.h"
|
2014-09-07 18:51:22 +02:00
|
|
|
#include "../../visualization/vistoolsplinepath.h"
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2015-04-01 20:21:24 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
2015-06-15 14:02:42 +02:00
|
|
|
# include "../../libs/vmisc/vmath.h"
|
2015-04-01 20:21:24 +02:00
|
|
|
#else
|
|
|
|
# include <QtMath>
|
|
|
|
#endif
|
2015-02-26 21:18:52 +01:00
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VToolSplinePath::ToolType = QStringLiteral("path");
|
|
|
|
|
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.
|
|
|
|
*/
|
2015-02-07 12:17:31 +01:00
|
|
|
VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const QString &color,
|
|
|
|
const Source &typeCreation, QGraphicsItem *parent)
|
2015-02-12 16:42:44 +01:00
|
|
|
:VAbstractSpline(doc, data, id, parent), oldPosition()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-17 17:50:33 +02:00
|
|
|
sceneType = SceneObject::SplinePath;
|
2015-02-18 17:04:27 +01:00
|
|
|
lineColor = color;
|
2014-08-17 17:50:33 +02:00
|
|
|
|
2014-08-17 16:22:30 +02:00
|
|
|
this->setPath(ToolPath());
|
2015-06-15 11:32:27 +02:00
|
|
|
this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
2013-08-09 08:49:34 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
2014-01-03 16:13:43 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
|
2015-02-12 16:42:44 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
2013-08-09 08:49:34 +02:00
|
|
|
this->setAcceptHoverEvents(true);
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(id);
|
2013-12-29 17:48:57 +01:00
|
|
|
for (qint32 i = 1; i<=splPath->Count(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VSpline spl = splPath->GetSpline(i);
|
2014-06-12 09:22:29 +02:00
|
|
|
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(),
|
2015-06-15 11:32:27 +02:00
|
|
|
spl.GetP1().toQPointF(), *data->GetPatternUnit(),
|
|
|
|
this);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
|
|
|
|
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-06-13 19:02:41 +02:00
|
|
|
controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, spl.GetP3(), spl.GetP4().toQPointF(),
|
2015-06-15 11:32:27 +02:00
|
|
|
*data->GetPatternUnit(), this);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
|
|
|
|
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()
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogSplinePath *dialogTool = qobject_cast<DialogSplinePath*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
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);
|
2015-02-06 18:43:31 +01:00
|
|
|
dialogTool->SetColor(lineColor);
|
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.
|
|
|
|
*/
|
2014-08-30 21:58:31 +02:00
|
|
|
VToolSplinePath* VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogSplinePath *dialogTool = qobject_cast<DialogSplinePath*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
VSplinePath *path = new VSplinePath(dialogTool->GetPath());
|
2015-02-07 12:17:31 +01:00
|
|
|
const QString color = dialogTool->GetColor();
|
2013-12-29 17:48:57 +01:00
|
|
|
for (qint32 i = 0; i < path->CountPoint(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
doc->IncrementReferens((*path)[i].P().id());
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
2014-08-30 21:58:31 +02:00
|
|
|
VToolSplinePath* spl = nullptr;
|
2015-02-07 12:17:31 +01:00
|
|
|
spl = Create(0, path, color, scene, doc, data, Document::FullParse, Source::FromGui);
|
2014-08-30 21:58:31 +02:00
|
|
|
if (spl != nullptr)
|
|
|
|
{
|
|
|
|
spl->dialog=dialogTool;
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
*/
|
2015-02-07 12:17:31 +01:00
|
|
|
VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, const QString &color,
|
|
|
|
VMainGraphicsScene *scene, VPattern *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;
|
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);
|
2015-06-02 15:53:19 +02:00
|
|
|
data->AddCurve<VSplinePath>(id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
data->UpdateGObject(id, path);
|
2015-06-02 15:53:19 +02:00
|
|
|
data->AddCurve<VSplinePath>(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
|
|
|
}
|
|
|
|
}
|
2014-08-26 20:31:28 +02:00
|
|
|
VDrawTool::AddRecord(id, Tool::SplinePath, doc);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2015-02-07 12:17:31 +01:00
|
|
|
VToolSplinePath *spl = new VToolSplinePath(doc, data, id, color, typeCreation);
|
2013-08-13 18:48:36 +02:00
|
|
|
scene->addItem(spl);
|
|
|
|
connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2013-10-16 11:17:34 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSplinePath::SetFactor);
|
2014-06-24 10:23:39 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolSplinePath::Disable);
|
2015-02-12 16:42:44 +01:00
|
|
|
connect(scene, &VMainGraphicsScene::EnableToolMove, spl, &VToolSplinePath::EnableToolMove);
|
2015-04-23 17:06:17 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::CurveDetailsMode, spl, &VToolSplinePath::DetailsMode);
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
2014-06-11 16:18:50 +02:00
|
|
|
VSplinePath newSplPath = oldSplPath;
|
|
|
|
VSpline spl = newSplPath.GetSpline(indexSpline);
|
2014-06-12 09:22:29 +02:00
|
|
|
if (position == SplinePointPosition::FirstPoint)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
spl = VSpline(spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve());
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2014-06-11 16:18:50 +02:00
|
|
|
UpdateControlPoints(spl, newSplPath, indexSpline);
|
|
|
|
|
|
|
|
MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id, this->scene());
|
2014-07-16 14:37:38 +02:00
|
|
|
connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VPattern::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);
|
2015-06-02 15:53:19 +02:00
|
|
|
p.SetAngle2(spl.GetStartAngle());
|
2013-08-09 08:49:34 +02:00
|
|
|
p.SetKAsm2(spl.GetKasm1());
|
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);
|
2015-06-02 15:53:19 +02:00
|
|
|
p.SetAngle2(spl.GetEndAngle()-180);
|
2013-08-09 08:49:34 +02:00
|
|
|
p.SetKAsm1(spl.GetKasm2());
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-04 13:55:57 +01:00
|
|
|
void VToolSplinePath::RefreshSplinePath(VSplinePath &splPath)
|
|
|
|
{
|
|
|
|
for (qint32 i = 1; i<=splPath.Count(); ++i)
|
|
|
|
{
|
|
|
|
VSpline spl = splPath.GetSpline(i);
|
|
|
|
qint32 j = i*2;
|
2014-08-09 10:43:01 +02:00
|
|
|
|
|
|
|
controlPoints[j-2]->blockSignals(true);
|
|
|
|
controlPoints[j-1]->blockSignals(true);
|
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
controlPoints[j-2]->setPos(spl.GetP2());
|
|
|
|
controlPoints[j-1]->setPos(spl.GetP3());
|
2014-08-09 10:43:01 +02:00
|
|
|
|
|
|
|
controlPoints[j-2]->blockSignals(false);
|
|
|
|
controlPoints[j-1]->blockSignals(false);
|
2014-03-04 13:55:57 +01:00
|
|
|
|
|
|
|
spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(),
|
2015-02-03 11:17:04 +01:00
|
|
|
splPath.GetKCurve());
|
2014-06-11 16:18:50 +02:00
|
|
|
UpdateControlPoints(spl, splPath, i);
|
2014-03-04 13:55:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief UpdatePathPoint update spline path in pattern file.
|
2014-09-11 18:52:02 +02:00
|
|
|
* @param doc dom document container.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param node tag in file.
|
|
|
|
* @param path spline path.
|
|
|
|
*/
|
2014-06-11 16:18:50 +02:00
|
|
|
void VToolSplinePath::UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-27 14:56:44 +01:00
|
|
|
SCASSERT(doc != nullptr);
|
|
|
|
QDomElement element = node.toElement();
|
|
|
|
if (element.isElement() == false)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-27 14:56:44 +01:00
|
|
|
qDebug()<<"Couldn't convert parent to element.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doc->removeAllChilds(element);
|
|
|
|
for (qint32 i = 0; i < path.CountPoint(); ++i)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
ContextMenu<DialogSplinePath>(this, event);
|
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 RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
|
|
|
|
*/
|
2013-12-24 12:24:29 +01:00
|
|
|
void VToolSplinePath::RefreshDataInFile()
|
|
|
|
{
|
2015-02-11 11:43:50 +01:00
|
|
|
QDomElement domElement = doc->elementById(id);
|
2014-03-04 13:55:57 +01:00
|
|
|
if (domElement.isElement() == false)
|
2013-12-24 12:24:29 +01:00
|
|
|
{
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"Can't find element with id="<<id<<"in pattern file";
|
2014-03-04 13:55:57 +01:00
|
|
|
return;
|
2013-12-24 12:24:29 +01:00
|
|
|
}
|
2014-08-21 14:44:40 +02:00
|
|
|
VSplinePath splPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
2014-03-04 13:55:57 +01:00
|
|
|
RefreshSplinePath(splPath);
|
2015-02-03 11:17:04 +01:00
|
|
|
doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.GetKCurve()));
|
2014-06-11 16:18:50 +02:00
|
|
|
UpdatePathPoint(doc, domElement, splPath);
|
2013-12-24 12:24:29 +01: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-01-27 14:56:44 +01:00
|
|
|
void VToolSplinePath::AddPathPoint(VPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-01-27 14:56:44 +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());
|
|
|
|
doc->SetAttribute(pathPoint, AttrKAsm1, splPoint.KAsm1());
|
|
|
|
doc->SetAttribute(pathPoint, AttrKAsm2, splPoint.KAsm2());
|
|
|
|
doc->SetAttribute(pathPoint, AttrAngle, splPoint.Angle2());
|
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()
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
VSplinePath splPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
2013-11-04 21:35:15 +01:00
|
|
|
for (qint32 i = 0; i < splPath.Count(); ++i)
|
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
doc->DecrementReferens(splPath.at(i).P().id());
|
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)
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogSplinePath *dialogTool = qobject_cast<DialogSplinePath*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
|
|
|
|
VSplinePath splPath = dialogTool->GetPath();
|
2014-03-04 13:55:57 +01:00
|
|
|
RefreshSplinePath(splPath);
|
2015-02-03 11:17:04 +01:00
|
|
|
doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.GetKCurve()));
|
2015-02-06 18:50:33 +01:00
|
|
|
doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor());
|
2014-06-11 16:18:50 +02:00
|
|
|
UpdatePathPoint(doc, 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);
|
|
|
|
SCASSERT(splPath.isNull() == false);
|
|
|
|
|
|
|
|
doc->SetAttribute(tag, AttrType, ToolType);
|
2015-02-03 11:17:04 +01:00
|
|
|
doc->SetAttribute(tag, AttrKCurve, splPath->GetKCurve());
|
2014-08-30 21:58:31 +02:00
|
|
|
|
2014-09-03 13:10:51 +02:00
|
|
|
doc->RemoveAllChild(tag);
|
2014-08-30 21:58:31 +02:00
|
|
|
for (qint32 i = 0; i < splPath->CountPoint(); ++i)
|
|
|
|
{
|
2015-01-27 14:56:44 +01:00
|
|
|
AddPathPoint(doc, tag, splPath->at(i));
|
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)
|
|
|
|
{
|
2015-06-15 15:47:44 +02:00
|
|
|
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
|
2015-02-12 16:42:44 +01:00
|
|
|
oldPosition = event->scenePos();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VAbstractSpline::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
|
|
|
//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)
|
|
|
|
{
|
|
|
|
// Don't need check if left mouse button was pressed. According to the Qt documentation "If you do receive this
|
|
|
|
// event, you can be certain that this item also received a mouse press event, and that this item is the current
|
|
|
|
// mouse grabber.".
|
|
|
|
|
|
|
|
VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
VSplinePath newSplPath = oldSplPath;
|
|
|
|
int indexSpline = oldSplPath.Segment(oldPosition);
|
|
|
|
if (indexSpline == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VSpline spline = newSplPath.GetSpline(indexSpline);
|
|
|
|
const qreal t = spline.ParamT(oldPosition);
|
|
|
|
|
|
|
|
if (qFloor(t) == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
const QPointF p2 = spline.GetP2() + offset0;
|
|
|
|
const QPointF p3 = spline.GetP3() + offset1;
|
|
|
|
|
|
|
|
oldPosition = event->scenePos(); // Now mouse here
|
|
|
|
|
|
|
|
const VSpline spl = VSpline(spline.GetP1(), p2, p3, spline.GetP4(), spline.GetKcurve());
|
|
|
|
|
|
|
|
UpdateControlPoints(spl, newSplPath, indexSpline);
|
|
|
|
|
|
|
|
MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, id, this->scene());
|
|
|
|
connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveSplPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
2015-06-15 15:47:44 +02:00
|
|
|
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
|
2015-02-12 16:42:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VAbstractSpline::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
//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()
|
|
|
|
{
|
|
|
|
if (vis != nullptr)
|
|
|
|
{
|
|
|
|
VisToolSplinePath *visual = qobject_cast<VisToolSplinePath *>(vis);
|
|
|
|
SCASSERT(visual != nullptr);
|
|
|
|
|
|
|
|
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
|
|
|
visual->setPath(*splPath.data());
|
|
|
|
visual->setMode(Mode::Show);
|
|
|
|
visual->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief RefreshGeometry refresh item on scene.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::RefreshGeometry()
|
|
|
|
{
|
2015-04-23 17:06:17 +02:00
|
|
|
if (isHovered || detailsMode)
|
2014-08-19 13:16:00 +02:00
|
|
|
{
|
|
|
|
this->setPath(ToolPath(PathDirection::Show));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->setPath(ToolPath());
|
|
|
|
}
|
2015-06-15 11:32:27 +02:00
|
|
|
this->setPen(QPen(CorrectColor(lineColor),
|
|
|
|
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
|
2013-12-29 17:48:57 +01:00
|
|
|
for (qint32 i = 1; i<=splPath->Count(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VSpline spl = splPath->GetSpline(i);
|
|
|
|
QPointF splinePoint = spl.GetP1().toQPointF();
|
2013-08-09 08:49:34 +02:00
|
|
|
QPointF controlPoint = spl.GetP2();
|
2014-06-12 09:22:29 +02:00
|
|
|
emit RefreshLine(i, SplinePointPosition::FirstPoint, controlPoint, splinePoint);
|
2013-12-29 17:48:57 +01:00
|
|
|
splinePoint = spl.GetP4().toQPointF();
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoint = spl.GetP3();
|
2014-06-12 09:22:29 +02:00
|
|
|
emit RefreshLine(i, SplinePointPosition::LastPoint, controlPoint, splinePoint);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
|
|
qint32 j = i*2;
|
2014-08-09 10:43:01 +02:00
|
|
|
|
|
|
|
controlPoints[j-2]->blockSignals(true);
|
|
|
|
controlPoints[j-1]->blockSignals(true);
|
|
|
|
|
2013-08-13 18:48:36 +02:00
|
|
|
controlPoints[j-2]->setPos(spl.GetP2());
|
|
|
|
controlPoints[j-1]->setPos(spl.GetP3());
|
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
|
|
|
|
2015-05-23 13:40:43 +02:00
|
|
|
SetVisualization();
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|