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.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <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"
|
2013-08-09 08:49:34 +02: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.
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
|
2014-07-24 12:19:41 +02:00
|
|
|
QGraphicsItem *parent)
|
|
|
|
:VAbstractSpline(doc, data, id, parent)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-17 17:50:33 +02:00
|
|
|
sceneType = SceneObject::SplinePath;
|
|
|
|
|
2014-08-17 16:22:30 +02:00
|
|
|
this->setPath(ToolPath());
|
2014-03-26 05:39:07 +01:00
|
|
|
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/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);
|
2013-08-09 08:49:34 +02:00
|
|
|
this->setAcceptHoverEvents(true);
|
|
|
|
|
2014-08-17 16:22:30 +02:00
|
|
|
const VSplinePath *splPath = data->GeometricObject<const 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(),
|
2013-12-29 17:48:57 +01:00
|
|
|
spl.GetP1().toQPointF(), 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);
|
|
|
|
controlPoints.append(controlPoint);
|
|
|
|
|
2014-06-13 19:02:41 +02:00
|
|
|
controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, spl.GetP3(), spl.GetP4().toQPointF(),
|
|
|
|
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);
|
|
|
|
controlPoints.append(controlPoint);
|
|
|
|
}
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
AddToFile();
|
|
|
|
}
|
2013-12-24 12:24:29 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RefreshDataInFile();
|
|
|
|
}
|
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 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);
|
2013-12-29 17:48:57 +01:00
|
|
|
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
2014-02-06 14:57:23 +01:00
|
|
|
dialogTool->SetPath(*splPath);
|
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-02-25 15:02:09 +01:00
|
|
|
void 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());
|
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-06-12 09:22:29 +02:00
|
|
|
Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui);
|
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.
|
|
|
|
*/
|
|
|
|
void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, 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);
|
2014-08-15 19:27:30 +02:00
|
|
|
data->AddCurveLength<VSplineLength>(id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
data->UpdateGObject(id, path);
|
2014-08-15 19:27:30 +02:00
|
|
|
data->AddCurveLength<VSplineLength>(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-06-12 09:22:29 +02:00
|
|
|
VDrawTool::AddRecord(id, Tool::SplinePathTool, doc);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
VToolSplinePath *spl = new VToolSplinePath(doc, data, id, 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);
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->AddTool(id, 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 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-06-11 16:18:50 +02:00
|
|
|
VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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);
|
2014-02-14 16:16:43 +01:00
|
|
|
p.SetAngle2(spl.GetAngle1());
|
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);
|
2014-02-14 16:16:43 +01:00
|
|
|
p.SetAngle2(spl.GetAngle2()-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(),
|
|
|
|
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.
|
|
|
|
* @brief doc dom document container.
|
|
|
|
* @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
|
|
|
{
|
2014-06-11 16:18:50 +02:00
|
|
|
SCASSERT(doc != nullptr)
|
2013-08-09 08:49:34 +02:00
|
|
|
QDomNodeList nodeList = node.childNodes();
|
|
|
|
qint32 num = nodeList.size();
|
2013-11-04 21:35:15 +01:00
|
|
|
for (qint32 i = 0; i < num; ++i)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
QDomElement domElement = nodeList.at(i).toElement();
|
2013-11-04 21:35:15 +01:00
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
VSplinePoint p = path.at(i);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrPSpline, p.P().id());
|
|
|
|
doc->SetAttribute(domElement, AttrKAsm1, p.KAsm1());
|
|
|
|
doc->SetAttribute(domElement, AttrKAsm2, p.KAsm2());
|
|
|
|
doc->SetAttribute(domElement, AttrAngle, p.Angle2());
|
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 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 AddToFile add tag with informations about tool into file.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::AddToFile()
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2014-03-21 11:08:29 +01:00
|
|
|
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrType, ToolType);
|
|
|
|
doc->SetAttribute(domElement, AttrKCurve, splPath.getKCurve());
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
for (qint32 i = 0; i < splPath.CountPoint(); ++i)
|
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
AddPathPoint(domElement, splPath.at(i));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
AddToCalculation(domElement);
|
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()
|
|
|
|
{
|
2014-03-04 13:55:57 +01:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
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-03-04 13:55:57 +01:00
|
|
|
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
|
|
|
RefreshSplinePath(splPath);
|
|
|
|
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.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint)
|
|
|
|
{
|
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()
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const 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);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve()));
|
2014-06-11 16:18:50 +02:00
|
|
|
UpdatePathPoint(doc, domElement, splPath);
|
2014-02-06 14:57:23 +01:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2014-03-26 05:39:07 +01:00
|
|
|
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
2014-08-17 16:22:30 +02:00
|
|
|
this->setPath(ToolPath());
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|