Fix export to DXF AAMA/ASTM on Windows with Qt 6.

This commit is contained in:
Roman Telezhynskyi 2024-01-16 20:12:41 +02:00
parent ad20f93085
commit 4f7c9fd59b

View File

@ -109,17 +109,21 @@ auto dxfRW::read(DRW_Interface *interface_, bool ext) -> bool
auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool
{
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);
if (!filestr.is_open())
{
errorString = "Error opening file!";
writer.reset();
return false;
}
// write sentinel
filestr << "AutoCAD Binary DXF\r\n" << static_cast<char>(26) << '\0';
writer = std::make_unique<dxfWriterBinary>(&filestr);
@ -128,10 +132,19 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool
else
{
filestr.open(fileName.c_str(), std::ios_base::out | std::ios::trunc);
if (!filestr.is_open())
{
errorString = "Error opening file!";
writer.reset();
return false;
}
writer = std::make_unique<dxfWriterAscii>(&filestr);
std::string comm = std::string("dxfrw ") + std::string(DRW_VERSION);
std::string const comm = std::string("dxfrw ") + std::string(DRW_VERSION);
writer->writeString(999, comm);
}
this->header = DRW_Header();
iface->writeHeader(header);
writer->writeString(0, "SECTION");
@ -167,17 +180,16 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool
}
writer->writeString(0, "EOF");
filestr.flush();
filestr.close();
}
catch (std::ofstream::failure &writeErr)
if (filestr.fail())
{
errorString = writeErr.what();
writer.reset();
return isOk;
errorString = "Error writing to file!";
return false;
}
isOk = true;
filestr.close();
writer.reset();
return isOk;
return true;
}
auto dxfRW::writeEntity(DRW_Entity *ent) -> bool