Resolved issue #660. New export: Export details without layout.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-07-09 14:45:49 +03:00
parent b4622341b6
commit 7d205d7596
14 changed files with 443 additions and 207 deletions

View File

@ -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.

View File

@ -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 <The size value>"
.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 <The height value>"

View File

@ -108,6 +108,12 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap<QString, int>
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
{

View File

@ -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

View File

@ -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<int>(v.second)));
}
#ifdef V_NO_ASSERT // Temporarily unavailable
const int index = ui->comboBoxFormat->findData(static_cast<int>(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<void (QComboBox::*)(int)>(&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<std::pair<QString, LayoutExportFormats> > DialogSaveLayout::InitFormats(
return list;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSaveLayout::RemoveFormatFromList(LayoutExportFormats format)
{
const int index = ui->comboBoxFormat->findData(static_cast<int>(format));
if (index != -1)
{
ui->comboBoxFormat->removeItem(index);
}
}

View File

@ -30,6 +30,7 @@
#define DIALOGSAVELAYOUT_H
#include <QDialog>
#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<std::pair<QString, LayoutExportFormats> > InitFormats();
void RemoveFormatFromList(LayoutExportFormats format);
};
#endif // DIALOGSAVELAYOUT_H

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>748</width>
<height>178</height>
<height>206</height>
</rect>
</property>
<property name="windowTitle">
@ -92,14 +92,31 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBoxBinaryDXF">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Binary form</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="lineEditFileName">
@ -135,20 +152,13 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBoxBinaryDXF">
<item row="3" column="1">
<widget class="QCheckBox" name="checkBoxTextAsPaths">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Binary form</string>
<string>Text as paths</string>
</property>
</widget>
</item>

View File

@ -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<quint32, VPiece> *allDetails = pattern->DataPieces();
QHash<quint32, VPiece>::const_iterator i = allDetails->constBegin();
QHash<quint32, VPiece> 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<VLayoutPiece> 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<LayoutExportFormats>(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<LayoutExportFormats>(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);

View File

@ -118,6 +118,7 @@ private slots:
void CreateMeasurements();
#endif
void ExportLayoutAs();
void ExportDetailsAs();
void ArrowTool();
void ToolEndLine(bool checked);

View File

@ -45,10 +45,10 @@
</font>
</property>
<property name="toolTip">
<string>Tools</string>
<string>Export details skiping the Layout stage</string>
</property>
<property name="currentIndex">
<number>5</number>
<number>6</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
@ -1504,6 +1504,29 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QToolButton" name="toolButtonDetailExportAs">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset resource="../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/32x32/export_to_picture_document.png</normaloff>:/icon/32x32/export_to_picture_document.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutPage">
@ -2655,8 +2678,8 @@
</customwidget>
</customwidgets>
<resources>
<include location="../../libs/vmisc/share/resources/icon.qrc"/>
<include location="share/resources/toolicon.qrc"/>
<include location="../../libs/vmisc/share/resources/icon.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -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<VLayoutPiece> &listDetails, const DialogSaveLayout &dialog)
{
if (dialog.Mode() == Draw::Layout)
{
ExportLayout(dialog, scenes, papers, shadows, ignorePrinterFields, margins);
}
else
{
QScopedPointer<QGraphicsScene> scene(new QGraphicsScene());
QList<QGraphicsItem *> 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<QGraphicsItem *> papers;// Blank sheets
papers.append(new QGraphicsRectItem(scene->itemsBoundingRect().toRect()));
QList<QList<QGraphicsItem *> > details;// All details
details.append(list);
QList<QGraphicsItem *> shadows = CreateShadows(papers);
QList<QGraphicsScene *> 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<QGraphicsScene *> &scenes,
const QList<QGraphicsItem *> &papers, const QList<QGraphicsItem *> &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<quint32, VPiece> *details)
QVector<VLayoutPiece> MainWindowsNoGUI::PrepareDetailsForLayout(const QHash<quint32, VPiece> &details)
{
listDetails.clear();
SCASSERT(details != nullptr)
if (details->count() == 0)
QVector<VLayoutPiece> listDetails;
if (not details.isEmpty())
{
return;
QHash<quint32, VPiece>::const_iterator i = details.constBegin();
while (i != details.constEnd())
{
VAbstractTool *tool = qobject_cast<VAbstractTool*>(VAbstractPattern::getTool(i.key()));
SCASSERT(tool != nullptr)
listDetails.append(VLayoutPiece::Create(i.value(), tool->getData()));
++i;
}
}
QHash<quint32, VPiece>::const_iterator i = details->constBegin();
while (i != details->constEnd())
{
VAbstractTool *tool = qobject_cast<VAbstractTool*>(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<QGraphicsItem *> MainWindowsNoGUI::CreateShadows(const QList<QGraphicsItem *> &papers)
{
QList<QGraphicsItem *> 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<QGraphicsScene *> MainWindowsNoGUI::CreateScenes(const QList<QGraphicsItem *> &papers,
const QList<QGraphicsItem *> &shadows,
const QList<QList<QGraphicsItem *> > &details)
{
QList<QGraphicsScene *> scenes;
for (int i=0; i<papers.size(); ++i)
{
QGraphicsScene *scene = new VMainGraphicsScene();
@ -661,6 +709,8 @@ void MainWindowsNoGUI::CreateScenes()
scenes.append(scene);
}
return scenes;
}
//---------------------------------------------------------------------------------------------------------------------
@ -668,27 +718,23 @@ void MainWindowsNoGUI::CreateScenes()
* @brief SvgFile save layout to svg file.
* @param name name layout file.
*/
void MainWindowsNoGUI::SvgFile(const QString &name, int i) const
void MainWindowsNoGUI::SvgFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene) const
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(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<int>(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<int>(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<QGraphicsRectItem *>(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<QGraphicsRectItem *>(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<int>(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<int>(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 &params) 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<QGraphicsRectItem *>(papers.at(i));
if (paper)
{
VObjPaintDevice generator;
generator.setFileName(name);
generator.setSize(paper->rect().size().toSize());
generator.setResolution(static_cast<int>(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<int>(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<QGraphicsRectItem *>(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<DRW::Version>(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<DRW::Version>(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

View File

@ -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<quint32, VPiece> *details);
void ExportLayout(const DialogSaveLayout &dialog);
static QVector<VLayoutPiece> PrepareDetailsForLayout(const QHash<quint32, VPiece> &details);
void ExportData(const QVector<VLayoutPiece> &listDetails, const DialogSaveLayout &dialog);
void ExportLayout(const DialogSaveLayout &dialog,
const QList<QGraphicsScene *> &scenes,
const QList<QGraphicsItem *> &papers,
const QList<QGraphicsItem *> &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<QGraphicsItem *> CreateShadows(const QList<QGraphicsItem *> &papers);
static QList<QGraphicsScene *> CreateScenes(const QList<QGraphicsItem *> &papers,
const QList<QGraphicsItem *> &shadows,
const QList<QList<QGraphicsItem *> > &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 &params)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;

View File

@ -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");

View File

@ -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;