Refactoring.

Code style.
This commit is contained in:
Roman Telezhynskyi 2023-11-20 13:28:31 +02:00
parent f5256c514c
commit 348b7c4e8a
3 changed files with 167 additions and 155 deletions

View File

@ -10,14 +10,15 @@
******************************************************************************/ ******************************************************************************/
#include "dxiface.h" #include "dxiface.h"
#include "libdxfrw/libdxfrw.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "libdxfrw/libdxfrw.h"
#include "vdxf/libdxfrw/drw_entities.h"
#include <iostream>
#include <algorithm>
#include <QDateTime> #include <QDateTime>
#include <QFont> #include <QFont>
#include <QLocale> #include <QLocale>
#include <algorithm>
#include <iostream>
dx_iface::dx_iface(const std::string &file, DRW::Version v, VarMeasurement varMeasurement, VarInsunits varInsunits) dx_iface::dx_iface(const std::string &file, DRW::Version v, VarMeasurement varMeasurement, VarInsunits varInsunits)
: dxfW(new dxfRW(file.c_str())), : dxfW(new dxfRW(file.c_str())),
@ -41,8 +42,10 @@ auto dx_iface::fileExport(bool binary) -> bool
return success; return success;
} }
void dx_iface::writeEntity(DRW_Entity* e){ void dx_iface::writeEntity(DRW_Entity *e)
switch (e->eType) { {
switch (e->eType)
{
case DRW::POINT: case DRW::POINT:
dxfW->writePoint(static_cast<DRW_Point *>(e)); dxfW->writePoint(static_cast<DRW_Point *>(e));
break; break;
@ -115,7 +118,8 @@ auto dx_iface::ErrorString() const -> std::string
return dxfW->ErrorString(); 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;
// or copy one by one: // or copy one by one:
@ -123,9 +127,11 @@ void dx_iface::writeHeader(DRW_Header &data){
// data.vars[it->first] = new DRW_Variant( *(it->second) ); // data.vars[it->first] = new DRW_Variant( *(it->second) );
} }
void dx_iface::writeBlocks(){ void dx_iface::writeBlocks()
{
// write each block // write each block
for (auto *bk : cData.blocks){ for (auto *bk : cData.blocks)
{
dxfW->writeBlock(bk); dxfW->writeBlock(bk);
// and write each entity in block // and write each entity in block
for (std::list<DRW_Entity *>::const_iterator it = bk->ent.begin(); it != bk->ent.end(); ++it) for (std::list<DRW_Entity *>::const_iterator it = bk->ent.begin(); it != bk->ent.end(); ++it)
@ -133,37 +139,44 @@ void dx_iface::writeBlocks(){
} }
} }
void dx_iface::writeBlockRecords(){ void dx_iface::writeBlockRecords()
{
for (std::list<dx_ifaceBlock *>::iterator it = cData.blocks.begin(); it != cData.blocks.end(); ++it) for (std::list<dx_ifaceBlock *>::iterator it = cData.blocks.begin(); it != cData.blocks.end(); ++it)
dxfW->writeBlockRecord((*it)->name); dxfW->writeBlockRecord((*it)->name);
} }
void dx_iface::writeEntities(){ void dx_iface::writeEntities()
{
for (std::list<DRW_Entity *>::const_iterator it = cData.mBlock->ent.begin(); it != cData.mBlock->ent.end(); ++it) for (std::list<DRW_Entity *>::const_iterator it = cData.mBlock->ent.begin(); it != cData.mBlock->ent.end(); ++it)
writeEntity(*it); writeEntity(*it);
} }
void dx_iface::writeLTypes(){ void dx_iface::writeLTypes()
{
for (std::list<DRW_LType>::iterator it = cData.lineTypes.begin(); it != cData.lineTypes.end(); ++it) for (std::list<DRW_LType>::iterator it = cData.lineTypes.begin(); it != cData.lineTypes.end(); ++it)
dxfW->writeLineType(&(*it)); dxfW->writeLineType(&(*it));
} }
void dx_iface::writeLayers(){ void dx_iface::writeLayers()
{
for (std::list<DRW_Layer>::iterator it = cData.layers.begin(); it != cData.layers.end(); ++it) for (std::list<DRW_Layer>::iterator it = cData.layers.begin(); it != cData.layers.end(); ++it)
dxfW->writeLayer(&(*it)); dxfW->writeLayer(&(*it));
} }
void dx_iface::writeTextstyles(){ void dx_iface::writeTextstyles()
{
for (std::list<DRW_Textstyle>::iterator it = cData.textStyles.begin(); it != cData.textStyles.end(); ++it) for (std::list<DRW_Textstyle>::iterator it = cData.textStyles.begin(); it != cData.textStyles.end(); ++it)
dxfW->writeTextstyle(&(*it)); dxfW->writeTextstyle(&(*it));
} }
void dx_iface::writeVports(){ void dx_iface::writeVports()
{
for (std::list<DRW_Vport>::iterator it = cData.VPorts.begin(); it != cData.VPorts.end(); ++it) for (std::list<DRW_Vport>::iterator it = cData.VPorts.begin(); it != cData.VPorts.end(); ++it)
dxfW->writeVport(&(*it)); dxfW->writeVport(&(*it));
} }
void dx_iface::writeDimstyles(){ void dx_iface::writeDimstyles()
{
for (std::list<DRW_Dimstyle>::iterator it = cData.dimStyles.begin(); it != cData.dimStyles.end(); ++it) for (std::list<DRW_Dimstyle>::iterator it = cData.dimStyles.begin(); it != cData.dimStyles.end(); ++it)
dxfW->writeDimstyle(&(*it)); dxfW->writeDimstyle(&(*it));
} }
@ -173,7 +186,8 @@ void dx_iface::writeObjects()
// default implementation for new DRW_Interface method // default implementation for new DRW_Interface method
} }
void dx_iface::writeAppId(){ void dx_iface::writeAppId()
{
for (auto it = cData.appIds.begin(); it != cData.appIds.end(); ++it) for (auto it = cData.appIds.begin(); it != cData.appIds.end(); ++it)
dxfW->writeAppId(&(*it)); dxfW->writeAppId(&(*it));
} }
@ -483,6 +497,6 @@ void dx_iface::AddBlock(dx_ifaceBlock *block)
auto dx_iface::LocaleToISO() -> std::string auto dx_iface::LocaleToISO() -> std::string
{ {
QMap<QString, QString> locMap = LocaleMap(); QMap<QString, QString> locMap = LocaleMap();
return locMap.value(QLocale(VAbstractApplication::VApp()->Settings()->GetLocale()).name(), return locMap.value(QLocale(VAbstractApplication::VApp()->Settings()->GetLocale()).name(), "ISO8859-1")
"ISO8859-1").toStdString(); .toStdString();
} }

View File

@ -1348,10 +1348,8 @@ auto DRW_Viewport::parseCode(int code, const std::unique_ptr<dxfReader> &reader)
vpID = reader->getInt32(); vpID = reader->getInt32();
break; break;
case 12: case 12:
{
centerPX = reader->getDouble(); centerPX = reader->getDouble();
break; break;
}
case 22: case 22:
centerPY = reader->getDouble(); centerPY = reader->getDouble();
break; break;

View File

@ -55,7 +55,7 @@ public:
auto getDouble() const -> double { return doubleData; } auto getDouble() const -> double { return doubleData; }
auto getInt32() const -> int { return intData; } auto getInt32() const -> int { return intData; }
auto getInt64() const -> unsigned long long int { return int64; } auto getInt64() const -> unsigned long long int { return int64; }
auto getBool() const -> bool { return (intData == 0) ? false : true; } auto getBool() const -> bool { return intData != 0; }
auto getVersion() const -> int { return decoder.getVersion(); } auto getVersion() const -> int { return decoder.getVersion(); }
void setVersion(const std::string &v, bool dxfFormat) { decoder.setVersion(v, dxfFormat); } void setVersion(const std::string &v, bool dxfFormat) { decoder.setVersion(v, dxfFormat); }
void setCodePage(const std::string &c) { decoder.setCodePage(c, true); } void setCodePage(const std::string &c) { decoder.setCodePage(c, true); }