From 3a76f4a2d829be2ded370c68bd42f82be094fd2d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 8 Sep 2021 18:32:43 +0300 Subject: [PATCH] Added page Tiles Scheme. --- .../puzzle/dialogs/dialogsavemanuallayout.cpp | 117 +++-------- .../puzzle/dialogs/dialogsavemanuallayout.h | 3 + .../puzzle/dialogs/dialogsavemanuallayout.ui | 10 + src/app/puzzle/layout/vppiece.cpp | 2 +- src/app/puzzle/layout/vpsheet.cpp | 25 +++ src/app/puzzle/layout/vpsheet.h | 5 + src/app/puzzle/vpmainwindow.cpp | 197 +++++++++++++----- src/app/puzzle/vpmainwindow.h | 3 +- src/app/puzzle/vptilefactory.cpp | 4 +- 9 files changed, 221 insertions(+), 145 deletions(-) diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp index 52a23e571..4e85c3efc 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.cpp @@ -205,16 +205,6 @@ void DialogSaveManualLayout::SetBinaryDXFFormat(bool binary) case LayoutExportFormats::DXF_AC1027_ASTM: ui->checkBoxBinaryDXF->setChecked(binary); break; - case LayoutExportFormats::SVG: - case LayoutExportFormats::PDF: - case LayoutExportFormats::PDFTiled: - case LayoutExportFormats::PNG: - case LayoutExportFormats::OBJ: - case LayoutExportFormats::PS: - case LayoutExportFormats::EPS: - case LayoutExportFormats::NC: - case LayoutExportFormats::RLD: - case LayoutExportFormats::TIF: default: ui->checkBoxBinaryDXF->setChecked(false); break; @@ -254,16 +244,6 @@ auto DialogSaveManualLayout::IsBinaryDXFFormat() const -> bool case LayoutExportFormats::DXF_AC1024_ASTM: case LayoutExportFormats::DXF_AC1027_ASTM: return ui->checkBoxBinaryDXF->isChecked(); - case LayoutExportFormats::SVG: - case LayoutExportFormats::PDF: - case LayoutExportFormats::PDFTiled: - case LayoutExportFormats::PNG: - case LayoutExportFormats::OBJ: - case LayoutExportFormats::PS: - case LayoutExportFormats::EPS: - case LayoutExportFormats::NC: - case LayoutExportFormats::RLD: - case LayoutExportFormats::TIF: default: return false; } @@ -318,44 +298,10 @@ void DialogSaveManualLayout::SetExportUnified(bool value) case LayoutExportFormats::EPS: ui->checkBoxExportUnified->setChecked(value); break; - case LayoutExportFormats::DXF_AC1006_Flat: - case LayoutExportFormats::DXF_AC1009_Flat: - case LayoutExportFormats::DXF_AC1012_Flat: - case LayoutExportFormats::DXF_AC1014_Flat: - case LayoutExportFormats::DXF_AC1015_Flat: - case LayoutExportFormats::DXF_AC1018_Flat: - case LayoutExportFormats::DXF_AC1021_Flat: - case LayoutExportFormats::DXF_AC1024_Flat: - case LayoutExportFormats::DXF_AC1027_Flat: - case LayoutExportFormats::DXF_AC1006_AAMA: - case LayoutExportFormats::DXF_AC1009_AAMA: - case LayoutExportFormats::DXF_AC1012_AAMA: - case LayoutExportFormats::DXF_AC1014_AAMA: - case LayoutExportFormats::DXF_AC1015_AAMA: - case LayoutExportFormats::DXF_AC1018_AAMA: - case LayoutExportFormats::DXF_AC1021_AAMA: - case LayoutExportFormats::DXF_AC1024_AAMA: - case LayoutExportFormats::DXF_AC1027_AAMA: - case LayoutExportFormats::DXF_AC1006_ASTM: - case LayoutExportFormats::DXF_AC1009_ASTM: - case LayoutExportFormats::DXF_AC1012_ASTM: - case LayoutExportFormats::DXF_AC1014_ASTM: - case LayoutExportFormats::DXF_AC1015_ASTM: - case LayoutExportFormats::DXF_AC1018_ASTM: - case LayoutExportFormats::DXF_AC1021_ASTM: - case LayoutExportFormats::DXF_AC1024_ASTM: - case LayoutExportFormats::DXF_AC1027_ASTM: - case LayoutExportFormats::SVG: - case LayoutExportFormats::PNG: - case LayoutExportFormats::OBJ: - case LayoutExportFormats::NC: - case LayoutExportFormats::RLD: - case LayoutExportFormats::TIF: default: ui->checkBoxExportUnified->setChecked(false); break; } - } //--------------------------------------------------------------------------------------------------------------------- @@ -368,39 +314,32 @@ auto DialogSaveManualLayout::IsExportUnified() const -> bool case LayoutExportFormats::PS: case LayoutExportFormats::EPS: return ui->checkBoxExportUnified->isChecked(); - case LayoutExportFormats::DXF_AC1006_Flat: - case LayoutExportFormats::DXF_AC1009_Flat: - case LayoutExportFormats::DXF_AC1012_Flat: - case LayoutExportFormats::DXF_AC1014_Flat: - case LayoutExportFormats::DXF_AC1015_Flat: - case LayoutExportFormats::DXF_AC1018_Flat: - case LayoutExportFormats::DXF_AC1021_Flat: - case LayoutExportFormats::DXF_AC1024_Flat: - case LayoutExportFormats::DXF_AC1027_Flat: - case LayoutExportFormats::DXF_AC1006_AAMA: - case LayoutExportFormats::DXF_AC1009_AAMA: - case LayoutExportFormats::DXF_AC1012_AAMA: - case LayoutExportFormats::DXF_AC1014_AAMA: - case LayoutExportFormats::DXF_AC1015_AAMA: - case LayoutExportFormats::DXF_AC1018_AAMA: - case LayoutExportFormats::DXF_AC1021_AAMA: - case LayoutExportFormats::DXF_AC1024_AAMA: - case LayoutExportFormats::DXF_AC1027_AAMA: - case LayoutExportFormats::DXF_AC1006_ASTM: - case LayoutExportFormats::DXF_AC1009_ASTM: - case LayoutExportFormats::DXF_AC1012_ASTM: - case LayoutExportFormats::DXF_AC1014_ASTM: - case LayoutExportFormats::DXF_AC1015_ASTM: - case LayoutExportFormats::DXF_AC1018_ASTM: - case LayoutExportFormats::DXF_AC1021_ASTM: - case LayoutExportFormats::DXF_AC1024_ASTM: - case LayoutExportFormats::DXF_AC1027_ASTM: - case LayoutExportFormats::SVG: - case LayoutExportFormats::PNG: - case LayoutExportFormats::OBJ: - case LayoutExportFormats::NC: - case LayoutExportFormats::RLD: - case LayoutExportFormats::TIF: + default: + return false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveManualLayout::SetTilesScheme(bool value) +{ + switch(Format()) + { + case LayoutExportFormats::PDFTiled: + ui->checkBoxTilesScheme->setChecked(value); + break; + default: + ui->checkBoxTilesScheme->setChecked(false); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSaveManualLayout::IsTilesScheme() const +{ + switch(Format()) + { + case LayoutExportFormats::PDFTiled: + return ui->checkBoxTilesScheme->isChecked(); default: return false; } @@ -503,6 +442,7 @@ void DialogSaveManualLayout::ShowExample() ui->checkBoxBinaryDXF->setEnabled(false); ui->checkBoxTextAsPaths->setEnabled(true); ui->checkBoxExportUnified->setEnabled(false); + ui->checkBoxTilesScheme->setEnabled(false); switch(currentFormat) { @@ -539,6 +479,9 @@ void DialogSaveManualLayout::ShowExample() ui->checkBoxTextAsPaths->setEnabled(false); break; case LayoutExportFormats::PDFTiled: + ui->checkBoxTilesScheme->setEnabled(true); + ui->checkBoxExportUnified->setEnabled(true); + break; case LayoutExportFormats::PDF: case LayoutExportFormats::PS: case LayoutExportFormats::EPS: diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.h b/src/app/puzzle/dialogs/dialogsavemanuallayout.h index 8fa47a3a3..8d2bb065c 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.h +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.h @@ -62,6 +62,9 @@ public: void SetExportUnified(bool value); auto IsExportUnified() const -> bool; + void SetTilesScheme(bool value); + auto IsTilesScheme() const -> bool; + protected: virtual void showEvent(QShowEvent *event) override; diff --git a/src/app/puzzle/dialogs/dialogsavemanuallayout.ui b/src/app/puzzle/dialogs/dialogsavemanuallayout.ui index c494d4685..f14638ab3 100644 --- a/src/app/puzzle/dialogs/dialogsavemanuallayout.ui +++ b/src/app/puzzle/dialogs/dialogsavemanuallayout.ui @@ -141,6 +141,16 @@ + + + + false + + + Tiles scheme + + + diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index b422c71d1..a71390392 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -155,7 +155,7 @@ void VPPiece::Update(const VPPiecePtr &piece) } //--------------------------------------------------------------------------------------------------------------------- -QString VPPiece::GetUniqueID() const +auto VPPiece::GetUniqueID() const -> QString { QString id = VLayoutPiece::GetUniqueID(); diff --git a/src/app/puzzle/layout/vpsheet.cpp b/src/app/puzzle/layout/vpsheet.cpp index c54cd4cf8..968215fbc 100644 --- a/src/app/puzzle/layout/vpsheet.cpp +++ b/src/app/puzzle/layout/vpsheet.cpp @@ -255,6 +255,31 @@ void VPSheetSceneData::SetTextAsPaths(bool textAsPaths) const } } +//--------------------------------------------------------------------------------------------------------------------- +void VPSheetSceneData::PrepareTilesScheme() +{ + VPLayoutPtr layout = m_layout.toStrongRef(); + if (not layout.isNull()) + { + m_showTilesSchemeTmp = layout->LayoutSettings().GetShowTiles(); + layout->LayoutSettings().SetShowTiles(true); + } + + RefreshLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheetSceneData::ClearTilesScheme() +{ + VPLayoutPtr layout = m_layout.toStrongRef(); + if (not layout.isNull()) + { + layout->LayoutSettings().SetShowTiles(m_showTilesSchemeTmp); + } + + RefreshLayout(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece) { diff --git a/src/app/puzzle/layout/vpsheet.h b/src/app/puzzle/layout/vpsheet.h index 0aa97d468..e42082968 100644 --- a/src/app/puzzle/layout/vpsheet.h +++ b/src/app/puzzle/layout/vpsheet.h @@ -84,6 +84,9 @@ public: void SetTextAsPaths(bool textAsPaths) const; + void PrepareTilesScheme(); + void ClearTilesScheme(); + private: Q_DISABLE_COPY(VPSheetSceneData) @@ -105,6 +108,8 @@ private: */ bool m_showTilesTmp{false}; + bool m_showTilesSchemeTmp{false}; + /** * variable to hold temporarly hte value of the show grid */ diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 09f9e0f0c..f5e0be6b3 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -156,6 +156,7 @@ struct VPExportData bool isBinaryDXF{false}; bool textAsPaths{false}; bool exportUnified{true}; + bool showTilesScheme{false}; }; //--------------------------------------------------------------------------------------------------------------------- @@ -2440,27 +2441,6 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data) printer.setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) + QCoreApplication::applicationVersion()); - QPageLayout::Orientation tiledPDFOrientation = m_layout->LayoutSettings().GetTilesOrientation(); - - QSizeF tileSize = m_layout->LayoutSettings().GetTilesSize(Unit::Mm); - QSizeF pageSize = tiledPDFOrientation == QPageLayout::Portrait ? tileSize - : QSizeF(tileSize.height(), tileSize.width()); - if (not printer.setPageSize(QPageSize(pageSize, QPageSize::Millimeter))) - { - qWarning() << tr("Cannot set printer page size"); - } - - printer.setPageOrientation(tiledPDFOrientation); - printer.setFullPage(m_layout->LayoutSettings().IgnoreTilesMargins()); - - if (not m_layout->LayoutSettings().IgnoreTilesMargins()) - { - if (not printer.setPageMargins(m_layout->LayoutSettings().GetTilesMargins(Unit::Mm), QPageLayout::Millimeter)) - { - qWarning() << tr("Cannot set printer margins"); - } - } - printer.setResolution(static_cast(PrintDPI)); if (data.exportUnified) @@ -2471,25 +2451,11 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data) printer.setDocName(QFileInfo(name).baseName()); QPainter painter; - if (not painter.begin(&printer)) - { // failed to open file - qCritical() << tr("Failed to open file, is it writable?"); - return; - } - - painter.setPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthMainLine(), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush(QBrush(Qt::NoBrush)); - painter.setRenderHint(QPainter::Antialiasing, true); - - bool firstSheet = true; + bool firstPage = true; for (const auto& sheet : data.sheets) { - GeneratePdfTiledFile(sheet, &painter, &printer, firstSheet); - firstSheet = false; + GeneratePdfTiledFile(sheet, data.showTilesScheme, &painter, &printer, firstPage); } - - painter.end(); } else { @@ -2502,27 +2468,15 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data) printer.setDocName(QFileInfo(name).baseName()); QPainter painter; - if (not painter.begin(&printer)) - { // failed to open file - qCritical() << tr("Failed to open file, is it writable?"); - return; - } - - painter.setPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthMainLine(), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush(QBrush(Qt::NoBrush)); - painter.setRenderHint(QPainter::Antialiasing, true); - - bool firstSheet = true; - GeneratePdfTiledFile(data.sheets.at(i), &painter, &printer, firstSheet); - - painter.end(); + bool firstPage = true; + GeneratePdfTiledFile(data.sheets.at(i), data.showTilesScheme, &painter, &printer, firstPage); } } } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, QPainter *painter, QPrinter *printer, bool firstSheet) +void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, QPainter *painter, + QPrinter *printer, bool &firstPage) { SCASSERT(not sheet.isNull()) SCASSERT(painter != nullptr) @@ -2532,12 +2486,143 @@ void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, QPainter *paint m_layout->TileFactory()->refreshTileInfos(); sheet->SceneData()->SetTextAsPaths(false); + auto SetPageSettings = [this, &printer, sheet](QPageLayout::Orientation orientation, bool forSheet) + { + QSizeF tileSize = m_layout->LayoutSettings().GetTilesSize(Unit::Mm); + QSizeF pageSize; + + if (not forSheet) + { + pageSize = orientation == QPageLayout::Portrait ? tileSize : tileSize.transposed(); + } + else + { + QPageLayout::Orientation tileOrientation = m_layout->LayoutSettings().GetTilesOrientation(); + QPageLayout::Orientation sheetOrientation = sheet->GetSheetOrientation(); + + if (tileOrientation != sheetOrientation) + { + pageSize = orientation == QPageLayout::Portrait ? tileSize.transposed() : tileSize; + } + else + { + pageSize = orientation == QPageLayout::Portrait ? tileSize : tileSize.transposed(); + } + } + + if (not printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter))) + { + qWarning() << tr("Cannot set printer page size"); + } + + printer->setPageOrientation(orientation); + printer->setFullPage(m_layout->LayoutSettings().IgnoreTilesMargins()); + + if (not m_layout->LayoutSettings().IgnoreTilesMargins()) + { + if (not printer->setPageMargins(m_layout->LayoutSettings().GetTilesMargins(Unit::Mm), + QPageLayout::Millimeter)) + { + qWarning() << tr("Cannot set printer margins"); + } + } + }; + + if (showTilesScheme) + { + SetPageSettings(sheet->GetSheetOrientation(), true); + } + else + { + SetPageSettings(m_layout->LayoutSettings().GetTilesOrientation(), false); + } + + if (firstPage) + { + if (not painter->begin(printer)) + { // failed to open file + qCritical() << tr("Failed to open file, is it writable?"); + return; + } + + painter->setPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthMainLine(), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); + painter->setBrush(QBrush(Qt::NoBrush)); + painter->setRenderHint(QPainter::Antialiasing, true); + } + + if (showTilesScheme) + { + VPLayoutPtr layout = sheet->GetLayout(); + if(layout.isNull()) + { + return; + } + + if(not firstPage) + { + SetPageSettings(sheet->GetSheetOrientation(), true); + + if (not printer->newPage()) + { + qWarning("failed in flushing page to disk, disk full?"); + return; + } + } + + sheet->SceneData()->PrepareTilesScheme(); + + qreal xScale = layout->LayoutSettings().HorizontalScale(); + qreal yScale = layout->LayoutSettings().VerticalScale(); + + qreal width = m_layout->TileFactory()->DrawingAreaWidth(); + qreal height = m_layout->TileFactory()->DrawingAreaHeight(); + + QPageLayout::Orientation tileOrientation = m_layout->LayoutSettings().GetTilesOrientation(); + QPageLayout::Orientation sheetOrientation = sheet->GetSheetOrientation(); + + QRectF sheetRect = sheet->GetMarginsRect(); + + const int nbCol = m_layout->TileFactory()->ColNb(sheet); + const int nbRow = m_layout->TileFactory()->RowNb(sheet); + + QRectF source = QRectF(sheetRect.topLeft(), QSizeF(nbCol * ((width - VPTileFactory::tileStripeWidth) / xScale), + nbRow * ((height - VPTileFactory::tileStripeWidth) / yScale))); + QRectF target; + + if (tileOrientation != sheetOrientation) + { + QMarginsF margins; + if (not m_layout->LayoutSettings().IgnoreTilesMargins()) + { + margins = m_layout->LayoutSettings().GetTilesMargins(); + } + + QSizeF tilesSize = layout->LayoutSettings().GetTilesSize(); + target = QRectF(0, 0, + tilesSize.height() - margins.left() - margins.right(), + tilesSize.width() - margins.top() - margins.bottom()); + } + else + { + target = QRectF(0, 0, width, height); + } + sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source, + Qt::KeepAspectRatio); + + sheet->SceneData()->ClearTilesScheme(); + + firstPage = false; + } + for(int row=0; row < m_layout->TileFactory()->RowNb(sheet); row++) // for each row of the tiling grid { for(int col=0; col < m_layout->TileFactory()->ColNb(sheet); col++) // for each column of tiling grid { - if(not (row == 0 && col == 0) || not firstSheet) + if(not firstPage) { + SetPageSettings(m_layout->LayoutSettings().GetTilesOrientation(), false); + if (not printer->newPage()) { qWarning("failed in flushing page to disk, disk full?"); @@ -2546,6 +2631,8 @@ void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, QPainter *paint } m_layout->TileFactory()->drawTile(painter, printer, sheet, row, col); + + firstPage = false; } } @@ -3480,6 +3567,7 @@ void VPMainWindow::on_ExportLayout() data.isBinaryDXF = dialog.IsBinaryDXFFormat(); data.textAsPaths = dialog.IsTextAsPaths(); data.exportUnified = dialog.IsExportUnified(); + data.showTilesScheme = dialog.IsTilesScheme(); ExportData(data); } @@ -3574,6 +3662,7 @@ void VPMainWindow::on_ExportSheet() data.isBinaryDXF = dialog.IsBinaryDXFFormat(); data.textAsPaths = dialog.IsTextAsPaths(); data.exportUnified = dialog.IsExportUnified(); + data.showTilesScheme = dialog.IsTilesScheme(); ExportData(data); } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 5ff32e917..e0b43ad16 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -447,7 +447,8 @@ private: void ExportUnifiedPdfFile(const VPExportData &data); void GenerateUnifiedPdfFile(const VPExportData &data, const QString &name); void ExportPdfTiledFile(const VPExportData &data); - void GeneratePdfTiledFile(const VPSheetPtr &sheet, QPainter *painter, QPrinter *printer, bool firstSheet); + void GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, QPainter *painter, QPrinter *printer, + bool &firstPage); void UpdateScaleConnection() const; }; diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index e761d1560..e17a3784e 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -322,7 +322,7 @@ auto VPTileFactory::RowNb(const VPSheetPtr &sheet) const -> int yScale = layout->LayoutSettings().VerticalScale(); } - QSizeF sheetSize = sheet->GetSheetSize(); + QRectF sheetSize = sheet->GetMarginsRect(); return qCeil(sheetSize.height() * yScale / (m_drawingAreaHeight - tileStripeWidth)); } @@ -341,7 +341,7 @@ auto VPTileFactory::ColNb(const VPSheetPtr &sheet) const -> int xScale = layout->LayoutSettings().HorizontalScale(); } - QSizeF sheetSize = sheet->GetSheetSize(); + QRectF sheetSize = sheet->GetMarginsRect(); return qCeil(sheetSize.width() * xScale / (m_drawingAreaWidth - tileStripeWidth)); }