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.
|
||||
- Remember last selected export format.
|
||||
- [smart-pattern/valentina#123] Error inside Save layout dialog.
|
||||
- Improve error handling for the dxf export.
|
||||
|
||||
# Version 0.7.46 Mar 31, 2021
|
||||
- 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){
|
||||
//complete copy of header vars:
|
||||
data = cData.headerC;
|
||||
|
|
|
@ -101,6 +101,8 @@ public:
|
|||
bool fileExport(bool binary);
|
||||
void writeEntity(DRW_Entity* e);
|
||||
|
||||
std::string ErrorString() const;
|
||||
|
||||
//reimplement virtual DRW_Interface functions
|
||||
//writer part, send all in class dx_data to writer
|
||||
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 isOk = false;
|
||||
std::ofstream filestr;
|
||||
filestr.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
version = ver;
|
||||
binFile = bin;
|
||||
iface = interface_;
|
||||
try
|
||||
{
|
||||
if (binFile) {
|
||||
filestr.open (fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc);
|
||||
//write sentinel
|
||||
|
@ -172,6 +175,14 @@ bool dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin){
|
|||
writer->writeString(0, "EOF");
|
||||
filestr.flush();
|
||||
filestr.close();
|
||||
}
|
||||
catch(std::ofstream::failure &writeErr)
|
||||
{
|
||||
errorString = writeErr.what();
|
||||
delete writer;
|
||||
writer = nullptr;
|
||||
return isOk;
|
||||
}
|
||||
isOk = true;
|
||||
delete writer;
|
||||
writer = nullptr;
|
||||
|
@ -1160,6 +1171,11 @@ bool dxfRW::writeDimension(DRW_Dimension *ent) {
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string dxfRW::ErrorString() const
|
||||
{
|
||||
return errorString;
|
||||
}
|
||||
|
||||
bool dxfRW::writeInsert(DRW_Insert *ent){
|
||||
writer->writeString(0, "INSERT");
|
||||
writeEntity(ent);
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
bool writeDimension(DRW_Dimension *ent);
|
||||
void setEllipseParts(int parts){elParts = parts;} /*!< set parts munber when convert ellipse to polyline */
|
||||
|
||||
std::string ErrorString() const;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(dxfRW)
|
||||
/// used by read() to parse the content of the file
|
||||
|
@ -144,6 +146,7 @@ private:
|
|||
|
||||
int currHandle;
|
||||
|
||||
std::string errorString{};
|
||||
};
|
||||
|
||||
#endif // LIBDXFRW_H
|
||||
|
|
|
@ -138,8 +138,7 @@ bool VDxfEngine::begin(QPaintDevice *pdev)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VDxfEngine::end()
|
||||
{
|
||||
const bool res = input->fileExport(m_binary);
|
||||
return res;
|
||||
return input->fileExport(m_binary);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -611,6 +610,12 @@ void VDxfEngine::SetYScale(const qreal &yscale)
|
|||
m_yscale = yscale;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VDxfEngine::ErrorString() const
|
||||
{
|
||||
return QString::fromStdString(input->ErrorString());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_GCC("-Wswitch-default")
|
||||
|
@ -668,7 +673,7 @@ bool VDxfEngine::ExportToAAMA(const QVector<VLayoutPiece> &details)
|
|||
|
||||
for(auto detail : details)
|
||||
{
|
||||
dx_ifaceBlock *detailBlock = new dx_ifaceBlock();
|
||||
auto *detailBlock = new dx_ifaceBlock();
|
||||
|
||||
QString blockName = detail.GetName();
|
||||
if (m_version <= DRW::AC1009)
|
||||
|
@ -691,7 +696,7 @@ bool VDxfEngine::ExportToAAMA(const QVector<VLayoutPiece> &details)
|
|||
|
||||
input->AddBlock(detailBlock);
|
||||
|
||||
DRW_Insert *insert = new DRW_Insert();
|
||||
auto *insert = new DRW_Insert();
|
||||
insert->name = blockName.toStdString();
|
||||
insert->layer = '1';
|
||||
|
||||
|
@ -869,7 +874,7 @@ bool VDxfEngine::ExportToASTM(const QVector<VLayoutPiece> &details)
|
|||
|
||||
for(auto detail : details)
|
||||
{
|
||||
dx_ifaceBlock *detailBlock = new dx_ifaceBlock();
|
||||
auto *detailBlock = new dx_ifaceBlock();
|
||||
|
||||
QString blockName = detail.GetName();
|
||||
if (m_version <= DRW::AC1009)
|
||||
|
@ -894,7 +899,7 @@ bool VDxfEngine::ExportToASTM(const QVector<VLayoutPiece> &details)
|
|||
|
||||
input->AddBlock(detailBlock);
|
||||
|
||||
DRW_Insert *insert = new DRW_Insert();
|
||||
auto *insert = new DRW_Insert();
|
||||
insert->name = blockName.toStdString();
|
||||
insert->layer = '1';
|
||||
|
||||
|
|
|
@ -98,6 +98,8 @@ public:
|
|||
qreal GetYScale() const;
|
||||
void SetYScale(const qreal &yscale);
|
||||
|
||||
QString ErrorString() const;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VDxfEngine)
|
||||
QSize size;
|
||||
|
|
|
@ -214,6 +214,12 @@ bool VDxfPaintDevice::ExportToASTM(const QVector<VLayoutPiece> &details) const
|
|||
return res;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VDxfPaintDevice::ErrorString() const
|
||||
{
|
||||
return engine->ErrorString();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
|
||||
{
|
||||
|
|
|
@ -75,6 +75,8 @@ public:
|
|||
bool ExportToAAMA(const QVector<VLayoutPiece> &details) const;
|
||||
bool ExportToASTM(const QVector<VLayoutPiece> &details) const;
|
||||
|
||||
QString ErrorString() const;
|
||||
|
||||
protected:
|
||||
virtual int metric(PaintDeviceMetric metric) const override;
|
||||
private:
|
||||
|
|
|
@ -301,7 +301,11 @@ void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QList<Q
|
|||
{
|
||||
painter.scale(m_xScale, m_yScale);
|
||||
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);
|
||||
|
@ -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.SetXScale(m_xScale);
|
||||
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.SetXScale(m_xScale);
|
||||
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