Improve error handling for the dxf export.
This commit is contained in:
parent
a2d7446308
commit
613502b392
|
@ -7,6 +7,7 @@
|
||||||
- [smart-pattern/valentina#122] Extend piece bounding rect.
|
- [smart-pattern/valentina#122] Extend piece bounding rect.
|
||||||
- Remember last selected export format.
|
- Remember last selected export format.
|
||||||
- [smart-pattern/valentina#123] Error inside Save layout dialog.
|
- [smart-pattern/valentina#123] Error inside Save layout dialog.
|
||||||
|
- Improve error handling for the dxf export.
|
||||||
|
|
||||||
# Version 0.7.46 Mar 31, 2021
|
# Version 0.7.46 Mar 31, 2021
|
||||||
- Fix incorrect calculation of value for multisize measurements in Valentina.
|
- Fix incorrect calculation of value for multisize measurements in Valentina.
|
||||||
|
|
|
@ -110,6 +110,11 @@ void dx_iface::writeEntity(DRW_Entity* e){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string dx_iface::ErrorString() const
|
||||||
|
{
|
||||||
|
return dxfW->ErrorString();
|
||||||
|
}
|
||||||
|
|
||||||
void dx_iface::writeHeader(DRW_Header &data){
|
void dx_iface::writeHeader(DRW_Header &data){
|
||||||
//complete copy of header vars:
|
//complete copy of header vars:
|
||||||
data = cData.headerC;
|
data = cData.headerC;
|
||||||
|
|
|
@ -101,6 +101,8 @@ public:
|
||||||
bool fileExport(bool binary);
|
bool fileExport(bool binary);
|
||||||
void writeEntity(DRW_Entity* e);
|
void writeEntity(DRW_Entity* e);
|
||||||
|
|
||||||
|
std::string ErrorString() const;
|
||||||
|
|
||||||
//reimplement virtual DRW_Interface functions
|
//reimplement virtual DRW_Interface functions
|
||||||
//writer part, send all in class dx_data to writer
|
//writer part, send all in class dx_data to writer
|
||||||
virtual void writeHeader(DRW_Header& data) override;
|
virtual void writeHeader(DRW_Header& data) override;
|
||||||
|
|
|
@ -123,9 +123,12 @@ bool dxfRW::read(DRW_Interface *interface_, bool ext){
|
||||||
bool dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin){
|
bool dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin){
|
||||||
bool isOk = false;
|
bool isOk = false;
|
||||||
std::ofstream filestr;
|
std::ofstream filestr;
|
||||||
|
filestr.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
version = ver;
|
version = ver;
|
||||||
binFile = bin;
|
binFile = bin;
|
||||||
iface = interface_;
|
iface = interface_;
|
||||||
|
try
|
||||||
|
{
|
||||||
if (binFile) {
|
if (binFile) {
|
||||||
filestr.open (fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc);
|
filestr.open (fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc);
|
||||||
//write sentinel
|
//write sentinel
|
||||||
|
@ -172,6 +175,14 @@ bool dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin){
|
||||||
writer->writeString(0, "EOF");
|
writer->writeString(0, "EOF");
|
||||||
filestr.flush();
|
filestr.flush();
|
||||||
filestr.close();
|
filestr.close();
|
||||||
|
}
|
||||||
|
catch(std::ofstream::failure &writeErr)
|
||||||
|
{
|
||||||
|
errorString = writeErr.what();
|
||||||
|
delete writer;
|
||||||
|
writer = nullptr;
|
||||||
|
return isOk;
|
||||||
|
}
|
||||||
isOk = true;
|
isOk = true;
|
||||||
delete writer;
|
delete writer;
|
||||||
writer = nullptr;
|
writer = nullptr;
|
||||||
|
@ -1160,6 +1171,11 @@ bool dxfRW::writeDimension(DRW_Dimension *ent) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string dxfRW::ErrorString() const
|
||||||
|
{
|
||||||
|
return errorString;
|
||||||
|
}
|
||||||
|
|
||||||
bool dxfRW::writeInsert(DRW_Insert *ent){
|
bool dxfRW::writeInsert(DRW_Insert *ent){
|
||||||
writer->writeString(0, "INSERT");
|
writer->writeString(0, "INSERT");
|
||||||
writeEntity(ent);
|
writeEntity(ent);
|
||||||
|
|
|
@ -72,6 +72,8 @@ public:
|
||||||
bool writeDimension(DRW_Dimension *ent);
|
bool writeDimension(DRW_Dimension *ent);
|
||||||
void setEllipseParts(int parts){elParts = parts;} /*!< set parts munber when convert ellipse to polyline */
|
void setEllipseParts(int parts){elParts = parts;} /*!< set parts munber when convert ellipse to polyline */
|
||||||
|
|
||||||
|
std::string ErrorString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(dxfRW)
|
Q_DISABLE_COPY(dxfRW)
|
||||||
/// used by read() to parse the content of the file
|
/// used by read() to parse the content of the file
|
||||||
|
@ -144,6 +146,7 @@ private:
|
||||||
|
|
||||||
int currHandle;
|
int currHandle;
|
||||||
|
|
||||||
|
std::string errorString{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIBDXFRW_H
|
#endif // LIBDXFRW_H
|
||||||
|
|
|
@ -138,8 +138,7 @@ bool VDxfEngine::begin(QPaintDevice *pdev)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VDxfEngine::end()
|
bool VDxfEngine::end()
|
||||||
{
|
{
|
||||||
const bool res = input->fileExport(m_binary);
|
return input->fileExport(m_binary);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -611,6 +610,12 @@ void VDxfEngine::SetYScale(const qreal &yscale)
|
||||||
m_yscale = yscale;
|
m_yscale = yscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VDxfEngine::ErrorString() const
|
||||||
|
{
|
||||||
|
return QString::fromStdString(input->ErrorString());
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QT_WARNING_PUSH
|
QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_GCC("-Wswitch-default")
|
QT_WARNING_DISABLE_GCC("-Wswitch-default")
|
||||||
|
@ -668,7 +673,7 @@ bool VDxfEngine::ExportToAAMA(const QVector<VLayoutPiece> &details)
|
||||||
|
|
||||||
for(auto detail : details)
|
for(auto detail : details)
|
||||||
{
|
{
|
||||||
dx_ifaceBlock *detailBlock = new dx_ifaceBlock();
|
auto *detailBlock = new dx_ifaceBlock();
|
||||||
|
|
||||||
QString blockName = detail.GetName();
|
QString blockName = detail.GetName();
|
||||||
if (m_version <= DRW::AC1009)
|
if (m_version <= DRW::AC1009)
|
||||||
|
@ -691,7 +696,7 @@ bool VDxfEngine::ExportToAAMA(const QVector<VLayoutPiece> &details)
|
||||||
|
|
||||||
input->AddBlock(detailBlock);
|
input->AddBlock(detailBlock);
|
||||||
|
|
||||||
DRW_Insert *insert = new DRW_Insert();
|
auto *insert = new DRW_Insert();
|
||||||
insert->name = blockName.toStdString();
|
insert->name = blockName.toStdString();
|
||||||
insert->layer = '1';
|
insert->layer = '1';
|
||||||
|
|
||||||
|
@ -869,7 +874,7 @@ bool VDxfEngine::ExportToASTM(const QVector<VLayoutPiece> &details)
|
||||||
|
|
||||||
for(auto detail : details)
|
for(auto detail : details)
|
||||||
{
|
{
|
||||||
dx_ifaceBlock *detailBlock = new dx_ifaceBlock();
|
auto *detailBlock = new dx_ifaceBlock();
|
||||||
|
|
||||||
QString blockName = detail.GetName();
|
QString blockName = detail.GetName();
|
||||||
if (m_version <= DRW::AC1009)
|
if (m_version <= DRW::AC1009)
|
||||||
|
@ -894,7 +899,7 @@ bool VDxfEngine::ExportToASTM(const QVector<VLayoutPiece> &details)
|
||||||
|
|
||||||
input->AddBlock(detailBlock);
|
input->AddBlock(detailBlock);
|
||||||
|
|
||||||
DRW_Insert *insert = new DRW_Insert();
|
auto *insert = new DRW_Insert();
|
||||||
insert->name = blockName.toStdString();
|
insert->name = blockName.toStdString();
|
||||||
insert->layer = '1';
|
insert->layer = '1';
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,8 @@ public:
|
||||||
qreal GetYScale() const;
|
qreal GetYScale() const;
|
||||||
void SetYScale(const qreal &yscale);
|
void SetYScale(const qreal &yscale);
|
||||||
|
|
||||||
|
QString ErrorString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VDxfEngine)
|
Q_DISABLE_COPY(VDxfEngine)
|
||||||
QSize size;
|
QSize size;
|
||||||
|
|
|
@ -214,6 +214,12 @@ bool VDxfPaintDevice::ExportToASTM(const QVector<VLayoutPiece> &details) const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString VDxfPaintDevice::ErrorString() const
|
||||||
|
{
|
||||||
|
return engine->ErrorString();
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
int VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
|
int VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,6 +75,8 @@ public:
|
||||||
bool ExportToAAMA(const QVector<VLayoutPiece> &details) const;
|
bool ExportToAAMA(const QVector<VLayoutPiece> &details) const;
|
||||||
bool ExportToASTM(const QVector<VLayoutPiece> &details) const;
|
bool ExportToASTM(const QVector<VLayoutPiece> &details) const;
|
||||||
|
|
||||||
|
QString ErrorString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int metric(PaintDeviceMetric metric) const override;
|
virtual int metric(PaintDeviceMetric metric) const override;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -301,7 +301,11 @@ void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QList<Q
|
||||||
{
|
{
|
||||||
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();
|
if (not painter.end())
|
||||||
|
{
|
||||||
|
qCritical() << tr("Can't create an flat dxf file.")
|
||||||
|
<< generator.ErrorString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RestoreTextAfterDXF(endStringPlaceholder, details);
|
RestoreTextAfterDXF(endStringPlaceholder, details);
|
||||||
|
@ -319,7 +323,11 @@ void VLayoutExporter::ExportToAAMADXF(const QVector<VLayoutPiece> &details) cons
|
||||||
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
|
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
|
||||||
generator.SetXScale(m_xScale);
|
generator.SetXScale(m_xScale);
|
||||||
generator.SetYScale(m_yScale);
|
generator.SetYScale(m_yScale);
|
||||||
generator.ExportToAAMA(details);
|
if (not generator.ExportToAAMA(details))
|
||||||
|
{
|
||||||
|
qCritical() << tr("Can't create an AAMA dxf file.")
|
||||||
|
<< generator.ErrorString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -334,7 +342,11 @@ void VLayoutExporter::ExportToASTMDXF(const QVector<VLayoutPiece> &details) cons
|
||||||
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
|
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
|
||||||
generator.SetXScale(m_xScale);
|
generator.SetXScale(m_xScale);
|
||||||
generator.SetYScale(m_yScale);
|
generator.SetYScale(m_yScale);
|
||||||
generator.ExportToASTM(details);
|
if (not generator.ExportToASTM(details))
|
||||||
|
{
|
||||||
|
qCritical() << tr("Can't create an ASTM dxf file.")
|
||||||
|
<< generator.ErrorString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user