Validate a piece when import raw layout or read the layout format.
This commit is contained in:
parent
b877009d90
commit
0944ea968a
|
@ -428,3 +428,29 @@ auto VPPiece::PathsSuperposition(const QVector<QPointF> &path1, const QVector<QP
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
auto VPPiece::IsValid() const -> 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;
|
||||
}
|
||||
|
|
|
@ -116,6 +116,8 @@ public:
|
|||
|
||||
static auto PathsSuperposition(const QVector<QPointF> &path1, const QVector<QPointF> &path2) -> bool;
|
||||
|
||||
auto IsValid() const -> bool;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPPiece)
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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 ...)
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user