diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index ba0d21475..0e90e77e7 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -428,3 +428,29 @@ auto VPPiece::PathsSuperposition(const QVector &path1, const QVector bool +{ + if (not IsHideMainPath() && GetContourPoints().isEmpty()) + { + return false; + } + + if (IsSeamAllowance() && IsSeamAllowanceBuiltIn() && GetContourPoints().isEmpty()) + { + return false; + } + + if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn() && GetSeamAllowancePoints().isEmpty()) + { + return false; + } + + if (IsGrainlineEnabled() && GetGrainline().isEmpty()) + { + return false; + } + + return true; +} diff --git a/src/app/puzzle/layout/vppiece.h b/src/app/puzzle/layout/vppiece.h index 4541ed210..35a41d12b 100644 --- a/src/app/puzzle/layout/vppiece.h +++ b/src/app/puzzle/layout/vppiece.h @@ -116,6 +116,8 @@ public: static auto PathsSuperposition(const QVector &path1, const QVector &path2) -> bool; + auto IsValid() const -> bool; + private: Q_DISABLE_COPY(VPPiece) diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index 8767cf4e1..2571b0522 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -582,7 +582,7 @@ void VPGraphicsPiece::GroupMove(const QPointF &pos) } //--------------------------------------------------------------------------------------------------------------------- -QColor VPGraphicsPiece::PieceColor() const +auto VPGraphicsPiece::PieceColor() const -> QColor { VPPiecePtr piece = m_piece.toStrongRef(); if (piece.isNull()) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 4f521e894..48302b807 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -371,15 +371,20 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) { for (const auto& rawPiece : data.pieces) { - // TODO / FIXME: make a few tests, on the data to check for validity. If not - // - // If seam allowance enabled, but the path is empty — invalid. - // If seam line path not hidden, but the path is empty — invalid. - // If seam allowance is built-in, but the seam line path is empty — invalid. - - // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() - VPPiecePtr piece(CreatePiece(rawPiece)); + VPPiecePtr piece(new VPPiece(rawPiece)); + + if (not piece->IsValid()) + { + qCCritical(pWindow) << qPrintable(tr("Piece %1 invalid.").arg(piece->GetName())); + + if (m_cmd != nullptr && not m_cmd->IsGuiEnabled()) + { + QGuiApplication::exit(V_EX_DATAERR); + return; + } + } + piece->SetSheet(nullptr); // just in case VPLayout::AddPiece(m_layout, piece); } @@ -408,24 +413,6 @@ void VPMainWindow::InitZoom() } } -//--------------------------------------------------------------------------------------------------------------------- -VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece) -{ - auto *piece = new VPPiece(rawPiece); - - - // cutting line : GetMappedSeamAllowancePoints(); - // seamline : GetMappedContourPoints(); - - // rawPiece.IsGrainlineEnabled() , GrainlineAngle , GetGrainline - - - // TODO : set all the information we need for the piece! - - - return piece; -} - //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetupMenu() { diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 730bd3634..d1f29de1e 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -324,12 +324,6 @@ private: Unit m_oldPieceTranslationUnit{Unit::Mm}; Unit m_oldLayoutUnit{Unit::Mm}; - /** - * @brief CreatePiece creates a piece from the given VLayoutPiece data - * @param rawPiece the raw piece data - */ - Q_REQUIRED_RESULT VPPiece* CreatePiece(const VLayoutPiece &rawPiece); - /** * @brief InitMenuBar Inits the menu bar (File, Edit, Help ...) */ diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 6406e840e..a6507066a 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -410,6 +410,12 @@ void VPLayoutFileReader::ReadPieces(const VPLayoutPtr &layout, const VPSheetPtr { VPPiecePtr piece(new VPPiece()); ReadPiece(piece); + + if (not piece->IsValid()) + { + throw VException(tr("Piece %1 invalid.").arg(piece->GetName())); + } + piece->SetSheet(sheet); VPLayout::AddPiece(layout, piece); }