From c074318d65b25ca5249a3e4ccf8fdf5d5c953d27 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 8 Jul 2017 20:18:47 +0300 Subject: [PATCH] Resolved issue #716. Command line option to create *tiled* export. --HG-- branch : develop --- ChangeLog.txt | 1 + dist/OBS_debian/debian.valentina.1 | 5 +- dist/debian/valentina.1 | 5 +- .../valentina/dialogs/dialogsavelayout.cpp | 16 +- src/app/valentina/dialogs/dialogsavelayout.h | 1 + src/app/valentina/mainwindow.cpp | 2 - src/app/valentina/mainwindow.ui | 33 +- src/app/valentina/mainwindowsnogui.cpp | 320 +++++++++--------- src/app/valentina/mainwindowsnogui.h | 3 +- 9 files changed, 185 insertions(+), 201 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index bc9ab1410..339403aa7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ - [#712] Default seam allowance setting. - [#630] Improve export: upgrade to DXF r14 format. - [#669] Improve export: export labels as text in DXF. +- [#716] Command line option to create *tiled* export. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/dist/OBS_debian/debian.valentina.1 b/dist/OBS_debian/debian.valentina.1 index 0e480b1f5..0757ba7ee 100644 --- a/dist/OBS_debian/debian.valentina.1 +++ b/dist/OBS_debian/debian.valentina.1 @@ -68,7 +68,10 @@ The path to output destination folder. By default the directory at which the app .BR "*" " AutoCAD DXF 2010 (flat) files (*.dxf) = 13," .RE .RS -.BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14." +.BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14," +.RE +.RS +.BR "*" " PDF tiled files (*.pdf) = 33." .RE .IP "--bdxf" .RB "Export dxf in binary form." diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 0e480b1f5..0757ba7ee 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -68,7 +68,10 @@ The path to output destination folder. By default the directory at which the app .BR "*" " AutoCAD DXF 2010 (flat) files (*.dxf) = 13," .RE .RS -.BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14." +.BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14," +.RE +.RS +.BR "*" " PDF tiled files (*.pdf) = 33." .RE .IP "--bdxf" .RB "Export dxf in binary form." diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 6f280c01e..ac69df1b5 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -87,6 +87,13 @@ DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget * { ui->comboBoxFormat->addItem(v.first, QVariant(static_cast(v.second))); } +#ifdef V_NO_ASSERT // Temporarily unavailable + const int index = ui->comboBoxFormat->findData(LayoutExportFormats::OBJ); + if (index != -1) + { + ui->comboBoxFormat->removeItem(index); + } +#endif connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save); connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample); connect(ui->comboBoxFormat, static_cast(&QComboBox::currentIndexChanged), @@ -176,6 +183,7 @@ void DialogSaveLayout::SetBinaryDXFFormat(bool binary) break; case LayoutExportFormats::SVG: case LayoutExportFormats::PDF: + case LayoutExportFormats::PDFTiled: case LayoutExportFormats::PNG: case LayoutExportFormats::OBJ: case LayoutExportFormats::PS: @@ -221,6 +229,7 @@ bool DialogSaveLayout::IsBinaryDXFFormat() const return ui->checkBoxBinaryDXF->isChecked(); case LayoutExportFormats::SVG: case LayoutExportFormats::PDF: + case LayoutExportFormats::PDFTiled: case LayoutExportFormats::PNG: case LayoutExportFormats::OBJ: case LayoutExportFormats::PS: @@ -344,6 +353,8 @@ QString DialogSaveLayout::ExportFormatDescription(LayoutExportFormats format) return QString("AutoCAD DXF 2010 ASTM %1 %2").arg(filesStr, dxfSuffix); case LayoutExportFormats::DXF_AC1027_ASTM: return QString("AutoCAD DXF 2013 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::PDFTiled: + return QString("PDF tiled %1 (*.pdf)").arg(filesStr); default: return QString(); } @@ -357,6 +368,7 @@ QString DialogSaveLayout::ExportFromatSuffix(LayoutExportFormats format) case LayoutExportFormats::SVG: return ".svg"; case LayoutExportFormats::PDF: + case LayoutExportFormats::PDFTiled: return ".pdf"; case LayoutExportFormats::PNG: return ".png"; @@ -511,6 +523,7 @@ void DialogSaveLayout::ShowExample() break; case LayoutExportFormats::SVG: case LayoutExportFormats::PDF: + case LayoutExportFormats::PDFTiled: case LayoutExportFormats::PNG: case LayoutExportFormats::OBJ: case LayoutExportFormats::PS: @@ -588,9 +601,7 @@ QVector > DialogSaveLayout::InitFormats( InitFormat(LayoutExportFormats::SVG); InitFormat(LayoutExportFormats::PDF); InitFormat(LayoutExportFormats::PNG); -#ifndef V_NO_ASSERT // Temporarily unavailable InitFormat(LayoutExportFormats::OBJ); -#endif if (SupportPSTest()) { InitFormat(LayoutExportFormats::PS); @@ -625,6 +636,7 @@ QVector > DialogSaveLayout::InitFormats( // InitFormat(LayoutExportFormats::DXF_AC1021_ASTM); // InitFormat(LayoutExportFormats::DXF_AC1024_ASTM); // InitFormat(LayoutExportFormats::DXF_AC1027_ASTM); + InitFormat(LayoutExportFormats::PDFTiled); return list; } diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index 513801d26..9dc7b6806 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -77,6 +77,7 @@ enum class LayoutExportFormats : char DXF_AC1021_ASTM = 30, /* ACAD 2007. */ DXF_AC1024_ASTM = 31, /* ACAD 2010. */ DXF_AC1027_ASTM = 32, /* ACAD 2013. */ + PDFTiled = 33, COUNT /*Use only for validation*/ }; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 2cb82d20c..6f7e8012e 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -3343,7 +3343,6 @@ void MainWindow::SetLayoutModeActions() ui->actionExportAs->setEnabled(enabled); ui->actionPrintPreview->setEnabled(enabled); ui->actionPrintPreviewTiled->setEnabled(enabled); - ui->actionSaveAsTiledPDF->setEnabled(enabled); ui->actionPrint->setEnabled(enabled); ui->actionPrintTiled->setEnabled(enabled); } @@ -4013,7 +4012,6 @@ void MainWindow::CreateActions() connect(ui->actionExportAs, &QAction::triggered, this, &MainWindow::ExportLayoutAs); connect(ui->actionPrintPreview, &QAction::triggered, this, &MainWindow::PrintPreviewOrigin); connect(ui->actionPrintPreviewTiled, &QAction::triggered, this, &MainWindow::PrintPreviewTiled); - connect(ui->actionSaveAsTiledPDF, &QAction::triggered, this, &MainWindow::SaveAsTiledPDF); connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::PrintOrigin); connect(ui->actionPrintTiled, &QAction::triggered, this, &MainWindow::PrintTiled); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 6bc597bab..868a9d65f 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -54,7 +54,7 @@ 0 - -32 + 0 127 358 @@ -401,7 +401,7 @@ 0 0 - 127 + 140 110 @@ -510,7 +510,7 @@ 0 0 - 127 + 140 248 @@ -772,7 +772,7 @@ 0 0 - 127 + 140 248 @@ -1121,7 +1121,7 @@ 0 0 140 - 326 + 328 @@ -1512,7 +1512,7 @@ 0 0 140 - 326 + 328 @@ -1626,7 +1626,6 @@ - @@ -2420,24 +2419,6 @@ QAction::NoRole - - - false - - - - :/icon/32x32/pdf.png:/icon/32x32/pdf.png - - - Save as tiled PDF - - - Split and save a layout into smaller pages - - - - - false @@ -2674,8 +2655,8 @@ - + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 70d38a921..cbaf094ba 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -202,13 +202,15 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state) void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) { const QString path = dialog.Path(); + bool usedNotExistedDir = false; QDir dir(path); dir.setPath(path); if (not dir.exists(path)) { - if (not dir.mkpath(path)) + usedNotExistedDir = dir.mkpath("."); + if (not usedNotExistedDir) { - qCritical() << tr("Can't create path"); + qCritical() << tr("Can't create a path"); return; } } @@ -216,126 +218,135 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) const QString mask = dialog.FileName(); const LayoutExportFormats format = dialog.Format(); - for (int i=0; i < scenes.size(); ++i) + if (format == LayoutExportFormats::PDFTiled) { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) + const QString name = path + QLatin1String("/") + mask + QString::number(1) + + DialogSaveLayout::ExportFromatSuffix(format); + PdfTiledFile(name); + } + else + { + for (int i=0; i < scenes.size(); ++i) { - const QString name = path + QLatin1String("/") + mask+QString::number(i+1) - + DialogSaveLayout::ExportFromatSuffix(format); - QBrush *brush = new QBrush(); - brush->setColor( QColor( Qt::white ) ); - scenes[i]->setBackgroundBrush( *brush ); - shadows[i]->setVisible(false); - paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); - - switch (format) + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) { - 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: - Q_UNREACHABLE(); // For now not supported - case LayoutExportFormats::SVG: - paper->setVisible(false); - SvgFile(name, i); - paper->setVisible(true); - break; - case LayoutExportFormats::PDF: - PdfFile(name, i); - break; - case LayoutExportFormats::PNG: - PngFile(name, i); - break; - case LayoutExportFormats::OBJ: - paper->setVisible(false); - ObjFile(name, i); - paper->setVisible(true); - break; - case LayoutExportFormats::PS: - PsFile(name, i); - break; - case LayoutExportFormats::EPS: - EpsFile(name, i); - break; - case LayoutExportFormats::DXF_AC1006_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1009_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1012_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1014_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1015_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1018_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1021_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1024_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1027_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), i); - paper->setVisible(true); - break; - default: - qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO; - break; + const QString name = path + QLatin1String("/") + mask+QString::number(i+1) + + DialogSaveLayout::ExportFromatSuffix(format); + QBrush *brush = new QBrush(); + brush->setColor( QColor( Qt::white ) ); + scenes[i]->setBackgroundBrush( *brush ); + shadows[i]->setVisible(false); + paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); + + switch (format) + { + case LayoutExportFormats::PDFTiled: // Handled separately + 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: + Q_UNREACHABLE(); // For now not supported + case LayoutExportFormats::SVG: + paper->setVisible(false); + SvgFile(name, i); + paper->setVisible(true); + break; + case LayoutExportFormats::PDF: + PdfFile(name, i); + break; + case LayoutExportFormats::PNG: + PngFile(name, i); + break; + case LayoutExportFormats::OBJ: + paper->setVisible(false); + ObjFile(name, i); + paper->setVisible(true); + break; + case LayoutExportFormats::PS: + PsFile(name, i); + break; + case LayoutExportFormats::EPS: + EpsFile(name, i); + break; + case LayoutExportFormats::DXF_AC1006_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1009_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1012_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1014_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1015_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1018_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1021_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1024_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1027_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + default: + qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO; + break; + } + paper->setPen(QPen(Qt::black, 1)); + brush->setColor( QColor( Qt::gray ) ); + brush->setStyle( Qt::SolidPattern ); + scenes[i]->setBackgroundBrush( *brush ); + shadows[i]->setVisible(true); + delete brush; } - paper->setPen(QPen(Qt::black, 1)); - brush->setColor( QColor( Qt::gray ) ); - brush->setStyle( Qt::SolidPattern ); - scenes[i]->setBackgroundBrush( *brush ); - shadows[i]->setVisible(true); - delete brush; } } -} -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::SaveAsTiledPDF() -{ - isTiled = true; - SaveLayoutAs(); + if (usedNotExistedDir) + { + QDir directory(dir); + directory.rmpath("."); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -749,6 +760,33 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::PdfTiledFile(const QString &name) +{ + isTiled = true; + + if (isLayoutStale) + { + if (ContinueIfLayoutStale() == QMessageBox::No) + { + return; + } + } + QPrinter printer; + SetPrinterSettings(&printer, PrintType::PrintPDF); + printer.setPageSize(QPrinter::A4);// Want to be sure that page size is correct. + + // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size + if (not isTiled && not IsPagesFit(printer.paperRect().size())) + { + qWarning()<(PrintDPI)); + PrintPages( &printer ); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief EpsFile save layout to eps file. @@ -974,58 +1012,6 @@ void MainWindowsNoGUI::RestoreTextAfterDXF(const QString &placeholder) const } } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::SaveLayoutAs() -{ - if (isLayoutStale) - { - if (ContinueIfLayoutStale() == QMessageBox::No) - { - return; - } - } - QPrinter printer; - SetPrinterSettings(&printer, PrintType::PrintPDF); - printer.setPageSize(QPrinter::A4);// Want to be sure that page size is correct. - - // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size - if (not isTiled && not IsPagesFit(printer.paperRect().size())) - { - qWarning()<ValentinaSettings()->GetPathLayout(); - bool usedNotExistedDir = false; - QDir directory(dir); - if (not directory.exists()) - { - usedNotExistedDir = directory.mkpath("."); - } - - QString fileName = QFileDialog::getSaveFileName(this, tr("Print to pdf"), - dir + QLatin1String("/") + FileName() + QLatin1String(".pdf"), - tr("PDF file (*.pdf)"), nullptr, QFileDialog::DontUseNativeDialog); - if (not fileName.isEmpty()) - { - QFileInfo f( fileName ); - if(f.suffix().isEmpty()) - { - fileName.append(".pdf"); - } - qApp->ValentinaSettings()->SetPathLayout(f.absolutePath()); - - printer.setOutputFileName(fileName); - printer.setResolution(static_cast(PrintDPI)); - PrintPages( &printer ); - } - - if (usedNotExistedDir) - { - QDir directory(dir); - directory.rmpath("."); - } -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrintPreview() { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 0bfba5c03..441fc71e6 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -50,7 +50,6 @@ public: public slots: void ToolLayoutSettings(bool checked); - void SaveAsTiledPDF(); void PrintPreviewOrigin(); void PrintPreviewTiled(); void PrintOrigin(); @@ -117,6 +116,7 @@ private: void SvgFile(const QString &name, int i)const; void PngFile(const QString &name, int i)const; void PdfFile(const QString &name, int i)const; + void PdfTiledFile(const QString &name); void EpsFile(const QString &name, int i)const; void PsFile(const QString &name, int i)const; void PdfToPs(const QStringList ¶ms)const; @@ -129,7 +129,6 @@ private: void PrepareTextForDXF(const QString &placeholder) const; void RestoreTextAfterDXF(const QString &placeholder) const; - void SaveLayoutAs(); void PrintPreview(); void LayoutPrint();