From 54eadfdb3c6baa6f66b93d5f6e4460db8c9131ed Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 16 Jul 2017 21:10:48 +0300 Subject: [PATCH] Export to DXF-AAMA. --HG-- branch : feature --- dist/OBS_debian/debian.valentina.1 | 27 + dist/debian/valentina.1 | 27 + .../valentina/dialogs/dialogsavelayout.cpp | 23 +- src/app/valentina/mainwindow.cpp | 2 +- src/app/valentina/mainwindowsnogui.cpp | 567 ++++++++++++------ src/app/valentina/mainwindowsnogui.h | 33 +- src/libs/vdxf/dxiface.cpp | 61 +- src/libs/vdxf/dxiface.h | 7 +- src/libs/vdxf/libdxfrw/drw_base.h | 2 +- src/libs/vdxf/libdxfrw/drw_entities.h | 2 +- src/libs/vdxf/vdxfengine.cpp | 267 ++++++++- src/libs/vdxf/vdxfengine.h | 21 + src/libs/vdxf/vdxfpaintdevice.cpp | 9 + src/libs/vdxf/vdxfpaintdevice.h | 3 + src/libs/vlayout/vlayoutgenerator.cpp | 13 +- src/libs/vlayout/vlayoutgenerator.h | 4 +- src/libs/vlayout/vlayoutpiece.cpp | 84 ++- src/libs/vlayout/vlayoutpiece.h | 8 +- src/libs/vlayout/vlayoutpiecepath.cpp | 16 +- src/libs/vlayout/vlayoutpiecepath.h | 5 +- src/libs/vlayout/vlayoutpiecepath_p.h | 13 +- src/libs/vpatterndb/vpiecepath.cpp | 12 + src/libs/vpatterndb/vpiecepath.h | 3 + src/libs/vpatterndb/vpiecepath_p.h | 10 +- 24 files changed, 979 insertions(+), 240 deletions(-) diff --git a/dist/OBS_debian/debian.valentina.1 b/dist/OBS_debian/debian.valentina.1 index 67e1aff90..dc731a0f8 100644 --- a/dist/OBS_debian/debian.valentina.1 +++ b/dist/OBS_debian/debian.valentina.1 @@ -71,6 +71,33 @@ The path to output destination folder. By default the directory at which the app .BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14," .RE .RS +.BR "*" " AutoCAD DXF R10 AAMA files (*.dxf) = 15," +.RE +.RS +.BR "*" " AutoCAD DXF R11/12 AAMA files (*.dxf) = 16," +.RE +.RS +.BR "*" " AutoCAD DXF R13 AAMA files (*.dxf) = 17," +.RE +.RS +.BR "*" " AutoCAD DXF R14 AAMA files (*.dxf) = 18," +.RE +.RS +.BR "*" " AutoCAD DXF 2000 AAMA files (*.dxf) = 19," +.RE +.RS +.BR "*" " AutoCAD DXF 2004 AAMA files (*.dxf) = 20," +.RE +.RS +.BR "*" " AutoCAD DXF 2007 AAMA files (*.dxf) = 21," +.RE +.RS +.BR "*" " AutoCAD DXF 2010 AAMA files (*.dxf) = 22," +.RE +.RS +.BR "*" " AutoCAD DXF 2013 AAMA files (*.dxf) = 23," +.RE +.RS .BR "*" " PDF tiled files (*.pdf) = 33." .RE .IP "--bdxf" diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 67e1aff90..dc731a0f8 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -71,6 +71,33 @@ The path to output destination folder. By default the directory at which the app .BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14," .RE .RS +.BR "*" " AutoCAD DXF R10 AAMA files (*.dxf) = 15," +.RE +.RS +.BR "*" " AutoCAD DXF R11/12 AAMA files (*.dxf) = 16," +.RE +.RS +.BR "*" " AutoCAD DXF R13 AAMA files (*.dxf) = 17," +.RE +.RS +.BR "*" " AutoCAD DXF R14 AAMA files (*.dxf) = 18," +.RE +.RS +.BR "*" " AutoCAD DXF 2000 AAMA files (*.dxf) = 19," +.RE +.RS +.BR "*" " AutoCAD DXF 2004 AAMA files (*.dxf) = 20," +.RE +.RS +.BR "*" " AutoCAD DXF 2007 AAMA files (*.dxf) = 21," +.RE +.RS +.BR "*" " AutoCAD DXF 2010 AAMA files (*.dxf) = 22," +.RE +.RS +.BR "*" " AutoCAD DXF 2013 AAMA files (*.dxf) = 23," +.RE +.RS .BR "*" " PDF tiled files (*.pdf) = 33." .RE .IP "--bdxf" diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 83babbe83..cf87c4d66 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -331,9 +331,9 @@ QString DialogSaveLayout::ExportFormatDescription(LayoutExportFormats format) case LayoutExportFormats::DXF_AC1027_Flat: return QString("AutoCAD DXF 2013 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); case LayoutExportFormats::DXF_AC1006_AAMA: - return QString("AutoCAD DXF R10 AAMA %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + return QString("AutoCAD DXF R10 AAMA %1 %2").arg(filesStr, dxfSuffix); case LayoutExportFormats::DXF_AC1009_AAMA: - return QString("AutoCAD DXF R11/12 AAMA %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + return QString("AutoCAD DXF R11/12 AAMA %1 %2").arg(filesStr, dxfSuffix); case LayoutExportFormats::DXF_AC1012_AAMA: return QString("AutoCAD DXF R13 AAMA %1 %2").arg(filesStr, dxfSuffix); case LayoutExportFormats::DXF_AC1014_AAMA: @@ -648,17 +648,16 @@ QVector > DialogSaveLayout::InitFormats( InitFormat(LayoutExportFormats::DXF_AC1021_Flat); InitFormat(LayoutExportFormats::DXF_AC1024_Flat); InitFormat(LayoutExportFormats::DXF_AC1027_Flat); - + InitFormat(LayoutExportFormats::DXF_AC1006_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1009_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1012_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1014_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1015_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1018_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1021_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1024_AAMA); + InitFormat(LayoutExportFormats::DXF_AC1027_AAMA); // We will support them anyway -// InitFormat(LayoutExportFormats::DXF_AC1006_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1009_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1012_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1014_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1015_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1018_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1021_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1024_AAMA); -// InitFormat(LayoutExportFormats::DXF_AC1027_AAMA); // InitFormat(LayoutExportFormats::DXF_AC1006_ASTM); // InitFormat(LayoutExportFormats::DXF_AC1009_ASTM); // InitFormat(LayoutExportFormats::DXF_AC1012_ASTM); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 2b7361f17..3caf3d198 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4399,7 +4399,7 @@ void MainWindow::ExportLayoutAs() return; } - ExportLayout(dialog, scenes, papers, shadows, details, ignorePrinterFields, margins); + ExportData(QVector(), dialog); } catch (const VException &e) { diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index a6acb36f5..b5b7c3972 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -60,6 +60,30 @@ # define PDFTOPS "pdftops" #endif +namespace +{ +bool CreateLayoutPath(const QString &path) +{ + bool usedNotExistedDir = true; + QDir dir(path); + dir.setPath(path); + if (not dir.exists(path)) + { + usedNotExistedDir = dir.mkpath("."); + } + return usedNotExistedDir; +} + +void RemoveLayoutPath(const QString &path, bool usedNotExistedDir) +{ + if (usedNotExistedDir) + { + QDir dir(path); + dir.rmpath("."); + } +} +} + //--------------------------------------------------------------------------------------------------------------------- MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) : VAbstractMainWindow(parent), @@ -72,6 +96,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) shadows(), scenes(), details(), + detailsOnLayout(), undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), @@ -148,7 +173,8 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator) case LayoutErrors::NoError: CleanLayout(); papers = lGenerator.GetPapersItems();// Blank sheets - details = lGenerator.GetAllDetails();// All details + details = lGenerator.GetAllDetailsItems();// All details items + detailsOnLayout = lGenerator.GetAllDetails();// All details items shadows = CreateShadows(papers); scenes = CreateScenes(papers, shadows, details); PrepareSceneList(); @@ -201,217 +227,256 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state) //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::ExportData(const QVector &listDetails, const DialogSaveLayout &dialog) { - if (dialog.Mode() == Draw::Layout) + const LayoutExportFormats format = dialog.Format(); + + if (format == LayoutExportFormats::DXF_AC1006_AAMA || + format == LayoutExportFormats::DXF_AC1009_AAMA || + format == LayoutExportFormats::DXF_AC1012_AAMA || + format == LayoutExportFormats::DXF_AC1014_AAMA || + format == LayoutExportFormats::DXF_AC1015_AAMA || + format == LayoutExportFormats::DXF_AC1018_AAMA || + format == LayoutExportFormats::DXF_AC1021_AAMA || + format == LayoutExportFormats::DXF_AC1024_AAMA || + format == LayoutExportFormats::DXF_AC1027_AAMA) { - ExportLayout(dialog, scenes, papers, shadows, details, ignorePrinterFields, margins); + if (dialog.Mode() == Draw::Layout) + { + for (int i = 0; i < detailsOnLayout.size(); ++i) + { + const QString name = dialog.Path() + QLatin1String("/") + dialog.FileName() + QString::number(i+1) + + DialogSaveLayout::ExportFromatSuffix(dialog.Format()); + + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + SCASSERT(paper != nullptr) + + ExportApparelLayout(dialog, detailsOnLayout.at(i), name, paper->rect().size().toSize()); + } + } + else + { + ExportDetailsAsApparelLayout(dialog, listDetails); + } } else { - QScopedPointer scene(new QGraphicsScene()); - - QList list; - for (int i=0; i < listDetails.count(); ++i) + if (dialog.Mode() == Draw::Layout) { - QGraphicsItem *item = listDetails.at(i).GetItem(dialog.IsTextAsPaths()); - item->setPos(listDetails.at(i).GetMx(), listDetails.at(i).GetMy()); - list.append(item); + ExportFlatLayout(dialog, scenes, papers, shadows, details, ignorePrinterFields, margins); } - - for (int i=0; i < list.size(); ++i) + else { - scene->addItem(list.at(i)); + ExportDetailsAsFlatLayout(dialog, listDetails); } - - QList papers;// Blank sheets - QRect rect = scene->itemsBoundingRect().toRect(); - - const int mx = rect.x(); - const int my = rect.y(); - - QTransform matrix; - matrix = matrix.translate(-mx, -my); - - for (int i=0; i < list.size(); ++i) - { - list.at(i)->setTransform(matrix); - } - - rect = scene->itemsBoundingRect().toRect(); - - QGraphicsRectItem *paper = new QGraphicsRectItem(rect); - paper->setPen(QPen(Qt::black, 1)); - paper->setBrush(QBrush(Qt::white)); - papers.append(paper); - - 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(1, Unit::Cm); - ExportLayout(dialog, scenes, papers, shadows, details, 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, - const QList > &details, bool ignorePrinterFields, - const QMarginsF &margins) +void MainWindowsNoGUI::ExportFlatLayout(const DialogSaveLayout &dialog, const QList &scenes, + const QList &papers, const QList &shadows, + const QList > &details, bool ignorePrinterFields, + const QMarginsF &margins) { const QString path = dialog.Path(); - bool usedNotExistedDir = false; - QDir dir(path); - dir.setPath(path); - if (not dir.exists(path)) + bool usedNotExistedDir = CreateLayoutPath(path); + if (not usedNotExistedDir) { - usedNotExistedDir = dir.mkpath("."); - if (not usedNotExistedDir) - { - qCritical() << tr("Can't create a path"); - return; - } + qCritical() << tr("Can't create a path"); + return; } + qApp->ValentinaSettings()->SetPathLayout(path); - const QString mask = dialog.FileName(); const LayoutExportFormats format = dialog.Format(); if (format == LayoutExportFormats::PDFTiled && dialog.Mode() == Draw::Layout) { - const QString name = path + QLatin1String("/") + mask + QString::number(1) - + DialogSaveLayout::ExportFromatSuffix(format); + const QString name = path + QLatin1String("/") + dialog.FileName() + QString::number(1) + + DialogSaveLayout::ExportFromatSuffix(dialog.Format()); PdfTiledFile(name); } else { - for (int i=0; i < scenes.size(); ++i) - { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - const QString name = path + QLatin1String("/") + mask+QString::number(i+1) - + DialogSaveLayout::ExportFromatSuffix(format); - QBrush *brush = new QBrush(); - brush->setColor( QColor( Qt::white ) ); - QGraphicsScene *scene = scenes.at(i); - scene->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 - break; - case LayoutExportFormats::SVG: - paper->setVisible(false); - SvgFile(name, paper, scene); - paper->setVisible(true); - break; - case LayoutExportFormats::PDF: - PdfFile(name, paper, scene, ignorePrinterFields, margins); - break; - case LayoutExportFormats::PNG: - PngFile(name, paper, scene); - break; - case LayoutExportFormats::OBJ: - paper->setVisible(false); - ObjFile(name, paper, scene); - paper->setVisible(true); - break; - case LayoutExportFormats::PS: - PsFile(name, paper, scene, ignorePrinterFields, margins); - break; - case LayoutExportFormats::EPS: - EpsFile(name, paper, scene, ignorePrinterFields, margins); - break; - case LayoutExportFormats::DXF_AC1006_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1009_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1012_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1014_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1015_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1018_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1021_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1024_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), paper, scene, details); - paper->setVisible(true); - break; - case LayoutExportFormats::DXF_AC1027_Flat: - paper->setVisible(false); - DxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), paper, scene, details); - 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; - } - } + ExportScene(dialog, scenes, papers, shadows, details, ignorePrinterFields, margins); } - if (usedNotExistedDir) + RemoveLayoutPath(path, usedNotExistedDir); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ExportDetailsAsFlatLayout(const DialogSaveLayout &dialog, + const QVector &listDetails) +{ + if (listDetails.isEmpty()) { - QDir directory(dir); - directory.rmpath("."); + return; } + + QScopedPointer scene(new QGraphicsScene()); + + QList list; + for (int i=0; i < listDetails.count(); ++i) + { + QGraphicsItem *item = listDetails.at(i).GetItem(dialog.IsTextAsPaths()); + item->setPos(listDetails.at(i).GetMx(), listDetails.at(i).GetMy()); + list.append(item); + } + + for (int i=0; i < list.size(); ++i) + { + scene->addItem(list.at(i)); + } + + QList papers;// Blank sheets + QRect rect = scene->itemsBoundingRect().toRect(); + + const int mx = rect.x(); + const int my = rect.y(); + + QTransform matrix; + matrix = matrix.translate(-mx, -my); + + for (int i=0; i < list.size(); ++i) + { + list.at(i)->setTransform(matrix); + } + + rect = scene->itemsBoundingRect().toRect(); + + QGraphicsRectItem *paper = new QGraphicsRectItem(rect); + paper->setPen(QPen(Qt::black, 1)); + paper->setBrush(QBrush(Qt::white)); + papers.append(paper); + + 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(1, Unit::Cm); + ExportFlatLayout(dialog, scenes, papers, shadows, details, ignorePrinterFields, + QMarginsF(margin, margin, margin, margin)); + + qDeleteAll(scenes);//Scene will clear all other items +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ExportApparelLayout(const DialogSaveLayout &dialog, const QVector &details, + const QString &name, const QSize &size) const +{ + const QString path = dialog.Path(); + bool usedNotExistedDir = CreateLayoutPath(path); + if (not usedNotExistedDir) + { + qCritical() << tr("Can't create a path"); + return; + } + + qApp->ValentinaSettings()->SetPathLayout(path); + const LayoutExportFormats format = dialog.Format(); + + switch (format) + { + 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 + break; + case LayoutExportFormats::DXF_AC1006_AAMA: + AAMADxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1009_AAMA: + AAMADxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1012_AAMA: + AAMADxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1014_AAMA: + AAMADxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1015_AAMA: + AAMADxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1018_AAMA: + AAMADxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1021_AAMA: + AAMADxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1024_AAMA: + AAMADxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), size, details); + break; + case LayoutExportFormats::DXF_AC1027_AAMA: + AAMADxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), size, details); + break; + default: + qDebug() << "Can't recognize file type." << Q_FUNC_INFO; + break; + } + + RemoveLayoutPath(path, usedNotExistedDir); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ExportDetailsAsApparelLayout(const DialogSaveLayout &dialog, + QVector listDetails) +{ + if (listDetails.isEmpty()) + { + return; + } + + QScopedPointer scene(new QGraphicsScene()); + + QList list; + for (int i=0; i < listDetails.count(); ++i) + { + QGraphicsItem *item = listDetails.at(i).GetItem(dialog.IsTextAsPaths()); + item->setPos(listDetails.at(i).GetMx(), listDetails.at(i).GetMy()); + list.append(item); + } + + for (int i=0; i < list.size(); ++i) + { + scene->addItem(list.at(i)); + } + + QRect rect = scene->itemsBoundingRect().toRect(); + + const int mx = rect.x(); + const int my = rect.y(); + + QTransform matrix; + matrix = matrix.translate(-mx, -my); + + for (int i=0; i < list.size(); ++i) + { + list.at(i)->setTransform(matrix); + } + + rect = scene->itemsBoundingRect().toRect(); + + for (int i=0; i < listDetails.count(); ++i) + { + QTransform moveMatrix; + matrix = matrix.translate(listDetails.at(i).GetMx(), listDetails.at(i).GetMy()); + matrix = matrix.translate(-mx, -my); + moveMatrix *= listDetails.at(i).GetMatrix(); + listDetails[i].SetMatrix(moveMatrix); + listDetails[i].SetMx(listDetails.at(i).GetMx()-mx); + listDetails[i].SetMy(listDetails.at(i).GetMy()-my); + } + + const QString name = dialog.Path() + QLatin1String("/") + dialog.FileName() + QString::number(1) + + DialogSaveLayout::ExportFromatSuffix(dialog.Format()); + + ExportApparelLayout(dialog, listDetails, name, rect.size()); } //--------------------------------------------------------------------------------------------------------------------- @@ -943,7 +1008,7 @@ void MainWindowsNoGUI::ObjFile(const QString &name, QGraphicsRectItem *paper, QG QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") -void MainWindowsNoGUI::DxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, +void MainWindowsNoGUI::FlatDxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, QGraphicsScene *scene, const QList > &details) const { PrepareTextForDXF(endStringPlaceholder, details); @@ -980,6 +1045,37 @@ void MainWindowsNoGUI::DxfFile(const QString &name, int version, bool binary, QG RestoreTextAfterDXF(endStringPlaceholder, details); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::AAMADxfFile(const QString &name, int version, bool binary, const QSize &size, + const QVector &details) const +{ + VDxfPaintDevice generator; + generator.setFileName(name); + generator.setSize(size); + 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; + } + + generator.ExportToAAMA(details); +} + QT_WARNING_POP //--------------------------------------------------------------------------------------------------------------------- @@ -1345,6 +1441,109 @@ bool MainWindowsNoGUI::IsPagesFit(const QSizeF &printPaper) const return false; } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::ExportScene(const DialogSaveLayout &dialog, const QList &scenes, + const QList &papers, const QList &shadows, + const QList > &details, bool ignorePrinterFields, + const QMarginsF &margins) const +{ + for (int i=0; i < scenes.size(); ++i) + { + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) + { + const QString name = dialog.Path() + QLatin1String("/") + dialog.FileName() + QString::number(i+1) + + DialogSaveLayout::ExportFromatSuffix(dialog.Format()); + QBrush *brush = new QBrush(); + brush->setColor( QColor( Qt::white ) ); + QGraphicsScene *scene = scenes.at(i); + scene->setBackgroundBrush( *brush ); + shadows[i]->setVisible(false); + paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); + + switch (dialog.Format()) + { + case LayoutExportFormats::SVG: + paper->setVisible(false); + SvgFile(name, paper, scene); + paper->setVisible(true); + break; + case LayoutExportFormats::PDF: + PdfFile(name, paper, scene, ignorePrinterFields, margins); + break; + case LayoutExportFormats::PNG: + PngFile(name, paper, scene); + break; + case LayoutExportFormats::OBJ: + paper->setVisible(false); + ObjFile(name, paper, scene); + paper->setVisible(true); + break; + case LayoutExportFormats::PS: + PsFile(name, paper, scene, ignorePrinterFields, margins); + break; + case LayoutExportFormats::EPS: + EpsFile(name, paper, scene, ignorePrinterFields, margins); + break; + case LayoutExportFormats::DXF_AC1006_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1009_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1012_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1014_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1015_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1018_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1021_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1024_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1027_Flat: + paper->setVisible(false); + FlatDxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), paper, scene, details); + paper->setVisible(true); + break; + default: + qDebug() << "Can't recognize file type." << 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; + } + } +} + //--------------------------------------------------------------------------------------------------------------------- QString MainWindowsNoGUI::FileName() const { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index d2e162a64..fcc5e4029 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -75,6 +75,8 @@ protected: QList scenes; QList > details; + QVector > detailsOnLayout; + QAction *undoAction; QAction *redoAction; QAction *actionDockWidgetToolOptions; @@ -92,12 +94,6 @@ protected: 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, - const QList > &details, - bool ignorePrinterFields, const QMarginsF &margins); void InitTempLayoutScene(); virtual void CleanLayout()=0; @@ -134,8 +130,10 @@ private: const QMarginsF &margins)const; void PdfToPs(const QStringList ¶ms)const; void ObjFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const; - void DxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, QGraphicsScene *scene, + void FlatDxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, QGraphicsScene *scene, const QList > &details)const; + void AAMADxfFile(const QString &name, int version, bool binary, const QSize &size, + const QVector &details) const; void PreparePaper(int index) const; void RestorePaper(int index) const; @@ -154,6 +152,27 @@ private: bool isPagesUniform() const; bool IsPagesFit(const QSizeF &printPaper) const; + + void ExportScene(const DialogSaveLayout &dialog, + const QList &scenes, + const QList &papers, + const QList &shadows, + const QList > &details, + bool ignorePrinterFields, const QMarginsF &margins) const; + + void ExportApparelLayout(const DialogSaveLayout &dialog, const QVector &details, const QString &name, + const QSize &size) const; + + void ExportDetailsAsApparelLayout(const DialogSaveLayout &dialog, QVector listDetails); + + void ExportFlatLayout(const DialogSaveLayout &dialog, + const QList &scenes, + const QList &papers, + const QList &shadows, + const QList > &details, + bool ignorePrinterFields, const QMarginsF &margins); + + void ExportDetailsAsFlatLayout(const DialogSaveLayout &dialog, const QVector &listDetails); }; #endif // MAINWINDOWSNOGUI_H diff --git a/src/libs/vdxf/dxiface.cpp b/src/libs/vdxf/dxiface.cpp index 61e8e2ea6..758c6e379 100644 --- a/src/libs/vdxf/dxiface.cpp +++ b/src/libs/vdxf/dxiface.cpp @@ -25,8 +25,7 @@ dx_iface::dx_iface(const std::string &file, DRW::Version v, VarMeasurement varMe version(v) { InitHeader(varMeasurement, varInsunits); - InitLTypes(); - InitLayers(); + InitDefLayers(); InitTextstyles(); InitAppId(); } @@ -192,7 +191,7 @@ void dx_iface::InitHeader(VarMeasurement varMeasurement, VarInsunits varInsunits } } -void dx_iface::InitLTypes() +void dx_iface::AddQtLTypes() { DRW_LType ltype; ltype.name = "DOT"; @@ -237,21 +236,54 @@ void dx_iface::InitLTypes() cData.lineTypes.push_back(ltype); } -void dx_iface::InitLayers() +void dx_iface::AddAAMALayers() +{ + DRW_Layer layer; + + layer.name = "1";// CUT, OUTLINE + layer.color = DRW::black; + cData.layers.push_back(layer); + + layer.name = "8";// DRAW, INK + layer.color = DRW::black; + cData.layers.push_back(layer); + + layer.name = "7";// GRAINLINE + layer.color = DRW::black; + cData.layers.push_back(layer); + +// layer.name = "6";// MIRROR LINES +// layer.color = DRW::black; +// cData.layers.push_back(layer); + + layer.name = "11";// INTCUT + layer.color = DRW::black; + cData.layers.push_back(layer); + +// layer.name = "13";// DRILL +// layer.color = DRW::black; +// cData.layers.push_back(layer); + + layer.name = "4";// NOTCH + layer.color = DRW::black; + cData.layers.push_back(layer); + + layer.name = "19";// TEXT + layer.color = DRW::black; + cData.layers.push_back(layer); + +// layer.name = "26";// REF +// layer.color = DRW::black; +// cData.layers.push_back(layer); +} + +void dx_iface::InitDefLayers() { DRW_Layer defLayer; defLayer.name = "0"; defLayer.color = DRW::black; // default color defLayer.lWeight = DRW_LW_Conv::width03; // default width - defLayer.lineType = "CONTINUOUS"; // default line style cData.layers.push_back(defLayer); - -// DRW_Layer mLayer; -// mLayer.name = "mainlayer"; -// mLayer.color = DRW::black; // default color -// mLayer.lWeight = 100; // default width -// mLayer.lineType = "CONTINUOUS"; // default line style -// cData.lineTypes.push_back(mLayer); } void dx_iface::InitTextstyles() @@ -309,6 +341,11 @@ UTF8STRING dx_iface::AddFont(const QFont &f) return ts.name; } +void dx_iface::AddBlock(dx_ifaceBlock *block) +{ + cData.blocks.push_back(block); +} + std::string dx_iface::LocaleToISO() { QMap locMap; diff --git a/src/libs/vdxf/dxiface.h b/src/libs/vdxf/dxiface.h index cb80424a1..daf75c3a0 100644 --- a/src/libs/vdxf/dxiface.h +++ b/src/libs/vdxf/dxiface.h @@ -118,6 +118,10 @@ public: void AddEntity(DRW_Entity* e); UTF8STRING AddFont(const QFont &f); + void AddBlock(dx_ifaceBlock* block); + + void AddQtLTypes(); + void AddAAMALayers(); private: Q_DISABLE_COPY(dx_iface) @@ -126,8 +130,7 @@ private: DRW::Version version; void InitHeader(VarMeasurement varMeasurement, VarInsunits varInsunits); - void InitLTypes(); - void InitLayers(); + void InitDefLayers(); void InitTextstyles(); void InitAppId(); diff --git a/src/libs/vdxf/libdxfrw/drw_base.h b/src/libs/vdxf/libdxfrw/drw_base.h index a5027501f..870c390b5 100644 --- a/src/libs/vdxf/libdxfrw/drw_base.h +++ b/src/libs/vdxf/libdxfrw/drw_base.h @@ -272,7 +272,7 @@ public: { // eType = DRW::LWPOLYLINE; } - DRW_Vertex2D(double sx, double sy, double b) + DRW_Vertex2D(double sx, double sy, double b = 0.0) : x(sx), y(sy), stawidth(0), diff --git a/src/libs/vdxf/libdxfrw/drw_entities.h b/src/libs/vdxf/libdxfrw/drw_entities.h index df7bb61ad..a02470cf6 100644 --- a/src/libs/vdxf/libdxfrw/drw_entities.h +++ b/src/libs/vdxf/libdxfrw/drw_entities.h @@ -762,7 +762,7 @@ public: eType = DRW::VERTEX; } - DRW_Vertex(double sx, double sy, double sz, double b) + DRW_Vertex(double sx, double sy, double sz = 0.0, double b = 0.0) : stawidth(0), endwidth(0), bulge(b), diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp index a7bc3a0c9..4c2eda949 100644 --- a/src/libs/vdxf/vdxfengine.cpp +++ b/src/libs/vdxf/vdxfengine.cpp @@ -1,4 +1,4 @@ -/************************************************************************ + /************************************************************************ ** ** @file vdxfengine.cpp ** @author Valentina Zhuravska @@ -49,6 +49,9 @@ #include "../vmisc/diagnostic.h" #include "../vmisc/vmath.h" #include "dxiface.h" +#include "../vlayout/vlayoutpiece.h" + +static const qreal AAMATextHeight = 2.5; //--------------------------------------------------------------------------------------------------------------------- static inline QPaintEngine::PaintEngineFeatures svgEngineFeatures() @@ -93,6 +96,13 @@ VDxfEngine::~VDxfEngine() bool VDxfEngine::begin(QPaintDevice *pdev) { Q_UNUSED(pdev) + + if (isActive()) + { + qWarning("VDxfEngine::begin(), the engine was alredy activated"); + return false; + } + if (size.isValid() == false) { qWarning()<<"VDxfEngine::begin(), size is not valid"; @@ -100,6 +110,7 @@ bool VDxfEngine::begin(QPaintDevice *pdev) } input = QSharedPointer(new dx_iface(fileName.toStdString(), m_version, varMeasurement, varInsunits)); + input->AddQtLTypes(); return true; } @@ -571,7 +582,259 @@ double VDxfEngine::FromPixel(double pix, const VarInsunits &unit) const case VarInsunits::Inches: return pix / resolution; } - return 0; + return pix; +} + +//--------------------------------------------------------------------------------------------------------------------- +double VDxfEngine::ToPixel(double val, const VarInsunits &unit) const +{ + switch (unit) + { + case VarInsunits::Millimeters: + return (val / 25.4) * resolution; + case VarInsunits::Centimeters: + return ((val * 10.0) / 25.4) * resolution; + case VarInsunits::Inches: + return val * resolution; + } + return val; } QT_WARNING_POP + +//--------------------------------------------------------------------------------------------------------------------- +bool VDxfEngine::ExportToAAMA(const QVector &details) +{ + if (size.isValid() == false) + { + qWarning()<<"VDxfEngine::begin(), size is not valid"; + return false; + } + + input = QSharedPointer(new dx_iface(fileName.toStdString(), m_version, varMeasurement, varInsunits)); + input->AddAAMALayers(); + + ExportAAMAGlobalText(input, details); + + for(int i = 0; i < details.size(); ++i) + { + const VLayoutPiece &detail = details.at(i); + + dx_ifaceBlock *detailBlock = new dx_ifaceBlock(); + detailBlock->name = detail.GetName().toStdString(); + + ExportAAMAOutline(detailBlock, detail); + ExportAAMADraw(detailBlock, detail); + ExportAAMAIntcut(detailBlock, detail); + ExportAAMANotch(detailBlock, detail); + ExportAAMAGrainline(detailBlock, detail); + ExportAAMAText(detailBlock, detail); + + input->AddBlock(detailBlock); + + DRW_Insert *insert = new DRW_Insert(); + insert->name = detail.GetName().toStdString(); + insert->basePoint = DRW_Coord(FromPixel(detail.GetMx(), varInsunits), + FromPixel(- detail.GetMy(), varInsunits), 0); + insert->layer = "0"; + + input->AddEntity(insert); + } + + return input->fileExport(m_binary); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMAOutline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + QVector outline; + if (detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn()) + { + outline = detail.GetSeamAllowancePoints(); + } + else + { + outline = detail.GetContourPoints(); + } + + DRW_Entity *e = AAMAPolygon(outline, "1", true); + if (e) + { + detailBlock->ent.push_back(e); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + if (not detail.IsHideMainPath()) + { + QVector poly = detail.GetContourPoints(); + DRW_Entity *e = AAMAPolygon(poly, "8", true); + if (e) + { + detailBlock->ent.push_back(e); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + QVector> drawIntCut = detail.InternalPathsForCut(false); + for(int j = 0; j < drawIntCut.size(); ++j) + { + DRW_Entity *e = AAMAPolygon(drawIntCut.at(j), "8", false); + if (e) + { + detailBlock->ent.push_back(e); + } + } + + drawIntCut = detail.InternalPathsForCut(true); + for(int j = 0; j < drawIntCut.size(); ++j) + { + DRW_Entity *e = AAMAPolygon(drawIntCut.at(j), "11", false); + if (e) + { + detailBlock->ent.push_back(e); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMANotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + if (detail.IsSeamAllowance()) + { + QVector passmarks = detail.GetPassmarks(); + for(int i = 0; i < passmarks.size(); ++i) + { + DRW_Entity *e = AAMALine(passmarks.at(i), "4"); + if (e) + { + detailBlock->ent.push_back(e); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMAGrainline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + const QVector grainline = detail.GetGrainline(); + if (grainline.count() > 1) + { + DRW_Entity *e = AAMALine(QLineF(grainline.last(), grainline.first()), "7"); + if (e) + { + detailBlock->ent.push_back(e); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMAText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail) +{ + const QStringList list = detail.GetPieceText(); + const QPointF startPos = detail.GetPieceTextPosition(); + + for (int i = 0; i < list.size(); ++i) + { + QPointF pos(startPos.x(), startPos.y() - ToPixel(AAMATextHeight, varInsunits)*(list.size() - i-1)); + detailBlock->ent.push_back(AAMAText(pos, list.at(i), "19")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::ExportAAMAGlobalText(const QSharedPointer &input, const QVector &details) +{ + for(int i = 0; i < details.size(); ++i) + { + const QStringList strings = details.at(i).GetPatternText(); + if (not strings.isEmpty()) + { + for (int j = 0; j < strings.size(); ++j) + { + QPointF pos(0, getSize().height() - ToPixel(AAMATextHeight, varInsunits)*(strings.size() - j-1)); + input->AddEntity(AAMAText(pos, strings.at(j), "1")); + } + return; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +DRW_Entity *VDxfEngine::AAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed) +{ + if (polygon.isEmpty()) + { + return nullptr; + } + + if (m_version > DRW::AC1009) + { // Use lwpolyline + return CreateAAMAPolygon(polygon, layer, forceClosed); + } + else + { // Use polyline + return CreateAAMAPolygon(polygon, layer, forceClosed); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +DRW_Entity *VDxfEngine::AAMALine(const QLineF &line, const QString &layer) +{ + DRW_Line *lineEnt = new DRW_Line(); + lineEnt->basePoint = DRW_Coord(FromPixel(line.p1().x(), varInsunits), + FromPixel(getSize().height() - line.p1().y(), varInsunits), 0); + lineEnt->secPoint = DRW_Coord(FromPixel(line.p2().x(), varInsunits), + FromPixel(getSize().height() - line.p2().y(), varInsunits), 0); + lineEnt->layer = layer.toStdString(); + + return lineEnt; +} + +//--------------------------------------------------------------------------------------------------------------------- +DRW_Entity *VDxfEngine::AAMAText(const QPointF &pos, const QString &text, const QString &layer) +{ + DRW_Text *textLine = new DRW_Text(); + + textLine->basePoint = DRW_Coord(FromPixel(pos.x(), varInsunits), + FromPixel(getSize().height() - pos.y(), varInsunits), 0); + textLine->secPoint = DRW_Coord(FromPixel(pos.x(), varInsunits), + FromPixel(getSize().height() - pos.y(), varInsunits), 0); + textLine->height = AAMATextHeight; + textLine->layer = layer.toStdString(); + textLine->text = text.toStdString(); + + return textLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +P *VDxfEngine::CreateAAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed) +{ + P *poly = new P(); + poly->layer = layer.toStdString(); + + if (forceClosed) + { + poly->flags |= 0x1; // closed + } + else + { + if (polygon.size() > 1 && polygon.first() == polygon.last()) + { + poly->flags |= 0x1; // closed + } + } + + for (int i=0; i < polygon.count(); ++i) + { + poly->addVertex(V(FromPixel(polygon.at(i).x(), varInsunits), + FromPixel(getSize().height() - polygon.at(i).y(), varInsunits))); + } + + return poly; +} diff --git a/src/libs/vdxf/vdxfengine.h b/src/libs/vdxf/vdxfengine.h index 1382b2a81..01c42dd74 100644 --- a/src/libs/vdxf/vdxfengine.h +++ b/src/libs/vdxf/vdxfengine.h @@ -46,9 +46,13 @@ class QTextStream; class dx_iface; class DRW_Text; +class VLayoutPiece; +class DRW_Entity; +class dx_ifaceBlock; class VDxfEngine : public QPaintEngine { + friend class VDxfPaintDevice; public: VDxfEngine(); virtual ~VDxfEngine(); @@ -102,6 +106,23 @@ private: DRW_Text *textBuffer; Q_REQUIRED_RESULT double FromPixel(double pix, const VarInsunits &unit) const; + Q_REQUIRED_RESULT double ToPixel(double val, const VarInsunits &unit) const; + + bool ExportToAAMA(const QVector &details); + void ExportAAMAOutline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); + void ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); + void ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); + void ExportAAMANotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); + void ExportAAMAGrainline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); + void ExportAAMAText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); + void ExportAAMAGlobalText(const QSharedPointer &input, const QVector &details); + + Q_REQUIRED_RESULT DRW_Entity *AAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed); + Q_REQUIRED_RESULT DRW_Entity *AAMALine(const QLineF &line, const QString &layer); + Q_REQUIRED_RESULT DRW_Entity *AAMAText(const QPointF &pos, const QString &text, const QString &layer); + + template + Q_REQUIRED_RESULT P *CreateAAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed); }; #endif // VDXFENGINE_H diff --git a/src/libs/vdxf/vdxfpaintdevice.cpp b/src/libs/vdxf/vdxfpaintdevice.cpp index cbfdb4deb..ddd186d00 100644 --- a/src/libs/vdxf/vdxfpaintdevice.cpp +++ b/src/libs/vdxf/vdxfpaintdevice.cpp @@ -162,6 +162,15 @@ void VDxfPaintDevice::setInsunits(const VarInsunits &var) engine->setInsunits(var); } +//--------------------------------------------------------------------------------------------------------------------- +bool VDxfPaintDevice::ExportToAAMA(const QVector &details) const +{ + engine->setActive(true); + const bool res = engine->ExportToAAMA(details); + engine->setActive(false); + return res; +} + //--------------------------------------------------------------------------------------------------------------------- int VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const { diff --git a/src/libs/vdxf/vdxfpaintdevice.h b/src/libs/vdxf/vdxfpaintdevice.h index 0739005a2..0584d3ed1 100644 --- a/src/libs/vdxf/vdxfpaintdevice.h +++ b/src/libs/vdxf/vdxfpaintdevice.h @@ -39,6 +39,7 @@ #include "libdxfrw/drw_base.h" class VDxfEngine; +class VLayoutPiece; class VDxfPaintDevice : public QPaintDevice { @@ -65,6 +66,8 @@ public: void setMeasurement(const VarMeasurement &var); void setInsunits(const VarInsunits &var); + bool ExportToAAMA(const QVector &details) const; + protected: virtual int metric(PaintDeviceMetric metric) const Q_DECL_OVERRIDE; private: diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 914c4c717..4dc7d143d 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -216,7 +216,7 @@ QList VLayoutGenerator::GetPapersItems() const } //--------------------------------------------------------------------------------------------------------------------- -QList > VLayoutGenerator::GetAllDetails() const +QList > VLayoutGenerator::GetAllDetailsItems() const { QList > list; for (int i=0; i < papers.count(); ++i) @@ -226,6 +226,17 @@ QList > VLayoutGenerator::GetAllDetails() const return list; } +//--------------------------------------------------------------------------------------------------------------------- +QVector > VLayoutGenerator::GetAllDetails() const +{ + QVector > list; + for (int i=0; i < papers.count(); ++i) + { + list.append(papers.at(i).GetDetails()); + } + return list; +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::Abort() { diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 0055e919c..af3d5650b 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -83,7 +83,9 @@ public: LayoutErrors State() const; Q_REQUIRED_RESULT QList GetPapersItems() const; - Q_REQUIRED_RESULT QList> GetAllDetails() const; + Q_REQUIRED_RESULT QList> GetAllDetailsItems() const; + + QVector> GetAllDetails() const; bool GetRotate() const; void SetRotate(bool value); diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 87244ae0d..e58effaf9 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -68,7 +68,7 @@ QVector ConvertInternalPaths(const VPiece &piece, const VConta const VPiecePath path = pattern->GetPiecePath(pathsId.at(i)); if (path.GetType() == PiecePathType::InternalPath) { - paths.append(VLayoutPiecePath(path.PathPoints(pattern), path.GetPenType())); + paths.append(VLayoutPiecePath(path.PathPoints(pattern), path.IsCutPath(), path.GetPenType())); } } return paths; @@ -336,6 +336,20 @@ QPointF RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) return ptDest + ptCenter; } + +//--------------------------------------------------------------------------------------------------------------------- +QStringList PieceLabelText(const QVector &labelShape, const VTextManager &tm) +{ + QStringList text; + if (labelShape.count() > 2) + { + for (int i = 0; i < tm.GetSourceLinesCount(); ++i) + { + text.append(tm.GetSourceLine(i).m_qsText); + } + } + return text; +} } //--------------------------------------------------------------------------------------------------------------------- @@ -389,7 +403,7 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern const VPieceLabelData& data = piece.GetPatternPieceData(); if (data.IsVisible() == true) { - det.SetDetail(piece.GetName(), data, qApp->Settings()->GetLabelFont(), pattern); + det.SetPieceText(piece.GetName(), data, qApp->Settings()->GetLabelFont(), pattern); } const VPatternLabelData& geom = piece.GetPatternInfo(); @@ -460,8 +474,27 @@ QVector VLayoutPiece::GetLayoutAllowancePoints() const } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, const QFont &font, - const VContainer *pattern) +QPointF VLayoutPiece::GetPieceTextPosition() const +{ + if (d->detailLabel.count() > 2) + { + return d->matrix.map(d->detailLabel.first()); + } + else + { + return QPointF(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VLayoutPiece::GetPieceText() const +{ + return PieceLabelText(d->detailLabel, d->m_tmDetail); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetPieceText(const QString& qsName, const VPieceLabelData& data, const QFont &font, + const VContainer *pattern) { QPointF ptPos; qreal labelWidth = 0; @@ -501,6 +534,25 @@ void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, d->m_tmDetail.FitFontSize(labelWidth, labelHeight); } +//--------------------------------------------------------------------------------------------------------------------- +QPointF VLayoutPiece::GetPatternTextPosition() const +{ + if (d->patternInfo.count() > 2) + { + return d->matrix.map(d->patternInfo.first()); + } + else + { + return QPointF(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VLayoutPiece::GetPatternText() const +{ + return PieceLabelText(d->patternInfo, d->m_tmPattern); +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font, qreal dSize, qreal dHeight, const VContainer *pattern) @@ -586,6 +638,12 @@ void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer* pa d->grainlinePoints = CorrectPosition(item->boundingRect(), RoundPoints(v)); } +//--------------------------------------------------------------------------------------------------------------------- +QVector VLayoutPiece::GetGrainline() const +{ + return Map(d->grainlinePoints); +} + //--------------------------------------------------------------------------------------------------------------------- QTransform VLayoutPiece::GetMatrix() const { @@ -806,6 +864,22 @@ void VLayoutPiece::SetPassmarks(const QVector &passmarks) } } +//--------------------------------------------------------------------------------------------------------------------- +QVector > VLayoutPiece::InternalPathsForCut(bool cut) const +{ + QVector > paths; + + for (int i=0;i < d->m_internalPaths.count(); ++i) + { + if (d->m_internalPaths.at(i).IsCutPath() == cut) + { + paths.append(Map(d->m_internalPaths.at(i).Points())); + } + } + + return paths; +} + //--------------------------------------------------------------------------------------------------------------------- QVector VLayoutPiece::GetInternalPaths() const { @@ -1059,7 +1133,7 @@ void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const QPainterPath path; - QVector gPoints = Map(d->grainlinePoints); + QVector gPoints = GetGrainline(); path.moveTo(gPoints.at(0)); for (int i = 1; i < gPoints.count(); ++i) { diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index be95f8b0c..1f2cf66b7 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -85,15 +85,21 @@ public: QVector GetPassmarks() const; void SetPassmarks(const QVector &passmarks); + QVector> InternalPathsForCut(bool cut) const; QVector GetInternalPaths() const; void SetInternalPaths(const QVector &internalPaths); - void SetDetail(const QString &qsName, const VPieceLabelData& data, const QFont& font, const VContainer *pattern); + QPointF GetPieceTextPosition() const; + QStringList GetPieceText() const; + void SetPieceText(const QString &qsName, const VPieceLabelData& data, const QFont& font, const VContainer *pattern); + QPointF GetPatternTextPosition() const; + QStringList GetPatternText() const; void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont& font, qreal dSize, qreal dHeight, const VContainer *pattern); void SetGrainline(const VGrainlineData& geom, const VContainer *pattern); + QVector GetGrainline() const; QTransform GetMatrix() const; void SetMatrix(const QTransform &matrix); diff --git a/src/libs/vlayout/vlayoutpiecepath.cpp b/src/libs/vlayout/vlayoutpiecepath.cpp index c2fe0a842..11f9c6679 100644 --- a/src/libs/vlayout/vlayoutpiecepath.cpp +++ b/src/libs/vlayout/vlayoutpiecepath.cpp @@ -39,8 +39,8 @@ VLayoutPiecePath::VLayoutPiecePath() } //--------------------------------------------------------------------------------------------------------------------- -VLayoutPiecePath::VLayoutPiecePath(const QVector &points, Qt::PenStyle penStyle) - : d(new VLayoutPiecePathData(points, penStyle)) +VLayoutPiecePath::VLayoutPiecePath(const QVector &points, bool cut, Qt::PenStyle penStyle) + : d(new VLayoutPiecePathData(points, cut, penStyle)) { } @@ -101,3 +101,15 @@ void VLayoutPiecePath::SetPenStyle(const Qt::PenStyle &penStyle) { d->m_penStyle = penStyle; } + +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutPiecePath::IsCutPath() const +{ + return d->m_cut; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiecePath::SetCutPath(bool cut) +{ + d->m_cut = cut; +} diff --git a/src/libs/vlayout/vlayoutpiecepath.h b/src/libs/vlayout/vlayoutpiecepath.h index 5499ff59e..3d2ce4319 100644 --- a/src/libs/vlayout/vlayoutpiecepath.h +++ b/src/libs/vlayout/vlayoutpiecepath.h @@ -39,7 +39,7 @@ class VLayoutPiecePath { public: VLayoutPiecePath(); - VLayoutPiecePath(const QVector &points, Qt::PenStyle penStyle = Qt::SolidLine); + VLayoutPiecePath(const QVector &points, bool cut, Qt::PenStyle penStyle = Qt::SolidLine); VLayoutPiecePath(const VLayoutPiecePath &path); virtual ~VLayoutPiecePath(); @@ -60,6 +60,9 @@ public: Qt::PenStyle PenStyle() const; void SetPenStyle(const Qt::PenStyle &penStyle); + bool IsCutPath() const; + void SetCutPath(bool cut); + private: QSharedDataPointer d; }; diff --git a/src/libs/vlayout/vlayoutpiecepath_p.h b/src/libs/vlayout/vlayoutpiecepath_p.h index 8d69994b5..37d46a723 100644 --- a/src/libs/vlayout/vlayoutpiecepath_p.h +++ b/src/libs/vlayout/vlayoutpiecepath_p.h @@ -44,18 +44,21 @@ class VLayoutPiecePathData : public QSharedData public: VLayoutPiecePathData() : m_points(), - m_penStyle(Qt::SolidLine) + m_penStyle(Qt::SolidLine), + m_cut(true) {} - VLayoutPiecePathData(const QVector points, Qt::PenStyle penStyle) + VLayoutPiecePathData(const QVector points, bool cut, Qt::PenStyle penStyle) : m_points(points), - m_penStyle(penStyle) + m_penStyle(penStyle), + m_cut(cut) {} VLayoutPiecePathData(const VLayoutPiecePathData &path) : QSharedData(path), m_points(path.m_points), - m_penStyle(path.m_penStyle) + m_penStyle(path.m_penStyle), + m_cut(path.m_cut) {} ~VLayoutPiecePathData() Q_DECL_EQ_DEFAULT; @@ -66,6 +69,8 @@ public: /** @brief m_penStyle path pen style. */ Qt::PenStyle m_penStyle; + bool m_cut; + private: VLayoutPiecePathData &operator=(const VLayoutPiecePathData &) Q_DECL_EQ_DELETE; }; diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index a24a94eff..a200f8f52 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -237,6 +237,18 @@ void VPiecePath::SetPenType(const Qt::PenStyle &type) d->m_penType = type; } +//--------------------------------------------------------------------------------------------------------------------- +bool VPiecePath::IsCutPath() const +{ + return d->m_cut; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiecePath::SetCutPath(bool cut) +{ + d->m_cut = cut; +} + //--------------------------------------------------------------------------------------------------------------------- QVector VPiecePath::PathPoints(const VContainer *data) const { diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index f62d603fe..136942230 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -78,6 +78,9 @@ public: Qt::PenStyle GetPenType() const; void SetPenType(const Qt::PenStyle &type); + bool IsCutPath() const; + void SetCutPath(bool cut); + QVector PathPoints(const VContainer *data) const; QVector PathNodePoints(const VContainer *data, bool showExcluded = true) const; QVector SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const; diff --git a/src/libs/vpatterndb/vpiecepath_p.h b/src/libs/vpatterndb/vpiecepath_p.h index 2cdc2c119..88d281f8d 100644 --- a/src/libs/vpatterndb/vpiecepath_p.h +++ b/src/libs/vpatterndb/vpiecepath_p.h @@ -46,14 +46,16 @@ public: : m_nodes(), m_type(PiecePathType::Unknown), m_name(), - m_penType(Qt::SolidLine) + m_penType(Qt::SolidLine), + m_cut(true) {} explicit VPiecePathData(PiecePathType type) : m_nodes(), m_type(type), m_name(), - m_penType(Qt::SolidLine) + m_penType(Qt::SolidLine), + m_cut(true) {} VPiecePathData(const VPiecePathData &path) @@ -61,7 +63,8 @@ public: m_nodes(path.m_nodes), m_type(path.m_type), m_name(path.m_name), - m_penType(path.m_penType) + m_penType(path.m_penType), + m_cut(path.m_cut) {} ~VPiecePathData(); @@ -70,6 +73,7 @@ public: PiecePathType m_type; QString m_name; Qt::PenStyle m_penType; + bool m_cut; private: VPiecePathData &operator=(const VPiecePathData &) Q_DECL_EQ_DELETE;