2014-01-08 15:05:32 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtoolcutarc.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-01-08 15:05:32 +01:00
|
|
|
** @date 7 1, 2014
|
|
|
|
**
|
|
|
|
** @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.
|
|
|
|
**
|
|
|
|
** 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 "vtoolcutarc.h"
|
|
|
|
#include "../../container/calculator.h"
|
2014-02-21 14:04:39 +01:00
|
|
|
#include "../../dialogs/tools/dialogcutarc.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../../geometry/vpointf.h"
|
|
|
|
#include "../../geometry/varc.h"
|
2014-01-08 15:05:32 +01:00
|
|
|
|
|
|
|
const QString VToolCutArc::ToolType = QStringLiteral("cutArc");
|
2014-06-26 12:26:13 +02:00
|
|
|
const QString VToolCutArc::AttrArc = QStringLiteral("arc");
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolCutArc constructor.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param formula string with formula length first arc.
|
|
|
|
* @param arcId id arc in data container.
|
|
|
|
* @param arc1id id first cutting arc.
|
|
|
|
* @param arc2id id second cutting arc.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
VToolCutArc::VToolCutArc(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
|
|
|
|
const quint32 &arcId, const quint32 &arc1id, const quint32 &arc2id,
|
2014-06-12 09:22:29 +02:00
|
|
|
const Source &typeCreation, QGraphicsItem * parent)
|
2014-06-26 12:26:13 +02:00
|
|
|
:VToolCut(doc, data, id, formula, arcId, arc1id, arc2id, parent)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-06-26 12:26:13 +02:00
|
|
|
RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
|
|
|
|
RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RefreshDataInFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::setDialog()
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogCutArc *dialogTool = qobject_cast<DialogCutArc*>(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);
|
2014-02-06 14:57:23 +01:00
|
|
|
dialogTool->setFormula(formula);
|
2014-07-29 15:08:38 +02:00
|
|
|
dialogTool->setArcId(curveCutId);
|
2014-02-06 14:57:23 +01:00
|
|
|
dialogTool->setPointName(point->name());
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool form GUI.
|
|
|
|
* @param dialog dialog.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
*/
|
|
|
|
VToolCutArc* VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogCutArc *dialogTool = qobject_cast<DialogCutArc*>(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();
|
2014-02-06 14:57:23 +01:00
|
|
|
QString formula = dialogTool->getFormula();
|
2014-05-30 13:50:41 +02:00
|
|
|
const quint32 arcId = dialogTool->getArcId();
|
2014-06-09 18:37:11 +02:00
|
|
|
VToolCutArc* point = nullptr;
|
2014-06-12 09:22:29 +02:00
|
|
|
point=Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui);
|
2014-06-09 18:37:11 +02:00
|
|
|
if (point != nullptr)
|
|
|
|
{
|
|
|
|
point->dialog=dialogTool;
|
|
|
|
}
|
|
|
|
return point;
|
2014-01-08 15:05: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 arc.
|
|
|
|
* @param arcId id arc 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-06-09 18:37:11 +02:00
|
|
|
VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId,
|
2014-06-13 19:02:41 +02:00
|
|
|
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
|
|
|
|
VContainer *data, const Document &parse, const Source &typeCreation)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(arcId);
|
2014-05-21 12:12:52 +02:00
|
|
|
|
2014-07-29 14:19:11 +02:00
|
|
|
const qreal result = CheckFormula(_id, formula, data);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VArc arc1;
|
|
|
|
VArc arc2;
|
|
|
|
QPointF point = arc->CutArc(qApp->toPixel(result), arc1, arc2);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
quint32 id = _id;
|
|
|
|
quint32 arc1id = 0;
|
|
|
|
quint32 arc2id = 0;
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2014-05-21 10:51:16 +02:00
|
|
|
{
|
2014-07-25 17:43:32 +02:00
|
|
|
id = data->AddGObject(new VPointF(point, pointName, mx, my));
|
|
|
|
arc1id = data->AddGObject(new VArc(arc1));
|
|
|
|
arc2id = data->AddGObject(new VArc(arc2));
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-08-15 19:27:30 +02:00
|
|
|
data->AddCurveLength<VArcLength>(arc1id, id);
|
|
|
|
data->AddCurveLength<VArcLength>(arc2id, id);
|
2014-05-21 10:51:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-25 17:43:32 +02:00
|
|
|
data->UpdateGObject(id, new VPointF(point, pointName, mx, my));
|
2014-05-21 10:51:16 +02:00
|
|
|
arc1id = id + 1;
|
|
|
|
arc2id = id + 2;
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-07-25 17:43:32 +02:00
|
|
|
data->UpdateGObject(arc1id, new VArc(arc1));
|
|
|
|
data->UpdateGObject(arc2id, new VArc(arc2));
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-08-15 19:27:30 +02:00
|
|
|
data->AddCurveLength<VArcLength>(arc1id, id);
|
|
|
|
data->AddCurveLength<VArcLength>(arc2id, id);
|
2014-05-21 10:51:16 +02:00
|
|
|
|
|
|
|
if (parse != Document::FullParse)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-05-21 10:51:16 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
VDrawTool::AddRecord(id, Tool::CutArcTool, doc);
|
2014-05-21 10:51:16 +02:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
|
|
|
VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, arc1id, arc2id, typeCreation);
|
|
|
|
scene->addItem(point);
|
|
|
|
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2014-06-24 10:23:39 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolCutArc::SetFactor);
|
|
|
|
connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolPoint::Disable);
|
2014-05-21 10:51:16 +02:00
|
|
|
doc->AddTool(id, point);
|
|
|
|
doc->AddTool(arc1id, point);
|
|
|
|
doc->AddTool(arc2id, point);
|
|
|
|
doc->IncrementReferens(arcId);
|
2014-06-09 18:37:11 +02:00
|
|
|
return point;
|
2014-05-21 10:51:16 +02:00
|
|
|
}
|
2014-06-09 18:37:11 +02:00
|
|
|
return nullptr;
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
|
|
|
*/
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::FullUpdateFromFile()
|
|
|
|
{
|
2014-06-26 12:26:13 +02:00
|
|
|
FullUpdateCurveFromFile(AttrArc);
|
2014-01-08 15:05:32 +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 CurveChoosed send signal about selection from cutted arc.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param id object id in container.
|
|
|
|
*/
|
2014-06-26 12:26:13 +02:00
|
|
|
void VToolCutArc::CurveChoosed(quint32 id)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
emit ChoosedTool(id, SceneObject::Arc);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief ShowContextMenu show context menu.
|
|
|
|
* @param event context menu event.
|
|
|
|
*/
|
2014-01-10 10:16:55 +01:00
|
|
|
void VToolCutArc::ShowContextMenu(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
ContextMenu<DialogCutArc>(this, event);
|
2014-01-10 10:16:55 +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.
|
|
|
|
*/
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2014-02-06 14:57:23 +01:00
|
|
|
ContextMenu<DialogCutArc>(this, event);
|
2014-01-08 15:05:32 +01: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.
|
|
|
|
*/
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::AddToFile()
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
2014-01-08 15:05:32 +01:00
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
|
|
|
|
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, AttrName, point->name());
|
2014-03-19 19:27:11 +01:00
|
|
|
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx()));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrLength, formula);
|
2014-06-26 12:26:13 +02:00
|
|
|
doc->SetAttribute(domElement, AttrArc, curveCutId);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
|
|
|
AddToCalculation(domElement);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::RefreshDataInFile()
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
2014-01-08 15:05:32 +01:00
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, point->name());
|
2014-03-19 19:27:11 +01:00
|
|
|
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx()));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrLength, formula);
|
2014-06-26 12:26:13 +02:00
|
|
|
doc->SetAttribute(domElement, AttrArc, curveCutId);
|
2014-01-08 15:05: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 VToolCutArc::SaveDialog(QDomElement &domElement)
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogCutArc *dialogTool = qobject_cast<DialogCutArc*>(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());
|
|
|
|
doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula());
|
|
|
|
doc->SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId()));
|
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.
|
|
|
|
* @param tr point type.
|
2014-06-13 19:02:41 +02:00
|
|
|
*/
|
2014-08-17 16:22:30 +02:00
|
|
|
void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
|
|
|
|
PathDirection direction)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(curveId);
|
2014-01-08 15:05:32 +01:00
|
|
|
QPainterPath path;
|
2014-08-17 16:22:30 +02:00
|
|
|
path.addPath(arc->GetPath(direction));
|
2014-01-08 15:05:32 +01:00
|
|
|
path.setFillRule( Qt::WindingFill );
|
2014-08-17 16:22:30 +02:00
|
|
|
if (curvePosition == SimpleCurvePoint::FirstPoint)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
path.translate(-arc->GetP1().x(), -arc->GetP1().y());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path.translate(-arc->GetP2().x(), -arc->GetP2().y());
|
|
|
|
}
|
2014-06-26 12:26:13 +02:00
|
|
|
curve->setPath(path);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|