Show/hide grainline when export. Closes #163

This commit is contained in:
Roman Telezhynskyi 2023-04-10 12:20:18 +03:00
parent 64acbfff4c
commit a2b701f083
22 changed files with 474 additions and 122 deletions

View File

@ -22,6 +22,7 @@
- Fix seam allowance. Loose requirements to case with prong. - Fix seam allowance. Loose requirements to case with prong.
- Fix list of dimension popup list. Make sure it will always has enough space for values. - Fix list of dimension popup list. Make sure it will always has enough space for values.
- New grainline type: Four way. - New grainline type: Four way.
- [smart-pattern/valentina#163] Show/hide grainline when export.
# Valentina 0.7.52 September 12, 2022 # Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru. - Fix crash when default locale is ru.

View File

@ -250,6 +250,62 @@ auto DialogSaveManualLayout::IsBinaryDXFFormat() const -> bool
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSaveManualLayout::SetShowGrainline(bool show)
{
switch(Format())
{
case LayoutExportFormats::SVG:
case LayoutExportFormats::PDF:
case LayoutExportFormats::PNG:
case LayoutExportFormats::PS:
case LayoutExportFormats::EPS:
case LayoutExportFormats::PDFTiled:
case LayoutExportFormats::TIF:
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:
ui->checkBoxShowGrainline->setChecked(show);
break;
default:
ui->checkBoxShowGrainline->setChecked(true);
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogSaveManualLayout::IsShowGrainline() const
{
switch(Format())
{
case LayoutExportFormats::SVG:
case LayoutExportFormats::PDF:
case LayoutExportFormats::PNG:
case LayoutExportFormats::PS:
case LayoutExportFormats::EPS:
case LayoutExportFormats::PDFTiled:
case LayoutExportFormats::TIF:
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:
return ui->checkBoxShowGrainline->isChecked();
default:
return true;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSaveManualLayout::SetDestinationPath(const QString &cmdDestinationPath) void DialogSaveManualLayout::SetDestinationPath(const QString &cmdDestinationPath)
{ {
@ -444,18 +500,10 @@ void DialogSaveManualLayout::ShowExample()
ui->checkBoxTextAsPaths->setEnabled(true); ui->checkBoxTextAsPaths->setEnabled(true);
ui->checkBoxExportUnified->setEnabled(false); ui->checkBoxExportUnified->setEnabled(false);
ui->checkBoxTilesScheme->setEnabled(false); ui->checkBoxTilesScheme->setEnabled(false);
ui->checkBoxShowGrainline->setEnabled(true);
switch(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_AC1006_AAMA:
case LayoutExportFormats::DXF_AC1009_AAMA: case LayoutExportFormats::DXF_AC1009_AAMA:
case LayoutExportFormats::DXF_AC1012_AAMA: case LayoutExportFormats::DXF_AC1012_AAMA:
@ -475,9 +523,11 @@ void DialogSaveManualLayout::ShowExample()
case LayoutExportFormats::DXF_AC1024_ASTM: case LayoutExportFormats::DXF_AC1024_ASTM:
case LayoutExportFormats::DXF_AC1027_ASTM: case LayoutExportFormats::DXF_AC1027_ASTM:
ui->checkBoxBinaryDXF->setEnabled(true); ui->checkBoxBinaryDXF->setEnabled(true);
ui->checkBoxShowGrainline->setEnabled(false);
break; break;
case LayoutExportFormats::RLD: case LayoutExportFormats::RLD:
ui->checkBoxTextAsPaths->setEnabled(false); ui->checkBoxTextAsPaths->setEnabled(false);
ui->checkBoxShowGrainline->setEnabled(false);
break; break;
case LayoutExportFormats::PDFTiled: case LayoutExportFormats::PDFTiled:
ui->checkBoxTilesScheme->setEnabled(true); ui->checkBoxTilesScheme->setEnabled(true);
@ -488,10 +538,21 @@ void DialogSaveManualLayout::ShowExample()
case LayoutExportFormats::EPS: case LayoutExportFormats::EPS:
ui->checkBoxExportUnified->setEnabled(true); ui->checkBoxExportUnified->setEnabled(true);
break; break;
case LayoutExportFormats::NC:
case LayoutExportFormats::OBJ:
ui->checkBoxShowGrainline->setEnabled(false);
break;
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::SVG: case LayoutExportFormats::SVG:
case LayoutExportFormats::PNG: case LayoutExportFormats::PNG:
case LayoutExportFormats::OBJ:
case LayoutExportFormats::NC:
case LayoutExportFormats::TIF: case LayoutExportFormats::TIF:
default: default:
break; break;
@ -580,6 +641,7 @@ void DialogSaveManualLayout::ReadSettings()
{ {
VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
SelectFormat(static_cast<LayoutExportFormats>(settings->GetLayoutExportFormat())); SelectFormat(static_cast<LayoutExportFormats>(settings->GetLayoutExportFormat()));
SetShowGrainline(settings->GetShowGrainline());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -592,4 +654,5 @@ void DialogSaveManualLayout::WriteSettings() const
VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
settings->SetLayoutExportFormat(static_cast<qint8>(Format())); settings->SetLayoutExportFormat(static_cast<qint8>(Format()));
settings->SetShowGrainline(IsShowGrainline());
} }

View File

@ -54,6 +54,9 @@ public:
void SetBinaryDXFFormat(bool binary); void SetBinaryDXFFormat(bool binary);
auto IsBinaryDXFFormat() const -> bool; auto IsBinaryDXFFormat() const -> bool;
void SetShowGrainline(bool show);
auto IsShowGrainline() const -> bool;
void SetDestinationPath(const QString& cmdDestinationPath); void SetDestinationPath(const QString& cmdDestinationPath);
auto IsTextAsPaths() const -> bool; auto IsTextAsPaths() const -> bool;

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>413</width> <width>413</width>
<height>310</height> <height>293</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -111,8 +111,8 @@
<property name="title"> <property name="title">
<string>Options</string> <string>Options</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QFormLayout" name="formLayout">
<item> <item row="0" column="0">
<widget class="QCheckBox" name="checkBoxBinaryDXF"> <widget class="QCheckBox" name="checkBoxBinaryDXF">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -122,17 +122,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QCheckBox" name="checkBoxTextAsPaths">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Text as paths</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxExportUnified"> <widget class="QCheckBox" name="checkBoxExportUnified">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -145,7 +135,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="0">
<widget class="QCheckBox" name="checkBoxShowGrainline">
<property name="text">
<string>Show grainline</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBoxTextAsPaths">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Text as paths</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBoxTilesScheme"> <widget class="QCheckBox" name="checkBoxTilesScheme">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>

View File

@ -43,6 +43,7 @@
#include "../layout/vplayout.h" #include "../layout/vplayout.h"
#include "../layout/vpsheet.h" #include "../layout/vpsheet.h"
#include "../vlayout/vtextmanager.h" #include "../vlayout/vtextmanager.h"
#include "../vlayout/vgraphicsfillitem.h"
#include "../vpapplication.h" #include "../vpapplication.h"
@ -167,6 +168,7 @@ VPGraphicsPiece::VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent)
PaintPiece(); PaintPiece();
InitLabels(); InitLabels();
InitGrainlineItem();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -181,7 +183,6 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF
QPainterPath shape; QPainterPath shape;
shape.addPath(m_seamLine); shape.addPath(m_seamLine);
shape.addPath(m_cuttingLine); shape.addPath(m_cuttingLine);
shape.addPath(m_grainline);
shape.addPath(m_internalPaths); shape.addPath(m_internalPaths);
shape.addPath(m_passmarks); shape.addPath(m_passmarks);
shape.addPath(m_placeLabels); shape.addPath(m_placeLabels);
@ -451,12 +452,45 @@ void VPGraphicsPiece::InitPieceLabel(const QVector<QPointF> &labelShape, const V
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::InitGrainlineItem()
{
delete m_grainlineItem;
VPPiecePtr piece = m_piece.toStrongRef();
if (piece.isNull())
{
return;
}
if(piece->IsGrainlineEnabled())
{
QPainterPath grainline;
QVector<QPointF> grainLinepoints = piece->GetMappedGrainline();
if(!grainLinepoints.isEmpty())
{
grainline.moveTo(ConstFirst(grainLinepoints));
for (int i = 1; i < grainLinepoints.size(); i++)
{
grainline.lineTo(grainLinepoints.at(i));
}
}
m_grainlineItem = new VGraphicsFillItem(this);
m_grainlineItem->setPath(grainline);
VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
QPen pen(PieceColor(), settings->GetLayoutLineWidth(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
m_grainlineItem->SetCustomPen(true);
m_grainlineItem->setPen(pen);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintPiece(QPainter *painter) void VPGraphicsPiece::PaintPiece(QPainter *painter)
{ {
m_seamLine = QPainterPath(); m_seamLine = QPainterPath();
m_cuttingLine = QPainterPath(); m_cuttingLine = QPainterPath();
m_grainline = QPainterPath();
m_internalPaths = QPainterPath(); m_internalPaths = QPainterPath();
m_passmarks = QPainterPath(); m_passmarks = QPainterPath();
m_placeLabels = QPainterPath(); m_placeLabels = QPainterPath();
@ -474,9 +508,6 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter)
// initiliases the cutting line // initiliases the cutting line
PaintCuttingLine(painter, piece); PaintCuttingLine(painter, piece);
// initialises the grainline
PaintGrainline(painter, piece);
// initialises the internal paths // initialises the internal paths
PaintInternalPaths(painter, piece); PaintInternalPaths(painter, piece);
@ -539,35 +570,6 @@ void VPGraphicsPiece::PaintCuttingLine(QPainter *painter, const VPPiecePtr &piec
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintGrainline(QPainter *painter, const VPPiecePtr &piece)
{
if(piece->IsGrainlineEnabled())
{
QVector<QPointF> grainLinepoints = piece->GetMappedGrainline();
if(!grainLinepoints.isEmpty())
{
m_grainline.moveTo(ConstFirst(grainLinepoints));
for (int i = 1; i < grainLinepoints.size(); i++)
{
m_grainline.lineTo(grainLinepoints.at(i));
}
if (painter != nullptr)
{
painter->save();
// here to fill the grainlines arrow. Not wanted for mvp
// later maybe if it's configurable
// painter->setBrush(blackBrush);
painter->setBrush(NoBrush());
painter->drawPath(m_grainline);
painter->restore();
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece) void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece)
{ {
@ -790,6 +792,7 @@ void VPGraphicsPiece::on_RefreshPiece(const VPPiecePtr &piece)
prepareGeometryChange(); prepareGeometryChange();
PaintPiece(); // refresh shapes PaintPiece(); // refresh shapes
InitLabels(); InitLabels();
InitGrainlineItem();
emit PieceTransformationChanged(); emit PieceTransformationChanged();
} }
} }

View File

@ -40,6 +40,7 @@
#endif // QT_VERSION < QT_VERSION_CHECK(5, 13, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
class VTextManager; class VTextManager;
class VGraphicsFillItem;
class VPGraphicsPiece : public QGraphicsObject class VPGraphicsPiece : public QGraphicsObject
{ {
@ -92,7 +93,6 @@ private:
QPainterPath m_cuttingLine{}; QPainterPath m_cuttingLine{};
QPainterPath m_seamLine{}; QPainterPath m_seamLine{};
QPainterPath m_grainline{};
QPainterPath m_internalPaths{}; QPainterPath m_internalPaths{};
QPainterPath m_passmarks{}; QPainterPath m_passmarks{};
QPainterPath m_placeLabels{}; QPainterPath m_placeLabels{};
@ -113,15 +113,16 @@ private:
bool m_hoverMode{false}; bool m_hoverMode{false};
VGraphicsFillItem *m_grainlineItem{nullptr};
QVector<QGraphicsPathItem *> m_labelPathItems{}; QVector<QGraphicsPathItem *> m_labelPathItems{};
QVector<QGraphicsSimpleTextItem *> m_labelTextItems{}; QVector<QGraphicsSimpleTextItem *> m_labelTextItems{};
void InitLabels(); void InitLabels();
void InitPieceLabel(const QVector<QPointF> &labelShape, const VTextManager &tm); void InitPieceLabel(const QVector<QPointF> &labelShape, const VTextManager &tm);
void InitGrainlineItem();
void PaintPiece(QPainter *painter=nullptr); void PaintPiece(QPainter *painter=nullptr);
void PaintSeamLine(QPainter *painter, const VPPiecePtr &piece); void PaintSeamLine(QPainter *painter, const VPPiecePtr &piece);
void PaintCuttingLine(QPainter *painter, const VPPiecePtr &piece); void PaintCuttingLine(QPainter *painter, const VPPiecePtr &piece);
void PaintGrainline(QPainter *painter, const VPPiecePtr &piece);
void PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece); void PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece);
void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece); void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece);
void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece); void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece);

View File

@ -293,6 +293,7 @@ struct VPExportData
bool textAsPaths{false}; bool textAsPaths{false};
bool exportUnified{true}; bool exportUnified{true};
bool showTilesScheme{false}; bool showTilesScheme{false};
bool showGrainline{true};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2376,6 +2377,7 @@ void VPMainWindow::ExportScene(const VPExportData &data)
exporter.SetYScale(data.yScale); exporter.SetYScale(data.yScale);
exporter.SetDescription(m_layout->LayoutSettings().GetDescription()); exporter.SetDescription(m_layout->LayoutSettings().GetDescription());
exporter.SetBinaryDxfFormat(data.isBinaryDXF); exporter.SetBinaryDxfFormat(data.isBinaryDXF);
exporter.SetShowGrainline(data.showGrainline);
QList<VPSheetPtr> sheets = data.sheets; QList<VPSheetPtr> sheets = data.sheets;
@ -2413,17 +2415,17 @@ void VPMainWindow::ExportScene(const VPExportData &data)
case LayoutExportFormats::SVG: case LayoutExportFormats::SVG:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToSVG(sheet->SceneData()->Scene()); exporter.ExportToSVG(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems());
break; break;
case LayoutExportFormats::PDF: case LayoutExportFormats::PDF:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToPDF(sheet->SceneData()->Scene()); exporter.ExportToPDF(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems());
break; break;
case LayoutExportFormats::PNG: case LayoutExportFormats::PNG:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToPNG(sheet->SceneData()->Scene()); exporter.ExportToPNG(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems());
break; break;
case LayoutExportFormats::OBJ: case LayoutExportFormats::OBJ:
exporter.ExportToOBJ(sheet->SceneData()->Scene()); exporter.ExportToOBJ(sheet->SceneData()->Scene());
@ -2431,12 +2433,12 @@ void VPMainWindow::ExportScene(const VPExportData &data)
case LayoutExportFormats::PS: case LayoutExportFormats::PS:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToPS(sheet->SceneData()->Scene()); exporter.ExportToPS(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems());
break; break;
case LayoutExportFormats::EPS: case LayoutExportFormats::EPS:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToEPS(sheet->SceneData()->Scene()); exporter.ExportToEPS(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems());
break; break;
case LayoutExportFormats::DXF_AC1006_Flat: case LayoutExportFormats::DXF_AC1006_Flat:
exporter.SetDxfVersion(DRW::AC1006); exporter.SetDxfVersion(DRW::AC1006);
@ -2477,7 +2479,7 @@ void VPMainWindow::ExportScene(const VPExportData &data)
case LayoutExportFormats::TIF: case LayoutExportFormats::TIF:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToTIF(sheet->SceneData()->Scene()); exporter.ExportToTIF(sheet->SceneData()->Scene(), sheet->SceneData()->GraphicsPiecesAsItems());
break; break;
default: default:
qDebug() << "Can't recognize file type." << Q_FUNC_INFO; qDebug() << "Can't recognize file type." << Q_FUNC_INFO;
@ -2565,11 +2567,12 @@ void VPMainWindow::GenerateUnifiedPdfFile(const VPExportData &data, const QStrin
} }
} }
sheet->SceneData()->PrepareForExport(); sheet->SceneData()->PrepareForExport(); // Go first because recreates pieces
VLayoutExporter::PrepareGrainlineForExport(sheet->SceneData()->GraphicsPiecesAsItems(), data.showGrainline);
QRectF imageRect = sheet->GetMarginsRect(); QRectF imageRect = sheet->GetMarginsRect();
sheet->SceneData()->Scene()->render(&painter, VPrintLayout::SceneTargetRect(printer.data(), imageRect), sheet->SceneData()->Scene()->render(&painter, VPrintLayout::SceneTargetRect(printer.data(), imageRect),
imageRect, Qt::IgnoreAspectRatio); imageRect, Qt::IgnoreAspectRatio);
sheet->SceneData()->CleanAfterExport(); sheet->SceneData()->CleanAfterExport(); // Will restore the grainlines automatically
firstPage = false; firstPage = false;
} }
@ -2602,7 +2605,7 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data)
bool firstPage = true; bool firstPage = true;
for (const auto& sheet : data.sheets) for (const auto& sheet : data.sheets)
{ {
if (not GeneratePdfTiledFile(sheet, data.showTilesScheme, &painter, printer, firstPage)) if (not GeneratePdfTiledFile(sheet, data.showTilesScheme, data.showGrainline, &painter, printer, firstPage))
{ {
break; break;
} }
@ -2620,7 +2623,8 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data)
QPainter painter; QPainter painter;
bool firstPage = true; bool firstPage = true;
if (not GeneratePdfTiledFile(data.sheets.at(i), data.showTilesScheme, &painter, printer, firstPage)) if (not GeneratePdfTiledFile(data.sheets.at(i), data.showTilesScheme, data.showGrainline, &painter, printer,
firstPage))
{ {
break; break;
} }
@ -2629,18 +2633,25 @@ void VPMainWindow::ExportPdfTiledFile(const VPExportData &data)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, QPainter *painter, auto VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, bool showGrainline,
const QSharedPointer<QPrinter> &printer, bool &firstPage) -> bool QPainter *painter, const QSharedPointer<QPrinter> &printer,
bool &firstPage) -> bool
{ {
SCASSERT(not sheet.isNull()) SCASSERT(not sheet.isNull())
SCASSERT(painter != nullptr) SCASSERT(painter != nullptr)
SCASSERT(not printer.isNull()) SCASSERT(not printer.isNull())
sheet->SceneData()->PrepareForExport(); sheet->SceneData()->PrepareForExport(); // Go first because recreates pieces
VLayoutExporter::PrepareGrainlineForExport(sheet->SceneData()->GraphicsPiecesAsItems(), showGrainline);
m_layout->TileFactory()->RefreshTileInfos(); m_layout->TileFactory()->RefreshTileInfos();
m_layout->TileFactory()->RefreshWatermarkData(); m_layout->TileFactory()->RefreshWatermarkData();
sheet->SceneData()->SetTextAsPaths(false); sheet->SceneData()->SetTextAsPaths(false);
auto Clean = qScopeGuard([sheet]()
{
sheet->SceneData()->CleanAfterExport(); // Will restore the grainlines automatically
});
if (showTilesScheme) if (showTilesScheme)
{ {
SetPrinterTiledPageSettings(printer, m_layout, sheet, sheet->GetSheetOrientation(), true); SetPrinterTiledPageSettings(printer, m_layout, sheet, sheet->GetSheetOrientation(), true);
@ -2695,8 +2706,6 @@ auto VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesS
} }
} }
sheet->SceneData()->CleanAfterExport();
return true; return true;
} }
@ -4144,6 +4153,7 @@ void VPMainWindow::on_ExportLayout()
data.textAsPaths = dialog.IsTextAsPaths(); data.textAsPaths = dialog.IsTextAsPaths();
data.exportUnified = dialog.IsExportUnified(); data.exportUnified = dialog.IsExportUnified();
data.showTilesScheme = dialog.IsTilesScheme(); data.showTilesScheme = dialog.IsTilesScheme();
data.showGrainline = dialog.IsShowGrainline();
ExportData(data); ExportData(data);
} }
@ -4194,6 +4204,7 @@ void VPMainWindow::on_ExportSheet()
data.textAsPaths = dialog.IsTextAsPaths(); data.textAsPaths = dialog.IsTextAsPaths();
data.exportUnified = dialog.IsExportUnified(); data.exportUnified = dialog.IsExportUnified();
data.showTilesScheme = dialog.IsTilesScheme(); data.showTilesScheme = dialog.IsTilesScheme();
data.showGrainline = dialog.IsShowGrainline();
ExportData(data); ExportData(data);
} }

