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 vmodelingspline.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-09-10 14:29:06 +02:00
|
|
|
#include "vmodelingspline.h"
|
2013-11-06 18:06:00 +01:00
|
|
|
#include "../../geometry/vspline.h"
|
2013-08-20 12:26:02 +02:00
|
|
|
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VModelingSpline::TagName = QStringLiteral("spline");
|
|
|
|
const QString VModelingSpline::ToolType = QStringLiteral("simple");
|
|
|
|
|
2013-11-06 22:11:12 +01:00
|
|
|
VModelingSpline::VModelingSpline(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation,
|
2013-11-04 21:35:15 +01:00
|
|
|
QGraphicsItem *parent)
|
|
|
|
:VModelingTool(doc, data, id), QGraphicsPathItem(parent),
|
|
|
|
dialogSpline(QSharedPointer<DialogSpline>()), controlPoints(QVector<VControlPointSpline *>())
|
|
|
|
{
|
2013-10-21 16:09:05 +02:00
|
|
|
ignoreFullUpdate = true;
|
2013-09-10 14:29:06 +02:00
|
|
|
VSpline spl = data->GetModelingSpline(id);
|
2013-08-05 10:37:56 +02:00
|
|
|
QPainterPath path;
|
|
|
|
path.addPath(spl.GetPath());
|
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
this->setPath(path);
|
|
|
|
this->setPen(QPen(Qt::black, widthHairLine));
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
this->setAcceptHoverEvents(true);
|
|
|
|
|
2013-08-09 08:49:34 +02:00
|
|
|
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePoint::FirstPoint, spl.GetP2(),
|
2013-08-13 18:48:36 +02:00
|
|
|
spl.GetPointP1().toQPointF(), this);
|
2013-08-05 10:37:56 +02:00
|
|
|
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
|
|
|
connect(this, &VModelingSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
|
|
|
|
connect(this, &VModelingSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint1);
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2013-08-09 08:49:34 +02:00
|
|
|
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePoint::LastPoint, spl.GetP3(),
|
2013-08-13 18:48:36 +02:00
|
|
|
spl.GetPointP4().toQPointF(), this);
|
2013-08-05 10:37:56 +02:00
|
|
|
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
|
|
|
connect(this, &VModelingSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine);
|
|
|
|
connect(this, &VModelingSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint2);
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
if (typeCreation == Tool::FromGui)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::setDialog()
|
|
|
|
{
|
|
|
|
Q_ASSERT(dialogSpline.isNull() == false);
|
|
|
|
VSpline spl = VAbstractTool::data.GetModelingSpline(id);
|
|
|
|
dialogSpline->setP1(spl.GetP1());
|
|
|
|
dialogSpline->setP4(spl.GetP4());
|
|
|
|
dialogSpline->setAngle1(spl.GetAngle1());
|
|
|
|
dialogSpline->setAngle2(spl.GetAngle2());
|
|
|
|
dialogSpline->setKAsm1(spl.GetKasm1());
|
|
|
|
dialogSpline->setKAsm2(spl.GetKasm2());
|
|
|
|
dialogSpline->setKCurve(spl.GetKcurve());
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
VModelingSpline *VModelingSpline::Create(QSharedPointer<DialogSpline> &dialog, VDomDocument *doc, VContainer *data)
|
|
|
|
{
|
2013-08-13 18:48:36 +02:00
|
|
|
qint64 p1 = dialog->getP1();
|
|
|
|
qint64 p4 = dialog->getP4();
|
|
|
|
qreal kAsm1 = dialog->getKAsm1();
|
|
|
|
qreal kAsm2 = dialog->getKAsm2();
|
|
|
|
qreal angle1 = dialog->getAngle1();
|
|
|
|
qreal angle2 = dialog->getAngle2();
|
|
|
|
qreal kCurve = dialog->getKCurve();
|
2013-09-10 14:29:06 +02:00
|
|
|
return Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, doc, data, Document::FullParse,
|
|
|
|
Tool::FromGui);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingSpline *VModelingSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4,
|
|
|
|
const qreal &kAsm1, const qreal kAsm2, const qreal &angle1,
|
|
|
|
const qreal &angle2, const qreal &kCurve, VDomDocument *doc,
|
2013-11-07 15:44:55 +01:00
|
|
|
VContainer *data, const Document::Documents &parse,
|
|
|
|
const Tool::Sources &typeCreation)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
VModelingSpline *spl = 0;
|
|
|
|
VSpline spline = VSpline(data->DataModelingPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve);
|
2013-08-13 18:48:36 +02:00
|
|
|
qint64 id = _id;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (typeCreation == Tool::FromGui)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
id = data->AddModelingSpline(spline);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
data->UpdateModelingSpline(id, spline);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
2013-09-11 16:14:21 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
2013-11-12 14:04:18 +01:00
|
|
|
data->AddLengthSpline(spline.name(), toMM(spline.GetLength()));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
spl = new VModelingSpline(doc, data, id, typeCreation);
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->AddTool(id, spl);
|
|
|
|
doc->IncrementReferens(p1);
|
|
|
|
doc->IncrementReferens(p4);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
return spl;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::FullUpdateFromFile()
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::FullUpdateFromGui(int result)
|
|
|
|
{
|
|
|
|
if (result == QDialog::Accepted)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
VSpline spl = VSpline (VAbstractTool::data.DataModelingPoints(), dialogSpline->getP1(),
|
2013-08-05 10:37:56 +02:00
|
|
|
dialogSpline->getP4(), dialogSpline->getAngle1(), dialogSpline->getAngle2(),
|
|
|
|
dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve());
|
|
|
|
|
2013-08-09 08:49:34 +02:00
|
|
|
disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints[0]->setPos(spl.GetP2());
|
|
|
|
controlPoints[1]->setPos(spl.GetP3());
|
|
|
|
connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
spl = VSpline (VAbstractTool::data.DataModelingPoints(), dialogSpline->getP1(),
|
|
|
|
controlPoints[0]->pos(), controlPoints[1]->pos(), dialogSpline->getP4(),
|
|
|
|
dialogSpline->getKCurve());
|
2013-08-05 10:37:56 +02:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2013-10-29 14:45:07 +01:00
|
|
|
domElement.setAttribute(AttrPoint1, QString().setNum(spl.GetP1()));
|
|
|
|
domElement.setAttribute(AttrPoint4, QString().setNum(spl.GetP4()));
|
|
|
|
domElement.setAttribute(AttrAngle1, QString().setNum(spl.GetAngle1()));
|
|
|
|
domElement.setAttribute(AttrAngle2, QString().setNum(spl.GetAngle2()));
|
|
|
|
domElement.setAttribute(AttrKAsm1, QString().setNum(spl.GetKasm1()));
|
|
|
|
domElement.setAttribute(AttrKAsm2, QString().setNum(spl.GetKasm2()));
|
|
|
|
domElement.setAttribute(AttrKCurve, QString().setNum(spl.GetKcurve()));
|
2013-08-05 10:37:56 +02:00
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialogSpline.clear();
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
void VModelingSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position,
|
2013-11-07 15:40:39 +01:00
|
|
|
const QPointF &pos)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
Q_UNUSED(indexSpline);
|
2013-09-10 14:29:06 +02:00
|
|
|
VSpline spl = VAbstractTool::data.GetModelingSpline(id);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (position == SplinePoint::FirstPoint)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve());
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2013-10-29 14:45:07 +01:00
|
|
|
domElement.setAttribute(AttrAngle1, QString().setNum(spl.GetAngle1()));
|
|
|
|
domElement.setAttribute(AttrAngle2, QString().setNum(spl.GetAngle2()));
|
|
|
|
domElement.setAttribute(AttrKAsm1, QString().setNum(spl.GetKasm1()));
|
|
|
|
domElement.setAttribute(AttrKAsm2, QString().setNum(spl.GetKasm2()));
|
|
|
|
domElement.setAttribute(AttrKCurve, QString().setNum(spl.GetKcurve()));
|
2013-08-05 10:37:56 +02:00
|
|
|
emit FullUpdateTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2013-08-13 18:48:36 +02:00
|
|
|
ContextMenu(dialogSpline, this, event);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::AddToFile()
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
VSpline spl = VAbstractTool::data.GetModelingSpline(id);
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
|
|
|
|
|
|
|
AddAttribute(domElement, AttrId, id);
|
|
|
|
AddAttribute(domElement, AttrType, ToolType);
|
|
|
|
AddAttribute(domElement, AttrPoint1, spl.GetP1());
|
|
|
|
AddAttribute(domElement, AttrPoint4, spl.GetP4());
|
|
|
|
AddAttribute(domElement, AttrAngle1, spl.GetAngle1());
|
|
|
|
AddAttribute(domElement, AttrAngle2, spl.GetAngle2());
|
|
|
|
AddAttribute(domElement, AttrKAsm1, spl.GetKasm1());
|
|
|
|
AddAttribute(domElement, AttrKAsm2, spl.GetKasm2());
|
|
|
|
AddAttribute(domElement, AttrKCurve, spl.GetKcurve());
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
AddToModeling(domElement);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
emit ChoosedTool(id, Scene::Spline);
|
|
|
|
}
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
Q_UNUSED(event);
|
2013-08-15 22:39:00 +02:00
|
|
|
this->setPen(QPen(currentColor, widthMainLine));
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
Q_UNUSED(event);
|
2013-08-15 22:39:00 +02:00
|
|
|
this->setPen(QPen(currentColor, widthHairLine));
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::RemoveReferens()
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
VSpline spl = VAbstractTool::data.GetModelingSpline(id);
|
|
|
|
doc->DecrementReferens(spl.GetP1());
|
|
|
|
doc->DecrementReferens(spl.GetP4());
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VModelingSpline::RefreshGeometry()
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
VSpline spl = VAbstractTool::data.GetModelingSpline(id);
|
2013-08-05 10:37:56 +02:00
|
|
|
QPainterPath path;
|
|
|
|
path.addPath(spl.GetPath());
|
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
this->setPath(path);
|
2013-09-10 14:29:06 +02:00
|
|
|
QPointF splinePoint = VAbstractTool::data.GetModelingPoint(spl.GetP1()).toQPointF();
|
2013-08-05 10:37:56 +02:00
|
|
|
QPointF controlPoint = spl.GetP2();
|
2013-08-09 08:49:34 +02:00
|
|
|
emit RefreshLine(1, SplinePoint::FirstPoint, controlPoint, splinePoint);
|
2013-09-10 14:29:06 +02:00
|
|
|
splinePoint = VAbstractTool::data.GetModelingPoint(spl.GetP4()).toQPointF();
|
2013-08-05 10:37:56 +02:00
|
|
|
controlPoint = spl.GetP3();
|
2013-08-09 08:49:34 +02:00
|
|
|
emit RefreshLine(1, SplinePoint::LastPoint, controlPoint, splinePoint);
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
|
|
disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-13 18:48:36 +02:00
|
|
|
disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-13 18:48:36 +02:00
|
|
|
controlPoints[0]->setPos(spl.GetP2());
|
|
|
|
controlPoints[1]->setPos(spl.GetP3());
|
|
|
|
connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-13 18:48:36 +02:00
|
|
|
connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
|
2013-09-10 14:29:06 +02:00
|
|
|
&VModelingSpline::ControlPointChangePosition);
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|