2016-11-03 16:59:53 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 3 11, 2016
|
|
|
|
**
|
|
|
|
** @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) 2016 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 "vpiecenode.h"
|
|
|
|
#include "vpiecenode_p.h"
|
2017-01-21 14:24:40 +01:00
|
|
|
#include "vcontainer.h"
|
|
|
|
#include "calculator.h"
|
2016-11-03 16:59:53 +01:00
|
|
|
|
2017-01-11 14:01:49 +01:00
|
|
|
#include <QDataStream>
|
2017-01-21 14:24:40 +01:00
|
|
|
#include <QtNumeric>
|
2017-01-11 14:01:49 +01:00
|
|
|
|
2017-01-25 16:04:53 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal EvalFormula(const VContainer *data, QString formula)
|
|
|
|
{
|
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Replace line return character with spaces for calc if exist
|
|
|
|
formula.replace("\n", " ");
|
|
|
|
QScopedPointer<Calculator> cal(new Calculator());
|
2017-08-04 19:29:43 +02:00
|
|
|
const qreal result = cal->EvalFormula(data->DataVariables(), formula);
|
2017-01-25 16:04:53 +01:00
|
|
|
|
|
|
|
if (qIsInf(result) || qIsNaN(result))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-03 16:59:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPieceNode::VPieceNode()
|
|
|
|
: d(new VPieceNodeData)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPieceNode::VPieceNode(quint32 id, Tool typeTool, bool reverse)
|
|
|
|
: d(new VPieceNodeData(id, typeTool, reverse))
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPieceNode::VPieceNode(const VPieceNode &node)
|
|
|
|
: d (node.d)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPieceNode &VPieceNode::operator=(const VPieceNode &node)
|
|
|
|
{
|
|
|
|
if ( &node == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
d = node.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPieceNode::~VPieceNode()
|
|
|
|
{}
|
|
|
|
|
2017-03-28 11:08:33 +02:00
|
|
|
// Friend functions
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDataStream &operator<<(QDataStream &out, const VPieceNode &p)
|
|
|
|
{
|
|
|
|
out << p.d;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDataStream &operator>>(QDataStream &in, VPieceNode &p)
|
|
|
|
{
|
|
|
|
in >> *p.d;
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2016-11-03 16:59:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VPieceNode::GetId() const
|
|
|
|
{
|
2016-11-04 15:28:10 +01:00
|
|
|
return d->m_id;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetId(quint32 id)
|
|
|
|
{
|
2016-11-04 15:28:10 +01:00
|
|
|
d->m_id = id;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Tool VPieceNode::GetTypeTool() const
|
|
|
|
{
|
2016-11-04 15:28:10 +01:00
|
|
|
return d->m_typeTool;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetTypeTool(Tool value)
|
|
|
|
{
|
2016-11-04 15:28:10 +01:00
|
|
|
d->m_typeTool = value;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VPieceNode::GetReverse() const
|
|
|
|
{
|
2016-11-04 15:28:10 +01:00
|
|
|
return d->m_reverse;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetReverse(bool reverse)
|
|
|
|
{
|
2016-11-04 15:28:10 +01:00
|
|
|
if (d->m_typeTool != Tool::NodePoint)
|
2016-11-04 15:25:01 +01:00
|
|
|
{
|
2016-11-04 15:28:10 +01:00
|
|
|
d->m_reverse = reverse;
|
2016-11-04 15:25:01 +01:00
|
|
|
}
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
2016-11-04 16:34:15 +01:00
|
|
|
|
2016-11-12 11:41:04 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
qreal VPieceNode::GetSABefore(const VContainer *data) const
|
2016-11-12 11:41:04 +01:00
|
|
|
{
|
2017-03-30 10:09:12 +02:00
|
|
|
if (d->m_formulaWidthBefore == currentSeamAllowance)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
return EvalFormula(data, d->m_formulaWidthBefore);
|
2016-11-12 11:41:04 +01:00
|
|
|
}
|
|
|
|
|
2016-11-17 13:08:23 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
qreal VPieceNode::GetSABefore(const VContainer *data, Unit unit) const
|
2016-11-17 13:08:23 +01:00
|
|
|
{
|
2017-03-30 10:09:12 +02:00
|
|
|
if (d->m_formulaWidthBefore == currentSeamAllowance)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
qreal value = EvalFormula(data, d->m_formulaWidthBefore);
|
2016-11-17 13:08:23 +01:00
|
|
|
if (value >= 0)
|
|
|
|
{
|
|
|
|
value = ToPixel(value, unit);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-11-12 11:41:04 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
QString VPieceNode::GetFormulaSABefore() const
|
|
|
|
{
|
|
|
|
return d->m_formulaWidthBefore;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetFormulaSABefore(const QString &formula)
|
2016-11-12 11:41:04 +01:00
|
|
|
{
|
|
|
|
if (d->m_typeTool == Tool::NodePoint)
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
d->m_formulaWidthBefore = formula;
|
2016-11-12 11:41:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
qreal VPieceNode::GetSAAfter(const VContainer *data) const
|
2016-11-12 11:41:04 +01:00
|
|
|
{
|
2017-03-30 10:09:12 +02:00
|
|
|
if (d->m_formulaWidthAfter == currentSeamAllowance)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
return EvalFormula(data, d->m_formulaWidthAfter);
|
2016-11-12 11:41:04 +01:00
|
|
|
}
|
|
|
|
|
2016-11-17 13:08:23 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
qreal VPieceNode::GetSAAfter(const VContainer *data, Unit unit) const
|
2016-11-17 13:08:23 +01:00
|
|
|
{
|
2017-03-30 10:09:12 +02:00
|
|
|
if (d->m_formulaWidthAfter == currentSeamAllowance)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
qreal value = EvalFormula(data, d->m_formulaWidthAfter);
|
2016-11-17 13:08:23 +01:00
|
|
|
if (value >= 0)
|
|
|
|
{
|
|
|
|
value = ToPixel(value, unit);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-11-12 11:41:04 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
QString VPieceNode::GetFormulaSAAfter() const
|
|
|
|
{
|
|
|
|
return d->m_formulaWidthAfter;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetFormulaSAAfter(const QString &formula)
|
2016-11-12 11:41:04 +01:00
|
|
|
{
|
|
|
|
if (d->m_typeTool == Tool::NodePoint)
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
d->m_formulaWidthAfter = formula;
|
2016-11-12 11:41:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-19 12:44:12 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PieceNodeAngle VPieceNode::GetAngleType() const
|
|
|
|
{
|
|
|
|
return d->m_angleType;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetAngleType(PieceNodeAngle type)
|
|
|
|
{
|
2016-11-19 17:52:47 +01:00
|
|
|
if (d->m_typeTool == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
d->m_angleType = type;
|
|
|
|
}
|
2016-11-19 12:44:12 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 16:34:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-24 12:08:16 +01:00
|
|
|
bool VPieceNode::IsPassmark() const
|
2016-11-04 16:34:15 +01:00
|
|
|
{
|
2017-03-24 12:08:16 +01:00
|
|
|
return d->m_isPassmark;
|
2016-11-04 16:34:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-24 12:08:16 +01:00
|
|
|
void VPieceNode::SetPassmark(bool passmark)
|
2016-11-04 16:34:15 +01:00
|
|
|
{
|
2017-03-24 12:08:16 +01:00
|
|
|
if (GetTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
d->m_isPassmark = passmark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-05 12:22:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VPieceNode::IsMainPathNode() const
|
|
|
|
{
|
|
|
|
return d->m_isMainPathNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetMainPathNode(bool value)
|
|
|
|
{
|
|
|
|
d->m_isMainPathNode = value;
|
|
|
|
}
|
|
|
|
|
2017-03-24 12:08:16 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PassmarkLineType VPieceNode::GetPassmarkLineType() const
|
|
|
|
{
|
|
|
|
return d->m_passmarkLineType;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetPassmarkLineType(PassmarkLineType lineType)
|
|
|
|
{
|
|
|
|
d->m_passmarkLineType = lineType;
|
|
|
|
}
|
2016-11-04 16:34:15 +01:00
|
|
|
|
2017-03-24 12:08:16 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PassmarkAngleType VPieceNode::GetPassmarkAngleType() const
|
|
|
|
{
|
|
|
|
return d->m_passmarkAngleType;
|
|
|
|
}
|
2016-11-04 16:34:15 +01:00
|
|
|
|
2017-03-24 12:08:16 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetPassmarkAngleType(PassmarkAngleType angleType)
|
|
|
|
{
|
|
|
|
d->m_passmarkAngleType = angleType;
|
2016-11-04 16:34:15 +01:00
|
|
|
}
|
2017-03-21 16:18:48 +01:00
|
|
|
|
2017-04-26 10:22:42 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VPieceNode::IsShowSecondPassmark() const
|
|
|
|
{
|
|
|
|
return d->m_isShowSecondPassmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetShowSecondPassmark(bool value)
|
|
|
|
{
|
|
|
|
d->m_isShowSecondPassmark = value;
|
|
|
|
}
|
|
|
|
|
2017-03-21 16:18:48 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VPieceNode::IsExcluded() const
|
|
|
|
{
|
|
|
|
return d->m_excluded;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPieceNode::SetExcluded(bool exclude)
|
|
|
|
{
|
|
|
|
d->m_excluded = exclude;
|
|
|
|
}
|