2016-11-08 11:57:01 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 6 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-08 11:57:01 +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-08 11:57:01 +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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VTOOLSEAMALLOWANCE_H
|
|
|
|
#define VTOOLSEAMALLOWANCE_H
|
|
|
|
|
2016-12-03 17:51:36 +01:00
|
|
|
#include <QGraphicsPathItem>
|
2023-05-02 16:38:30 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QtGlobal>
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2017-01-19 11:23:42 +01:00
|
|
|
#include "../vwidgets/vgrainlineitem.h"
|
2023-05-02 16:38:30 +02:00
|
|
|
#include "../vwidgets/vtextgraphicsitem.h"
|
|
|
|
#include "vinteractivetool.h"
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
class DialogTool;
|
2017-01-19 11:23:42 +01:00
|
|
|
class VNoBrushScalePathItem;
|
2024-01-06 13:20:56 +01:00
|
|
|
class VFoldLine;
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2017-09-21 09:05:58 +02:00
|
|
|
struct VToolSeamAllowanceInitData : VAbstractToolInitData
|
2017-09-18 10:37:23 +02:00
|
|
|
{
|
2023-05-02 16:38:30 +02:00
|
|
|
VToolSeamAllowanceInitData() = default;
|
|
|
|
|
|
|
|
VPiece detail{}; // NOLINT(misc-non-private-member-variables-in-classes)
|
|
|
|
QString width{'0'}; // NOLINT(misc-non-private-member-variables-in-classes)
|
|
|
|
QString drawName{}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2017-09-18 10:37:23 +02:00
|
|
|
};
|
|
|
|
|
2024-03-02 14:24:09 +01:00
|
|
|
class VToolSeamAllowance final : public VInteractiveTool, public QGraphicsPathItem
|
2016-11-08 11:57:01 +01:00
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_OBJECT // NOLINT
|
2023-08-05 16:51:23 +02:00
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
public:
|
2023-05-02 16:38:30 +02:00
|
|
|
~VToolSeamAllowance() override = default;
|
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
static auto Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
|
2023-05-02 16:38:30 +02:00
|
|
|
VContainer *data) -> VToolSeamAllowance *;
|
|
|
|
static auto Create(VToolSeamAllowanceInitData &initData) -> VToolSeamAllowance *;
|
2023-05-22 16:27:15 +02:00
|
|
|
static auto Duplicate(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc)
|
|
|
|
-> VToolSeamAllowance *;
|
2021-03-29 15:09:00 +02:00
|
|
|
static auto Duplicate(VToolSeamAllowanceInitData &initData) -> VToolSeamAllowance *;
|
2016-11-08 11:57:01 +01:00
|
|
|
|
|
|
|
static const quint8 pieceVersion;
|
|
|
|
|
2016-11-25 13:19:44 +01:00
|
|
|
static const QString TagCSA;
|
|
|
|
static const QString TagRecord;
|
2016-12-03 17:01:39 +01:00
|
|
|
static const QString TagIPaths;
|
2017-01-31 17:09:18 +01:00
|
|
|
static const QString TagPins;
|
2017-10-15 11:25:20 +02:00
|
|
|
static const QString TagPlaceLabels;
|
2024-01-06 13:20:56 +01:00
|
|
|
static const QString TagMirrorLine;
|
2016-11-25 13:19:44 +01:00
|
|
|
|
2016-11-10 11:53:02 +01:00
|
|
|
static const QString AttrSeamAllowance;
|
2017-05-16 14:16:50 +02:00
|
|
|
static const QString AttrHideMainPath;
|
2024-01-06 13:20:56 +01:00
|
|
|
static const QString AttrShowFullPiece;
|
2017-04-05 12:22:33 +02:00
|
|
|
static const QString AttrSeamAllowanceBuiltIn;
|
2016-11-23 17:40:27 +01:00
|
|
|
static const QString AttrUnited;
|
2017-01-12 14:51:08 +01:00
|
|
|
static const QString AttrFont;
|
2017-02-23 15:49:20 +01:00
|
|
|
static const QString AttrTopLeftPin;
|
|
|
|
static const QString AttrBottomRightPin;
|
2017-03-09 12:10:46 +01:00
|
|
|
static const QString AttrCenterPin;
|
2017-02-23 15:49:20 +01:00
|
|
|
static const QString AttrTopPin;
|
|
|
|
static const QString AttrBottomPin;
|
2019-07-19 09:45:57 +02:00
|
|
|
static const QString AttrPiecePriority;
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2017-10-19 10:24:21 +02:00
|
|
|
void RemoveWithConfirm(bool ask);
|
2016-11-09 10:57:39 +01:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
static void InsertNodes(const QVector<VPieceNode> &nodes, quint32 pieceId, VMainGraphicsScene *scene,
|
|
|
|
VContainer *data, VAbstractPattern *doc);
|
2017-03-21 16:18:48 +01:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece);
|
2019-02-11 12:25:27 +01:00
|
|
|
static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, CustomSARecord record);
|
2023-05-22 16:27:15 +02:00
|
|
|
static void AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, const QVector<CustomSARecord> &records);
|
|
|
|
static void AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &paths);
|
|
|
|
static void AddPins(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &pins);
|
|
|
|
static void AddPlaceLabels(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &placeLabels);
|
|
|
|
static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
2016-11-09 13:11:58 +01:00
|
|
|
static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
|
|
|
static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
2024-01-06 13:20:56 +01:00
|
|
|
static void AddMirrorLine(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2017-10-18 10:24:15 +02:00
|
|
|
void Move(qreal x, qreal y);
|
2017-10-18 10:56:29 +02:00
|
|
|
void Update(const VPiece &piece);
|
2017-10-18 15:40:20 +02:00
|
|
|
void DisconnectOutsideSignals();
|
|
|
|
void ConnectOutsideSignals();
|
|
|
|
void ReinitInternals(const VPiece &detail, VMainGraphicsScene *scene);
|
2017-11-21 10:55:37 +01:00
|
|
|
void RefreshGeometry(bool updateChildren = true);
|
2017-10-18 10:24:15 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto type() const -> int override { return Type; }
|
2023-05-22 16:27:15 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
Type = UserType + static_cast<int>(Tool::Piece)
|
|
|
|
};
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto getTagName() const -> QString override;
|
|
|
|
void ShowVisualization(bool show) override;
|
|
|
|
void GroupVisibility(quint32 object, bool visible) override;
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
|
|
|
auto boundingRect() const -> QRectF override;
|
|
|
|
auto shape() const -> QPainterPath override;
|
2016-11-08 11:57:01 +01:00
|
|
|
public slots:
|
2023-05-02 16:38:30 +02:00
|
|
|
void FullUpdateFromGuiApply() override;
|
|
|
|
void FullUpdateFromFile() override;
|
|
|
|
void EnableToolMove(bool move);
|
|
|
|
void AllowHover(bool enabled) override;
|
|
|
|
void AllowSelecting(bool enabled) override;
|
|
|
|
virtual void ResetChildren(QGraphicsItem *pItem);
|
2017-01-12 14:51:08 +01:00
|
|
|
virtual void UpdateAll();
|
|
|
|
virtual void retranslateUi();
|
2023-05-02 16:38:30 +02:00
|
|
|
void Highlight(quint32 id);
|
|
|
|
void UpdateDetailLabel();
|
|
|
|
void UpdatePatternInfo();
|
|
|
|
void UpdatePassmarks();
|
|
|
|
void ShowOptions();
|
|
|
|
void DeleteFromMenu();
|
2017-01-12 14:51:08 +01:00
|
|
|
protected slots:
|
2017-04-27 13:30:20 +02:00
|
|
|
void UpdateGrainline();
|
|
|
|
void SaveMoveDetail(const QPointF &ptPos);
|
2023-05-22 16:30:18 +02:00
|
|
|
void SaveResizeDetail(qreal dLabelW);
|
2017-04-27 13:30:20 +02:00
|
|
|
void SaveRotationDetail(qreal dRot);
|
2023-05-02 16:38:30 +02:00
|
|
|
void SaveMovePattern(const QPointF &ptPos);
|
2023-05-22 16:30:18 +02:00
|
|
|
void SaveResizePattern(qreal dLabelW);
|
2017-04-27 13:30:20 +02:00
|
|
|
void SaveRotationPattern(qreal dRot);
|
2023-05-02 16:38:30 +02:00
|
|
|
void SaveMoveGrainline(const QPointF &ptPos);
|
2017-04-27 13:30:20 +02:00
|
|
|
void SaveResizeGrainline(qreal dLength);
|
2023-05-02 16:38:30 +02:00
|
|
|
void SaveRotateGrainline(qreal dRot, const QPointF &ptPos);
|
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
protected:
|
2023-05-02 16:38:30 +02:00
|
|
|
void AddToFile() override;
|
|
|
|
void RefreshDataInFile() override;
|
|
|
|
auto itemChange(GraphicsItemChange change, const QVariant &value) -> QVariant override;
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
void keyReleaseEvent(QKeyEvent *event) override;
|
|
|
|
void SetVisualization() override {}
|
|
|
|
void DeleteToolWithConfirm(bool ask = true) override;
|
|
|
|
void ToolCreation(const Source &typeCreation) override;
|
2024-03-02 14:24:09 +01:00
|
|
|
void SetDialog() override;
|
|
|
|
void SaveDialogChange(const QString &undoText = QString()) override;
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2017-10-27 10:53:35 +02:00
|
|
|
private slots:
|
|
|
|
void ToggleInLayout(bool checked);
|
2023-10-05 08:02:53 +02:00
|
|
|
void ToggleHideMainPath(bool checked);
|
2018-02-03 13:18:32 +01:00
|
|
|
void ToggleForbidFlipping(bool checked);
|
|
|
|
void ToggleForceFlipping(bool checked);
|
2024-01-06 13:20:56 +01:00
|
|
|
void ToggleShowFullPiece(bool checked);
|
2017-10-27 13:02:17 +02:00
|
|
|
void ToggleExcludeState(quint32 id);
|
2022-10-21 13:04:24 +02:00
|
|
|
void ToggleTurnPointState(quint32 id);
|
2018-09-01 11:21:29 +02:00
|
|
|
void ToggleNodePointAngleType(quint32 id, PieceNodeAngle type);
|
2018-10-22 14:06:32 +02:00
|
|
|
void ToggleNodePointPassmark(quint32 id, bool toggle);
|
2019-09-05 10:29:20 +02:00
|
|
|
void TogglePassmarkAngleType(quint32 id, PassmarkAngleType type);
|
|
|
|
void TogglePassmarkLineType(quint32 id, PassmarkLineType type);
|
2023-01-16 15:40:50 +01:00
|
|
|
void ResetPieceLabelTemplate();
|
2017-10-27 10:53:35 +02:00
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
private:
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DISABLE_COPY_MOVE(VToolSeamAllowance) // NOLINT
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
QPainterPath m_mainPath{}; // Must be first to prevent crash
|
|
|
|
QRectF m_pieceBoundingRect{};
|
2017-08-01 11:57:19 +02:00
|
|
|
|
2016-11-08 11:57:01 +01:00
|
|
|
/** @brief sceneDetails pointer to the scene. */
|
|
|
|
VMainGraphicsScene *m_sceneDetails;
|
2023-05-02 16:38:30 +02:00
|
|
|
QString m_drawName;
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2016-11-10 13:06:09 +01:00
|
|
|
VNoBrushScalePathItem *m_seamAllowance;
|
2023-05-02 16:38:30 +02:00
|
|
|
VTextGraphicsItem *m_dataLabel;
|
|
|
|
VTextGraphicsItem *m_patternInfo;
|
|
|
|
VGrainlineItem *m_grainLine;
|
|
|
|
QGraphicsPathItem *m_passmarks;
|
|
|
|
QGraphicsPathItem *m_placeLabels;
|
2024-01-06 13:20:56 +01:00
|
|
|
QGraphicsPathItem *m_mirrorLine;
|
|
|
|
QGraphicsPathItem *m_foldLineMark;
|
|
|
|
QGraphicsPathItem *m_foldLineLabel;
|
|
|
|
QGraphicsSimpleTextItem *m_foldLineLabelText;
|
2016-11-10 13:06:09 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
bool m_acceptHoverEvents{true};
|
2017-10-30 10:08:25 +01:00
|
|
|
|
2021-01-23 14:24:44 +01:00
|
|
|
/** @brief m_geometryIsReady is true when a piece's geometry is ready and checks for validity can be enabled. */
|
|
|
|
bool m_geometryIsReady{false};
|
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
explicit VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem *parent = nullptr);
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2017-03-22 11:05:53 +01:00
|
|
|
void UpdateExcludeState();
|
2017-11-21 10:55:37 +01:00
|
|
|
void UpdateInternalPaths();
|
2017-04-15 16:39:59 +02:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
auto FindLabelGeometry(const VPatternLabelData &labelData, const QVector<quint32> &pins, qreal &rotationAngle,
|
|
|
|
qreal &labelWidth, qreal &labelHeight, QPointF &pos) -> VPieceItem::MoveTypes;
|
|
|
|
auto FindGrainlineGeometry(const VGrainlineData &geom, const QVector<quint32> &pins, qreal &length,
|
|
|
|
qreal &rotationAngle, QPointF &pos) -> VPieceItem::MoveTypes;
|
2016-11-08 11:57:01 +01:00
|
|
|
|
2016-11-25 15:37:32 +01:00
|
|
|
void InitNodes(const VPiece &detail, VMainGraphicsScene *scene);
|
2023-05-22 16:27:15 +02:00
|
|
|
static void InitNode(const VPieceNode &node, VMainGraphicsScene *scene, VToolSeamAllowance *parent);
|
2017-10-15 11:25:20 +02:00
|
|
|
void InitCSAPaths(const VPiece &detail) const;
|
2016-12-03 17:01:39 +01:00
|
|
|
void InitInternalPaths(const VPiece &detail);
|
2017-10-15 11:25:20 +02:00
|
|
|
void InitSpecialPoints(const QVector<quint32> &points) const;
|
2017-04-27 13:30:20 +02:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
auto PrepareLabelData(const VPatternLabelData &labelData, const QVector<quint32> &pins,
|
|
|
|
VTextGraphicsItem *labelItem, QPointF &pos, qreal &labelAngle) -> bool;
|
2017-10-19 10:20:19 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto SelectedTools() const -> QList<VToolSeamAllowance *>;
|
2017-10-15 11:25:20 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto IsGrainlinePositionValid() const -> bool;
|
2024-01-06 13:20:56 +01:00
|
|
|
auto IsFoldLinePositionValid(const QVector<QPainterPath> &shape, FoldLineType type) const -> bool;
|
2021-01-23 14:24:44 +01:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
static void AddPointRecords(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &records,
|
2017-10-15 11:25:20 +02:00
|
|
|
const QString &tag);
|
2017-10-26 15:57:52 +02:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
static auto DuplicateNodes(const VPiecePath &path, const VToolSeamAllowanceInitData &initData,
|
2023-05-02 16:38:30 +02:00
|
|
|
QMap<quint32, quint32> &replacements) -> QVector<VPieceNode>;
|
2023-05-22 16:27:15 +02:00
|
|
|
static auto DuplicateNode(const VPieceNode &node, const VToolSeamAllowanceInitData &initData) -> quint32;
|
2023-05-02 16:38:30 +02:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
static auto DuplicatePiecePath(quint32 id, const VToolSeamAllowanceInitData &initData) -> quint32;
|
2023-05-02 16:38:30 +02:00
|
|
|
|
|
|
|
static auto DuplicateCustomSARecords(const QVector<CustomSARecord> &records,
|
|
|
|
const VToolSeamAllowanceInitData &initData,
|
2023-05-22 16:27:15 +02:00
|
|
|
const QMap<quint32, quint32> &replacements) -> QVector<CustomSARecord>;
|
2023-05-02 16:38:30 +02:00
|
|
|
|
2023-05-22 16:27:15 +02:00
|
|
|
static auto DuplicateInternalPaths(const QVector<quint32> &iPaths, const VToolSeamAllowanceInitData &initData)
|
2023-05-02 16:38:30 +02:00
|
|
|
-> QVector<quint32>;
|
2023-05-22 16:27:15 +02:00
|
|
|
static auto DuplicatePlaceLabels(const QVector<quint32> &placeLabels, const VToolSeamAllowanceInitData &initData)
|
2023-05-02 16:38:30 +02:00
|
|
|
-> QVector<quint32>;
|
2024-01-06 13:20:56 +01:00
|
|
|
|
|
|
|
void UpdateFoldLine(const VFoldLine &foldLine);
|
2016-11-08 11:57:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VTOOLSEAMALLOWANCE_H
|