2015-01-23 11:07:58 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogsavelayout.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 22 1, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2015-01-23 11:07:58 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "dialogsavelayout.h"
|
|
|
|
#include "ui_dialogsavelayout.h"
|
2015-06-19 13:21:46 +02:00
|
|
|
#include "../options.h"
|
|
|
|
#include "../core/vapplication.h"
|
2015-10-08 20:11:50 +02:00
|
|
|
#include "../vmisc/vsettings.h"
|
2015-10-11 11:06:14 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
2015-01-23 11:07:58 +01:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2015-08-26 05:39:33 +02:00
|
|
|
#include <QProcess>
|
2016-08-16 19:35:21 +02:00
|
|
|
#include <QtDebug>
|
2016-10-23 11:11:00 +02:00
|
|
|
#include <QRegularExpression>
|
2015-01-23 11:07:58 +01:00
|
|
|
|
2015-10-05 15:08:26 +02:00
|
|
|
const QString baseFilenameRegExp = QStringLiteral("^[\\w\\-. ]+$");
|
|
|
|
|
2015-10-23 19:47:33 +02:00
|
|
|
bool DialogSaveLayout::havePdf = false;
|
|
|
|
bool DialogSaveLayout::tested = false;
|
2015-08-25 19:53:03 +02:00
|
|
|
|
2015-01-23 11:07:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-07-09 13:45:49 +02:00
|
|
|
DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName, QWidget *parent)
|
2017-06-26 16:28:41 +02:00
|
|
|
: QDialog(parent),
|
|
|
|
ui(new Ui::DialogSaveLAyout),
|
|
|
|
count(count),
|
2017-07-09 13:45:49 +02:00
|
|
|
isInitialized(false),
|
|
|
|
m_mode(mode)
|
2015-01-23 11:07:58 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2015-12-09 11:40:43 +01:00
|
|
|
ui->lineEditPath->setClearButtonEnabled(true);
|
|
|
|
ui->lineEditFileName->setClearButtonEnabled(true);
|
|
|
|
|
2017-01-03 09:46:28 +01:00
|
|
|
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
|
2015-02-10 20:27:11 +01:00
|
|
|
|
2015-01-23 11:07:58 +01:00
|
|
|
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(bOk != nullptr)
|
2015-01-23 11:07:58 +01:00
|
|
|
bOk->setEnabled(false);
|
|
|
|
|
2015-10-08 19:45:26 +02:00
|
|
|
ui->lineEditFileName->setValidator( new QRegularExpressionValidator(QRegularExpression(baseFilenameRegExp), this));
|
|
|
|
|
2016-07-20 10:39:15 +02:00
|
|
|
const QString mask = fileName+QLatin1String("_");
|
2015-12-09 12:31:33 +01:00
|
|
|
if (VApplication::IsGUIMode())
|
2015-10-05 15:08:26 +02:00
|
|
|
{
|
|
|
|
ui->lineEditFileName->setText(mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (QRegularExpression(baseFilenameRegExp).match(mask).hasMatch())
|
|
|
|
{
|
|
|
|
ui->lineEditFileName->setText(mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-13 18:30:25 +01:00
|
|
|
VException e(tr("The base filename does not match a regular expression."));
|
2015-10-11 11:06:14 +02:00
|
|
|
throw e;
|
2015-10-05 15:08:26 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-23 11:07:58 +01:00
|
|
|
|
2017-06-26 16:28:41 +02:00
|
|
|
foreach (auto& v, InitFormats())
|
2015-01-23 11:07:58 +01:00
|
|
|
{
|
2017-06-26 16:28:41 +02:00
|
|
|
ui->comboBoxFormat->addItem(v.first, QVariant(static_cast<int>(v.second)));
|
2015-01-23 11:07:58 +01:00
|
|
|
}
|
2017-07-08 19:18:47 +02:00
|
|
|
#ifdef V_NO_ASSERT // Temporarily unavailable
|
2017-07-09 13:45:49 +02:00
|
|
|
RemoveFormatFromList(LayoutExportFormats::OBJ);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (m_mode != Draw::Layout)
|
2017-07-08 19:18:47 +02:00
|
|
|
{
|
2017-07-09 13:45:49 +02:00
|
|
|
RemoveFormatFromList(LayoutExportFormats::PDFTiled);
|
2017-07-08 19:18:47 +02:00
|
|
|
}
|
2017-07-09 13:45:49 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->checkBoxTextAsPaths->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2015-01-23 11:07:58 +01:00
|
|
|
connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save);
|
2017-06-26 16:28:41 +02:00
|
|
|
connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample);
|
2016-12-21 19:45:14 +01:00
|
|
|
connect(ui->comboBoxFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
2017-06-26 16:28:41 +02:00
|
|
|
this, &DialogSaveLayout::ShowExample);
|
2017-05-30 18:52:38 +02:00
|
|
|
connect(ui->pushButtonBrowse, &QPushButton::clicked, this, [this]()
|
2016-07-18 17:09:15 +02:00
|
|
|
{
|
2017-02-17 19:37:49 +01:00
|
|
|
const QString dirPath = qApp->ValentinaSettings()->GetPathLayout();
|
|
|
|
bool usedNotExistedDir = false;
|
|
|
|
QDir directory(dirPath);
|
|
|
|
if (not directory.exists())
|
|
|
|
{
|
|
|
|
usedNotExistedDir = directory.mkpath(".");
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder"), dirPath,
|
2017-06-19 15:11:44 +02:00
|
|
|
QFileDialog::ShowDirsOnly
|
|
|
|
| QFileDialog::DontResolveSymlinks
|
|
|
|
| QFileDialog::DontUseNativeDialog);
|
2016-08-15 14:03:10 +02:00
|
|
|
if (not dir.isEmpty())
|
|
|
|
{// If paths equal the signal will not be called, we will do this manually
|
|
|
|
dir == ui->lineEditPath->text() ? PathChanged(dir) : ui->lineEditPath->setText(dir);
|
|
|
|
}
|
2017-02-17 19:37:49 +01:00
|
|
|
|
|
|
|
if (usedNotExistedDir)
|
|
|
|
{
|
|
|
|
QDir directory(dirPath);
|
|
|
|
directory.rmpath(".");
|
|
|
|
}
|
2016-07-18 17:09:15 +02:00
|
|
|
});
|
2015-01-23 11:07:58 +01:00
|
|
|
connect(ui->lineEditPath, &QLineEdit::textChanged, this, &DialogSaveLayout::PathChanged);
|
|
|
|
|
2015-07-24 14:06:53 +02:00
|
|
|
ui->lineEditPath->setText(qApp->ValentinaSettings()->GetPathLayout());
|
2015-03-31 15:38:59 +02:00
|
|
|
ShowExample();//Show example for current format.
|
2015-01-23 11:07:58 +01:00
|
|
|
}
|
2015-08-25 19:53:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2017-06-26 16:28:41 +02:00
|
|
|
void DialogSaveLayout::SelectFormat(LayoutExportFormats format)
|
2015-08-25 19:53:03 +02:00
|
|
|
{
|
2017-06-26 16:28:41 +02:00
|
|
|
if (static_cast<int>(format) < 0 || format >= LayoutExportFormats::COUNT)
|
2015-08-25 19:53:03 +02:00
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
VException e(tr("Tried to use out of range format number."));
|
|
|
|
throw e;
|
2015-08-25 19:53:03 +02:00
|
|
|
}
|
|
|
|
|
2017-06-26 16:28:41 +02:00
|
|
|
const int i = ui->comboBoxFormat->findData(static_cast<int>(format));
|
2015-08-25 19:53:03 +02:00
|
|
|
if (i < 0)
|
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
VException e(tr("Selected not present format."));
|
|
|
|
throw e;
|
2015-08-25 19:53:03 +02:00
|
|
|
}
|
|
|
|
ui->comboBoxFormat->setCurrentIndex(i);
|
|
|
|
}
|
|
|
|
|
2017-06-26 16:28:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSaveLayout::SetBinaryDXFFormat(bool binary)
|
|
|
|
{
|
|
|
|
switch(Format())
|
|
|
|
{
|
|
|
|
case LayoutExportFormats::DXF_AC1006_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_ASTM:
|
|
|
|
ui->checkBoxBinaryDXF->setChecked(binary);
|
|
|
|
break;
|
|
|
|
case LayoutExportFormats::SVG:
|
|
|
|
case LayoutExportFormats::PDF:
|
2017-07-08 19:18:47 +02:00
|
|
|
case LayoutExportFormats::PDFTiled:
|
2017-06-26 16:28:41 +02:00
|
|
|
case LayoutExportFormats::PNG:
|
|
|
|
case LayoutExportFormats::OBJ:
|
|
|
|
case LayoutExportFormats::PS:
|
|
|
|
case LayoutExportFormats::EPS:
|
|
|
|
default:
|
|
|
|
ui->checkBoxBinaryDXF->setChecked(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogSaveLayout::IsBinaryDXFFormat() const
|
|
|
|
{
|
|
|
|
switch(Format())
|
|
|
|
{
|
|
|
|
case LayoutExportFormats::DXF_AC1006_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_ASTM:
|
|
|
|
return ui->checkBoxBinaryDXF->isChecked();
|
|
|
|
case LayoutExportFormats::SVG:
|
|
|
|
case LayoutExportFormats::PDF:
|
2017-07-08 19:18:47 +02:00
|
|
|
case LayoutExportFormats::PDFTiled:
|
2017-06-26 16:28:41 +02:00
|
|
|
case LayoutExportFormats::PNG:
|
|
|
|
case LayoutExportFormats::OBJ:
|
|
|
|
case LayoutExportFormats::PS:
|
|
|
|
case LayoutExportFormats::EPS:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 19:53:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogSaveLayout::MakeHelpFormatList()
|
|
|
|
{
|
2016-08-15 14:03:10 +02:00
|
|
|
QString out("\n");
|
2017-06-26 16:28:41 +02:00
|
|
|
foreach(auto& v, InitFormats())
|
2015-08-25 19:53:03 +02:00
|
|
|
{
|
2017-06-26 16:28:41 +02:00
|
|
|
out += QLatin1String("\t") + v.first + QLatin1String(" = ") + QString::number(static_cast<int>(v.second))
|
|
|
|
+ QLatin1String("\n");
|
2015-08-25 19:53:03 +02:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2015-01-23 11:07:58 +01:00
|
|
|
|
2015-08-27 23:29:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-05 15:08:26 +02:00
|
|
|
void DialogSaveLayout::SetDestinationPath(const QString &cmdDestinationPath)
|
2015-08-27 23:29:08 +02:00
|
|
|
{
|
2015-10-05 15:08:26 +02:00
|
|
|
QString path;
|
|
|
|
if (cmdDestinationPath.isEmpty())
|
|
|
|
{
|
|
|
|
path = QDir::currentPath();
|
|
|
|
}
|
|
|
|
else if (QDir(cmdDestinationPath).isAbsolute())
|
|
|
|
{
|
|
|
|
path = cmdDestinationPath;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QDir dir;
|
|
|
|
if (not dir.cd(cmdDestinationPath))
|
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
VException e(tr("The destination directory doesn't exists or is not readable."));
|
|
|
|
throw e;
|
2015-10-05 15:08:26 +02:00
|
|
|
}
|
|
|
|
path = dir.absolutePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Output full path: " << path << "\n";
|
|
|
|
ui->lineEditPath->setText(path);
|
2015-08-27 23:29:08 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 13:45:49 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Draw DialogSaveLayout::Mode() const
|
|
|
|
{
|
|
|
|
return m_mode;
|
|
|
|
}
|
|
|
|
|
2017-06-26 16:28:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogSaveLayout::ExportFormatDescription(LayoutExportFormats format)
|
|
|
|
{
|
|
|
|
const QString dxfSuffix = QStringLiteral("(*.dxf)");
|
|
|
|
const QString dxfFlatFilesStr = tr("(flat) files");
|
|
|
|
const QString filesStr = tr("files");
|
|
|
|
|
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case LayoutExportFormats::SVG:
|
|
|
|
return QString("Svg %1 (*.svg)").arg(filesStr);
|
|
|
|
case LayoutExportFormats::PDF:
|
|
|
|
return QString("PDF %1 (*.pdf)").arg(filesStr);
|
|
|
|
case LayoutExportFormats::PNG:
|
|
|
|
return tr("Image files") + QLatin1String(" (*.png)");
|
|
|
|
case LayoutExportFormats::OBJ:
|
|
|
|
return "Wavefront OBJ (*.obj)";
|
|
|
|
case LayoutExportFormats::PS:
|
|
|
|
return QString("PS %1 (*.ps)").arg(filesStr);
|
|
|
|
case LayoutExportFormats::EPS:
|
|
|
|
return QString("EPS %1 (*.eps)").arg(filesStr);
|
|
|
|
case LayoutExportFormats::DXF_AC1006_Flat:
|
|
|
|
return QString("AutoCAD DXF R10 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1009_Flat:
|
|
|
|
return QString("AutoCAD DXF R11/12 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1012_Flat:
|
|
|
|
return QString("AutoCAD DXF R13 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1014_Flat:
|
|
|
|
return QString("AutoCAD DXF R14 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1015_Flat:
|
|
|
|
return QString("AutoCAD DXF 2000 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1018_Flat:
|
|
|
|
return QString("AutoCAD DXF 2004 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1021_Flat:
|
|
|
|
return QString("AutoCAD DXF 2007 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1024_Flat:
|
|
|
|
return QString("AutoCAD DXF 2010 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1027_Flat:
|
|
|
|
return QString("AutoCAD DXF 2013 %1 %2").arg(dxfFlatFilesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1006_AAMA:
|
2017-07-16 20:10:48 +02:00
|
|
|
return QString("AutoCAD DXF R10 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
2017-06-26 16:28:41 +02:00
|
|
|
case LayoutExportFormats::DXF_AC1009_AAMA:
|
2017-07-16 20:10:48 +02:00
|
|
|
return QString("AutoCAD DXF R11/12 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
2017-06-26 16:28:41 +02:00
|
|
|
case LayoutExportFormats::DXF_AC1012_AAMA:
|
|
|
|
return QString("AutoCAD DXF R13 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1014_AAMA:
|
|
|
|
return QString("AutoCAD DXF R14 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1015_AAMA:
|
|
|
|
return QString("AutoCAD DXF 2000 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1018_AAMA:
|
|
|
|
return QString("AutoCAD DXF 2004 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1021_AAMA:
|
|
|
|
return QString("AutoCAD DXF 2007 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1024_AAMA:
|
|
|
|
return QString("AutoCAD DXF 2010 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1027_AAMA:
|
|
|
|
return QString("AutoCAD DXF 2013 AAMA %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1006_ASTM:
|
|
|
|
return QString("AutoCAD DXF R10 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1009_ASTM:
|
|
|
|
return QString("AutoCAD DXF R11/12 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1012_ASTM:
|
|
|
|
return QString("AutoCAD DXF R13 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1014_ASTM:
|
|
|
|
return QString("AutoCAD DXF R14 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1015_ASTM:
|
|
|
|
return QString("AutoCAD DXF 2000 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1018_ASTM:
|
|
|
|
return QString("AutoCAD DXF 2004 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1021_ASTM:
|
|
|
|
return QString("AutoCAD DXF 2007 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1024_ASTM:
|
|
|
|
return QString("AutoCAD DXF 2010 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
|
|
|
case LayoutExportFormats::DXF_AC1027_ASTM:
|
|
|
|
return QString("AutoCAD DXF 2013 ASTM %1 %2").arg(filesStr, dxfSuffix);
|
2017-07-08 19:18:47 +02:00
|
|
|
case LayoutExportFormats::PDFTiled:
|
|
|
|
return QString("PDF tiled %1 (*.pdf)").arg(filesStr);
|
2017-06-26 16:28:41 +02:00
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogSaveLayout::ExportFromatSuffix(LayoutExportFormats format)
|
|
|
|
{
|
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case LayoutExportFormats::SVG:
|
|
|
|
return ".svg";
|
|
|
|
case LayoutExportFormats::PDF:
|
2017-07-08 19:18:47 +02:00
|
|
|
case LayoutExportFormats::PDFTiled:
|
2017-06-26 16:28:41 +02:00
|
|
|
return ".pdf";
|
|
|
|
case LayoutExportFormats::PNG:
|
|
|
|
return ".png";
|
|
|
|
case LayoutExportFormats::OBJ:
|
|
|
|
return ".obj";
|
|
|
|
case LayoutExportFormats::PS:
|
|
|
|
return ".ps";
|
|
|
|
case LayoutExportFormats::EPS:
|
|
|
|
return ".eps";
|
|
|
|
case LayoutExportFormats::DXF_AC1006_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_ASTM:
|
|
|
|
return ".dxf";
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-23 11:07:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogSaveLayout::~DialogSaveLayout()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogSaveLayout::Path() const
|
|
|
|
{
|
|
|
|
return ui->lineEditPath->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-26 14:38:51 +01:00
|
|
|
QString DialogSaveLayout::FileName() const
|
2015-01-23 11:07:58 +01:00
|
|
|
{
|
2015-01-26 14:38:51 +01:00
|
|
|
return ui->lineEditFileName->text();
|
2015-01-23 11:07:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-26 16:28:41 +02:00
|
|
|
LayoutExportFormats DialogSaveLayout::Format() const
|
2015-01-23 11:07:58 +01:00
|
|
|
{
|
2017-06-26 16:28:41 +02:00
|
|
|
return static_cast<LayoutExportFormats>(ui->comboBoxFormat->currentData().toInt());
|
2015-01-23 11:07:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSaveLayout::Save()
|
|
|
|
{
|
|
|
|
for (int i=0; i < count; ++i)
|
2015-09-28 20:54:41 +02:00
|
|
|
{
|
2017-06-26 16:28:41 +02:00
|
|
|
const QString name = Path()+QLatin1Literal("/")+FileName()+QString::number(i+1)+ExportFromatSuffix(Format());
|
2015-01-23 11:07:58 +01:00
|
|
|
if (QFile::exists(name))
|
|
|
|
{
|
|
|
|
QMessageBox::StandardButton res = QMessageBox::question(this, tr("Name conflict"),
|
|
|
|
tr("Folder already contain file with name %1. Rewrite all conflict file names?")
|
|
|
|
.arg(name), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
|
|
|
|
if (res == QMessageBox::No)
|
|
|
|
{
|
2017-06-27 15:09:16 +02:00
|
|
|
reject();
|
2015-01-23 11:07:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSaveLayout::PathChanged(const QString &text)
|
|
|
|
{
|
|
|
|
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(bOk != nullptr)
|
2015-01-23 11:07:58 +01:00
|
|
|
|
|
|
|
QPalette palette = ui->lineEditPath->palette();
|
|
|
|
|
|
|
|
QDir dir(text);
|
|
|
|
dir.setPath(text);
|
|
|
|
if (dir.exists(text))
|
|
|
|
{
|
|
|
|
bOk->setEnabled(true);
|
|
|
|
palette.setColor(ui->lineEditPath->foregroundRole(), Qt::black);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bOk->setEnabled(false);
|
|
|
|
palette.setColor(ui->lineEditPath->foregroundRole(), Qt::red);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->lineEditPath->setPalette(palette);
|
|
|
|
}
|
2015-10-23 19:47:33 +02:00
|
|
|
|
2017-06-26 16:28:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSaveLayout::ShowExample()
|
|
|
|
{
|
|
|
|
const LayoutExportFormats currentFormat = Format();
|
|
|
|
ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + ExportFromatSuffix(currentFormat));
|
|
|
|
|
|
|
|
switch(currentFormat)
|
|
|
|
{
|
|
|
|
case LayoutExportFormats::DXF_AC1006_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_Flat:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_AAMA:
|
|
|
|
case LayoutExportFormats::DXF_AC1006_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1009_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1012_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1014_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1015_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1018_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1021_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1024_ASTM:
|
|
|
|
case LayoutExportFormats::DXF_AC1027_ASTM:
|
|
|
|
ui->checkBoxBinaryDXF->setEnabled(true);
|
|
|
|
break;
|
|
|
|
case LayoutExportFormats::SVG:
|
|
|
|
case LayoutExportFormats::PDF:
|
2017-07-08 19:18:47 +02:00
|
|
|
case LayoutExportFormats::PDFTiled:
|
2017-06-26 16:28:41 +02:00
|
|
|
case LayoutExportFormats::PNG:
|
|
|
|
case LayoutExportFormats::OBJ:
|
|
|
|
case LayoutExportFormats::PS:
|
|
|
|
case LayoutExportFormats::EPS:
|
|
|
|
default:
|
|
|
|
ui->checkBoxBinaryDXF->setEnabled(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-09 13:45:49 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 14:01:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSaveLayout::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QDialog::showEvent( event );
|
|
|
|
if ( event->spontaneous() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInitialized)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// do your init stuff here
|
|
|
|
|
2016-08-15 14:03:10 +02:00
|
|
|
setFixedHeight(size().height());
|
2015-11-05 14:01:33 +01:00
|
|
|
|
|
|
|
isInitialized = true;//first show windows are held
|
|
|
|
}
|
|
|
|
|
2015-08-25 19:53:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-23 19:47:33 +02:00
|
|
|
bool DialogSaveLayout::SupportPSTest()
|
|
|
|
{
|
|
|
|
if (!tested)
|
|
|
|
{
|
|
|
|
havePdf = TestPdf();
|
|
|
|
tested = true;
|
|
|
|
}
|
|
|
|
return havePdf;
|
|
|
|
}
|
2015-08-25 19:53:03 +02:00
|
|
|
|
2015-10-23 19:47:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogSaveLayout::TestPdf()
|
2015-08-25 19:53:03 +02:00
|
|
|
{
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
QProcess proc;
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
2016-08-15 14:03:10 +02:00
|
|
|
// Seek pdftops in app bundle or near valentin.exe
|
|
|
|
proc.start(qApp->applicationDirPath() + QLatin1String("/")+ PDFTOPS);
|
2015-08-25 19:53:03 +02:00
|
|
|
#else
|
|
|
|
proc.start(PDFTOPS); // Seek pdftops in standard path
|
|
|
|
#endif
|
2016-12-03 09:40:23 +01:00
|
|
|
if (proc.waitForStarted(15000) && (proc.waitForFinished(15000) || proc.state() == QProcess::NotRunning))
|
2015-08-25 19:53:03 +02:00
|
|
|
{
|
|
|
|
res = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2015-10-23 19:47:33 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-26 16:28:41 +02:00
|
|
|
QVector<std::pair<QString, LayoutExportFormats> > DialogSaveLayout::InitFormats()
|
2015-10-23 19:47:33 +02:00
|
|
|
{
|
2017-06-26 16:28:41 +02:00
|
|
|
QVector<std::pair<QString, LayoutExportFormats>> list;
|
|
|
|
|
|
|
|
auto InitFormat = [&list](LayoutExportFormats format)
|
|
|
|
{
|
|
|
|
list.append(std::make_pair(ExportFormatDescription(format), format));
|
|
|
|
};
|
|
|
|
|
|
|
|
InitFormat(LayoutExportFormats::SVG);
|
|
|
|
InitFormat(LayoutExportFormats::PDF);
|
|
|
|
InitFormat(LayoutExportFormats::PNG);
|
|
|
|
InitFormat(LayoutExportFormats::OBJ);
|
2015-10-23 19:47:33 +02:00
|
|
|
if (SupportPSTest())
|
|
|
|
{
|
2017-06-26 16:28:41 +02:00
|
|
|
InitFormat(LayoutExportFormats::PS);
|
|
|
|
InitFormat(LayoutExportFormats::EPS);
|
2015-10-23 19:47:33 +02:00
|
|
|
}
|
2017-06-26 16:28:41 +02:00
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1006_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1009_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1012_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1014_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1015_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1018_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1021_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1024_Flat);
|
|
|
|
InitFormat(LayoutExportFormats::DXF_AC1027_Flat);
|
2017-07-16 20:10:48 +02:00
|
|
|
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);
|
2017-06-26 16:28:41 +02:00
|
|
|
// We will support them anyway
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1006_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1009_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1012_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1014_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1015_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1018_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1021_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1024_ASTM);
|
|
|
|
// InitFormat(LayoutExportFormats::DXF_AC1027_ASTM);
|
2017-07-08 19:18:47 +02:00
|
|
|
InitFormat(LayoutExportFormats::PDFTiled);
|
2017-06-26 16:28:41 +02:00
|
|
|
|
2015-10-23 19:47:33 +02:00
|
|
|
return list;
|
|
|
|
}
|
2017-07-09 13:45:49 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSaveLayout::RemoveFormatFromList(LayoutExportFormats format)
|
|
|
|
{
|
|
|
|
const int index = ui->comboBoxFormat->findData(static_cast<int>(format));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxFormat->removeItem(index);
|
|
|
|
}
|
|
|
|
}
|