2014-06-26 12:26:13 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtoolcut.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 25 6, 2014
|
|
|
|
**
|
|
|
|
** @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
|
2014-06-26 12:26:13 +02: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 "vtoolcut.h"
|
2015-05-07 14:31:53 +02:00
|
|
|
#include "../../libs/vgeometry/vpointf.h"
|
2015-06-12 11:22:25 +02:00
|
|
|
#include "../../core/vformula.h"
|
2014-06-26 12:26:13 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
|
2015-02-08 11:23:26 +01:00
|
|
|
const quint32 &curveCutId, const quint32 &curve1id, const quint32 &curve2id, const QString &color,
|
2014-06-26 12:26:13 +02:00
|
|
|
QGraphicsItem *parent)
|
|
|
|
:VToolPoint(doc, data, id, parent), formula(formula), firstCurve(nullptr), secondCurve(nullptr),
|
2015-04-23 17:06:17 +02:00
|
|
|
curveCutId(curveCutId), curve1id(curve1id), curve2id(curve2id), detailsMode(false)
|
2014-06-26 12:26:13 +02:00
|
|
|
{
|
|
|
|
Q_ASSERT_X(curveCutId > 0, Q_FUNC_INFO, "curveCutId <= 0");
|
|
|
|
Q_ASSERT_X(curve1id > 0, Q_FUNC_INFO, "curve1id <= 0");
|
|
|
|
Q_ASSERT_X(curve2id > 0, Q_FUNC_INFO, "curve2id <= 0");
|
|
|
|
|
2015-02-08 11:23:26 +01:00
|
|
|
lineColor = color;
|
|
|
|
|
2015-06-15 11:32:27 +02:00
|
|
|
firstCurve = new VSimpleCurve(curve1id, QColor(lineColor), SimpleCurvePoint::ForthPoint, *data->GetPatternUnit(),
|
|
|
|
&factor);
|
2014-06-26 12:26:13 +02:00
|
|
|
firstCurve->setParentItem(this);
|
|
|
|
connect(firstCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
|
2014-08-17 16:22:30 +02:00
|
|
|
connect(firstCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath);
|
2015-02-13 10:26:02 +01:00
|
|
|
// TODO: Now we only hide simple curves, but in future need totally delete them all.
|
|
|
|
firstCurve->setVisible(false);
|
2014-06-26 12:26:13 +02:00
|
|
|
|
2015-06-15 11:32:27 +02:00
|
|
|
secondCurve = new VSimpleCurve(curve2id, QColor(lineColor), SimpleCurvePoint::FirstPoint, *data->GetPatternUnit(),
|
|
|
|
&factor);
|
2014-06-26 12:26:13 +02:00
|
|
|
secondCurve->setParentItem(this);
|
|
|
|
connect(secondCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
|
2014-08-17 16:22:30 +02:00
|
|
|
connect(secondCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath);
|
2015-02-13 10:26:02 +01:00
|
|
|
secondCurve->setVisible(false);
|
2014-06-26 12:26:13 +02:00
|
|
|
}
|
|
|
|
|
2014-08-17 16:22:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolCut::HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirection direction)
|
|
|
|
{
|
|
|
|
VSimpleCurve* simpleCurve = qobject_cast<VSimpleCurve*>(sender());
|
|
|
|
if (simpleCurve)
|
|
|
|
{
|
|
|
|
RefreshCurve(simpleCurve, id, curvePosition, direction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 13:31:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-25 08:24:16 +02:00
|
|
|
void VToolCut::Disable(bool disable, const QString &namePP)
|
2015-02-06 13:31:40 +01:00
|
|
|
{
|
2015-05-25 08:24:16 +02:00
|
|
|
VToolPoint::Disable(disable, namePP);
|
2015-02-06 13:31:40 +01:00
|
|
|
firstCurve->ChangedActivDraw(enabled);
|
|
|
|
secondCurve->ChangedActivDraw(enabled);
|
|
|
|
}
|
|
|
|
|
2015-04-23 17:06:17 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolCut::DetailsMode(bool mode)
|
|
|
|
{
|
|
|
|
detailsMode = mode;
|
|
|
|
}
|
|
|
|
|
2015-05-28 14:36:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
|
|
|
*/
|
|
|
|
void VToolCut::FullUpdateFromFile()
|
|
|
|
{
|
|
|
|
ReadAttributes();
|
|
|
|
RefreshGeometry();
|
|
|
|
SetVisualization();
|
|
|
|
}
|
|
|
|
|
2014-09-01 17:07:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-09-01 17:07:21 +02:00
|
|
|
quint32 VToolCut::getCurveCutId() const
|
|
|
|
{
|
|
|
|
return curveCutId;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-09-01 17:07:21 +02:00
|
|
|
void VToolCut::setCurveCutId(const quint32 &value)
|
|
|
|
{
|
|
|
|
if (value != NULL_ID)
|
|
|
|
{
|
|
|
|
curveCutId = value;
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
VFormula VToolCut::GetFormula() const
|
2014-09-01 17:07:21 +02:00
|
|
|
{
|
|
|
|
VFormula val(formula, getData());
|
|
|
|
val.setCheckZero(true);
|
|
|
|
val.setToolId(id);
|
|
|
|
val.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit()));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VToolCut::SetFormula(const VFormula &value)
|
2014-09-01 17:07:21 +02:00
|
|
|
{
|
|
|
|
if (value.error() == false)
|
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
formula = value.GetFormula(FormulaType::FromUser);
|
2014-09-03 13:10:51 +02:00
|
|
|
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
2014-09-01 17:07:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 12:26:13 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief RefreshGeometry refresh item on scene.
|
|
|
|
*/
|
|
|
|
void VToolCut::RefreshGeometry()
|
|
|
|
{
|
|
|
|
RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint);
|
|
|
|
RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint);
|
2014-08-21 14:44:40 +02:00
|
|
|
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<VPointF>(id));
|
2014-06-26 12:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief RemoveReferens decrement referens value for used objects.
|
|
|
|
*/
|
|
|
|
void VToolCut::RemoveReferens()
|
|
|
|
{
|
|
|
|
doc->DecrementReferens(curveCutId);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-06-26 12:26:13 +02:00
|
|
|
void VToolCut::FullUpdateCurveFromFile(const QString &attrCurve)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(attrCurve.isEmpty() == false, Q_FUNC_INFO, "attribute name is empty");
|
|
|
|
|
2015-02-11 11:43:50 +01:00
|
|
|
QDomElement domElement = doc->elementById(id);
|
2014-06-26 12:26:13 +02:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
|
|
|
formula = domElement.attribute(AttrLength, "");
|
|
|
|
curveCutId = domElement.attribute(attrCurve, "").toUInt();
|
|
|
|
}
|
|
|
|
}
|
2015-05-28 14:13:37 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolCut::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
|
|
|
VToolPoint::SaveOptions(tag, obj);
|
|
|
|
|
|
|
|
doc->SetAttribute(tag, AttrColor, lineColor);
|
|
|
|
}
|