Fix manual layout format conversion and reading.
This commit is contained in:
parent
1925300ff3
commit
0f2c922ead
|
@ -492,25 +492,29 @@ auto VPPiece::PathsSuperposition(const QVector<QPointF> &path1, const QVector<QP
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VPPiece::IsValid() const -> bool
|
auto VPPiece::IsValid(QString &error) const -> bool
|
||||||
{
|
{
|
||||||
if (not IsHideMainPath() && GetContourPoints().isEmpty())
|
if (not IsHideMainPath() && GetContourPoints().isEmpty())
|
||||||
{
|
{
|
||||||
|
error = tr("Seam line is empty");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsSeamAllowance() && IsSeamAllowanceBuiltIn() && GetContourPoints().isEmpty())
|
if (IsSeamAllowance() && IsSeamAllowanceBuiltIn() && GetContourPoints().isEmpty())
|
||||||
{
|
{
|
||||||
|
error = tr("Seam line is empty");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn() && GetSeamAllowancePoints().isEmpty())
|
if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn() && GetSeamAllowancePoints().isEmpty())
|
||||||
{
|
{
|
||||||
|
error = tr("Seam allowance line is empty");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsGrainlineEnabled() && GetGrainline().isEmpty())
|
if (IsGrainlineEnabled() && GetGrainline().isEmpty())
|
||||||
{
|
{
|
||||||
|
error = tr("Grainline is empty");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ public:
|
||||||
|
|
||||||
static auto PathsSuperposition(const QVector<QPointF> &path1, const QVector<QPointF> &path2) -> bool;
|
static auto PathsSuperposition(const QVector<QPointF> &path1, const QVector<QPointF> &path2) -> bool;
|
||||||
|
|
||||||
auto IsValid() const -> bool;
|
auto IsValid(QString &error) const -> bool;
|
||||||
|
|
||||||
auto CopyNumber() const -> quint16;
|
auto CopyNumber() const -> quint16;
|
||||||
void SetCopyNumber(quint16 newCopyNumber);
|
void SetCopyNumber(quint16 newCopyNumber);
|
||||||
|
|
|
@ -3203,9 +3203,10 @@ auto VPMainWindow::AddLayoutPieces(const QVector<VLayoutPiece> &pieces) -> bool
|
||||||
VPPiecePtr piece(new VPPiece(rawPiece));
|
VPPiecePtr piece(new VPPiece(rawPiece));
|
||||||
piece->SetCopyNumber(i);
|
piece->SetCopyNumber(i);
|
||||||
|
|
||||||
if (not piece->IsValid())
|
QString error;
|
||||||
|
if (not piece->IsValid(error))
|
||||||
{
|
{
|
||||||
qCCritical(pWindow) << qPrintable(tr("Piece %1 invalid.").arg(piece->GetName()));
|
qCCritical(pWindow) << qPrintable(tr("Piece %1 invalid. %2").arg(piece->GetName(), error));
|
||||||
|
|
||||||
if (m_cmd != nullptr && not m_cmd->IsGuiEnabled())
|
if (m_cmd != nullptr && not m_cmd->IsGuiEnabled())
|
||||||
{
|
{
|
||||||
|
|
|
@ -437,9 +437,10 @@ void VPLayoutFileReader::ReadPieces(const VPLayoutPtr &layout, const VPSheetPtr
|
||||||
VPPiecePtr piece(new VPPiece());
|
VPPiecePtr piece(new VPPiece());
|
||||||
ReadPiece(piece);
|
ReadPiece(piece);
|
||||||
|
|
||||||
if (not piece->IsValid())
|
QString error;
|
||||||
|
if (not piece->IsValid(error))
|
||||||
{
|
{
|
||||||
throw VException(tr("Piece %1 invalid.").arg(piece->GetName()));
|
throw VException(tr("Piece %1 invalid. %2").arg(piece->GetName(), error));
|
||||||
}
|
}
|
||||||
|
|
||||||
piece->SetSheet(sheet);
|
piece->SetSheet(sheet);
|
||||||
|
@ -461,7 +462,7 @@ void VPLayoutFileReader::ReadPiece(const VPPiecePtr &piece)
|
||||||
QXmlStreamAttributes attribs = attributes();
|
QXmlStreamAttributes attribs = attributes();
|
||||||
piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece")));
|
piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece")));
|
||||||
|
|
||||||
QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid::createUuid().toString());
|
QString uuidStr = ReadAttributeString(attribs, ML::AttrUID, QUuid::createUuid().toString());
|
||||||
piece->SetUUID(QUuid(uuidStr));
|
piece->SetUUID(QUuid(uuidStr));
|
||||||
|
|
||||||
piece->SetGradationId(ReadAttributeEmptyString(attribs, ML::AttrGradationLabel));
|
piece->SetGradationId(ReadAttributeEmptyString(attribs, ML::AttrGradationLabel));
|
||||||
|
@ -576,6 +577,7 @@ void VPLayoutFileReader::ReadSeamAllowance(const VPPiecePtr &piece)
|
||||||
piece->SetSeamAllowance(enabled);
|
piece->SetSeamAllowance(enabled);
|
||||||
|
|
||||||
bool builtIn = ReadAttributeBool(attribs, ML::AttrBuiltIn, falseStr);
|
bool builtIn = ReadAttributeBool(attribs, ML::AttrBuiltIn, falseStr);
|
||||||
|
piece->SetSeamAllowanceBuiltIn(builtIn);
|
||||||
|
|
||||||
QVector<VLayoutPoint> path = ReadLayoutPoints();
|
QVector<VLayoutPoint> path = ReadLayoutPoints();
|
||||||
|
|
||||||
|
|
|
@ -251,7 +251,7 @@ void VPLayoutFileWriter::WritePieceList(const QList<VPPiecePtr> &list, const QSt
|
||||||
void VPLayoutFileWriter::WritePiece(const VPPiecePtr &piece)
|
void VPLayoutFileWriter::WritePiece(const VPPiecePtr &piece)
|
||||||
{
|
{
|
||||||
writeStartElement(ML::TagPiece);
|
writeStartElement(ML::TagPiece);
|
||||||
SetAttribute(ML::AttrID, piece->GetUUID().toString());
|
SetAttribute(ML::AttrUID, piece->GetUUID().toString());
|
||||||
SetAttribute(ML::AttrName, piece->GetName());
|
SetAttribute(ML::AttrName, piece->GetName());
|
||||||
SetAttributeOrRemoveIf<bool>(ML::AttrMirrored, piece->IsMirror(),
|
SetAttributeOrRemoveIf<bool>(ML::AttrMirrored, piece->IsMirror(),
|
||||||
[](bool mirrored) noexcept {return not mirrored;});
|
[](bool mirrored) noexcept {return not mirrored;});
|
||||||
|
|
|
@ -76,7 +76,7 @@ const QString AttrBottom = QStringLiteral("bottom"); // NOLINT(cer
|
||||||
const QString AttrWidth = QStringLiteral("width"); // NOLINT(cert-err58-cpp)
|
const QString AttrWidth = QStringLiteral("width"); // NOLINT(cert-err58-cpp)
|
||||||
const QString AttrLength = QStringLiteral("length"); // NOLINT(cert-err58-cpp)
|
const QString AttrLength = QStringLiteral("length"); // NOLINT(cert-err58-cpp)
|
||||||
const QString AttrFollowGrainline = QStringLiteral("followGrainline"); // NOLINT(cert-err58-cpp)
|
const QString AttrFollowGrainline = QStringLiteral("followGrainline"); // NOLINT(cert-err58-cpp)
|
||||||
const QString AttrID = QStringLiteral("id"); // NOLINT(cert-err58-cpp)
|
const QString AttrUID = QStringLiteral("uid"); // NOLINT(cert-err58-cpp)
|
||||||
const QString AttrMirrored = QStringLiteral("mirrored"); // NOLINT(cert-err58-cpp)
|
const QString AttrMirrored = QStringLiteral("mirrored"); // NOLINT(cert-err58-cpp)
|
||||||
const QString AttrForbidFlipping = QStringLiteral("forbidFlipping"); // NOLINT(cert-err58-cpp)
|
const QString AttrForbidFlipping = QStringLiteral("forbidFlipping"); // NOLINT(cert-err58-cpp)
|
||||||
const QString AttrForceFlipping = QStringLiteral("forceFlipping"); // NOLINT(cert-err58-cpp)
|
const QString AttrForceFlipping = QStringLiteral("forceFlipping"); // NOLINT(cert-err58-cpp)
|
||||||
|
|
|
@ -81,7 +81,7 @@ extern const QString AttrBottom;
|
||||||
extern const QString AttrWidth;
|
extern const QString AttrWidth;
|
||||||
extern const QString AttrLength;
|
extern const QString AttrLength;
|
||||||
extern const QString AttrFollowGrainline;
|
extern const QString AttrFollowGrainline;
|
||||||
extern const QString AttrID;
|
extern const QString AttrUID;
|
||||||
extern const QString AttrMirrored;
|
extern const QString AttrMirrored;
|
||||||
extern const QString AttrForbidFlipping;
|
extern const QString AttrForbidFlipping;
|
||||||
extern const QString AttrForceFlipping;
|
extern const QString AttrForceFlipping;
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
<xs:simpleContent>
|
<xs:simpleContent>
|
||||||
<xs:extension base="PathOrEmpty">
|
<xs:extension base="PathOrEmpty">
|
||||||
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
||||||
|
<xs:attribute type="xs:boolean" name="builtIn" use="optional"/>
|
||||||
</xs:extension>
|
</xs:extension>
|
||||||
</xs:simpleContent>
|
</xs:simpleContent>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
@ -244,6 +245,7 @@
|
||||||
<xs:simpleContent>
|
<xs:simpleContent>
|
||||||
<xs:extension base="PathOrEmpty">
|
<xs:extension base="PathOrEmpty">
|
||||||
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
||||||
|
<xs:attribute type="xs:boolean" name="builtIn" use="optional"/>
|
||||||
</xs:extension>
|
</xs:extension>
|
||||||
</xs:simpleContent>
|
</xs:simpleContent>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
|
@ -93,6 +93,7 @@
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
||||||
|
<xs:attribute type="xs:boolean" name="builtIn" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
<xs:element name="grainline">
|
<xs:element name="grainline">
|
||||||
|
@ -215,7 +216,7 @@
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attribute name="id" type="uuid" use="required"/>
|
<xs:attribute name="uid" type="uuid" use="required"/>
|
||||||
<xs:attribute type="xs:string" name="name"/>
|
<xs:attribute type="xs:string" name="name"/>
|
||||||
<xs:attribute type="xs:boolean" name="mirrored"/>
|
<xs:attribute type="xs:boolean" name="mirrored"/>
|
||||||
<xs:attribute type="xs:boolean" name="forbidFlipping"/>
|
<xs:attribute type="xs:boolean" name="forbidFlipping"/>
|
||||||
|
@ -287,6 +288,7 @@
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
<xs:attribute type="xs:boolean" name="enabled" use="optional"/>
|
||||||
|
<xs:attribute type="xs:boolean" name="builtIn" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
<xs:element name="grainline">
|
<xs:element name="grainline">
|
||||||
|
@ -409,7 +411,7 @@
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attribute name="id" type="uuid" use="required"/>
|
<xs:attribute name="uid" type="uuid" use="required"/>
|
||||||
<xs:attribute type="xs:string" name="name"/>
|
<xs:attribute type="xs:string" name="name"/>
|
||||||
<xs:attribute type="xs:boolean" name="mirrored"/>
|
<xs:attribute type="xs:boolean" name="mirrored"/>
|
||||||
<xs:attribute type="xs:boolean" name="forbidFlipping"/>
|
<xs:attribute type="xs:boolean" name="forbidFlipping"/>
|
||||||
|
|
|
@ -339,21 +339,28 @@ QDomElement VDomDocument::elementById(quint32 id, const QString &tagName, bool u
|
||||||
* @param id id value
|
* @param id id value
|
||||||
* @return true if found
|
* @return true if found
|
||||||
*/
|
*/
|
||||||
bool VDomDocument::find(QHash<quint32, QDomElement> &cache, const QDomElement &node, quint32 id)
|
auto VDomDocument::find(QHash<quint32, QDomElement> &cache, const QDomElement &node, quint32 id) -> bool
|
||||||
{
|
{
|
||||||
if (node.hasAttribute(AttrId))
|
if (node.hasAttribute(AttrId))
|
||||||
{
|
{
|
||||||
const quint32 elementId = GetParametrUInt(node, AttrId, NULL_ID_STR);
|
try
|
||||||
|
|
||||||
if (cache.contains(elementId))
|
|
||||||
{
|
{
|
||||||
qWarning() << tr("Not unique id (%1)").arg(elementId);
|
const quint32 elementId = GetParametrUInt(node, AttrId, NULL_ID_STR);
|
||||||
|
|
||||||
|
if (cache.contains(elementId))
|
||||||
|
{
|
||||||
|
qWarning() << tr("Not unique id (%1)").arg(elementId);
|
||||||
|
}
|
||||||
|
|
||||||
|
cache.insert(elementId, node);
|
||||||
|
if (elementId == id)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (const VExceptionConversionError &)
|
||||||
cache.insert(elementId, node);
|
|
||||||
if (elementId == id)
|
|
||||||
{
|
{
|
||||||
return true;
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,13 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, strSeamAllowanceTag, (QLatin1String("se
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strInternalPathTag, (QLatin1String("internalPath"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strInternalPathTag, (QLatin1String("internalPath"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strMarkerTag, (QLatin1String("marker"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strMarkerTag, (QLatin1String("marker"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strPointTag, (QLatin1String("point"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strPointTag, (QLatin1String("point"))) // NOLINT
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strPieceTag, (QLatin1String("piece"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrX, (QLatin1String("x"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrX, (QLatin1String("x"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrY, (QLatin1String("y"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrY, (QLatin1String("y"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrTurnPoint, (QLatin1String("turnPoint"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrTurnPoint, (QLatin1String("turnPoint"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrCurvePoint, (QLatin1String("curvePoint"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrCurvePoint, (QLatin1String("curvePoint"))) // NOLINT
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrId, (QLatin1String("id"))) // NOLINT
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strAttrUId, (QLatin1String("uid"))) // NOLINT
|
||||||
|
|
||||||
//const QChar groupSep = QLatin1Char(';');
|
//const QChar groupSep = QLatin1Char(';');
|
||||||
const QChar coordintatesSep = QLatin1Char(',');
|
const QChar coordintatesSep = QLatin1Char(',');
|
||||||
|
@ -210,6 +213,17 @@ void VLayoutConverter::ConvertPiecesToV0_1_3()
|
||||||
QDomElement node = tags.at(i).toElement();
|
QDomElement node = tags.at(i).toElement();
|
||||||
RemoveAllChildren(node);
|
RemoveAllChildren(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDomNodeList pieceTags = elementsByTagName(*strPieceTag);
|
||||||
|
for (int i=0; i < pieceTags.size(); ++i)
|
||||||
|
{
|
||||||
|
QDomElement node = pieceTags.at(i).toElement();
|
||||||
|
if (node.isElement() && node.hasAttribute(*strAttrId))
|
||||||
|
{
|
||||||
|
node.setAttribute(*strAttrUId, node.attribute(*strAttrId));
|
||||||
|
node.removeAttribute(*strAttrId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -62,7 +62,6 @@ protected:
|
||||||
auto IsReadOnly() const -> bool override;
|
auto IsReadOnly() const -> bool override;
|
||||||
|
|
||||||
void ConvertPiecesToV0_1_3();
|
void ConvertPiecesToV0_1_3();
|
||||||
void ConvertPieceToV0_1_3(const QDomElement &piece);
|
|
||||||
void ConvertPathToV0_1_3(QDomElement &node);
|
void ConvertPathToV0_1_3(QDomElement &node);
|
||||||
|
|
||||||
void ToV0_1_3();
|
void ToV0_1_3();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user