2020-05-23 17:47:04 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpsheet.cpp
|
|
|
|
** @author Ronan Le Tiec
|
|
|
|
** @date 23 5, 2020
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2020 Valentina project
|
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
2020-05-23 17:46:46 +02:00
|
|
|
#include "vpsheet.h"
|
|
|
|
|
2020-05-23 17:47:04 +02:00
|
|
|
#include "vplayout.h"
|
2021-08-25 15:58:50 +02:00
|
|
|
#include "vppiece.h"
|
2021-09-01 08:20:58 +02:00
|
|
|
#include "../vpapplication.h"
|
2021-09-06 14:31:19 +02:00
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
|
|
|
#include "../scene/vpgraphicssheet.h"
|
|
|
|
#include "../scene/vpgraphicspiece.h"
|
|
|
|
#include "../scene/vpgraphicstilegrid.h"
|
|
|
|
#include "../scene/vpgraphicspiececontrols.h"
|
|
|
|
#include "../scene/vpgraphicstilegrid.h"
|
|
|
|
|
|
|
|
// VPSheetSceneData
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPSheetSceneData::VPSheetSceneData(const VPLayoutPtr &layout, const QUuid &sheetUuid)
|
|
|
|
: m_layout(layout),
|
2021-09-06 17:06:06 +02:00
|
|
|
m_scene(new VMainGraphicsScene()),
|
|
|
|
m_sheetUuid(sheetUuid)
|
2021-09-06 14:31:19 +02:00
|
|
|
{
|
|
|
|
SCASSERT(not layout.isNull())
|
|
|
|
|
|
|
|
m_graphicsSheet = new VPGraphicsSheet(layout);
|
|
|
|
m_graphicsSheet->setPos(0, 0);
|
|
|
|
m_scene->addItem(m_graphicsSheet);
|
|
|
|
|
2021-09-06 17:06:06 +02:00
|
|
|
m_graphicsTileGrid = new VPGraphicsTileGrid(layout, m_sheetUuid);
|
2021-09-06 14:31:19 +02:00
|
|
|
m_scene->addItem(m_graphicsTileGrid);
|
|
|
|
|
|
|
|
m_rotationControls = new VPGraphicsPieceControls(layout);
|
|
|
|
m_rotationControls->setVisible(false);
|
|
|
|
m_scene->addItem(m_rotationControls);
|
|
|
|
|
|
|
|
m_rotationOrigin = new VPGraphicsTransformationOrigin(layout);
|
|
|
|
m_rotationOrigin->setVisible(false);
|
|
|
|
m_scene->addItem(m_rotationOrigin);
|
|
|
|
|
|
|
|
QObject::connect(m_rotationControls, &VPGraphicsPieceControls::ShowOrigin,
|
|
|
|
m_rotationOrigin, &VPGraphicsTransformationOrigin::on_ShowOrigin);
|
|
|
|
QObject::connect(m_rotationControls, &VPGraphicsPieceControls::TransformationOriginChanged,
|
|
|
|
m_rotationOrigin, &VPGraphicsTransformationOrigin::SetTransformationOrigin);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPSheetSceneData::~VPSheetSceneData()
|
|
|
|
{
|
|
|
|
delete m_scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheetSceneData::Scene() const -> VMainGraphicsScene *
|
|
|
|
{
|
|
|
|
return m_scene;
|
|
|
|
}
|
2020-05-23 17:47:04 +02:00
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheetSceneData::RefreshLayout()
|
|
|
|
{
|
|
|
|
m_graphicsSheet->update();
|
|
|
|
|
|
|
|
m_graphicsTileGrid->update();
|
|
|
|
|
|
|
|
m_scene->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 17:06:06 +02:00
|
|
|
void VPSheetSceneData::RefreshPieces()
|
2021-09-06 14:31:19 +02:00
|
|
|
{
|
|
|
|
qDeleteAll(m_graphicsPieces);
|
|
|
|
m_graphicsPieces.clear();
|
|
|
|
|
2021-09-06 17:06:06 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if(layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetSheet(m_sheetUuid);
|
2021-09-06 14:31:19 +02:00
|
|
|
if (not sheet.isNull())
|
|
|
|
{
|
|
|
|
QList<VPPiecePtr> pieces = sheet->GetPieces();
|
|
|
|
m_graphicsPieces.reserve(pieces.size());
|
|
|
|
|
|
|
|
for (const auto &piece : pieces)
|
|
|
|
{
|
|
|
|
if (not piece.isNull())
|
|
|
|
{
|
|
|
|
auto *graphicsPiece = new VPGraphicsPiece(piece);
|
|
|
|
m_graphicsPieces.append(graphicsPiece);
|
|
|
|
m_scene->addItem(graphicsPiece);
|
|
|
|
ConnectPiece(graphicsPiece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheetSceneData::PrepareForExport()
|
|
|
|
{
|
|
|
|
m_graphicsSheet->SetShowBorder(false);
|
|
|
|
m_graphicsSheet->SetShowMargin(false);
|
|
|
|
|
2021-09-06 17:06:06 +02:00
|
|
|
m_rotationControls->setVisible(false);
|
|
|
|
m_rotationOrigin->setVisible(false);
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
m_showGridTmp = layout->LayoutSettings().GetShowGrid();
|
|
|
|
layout->LayoutSettings().SetShowGrid(false);
|
|
|
|
|
|
|
|
m_showTilesTmp = layout->LayoutSettings().GetShowTiles();
|
|
|
|
layout->LayoutSettings().SetShowTiles(false);
|
2021-09-06 17:06:06 +02:00
|
|
|
|
|
|
|
VPSheetPtr sheet = layout->GetSheet(m_sheetUuid);
|
|
|
|
m_slectedPiecesTmp = sheet->GetSelectedPieces();
|
|
|
|
|
|
|
|
for (const auto& piece : m_slectedPiecesTmp)
|
|
|
|
{
|
|
|
|
if (not piece.isNull())
|
|
|
|
{
|
|
|
|
piece->SetSelected(false);
|
|
|
|
}
|
|
|
|
}
|
2021-09-08 10:19:29 +02:00
|
|
|
|
|
|
|
m_outOfBoundTmp = layout->LayoutSettings().GetWarningPiecesOutOfBound();
|
|
|
|
layout->LayoutSettings().SetWarningPiecesOutOfBound(false);
|
|
|
|
|
|
|
|
m_pieceSuperpositionTmp = layout->LayoutSettings().GetWarningSuperpositionOfPieces();
|
|
|
|
layout->LayoutSettings().SetWarningSuperpositionOfPieces(false);
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshLayout();
|
2021-09-06 17:06:06 +02:00
|
|
|
RefreshPieces();
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheetSceneData::CleanAfterExport()
|
|
|
|
{
|
|
|
|
m_graphicsSheet->SetShowBorder(true);
|
|
|
|
m_graphicsSheet->SetShowMargin(true);
|
|
|
|
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
layout->LayoutSettings().SetShowGrid(m_showGridTmp);
|
|
|
|
layout->LayoutSettings().SetShowTiles(m_showTilesTmp);
|
2021-09-06 17:06:06 +02:00
|
|
|
|
|
|
|
for (const auto& piece : m_slectedPiecesTmp)
|
|
|
|
{
|
|
|
|
if (not piece.isNull())
|
|
|
|
{
|
|
|
|
piece->SetSelected(true);
|
|
|
|
emit layout->PieceSelectionChanged(piece);
|
|
|
|
}
|
|
|
|
}
|
2021-09-08 10:19:29 +02:00
|
|
|
|
|
|
|
layout->LayoutSettings().SetWarningPiecesOutOfBound(m_outOfBoundTmp);
|
|
|
|
layout->LayoutSettings().SetWarningSuperpositionOfPieces(m_pieceSuperpositionTmp);
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshLayout();
|
2021-09-06 17:06:06 +02:00
|
|
|
RefreshPieces();
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheetSceneData::GraphicsPieces() const -> const QList<VPGraphicsPiece *> &
|
|
|
|
{
|
|
|
|
return m_graphicsPieces;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheetSceneData::GraphicsPiecesAsItems() const -> QList<QGraphicsItem *>
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> items;
|
|
|
|
items.reserve(m_graphicsPieces.size());
|
|
|
|
|
|
|
|
for(auto *item : m_graphicsPieces)
|
|
|
|
{
|
|
|
|
items.append(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheetSceneData::RotationControls() const -> VPGraphicsPieceControls *
|
|
|
|
{
|
|
|
|
return m_rotationControls;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheetSceneData::ScenePiece(const VPPiecePtr &piece) const -> VPGraphicsPiece *
|
|
|
|
{
|
|
|
|
VPGraphicsPiece *_graphicsPiece = nullptr;
|
|
|
|
for(auto *graphicPiece : m_graphicsPieces)
|
|
|
|
{
|
|
|
|
if(graphicPiece->GetPiece() == piece)
|
|
|
|
{
|
|
|
|
_graphicsPiece = graphicPiece;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _graphicsPiece;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheetSceneData::RemovePiece(VPGraphicsPiece *piece)
|
|
|
|
{
|
|
|
|
m_graphicsPieces.removeAll(piece);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheetSceneData::AddPiece(VPGraphicsPiece *piece)
|
|
|
|
{
|
|
|
|
m_graphicsPieces.append(piece);
|
|
|
|
ConnectPiece(piece);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheetSceneData::SetTextAsPaths(bool textAsPaths) const
|
|
|
|
{
|
|
|
|
for (auto *piece : m_graphicsPieces)
|
|
|
|
{
|
|
|
|
if (piece != nullptr)
|
|
|
|
{
|
|
|
|
piece->SetTextAsPaths(textAsPaths);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece)
|
|
|
|
{
|
|
|
|
SCASSERT(piece != nullptr)
|
|
|
|
|
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject::connect(layout.get(), &VPLayout::PieceTransformationChanged, piece,
|
|
|
|
&VPGraphicsPiece::on_RefreshPiece);
|
|
|
|
QObject::connect(layout.get(), &VPLayout::PieceSelectionChanged,
|
|
|
|
m_rotationControls, &VPGraphicsPieceControls::on_UpdateControls);
|
|
|
|
QObject::connect(layout.get(), &VPLayout::PiecePositionValidityChanged,
|
|
|
|
piece, &VPGraphicsPiece::on_RefreshPiece);
|
|
|
|
QObject::connect(piece, &VPGraphicsPiece::PieceTransformationChanged,
|
|
|
|
m_rotationControls, &VPGraphicsPieceControls::on_UpdateControls);
|
|
|
|
QObject::connect(piece, &VPGraphicsPiece::HideTransformationHandles,
|
|
|
|
m_rotationControls, &VPGraphicsPieceControls::on_HideHandles);
|
|
|
|
QObject::connect(piece, &VPGraphicsPiece::HideTransformationHandles,
|
|
|
|
m_rotationOrigin, &VPGraphicsTransformationOrigin::on_HideHandles);
|
|
|
|
}
|
|
|
|
|
|
|
|
// VPSheet
|
2020-05-23 17:47:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-17 17:49:28 +02:00
|
|
|
VPSheet::VPSheet(const VPLayoutPtr &layout) :
|
2021-09-06 14:31:19 +02:00
|
|
|
m_layout(layout),
|
|
|
|
m_sceneData(new VPSheetSceneData(layout, Uuid()))
|
2020-05-23 17:47:04 +02:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
SCASSERT(not layout.isNull())
|
2021-09-01 08:20:58 +02:00
|
|
|
|
|
|
|
VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
|
|
|
|
SetIgnoreMargins(settings->GetLayoutSheetIgnoreMargins());
|
|
|
|
SetSheetMargins(settings->GetLayoutSheetMargins());
|
|
|
|
SetSheetSize(QSizeF(settings->GetLayoutSheetPaperWidth(), settings->GetLayoutSheetPaperHeight()));
|
2020-05-23 17:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-17 17:49:28 +02:00
|
|
|
auto VPSheet::GetLayout() const -> VPLayoutPtr
|
2020-05-23 17:47:04 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
return m_layout;
|
2020-11-20 15:51:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-17 17:49:28 +02:00
|
|
|
auto VPSheet::GetPieces() const -> QList<VPPiecePtr>
|
2020-11-20 15:51:24 +01:00
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = GetLayout();
|
|
|
|
if (not layout.isNull())
|
2020-11-20 15:51:24 +01:00
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
return layout->PiecesForSheet(m_uuid);
|
2020-11-20 15:51:24 +01:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:11:18 +02:00
|
|
|
return {};
|
2020-05-23 17:47:04 +02:00
|
|
|
}
|
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetSelectedPieces() const -> QList<VPPiecePtr>
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = GetLayout();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
QList<VPPiecePtr> list = layout->PiecesForSheet(m_uuid);
|
|
|
|
|
|
|
|
QList<VPPiecePtr> selected;
|
|
|
|
selected.reserve(list.size());
|
|
|
|
|
|
|
|
for (const auto& piece : list)
|
|
|
|
{
|
|
|
|
if (not piece.isNull() && piece->IsSelected())
|
|
|
|
{
|
|
|
|
selected.append(piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetAsLayoutPieces() const -> QVector<VLayoutPiece>
|
|
|
|
{
|
|
|
|
QList<VPPiecePtr> pieces = GetPieces();
|
|
|
|
|
|
|
|
QVector<VLayoutPiece> details;
|
|
|
|
details.reserve(pieces.size());
|
|
|
|
|
|
|
|
for (auto piece : pieces)
|
|
|
|
{
|
|
|
|
if (not piece.isNull())
|
|
|
|
{
|
|
|
|
details.append(*piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
2020-05-23 17:47:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPSheet::GetName() const -> QString
|
2020-05-23 17:47:04 +02:00
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetName(const QString &name)
|
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
}
|
2021-07-31 11:21:07 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::Uuid() const -> const QUuid &
|
|
|
|
{
|
|
|
|
return m_uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::IsVisible() const -> bool
|
|
|
|
{
|
|
|
|
return m_visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetVisible(bool visible)
|
|
|
|
{
|
|
|
|
m_visible = visible;
|
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-01 08:20:58 +02:00
|
|
|
GrainlineType VPSheet::GrainlineOrientation() const
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
if (m_grainlineType == GrainlineType::NotFixed)
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
if (m_size.height() < m_size.width())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
|
|
|
return GrainlineType::Horizontal;
|
|
|
|
}
|
2021-09-01 08:20:58 +02:00
|
|
|
|
|
|
|
return GrainlineType::Vertical;
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 08:20:58 +02:00
|
|
|
return m_grainlineType;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetGrainlineType() const -> GrainlineType
|
|
|
|
{
|
|
|
|
return m_grainlineType;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetGrainlineType(GrainlineType type)
|
|
|
|
{
|
|
|
|
m_grainlineType = type;
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::TransformationOrigin() const -> const VPTransformationOrigon &
|
|
|
|
{
|
|
|
|
return m_transformationOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetTransformationOrigin(const VPTransformationOrigon &newTransformationOrigin)
|
|
|
|
{
|
|
|
|
m_transformationOrigin = newTransformationOrigin;
|
|
|
|
}
|
2021-08-17 17:49:28 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::Clear()
|
|
|
|
{
|
|
|
|
m_name.clear();
|
|
|
|
m_visible = true;
|
|
|
|
m_transformationOrigin = VPTransformationOrigon();
|
2021-08-19 14:13:54 +02:00
|
|
|
m_trashSheet = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::TrashSheet() const -> bool
|
|
|
|
{
|
|
|
|
return m_trashSheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetTrashSheet(bool newTrashSheet)
|
|
|
|
{
|
|
|
|
m_trashSheet = newTrashSheet;
|
2021-08-17 17:49:28 +02:00
|
|
|
}
|
2021-08-27 17:27:38 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::ValidateSuperpositionOfPieces() const
|
|
|
|
{
|
|
|
|
QList<VPPiecePtr> pieces = GetPieces();
|
|
|
|
|
|
|
|
for (const auto &piece : pieces)
|
|
|
|
{
|
|
|
|
if (piece.isNull())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool oldSuperpositionOfPieces = piece->HasSuperpositionWithPieces();
|
|
|
|
QVector<QPointF> path1 = piece->GetMappedExternalContourPoints();
|
|
|
|
bool hasSuperposition = false;
|
|
|
|
|
|
|
|
for (const auto &p : pieces)
|
|
|
|
{
|
|
|
|
if (p.isNull() || piece == p)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QPointF> path2 = p->GetMappedExternalContourPoints();
|
|
|
|
|
2021-08-30 17:45:27 +02:00
|
|
|
bool superposition = VPPiece::PathsSuperposition(path1, path2);
|
2021-08-27 17:27:38 +02:00
|
|
|
if (superposition)
|
|
|
|
{
|
|
|
|
hasSuperposition = superposition;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
piece->SetHasSuperpositionWithPieces(hasSuperposition);
|
|
|
|
|
|
|
|
if (oldSuperpositionOfPieces != piece->HasSuperpositionWithPieces())
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = GetLayout();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
emit layout->PiecePositionValidityChanged(piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::ValidatePieceOutOfBound(const VPPiecePtr &piece) const
|
|
|
|
{
|
|
|
|
if (piece.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool oldOutOfBound = piece->OutOfBound();
|
|
|
|
|
|
|
|
QRectF pieceRect = piece->MappedDetailBoundingRect();
|
|
|
|
QRectF sheetRect = GetMarginsRect();
|
|
|
|
|
|
|
|
piece->SetOutOfBound(not sheetRect.contains(pieceRect));
|
|
|
|
|
|
|
|
if (oldOutOfBound != piece->OutOfBound())
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = GetLayout();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
emit layout->PiecePositionValidityChanged(piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::ValidatePiecesOutOfBound() const
|
|
|
|
{
|
|
|
|
QList<VPPiecePtr> pieces = GetPieces();
|
|
|
|
for (const auto &piece : pieces)
|
|
|
|
{
|
|
|
|
ValidatePieceOutOfBound(piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetSheetRect() const -> QRectF
|
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
return QRectF(QPoint(0, 0), m_size);
|
2021-08-27 17:27:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetMarginsRect() const -> QRectF
|
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
if (not m_ignoreMargins)
|
|
|
|
{
|
|
|
|
QRectF rect = QRectF(QPointF(m_margins.left(), m_margins.top()),
|
|
|
|
QPointF(m_size.width() - m_margins.right(), m_size.height() - m_margins.bottom()));
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QRectF(0, 0, m_size.width(), m_size.height());
|
2021-08-27 17:27:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-01 08:20:58 +02:00
|
|
|
void VPSheet::RemoveUnusedLength()
|
2021-08-27 17:27:38 +02:00
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
VPLayoutPtr layout = GetLayout();
|
2021-08-27 17:27:38 +02:00
|
|
|
if (layout.isNull())
|
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
return;
|
2021-08-27 17:27:38 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 08:20:58 +02:00
|
|
|
QList<VPPiecePtr> pieces = GetPieces();
|
|
|
|
if (pieces.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-08-27 17:27:38 +02:00
|
|
|
|
2021-09-01 08:20:58 +02:00
|
|
|
QRectF piecesBoundingRect;
|
|
|
|
|
|
|
|
for (const auto& piece : pieces)
|
2021-08-27 17:27:38 +02:00
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
if (not piece.isNull())
|
|
|
|
{
|
|
|
|
piecesBoundingRect = piecesBoundingRect.united(piece->MappedDetailBoundingRect());
|
|
|
|
}
|
2021-08-27 17:27:38 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 08:20:58 +02:00
|
|
|
const qreal extra = 2;
|
|
|
|
QRectF sheetRect = GetSheetRect();
|
|
|
|
GrainlineType type = GrainlineOrientation();
|
2021-08-27 17:27:38 +02:00
|
|
|
|
2021-09-01 08:20:58 +02:00
|
|
|
if (type == GrainlineType::Vertical)
|
2021-08-27 17:27:38 +02:00
|
|
|
{
|
2021-09-01 08:20:58 +02:00
|
|
|
qreal margin = 0;
|
|
|
|
if (not m_ignoreMargins)
|
|
|
|
{
|
|
|
|
margin = m_margins.bottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sheetRect.bottomRight().y() - margin > piecesBoundingRect.bottomRight().y())
|
|
|
|
{
|
|
|
|
m_size = QSizeF(m_size.width(), piecesBoundingRect.bottomRight().y() + margin + extra);
|
|
|
|
}
|
2021-08-27 17:27:38 +02:00
|
|
|
}
|
2021-09-01 08:20:58 +02:00
|
|
|
else if (type == GrainlineType::Horizontal)
|
|
|
|
{
|
|
|
|
qreal margin = 0;
|
|
|
|
if (not m_ignoreMargins)
|
|
|
|
{
|
|
|
|
margin = m_margins.right();
|
|
|
|
}
|
2021-08-27 17:27:38 +02:00
|
|
|
|
2021-09-01 08:20:58 +02:00
|
|
|
if (sheetRect.topRight().x() - margin > piecesBoundingRect.topRight().x())
|
|
|
|
{
|
|
|
|
m_size = QSizeF(piecesBoundingRect.topRight().x() + margin + extra, m_size.height());
|
|
|
|
}
|
|
|
|
}
|
2021-08-27 17:27:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::CheckPiecePositionValidity(const VPPiecePtr &piece) const
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = GetLayout();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<VPPiecePtr> pieces = GetPieces();
|
|
|
|
if (piece.isNull() || not pieces.contains(piece))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->LayoutSettings().GetWarningPiecesOutOfBound())
|
|
|
|
{
|
|
|
|
ValidatePieceOutOfBound(piece);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->LayoutSettings().GetWarningSuperpositionOfPieces())
|
|
|
|
{
|
|
|
|
ValidateSuperpositionOfPieces();
|
|
|
|
}
|
|
|
|
}
|
2021-09-01 08:20:58 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
auto VPSheet::SceneData() const -> VPSheetSceneData *
|
|
|
|
{
|
|
|
|
return m_sceneData;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 16:44:27 +02:00
|
|
|
void VPSheet::ClearSelection() const
|
|
|
|
{
|
|
|
|
QList<VPPiecePtr> selectedPieces = GetSelectedPieces();
|
|
|
|
for (const auto& piece : selectedPieces)
|
|
|
|
{
|
|
|
|
if (piece->IsSelected())
|
|
|
|
{
|
|
|
|
piece->SetSelected(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not selectedPieces.isEmpty())
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = GetLayout();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
2021-09-06 17:06:06 +02:00
|
|
|
emit layout->PieceSelectionChanged(VPPiecePtr());
|
2021-09-06 16:44:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-07 11:31:52 +02:00
|
|
|
QPageLayout::Orientation VPSheet::GetSheetOrientation() const
|
|
|
|
{
|
|
|
|
return m_size.height() >= m_size.width() ? QPageLayout::Portrait : QPageLayout::Landscape;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
auto VPSheet::SheetUnits() const -> Unit
|
2021-09-01 08:20:58 +02:00
|
|
|
{
|
|
|
|
VPLayoutPtr layout = GetLayout();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
return layout->LayoutSettings().GetUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Unit::Cm;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetSize(qreal width, qreal height)
|
|
|
|
{
|
|
|
|
m_size.setWidth(width);
|
|
|
|
m_size.setHeight(height);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetSizeConverted(qreal width, qreal height)
|
|
|
|
{
|
|
|
|
Unit unit = SheetUnits();
|
|
|
|
m_size.setWidth(UnitConvertor(width, unit, Unit::Px));
|
|
|
|
m_size.setHeight(UnitConvertor(height, unit, Unit::Px));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetSize(const QSizeF &size)
|
|
|
|
{
|
|
|
|
m_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetSizeConverted(const QSizeF &size)
|
|
|
|
{
|
|
|
|
Unit unit = SheetUnits();
|
|
|
|
m_size = QSizeF(UnitConvertor(size.width(), unit, Unit::Px),
|
|
|
|
UnitConvertor(size.height(), unit, Unit::Px));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetSheetSize() const -> QSizeF
|
|
|
|
{
|
|
|
|
return m_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetSheetSizeConverted() const -> QSizeF
|
|
|
|
{
|
|
|
|
Unit unit = SheetUnits();
|
|
|
|
QSizeF convertedSize = QSizeF(
|
|
|
|
UnitConvertor(m_size.width(), Unit::Px, unit),
|
|
|
|
UnitConvertor(m_size.height(), Unit::Px, unit)
|
|
|
|
);
|
|
|
|
|
|
|
|
return convertedSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom)
|
|
|
|
{
|
|
|
|
m_margins.setLeft(left);
|
|
|
|
m_margins.setTop(top);
|
|
|
|
m_margins.setRight(right);
|
|
|
|
m_margins.setBottom(bottom);
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom)
|
|
|
|
{
|
|
|
|
Unit unit = SheetUnits();
|
|
|
|
m_margins.setLeft(UnitConvertor(left, unit, Unit::Px));
|
|
|
|
m_margins.setTop(UnitConvertor(top, unit, Unit::Px));
|
|
|
|
m_margins.setRight(UnitConvertor(right, unit, Unit::Px));
|
|
|
|
m_margins.setBottom(UnitConvertor(bottom, unit, Unit::Px));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetMargins(const QMarginsF &margins)
|
|
|
|
{
|
|
|
|
m_margins = margins;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetSheetMarginsConverted(const QMarginsF &margins)
|
|
|
|
{
|
|
|
|
Unit unit = SheetUnits();
|
|
|
|
m_margins = UnitConvertor(margins, unit, Unit::Px);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetSheetMargins() const -> QMarginsF
|
|
|
|
{
|
|
|
|
return m_margins;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::GetSheetMarginsConverted() const -> QMarginsF
|
|
|
|
{
|
|
|
|
Unit unit = SheetUnits();
|
|
|
|
return UnitConvertor(m_margins, Unit::Px, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPSheet::IgnoreMargins() const -> bool
|
|
|
|
{
|
|
|
|
return m_ignoreMargins;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPSheet::SetIgnoreMargins(bool newIgnoreMargins)
|
|
|
|
{
|
|
|
|
m_ignoreMargins = newIgnoreMargins;
|
|
|
|
}
|