Keep original scale from raw layout data.

This commit is contained in:
Roman Telezhynskyi 2021-09-08 12:57:12 +03:00
parent 84cf53f612
commit a3e5948167
9 changed files with 73 additions and 11 deletions

View File

@ -171,13 +171,19 @@ QString VPPiece::GetUniqueID() const
void VPPiece::ClearTransformations() void VPPiece::ClearTransformations()
{ {
// Reset the piece position to the default state // 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); SetMatrix(matrix);
// translate the piece so that the top left corner of the bouding rect of the piece is at the position // 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 // (0,0) in the sheet coordinate system
const QPointF offset = MappedDetailBoundingRect().topLeft(); const QPointF offset = MappedDetailBoundingRect().topLeft();
matrix.translate(-offset.x() ,-offset.y()); Translate(-offset.x(), -offset.y());
SetMatrix(matrix);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -461,6 +461,8 @@ void VPLayoutFileReader::ReadPiece(const VPPiecePtr &piece)
piece->SetName(ReadAttributeEmptyString(attribs, ML::AttrGradationLabel)); piece->SetName(ReadAttributeEmptyString(attribs, ML::AttrGradationLabel));
piece->SetCopyNumber(static_cast<quint16>(ReadAttributeUInt(attribs, ML::AttrCopyNumber, QChar('1')))); piece->SetCopyNumber(static_cast<quint16>(ReadAttributeUInt(attribs, ML::AttrCopyNumber, QChar('1'))));
piece->SetHideMainPath(not ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr)); 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); bool pieceMirrored = ReadAttributeBool(attribs, ML::AttrMirrored, falseStr);
piece->SetMirror(pieceMirrored); 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(); 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(); QXmlStreamAttributes attribs = attributes();

View File

@ -76,8 +76,8 @@ private:
auto ReadLabelLines() -> VTextManager; auto ReadLabelLines() -> VTextManager;
auto ReadLabelLine() -> TextLine; auto ReadLabelLine() -> TextLine;
auto ReadLayoutMargins(const VPLayoutPtr &layout) -> QMarginsF; void ReadLayoutMargins(const VPLayoutPtr &layout);
auto ReadSheetMargins(const VPSheetPtr &sheet) -> QMarginsF; void ReadSheetMargins(const VPSheetPtr &sheet);
auto ReadSize() -> QSizeF; auto ReadSize() -> QSizeF;
void AssertRootTag(const QString &tag) const; void AssertRootTag(const QString &tag) const;

View File

@ -260,6 +260,10 @@ void VPLayoutFileWriter::WritePiece(const VPPiecePtr &piece)
[](const QString &label){return label.isEmpty();}); [](const QString &label){return label.isEmpty();});
SetAttribute(ML::AttrCopyNumber, piece->CopyNumber()); SetAttribute(ML::AttrCopyNumber, piece->CopyNumber());
SetAttributeOrRemoveIf<bool>(ML::AttrShowSeamline, not piece->IsHideMainPath(), [](bool show){return show;}); SetAttributeOrRemoveIf<bool>(ML::AttrShowSeamline, not piece->IsHideMainPath(), [](bool show){return show;});
SetAttributeOrRemoveIf<qreal>(ML::AttrXScale, piece->GetXScale(),
[](qreal xs){return VFuzzyComparePossibleNulls(xs, 1.0);});
SetAttributeOrRemoveIf<qreal>(ML::AttrYScale, piece->GetYScale(),
[](qreal ys){return VFuzzyComparePossibleNulls(ys, 1.0);});
writeStartElement(ML::TagSeamLine); writeStartElement(ML::TagSeamLine);
writeCharacters(PathToString(piece->GetContourPoints())); writeCharacters(PathToString(piece->GetContourPoints()));

View File

