From 7d205d75964f5c58d1625746c10341eab50272d1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 9 Jul 2017 14:45:49 +0300 Subject: [PATCH] Resolved issue #660. New export: Export details without layout. --HG-- branch : develop --- ChangeLog.txt | 1 + dist/debian/valentina.1 | 2 + src/app/valentina/core/vcmdexport.cpp | 12 + src/app/valentina/core/vcmdexport.h | 1 + .../valentina/dialogs/dialogsavelayout.cpp | 56 ++- src/app/valentina/dialogs/dialogsavelayout.h | 14 +- src/app/valentina/dialogs/dialogsavelayout.ui | 38 +- src/app/valentina/mainwindow.cpp | 106 +++++- src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 29 +- src/app/valentina/mainwindowsnogui.cpp | 352 ++++++++++-------- src/app/valentina/mainwindowsnogui.h | 34 +- src/libs/vmisc/commandoptions.cpp | 3 +- src/libs/vmisc/commandoptions.h | 1 + 14 files changed, 443 insertions(+), 207 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 339403aa7..6d4a09506 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,7 @@ - [#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. +- [#660] New export: Export details without layout. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 0757ba7ee..5a0b89154 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -77,6 +77,8 @@ The path to output destination folder. By default the directory at which the app .RB "Export dxf in binary form." .IP "--text2paths" .RB "Export text as paths." +.IP "--exportOnlyDetails" +.RB "Export only details. Export details as they positioned in the details mode. Any layout related options will be ignored." .IP "-x, --gsize " .RB "Set size value a pattern file, that was opened with standard measurements " "(export mode)" ". Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56cm." .IP "-e, --gheight " diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 73ab2f0fb..09363c9a4 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -108,6 +108,12 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap options.append(new QCommandLineOption(QStringList() << LONG_OPTION_TEXT2PATHS, translate("VCommandLine", "Export text as paths."))); + optionsIndex.insert(LONG_OPTION_EXPORTONLYDETAILS, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_EXPORTONLYDETAILS, + translate("VCommandLine", "Export only details. Export details as they " + "positioned in the details mode. Any layout related" + " options will be ignored."))); + optionsIndex.insert(LONG_OPTION_GRADATIONSIZE, index++); options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE, translate("VCommandLine", "Set size value a pattern file, that was opened " @@ -637,6 +643,12 @@ int VCommandLine::IsTextAsPaths() const return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TEXT2PATHS))); } +//--------------------------------------------------------------------------------------------------------------------- +int VCommandLine::IsExportOnlyDetails() const +{ + return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXPORTONLYDETAILS))); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VCommandLine::OptInputFileNames() const { diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index a27e60333..429947578 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -77,6 +77,7 @@ public: int IsBinaryDXF() const; int IsTextAsPaths() const; + int IsExportOnlyDetails() const; //generator creation is moved here ... because most options are for it only, so no need to create extra getters... //@brief creates VLayoutGenerator diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 3b736dec1..83babbe83 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -46,11 +46,12 @@ bool DialogSaveLayout::havePdf = false; bool DialogSaveLayout::tested = false; //--------------------------------------------------------------------------------------------------------------------- -DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget *parent) +DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName, QWidget *parent) : QDialog(parent), ui(new Ui::DialogSaveLAyout), count(count), - isInitialized(false) + isInitialized(false), + m_mode(mode) { ui->setupUi(this); @@ -88,12 +89,18 @@ 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(static_cast(LayoutExportFormats::OBJ)); - if (index != -1) - { - ui->comboBoxFormat->removeItem(index); - } + RemoveFormatFromList(LayoutExportFormats::OBJ); #endif + + if (m_mode != Draw::Layout) + { + RemoveFormatFromList(LayoutExportFormats::PDFTiled); + } + else + { + ui->checkBoxTextAsPaths->setVisible(false); + } + connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save); connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample); connect(ui->comboBoxFormat, static_cast(&QComboBox::currentIndexChanged), @@ -278,6 +285,12 @@ void DialogSaveLayout::SetDestinationPath(const QString &cmdDestinationPath) ui->lineEditPath->setText(path); } +//--------------------------------------------------------------------------------------------------------------------- +Draw DialogSaveLayout::Mode() const +{ + return m_mode; +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogSaveLayout::ExportFormatDescription(LayoutExportFormats format) { @@ -534,6 +547,25 @@ void DialogSaveLayout::ShowExample() } } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSaveLayout::IsTextAsPaths() const +{ + return ui->checkBoxTextAsPaths->isChecked(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveLayout::SetTextAsPaths(bool textAsPaths) +{ + if (m_mode != Draw::Layout) + { + ui->checkBoxTextAsPaths->setChecked(textAsPaths); + } + else + { + ui->checkBoxTextAsPaths->setChecked(false); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSaveLayout::showEvent(QShowEvent *event) { @@ -640,3 +672,13 @@ QVector > DialogSaveLayout::InitFormats( return list; } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveLayout::RemoveFormatFromList(LayoutExportFormats format) +{ + const int index = ui->comboBoxFormat->findData(static_cast(format)); + if (index != -1) + { + ui->comboBoxFormat->removeItem(index); + } +} diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index 9dc7b6806..47325074d 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -30,6 +30,7 @@ #define DIALOGSAVELAYOUT_H #include +#include "../vgeometry/vgeometrydef.h" #ifdef Q_OS_WIN # define PDFTOPS "pdftops.exe" @@ -86,7 +87,8 @@ class DialogSaveLayout : public QDialog Q_OBJECT public: - explicit DialogSaveLayout(int count, const QString &fileName = QString(), QWidget *parent = nullptr); + explicit DialogSaveLayout(int count, Draw mode = Draw::Layout, const QString &fileName = QString(), + QWidget *parent = nullptr); virtual ~DialogSaveLayout(); QString Path() const; @@ -101,8 +103,14 @@ public: static QString MakeHelpFormatList(); void SetDestinationPath(const QString& cmdDestinationPath); + Draw Mode() const; + static QString ExportFormatDescription(LayoutExportFormats format); static QString ExportFromatSuffix(LayoutExportFormats format); + + bool IsTextAsPaths() const; + void SetTextAsPaths(bool textAsPaths); + protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; private slots: @@ -114,11 +122,15 @@ private: Ui::DialogSaveLAyout *ui; int count; bool isInitialized; + Draw m_mode; + static bool havePdf; static bool tested; static bool SupportPSTest(); static bool TestPdf(); static QVector > InitFormats(); + + void RemoveFormatFromList(LayoutExportFormats format); }; #endif // DIALOGSAVELAYOUT_H diff --git a/src/app/valentina/dialogs/dialogsavelayout.ui b/src/app/valentina/dialogs/dialogsavelayout.ui index e98cf5706..c8b16be3e 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.ui +++ b/src/app/valentina/dialogs/dialogsavelayout.ui @@ -7,7 +7,7 @@ 0 0 748 - 178 + 206 @@ -92,14 +92,31 @@ - + + + + + + + + + + + false + + + Binary form + + + + File name: - + @@ -135,20 +152,13 @@ - - - - - - - - - + + - false + true - Binary form + Text as paths diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 8a77b0bea..aebac0ed6 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1947,6 +1947,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonMove, &QToolButton::clicked, this, &MainWindow::ToolMove); connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs); + connect(ui->toolButtonDetailExportAs, &QToolButton::clicked, this, &MainWindow::ExportDetailsAs); connect(ui->toolButtonEllipticalArc, &QToolButton::clicked, this, &MainWindow::ToolEllipticalArc); connect(ui->toolButtonPin, &QToolButton::clicked, this, &MainWindow::ToolPin); connect(ui->toolButtonInsertNode, &QToolButton::clicked, this, &MainWindow::ToolInsertNode); @@ -2461,7 +2462,7 @@ void MainWindow::ActionLayout(bool checked) try { - PrepareDetailsForLayout(&details); + listDetails = PrepareDetailsForLayout(details); } catch (VException &e) { @@ -3329,6 +3330,7 @@ void MainWindow::SetEnableTool(bool enable) //Modeling Tools ui->toolButtonUnionDetails->setEnabled(modelingTools); + ui->toolButtonDetailExportAs->setEnabled(modelingTools); //Layout tools ui->toolButtonLayoutSettings->setEnabled(layoutTools); @@ -4389,7 +4391,7 @@ void MainWindow::ExportLayoutAs() try { - DialogSaveLayout dialog(scenes.size(), FileName(), this); + DialogSaveLayout dialog(scenes.size(), Draw::Layout, FileName(), this); if (dialog.exec() == QDialog::Rejected) { @@ -4397,7 +4399,7 @@ void MainWindow::ExportLayoutAs() return; } - ExportLayout(dialog); + ExportLayout(dialog, scenes, papers, shadows, ignorePrinterFields, margins); } catch (const VException &e) { @@ -4409,6 +4411,64 @@ void MainWindow::ExportLayoutAs() ui->toolButtonLayoutExportAs->setChecked(false); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ExportDetailsAs() +{ + const QHash *allDetails = pattern->DataPieces(); + QHash::const_iterator i = allDetails->constBegin(); + QHash detailsInLayout; + while (i != allDetails->constEnd()) + { + if (i.value().IsInLayout()) + { + detailsInLayout.insert(i.key(), i.value()); + } + ++i; + } + + if (detailsInLayout.count() == 0) + { + QMessageBox::information(this, tr("Layout mode"), tr("You don't have enough details to export. Please, " + "include at least one detail in layout."), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + + QVector listDetails; + try + { + listDetails = PrepareDetailsForLayout(detailsInLayout); + } + catch (VException &e) + { + QMessageBox::warning(this, tr("Export details"), + tr("Can't export details.") + QLatin1String(" \n") + e.ErrorMessage(), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + + try + { + DialogSaveLayout dialog(1, Draw::Modeling, FileName(), this); + + if (dialog.exec() == QDialog::Rejected) + { + ui->toolButtonDetailExportAs->setChecked(false); + return; + } + + ExportData(listDetails, dialog); + } + catch (const VException &e) + { + ui->toolButtonDetailExportAs->setChecked(false); + qCritical("%s\n\n%s\n\n%s", qUtf8Printable(tr("Export error.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + return; + } + ui->toolButtonDetailExportAs->setChecked(false); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ReopenFilesAfterCrash(QStringList &args) { @@ -4686,20 +4746,20 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) return; } } - PrepareDetailsForLayout(details); + listDetails = PrepareDetailsForLayout(*details); - auto settings = expParams->DefaultGenerator(); - settings->SetTestAsPaths(expParams->IsTextAsPaths()); - - if (LayoutSettings(*settings.get())) + const bool exportOnlyDetails = expParams->IsExportOnlyDetails(); + if (exportOnlyDetails) { try { - DialogSaveLayout dialog(scenes.size(), expParams->OptBaseName(), this); + DialogSaveLayout dialog(1, Draw::Modeling, expParams->OptBaseName(), this); dialog.SetDestinationPath(expParams->OptDestinationPath()); dialog.SelectFormat(static_cast(expParams->OptExportType())); dialog.SetBinaryDXFFormat(expParams->IsBinaryDXF()); - ExportLayout(dialog); + dialog.SetTextAsPaths(expParams->IsTextAsPaths()); + + ExportData(listDetails, dialog); } catch (const VException &e) { @@ -4710,7 +4770,31 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) } else { - return; + auto settings = expParams->DefaultGenerator(); + settings->SetTestAsPaths(expParams->IsTextAsPaths()); + + if (LayoutSettings(*settings.get())) + { + try + { + DialogSaveLayout dialog(scenes.size(), Draw::Layout, expParams->OptBaseName(), this); + dialog.SetDestinationPath(expParams->OptDestinationPath()); + dialog.SelectFormat(static_cast(expParams->OptExportType())); + dialog.SetBinaryDXFFormat(expParams->IsBinaryDXF()); + + ExportData(listDetails, dialog); + } + catch (const VException &e) + { + qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Export error.")), qUtf8Printable(e.ErrorMessage())); + qApp->exit(V_EX_DATAERR); + return; + } + } + else + { + return; + } } qApp->exit(V_EX_OK); diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 5896f8b7b..1a4562586 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -118,6 +118,7 @@ private slots: void CreateMeasurements(); #endif void ExportLayoutAs(); + void ExportDetailsAs(); void ArrowTool(); void ToolEndLine(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 868a9d65f..cda35ab90 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -45,10 +45,10 @@ - Tools + Export details skiping the Layout stage - 5 + 6 @@ -1504,6 +1504,29 @@ + + + + false + + + ... + + + + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png + + + + 32 + 32 + + + + true + + + @@ -2655,8 +2678,8 @@ - + diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 20abe8712..54b0b3027 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -149,8 +149,8 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator) CleanLayout(); papers = lGenerator.GetPapersItems();// Blank sheets details = lGenerator.GetAllDetails();// All details - CreateShadows(); - CreateScenes(); + shadows = CreateShadows(papers); + scenes = CreateScenes(papers, shadows, details); PrepareSceneList(); ignorePrinterFields = not lGenerator.IsUsePrinterFields(); margins = lGenerator.GetPrinterFields(); @@ -199,7 +199,48 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state) } //--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) +void MainWindowsNoGUI::ExportData(const QVector &listDetails, const DialogSaveLayout &dialog) +{ + if (dialog.Mode() == Draw::Layout) + { + ExportLayout(dialog, scenes, papers, shadows, ignorePrinterFields, margins); + } + else + { + QScopedPointer scene(new QGraphicsScene()); + + QList list; + for (int i=0; i < listDetails.count(); ++i) + { + list.append(listDetails.at(i).GetItem(dialog.IsTextAsPaths())); + } + + for (int i=0; i < list.size(); ++i) + { + scene->addItem(list.at(i)); + } + + QList papers;// Blank sheets + papers.append(new QGraphicsRectItem(scene->itemsBoundingRect().toRect())); + + QList > details;// All details + details.append(list); + + QList shadows = CreateShadows(papers); + QList scenes = CreateScenes(papers, shadows, details); + + const bool ignorePrinterFields = false; + const qreal margin = ToPixel(2, Unit::Mm); + ExportLayout(dialog, scenes, papers, shadows, ignorePrinterFields, QMarginsF(margin, margin, margin, margin)); + + qDeleteAll(scenes);//Scene will clear all other items + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog, const QList &scenes, + const QList &papers, const QList &shadows, + bool ignorePrinterFields, const QMarginsF &margins) { const QString path = dialog.Path(); bool usedNotExistedDir = false; @@ -218,7 +259,7 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) const QString mask = dialog.FileName(); const LayoutExportFormats format = dialog.Format(); - if (format == LayoutExportFormats::PDFTiled) + if (format == LayoutExportFormats::PDFTiled && dialog.Mode() == Draw::Layout) { const QString name = path + QLatin1String("/") + mask + QString::number(1) + DialogSaveLayout::ExportFromatSuffix(format); @@ -235,7 +276,8 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) + DialogSaveLayout::ExportFromatSuffix(format); QBrush *brush = new QBrush(); brush->setColor( QColor( Qt::white ) ); - scenes[i]->setBackgroundBrush( *brush ); + QGraphicsScene *scene = scenes.at(i); + scene->setBackgroundBrush( *brush ); shadows[i]->setVisible(false); paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); @@ -264,69 +306,69 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) break; case LayoutExportFormats::SVG: paper->setVisible(false); - SvgFile(name, i); + SvgFile(name, paper, scene); paper->setVisible(true); break; case LayoutExportFormats::PDF: - PdfFile(name, i); + PdfFile(name, paper, scene, ignorePrinterFields, margins); break; case LayoutExportFormats::PNG: - PngFile(name, i); + PngFile(name, paper, scene); break; case LayoutExportFormats::OBJ: paper->setVisible(false); - ObjFile(name, i); + ObjFile(name, paper, scene); paper->setVisible(true); break; case LayoutExportFormats::PS: - PsFile(name, i); + PsFile(name, paper, scene, ignorePrinterFields, margins); break; case LayoutExportFormats::EPS: - EpsFile(name, i); + EpsFile(name, paper, scene, ignorePrinterFields, margins); break; case LayoutExportFormats::DXF_AC1006_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1009_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1012_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1014_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1015_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1018_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1021_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1024_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1027_Flat: paper->setVisible(false); - DxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), i); + DxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), paper, scene); paper->setVisible(true); break; default: @@ -561,23 +603,22 @@ void MainWindowsNoGUI::RefreshDetailsLabel() } //--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *details) +QVector MainWindowsNoGUI::PrepareDetailsForLayout(const QHash &details) { - listDetails.clear(); - SCASSERT(details != nullptr) - if (details->count() == 0) + QVector listDetails; + if (not details.isEmpty()) { - return; + QHash::const_iterator i = details.constBegin(); + while (i != details.constEnd()) + { + VAbstractTool *tool = qobject_cast(VAbstractPattern::getTool(i.key())); + SCASSERT(tool != nullptr) + listDetails.append(VLayoutPiece::Create(i.value(), tool->getData())); + ++i; + } } - QHash::const_iterator i = details->constBegin(); - while (i != details->constEnd()) - { - VAbstractTool *tool = qobject_cast(VAbstractPattern::getTool(i.key())); - SCASSERT(tool != nullptr) - listDetails.append(VLayoutPiece::Create(i.value(), tool->getData())); - ++i; - } + return listDetails; } //--------------------------------------------------------------------------------------------------------------------- @@ -623,8 +664,10 @@ QIcon MainWindowsNoGUI::ScenePreview(int i) const } //--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::CreateShadows() +QList MainWindowsNoGUI::CreateShadows(const QList &papers) { + QList shadows; + for (int i=0; i< papers.size(); ++i) { qreal x1=0, y1=0, x2=0, y2=0; @@ -641,11 +684,16 @@ void MainWindowsNoGUI::CreateShadows() shadows.append(nullptr); } } + + return shadows; } //--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::CreateScenes() +QList MainWindowsNoGUI::CreateScenes(const QList &papers, + const QList &shadows, + const QList > &details) { + QList scenes; for (int i=0; i(papers.at(i)); - if (paper) - { - QSvgGenerator generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setViewBox(paper->rect()); - generator.setTitle("Valentina. Pattern layout"); - generator.setDescription(doc->GetDescription()); - generator.setResolution(static_cast(PrintDPI)); - QPainter painter; - painter.begin(&generator); - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, widthHairLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); - painter.end(); - } + QSvgGenerator generator; + generator.setFileName(name); + generator.setSize(paper->rect().size().toSize()); + generator.setViewBox(paper->rect()); + generator.setTitle(tr("Pattern")); + generator.setDescription(doc->GetDescription()); + generator.setResolution(static_cast(PrintDPI)); + QPainter painter; + painter.begin(&generator); + painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, widthHairLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + scene->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); + painter.end(); } //--------------------------------------------------------------------------------------------------------------------- @@ -696,23 +742,19 @@ void MainWindowsNoGUI::SvgFile(const QString &name, int i) const * @brief PngFile save layout to png file. * @param name name layout file. */ -void MainWindowsNoGUI::PngFile(const QString &name, int i) const +void MainWindowsNoGUI::PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene) const { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - const QRectF r = paper->rect(); - // Create the image with the exact size of the shrunk scene - QImage image(r.size().toSize(), QImage::Format_ARGB32); - image.fill(Qt::transparent); // Start all pixels transparent - QPainter painter(&image); - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); - image.save(name); - } + const QRectF r = paper->rect(); + // Create the image with the exact size of the shrunk scene + QImage image(r.size().toSize(), QImage::Format_ARGB32); + image.fill(Qt::transparent); // Start all pixels transparent + QPainter painter(&image); + painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + scene->render(&painter, r, r, Qt::IgnoreAspectRatio); + image.save(name); } //--------------------------------------------------------------------------------------------------------------------- @@ -720,45 +762,42 @@ void MainWindowsNoGUI::PngFile(const QString &name, int i) const * @brief PdfFile save layout to pdf file. * @param name name layout file. */ -void MainWindowsNoGUI::PdfFile(const QString &name, int i) const +void MainWindowsNoGUI::PdfFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, + bool ignorePrinterFields, const QMarginsF &margins) const { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) + QPrinter printer; + printer.setCreator(QGuiApplication::applicationDisplayName()+QLatin1String(" ")+ + QCoreApplication::applicationVersion()); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(name); + printer.setDocName(FileName()); + const QRectF r = paper->rect(); + printer.setResolution(static_cast(PrintDPI)); + // Set orientation + if (paper->rect().height()>= paper->rect().width()) { - QPrinter printer; - printer.setCreator(QGuiApplication::applicationDisplayName()+QLatin1String(" ")+ - QCoreApplication::applicationVersion()); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(name); - printer.setDocName(FileName()); - const QRectF r = paper->rect(); - printer.setResolution(static_cast(PrintDPI)); - // Set orientation - if (paper->rect().height()>= paper->rect().width()) - { - printer.setOrientation(QPrinter::Portrait); - } - else - { - printer.setOrientation(QPrinter::Landscape); - } - printer.setFullPage(ignorePrinterFields); - printer.setPaperSize ( QSizeF(FromPixel(r.width() + margins.left() + margins.right(), Unit::Mm), - FromPixel(r.height() + margins.top() + margins.bottom(), Unit::Mm)), - QPrinter::Millimeter ); - QPainter painter; - if (painter.begin( &printer ) == false) - { // failed to open file - qCritical("%s", qUtf8Printable(tr("Can't open printer %1").arg(name))); - return; - } - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); - painter.end(); + printer.setOrientation(QPrinter::Portrait); } + else + { + printer.setOrientation(QPrinter::Landscape); + } + printer.setFullPage(ignorePrinterFields); + printer.setPaperSize ( QSizeF(FromPixel(r.width() + margins.left() + margins.right(), Unit::Mm), + FromPixel(r.height() + margins.top() + margins.bottom(), Unit::Mm)), + QPrinter::Millimeter ); + QPainter painter; + if (painter.begin( &printer ) == false) + { // failed to open file + qCritical("%s", qUtf8Printable(tr("Can't open printer %1").arg(name))); + return; + } + painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + scene->render(&painter, r, r, Qt::IgnoreAspectRatio); + painter.end(); } //--------------------------------------------------------------------------------------------------------------------- @@ -793,12 +832,13 @@ void MainWindowsNoGUI::PdfTiledFile(const QString &name) * @brief EpsFile save layout to eps file. * @param name name layout file. */ -void MainWindowsNoGUI::EpsFile(const QString &name, int i) const +void MainWindowsNoGUI::EpsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, + bool ignorePrinterFields, const QMarginsF &margins) const { QTemporaryFile tmp; if (tmp.open()) { - PdfFile(tmp.fileName(), i); + PdfFile(tmp.fileName(), paper, scene, ignorePrinterFields, margins); QStringList params = QStringList() << "-eps" << tmp.fileName() << name; PdfToPs(params); } @@ -809,12 +849,13 @@ void MainWindowsNoGUI::EpsFile(const QString &name, int i) const * @brief PsFile save layout to ps file. * @param name name layout file. */ -void MainWindowsNoGUI::PsFile(const QString &name, int i) const +void MainWindowsNoGUI::PsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool + ignorePrinterFields, const QMarginsF &margins) const { QTemporaryFile tmp; if (tmp.open()) { - PdfFile(tmp.fileName(), i); + PdfFile(tmp.fileName(), paper, scene, ignorePrinterFields, margins); QStringList params = QStringList() << tmp.fileName() << name; PdfToPs(params); } @@ -857,64 +898,57 @@ void MainWindowsNoGUI::PdfToPs(const QStringList ¶ms) const } //--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::ObjFile(const QString &name, int i) const +void MainWindowsNoGUI::ObjFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene) const { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - VObjPaintDevice generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setResolution(static_cast(PrintDPI)); - QPainter painter; - painter.begin(&generator); - scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); - painter.end(); - } + VObjPaintDevice generator; + generator.setFileName(name); + generator.setSize(paper->rect().size().toSize()); + generator.setResolution(static_cast(PrintDPI)); + QPainter painter; + painter.begin(&generator); + scene->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); + painter.end(); } //--------------------------------------------------------------------------------------------------------------------- QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") -void MainWindowsNoGUI::DxfFile(const QString &name, int version, bool binary, int i) const +void MainWindowsNoGUI::DxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, + QGraphicsScene *scene) const { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) + PrepareTextForDXF(endStringPlaceholder); + VDxfPaintDevice generator; + generator.setFileName(name); + generator.setSize(paper->rect().size().toSize()); + generator.setResolution(PrintDPI); + generator.SetVersion(static_cast(version)); + generator.SetBinaryFormat(binary); + + switch (*pattern->GetPatternUnit()) { - PrepareTextForDXF(endStringPlaceholder); - VDxfPaintDevice generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setResolution(PrintDPI); - generator.SetVersion(static_cast(version)); - generator.SetBinaryFormat(binary); - - switch (*pattern->GetPatternUnit()) - { - case Unit::Cm: - generator.setInsunits(VarInsunits::Centimeters); - break; - case Unit::Mm: - generator.setInsunits(VarInsunits::Millimeters); - break; - case Unit::Inch: - generator.setInsunits(VarInsunits::Inches); - break; - case Unit::Px: - case Unit::LAST_UNIT_DO_NOT_USE: - Q_UNREACHABLE(); - break; - } - - QPainter painter; - if (painter.begin(&generator)) - { - scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); - painter.end(); - } - RestoreTextAfterDXF(endStringPlaceholder); + case Unit::Cm: + generator.setInsunits(VarInsunits::Centimeters); + break; + case Unit::Mm: + generator.setInsunits(VarInsunits::Millimeters); + break; + case Unit::Inch: + generator.setInsunits(VarInsunits::Inches); + break; + case Unit::Px: + case Unit::LAST_UNIT_DO_NOT_USE: + Q_UNREACHABLE(); + break; } + + QPainter painter; + if (painter.begin(&generator)) + { + scene->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); + painter.end(); + } + RestoreTextAfterDXF(endStringPlaceholder); } QT_WARNING_POP diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 441fc71e6..9cd8cc594 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -40,6 +40,7 @@ class QGraphicsScene; struct PosterData; +class QGraphicsRectItem; class MainWindowsNoGUI : public VAbstractMainWindow { @@ -88,8 +89,14 @@ protected: QMarginsF margins; QSizeF paperSize; - void PrepareDetailsForLayout(const QHash *details); - void ExportLayout(const DialogSaveLayout &dialog); + static QVector PrepareDetailsForLayout(const QHash &details); + + void ExportData(const QVector &listDetails, const DialogSaveLayout &dialog); + void ExportLayout(const DialogSaveLayout &dialog, + const QList &scenes, + const QList &papers, + const QList &shadows, + bool ignorePrinterFields, const QMarginsF &margins); void InitTempLayoutScene(); virtual void CleanLayout()=0; @@ -110,18 +117,23 @@ private: QString layoutPrinterName; - void CreateShadows(); - void CreateScenes(); + static QList CreateShadows(const QList &papers); + static QList CreateScenes(const QList &papers, + const QList &shadows, + const QList > &details); - 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 SvgFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const; + void PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const; + void PdfFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields, + const QMarginsF &margins)const; void PdfTiledFile(const QString &name); - void EpsFile(const QString &name, int i)const; - void PsFile(const QString &name, int i)const; + void EpsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields, + const QMarginsF &margins)const; + void PsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields, + const QMarginsF &margins)const; void PdfToPs(const QStringList ¶ms)const; - void ObjFile(const QString &name, int i)const; - void DxfFile(const QString &name, int version, bool binary, int i)const; + void ObjFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const; + void DxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, QGraphicsScene *scene)const; void PreparePaper(int index) const; void RestorePaper(int index) const; diff --git a/src/libs/vmisc/commandoptions.cpp b/src/libs/vmisc/commandoptions.cpp index 5f3e072d2..0d45a6df4 100644 --- a/src/libs/vmisc/commandoptions.cpp +++ b/src/libs/vmisc/commandoptions.cpp @@ -50,7 +50,8 @@ const QString LONG_OPTION_EXP2FORMAT = QStringLiteral("format"); const QString SINGLE_OPTION_EXP2FORMAT = QStringLiteral("f"); const QString LONG_OPTION_BINARYDXF = QStringLiteral("bdxf"); -const QString LONG_OPTION_TEXT2PATHS = QStringLiteral("text2paths"); +const QString LONG_OPTION_TEXT2PATHS = QStringLiteral("text2paths"); +const QString LONG_OPTION_EXPORTONLYDETAILS = QStringLiteral("exportOnlyDetails"); const QString LONG_OPTION_ROTATE = QStringLiteral("rotate"); const QString SINGLE_OPTION_ROTATE = QStringLiteral("r"); diff --git a/src/libs/vmisc/commandoptions.h b/src/libs/vmisc/commandoptions.h index fb7888dc9..0ac1af09c 100644 --- a/src/libs/vmisc/commandoptions.h +++ b/src/libs/vmisc/commandoptions.h @@ -48,6 +48,7 @@ extern const QString SINGLE_OPTION_EXP2FORMAT; extern const QString LONG_OPTION_BINARYDXF; extern const QString LONG_OPTION_TEXT2PATHS; +extern const QString LONG_OPTION_EXPORTONLYDETAILS; extern const QString LONG_OPTION_ROTATE; extern const QString SINGLE_OPTION_ROTATE;