2016-11-03 16:59:53 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 3 11, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-11-03 16:59:53 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-11-03 16:59:53 +01:00
|
|
|
**
|
|
|
|
** 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 "vpiece.h"
|
2023-07-15 09:58:28 +02:00
|
|
|
#include "../ifc/exception/vexceptioninvalidnotch.h"
|
|
|
|
#include "../ifc/exception/vexceptionobjecterror.h"
|
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
2016-11-03 19:15:53 +01:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
2022-10-28 15:16:02 +02:00
|
|
|
#include "../vgeometry/vlayoutplacelabel.h"
|
2023-07-15 09:58:28 +02:00
|
|
|
#include "../vgeometry/vplacelabelitem.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
2020-07-13 15:28:13 +02:00
|
|
|
#include "../vmisc/compatibility.h"
|
2021-09-24 11:51:39 +02:00
|
|
|
#include "../vmisc/testpath.h"
|
2023-07-15 09:58:28 +02:00
|
|
|
#include "../vmisc/vabstractvalapplication.h"
|
2023-01-02 10:32:21 +01:00
|
|
|
#include "../vpatterndb/variables/vpiecearea.h"
|
2023-07-15 09:58:28 +02:00
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
|
|
|
#include "vcontainer.h"
|
2024-01-06 13:20:56 +01:00
|
|
|
#include "vgeometrydef.h"
|
2023-07-15 09:58:28 +02:00
|
|
|
#include "vpassmark.h"
|
|
|
|
#include "vpiece_p.h"
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
|
|
#include <QDebug>
|
2023-07-15 09:58:28 +02:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
2016-11-05 09:56:44 +01:00
|
|
|
#include <QPainterPath>
|
2023-07-15 09:58:28 +02:00
|
|
|
#include <QSharedPointer>
|
2019-08-29 14:01:27 +02:00
|
|
|
#include <QTemporaryFile>
|
2016-11-03 16:59:53 +01:00
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
|
2017-01-31 17:09:18 +01:00
|
|
|
namespace
|
|
|
|
{
|
2023-05-03 13:07:02 +02:00
|
|
|
auto PieceMissingNodes(const QVector<quint32> &d1Nodes, const QVector<quint32> &d2Nodes) -> QVector<quint32>
|
2017-01-31 17:09:18 +01:00
|
|
|
{
|
|
|
|
if (d1Nodes.size() == d2Nodes.size()) //-V807
|
|
|
|
{
|
|
|
|
return QVector<quint32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<quint32> set1;
|
|
|
|
for (qint32 i = 0; i < d1Nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
set1.insert(d1Nodes.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<quint32> set2;
|
|
|
|
for (qint32 j = 0; j < d2Nodes.size(); ++j)
|
|
|
|
{
|
|
|
|
set2.insert(d2Nodes.at(j));
|
|
|
|
}
|
|
|
|
|
2020-01-06 19:10:09 +01:00
|
|
|
const QList<quint32> set3 = set1.subtract(set2).values();
|
2017-01-31 17:09:18 +01:00
|
|
|
QVector<quint32> r;
|
2019-08-29 14:04:39 +02:00
|
|
|
r.reserve(set3.size());
|
2017-01-31 17:09:18 +01:00
|
|
|
for (qint32 i = 0; i < set3.size(); ++i)
|
|
|
|
{
|
|
|
|
r.append(set3.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2017-03-28 12:09:00 +02:00
|
|
|
|
2017-03-30 12:59:10 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto IsPassmarksPossible(const QVector<VPieceNode> &path) -> bool
|
2017-03-30 12:59:10 +02:00
|
|
|
{
|
|
|
|
int countPointNodes = 0;
|
|
|
|
int countOthers = 0;
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &node : path)
|
2017-03-30 12:59:10 +02:00
|
|
|
{
|
|
|
|
if (node.IsExcluded())
|
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
continue; // skip node
|
2017-03-30 12:59:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
node.GetTypeTool() == Tool::NodePoint ? ++countPointNodes : ++countOthers;
|
|
|
|
}
|
|
|
|
|
|
|
|
return countPointNodes >= 3 || (countPointNodes >= 1 && countOthers >= 1);
|
|
|
|
}
|
2018-09-28 12:43:03 +02:00
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto RotatePath(const QVector<VPieceNode> &path, vsizetype index) -> QVector<VPieceNode>
|
2019-01-09 16:46:02 +01:00
|
|
|
{
|
|
|
|
if (index < 0 || index >= path.size())
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path.mid(index) + path.mid(0, index);
|
2017-01-31 17:09:18 +01:00
|
|
|
}
|
2019-01-09 16:46:02 +01:00
|
|
|
} // anonymous namespace
|
2017-01-31 17:09:18 +01:00
|
|
|
|
2016-11-03 16:59:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPiece::VPiece()
|
2023-07-15 09:58:28 +02:00
|
|
|
: VAbstractPiece(),
|
|
|
|
d(new VPieceData(PiecePathType::PiecePath))
|
|
|
|
{
|
|
|
|
}
|
2016-11-03 16:59:53 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
COPY_CONSTRUCTOR_IMPL_2(VPiece, VAbstractPiece)
|
2016-11-03 16:59:53 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::operator=(const VPiece &piece) -> VPiece &
|
2016-11-03 16:59:53 +01:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
if (&piece == this)
|
2016-11-03 16:59:53 +01:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2016-11-03 19:15:53 +01:00
|
|
|
VAbstractPiece::operator=(piece);
|
2016-11-03 16:59:53 +01:00
|
|
|
d = piece.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VPiece::VPiece(VPiece &&piece) noexcept
|
2023-07-15 09:58:28 +02:00
|
|
|
: VAbstractPiece(std::move(piece)),
|
|
|
|
d(std::move(piece.d))
|
|
|
|
{
|
|
|
|
}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
auto VPiece::operator=(VPiece &&piece) noexcept -> VPiece &
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
2019-12-30 16:13:18 +01:00
|
|
|
VAbstractPiece::operator=(piece);
|
2019-12-30 12:00:57 +01:00
|
|
|
std::swap(d, piece.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
#endif
|
2019-12-30 12:00:57 +01:00
|
|
|
|
2016-11-03 16:59:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
VPiece::~VPiece() = default;
|
2016-11-03 16:59:53 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPath() const -> VPiecePath
|
2016-11-03 16:59:53 +01:00
|
|
|
{
|
2016-11-23 11:54:46 +01:00
|
|
|
return d->m_path;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPath() -> VPiecePath &
|
2016-11-03 16:59:53 +01:00
|
|
|
{
|
2016-11-23 11:54:46 +01:00
|
|
|
return d->m_path;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-23 11:54:46 +01:00
|
|
|
void VPiece::SetPath(const VPiecePath &path)
|
2016-11-03 16:59:53 +01:00
|
|
|
{
|
2016-11-23 11:54:46 +01:00
|
|
|
d->m_path = path;
|
2016-11-03 16:59:53 +01:00
|
|
|
}
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MainPathPoints(const VContainer *data) const -> QVector<VLayoutPoint>
|
2016-11-03 19:15:53 +01:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
// DumpPiece(*this, data, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data
|
2019-08-29 14:01:27 +02:00
|
|
|
|
2020-10-05 15:39:01 +02:00
|
|
|
VPiecePath mainPath = GetPath();
|
2023-05-08 16:50:58 +02:00
|
|
|
mainPath.SetName(QCoreApplication::translate("VPiece", "Main path of piece %1").arg(GetName()));
|
2020-10-05 15:39:01 +02:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<VLayoutPoint> points = mainPath.PathPoints(data);
|
2023-07-15 09:58:28 +02:00
|
|
|
points = CheckLoops(CorrectEquidistantPoints(points)); // A path can contains loops
|
2019-08-29 14:01:27 +02:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
// DumpVector(points, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data
|
2016-11-03 19:15:53 +01:00
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::FullMainPathPoints(const VContainer *data) const -> QVector<VLayoutPoint>
|
|
|
|
{
|
|
|
|
// DumpPiece(*this, data, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data
|
|
|
|
|
|
|
|
VPiecePath mainPath = GetPath();
|
|
|
|
mainPath.SetName(QCoreApplication::translate("VPiece", "Main path of piece %1").arg(GetName()));
|
|
|
|
|
|
|
|
QVector<VLayoutPoint> points = mainPath.PathPoints(data);
|
|
|
|
|
|
|
|
QLineF const mirrorLine = SeamMirrorLine(data);
|
|
|
|
if (!mirrorLine.isNull() && IsShowFullPiece())
|
|
|
|
{
|
|
|
|
points = VAbstractPiece::FullPath(points, mirrorLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
points = CheckLoops(CorrectEquidistantPoints(points)); // A path can contains loops
|
|
|
|
|
|
|
|
// DumpVector(points, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2019-02-11 14:00:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::UniteMainPathPoints(const VContainer *data) const -> QVector<VLayoutPoint>
|
2019-02-11 14:00:32 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<VLayoutPoint> points = VPiecePath::NodesToPoints(data, GetUnitedPath(data), GetName());
|
2023-07-15 09:58:28 +02:00
|
|
|
points = CheckLoops(CorrectEquidistantPoints(points)); // A path can contains loops
|
2019-02-11 14:00:32 +01:00
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2016-11-05 09:56:44 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MainPathNodePoints(const VContainer *data, bool showExcluded) const -> QVector<VPointF>
|
2016-11-05 09:56:44 +01:00
|
|
|
{
|
2017-03-22 11:05:53 +01:00
|
|
|
return GetPath().PathNodePoints(data, showExcluded);
|
2016-11-05 09:56:44 +01:00
|
|
|
}
|
|
|
|
|
2016-11-10 13:06:09 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::SeamAllowancePoints(const VContainer *data) const -> QVector<VLayoutPoint>
|
2016-11-10 13:06:09 +01:00
|
|
|
{
|
2019-01-09 16:46:02 +01:00
|
|
|
return SeamAllowancePointsWithRotation(data, -1);
|
2016-11-10 13:06:09 +01:00
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::FullSeamAllowancePoints(const VContainer *data) const -> QVector<VLayoutPoint>
|
|
|
|
{
|
|
|
|
QVector<VLayoutPoint> points = SeamAllowancePointsWithRotation(data, -1);
|
|
|
|
|
|
|
|
QLineF const mirrorLine = SeamAllowanceMirrorLine(data);
|
|
|
|
if (!mirrorLine.isNull() && IsShowFullPiece())
|
|
|
|
{
|
|
|
|
points = VAbstractPiece::FullPath(points, mirrorLine);
|
|
|
|
points = CheckLoops(CorrectEquidistantPoints(points)); // A path can contains loops
|
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2018-07-26 19:00:24 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::CuttingPathPoints(const VContainer *data) const -> QVector<QPointF>
|
2018-07-26 19:00:24 +02:00
|
|
|
{
|
2022-10-28 12:55:24 +02:00
|
|
|
QVector<QPointF> points;
|
2022-10-28 15:16:02 +02:00
|
|
|
if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn())
|
2018-07-26 19:00:24 +02:00
|
|
|
{
|
2022-10-28 12:55:24 +02:00
|
|
|
CastTo(SeamAllowancePoints(data), points);
|
|
|
|
return points;
|
2018-07-26 19:00:24 +02:00
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
2022-10-28 12:55:24 +02:00
|
|
|
CastTo(MainPathPoints(data), points);
|
|
|
|
return points;
|
2018-07-26 19:00:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-28 12:09:00 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::PassmarksLines(const VContainer *data) const -> QVector<QLineF>
|
2019-05-08 14:19:03 +02:00
|
|
|
{
|
|
|
|
QVector<VPassmark> passmarks = Passmarks(data);
|
|
|
|
QVector<QLineF> lines;
|
2023-07-15 09:58:28 +02:00
|
|
|
for (auto &passmark : passmarks)
|
2019-05-08 14:19:03 +02:00
|
|
|
{
|
|
|
|
if (not passmark.IsNull())
|
|
|
|
{
|
|
|
|
lines += passmark.FullPassmark(*this, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::Passmarks(const VContainer *data) const -> QVector<VPassmark>
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2017-03-30 11:26:06 +02:00
|
|
|
const QVector<VPieceNode> unitedPath = GetUnitedPath(data);
|
|
|
|
if (not IsSeamAllowance() || not IsPassmarksPossible(unitedPath))
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2023-11-28 15:40:27 +01:00
|
|
|
return {};
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 14:19:03 +02:00
|
|
|
QVector<VPassmark> passmarks;
|
2017-03-28 12:09:00 +02:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
for (int i = 0; i < unitedPath.size(); ++i)
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2017-03-30 11:26:06 +02:00
|
|
|
const VPieceNode &node = unitedPath.at(i);
|
2017-03-28 12:09:00 +02:00
|
|
|
if (node.IsExcluded() || not node.IsPassmark())
|
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
continue; // skip node
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 16:23:11 +01:00
|
|
|
const vsizetype previousIndex = VPiecePath::FindInLoopNotExcludedUp(i, unitedPath);
|
|
|
|
const vsizetype nextIndex = VPiecePath::FindInLoopNotExcludedDown(i, unitedPath);
|
2017-03-28 12:09:00 +02:00
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
passmarks += CreatePassmark(unitedPath, previousIndex, i, nextIndex, data);
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return passmarks;
|
|
|
|
}
|
|
|
|
|
2018-04-02 15:49:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::CurvesPainterPath(const VContainer *data) const -> QVector<QPainterPath>
|
2018-04-02 15:49:53 +02:00
|
|
|
{
|
|
|
|
return GetPath().CurvesPainterPath(data);
|
|
|
|
}
|
|
|
|
|
2016-11-05 09:56:44 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MainPathPath(const VContainer *data) const -> QPainterPath
|
2016-11-05 09:56:44 +01:00
|
|
|
{
|
2022-10-28 12:55:24 +02:00
|
|
|
QVector<QPointF> points;
|
|
|
|
CastTo(MainPathPoints(data), points);
|
|
|
|
return VPiece::MainPathPath(points);
|
2018-04-02 15:49:53 +02:00
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::FullMainPathPath(const VContainer *data) const -> QPainterPath
|
|
|
|
{
|
|
|
|
QVector<QPointF> points;
|
|
|
|
CastTo(FullMainPathPoints(data), points);
|
|
|
|
return VPiece::MainPathPath(points);
|
|
|
|
}
|
|
|
|
|
2018-04-02 15:49:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MainPathPath(const QVector<QPointF> &points) -> QPainterPath
|
2018-04-02 15:49:53 +02:00
|
|
|
{
|
2016-11-05 09:56:44 +01:00
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
if (not points.isEmpty())
|
|
|
|
{
|
|
|
|
path.moveTo(points[0]);
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
|
|
|
{
|
|
|
|
path.lineTo(points.at(i));
|
|
|
|
}
|
|
|
|
path.lineTo(points.at(0));
|
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:53:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::SeamAllowancePath(const VContainer *data) const -> QPainterPath
|
2016-11-10 13:06:09 +01:00
|
|
|
{
|
2017-08-05 10:03:19 +02:00
|
|
|
return SeamAllowancePath(SeamAllowancePoints(data));
|
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::FullSeamAllowancePath(const VContainer *data) const -> QPainterPath
|
|
|
|
{
|
|
|
|
return SeamAllowancePath(FullSeamAllowancePoints(data));
|
|
|
|
}
|
|
|
|
|
2017-03-28 12:09:00 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::PassmarksPath(const VContainer *data) const -> QPainterPath
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2019-01-09 16:46:02 +01:00
|
|
|
const QVector<QLineF> passmarks = PassmarksLines(data);
|
2017-03-28 12:09:00 +02:00
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
// seam allowence
|
|
|
|
if (IsSeamAllowance())
|
|
|
|
{
|
|
|
|
if (not passmarks.isEmpty())
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < passmarks.count(); ++i)
|
|
|
|
{
|
|
|
|
path.moveTo(passmarks.at(i).p1());
|
|
|
|
path.lineTo(passmarks.at(i).p2());
|
|
|
|
}
|
|
|
|
|
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::PlaceLabelPath(const VContainer *data) const -> QPainterPath
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
QPainterPath path;
|
2023-07-15 09:58:28 +02:00
|
|
|
for (auto placeLabel : d->m_placeLabels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2019-05-08 14:19:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto label = data->GeometricObject<VPlaceLabelItem>(placeLabel);
|
|
|
|
if (label->IsVisible())
|
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
VLayoutPlaceLabel layoutLabel(*label);
|
|
|
|
path.addPath(LabelShapePath(layoutLabel));
|
|
|
|
|
|
|
|
const QLineF mirrorLine = SeamMirrorLine(data);
|
|
|
|
if (!label->IsNotMirrored() && IsShowFullPiece() && !mirrorLine.isNull())
|
|
|
|
{
|
|
|
|
PlaceLabelImg shape = VAbstractPiece::PlaceLabelShape(layoutLabel);
|
|
|
|
const QTransform matrix = VGObject::FlippingMatrix(mirrorLine);
|
|
|
|
for (auto &points : shape)
|
|
|
|
{
|
|
|
|
std::transform(points.begin(), points.end(), points.begin(),
|
|
|
|
[matrix](const VLayoutPoint &point) { return MapPoint(point, matrix); });
|
|
|
|
}
|
|
|
|
|
|
|
|
path.addPath(LabelShapePath(shape));
|
|
|
|
}
|
2019-05-08 14:19:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &e)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2019-05-08 14:19:03 +02:00
|
|
|
qWarning() << e.ErrorMessage();
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-08 14:19:03 +02:00
|
|
|
path.setFillRule(Qt::WindingFill);
|
2017-10-15 11:25:20 +02:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2019-02-23 17:43:06 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::IsSeamAllowanceValid(const VContainer *data) const -> bool
|
2019-02-23 17:43:06 +01:00
|
|
|
{
|
2019-03-01 16:20:21 +01:00
|
|
|
if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
2022-10-28 12:55:24 +02:00
|
|
|
QVector<QPointF> mainPathPoints;
|
|
|
|
CastTo<QPointF>(UniteMainPathPoints(data), mainPathPoints);
|
|
|
|
|
|
|
|
QVector<QPointF> seamAllowancePoints;
|
|
|
|
CastTo<QPointF>(SeamAllowancePoints(data), seamAllowancePoints);
|
|
|
|
|
|
|
|
return VAbstractPiece::IsAllowanceValid(mainPathPoints, seamAllowancePoints);
|
2019-03-01 16:20:21 +01:00
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
return true;
|
2019-02-23 17:43:06 +01:00
|
|
|
}
|
|
|
|
|
2016-11-09 13:11:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::IsInLayout() const -> bool
|
2016-11-09 14:53:22 +01:00
|
|
|
{
|
|
|
|
return d->m_inLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetInLayout(bool inLayout)
|
|
|
|
{
|
|
|
|
d->m_inLayout = inLayout;
|
|
|
|
}
|
|
|
|
|
2016-11-23 17:40:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::IsUnited() const -> bool
|
2016-11-23 17:40:27 +01:00
|
|
|
{
|
|
|
|
return d->m_united;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetUnited(bool united)
|
|
|
|
{
|
|
|
|
d->m_united = united;
|
|
|
|
}
|
|
|
|
|
2022-11-10 10:30:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::GetShortName() const -> QString
|
|
|
|
{
|
|
|
|
return d->m_shortName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetShortName(const QString &value)
|
|
|
|
{
|
|
|
|
d->m_shortName = value;
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetFormulaSAWidth() const -> QString
|
2017-01-21 14:24:40 +01:00
|
|
|
{
|
|
|
|
return d->m_formulaWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetFormulaSAWidth(const QString &formula, qreal value)
|
|
|
|
{
|
|
|
|
SetSAWidth(value);
|
|
|
|
const qreal width = GetSAWidth();
|
2023-10-07 17:56:39 +02:00
|
|
|
width >= 0 ? d->m_formulaWidth = formula : d->m_formulaWidth = '0'_L1;
|
2017-01-21 14:24:40 +01:00
|
|
|
}
|
|
|
|
|
2016-12-03 17:01:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetInternalPaths() const -> QVector<quint32>
|
2016-12-03 17:01:39 +01:00
|
|
|
{
|
|
|
|
return d->m_internalPaths;
|
|
|
|
}
|
|
|
|
|
2017-01-31 15:26:28 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetInternalPaths() -> QVector<quint32> &
|
2017-01-31 15:26:28 +01:00
|
|
|
{
|
|
|
|
return d->m_internalPaths;
|
|
|
|
}
|
|
|
|
|
2016-12-03 17:01:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetInternalPaths(const QVector<quint32> &iPaths)
|
|
|
|
{
|
|
|
|
d->m_internalPaths = iPaths;
|
|
|
|
}
|
|
|
|
|
2017-01-18 09:17:18 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetCustomSARecords() const -> QVector<CustomSARecord>
|
2017-01-18 09:17:18 +01:00
|
|
|
{
|
2017-01-31 15:26:28 +01:00
|
|
|
return d->m_customSARecords;
|
2017-01-18 09:17:18 +01:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:19:44 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetCustomSARecords() -> QVector<CustomSARecord> &
|
2016-11-25 13:19:44 +01:00
|
|
|
{
|
|
|
|
return d->m_customSARecords;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetCustomSARecords(const QVector<CustomSARecord> &records)
|
|
|
|
{
|
|
|
|
d->m_customSARecords = records;
|
|
|
|
}
|
|
|
|
|
2017-01-18 09:17:18 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPins() const -> QVector<quint32>
|
2017-01-31 15:26:28 +01:00
|
|
|
{
|
|
|
|
return d->m_pins;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPins() -> QVector<quint32> &
|
2017-01-31 15:26:28 +01:00
|
|
|
{
|
|
|
|
return d->m_pins;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetPins(const QVector<quint32> &pins)
|
2017-01-18 09:17:18 +01:00
|
|
|
{
|
2017-01-31 15:26:28 +01:00
|
|
|
d->m_pins = pins;
|
2017-01-18 09:17:18 +01:00
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPlaceLabels() const -> QVector<quint32>
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->m_placeLabels;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPlaceLabels() -> QVector<quint32> &
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->m_placeLabels;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetPlaceLabels(const QVector<quint32> &labels)
|
|
|
|
{
|
|
|
|
d->m_placeLabels = labels;
|
|
|
|
}
|
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::Dependencies() const -> QList<quint32>
|
2017-10-23 09:45:58 +02:00
|
|
|
{
|
|
|
|
QList<quint32> list = d->m_path.Dependencies();
|
2018-09-27 14:16:01 +02:00
|
|
|
list.reserve(list.size() + d->m_customSARecords.size() + d->m_internalPaths.size() + d->m_pins.size() +
|
|
|
|
d->m_placeLabels.size());
|
2017-10-23 09:45:58 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &record : d->m_customSARecords)
|
2017-10-23 09:45:58 +02:00
|
|
|
{
|
|
|
|
list.append(record.path);
|
|
|
|
}
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &value : d->m_internalPaths)
|
2017-10-23 09:45:58 +02:00
|
|
|
{
|
|
|
|
list.append(value);
|
|
|
|
}
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &value : d->m_pins)
|
2017-10-23 09:45:58 +02:00
|
|
|
{
|
|
|
|
list.append(value);
|
|
|
|
}
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &value : d->m_placeLabels)
|
2017-10-23 09:45:58 +02:00
|
|
|
{
|
|
|
|
list.append(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 13:11:58 +01:00
|
|
|
/**
|
2016-11-25 14:35:52 +01:00
|
|
|
* @brief MissingNodes find missing nodes in detail. When we deleted object in detail and return this detail need
|
2016-11-09 13:11:58 +01:00
|
|
|
* understand, what nodes need make invisible.
|
|
|
|
* @param det changed detail.
|
|
|
|
* @return list with missing nodes.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MissingNodes(const VPiece &det) const -> QVector<quint32>
|
2016-11-09 13:11:58 +01:00
|
|
|
{
|
2016-11-28 09:47:36 +01:00
|
|
|
return d->m_path.MissingNodes(det.GetPath());
|
2016-11-09 13:11:58 +01:00
|
|
|
}
|
|
|
|
|
2016-11-25 15:12:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MissingCSAPath(const VPiece &det) const -> QVector<quint32>
|
2016-11-25 15:12:33 +01:00
|
|
|
{
|
2017-01-31 17:09:18 +01:00
|
|
|
QVector<quint32> oldCSARecords;
|
2016-11-25 15:12:33 +01:00
|
|
|
for (qint32 i = 0; i < d->m_customSARecords.size(); ++i)
|
|
|
|
{
|
2017-01-31 17:09:18 +01:00
|
|
|
oldCSARecords.append(d->m_customSARecords.at(i).path);
|
2016-11-25 15:12:33 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 17:09:18 +01:00
|
|
|
QVector<quint32> newCSARecords;
|
|
|
|
for (qint32 i = 0; i < det.GetCustomSARecords().size(); ++i)
|
2016-11-25 15:12:33 +01:00
|
|
|
{
|
2017-01-31 17:09:18 +01:00
|
|
|
newCSARecords.append(det.GetCustomSARecords().at(i).path);
|
2016-11-25 15:12:33 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 17:09:18 +01:00
|
|
|
return PieceMissingNodes(oldCSARecords, newCSARecords);
|
2016-11-25 15:12:33 +01:00
|
|
|
}
|
|
|
|
|
2016-11-11 16:55:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MissingInternalPaths(const VPiece &det) const -> QVector<quint32>
|
2016-12-03 17:01:39 +01:00
|
|
|
{
|
2017-01-31 17:09:18 +01:00
|
|
|
return PieceMissingNodes(d->m_internalPaths, det.GetInternalPaths());
|
|
|
|
}
|
2016-12-03 17:01:39 +01:00
|
|
|
|
2017-01-31 17:09:18 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MissingPins(const VPiece &det) const -> QVector<quint32>
|
2017-01-31 17:09:18 +01:00
|
|
|
{
|
|
|
|
return PieceMissingNodes(d->m_pins, det.GetPins());
|
2016-12-03 17:01:39 +01:00
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MissingPlaceLabels(const VPiece &det) const -> QVector<quint32>
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return PieceMissingNodes(d->m_placeLabels, det.GetPlaceLabels());
|
|
|
|
}
|
|
|
|
|
2016-12-03 17:01:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-01-16 14:50:53 +01:00
|
|
|
void VPiece::SetPieceLabelData(const VPieceLabelData &data)
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
d->m_ppData = data;
|
2023-05-16 16:37:53 +02:00
|
|
|
d->m_ppData.SetAreaShortName(VPieceArea::PieceShortName(*this));
|
2017-01-12 14:51:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Returns full access to the pattern piece data object
|
|
|
|
* @return pattern piece data object
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPieceLabelData() -> VPieceLabelData &
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
return d->m_ppData;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Returns the read only reference to the pattern piece data object
|
|
|
|
* @return pattern piece data object
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPieceLabelData() const -> const VPieceLabelData &
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
return d->m_ppData;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-01-16 14:50:53 +01:00
|
|
|
void VPiece::SetPatternLabelData(const VPatternLabelData &info)
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
d->m_piPatternInfo = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Returns full access to the pattern info geometry object
|
|
|
|
* @return pattern info geometry object
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPatternLabelData() -> VPatternLabelData &
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
return d->m_piPatternInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Returns the read only reference to the pattern info geometry object
|
|
|
|
* @return pattern info geometry object
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPatternLabelData() const -> const VPatternLabelData &
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
return d->m_piPatternInfo;
|
|
|
|
}
|
|
|
|
|
2018-01-25 22:53:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetGrainlineGeometry(const VGrainlineData &data)
|
|
|
|
{
|
|
|
|
d->m_glGrainline = data;
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VDetail::GetGrainlineGeometry full access to the grainline geometry object
|
|
|
|
* @return reference to grainline geometry object
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetGrainlineGeometry() -> VGrainlineData &
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
return d->m_glGrainline;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VDetail::GetGrainlineGeometry returns the read-only reference to the grainline geometry object
|
|
|
|
* @return reference to grainline geometry object
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetGrainlineGeometry() const -> const VGrainlineData &
|
2017-01-12 14:51:08 +01:00
|
|
|
{
|
|
|
|
return d->m_glGrainline;
|
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetMirrorLineStartPoint(quint32 id)
|
|
|
|
{
|
|
|
|
d->m_mirrorLineStartPoint = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::GetMirrorLineStartPoint() const -> quint32
|
|
|
|
{
|
|
|
|
return d->m_mirrorLineStartPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetMirrorLineEndPoint(quint32 id)
|
|
|
|
{
|
|
|
|
d->m_mirrorLineEndPoint = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::GetMirrorLineEndPoint() const -> quint32
|
|
|
|
{
|
|
|
|
return d->m_mirrorLineEndPoint;
|
|
|
|
}
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::SeamAllowancePointsWithRotation(const VContainer *data, vsizetype makeFirst) const -> QVector<VLayoutPoint>
|
2019-01-09 16:46:02 +01:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr);
|
|
|
|
|
|
|
|
if (not IsSeamAllowance() || IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
return {};
|
2019-01-09 16:46:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<CustomSARecord> records = FilterRecords(GetValidRecords());
|
|
|
|
int recordIndex = -1;
|
|
|
|
bool insertingCSA = false;
|
|
|
|
const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit());
|
2023-07-15 09:58:28 +02:00
|
|
|
const QVector<VPieceNode> unitedPath =
|
|
|
|
makeFirst > 0 ? RotatePath(GetUnitedPath(data), makeFirst) : GetUnitedPath(data);
|
2019-01-09 16:46:02 +01:00
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
const QLineF mirrorLine = SeamMirrorLine(data);
|
|
|
|
const bool showMirrorLine = !mirrorLine.isNull();
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
QVector<VSAPoint> pointsEkv;
|
2023-07-15 09:58:28 +02:00
|
|
|
for (int i = 0; i < unitedPath.size(); ++i)
|
2019-01-09 16:46:02 +01:00
|
|
|
{
|
|
|
|
const VPieceNode &node = unitedPath.at(i);
|
|
|
|
if (node.IsExcluded())
|
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
continue; // skip excluded node
|
2019-01-09 16:46:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (node.GetTypeTool())
|
|
|
|
{
|
|
|
|
case (Tool::NodePoint):
|
|
|
|
{
|
|
|
|
if (not insertingCSA)
|
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
{
|
|
|
|
VSAPoint ekvPoint = VPiecePath::PreparePointEkv(node, data);
|
|
|
|
if (showMirrorLine && VFuzzyComparePoints(ekvPoint, mirrorLine.p1()))
|
|
|
|
{
|
|
|
|
ekvPoint.SetSAAfter(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showMirrorLine && VFuzzyComparePoints(ekvPoint, mirrorLine.p2()))
|
|
|
|
{
|
|
|
|
ekvPoint.SetSABefore(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pointsEkv.append(ekvPoint);
|
|
|
|
}
|
2019-01-09 16:46:02 +01:00
|
|
|
|
|
|
|
recordIndex = IsCSAStart(records, node.GetId());
|
|
|
|
if (recordIndex != -1 && records.at(recordIndex).includeType == PiecePathIncludeType::AsCustomSA)
|
|
|
|
{
|
|
|
|
insertingCSA = true;
|
|
|
|
|
|
|
|
const VPiecePath path = data->GetPiecePath(records.at(recordIndex).path);
|
|
|
|
QVector<VSAPoint> r = path.SeamAllowancePoints(data, width, records.at(recordIndex).reverse);
|
|
|
|
|
2023-11-28 15:40:27 +01:00
|
|
|
for (auto &j : r)
|
2019-01-09 16:46:02 +01:00
|
|
|
{
|
2023-10-10 09:36:30 +02:00
|
|
|
j.SetAngleType(PieceNodeAngle::ByLengthCurve);
|
|
|
|
j.SetSABefore(0);
|
|
|
|
j.SetSAAfter(0);
|
2019-01-09 16:46:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pointsEkv += r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (records.at(recordIndex).endPoint == node.GetId())
|
|
|
|
{
|
|
|
|
insertingCSA = false;
|
|
|
|
recordIndex = -1;
|
|
|
|
|
|
|
|
pointsEkv.append(VPiecePath::PreparePointEkv(node, data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (Tool::NodeArc):
|
|
|
|
case (Tool::NodeElArc):
|
|
|
|
case (Tool::NodeSpline):
|
|
|
|
case (Tool::NodeSplinePath):
|
|
|
|
{
|
|
|
|
if (not insertingCSA)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(node.GetId());
|
|
|
|
|
|
|
|
pointsEkv += VPiecePath::CurveSeamAllowanceSegment(data, unitedPath, curve, i, node.GetReverse(),
|
2020-10-05 15:39:01 +02:00
|
|
|
width, GetName());
|
2019-01-09 16:46:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2023-07-15 09:58:28 +02:00
|
|
|
qDebug() << "Get wrong tool type. Ignore." << static_cast<char>(node.GetTypeTool());
|
2019-01-09 16:46:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Equidistant(pointsEkv, width, GetName());
|
|
|
|
}
|
|
|
|
|
2021-08-31 11:07:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetGradationLabel(const QString &label)
|
|
|
|
{
|
|
|
|
d->m_gradationLabel = label;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetGradationLabel() const -> QString
|
2021-08-31 11:07:26 +02:00
|
|
|
{
|
|
|
|
return d->m_gradationLabel;
|
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::IsManualFoldHeight() const -> bool
|
|
|
|
{
|
|
|
|
return d->m_manualFoldHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetManualFoldHeight(bool value)
|
|
|
|
{
|
|
|
|
d->m_manualFoldHeight = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::IsManualFoldWidth() const -> bool
|
|
|
|
{
|
|
|
|
return d->m_manualFoldWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetManualFoldWidth(bool value)
|
|
|
|
{
|
|
|
|
d->m_manualFoldWidth = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::IsManualFoldCenter() const -> bool
|
|
|
|
{
|
|
|
|
return d->m_manualFoldCenter;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetManualFoldCenter(bool value)
|
|
|
|
{
|
|
|
|
d->m_manualFoldCenter = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::GetFormulaFoldHeight() const -> QString
|
|
|
|
{
|
|
|
|
return d->m_formulaFoldHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetFormulaFoldHeight(const QString &value)
|
|
|
|
{
|
|
|
|
d->m_formulaFoldHeight = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::GetFormulaFoldWidth() const -> QString
|
|
|
|
{
|
|
|
|
return d->m_formulaFoldWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetFormulaFoldWidth(const QString &value)
|
|
|
|
{
|
|
|
|
d->m_formulaFoldWidth = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::GetFormulaFoldCenter() const -> QString
|
|
|
|
{
|
|
|
|
return d->m_formulaFoldCenter;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::SetFormulaFoldCenter(const QString &value)
|
|
|
|
{
|
|
|
|
d->m_formulaFoldCenter = value;
|
|
|
|
}
|
|
|
|
|
2017-03-30 11:26:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetUnitedPath(const VContainer *data) const -> QVector<VPieceNode>
|
2017-03-30 11:26:06 +02:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
|
|
|
QVector<VPieceNode> united = d->m_path.GetNodes();
|
2017-04-05 12:22:33 +02:00
|
|
|
|
|
|
|
if (IsSeamAllowance() && IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
|
|
|
return united;
|
|
|
|
}
|
|
|
|
|
2017-03-30 11:26:06 +02:00
|
|
|
const QVector<CustomSARecord> records = FilterRecords(GetValidRecords());
|
|
|
|
|
|
|
|
for (int i = 0; i < records.size(); ++i)
|
|
|
|
{
|
|
|
|
if (records.at(i).includeType == PiecePathIncludeType::AsMainPath)
|
|
|
|
{
|
|
|
|
const int indexStartPoint = VPiecePath::indexOfNode(united, records.at(i).startPoint);
|
|
|
|
const int indexEndPoint = VPiecePath::indexOfNode(united, records.at(i).endPoint);
|
|
|
|
|
|
|
|
if (indexStartPoint == -1 || indexEndPoint == -1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-19 08:19:37 +01:00
|
|
|
QVector<VPieceNode> midBefore;
|
|
|
|
QVector<VPieceNode> midAfter;
|
|
|
|
if (indexStartPoint <= indexEndPoint)
|
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
midBefore = united.mid(0, indexStartPoint + 1);
|
2018-12-19 08:19:37 +01:00
|
|
|
midAfter = united.mid(indexEndPoint, united.size() - midBefore.size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
midBefore = united.mid(indexEndPoint, indexStartPoint + 1);
|
2018-12-19 08:19:37 +01:00
|
|
|
}
|
2017-03-30 11:26:06 +02:00
|
|
|
|
|
|
|
QVector<VPieceNode> customNodes = data->GetPiecePath(records.at(i).path).GetNodes();
|
|
|
|
if (records.at(i).reverse)
|
|
|
|
{
|
2020-07-13 15:28:13 +02:00
|
|
|
customNodes = Reverse(customNodes);
|
2017-04-05 12:22:33 +02:00
|
|
|
}
|
2017-03-30 11:26:06 +02:00
|
|
|
|
2017-04-05 12:22:33 +02:00
|
|
|
for (int j = 0; j < customNodes.size(); ++j)
|
|
|
|
{
|
2017-03-30 11:26:06 +02:00
|
|
|
// Additionally reverse all curves
|
2017-04-05 12:22:33 +02:00
|
|
|
if (records.at(i).reverse)
|
|
|
|
{
|
|
|
|
// don't make a check because node point will ignore the change
|
2017-03-30 11:26:06 +02:00
|
|
|
customNodes[j].SetReverse(not customNodes.at(j).GetReverse());
|
|
|
|
}
|
2017-04-05 12:22:33 +02:00
|
|
|
|
|
|
|
// If seam allowance is built in main path user will not see a passmark provided by piece path
|
|
|
|
if (IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
|
|
|
customNodes[j].SetPassmark(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
customNodes[j].SetMainPathNode(false);
|
|
|
|
}
|
2017-03-30 11:26:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
united = midBefore + customNodes + midAfter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return united;
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:51:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetValidRecords() const -> QVector<CustomSARecord>
|
2016-11-11 16:55:02 +01:00
|
|
|
{
|
2016-11-29 13:10:53 +01:00
|
|
|
QVector<CustomSARecord> records;
|
2018-09-27 14:16:01 +02:00
|
|
|
records.reserve(d->m_customSARecords.size());
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &record : d->m_customSARecords)
|
2016-11-11 19:17:39 +01:00
|
|
|
{
|
2017-03-22 11:05:53 +01:00
|
|
|
const int indexStartPoint = d->m_path.indexOfNode(record.startPoint);
|
|
|
|
const int indexEndPoint = d->m_path.indexOfNode(record.endPoint);
|
2016-11-11 16:55:02 +01:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
if (record.startPoint > NULL_ID && record.path > NULL_ID && record.endPoint > NULL_ID &&
|
|
|
|
indexStartPoint != -1 && not d->m_path.at(indexStartPoint).IsExcluded() && indexEndPoint != -1 &&
|
|
|
|
not d->m_path.at(indexEndPoint).IsExcluded())
|
2016-11-11 19:17:39 +01:00
|
|
|
{
|
2016-11-29 13:10:53 +01:00
|
|
|
records.append(record);
|
2016-11-11 19:17:39 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-29 13:10:53 +01:00
|
|
|
return records;
|
|
|
|
}
|
2016-11-11 19:17:39 +01:00
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::FilterRecords(QVector<CustomSARecord> records) const -> QVector<CustomSARecord>
|
2017-03-29 13:18:33 +02:00
|
|
|
{
|
|
|
|
if (records.size() < 2)
|
|
|
|
{
|
|
|
|
return records;
|
|
|
|
}
|
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
QVector<VPieceNode> path = d->m_path.GetNodes();
|
|
|
|
QVector<CustomSARecord> filteredRecords;
|
|
|
|
for (auto record : qAsConst(records))
|
2017-03-29 13:18:33 +02:00
|
|
|
{
|
2018-12-21 12:01:32 +01:00
|
|
|
const int indexStartPoint = VPiecePath::indexOfNode(path, record.startPoint);
|
|
|
|
const int indexEndPoint = VPiecePath::indexOfNode(path, record.endPoint);
|
|
|
|
|
|
|
|
if (indexStartPoint == -1 || indexEndPoint == -1)
|
2017-03-29 13:18:33 +02:00
|
|
|
{
|
2018-12-21 12:01:32 +01:00
|
|
|
continue;
|
2017-03-29 13:18:33 +02:00
|
|
|
}
|
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
QVector<VPieceNode> midBefore;
|
|
|
|
QVector<VPieceNode> midAfter;
|
|
|
|
if (indexStartPoint <= indexEndPoint)
|
2017-03-29 13:18:33 +02:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
midBefore = path.mid(0, indexStartPoint + 1);
|
2018-12-21 12:01:32 +01:00
|
|
|
midAfter = path.mid(indexEndPoint, path.size() - midBefore.size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
midBefore = path.mid(indexEndPoint, indexStartPoint + 1);
|
2017-03-29 13:18:33 +02:00
|
|
|
}
|
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
path = midBefore + midAfter;
|
|
|
|
filteredRecords.append(record);
|
|
|
|
}
|
2017-03-29 13:18:33 +02:00
|
|
|
|
2018-12-21 12:01:32 +01:00
|
|
|
return filteredRecords;
|
2017-03-29 13:18:33 +02:00
|
|
|
}
|
|
|
|
|
2017-03-28 12:09:00 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetNodeSAPoints(const QVector<VPieceNode> &path, vsizetype index, const VContainer *data) const
|
|
|
|
-> QVector<VSAPoint>
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
2017-03-30 11:26:06 +02:00
|
|
|
if (index < 0 || index >= path.size())
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2023-05-08 16:50:22 +02:00
|
|
|
return {};
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
2017-03-30 11:26:06 +02:00
|
|
|
const VPieceNode &node = path.at(index);
|
2017-03-28 12:09:00 +02:00
|
|
|
QVector<VSAPoint> points;
|
|
|
|
|
|
|
|
if (node.GetTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
points.append(VPiecePath::PreparePointEkv(node, data));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(node.GetId());
|
|
|
|
const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit());
|
|
|
|
|
2020-10-05 15:39:01 +02:00
|
|
|
points += VPiecePath::CurveSeamAllowanceSegment(data, path, curve, index, node.GetReverse(), width, GetName());
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPassmarkSAPoint(const QVector<VPieceNode> &path, vsizetype index, const VContainer *data,
|
|
|
|
VSAPoint &point) const -> bool
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
2017-03-30 11:26:06 +02:00
|
|
|
const QVector<VSAPoint> points = GetNodeSAPoints(path, index, data);
|
2017-03-28 12:09:00 +02:00
|
|
|
|
|
|
|
if (points.isEmpty() || points.size() > 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-12 11:03:28 +02:00
|
|
|
point = points.constFirst();
|
2017-03-28 12:09:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPassmarkPreviousSAPoints(const QVector<VPieceNode> &path, vsizetype index,
|
2023-02-09 16:23:11 +01:00
|
|
|
const VSAPoint &passmarkSAPoint, const VContainer *data, VSAPoint &point,
|
2023-05-03 13:07:02 +02:00
|
|
|
vsizetype passmarkIndex) const -> bool
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
2017-04-25 19:48:32 +02:00
|
|
|
const QVector<VSAPoint> points = GetNodeSAPoints(path, index, data);
|
2017-03-28 12:09:00 +02:00
|
|
|
|
2017-04-25 19:48:32 +02:00
|
|
|
if (points.isEmpty())
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2019-09-10 15:57:31 +02:00
|
|
|
const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.")
|
2023-07-15 09:58:28 +02:00
|
|
|
.arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VExceptionInvalidNotch(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2017-04-25 19:48:32 +02:00
|
|
|
return false; // Something wrong
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool found = false;
|
2023-07-15 09:58:28 +02:00
|
|
|
auto nodeIndex = points.size() - 1;
|
2017-03-28 12:09:00 +02:00
|
|
|
do
|
|
|
|
{
|
2017-04-25 19:48:32 +02:00
|
|
|
const VSAPoint previous = points.at(nodeIndex);
|
2019-07-02 18:41:49 +02:00
|
|
|
QLineF line(passmarkSAPoint, previous);
|
2023-04-12 20:05:29 +02:00
|
|
|
if (line.length() > accuracyPointOnLine)
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2017-04-25 19:48:32 +02:00
|
|
|
point = previous;
|
2017-03-28 12:09:00 +02:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
--nodeIndex;
|
|
|
|
} while (nodeIndex >= 0 && not found);
|
|
|
|
|
|
|
|
if (not found)
|
|
|
|
{
|
2018-09-29 21:01:13 +02:00
|
|
|
// No warning here because of valid case of passmark collapse
|
2017-04-25 19:48:32 +02:00
|
|
|
return false; // Something wrong
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
2017-04-25 19:48:32 +02:00
|
|
|
return true;
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::GetPassmarkNextSAPoints(const QVector<VPieceNode> &path, vsizetype index, const VSAPoint &passmarkSAPoint,
|
|
|
|
const VContainer *data, VSAPoint &point, vsizetype passmarkIndex) const -> bool
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2017-04-25 19:48:32 +02:00
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
|
|
|
const QVector<VSAPoint> points = GetNodeSAPoints(path, index, data);
|
2017-03-28 12:09:00 +02:00
|
|
|
|
2017-04-25 19:48:32 +02:00
|
|
|
if (points.isEmpty())
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2019-09-10 15:57:31 +02:00
|
|
|
const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.")
|
2023-07-15 09:58:28 +02:00
|
|
|
.arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VExceptionInvalidNotch(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2017-04-25 19:48:32 +02:00
|
|
|
return false; // Something wrong
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
int nodeIndex = 0;
|
|
|
|
do
|
|
|
|
{
|
2017-04-25 19:48:32 +02:00
|
|
|
const VSAPoint next = points.at(nodeIndex);
|
2019-07-02 18:41:49 +02:00
|
|
|
QLineF line(passmarkSAPoint, next);
|
|
|
|
if (line.length() >= ToPixel(1, Unit::Mm))
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2017-04-25 19:48:32 +02:00
|
|
|
point = next;
|
2017-03-28 12:09:00 +02:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
++nodeIndex;
|
|
|
|
|
2017-04-25 19:48:32 +02:00
|
|
|
} while (nodeIndex < points.size() && not found);
|
2017-03-28 12:09:00 +02:00
|
|
|
|
|
|
|
if (not found)
|
|
|
|
{
|
2018-09-29 21:01:13 +02:00
|
|
|
// No warning here because of valid case of passmark collapse
|
2017-04-25 19:48:32 +02:00
|
|
|
return false; // Something wrong
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
2017-04-25 19:48:32 +02:00
|
|
|
return true;
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::IsPassmarkVisible(const QVector<VPieceNode> &path, vsizetype passmarkIndex) const -> bool
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2017-03-30 11:26:06 +02:00
|
|
|
if (passmarkIndex < 0 || passmarkIndex >= path.size())
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-30 11:26:06 +02:00
|
|
|
const VPieceNode &node = path.at(passmarkIndex);
|
2017-03-28 12:09:00 +02:00
|
|
|
if (node.GetTypeTool() != Tool::NodePoint || not node.IsPassmark() || node.IsExcluded())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-05 12:22:33 +02:00
|
|
|
if (IsSeamAllowance() && IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-28 12:09:00 +02:00
|
|
|
const QVector<CustomSARecord> records = FilterRecords(GetValidRecords());
|
|
|
|
if (records.isEmpty())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &record : records)
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
if (record.includeType == PiecePathIncludeType::AsCustomSA)
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const int indexStartPoint = VPiecePath::indexOfNode(path, record.startPoint);
|
|
|
|
const int indexEndPoint = VPiecePath::indexOfNode(path, record.endPoint);
|
2017-03-30 11:26:06 +02:00
|
|
|
if (passmarkIndex > indexStartPoint && passmarkIndex < indexEndPoint)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::CreatePassmark(const QVector<VPieceNode> &path, vsizetype previousIndex, vsizetype passmarkIndex,
|
|
|
|
vsizetype nextIndex, const VContainer *data) const -> VPassmark
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr);
|
|
|
|
|
2017-03-30 11:26:06 +02:00
|
|
|
if (not IsPassmarkVisible(path, passmarkIndex))
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2023-05-08 16:50:22 +02:00
|
|
|
return {};
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VSAPoint passmarkSAPoint;
|
2017-03-30 11:26:06 +02:00
|
|
|
if (not GetPassmarkSAPoint(path, passmarkIndex, data, passmarkSAPoint))
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2019-09-10 15:57:31 +02:00
|
|
|
const QString errorMsg = tr("Cannot calculate a notch for point '%1' in piece '%2'.")
|
2023-07-15 09:58:28 +02:00
|
|
|
.arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VExceptionInvalidNotch(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2023-05-08 16:50:22 +02:00
|
|
|
return {};
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:48:32 +02:00
|
|
|
VSAPoint previousSAPoint;
|
2018-09-29 21:01:13 +02:00
|
|
|
if (not GetPassmarkPreviousSAPoints(path, previousIndex, passmarkSAPoint, data, previousSAPoint, passmarkIndex))
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2018-09-29 18:36:55 +02:00
|
|
|
// No check here because it will cover valid cases
|
2023-05-08 16:50:22 +02:00
|
|
|
return {}; // Something wrong
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:48:32 +02:00
|
|
|
VSAPoint nextSAPoint;
|
2018-09-29 21:01:13 +02:00
|
|
|
if (not GetPassmarkNextSAPoints(path, nextIndex, passmarkSAPoint, data, nextSAPoint, passmarkIndex))
|
2017-03-28 12:09:00 +02:00
|
|
|
{
|
2018-09-29 18:36:55 +02:00
|
|
|
// No check here because it will cover valid cases
|
2023-05-08 16:50:22 +02:00
|
|
|
return {}; // Something wrong
|
2019-05-08 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (passmarkSAPoint.IsManualPasskmarkLength() && passmarkSAPoint.GetPasskmarkLength() <= 0)
|
|
|
|
{
|
2023-05-08 16:50:22 +02:00
|
|
|
return {};
|
2017-03-28 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
if (passmarkSAPoint.IsManualPasskmarkLength() && passmarkSAPoint.GetPasskmarkLength() <= accuracyPointOnLine)
|
2020-01-10 11:19:07 +01:00
|
|
|
{
|
|
|
|
const QString infoMsg = tr("Notch for point '%1' in piece '%2' will be disabled. Manual length is less than "
|
2023-07-15 09:58:28 +02:00
|
|
|
"allowed value.")
|
|
|
|
.arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName());
|
2020-11-20 12:18:38 +01:00
|
|
|
qInfo() << VAbstractValApplication::warningMessageSignature + infoMsg;
|
2023-05-08 16:50:22 +02:00
|
|
|
return {};
|
2020-01-10 11:19:07 +01:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:22:52 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wnoexcept")
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
VPiecePassmarkData passmarkData;
|
|
|
|
passmarkData.previousSAPoint = previousSAPoint;
|
|
|
|
passmarkData.passmarkSAPoint = passmarkSAPoint;
|
|
|
|
passmarkData.nextSAPoint = nextSAPoint;
|
|
|
|
passmarkData.saWidth = ToPixel(GetSAWidth(), *data->GetPatternUnit());
|
|
|
|
passmarkData.nodeName = VPiecePath::NodeName(path, passmarkIndex, data);
|
|
|
|
passmarkData.pieceName = GetName();
|
|
|
|
passmarkData.passmarkLineType = path.at(passmarkIndex).GetPassmarkLineType();
|
|
|
|
passmarkData.passmarkAngleType = path.at(passmarkIndex).GetPassmarkAngleType();
|
2019-05-08 14:19:03 +02:00
|
|
|
passmarkData.isMainPathNode = path.at(passmarkIndex).IsMainPathNode();
|
|
|
|
passmarkData.isShowSecondPassmark = path.at(passmarkIndex).IsShowSecondPassmark();
|
|
|
|
passmarkData.passmarkIndex = passmarkIndex;
|
|
|
|
passmarkData.id = path.at(passmarkIndex).GetId();
|
2021-05-10 15:39:17 +02:00
|
|
|
passmarkData.globalPassmarkLength = ToPixel(GlobalPassmarkLength(data), *data->GetPatternUnit());
|
2023-05-06 19:01:15 +02:00
|
|
|
passmarkData.globalPassmarkWidth = ToPixel(GlobalPassmarkWidth(data), *data->GetPatternUnit());
|
2019-01-09 16:46:02 +01:00
|
|
|
|
2022-11-10 10:55:50 +01:00
|
|
|
// cppcheck-suppress unknownMacro
|
2022-10-08 13:22:52 +02:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2019-05-08 14:19:03 +02:00
|
|
|
return VPassmark(passmarkData);
|
2017-04-05 12:22:33 +02:00
|
|
|
}
|
|
|
|
|
2016-11-29 13:10:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::IsCSAStart(const QVector<CustomSARecord> &records, quint32 id) -> int
|
2016-11-29 13:10:53 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < records.size(); ++i)
|
|
|
|
{
|
|
|
|
if (records.at(i).startPoint == id)
|
2016-11-11 19:17:39 +01:00
|
|
|
{
|
2016-11-29 13:10:53 +01:00
|
|
|
return i;
|
2016-11-11 19:17:39 +01:00
|
|
|
}
|
2016-11-11 16:55:02 +01:00
|
|
|
}
|
2016-11-29 13:10:53 +01:00
|
|
|
|
|
|
|
return -1;
|
2016-11-11 16:55:02 +01:00
|
|
|
}
|
2019-08-29 14:01:27 +02:00
|
|
|
|
2023-01-18 15:46:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::Area(const QVector<QPointF> &shape, const VContainer *data) const -> qreal
|
2023-01-18 15:46:01 +01:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
const qreal mainArea = qAbs(VAbstractPiece::SumTrapezoids(shape)) / 2.0;
|
2023-01-18 15:46:01 +01:00
|
|
|
|
|
|
|
qreal internalPathArea = 0;
|
|
|
|
const QVector<quint32> pathsId = GetInternalPaths();
|
|
|
|
for (auto id : pathsId)
|
|
|
|
{
|
|
|
|
const VPiecePath path = data->GetPiecePath(id);
|
|
|
|
if (path.GetType() != PiecePathType::InternalPath || not path.IsVisible(data->DataVariables()) ||
|
|
|
|
not path.IsCutPath())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QPointF> points;
|
|
|
|
CastTo(path.PathPoints(data, shape), points);
|
2023-08-12 11:03:28 +02:00
|
|
|
if (points.isEmpty() || not VFuzzyComparePoints(points.constFirst(), points.constLast()))
|
2023-01-18 15:46:01 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
internalPathArea += qAbs(VAbstractPiece::SumTrapezoids(points)) / 2.0;
|
2023-01-18 15:46:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return mainArea - internalPathArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::GlobalPassmarkLength(const VContainer *data) const -> qreal
|
|
|
|
{
|
|
|
|
QString passmarkLengthVariable = VAbstractValApplication::VApp()->getCurrentDocument()->GetPassmarkLengthVariable();
|
|
|
|
if (passmarkLengthVariable.isEmpty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-08 16:50:22 +02:00
|
|
|
qreal length = 0;
|
|
|
|
|
2023-01-18 15:46:01 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
QSharedPointer<VInternalVariable> var = data->GetVariable<VInternalVariable>(passmarkLengthVariable);
|
|
|
|
length = *var->GetValue();
|
|
|
|
|
|
|
|
if (VAbstractValApplication::VApp()->toPixel(length) <= accuracyPointOnLine)
|
|
|
|
{
|
|
|
|
const QString errorMsg = QObject::tr("Invalid global value for a passmark length. Piece '%1'. Length is "
|
|
|
|
"less than minimal allowed.")
|
|
|
|
.arg(GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VException(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2023-05-06 19:01:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VPiece::GlobalPassmarkWidth(const VContainer *data) const
|
|
|
|
{
|
|
|
|
QString passmarkWidthVariable = VAbstractValApplication::VApp()->getCurrentDocument()->GetPassmarkWidthVariable();
|
|
|
|
if (passmarkWidthVariable.isEmpty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal width = 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QSharedPointer<VInternalVariable> var = data->GetVariable<VInternalVariable>(passmarkWidthVariable);
|
|
|
|
width = *var->GetValue();
|
|
|
|
|
|
|
|
if (VAbstractValApplication::VApp()->toPixel(width) <= accuracyPointOnLine)
|
|
|
|
{
|
|
|
|
const QString errorMsg = QObject::tr("Invalid global value for a passmark width. Piece '%1'. Width is "
|
|
|
|
"less than minimal allowed.")
|
|
|
|
.arg(GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VException(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
#if !defined(V_NO_ASSERT)
|
|
|
|
// Use for writing tests
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::MainPathToJson() const -> QJsonObject
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
QJsonObject pieceObject{
|
2019-08-29 14:01:27 +02:00
|
|
|
{"seamAllowance", IsSeamAllowance()},
|
|
|
|
{"saWidth", GetSAWidth()},
|
|
|
|
};
|
|
|
|
|
|
|
|
QJsonArray nodesArray;
|
|
|
|
for (qint32 i = 0; i < d->m_path.CountNodes(); ++i)
|
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
QJsonObject nodeObject{
|
2019-08-29 14:01:27 +02:00
|
|
|
{"id", static_cast<qint64>(d->m_path.at(i).GetId())},
|
|
|
|
{"type", static_cast<int>(d->m_path.at(i).GetTypeTool())},
|
|
|
|
{"reverse", d->m_path.at(i).GetReverse()},
|
|
|
|
};
|
|
|
|
|
|
|
|
nodesArray.append(nodeObject);
|
|
|
|
}
|
2023-10-07 17:56:39 +02:00
|
|
|
pieceObject["nodes"_L1] = nodesArray;
|
2019-08-29 14:01:27 +02:00
|
|
|
|
|
|
|
return pieceObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPiece::DBToJson(const VContainer *data) const -> QJsonObject
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
QJsonArray itemsArray;
|
|
|
|
for (qint32 i = 0; i < d->m_path.CountNodes(); ++i)
|
|
|
|
{
|
|
|
|
itemsArray.append(data->GetGObject(d->m_path.at(i).GetId())->ToJson());
|
|
|
|
}
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
QJsonObject dbObject{{"items", itemsArray}};
|
2019-08-29 14:01:27 +02:00
|
|
|
|
|
|
|
return dbObject;
|
|
|
|
}
|
|
|
|
|
2021-05-10 15:39:17 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-01-18 15:46:01 +01:00
|
|
|
void VPiece::DumpPiece(const VPiece &piece, const VContainer *data, const QString &templateName)
|
2021-05-10 15:39:17 +02:00
|
|
|
{
|
2023-01-18 15:46:01 +01:00
|
|
|
SCASSERT(data != nullptr)
|
2023-07-15 09:58:28 +02:00
|
|
|
QTemporaryFile temp; // Go to tmp folder to find dump
|
2023-01-18 15:46:01 +01:00
|
|
|
temp.setAutoRemove(false); // Remove dump manually
|
|
|
|
|
|
|
|
if (not templateName.isEmpty())
|
2021-05-10 15:39:17 +02:00
|
|
|
{
|
2023-01-18 15:46:01 +01:00
|
|
|
temp.setFileTemplate(QDir::tempPath() + QDir::separator() + templateName);
|
2021-05-10 15:39:17 +02:00
|
|
|
}
|
|
|
|
|
2023-01-18 15:46:01 +01:00
|
|
|
if (temp.open())
|
2021-05-10 15:39:17 +02:00
|
|
|
{
|
2023-01-18 15:46:01 +01:00
|
|
|
#if defined(Q_OS_LINUX)
|
2023-07-15 09:58:28 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
|
|
// On Linux, QTemporaryFile will attempt to create unnamed temporary
|
|
|
|
// files. If that succeeds, open() will return true but exists() will be
|
|
|
|
// false. If you call fileName() or any function that calls it,
|
|
|
|
// QTemporaryFile will give the file a name, so most applications will
|
|
|
|
// not see a difference.
|
2023-01-18 15:46:01 +01:00
|
|
|
temp.fileName(); // call to create a file on disk
|
|
|
|
#endif
|
2023-07-15 09:58:28 +02:00
|
|
|
#endif
|
|
|
|
QJsonObject testCase{
|
2023-01-18 15:46:01 +01:00
|
|
|
{"bd", piece.DBToJson(data)},
|
|
|
|
{"piece", piece.MainPathToJson()},
|
|
|
|
};
|
2021-05-10 15:39:17 +02:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
QJsonObject json{
|
2023-01-18 15:46:01 +01:00
|
|
|
{"testCase", testCase},
|
|
|
|
};
|
2021-05-10 15:39:17 +02:00
|
|
|
|
2023-01-18 15:46:01 +01:00
|
|
|
QJsonDocument document(json);
|
|
|
|
|
|
|
|
QTextStream out(&temp);
|
|
|
|
out << document.toJson();
|
|
|
|
out.flush();
|
|
|
|
}
|
2021-05-10 15:39:17 +02:00
|
|
|
}
|
2023-01-18 15:46:01 +01:00
|
|
|
#endif // !defined(V_NO_ASSERT)
|
2021-05-10 15:39:17 +02:00
|
|
|
|
2022-11-10 10:30:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::TestInternalPathCuttingPathIntersection(const VContainer *data) const
|
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
|
|
|
const QVector<QPointF> cuttingPoints = CuttingPathPoints(data);
|
2023-05-02 16:38:30 +02:00
|
|
|
const QPainterPath contourPath = VGObject::PainterPath(cuttingPoints);
|
2022-11-10 10:30:08 +01:00
|
|
|
|
|
|
|
// Internal path for cutting must not intersect cutting contour and be inside of it.
|
|
|
|
const QVector<quint32> pathsId = GetInternalPaths();
|
|
|
|
for (auto id : pathsId)
|
|
|
|
{
|
|
|
|
const VPiecePath path = data->GetPiecePath(id);
|
|
|
|
if (path.GetType() != PiecePathType::InternalPath || not path.IsVisible(data->DataVariables()) ||
|
|
|
|
not path.IsCutPath())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QPointF> points;
|
|
|
|
CastTo(path.PathPoints(data, cuttingPoints), points);
|
2023-08-12 11:03:28 +02:00
|
|
|
if (points.isEmpty() || not VFuzzyComparePoints(points.constFirst(), points.constLast()))
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
const QPainterPath internalPath = VGObject::PainterPath(points);
|
2022-11-10 10:30:08 +01:00
|
|
|
|
|
|
|
if (internalPath.intersects(contourPath))
|
|
|
|
{
|
|
|
|
const QString errorMsg = QObject::tr("Piece '%1'. Internal path '%2' intersects with cutting "
|
2023-07-15 09:58:28 +02:00
|
|
|
"contour.")
|
|
|
|
.arg(GetName(), path.GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VExceptionObjectError(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2022-11-10 10:30:08 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not contourPath.contains(internalPath))
|
|
|
|
{
|
|
|
|
const QString errorMsg = QObject::tr("Piece '%1'. Internal path '%2' not inside of cutting "
|
2023-07-15 09:58:28 +02:00
|
|
|
"contour.")
|
|
|
|
.arg(GetName(), path.GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VExceptionObjectError(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::TestInternalPathsIntersections(const VContainer *data) const
|
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
|
|
|
const QVector<quint32> pathsId = GetInternalPaths();
|
|
|
|
|
|
|
|
if (pathsId.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<QPointF> cuttingPoints = CuttingPathPoints(data);
|
|
|
|
|
|
|
|
// Internal pieces for cutting must not intersect
|
|
|
|
QSet<QPair<int, int>> pairs;
|
2023-07-15 09:58:28 +02:00
|
|
|
for (int k = 0; k < pathsId.size(); ++k)
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
|
|
|
const VPiecePath path1 = data->GetPiecePath(pathsId.at(k));
|
|
|
|
|
|
|
|
if (path1.GetType() != PiecePathType::InternalPath || not path1.IsVisible(data->DataVariables()) ||
|
|
|
|
not path1.IsCutPath())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QPointF> pointsPath1;
|
|
|
|
CastTo(path1.PathPoints(data, cuttingPoints), pointsPath1);
|
2023-08-12 11:03:28 +02:00
|
|
|
if (pointsPath1.isEmpty() || not VFuzzyComparePoints(pointsPath1.constFirst(), pointsPath1.constLast()))
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
const QPainterPath painterPath1 = VGObject::PainterPath(pointsPath1);
|
2022-11-10 10:30:08 +01:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
for (int i = 0; i < pathsId.size(); ++i)
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
|
|
|
if (k == i || pairs.contains(qMakePair(k, i)) || pairs.contains(qMakePair(i, k)))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VPiecePath path2 = data->GetPiecePath(pathsId.at(i));
|
|
|
|
|
|
|
|
if (path2.GetType() != PiecePathType::InternalPath || not path2.IsVisible(data->DataVariables()) ||
|
|
|
|
not path2.IsCutPath())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QPointF> pointsPath2;
|
|
|
|
CastTo(path2.PathPoints(data, cuttingPoints), pointsPath2);
|
2023-08-12 11:03:28 +02:00
|
|
|
if (pointsPath2.isEmpty() || not VFuzzyComparePoints(pointsPath2.constFirst(), pointsPath2.constLast()))
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
const QPainterPath painterPath2 = VGObject::PainterPath(pointsPath2);
|
2022-11-10 10:30:08 +01:00
|
|
|
|
|
|
|
pairs.insert(qMakePair(k, i));
|
|
|
|
pairs.insert(qMakePair(i, k));
|
|
|
|
|
|
|
|
if (painterPath1.intersects(painterPath2))
|
|
|
|
{
|
|
|
|
const QString errorMsg = QObject::tr("Piece '%1'. Internal path '%2' intersects with internal path "
|
2023-07-15 09:58:28 +02:00
|
|
|
"'%3'.")
|
|
|
|
.arg(GetName(), path1.GetName(), path2.GetName());
|
|
|
|
VAbstractApplication::VApp()->IsPedantic()
|
|
|
|
? throw VExceptionObjectError(errorMsg)
|
|
|
|
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPiece::TestInternalPaths(const VContainer *data) const
|
|
|
|
{
|
|
|
|
TestInternalPathCuttingPathIntersection(data);
|
|
|
|
TestInternalPathsIntersections(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-12-31 13:46:01 +01:00
|
|
|
auto VPiece::ExternalArea(const VContainer *data) const -> qreal
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
2022-12-31 13:46:01 +01:00
|
|
|
return Area(CuttingPathPoints(data), data);
|
|
|
|
}
|
2022-11-10 10:30:08 +01:00
|
|
|
|
2022-12-31 13:46:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::SeamLineArea(const VContainer *data) const -> qreal
|
|
|
|
{
|
|
|
|
QVector<QPointF> shape;
|
|
|
|
CastTo(MainPathPoints(data), shape);
|
|
|
|
return Area(shape, data);
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::SeamMirrorLine(const VContainer *data) const -> QLineF
|
|
|
|
{
|
|
|
|
Q_UNUSED(data);
|
|
|
|
|
|
|
|
if (d->m_mirrorLineStartPoint == d->m_mirrorLineEndPoint || d->m_mirrorLineStartPoint == NULL_ID ||
|
|
|
|
d->m_mirrorLineEndPoint == NULL_ID)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const QSharedPointer<VPointF> startPoint = data->GeometricObject<VPointF>(d->m_mirrorLineStartPoint);
|
|
|
|
const QSharedPointer<VPointF> endPoint = data->GeometricObject<VPointF>(d->m_mirrorLineEndPoint);
|
|
|
|
|
|
|
|
return {startPoint->toQPointF(), endPoint->toQPointF()};
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::SeamAllowanceMirrorLine(const VContainer *data) const -> QLineF
|
|
|
|
{
|
|
|
|
QLineF seamMirrorLine = SeamMirrorLine(data);
|
|
|
|
|
|
|
|
if (!IsSeamAllowance() || (IsSeamAllowance() && IsSeamAllowanceBuiltIn()))
|
|
|
|
{
|
|
|
|
return seamMirrorLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF rec = QRectF(0, 0, INT_MAX, INT_MAX);
|
|
|
|
rec.translate(-INT_MAX / 2.0, -INT_MAX / 2.0);
|
|
|
|
|
2024-01-13 07:33:22 +01:00
|
|
|
QLineF axis = QLineF(LineCenter(seamMirrorLine),
|
|
|
|
VGObject::BuildRay(LineCenter(seamMirrorLine), seamMirrorLine.angle() + 180, rec));
|
2024-01-06 13:20:56 +01:00
|
|
|
|
|
|
|
QVector<QPointF> points;
|
|
|
|
CastTo(SeamAllowancePoints(data), points);
|
|
|
|
|
|
|
|
QVector<QPointF> intersections = VAbstractCurve::CurveIntersectLine(points, axis);
|
|
|
|
if (intersections.isEmpty())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const QPointF startPoint = intersections.constFirst();
|
|
|
|
|
|
|
|
std::reverse(points.begin(), points.end());
|
2024-01-13 07:33:22 +01:00
|
|
|
axis =
|
|
|
|
QLineF(LineCenter(seamMirrorLine), VGObject::BuildRay(LineCenter(seamMirrorLine), seamMirrorLine.angle(), rec));
|
2024-01-06 13:20:56 +01:00
|
|
|
intersections = VAbstractCurve::CurveIntersectLine(points, axis);
|
|
|
|
if (intersections.isEmpty())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {startPoint, intersections.constFirst()};
|
|
|
|
}
|
|
|
|
|
2022-11-10 10:30:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPiece::ShortNameRegExp() -> QString
|
|
|
|
{
|
|
|
|
static QString regex;
|
|
|
|
|
|
|
|
if (regex.isEmpty())
|
|
|
|
{
|
|
|
|
const QList<QLocale> allLocales =
|
|
|
|
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
|
|
|
|
|
|
|
|
QString positiveSigns;
|
|
|
|
QString negativeSigns;
|
|
|
|
QString decimalPoints;
|
|
|
|
QString groupSeparators;
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
for (const auto &locale : allLocales)
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not positiveSigns.contains(LocalePositiveSign(locale)))
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
positiveSigns.append(LocalePositiveSign(locale));
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not negativeSigns.contains(LocaleNegativeSign(locale)))
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
negativeSigns.append(LocaleNegativeSign(locale));
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not decimalPoints.contains(LocaleDecimalPoint(locale)))
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
decimalPoints.append(LocaleDecimalPoint(locale));
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 14:42:34 +01:00
|
|
|
if (not groupSeparators.contains(LocaleGroupSeparator(locale)))
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
groupSeparators.append(LocaleGroupSeparator(locale));
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
negativeSigns.replace('-'_L1, "\\-"_L1);
|
|
|
|
groupSeparators.remove('\''_L1);
|
2022-11-10 10:30:08 +01:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
// Same regexp in pattern.xsd shema file. Don't forget to synchronize.
|
|
|
|
// \p{Zs} - \p{Space_Separator}
|
|
|
|
// Here we use permanent start of string and end of string anchors \A and \z to match whole pattern as one
|
|
|
|
// string. In some cases, a user may pass multiline or line that ends with a new line. To cover case with a new
|
|
|
|
// line at the end of string use /z anchor.
|
2022-11-10 10:30:08 +01:00
|
|
|
regex = QStringLiteral("\\A([^\\p{Zs}*\\/&|!<>^\\n\\()%1%2%3%4=?:;\"]){0,}\\z")
|
|
|
|
.arg(negativeSigns, positiveSigns, decimalPoints, groupSeparators);
|
|
|
|
}
|
|
|
|
|
|
|
|
return regex;
|
|
|
|
}
|