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,75 +109,87 @@ auto dxfRW::read(DRW_Interface *interface_, bool ext) -> bool
auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool
{ {
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
filestr << "AutoCAD Binary DXF\r\n" << static_cast<char>(26) << '\0';
writer = std::make_unique<dxfWriterBinary>(&filestr);
DRW_DBG("dxfRW::read binary file\n");
}
else
{
filestr.open(fileName.c_str(), std::ios_base::out | std::ios::trunc);
writer = std::make_unique<dxfWriterAscii>(&filestr);
std::string comm = std::string("dxfrw ") + std::string(DRW_VERSION);
writer->writeString(999, comm);
}
this->header = DRW_Header();
iface->writeHeader(header);
writer->writeString(0, "SECTION");
entCount = FIRSTHANDLE;
header.write(writer, version);
writer->writeString(0, "ENDSEC");
if (ver > DRW::AC1009)
{
writer->writeString(0, "SECTION");
writer->writeString(2, "CLASSES");
writer->writeString(0, "ENDSEC");
}
writer->writeString(0, "SECTION");
writer->writeString(2, "TABLES");
writeTables();
writer->writeString(0, "ENDSEC");
writer->writeString(0, "SECTION");
writer->writeString(2, "BLOCKS");
writeBlocks();
writer->writeString(0, "ENDSEC");
writer->writeString(0, "SECTION"); if (!filestr.is_open())
writer->writeString(2, "ENTITIES");
iface->writeEntities();
writer->writeString(0, "ENDSEC");
if (version > DRW::AC1009)
{ {
writer->writeString(0, "SECTION"); errorString = "Error opening file!";
writer->writeString(2, "OBJECTS"); writer.reset();
writeObjects(); return false;
writer->writeString(0, "ENDSEC");
} }
writer->writeString(0, "EOF");
filestr.flush(); // write sentinel
filestr.close(); filestr << "AutoCAD Binary DXF\r\n" << static_cast<char>(26) << '\0';
writer = std::make_unique<dxfWriterBinary>(&filestr);
DRW_DBG("dxfRW::read binary file\n");
} }
catch (std::ofstream::failure &writeErr) else
{ {
errorString = writeErr.what(); filestr.open(fileName.c_str(), std::ios_base::out | std::ios::trunc);
writer.reset();
return isOk; if (!filestr.is_open())
{
errorString = "Error opening file!";
writer.reset();
return false;
}
writer = std::make_unique<dxfWriterAscii>(&filestr);
std::string const comm = std::string("dxfrw ") + std::string(DRW_VERSION);
writer->writeString(999, comm);
} }
isOk = true;
this->header = DRW_Header();
iface->writeHeader(header);
writer->writeString(0, "SECTION");
entCount = FIRSTHANDLE;
header.write(writer, version);
writer->writeString(0, "ENDSEC");
if (ver > DRW::AC1009)
{
writer->writeString(0, "SECTION");
writer->writeString(2, "CLASSES");
writer->writeString(0, "ENDSEC");
}
writer->writeString(0, "SECTION");
writer->writeString(2, "TABLES");
writeTables();
writer->writeString(0, "ENDSEC");
writer->writeString(0, "SECTION");
writer->writeString(2, "BLOCKS");
writeBlocks();
writer->writeString(0, "ENDSEC");
writer->writeString(0, "SECTION");
writer->writeString(2, "ENTITIES");
iface->writeEntities();
writer->writeString(0, "ENDSEC");
if (version > DRW::AC1009)
{
writer->writeString(0, "SECTION");
writer->writeString(2, "OBJECTS");
writeObjects();
writer->writeString(0, "ENDSEC");
}
writer->writeString(0, "EOF");
filestr.flush();
if (filestr.fail())
{
errorString = "Error writing to file!";
return false;
}
filestr.close();
writer.reset(); writer.reset();
return isOk; return true;
} }
auto dxfRW::writeEntity(DRW_Entity *ent) -> bool auto dxfRW::writeEntity(DRW_Entity *ent) -> bool