View File

@ -479,7 +479,7 @@ private:
static void ExportUnifiedPdfFile(const VPExportData &data); static void ExportUnifiedPdfFile(const VPExportData &data);
static void GenerateUnifiedPdfFile(const VPExportData &data, const QString &name); static void GenerateUnifiedPdfFile(const VPExportData &data, const QString &name);
void ExportPdfTiledFile(const VPExportData &data); void ExportPdfTiledFile(const VPExportData &data);
auto GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, QPainter *painter, auto GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesScheme, bool showGrainline, QPainter *painter,
const QSharedPointer<QPrinter> &printer, bool &firstPage) -> bool; const QSharedPointer<QPrinter> &printer, bool &firstPage) -> bool;
void UpdateScaleConnection() const; void UpdateScaleConnection() const;

View File

@ -54,6 +54,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutFollowGrainline, (QLatin1S
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPieceGap, (QLatin1String("layout/pieceGap"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPieceGap, (QLatin1String("layout/pieceGap"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutExportFormat, (QLatin1String("layout/exportFormat"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutExportFormat, (QLatin1String("layout/exportFormat"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutLineWidth, (QLatin1String("layout/lineWidth"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutLineWidth, (QLatin1String("layout/lineWidth"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutShowGrainline, (QLatin1String("layout/showGrainline"))) // NOLINT
int cachedLineWidth = -1; int cachedLineWidth = -1;
} // namespace } // namespace
@ -340,3 +341,15 @@ void VPSettings::SetLayoutLineWidth(int width)
cachedLineWidth = qBound(1, width, 10); cachedLineWidth = qBound(1, width, 10);
setValue(*settingLayoutLineWidth, cachedLineWidth); setValue(*settingLayoutLineWidth, cachedLineWidth);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VPSettings::GetShowGrainline() const
{
return value(*settingLayoutShowGrainline, true).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VPSettings::SetShowGrainline(bool value)
{
setValue(*settingLayoutShowGrainline, value);
}

View File

@ -103,6 +103,9 @@ public:
auto GetLayoutLineWidth() const -> int; auto GetLayoutLineWidth() const -> int;
void SetLayoutLineWidth(int width); void SetLayoutLineWidth(int width);
bool GetShowGrainline() const;
void SetShowGrainline(bool value);
private: private:
Q_DISABLE_COPY_MOVE(VPSettings) // NOLINT Q_DISABLE_COPY_MOVE(VPSettings) // NOLINT
}; };

View File

@ -277,6 +277,104 @@ auto DialogSaveLayout::IsBinaryDXFFormat() const -> bool
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSaveLayout::SetShowGrainline(bool show)
{
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::SVG:
case LayoutExportFormats::PDF:
case LayoutExportFormats::PDFTiled:
case LayoutExportFormats::PNG:
case LayoutExportFormats::PS:
case LayoutExportFormats::EPS:
case LayoutExportFormats::TIF:
ui->checkBoxShowGrainline->setChecked(show);
break;
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:
case LayoutExportFormats::RLD:
case LayoutExportFormats::NC:
case LayoutExportFormats::OBJ:
default:
ui->checkBoxShowGrainline->setChecked(true);
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
auto DialogSaveLayout::IsShowGrainline() const -> bool
{
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::SVG:
case LayoutExportFormats::PDF:
case LayoutExportFormats::PDFTiled:
case LayoutExportFormats::PNG:
case LayoutExportFormats::PS:
case LayoutExportFormats::EPS:
case LayoutExportFormats::TIF:
return ui->checkBoxShowGrainline->isChecked();
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:
case LayoutExportFormats::RLD:
case LayoutExportFormats::NC:
case LayoutExportFormats::OBJ:
default:
return true;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto DialogSaveLayout::MakeHelpFormatList() -> QString auto DialogSaveLayout::MakeHelpFormatList() -> QString
{ {
@ -414,18 +512,10 @@ void DialogSaveLayout::ShowExample()
ui->groupBoxPaperFormat->setEnabled(false); ui->groupBoxPaperFormat->setEnabled(false);
ui->groupBoxMargins->setEnabled(false); ui->groupBoxMargins->setEnabled(false);
ui->checkBoxTextAsPaths->setEnabled(true); ui->checkBoxTextAsPaths->setEnabled(true);
ui->checkBoxShowGrainline->setEnabled(m_mode == Draw::Layout);
switch(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_AC1006_AAMA:
case LayoutExportFormats::DXF_AC1009_AAMA: case LayoutExportFormats::DXF_AC1009_AAMA:
case LayoutExportFormats::DXF_AC1012_AAMA: case LayoutExportFormats::DXF_AC1012_AAMA:
@ -445,6 +535,7 @@ void DialogSaveLayout::ShowExample()
case LayoutExportFormats::DXF_AC1024_ASTM: case LayoutExportFormats::DXF_AC1024_ASTM:
case LayoutExportFormats::DXF_AC1027_ASTM: case LayoutExportFormats::DXF_AC1027_ASTM:
ui->checkBoxBinaryDXF->setEnabled(true); ui->checkBoxBinaryDXF->setEnabled(true);
ui->checkBoxShowGrainline->setEnabled(false);
break; break;
case LayoutExportFormats::PDFTiled: case LayoutExportFormats::PDFTiled:
ui->groupBoxPaperFormat->setEnabled(true); ui->groupBoxPaperFormat->setEnabled(true);
@ -452,14 +543,26 @@ void DialogSaveLayout::ShowExample()
break; break;
case LayoutExportFormats::RLD: case LayoutExportFormats::RLD:
ui->checkBoxTextAsPaths->setEnabled(false); ui->checkBoxTextAsPaths->setEnabled(false);
ui->checkBoxShowGrainline->setEnabled(false);
break; break;
case LayoutExportFormats::NC:
case LayoutExportFormats::OBJ:
ui->checkBoxShowGrainline->setEnabled(false);
break;
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::SVG: case LayoutExportFormats::SVG:
case LayoutExportFormats::PDF: case LayoutExportFormats::PDF:
case LayoutExportFormats::PNG: case LayoutExportFormats::PNG:
case LayoutExportFormats::OBJ:
case LayoutExportFormats::PS: case LayoutExportFormats::PS:
case LayoutExportFormats::EPS: case LayoutExportFormats::EPS:
case LayoutExportFormats::NC:
case LayoutExportFormats::TIF: case LayoutExportFormats::TIF:
default: default:
break; break;
@ -768,6 +871,7 @@ void DialogSaveLayout::ReadSettings()
else else
{ {
SelectFormat(static_cast<LayoutExportFormats>(settings->GetLayoutExportFormat())); SelectFormat(static_cast<LayoutExportFormats>(settings->GetLayoutExportFormat()));
SetShowGrainline(settings->GetShowGrainline());
} }
} }
@ -819,6 +923,7 @@ void DialogSaveLayout::WriteSettings() const
else else
{ {
settings->SetLayoutExportFormat(static_cast<qint8>(Format())); settings->SetLayoutExportFormat(static_cast<qint8>(Format()));
settings->SetShowGrainline(IsShowGrainline());
} }
} }

View File

@ -56,6 +56,9 @@ public:
void SetBinaryDXFFormat(bool binary); void SetBinaryDXFFormat(bool binary);
auto IsBinaryDXFFormat() const -> bool; auto IsBinaryDXFFormat() const -> bool;
void SetShowGrainline(bool show);
auto IsShowGrainline() const -> bool;
static auto MakeHelpFormatList() -> QString; static auto MakeHelpFormatList() -> QString;
void SetDestinationPath(const QString& cmdDestinationPath); void SetDestinationPath(const QString& cmdDestinationPath);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>493</width> <width>544</width>
<height>391</height> <height>401</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -129,6 +129,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBoxShowGrainline">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Show grainline</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -2523,7 +2523,7 @@ void MainWindow::ExportDraw(const QString &fileName)
exporter.SetImageRect(rect); exporter.SetImageRect(rect);
exporter.SetOffset(rect.topLeft()); // Correct positions to fit SVG view rect exporter.SetOffset(rect.topLeft()); // Correct positions to fit SVG view rect
exporter.ExportToSVG(m_sceneDraw); exporter.ExportToSVG(m_sceneDraw, QList<QGraphicsItem *>());
m_sceneDraw->SetOriginsVisible(true); m_sceneDraw->SetOriginsVisible(true);

View File

@ -1116,6 +1116,7 @@ void MainWindowsNoGUI::ExportScene(const QList<QGraphicsScene *> &scenes,
exporter.SetDescription(doc->GetDescription().toHtmlEscaped()); exporter.SetDescription(doc->GetDescription().toHtmlEscaped());
exporter.SetIgnorePrinterMargins(ignorePrinterFields); exporter.SetIgnorePrinterMargins(ignorePrinterFields);
exporter.SetBinaryDxfFormat(m_dialogSaveLayout->IsBinaryDXFFormat()); exporter.SetBinaryDxfFormat(m_dialogSaveLayout->IsBinaryDXFFormat());
exporter.SetShowGrainline(m_dialogSaveLayout->IsShowGrainline());
for (int i=0; i < scenes.size(); ++i) for (int i=0; i < scenes.size(); ++i)
{ {
@ -1141,18 +1142,18 @@ void MainWindowsNoGUI::ExportScene(const QList<QGraphicsScene *> &scenes,
paper->setVisible(false); paper->setVisible(false);
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToSVG(scene); exporter.ExportToSVG(scene, details.at(i));
paper->setVisible(true); paper->setVisible(true);
break; break;
case LayoutExportFormats::PDF: case LayoutExportFormats::PDF:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToPDF(scene); exporter.ExportToPDF(scene, details.at(i));
break; break;
case LayoutExportFormats::PNG: case LayoutExportFormats::PNG:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToPNG(scene); exporter.ExportToPNG(scene, details.at(i));
break; break;
case LayoutExportFormats::OBJ: case LayoutExportFormats::OBJ:
paper->setVisible(false); paper->setVisible(false);
@ -1162,12 +1163,12 @@ void MainWindowsNoGUI::ExportScene(const QList<QGraphicsScene *> &scenes,
case LayoutExportFormats::PS: case LayoutExportFormats::PS:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToPS(scene); exporter.ExportToPS(scene, details.at(i));
break; break;
case LayoutExportFormats::EPS: case LayoutExportFormats::EPS:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToEPS(scene); exporter.ExportToEPS(scene, details.at(i));
break; break;
case LayoutExportFormats::DXF_AC1006_Flat: case LayoutExportFormats::DXF_AC1006_Flat:
paper->setVisible(false); paper->setVisible(false);
@ -1226,7 +1227,7 @@ void MainWindowsNoGUI::ExportScene(const QList<QGraphicsScene *> &scenes,
case LayoutExportFormats::TIF: case LayoutExportFormats::TIF:
exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(), exporter.SetPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthHairLine(),
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
exporter.ExportToTIF(scene); exporter.ExportToTIF(scene, details.at(i));
break; break;
default: default:
qDebug() << "Can't recognize file type." << Q_FUNC_INFO; qDebug() << "Can't recognize file type." << Q_FUNC_INFO;

View File

@ -44,8 +44,17 @@ void VGraphicsFillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*
Q_UNUSED(widget) Q_UNUSED(widget)
painter->save(); painter->save();
QPen pen = painter->pen(); QPen pen;
pen.setWidthF(width);
if (m_customPen)
{
pen = this->pen();
}
else
{
pen = painter->pen();
pen.setWidthF(width);
}
painter->setPen(pen); painter->setPen(pen);
painter->setBrush(painter->pen().color()); painter->setBrush(painter->pen().color());

View File

@ -32,6 +32,8 @@
#include <QGraphicsPathItem> #include <QGraphicsPathItem>
#include <QPainter> #include <QPainter>
#include "../vmisc/def.h"
class VGraphicsFillItem : public QGraphicsPathItem class VGraphicsFillItem : public QGraphicsPathItem
{ {
public: public:
@ -51,11 +53,18 @@ public:
*/ */
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
int type() const override {return Type;}
enum { Type = UserType + static_cast<int>(Layout::GrainlineItem)};
auto GetWidth() const -> qreal; auto GetWidth() const -> qreal;
void SetWidth(const qreal &value); void SetWidth(const qreal &value);
auto CustomPen() const -> bool;
void SetCustomPen(bool newCustomPen);
private: private:
qreal width{1}; qreal width{1};
bool m_customPen{false};
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -70,4 +79,15 @@ inline void VGraphicsFillItem::SetWidth(const qreal &value)
width = value; width = value;
} }
//---------------------------------------------------------------------------------------------------------------------
inline auto VGraphicsFillItem::CustomPen() const -> bool
{
return m_customPen;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VGraphicsFillItem::SetCustomPen(bool newCustomPen)
{
m_customPen = newCustomPen;
}
#endif // VGRAPHICSFILLITEM_H #endif // VGRAPHICSFILLITEM_H

View File

@ -49,6 +49,7 @@
#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vabstractvalapplication.h"
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "vprintlayout.h" #include "vprintlayout.h"
#include "vgraphicsfillitem.h"
namespace namespace
{ {
@ -67,7 +68,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, PDFTOPS, (QLatin1String("pdftops"))) //
* *
* @param placeholder placeholder that will be appended to each QGraphicsSimpleTextItem item's text string. * @param placeholder placeholder that will be appended to each QGraphicsSimpleTextItem item's text string.
*/ */
void PrepareTextForDXF(const QString &placeholder, const QList<QGraphicsItem *> &paperItems) void PrepareDetailsForDXF(const QString &placeholder, const QList<QGraphicsItem *> &paperItems)
{ {
for (auto *item : paperItems) for (auto *item : paperItems)
{ {
@ -94,7 +95,7 @@ void PrepareTextForDXF(const QString &placeholder, const QList<QGraphicsItem *>
* *
* @param placeholder placeholder that will be removed from each QGraphicsSimpleTextItem item's text string. * @param placeholder placeholder that will be removed from each QGraphicsSimpleTextItem item's text string.
*/ */
void RestoreTextAfterDXF(const QString &placeholder, const QList<QGraphicsItem *> &paperItems) void RestoreDetailsAfterDXF(const QString &placeholder, const QList<QGraphicsItem *> &paperItems)
{ {
for (auto *item : paperItems) for (auto *item : paperItems)
{ {
@ -116,8 +117,22 @@ void RestoreTextAfterDXF(const QString &placeholder, const QList<QGraphicsItem *
} // namespace } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToSVG(QGraphicsScene *scene) const auto VLayoutExporter::IsShowGrainline() const -> bool
{ {
return m_showGrainline;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::SetShowGrainline(bool show)
{
m_showGrainline = show;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToSVG(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const
{
PrepareGrainlineForExport(details, m_showGrainline);
QSvgGenerator generator; QSvgGenerator generator;
generator.setFileName(m_fileName); generator.setFileName(m_fileName);
@ -145,11 +160,15 @@ void VLayoutExporter::ExportToSVG(QGraphicsScene *scene) const
painter.scale(m_xScale, m_yScale); painter.scale(m_xScale, m_yScale);
scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio);
painter.end(); painter.end();
RestoreGrainlineAfterExport(details);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToPNG(QGraphicsScene *scene) const void VLayoutExporter::ExportToPNG(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const
{ {
PrepareGrainlineForExport(details, m_showGrainline);
// Create the image with the exact size of the shrunk scene // Create the image with the exact size of the shrunk scene
QSize drawingSize; QSize drawingSize;
drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right())); drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right()));
@ -167,11 +186,15 @@ void VLayoutExporter::ExportToPNG(QGraphicsScene *scene) const
scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio);
image.save(m_fileName); image.save(m_fileName);
RestoreGrainlineAfterExport(details);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToTIF(QGraphicsScene *scene) const void VLayoutExporter::ExportToTIF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const
{ {
PrepareGrainlineForExport(details, m_showGrainline);
// Create the image with the exact size of the shrunk scene // Create the image with the exact size of the shrunk scene
QSize drawingSize; QSize drawingSize;
drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right())); drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right()));
@ -197,14 +220,17 @@ void VLayoutExporter::ExportToTIF(QGraphicsScene *scene) const
if (not writer.write(image)) if (not writer.write(image))
{ // failed to save file { // failed to save file
qCritical() << qUtf8Printable(tr("Can't save file '%1'. Error: %2.").arg(m_fileName, writer.errorString())); qCritical() << qUtf8Printable(tr("Can't save file '%1'. Error: %2.").arg(m_fileName, writer.errorString()));
RestoreGrainlineAfterExport(details);
return; return;
} }
RestoreGrainlineAfterExport(details);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToPDF(QGraphicsScene *scene) const void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const
{ {
ExportToPDF(scene, m_fileName); ExportToPDF(scene, details, m_fileName);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -222,25 +248,25 @@ void VLayoutExporter::ExportToOBJ(QGraphicsScene *scene) const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToPS(QGraphicsScene *scene) const void VLayoutExporter::ExportToPS(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const
{ {
QTemporaryFile tmp; QTemporaryFile tmp;
if (tmp.open()) if (tmp.open())
{ {
const QString fileName = m_fileName; const QString fileName = m_fileName;
ExportToPDF(scene, tmp.fileName()); ExportToPDF(scene, details, tmp.fileName());
PdfToPs(QStringList{tmp.fileName(), fileName}); PdfToPs(QStringList{tmp.fileName(), fileName});
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToEPS(QGraphicsScene *scene) const void VLayoutExporter::ExportToEPS(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const
{ {
QTemporaryFile tmp; QTemporaryFile tmp;
if (tmp.open()) if (tmp.open())
{ {
const QString fileName = m_fileName; const QString fileName = m_fileName;
ExportToPDF(scene, tmp.fileName()); ExportToPDF(scene, details, tmp.fileName());
PdfToPs(QStringList{QStringLiteral("-eps"), tmp.fileName(), fileName}); PdfToPs(QStringList{QStringLiteral("-eps"), tmp.fileName(), fileName});
} }
} }
@ -248,7 +274,8 @@ void VLayoutExporter::ExportToEPS(QGraphicsScene *scene) const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const
{ {
PrepareTextForDXF(endStringPlaceholder, details); PrepareDetailsForDXF(endStringPlaceholder, details);
PrepareGrainlineForExport(details, m_showGrainline);
VDxfPaintDevice generator; VDxfPaintDevice generator;
generator.SetFileName(m_fileName); generator.SetFileName(m_fileName);
@ -270,7 +297,8 @@ void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QGraphi
} }
} }
RestoreTextAfterDXF(endStringPlaceholder, details); RestoreDetailsAfterDXF(endStringPlaceholder, details);
RestoreGrainlineAfterExport(details);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -411,8 +439,11 @@ void VLayoutExporter::PdfToPs(const QStringList &params)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QString &filename) const void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details,
const QString &filename) const
{ {
PrepareGrainlineForExport(details, m_showGrainline);
QPrinter printer; QPrinter printer;
printer.setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) + printer.setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) +
QCoreApplication::applicationVersion()); QCoreApplication::applicationVersion());
@ -453,6 +484,7 @@ void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QString &filename
if (not painter.begin(&printer)) if (not painter.begin(&printer))
{ // failed to open file { // failed to open file
qCritical() << qUtf8Printable(tr("Can't open file '%1'").arg(m_fileName)); qCritical() << qUtf8Printable(tr("Can't open file '%1'").arg(m_fileName));
RestoreGrainlineAfterExport(details);
return; return;
} }
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
@ -461,6 +493,8 @@ void VLayoutExporter::ExportToPDF(QGraphicsScene *scene, const QString &filename
painter.scale(m_xScale, m_yScale); painter.scale(m_xScale, m_yScale);
scene->render(&painter, VPrintLayout::SceneTargetRect(&printer, m_imageRect), m_imageRect, Qt::IgnoreAspectRatio); scene->render(&painter, VPrintLayout::SceneTargetRect(&printer, m_imageRect), m_imageRect, Qt::IgnoreAspectRatio);
painter.end(); painter.end();
RestoreGrainlineAfterExport(details);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -607,3 +641,35 @@ QString VLayoutExporter::ExportFormatSuffix(LayoutExportFormats format)
return QString(); return QString();
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::PrepareGrainlineForExport(const QList<QGraphicsItem *> &items, bool showGrainline)
{
for (auto *item : items)
{
QList<QGraphicsItem *> pieceChildren = item->childItems();
for (auto *child : qAsConst(pieceChildren))
{
if (child->type() == VGraphicsFillItem::Type)
{
child->setVisible(showGrainline);
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutExporter::RestoreGrainlineAfterExport(const QList<QGraphicsItem *> &items)
{
for (auto *item : items)
{
QList<QGraphicsItem *> pieceChildren = item->childItems();
for (auto *child : qAsConst(pieceChildren))
{
if (child->type() == VGraphicsFillItem::Type)
{
child->setVisible(true);
}
}
}
}

View File

@ -76,16 +76,19 @@ public:
auto BinaryDxfFormat() const -> bool; auto BinaryDxfFormat() const -> bool;
void SetBinaryDxfFormat(bool binaryFormat); void SetBinaryDxfFormat(bool binaryFormat);
auto IsShowGrainline() const -> bool;
void SetShowGrainline(bool show);
auto DxfVersion() const -> int; auto DxfVersion() const -> int;
void SetDxfVersion(int dxfVersion); void SetDxfVersion(int dxfVersion);
void ExportToSVG(QGraphicsScene *scene) const; void ExportToSVG(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const;
void ExportToPNG(QGraphicsScene *scene) const; void ExportToPNG(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const;
void ExportToTIF(QGraphicsScene *scene) const; void ExportToTIF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const;
void ExportToPDF(QGraphicsScene *scene) const; void ExportToPDF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const;
void ExportToOBJ(QGraphicsScene *scene) const; void ExportToOBJ(QGraphicsScene *scene) const;
void ExportToPS(QGraphicsScene *scene) const; void ExportToPS(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const;
void ExportToEPS(QGraphicsScene *scene) const; void ExportToEPS(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const;
void ExportToFlatDXF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const; void ExportToFlatDXF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details) const;
void ExportToAAMADXF(const QVector<VLayoutPiece> &details) const; void ExportToAAMADXF(const QVector<VLayoutPiece> &details) const;
void ExportToASTMDXF(const QVector<VLayoutPiece> &details) const; void ExportToASTMDXF(const QVector<VLayoutPiece> &details) const;
@ -93,10 +96,11 @@ public:
static auto SupportPDFConversion() -> bool; static auto SupportPDFConversion() -> bool;
static QString ExportFormatDescription(LayoutExportFormats format); static QString ExportFormatDescription(LayoutExportFormats format);
static QString ExportFormatSuffix(LayoutExportFormats format); static QString ExportFormatSuffix(LayoutExportFormats format);
static void PdfToPs(const QStringList &params); static void PdfToPs(const QStringList &params);
static void PrepareGrainlineForExport(const QList<QGraphicsItem *> &items, bool showGrainline);
static void RestoreGrainlineAfterExport(const QList<QGraphicsItem *> &items);
auto offset() const -> QPointF; auto offset() const -> QPointF;
void SetOffset(const QPointF &newOffset); void SetOffset(const QPointF &newOffset);
@ -112,10 +116,11 @@ private:
QPen m_pen{}; QPen m_pen{};
bool m_ignorePrinterMargins{false}; bool m_ignorePrinterMargins{false};
bool m_binaryDxfFormat{false}; bool m_binaryDxfFormat{false};
bool m_showGrainline{true};
int m_dxfVersion{0}; int m_dxfVersion{0};
QPointF m_offset{}; QPointF m_offset{};
void ExportToPDF(QGraphicsScene *scene, const QString &filename) const; void ExportToPDF(QGraphicsScene *scene, const QList<QGraphicsItem *> &details, const QString &filename) const;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -274,6 +274,12 @@ enum class Vis : ToolVisHolderType
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
}; };
enum class Layout : ToolVisHolderType
{
GrainlineItem = static_cast<ToolVisHolderType>(Vis::LAST_ONE_DO_NOT_USE),
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
};
enum class VarType : qint8 { Measurement, MeasurementSeparator, Increment, IncrementSeparator, LineLength, CurveLength, enum class VarType : qint8 { Measurement, MeasurementSeparator, Increment, IncrementSeparator, LineLength, CurveLength,
CurveCLength, LineAngle, CurveAngle, ArcRadius, PieceExternalArea, PieceSeamLineArea, CurveCLength, LineAngle, CurveAngle, ArcRadius, PieceExternalArea, PieceSeamLineArea,
Unknown }; Unknown };

View File

@ -77,6 +77,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSaveLength, (QLatin1String
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPreferOneSheetSolution, // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPreferOneSheetSolution, // NOLINT
(QLatin1String("layout/preferOneSheetSolution"))) (QLatin1String("layout/preferOneSheetSolution")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutUnitePages, (QLatin1String("layout/unitePages"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutUnitePages, (QLatin1String("layout/unitePages"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutShowGrainline, (QLatin1String("layout/showGrainline"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFields, (QLatin1String("layout/fields"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFields, (QLatin1String("layout/fields"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIgnoreFields, (QLatin1String("layout/ignoreFields"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingIgnoreFields, (QLatin1String("layout/ignoreFields"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingStripOptimization, (QLatin1String("layout/stripOptimization"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingStripOptimization, (QLatin1String("layout/stripOptimization"))) // NOLINT
@ -971,6 +972,18 @@ void VValentinaSettings::SetBackgroundImageDefOpacity(int value)
setValue(*settingPatternBackgroundImageDefOpacity, qBound(0, value, 100)); setValue(*settingPatternBackgroundImageDefOpacity, qBound(0, value, 100));
} }
//---------------------------------------------------------------------------------------------------------------------
bool VValentinaSettings::GetShowGrainline() const
{
return value(*settingLayoutShowGrainline, true).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VValentinaSettings::SetShowGrainline(bool value)
{
setValue(*settingLayoutShowGrainline, value);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template<typename T> template<typename T>
T VValentinaSettings::GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const T VValentinaSettings::GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const

View File

@ -235,6 +235,9 @@ public:
auto GetBackgroundImageDefOpacity() const -> int; auto GetBackgroundImageDefOpacity() const -> int;
void SetBackgroundImageDefOpacity(int value); void SetBackgroundImageDefOpacity(int value);
bool GetShowGrainline() const;
void SetShowGrainline(bool value);
private: private:
Q_DISABLE_COPY_MOVE(VValentinaSettings) // NOLINT Q_DISABLE_COPY_MOVE(VValentinaSettings) // NOLINT