@ -190,6 +190,8 @@
<xs:attribute type="xs:string" name="gradationLabel"/> <xs:attribute type="xs:string" name="gradationLabel"/>
<xs:attribute type="xs:unsignedInt" name="copyNumber"/> <xs:attribute type="xs:unsignedInt" name="copyNumber"/>
<xs:attribute type="xs:boolean" name="showSeamline"/> <xs:attribute type="xs:boolean" name="showSeamline"/>
<xs:attribute type="xs:float" name="xScale"/>
<xs:attribute type="xs:float" name="yScale"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
@ -358,6 +360,8 @@
<xs:attribute type="xs:string" name="gradationLabel"/> <xs:attribute type="xs:string" name="gradationLabel"/>
<xs:attribute type="xs:unsignedInt" name="copyNumber"/> <xs:attribute type="xs:unsignedInt" name="copyNumber"/>
<xs:attribute type="xs:boolean" name="showSeamline"/> <xs:attribute type="xs:boolean" name="showSeamline"/>
<xs:attribute type="xs:float" name="xScale"/>
<xs:attribute type="xs:float" name="yScale"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>

View File

@ -314,13 +314,17 @@ void VLayoutExporter::ExportToASTMDXF(const QVector<VLayoutPiece> &details) cons
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToRLD(const QVector<VLayoutPiece> &details) const void VLayoutExporter::ExportToRLD(const QVector<VLayoutPiece> &details) const
{ {
QVector<VLayoutPiece> scaledPieces;
scaledPieces.reserve(details.size());
for(auto detail : details) for(auto detail : details)
{ {
detail.Scale(m_xScale, m_yScale); detail.Scale(m_xScale, m_yScale);
scaledPieces.append(detail);
} }
VRawLayoutData layoutData; VRawLayoutData layoutData;
layoutData.pieces = details; layoutData.pieces = scaledPieces;
VRawLayout generator; VRawLayout generator;
if (not generator.WriteFile(m_fileName, layoutData)) if (not generator.WriteFile(m_fileName, layoutData))

View File

@ -1058,6 +1058,9 @@ void VLayoutPiece::Translate(const QPointF &p)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::Scale(qreal sx, qreal sy) void VLayoutPiece::Scale(qreal sx, qreal sy)
{ {
d->m_xScale *= sx;
d->m_yScale *= sy;
QTransform m; QTransform m;
m.scale(sx, sy); m.scale(sx, sy);
d->matrix *= m; d->matrix *= m;
@ -1680,6 +1683,30 @@ auto VLayoutPiece::GetGradationId() const -> QString
return d->m_gradationId; 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<QPointF> &path, int i) const QLineF VLayoutPiece::Edge(const QVector<QPointF> &path, int i) const
{ {

View File

@ -137,6 +137,12 @@ public:
void SetGradationId(const QString &id); void SetGradationId(const QString &id);
auto GetGradationId() const -> QString; 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(const QPointF &p);
void Translate(qreal dx, qreal dy); void Translate(qreal dx, qreal dy);
void Scale(qreal sx, qreal sy); void Scale(qreal sx, qreal sy);

View File

@ -78,7 +78,9 @@ public:
m_square(detail.m_square), m_square(detail.m_square),
m_quantity(detail.m_quantity), m_quantity(detail.m_quantity),
m_id(detail.m_id), 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; ~VLayoutPieceData() Q_DECL_EQ_DEFAULT;
@ -140,6 +142,9 @@ public:
QString m_gradationId{}; QString m_gradationId{};
qreal m_xScale{1.0};
qreal m_yScale{1.0};
private: private:
Q_DISABLE_ASSIGN(VLayoutPieceData) Q_DISABLE_ASSIGN(VLayoutPieceData)
@ -179,6 +184,8 @@ inline QDataStream &operator<<(QDataStream &dataStream, const VLayoutPieceData &
dataStream << piece.m_tmDetail; dataStream << piece.m_tmDetail;
dataStream << piece.m_tmPattern; dataStream << piece.m_tmPattern;
dataStream << piece.m_gradationId; dataStream << piece.m_gradationId;
dataStream << piece.m_xScale;
dataStream << piece.m_yScale;
return dataStream; return dataStream;
} }
@ -237,6 +244,8 @@ inline QDataStream &operator>>(QDataStream &dataStream, VLayoutPieceData &piece)
dataStream >> piece.m_tmDetail; dataStream >> piece.m_tmDetail;
dataStream >> piece.m_tmPattern; dataStream >> piece.m_tmPattern;
dataStream >> piece.m_gradationId; dataStream >> piece.m_gradationId;
dataStream >> piece.m_xScale;
dataStream >> piece.m_yScale;
} }
return dataStream; return dataStream;