diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index f6f5b90ee..b422c71d1 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -171,13 +171,19 @@ QString VPPiece::GetUniqueID() const void VPPiece::ClearTransformations() { // Reset the piece position to the default state - QTransform matrix; + SetMatrix(QTransform()); + + // restore original size + QTransform m; + m.scale(GetXScale(), GetYScale()); + QTransform matrix = GetMatrix(); + matrix *= m; SetMatrix(matrix); + // translate the piece so that the top left corner of the bouding rect of the piece is at the position // (0,0) in the sheet coordinate system const QPointF offset = MappedDetailBoundingRect().topLeft(); - matrix.translate(-offset.x() ,-offset.y()); - SetMatrix(matrix); + Translate(-offset.x(), -offset.y()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 25ba9a32e..3e39667ab 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -461,6 +461,8 @@ void VPLayoutFileReader::ReadPiece(const VPPiecePtr &piece) piece->SetName(ReadAttributeEmptyString(attribs, ML::AttrGradationLabel)); piece->SetCopyNumber(static_cast(ReadAttributeUInt(attribs, ML::AttrCopyNumber, QChar('1')))); piece->SetHideMainPath(not ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr)); + piece->SetXScale(ReadAttributeDouble(attribs, ML::AttrXScale, QChar('1'))); + piece->SetYScale(ReadAttributeDouble(attribs, ML::AttrYScale, QChar('1'))); bool pieceMirrored = ReadAttributeBool(attribs, ML::AttrMirrored, falseStr); piece->SetMirror(pieceMirrored); @@ -817,7 +819,7 @@ auto VPLayoutFileReader::ReadLabelLine() -> TextLine } //--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPLayoutFileReader::ReadLayoutMargins(const VPLayoutPtr &layout) +void VPLayoutFileReader::ReadLayoutMargins(const VPLayoutPtr &layout) { QXmlStreamAttributes attribs = attributes(); @@ -834,7 +836,7 @@ QMarginsF VPLayoutFileReader::ReadLayoutMargins(const VPLayoutPtr &layout) } //--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutFileReader::ReadSheetMargins(const VPSheetPtr &sheet) -> QMarginsF +void VPLayoutFileReader::ReadSheetMargins(const VPSheetPtr &sheet) { QXmlStreamAttributes attribs = attributes(); diff --git a/src/app/puzzle/xml/vplayoutfilereader.h b/src/app/puzzle/xml/vplayoutfilereader.h index 9d2b5c0c5..f87a9f855 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.h +++ b/src/app/puzzle/xml/vplayoutfilereader.h @@ -76,8 +76,8 @@ private: auto ReadLabelLines() -> VTextManager; auto ReadLabelLine() -> TextLine; - auto ReadLayoutMargins(const VPLayoutPtr &layout) -> QMarginsF; - auto ReadSheetMargins(const VPSheetPtr &sheet) -> QMarginsF; + void ReadLayoutMargins(const VPLayoutPtr &layout); + void ReadSheetMargins(const VPSheetPtr &sheet); auto ReadSize() -> QSizeF; void AssertRootTag(const QString &tag) const; diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index cc8bffead..7a174d8f9 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -260,6 +260,10 @@ void VPLayoutFileWriter::WritePiece(const VPPiecePtr &piece) [](const QString &label){return label.isEmpty();}); SetAttribute(ML::AttrCopyNumber, piece->CopyNumber()); SetAttributeOrRemoveIf(ML::AttrShowSeamline, not piece->IsHideMainPath(), [](bool show){return show;}); + SetAttributeOrRemoveIf(ML::AttrXScale, piece->GetXScale(), + [](qreal xs){return VFuzzyComparePossibleNulls(xs, 1.0);}); + SetAttributeOrRemoveIf(ML::AttrYScale, piece->GetYScale(), + [](qreal ys){return VFuzzyComparePossibleNulls(ys, 1.0);}); writeStartElement(ML::TagSeamLine); writeCharacters(PathToString(piece->GetContourPoints())); diff --git a/src/libs/ifc/schema/layout/v0.1.0.xsd b/src/libs/ifc/schema/layout/v0.1.0.xsd index a41916c62..b0cc63860 100644 --- a/src/libs/ifc/schema/layout/v0.1.0.xsd +++ b/src/libs/ifc/schema/layout/v0.1.0.xsd @@ -189,7 +189,9 @@ - + + + @@ -357,7 +359,9 @@ - + + + diff --git a/src/libs/vlayout/vlayoutexporter.cpp b/src/libs/vlayout/vlayoutexporter.cpp index bf2732f9d..8e93de220 100644 --- a/src/libs/vlayout/vlayoutexporter.cpp +++ b/src/libs/vlayout/vlayoutexporter.cpp @@ -314,13 +314,17 @@ void VLayoutExporter::ExportToASTMDXF(const QVector &details) cons //--------------------------------------------------------------------------------------------------------------------- void VLayoutExporter::ExportToRLD(const QVector &details) const { + QVector scaledPieces; + scaledPieces.reserve(details.size()); + for(auto detail : details) { detail.Scale(m_xScale, m_yScale); + scaledPieces.append(detail); } VRawLayoutData layoutData; - layoutData.pieces = details; + layoutData.pieces = scaledPieces; VRawLayout generator; if (not generator.WriteFile(m_fileName, layoutData)) diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 5783cd297..767b8f195 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -1058,6 +1058,9 @@ void VLayoutPiece::Translate(const QPointF &p) //--------------------------------------------------------------------------------------------------------------------- void VLayoutPiece::Scale(qreal sx, qreal sy) { + d->m_xScale *= sx; + d->m_yScale *= sy; + QTransform m; m.scale(sx, sy); d->matrix *= m; @@ -1680,6 +1683,30 @@ auto VLayoutPiece::GetGradationId() const -> QString return d->m_gradationId; } +//--------------------------------------------------------------------------------------------------------------------- +auto VLayoutPiece::GetXScale() const -> qreal +{ + return d->m_xScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetXScale(qreal xs) +{ + d->m_xScale = xs; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VLayoutPiece::GetYScale() const -> qreal +{ + return d->m_yScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetYScale(qreal ys) +{ + d->m_yScale = ys; +} + //--------------------------------------------------------------------------------------------------------------------- QLineF VLayoutPiece::Edge(const QVector &path, int i) const { diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 0d9581989..850416a69 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -137,6 +137,12 @@ public: void SetGradationId(const QString &id); auto GetGradationId() const -> QString; + auto GetXScale() const -> qreal; + void SetXScale(qreal xs); + + auto GetYScale() const -> qreal; + void SetYScale(qreal ys); + void Translate(const QPointF &p); void Translate(qreal dx, qreal dy); void Scale(qreal sx, qreal sy); diff --git a/src/libs/vlayout/vlayoutpiece_p.h b/src/libs/vlayout/vlayoutpiece_p.h index 9f435121a..2d5c6c3eb 100644 --- a/src/libs/vlayout/vlayoutpiece_p.h +++ b/src/libs/vlayout/vlayoutpiece_p.h @@ -78,7 +78,9 @@ public: m_square(detail.m_square), m_quantity(detail.m_quantity), m_id(detail.m_id), - m_gradationId(detail.m_gradationId) + m_gradationId(detail.m_gradationId), + m_xScale(detail.m_xScale), + m_yScale(detail.m_yScale) {} ~VLayoutPieceData() Q_DECL_EQ_DEFAULT; @@ -140,6 +142,9 @@ public: QString m_gradationId{}; + qreal m_xScale{1.0}; + qreal m_yScale{1.0}; + private: Q_DISABLE_ASSIGN(VLayoutPieceData) @@ -179,6 +184,8 @@ inline QDataStream &operator<<(QDataStream &dataStream, const VLayoutPieceData & dataStream << piece.m_tmDetail; dataStream << piece.m_tmPattern; dataStream << piece.m_gradationId; + dataStream << piece.m_xScale; + dataStream << piece.m_yScale; return dataStream; } @@ -237,6 +244,8 @@ inline QDataStream &operator>>(QDataStream &dataStream, VLayoutPieceData &piece) dataStream >> piece.m_tmDetail; dataStream >> piece.m_tmPattern; dataStream >> piece.m_gradationId; + dataStream >> piece.m_xScale; + dataStream >> piece.m_yScale; } return dataStream;