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
|
2013-11-15 13:41:26 +01:00
|
|
|
** @author Roman Telezhinsky <dismine@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"
|
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VToolSplinePath::TagName = QStringLiteral("spline");
|
|
|
|
const QString VToolSplinePath::ToolType = QStringLiteral("path");
|
|
|
|
|
2013-11-06 22:11:12 +01:00
|
|
|
VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation,
|
2013-11-04 21:35:15 +01:00
|
|
|
QGraphicsItem *parent)
|
|
|
|
:VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer<DialogSplinePath>()),
|
|
|
|
controlPoints(QVector<VControlPointSpline *>())
|
|
|
|
{
|
2013-10-21 16:09:05 +02:00
|
|
|
ignoreFullUpdate = true;
|
2013-12-29 17:48:57 +01:00
|
|
|
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
|
2013-08-09 08:49:34 +02:00
|
|
|
QPainterPath path;
|
2013-12-29 17:48:57 +01:00
|
|
|
path.addPath(splPath->GetPath());
|
2013-08-09 08:49:34 +02:00
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
this->setPath(path);
|
2013-10-16 11:17:34 +02:00
|
|
|
this->setPen(QPen(Qt::black, 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);
|
|
|
|
|
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);
|
2013-08-09 08:49:34 +02:00
|
|
|
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::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);
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
controlPoint = new VControlPointSpline(i, SplinePoint::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);
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (typeCreation == Tool::FromGui)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::setDialog()
|
|
|
|
{
|
|
|
|
Q_ASSERT(dialogSplinePath.isNull() == false);
|
2013-12-29 17:48:57 +01:00
|
|
|
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
|
|
|
dialogSplinePath->SetPath(*splPath);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VToolSplinePath::Create(QSharedPointer<DialogSplinePath> &dialog, VMainGraphicsScene *scene,
|
2013-11-04 21:35:15 +01:00
|
|
|
VDomDocument *doc, VContainer *data)
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VSplinePath *path = new VSplinePath(dialog->GetPath());
|
2014-01-30 14:47:41 +01:00
|
|
|
Q_CHECK_PTR(path);
|
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
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
void VToolSplinePath::Create(const qint64 _id, VSplinePath *path, VMainGraphicsScene *scene,
|
2013-09-27 11:17:00 +02:00
|
|
|
VDomDocument *doc, VContainer *data, const Document::Documents &parse,
|
2013-11-06 22:11:12 +01:00
|
|
|
const Tool::Sources &typeCreation)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-13 18:48:36 +02:00
|
|
|
qint64 id = _id;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (typeCreation == Tool::FromGui)
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
id = data->AddGObject(path);
|
|
|
|
data->AddLengthSpline(path->name(), toMM(path->GetLength()));
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
data->UpdateGObject(id, path);
|
|
|
|
data->AddLengthSpline(path->name(), toMM(path->GetLength()));
|
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
|
|
|
}
|
|
|
|
}
|
2013-09-27 11:17:00 +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);
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->AddTool(id, spl);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::FullUpdateFromFile()
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::FullUpdateFromGui(int result)
|
|
|
|
{
|
|
|
|
if (result == QDialog::Accepted)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
VSplinePath splPath = dialogSplinePath->GetPath();
|
2013-11-04 21:35:15 +01:00
|
|
|
for (qint32 i = 1; i<=splPath.Count(); ++i)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
VSpline spl = splPath.GetSpline(i);
|
|
|
|
qint32 j = i*2;
|
|
|
|
disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
controlPoints[j-2]->setPos(spl.GetP2());
|
|
|
|
controlPoints[j-1]->setPos(spl.GetP3());
|
|
|
|
connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(),
|
|
|
|
splPath.getKCurve());
|
2013-08-21 10:03:53 +02:00
|
|
|
CorectControlPoints(spl, splPath, i);
|
|
|
|
CorectControlPoints(spl, splPath, i);
|
2013-08-09 08:49:34 +02:00
|
|
|
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2014-01-20 15:00:38 +01:00
|
|
|
SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve()));
|
2013-08-09 08:49:34 +02:00
|
|
|
UpdatePathPoint(domElement, splPath);
|
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialogSplinePath.clear();
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:40:39 +01:00
|
|
|
void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position,
|
|
|
|
const QPointF &pos)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
2013-12-30 12:28:33 +01:00
|
|
|
VSpline spl = splPath.GetSpline(indexSpline);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (position == SplinePoint::FirstPoint)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2013-08-21 10:03:53 +02:00
|
|
|
CorectControlPoints(spl, splPath, indexSpline);
|
2013-08-09 08:49:34 +02:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2014-01-20 15:00:38 +01:00
|
|
|
SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve()));
|
2013-08-09 08:49:34 +02:00
|
|
|
UpdatePathPoint(domElement, splPath);
|
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePoint::FirstPoint);
|
|
|
|
p.SetAngle(spl.GetAngle1());
|
|
|
|
p.SetKAsm2(spl.GetKasm1());
|
|
|
|
splPath.UpdatePoint(indexSpline, SplinePoint::FirstPoint, p);
|
|
|
|
|
|
|
|
p = splPath.GetSplinePoint(indexSpline, SplinePoint::LastPoint);
|
|
|
|
p.SetAngle(spl.GetAngle2()-180);
|
|
|
|
p.SetKAsm1(spl.GetKasm2());
|
|
|
|
splPath.UpdatePoint(indexSpline, SplinePoint::LastPoint, p);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path)
|
|
|
|
{
|
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)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
VSplinePoint p = path[i];
|
2014-01-20 15:00:38 +01:00
|
|
|
SetAttribute(domElement, AttrPSpline, p.P().id());
|
|
|
|
SetAttribute(domElement, AttrKAsm1, p.KAsm1());
|
|
|
|
SetAttribute(domElement, AttrKAsm2, p.KAsm2());
|
|
|
|
SetAttribute(domElement, AttrAngle, p.Angle2());
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:11:12 +01:00
|
|
|
void VToolSplinePath::ChangedActivDraw(const QString &newName)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-10-28 16:45:27 +01:00
|
|
|
bool selectable = false;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (nameActivDraw == newName)
|
|
|
|
{
|
2013-10-28 16:45:27 +01:00
|
|
|
selectable = true;
|
2013-10-16 11:17:34 +02:00
|
|
|
currentColor = Qt::black;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-28 16:45:27 +01:00
|
|
|
selectable = false;
|
2013-10-16 11:17:34 +02:00
|
|
|
currentColor = Qt::gray;
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
2013-10-28 16:45:27 +01:00
|
|
|
this->setPen(QPen(currentColor, widthHairLine/factor));
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
|
|
|
|
this->setAcceptHoverEvents (selectable);
|
|
|
|
emit setEnabledPoint(selectable);
|
|
|
|
VDrawTool::ChangedActivDraw(newName);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable)
|
|
|
|
{
|
2013-10-28 16:45:27 +01:00
|
|
|
ShowItem(this, id, color, enable);
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::SetFactor(qreal factor)
|
|
|
|
{
|
2013-10-16 11:17:34 +02:00
|
|
|
VDrawTool::SetFactor(factor);
|
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
ContextMenu(dialogSplinePath, this, event);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
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-01-20 15:00:38 +01:00
|
|
|
SetAttribute(domElement, AttrId, id);
|
|
|
|
SetAttribute(domElement, AttrType, ToolType);
|
|
|
|
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)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
AddPathPoint(domElement, splPath[i]);
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
AddToCalculation(domElement);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-12-24 12:24:29 +01:00
|
|
|
void VToolSplinePath::RefreshDataInFile()
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
2013-12-24 12:24:29 +01:00
|
|
|
for (qint32 i = 1; i<=splPath.Count(); ++i)
|
|
|
|
{
|
|
|
|
VSpline spl = splPath.GetSpline(i);
|
|
|
|
qint32 j = i*2;
|
|
|
|
disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
controlPoints[j-2]->setPos(spl.GetP2());
|
|
|
|
controlPoints[j-1]->setPos(spl.GetP3());
|
|
|
|
connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(),
|
|
|
|
splPath.getKCurve());
|
2013-12-24 12:24:29 +01:00
|
|
|
CorectControlPoints(spl, splPath, i);
|
|
|
|
CorectControlPoints(spl, splPath, i);
|
|
|
|
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2014-01-20 15:00:38 +01:00
|
|
|
SetAttribute(domElement, AttrKCurve, QString().setNum(splPath.getKCurve()));
|
2013-12-24 12:24:29 +01:00
|
|
|
UpdatePathPoint(domElement, splPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-20 15:00:38 +01:00
|
|
|
SetAttribute(pathPoint, AttrPSpline, splPoint.P().id());
|
|
|
|
SetAttribute(pathPoint, AttrKAsm1, splPoint.KAsm1());
|
|
|
|
SetAttribute(pathPoint, AttrKAsm2, splPoint.KAsm2());
|
|
|
|
SetAttribute(pathPoint, AttrAngle, splPoint.Angle2());
|
2013-08-09 08:49:34 +02:00
|
|
|
|
|
|
|
domElement.appendChild(pathPoint);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
emit ChoosedTool(id, Scene::SplinePath);
|
|
|
|
}
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
Q_UNUSED(event);
|
2013-10-16 11:17:34 +02:00
|
|
|
this->setPen(QPen(currentColor, widthMainLine/factor));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
Q_UNUSED(event);
|
2013-10-16 11:17:34 +02:00
|
|
|
this->setPen(QPen(currentColor, widthHairLine/factor));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
doc->DecrementReferens(splPath[i].P().id());
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-03 16:13:43 +01:00
|
|
|
QVariant VToolSplinePath::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
if (change == QGraphicsItem::ItemSelectedChange)
|
|
|
|
{
|
|
|
|
if (value == true)
|
|
|
|
{
|
|
|
|
// do stuff if selected
|
|
|
|
this->setFocus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// do stuff if not selected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VToolSplinePath::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
DeleteTool(this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QGraphicsItem::keyReleaseEvent ( event );
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSplinePath::RefreshGeometry()
|
|
|
|
{
|
2013-10-16 11:17:34 +02:00
|
|
|
this->setPen(QPen(currentColor, widthHairLine/factor));
|
2013-12-29 17:48:57 +01:00
|
|
|
const VSplinePath *splPath = VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
|
2013-08-09 08:49:34 +02:00
|
|
|
QPainterPath path;
|
2013-12-29 17:48:57 +01:00
|
|
|
path.addPath(splPath->GetPath());
|
2013-08-09 08:49:34 +02:00
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
this->setPath(path);
|
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();
|
|
|
|
emit RefreshLine(i, SplinePoint::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();
|
|
|
|
emit RefreshLine(i, SplinePoint::LastPoint, controlPoint, splinePoint);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
|
|
qint32 j = i*2;
|
|
|
|
disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
controlPoints[j-2]->setPos(spl.GetP2());
|
|
|
|
controlPoints[j-1]->setPos(spl.GetP3());
|
|
|
|
connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
|
|
|
connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this,
|
|
|
|
&VToolSplinePath::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
}
|