2013-12-18 12:13:32 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtoolcutspline.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-12-18 12:13:32 +01:00
|
|
|
** @date 15 12, 2013
|
|
|
|
**
|
|
|
|
** @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-12-18 12:13:32 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vtoolcutspline.h"
|
|
|
|
#include "../../container/calculator.h"
|
2014-02-21 14:04:39 +01:00
|
|
|
#include "../../dialogs/tools/dialogcutspline.h"
|
2015-05-07 14:31:53 +02:00
|
|
|
#include "../../libs/vgeometry/vpointf.h"
|
2014-09-06 14:47:25 +02:00
|
|
|
#include "../../visualization/vistoolcutspline.h"
|
2015-05-07 14:31:53 +02:00
|
|
|
#include "../../libs/vgeometry/vspline.h"
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-06-26 12:26:13 +02:00
|
|
|
const QString VToolCutSpline::ToolType = QStringLiteral("cutSpline");
|
2013-12-18 12:13:32 +01:00
|
|
|
const QString VToolCutSpline::AttrSpline = QStringLiteral("spline");
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolCutSpline constructor.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param formula string with formula length first spline.
|
|
|
|
* @param splineId id spline in data container.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
VToolCutSpline::VToolCutSpline(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
|
|
|
|
const quint32 &splineId, const quint32 &spl1id, const quint32 &spl2id,
|
2015-02-08 11:23:26 +01:00
|
|
|
const QString &color, const Source &typeCreation, QGraphicsItem *parent)
|
|
|
|
:VToolCut(doc, data, id, formula, splineId, spl1id, spl2id, color, parent)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-06-26 12:26:13 +02:00
|
|
|
RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
|
|
|
|
RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2015-05-28 12:16:59 +02:00
|
|
|
ToolCreation(typeCreation);
|
2013-12-18 12:13:32 +01: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-12-18 12:13:32 +01:00
|
|
|
void VToolCutSpline::setDialog()
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogCutSpline *dialogTool = qobject_cast<DialogCutSpline*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
2015-02-03 11:17:04 +01:00
|
|
|
dialogTool->SetFormula(formula);
|
2014-07-29 15:08:38 +02:00
|
|
|
dialogTool->setSplineId(curveCutId);
|
2015-02-03 11:17:04 +01:00
|
|
|
dialogTool->SetPointName(point->name());
|
2015-02-08 11:23:26 +01:00
|
|
|
dialogTool->SetColor(lineColor);
|
2013-12-18 12:13:32 +01: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
|
|
|
VToolCutSpline* VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene,
|
2014-02-25 15:02:09 +01:00
|
|
|
VPattern *doc, VContainer *data)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogCutSpline *dialogTool = qobject_cast<DialogCutSpline*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-05-30 13:50:41 +02:00
|
|
|
const QString pointName = dialogTool->getPointName();
|
2015-02-03 11:17:04 +01:00
|
|
|
QString formula = dialogTool->GetFormula();
|
2014-05-30 13:50:41 +02:00
|
|
|
const quint32 splineId = dialogTool->getSplineId();
|
2015-02-08 11:23:26 +01:00
|
|
|
const QString color = dialogTool->GetColor();
|
2014-08-30 21:58:31 +02:00
|
|
|
VToolCutSpline* point = nullptr;
|
2015-02-08 11:23:26 +01:00
|
|
|
point = Create(0, pointName, formula, splineId, 5, 10, color, scene, doc, data, Document::FullParse,
|
|
|
|
Source::FromGui);
|
2014-08-30 21:58:31 +02:00
|
|
|
if (point != nullptr)
|
|
|
|
{
|
|
|
|
point->dialog=dialogTool;
|
|
|
|
}
|
|
|
|
return point;
|
2013-12-18 12:13:32 +01: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 pointName point name.
|
|
|
|
* @param formula string with formula length first spline.
|
|
|
|
* @param splineId id spline in data container.
|
|
|
|
* @param mx label bias x axis.
|
|
|
|
* @param my label bias y axis.
|
|
|
|
* @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.
|
|
|
|
*/
|
2014-08-30 21:58:31 +02:00
|
|
|
VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula,
|
2015-02-08 11:23:26 +01:00
|
|
|
const quint32 &splineId, const qreal &mx, const qreal &my, const QString &color,
|
2014-08-30 21:58:31 +02:00
|
|
|
VMainGraphicsScene *scene, VPattern *doc, VContainer *data,
|
|
|
|
const Document &parse, const Source &typeCreation)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(splineId);
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2014-07-29 14:19:11 +02:00
|
|
|
const qreal result = CheckFormula(_id, formula, data);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
|
|
|
QPointF point = spl->CutSpline(qApp->toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
quint32 id = _id;
|
|
|
|
quint32 spl1id = 0;
|
|
|
|
quint32 spl2id = 0;
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2014-05-21 10:51:16 +02:00
|
|
|
{
|
2014-07-25 13:53:39 +02:00
|
|
|
VPointF *p = new VPointF(point, pointName, mx, my);
|
2014-05-21 10:51:16 +02:00
|
|
|
id = data->AddGObject(p);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
|
|
|
|
spl1id = data->AddGObject(spline1);
|
2015-06-02 15:53:19 +02:00
|
|
|
data->AddCurve<VSpline>(spl1id, id);
|
2014-05-21 10:51:16 +02:00
|
|
|
|
|
|
|
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
|
|
|
|
spl2id = data->AddGObject(spline2);
|
2015-06-02 15:53:19 +02:00
|
|
|
data->AddCurve<VSpline>(spl2id, id);
|
2014-05-21 10:51:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-25 13:53:39 +02:00
|
|
|
VPointF *p = new VPointF(point, pointName, mx, my);
|
2014-05-21 10:51:16 +02:00
|
|
|
data->UpdateGObject(id, p);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
spl1id = id + 1;
|
|
|
|
spl2id = id + 2;
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
|
|
|
|
data->UpdateGObject(spl1id, spline1);
|
2015-06-02 15:53:19 +02:00
|
|
|
data->AddCurve<VSpline>(spl1id, id);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
|
|
|
|
data->UpdateGObject(spl2id, spline2);
|
2015-06-02 15:53:19 +02:00
|
|
|
data->AddCurve<VSpline>(spl2id, id);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
if (parse != Document::FullParse)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-05-21 10:51:16 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-26 20:31:28 +02:00
|
|
|
VDrawTool::AddRecord(id, Tool::CutSpline, doc);
|
2014-05-21 10:51:16 +02:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2015-02-08 11:23:26 +01:00
|
|
|
VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, color,
|
|
|
|
typeCreation);
|
2014-05-21 10:51:16 +02:00
|
|
|
scene->addItem(point);
|
|
|
|
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2014-06-24 10:23:39 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolCutSpline::SetFactor);
|
2015-02-06 15:25:04 +01:00
|
|
|
connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolCutSpline::Disable);
|
2015-03-19 12:13:13 +01:00
|
|
|
connect(scene, &VMainGraphicsScene::EnableToolMove, point, &VToolCutSpline::EnableToolMove);
|
2015-04-23 17:06:17 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::CurveDetailsMode, point, &VToolCutSpline::DetailsMode);
|
2014-05-21 10:51:16 +02:00
|
|
|
doc->AddTool(id, point);
|
|
|
|
doc->AddTool(spl1id, point);
|
|
|
|
doc->AddTool(spl2id, point);
|
|
|
|
doc->IncrementReferens(splineId);
|
2014-08-30 21:58:31 +02:00
|
|
|
return point;
|
2014-05-21 10:51:16 +02:00
|
|
|
}
|
2014-08-30 21:58:31 +02:00
|
|
|
return nullptr;
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
|
|
|
|
2014-09-03 15:52:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolCutSpline::ShowVisualization(bool show)
|
|
|
|
{
|
2015-05-23 15:10:08 +02:00
|
|
|
ShowToolVisualization<VisToolCutSpline>(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
|
|
|
/**
|
2014-06-26 12:26:13 +02:00
|
|
|
* @brief CurveChoosed send signal about selection from spline.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param id object id in container.
|
|
|
|
*/
|
2014-06-26 12:26:13 +02:00
|
|
|
void VToolCutSpline::CurveChoosed(quint32 id)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
emit ChoosedTool(id, SceneObject::Spline);
|
2013-12-18 12:13:32 +01: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-12-18 12:13:32 +01:00
|
|
|
void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
ContextMenu<DialogCutSpline>(this, event);
|
2013-12-18 12:13:32 +01: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 VToolCutSpline::SaveDialog(QDomElement &domElement)
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogCutSpline *dialogTool = qobject_cast<DialogCutSpline*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
|
2015-02-03 11:17:04 +01:00
|
|
|
doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula());
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId()));
|
2015-02-08 11:23:26 +01:00
|
|
|
doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor());
|
2014-02-06 14:57:23 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
2014-06-26 12:26:13 +02:00
|
|
|
* @brief RefreshCurve refresh curve on scene.
|
|
|
|
* @param curve curve.
|
|
|
|
* @param curveId curve id.
|
2014-06-13 19:02:41 +02:00
|
|
|
*/
|
2014-08-17 16:22:30 +02:00
|
|
|
void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
|
|
|
|
PathDirection direction)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(curveId);
|
2013-12-18 12:13:32 +01:00
|
|
|
QPainterPath path;
|
2014-08-17 16:22:30 +02:00
|
|
|
path.addPath(spl->GetPath(direction));
|
2013-12-18 12:13:32 +01:00
|
|
|
path.setFillRule( Qt::WindingFill );
|
2014-08-17 16:22:30 +02:00
|
|
|
if (curvePosition == SimpleCurvePoint::FirstPoint)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
path.translate(-spl->GetP1().toQPointF().x(), -spl->GetP1().toQPointF().y());
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
path.translate(-spl->GetP4().toQPointF().x(), -spl->GetP4().toQPointF().y());
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
2015-02-06 12:41:30 +01:00
|
|
|
curve->SetCurrentColor(QColor(lineColor));
|
2014-06-26 12:26:13 +02:00
|
|
|
curve->setPath(path);
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
2014-08-30 21:58:31 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolCutSpline::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
2015-05-28 14:13:37 +02:00
|
|
|
VToolCut::SaveOptions(tag, obj);
|
2014-08-30 21:58:31 +02:00
|
|
|
|
|
|
|
doc->SetAttribute(tag, AttrType, ToolType);
|
|
|
|
doc->SetAttribute(tag, AttrLength, formula);
|
|
|
|
doc->SetAttribute(tag, AttrSpline, curveCutId);
|
|
|
|
}
|
2015-02-06 18:43:31 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolCutSpline::ReadToolAttributes(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
formula = doc->GetParametrString(domElement, AttrLength, "");
|
|
|
|
curveCutId = doc->GetParametrUInt(domElement, AttrSpline, NULL_ID_STR);
|
2015-02-08 11:23:26 +01:00
|
|
|
lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack);
|
2015-02-06 18:43:31 +01:00
|
|
|
}
|
2015-05-23 13:40:43 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolCutSpline::SetVisualization()
|
|
|
|
{
|
|
|
|
if (vis != nullptr)
|
|
|
|
{
|
|
|
|
VisToolCutSpline *visual = qobject_cast<VisToolCutSpline *>(vis);
|
|
|
|
SCASSERT(visual != nullptr);
|
|
|
|
|
|
|
|
visual->setPoint1Id(curveCutId);
|
|
|
|
visual->setLength(qApp->FormulaToUser(formula));
|
|
|
|
visual->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|