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-01-08 15:05:32 +01:00
|
|
|
|
|
|
|
const QString VToolCutArc::ToolType = QStringLiteral("cutArc");
|
|
|
|
const QString VToolCutArc::AttrArc = QStringLiteral("arc");
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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-03-11 12:43:24 +01:00
|
|
|
const Valentina::Sources &typeCreation, QGraphicsItem * parent)
|
2014-02-06 14:57:23 +01:00
|
|
|
:VToolPoint(doc, data, id, parent), formula(formula), arcId(arcId), firstArc(), secondArc(), arc1id(arc1id),
|
|
|
|
arc2id(arc2id)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
Q_ASSERT_X(arcId > 0, Q_FUNC_INFO, "arcId <= 0");
|
|
|
|
Q_ASSERT_X(arc1id > 0, Q_FUNC_INFO, "arc1id <= 0");
|
|
|
|
Q_ASSERT_X(arc2id > 0, Q_FUNC_INFO, "arc2id <= 0");
|
|
|
|
|
|
|
|
firstArc = new VSimpleArc(arc1id, ¤tColor, &factor);
|
|
|
|
RefreshArc(firstArc, arc1id, SimpleArc::ForthPoint);
|
|
|
|
firstArc->setParentItem(this);
|
|
|
|
connect(firstArc, &VSimpleArc::Choosed, this, &VToolCutArc::ArcChoosed);
|
|
|
|
|
|
|
|
secondArc = new VSimpleArc(arc2id, ¤tColor, &factor);
|
|
|
|
RefreshArc(secondArc, arc2id, SimpleArc::FirstPoint);
|
|
|
|
secondArc->setParentItem(this);
|
|
|
|
connect(secondArc, &VSimpleArc::Choosed, this, &VToolCutArc::ArcChoosed);
|
|
|
|
|
2014-03-11 12:43:24 +01:00
|
|
|
if (typeCreation == Valentina::FromGui)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RefreshDataInFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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-01-08 15:05:32 +01:00
|
|
|
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
|
2014-02-06 14:57:23 +01:00
|
|
|
dialogTool->setFormula(formula);
|
|
|
|
dialogTool->setArcId(arcId, id);
|
|
|
|
dialogTool->setPointName(point->name());
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-09 18:37:11 +02:00
|
|
|
VToolCutArc* VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc,
|
2014-01-08 15:05:32 +01:00
|
|
|
VContainer *data)
|
|
|
|
{
|
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;
|
|
|
|
point=Create(0, pointName, formula, arcId, 5, 10, scene, doc, data, Document::FullParse, Valentina::FromGui);
|
|
|
|
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-09 18:37:11 +02:00
|
|
|
VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &arcId,
|
2014-02-25 15:02:09 +01:00
|
|
|
const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
|
2014-03-11 12:43:24 +01:00
|
|
|
VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
const VArc *arc = data->GeometricObject<const VArc *>(arcId);
|
2014-05-21 12:12:52 +02:00
|
|
|
|
2014-05-30 13:50:41 +02:00
|
|
|
const qreal result = CheckFormula(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;
|
|
|
|
if (typeCreation == Valentina::FromGui)
|
|
|
|
{
|
|
|
|
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
|
|
|
id = data->AddGObject(p);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VArc * ar1 = new VArc(arc1);
|
|
|
|
arc1id = data->AddGObject(ar1);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VArc * ar2 = new VArc(arc2);
|
|
|
|
arc2id = data->AddGObject(ar2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
|
|
|
data->UpdateGObject(id, p);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
arc1id = id + 1;
|
|
|
|
arc2id = id + 2;
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VArc * ar1 = new VArc(arc1);
|
|
|
|
data->UpdateGObject(arc1id, ar1);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
VArc * ar2 = new VArc(arc2);
|
|
|
|
data->UpdateGObject(arc2id, ar2);
|
|
|
|
|
|
|
|
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
|
|
|
data->AddLengthArc(arc1id);
|
|
|
|
data->AddLengthArc(arc2id);
|
|
|
|
|
|
|
|
VDrawTool::AddRecord(id, Valentina::CutArcTool, doc);
|
|
|
|
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);
|
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
|
|
|
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-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::FullUpdateFromFile()
|
|
|
|
{
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
|
|
|
formula = domElement.attribute(AttrLength, "");
|
2014-02-25 15:55:02 +01:00
|
|
|
arcId = domElement.attribute(AttrArc, "").toUInt();
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
void VToolCutArc::ArcChoosed(quint32 id)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-03-11 12:43:24 +01:00
|
|
|
emit ChoosedTool(id, Valentina::Arc);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::ChangedActivDraw(const QString &newName)
|
|
|
|
{
|
|
|
|
if (nameActivDraw == newName)
|
|
|
|
{
|
|
|
|
currentColor = Qt::black;
|
|
|
|
firstArc->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
firstArc->setAcceptHoverEvents(true);
|
|
|
|
secondArc->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
secondArc->setAcceptHoverEvents(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentColor = Qt::gray;
|
|
|
|
firstArc->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
|
|
firstArc->setAcceptHoverEvents(false);
|
|
|
|
secondArc->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
|
|
secondArc->setAcceptHoverEvents(false);
|
|
|
|
}
|
2014-03-26 05:39:07 +01:00
|
|
|
firstArc->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
|
|
|
secondArc->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
2014-01-08 15:05:32 +01:00
|
|
|
VToolPoint::ChangedActivDraw(newName);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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-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-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::AddToFile()
|
|
|
|
{
|
|
|
|
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
|
|
|
|
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);
|
|
|
|
doc->SetAttribute(domElement, AttrArc, arcId);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
|
|
|
AddToCalculation(domElement);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::RefreshDataInFile()
|
|
|
|
{
|
|
|
|
const VPointF *point = VAbstractTool::data.GeometricObject<const VPointF *>(id);
|
|
|
|
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);
|
|
|
|
doc->SetAttribute(domElement, AttrArc, arcId);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-08 15:05:32 +01:00
|
|
|
void VToolCutArc::RefreshGeometry()
|
|
|
|
{
|
|
|
|
RefreshArc(firstArc, arc1id, SimpleArc::ForthPoint);
|
|
|
|
RefreshArc(secondArc, arc2id, SimpleArc::FirstPoint);
|
|
|
|
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<const VPointF *>(id));
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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-02-25 15:40:24 +01:00
|
|
|
void VToolCutArc::RefreshArc(VSimpleArc *sArc, quint32 arcid, SimpleArc::Translation tr)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
const VArc *arc = VAbstractTool::data.GeometricObject<const VArc *>(arcid);
|
|
|
|
QPainterPath path;
|
|
|
|
path.addPath(arc->GetPath());
|
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
if (tr == SimpleArc::FirstPoint)
|
|
|
|
{
|
|
|
|
path.translate(-arc->GetP1().x(), -arc->GetP1().y());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path.translate(-arc->GetP2().x(), -arc->GetP2().y());
|
|
|
|
}
|
|
|
|
sArc->setPath(path);
|
|
|
|
}
|