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,19 +10,20 @@
******************************************************************************/ ******************************************************************************/
#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())),
cData(), cData(),
version(v) version(v)
{ {
InitHeader(varMeasurement, varInsunits); InitHeader(varMeasurement, varInsunits);
InitTextstyles(); InitTextstyles();
@ -41,72 +42,74 @@ 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) { {
case DRW::POINT: switch (e->eType)
dxfW->writePoint(static_cast<DRW_Point*>(e)); {
break; case DRW::POINT:
case DRW::ASTMNOTCH: dxfW->writePoint(static_cast<DRW_Point *>(e));
dxfW->writeASTMNotch(static_cast<DRW_ASTMNotch*>(e)); break;
break; case DRW::ASTMNOTCH:
case DRW::LINE: dxfW->writeASTMNotch(static_cast<DRW_ASTMNotch *>(e));
dxfW->writeLine(static_cast<DRW_Line*>(e)); break;
break; case DRW::LINE:
case DRW::CIRCLE: dxfW->writeLine(static_cast<DRW_Line *>(e));
dxfW->writeCircle(static_cast<DRW_Circle*>(e)); break;
break; case DRW::CIRCLE:
case DRW::ARC: dxfW->writeCircle(static_cast<DRW_Circle *>(e));
dxfW->writeArc(static_cast<DRW_Arc*>(e)); break;
break; case DRW::ARC:
case DRW::SOLID: dxfW->writeArc(static_cast<DRW_Arc *>(e));
dxfW->writeSolid(static_cast<DRW_Solid*>(e)); break;
break; case DRW::SOLID:
case DRW::ELLIPSE: dxfW->writeSolid(static_cast<DRW_Solid *>(e));
dxfW->writeEllipse(static_cast<DRW_Ellipse*>(e)); break;
break; case DRW::ELLIPSE:
case DRW::LWPOLYLINE: dxfW->writeEllipse(static_cast<DRW_Ellipse *>(e));
dxfW->writeLWPolyline(static_cast<DRW_LWPolyline*>(e)); break;
break; case DRW::LWPOLYLINE:
case DRW::POLYLINE: dxfW->writeLWPolyline(static_cast<DRW_LWPolyline *>(e));
dxfW->writePolyline(static_cast<DRW_Polyline*>(e)); break;
break; case DRW::POLYLINE:
case DRW::SPLINE: dxfW->writePolyline(static_cast<DRW_Polyline *>(e));
dxfW->writeSpline(static_cast<DRW_Spline*>(e)); break;
break; case DRW::SPLINE:
// case RS2::EntitySplinePoints: dxfW->writeSpline(static_cast<DRW_Spline *>(e));
// writeSplinePoints(static_cast<DRW_Point*>(e)); break;
// break; // case RS2::EntitySplinePoints:
// case RS2::EntityVertex: // writeSplinePoints(static_cast<DRW_Point*>(e));
// break; // break;
case DRW::INSERT: // case RS2::EntityVertex:
dxfW->writeInsert(static_cast<DRW_Insert*>(e)); // break;
break; case DRW::INSERT:
case DRW::MTEXT: dxfW->writeInsert(static_cast<DRW_Insert *>(e));
dxfW->writeMText(static_cast<DRW_MText*>(e)); break;
break; case DRW::MTEXT:
case DRW::TEXT: dxfW->writeMText(static_cast<DRW_MText *>(e));
dxfW->writeText(static_cast<DRW_Text*>(e)); break;
break; case DRW::TEXT:
case DRW::DIMLINEAR: dxfW->writeText(static_cast<DRW_Text *>(e));
case DRW::DIMALIGNED: break;
case DRW::DIMANGULAR: case DRW::DIMLINEAR:
case DRW::DIMANGULAR3P: case DRW::DIMALIGNED:
case DRW::DIMRADIAL: case DRW::DIMANGULAR:
case DRW::DIMDIAMETRIC: case DRW::DIMANGULAR3P:
case DRW::DIMORDINATE: case DRW::DIMRADIAL:
dxfW->writeDimension(static_cast<DRW_Dimension*>(e)); case DRW::DIMDIAMETRIC:
break; case DRW::DIMORDINATE:
case DRW::LEADER: dxfW->writeDimension(static_cast<DRW_Dimension *>(e));
dxfW->writeLeader(static_cast<DRW_Leader*>(e)); break;
break; case DRW::LEADER:
case DRW::HATCH: dxfW->writeLeader(static_cast<DRW_Leader *>(e));
dxfW->writeHatch(static_cast<DRW_Hatch*>(e)); break;
break; case DRW::HATCH:
case DRW::IMAGE: dxfW->writeHatch(static_cast<DRW_Hatch *>(e));
dxfW->writeImage(static_cast<DRW_Image*>(e), static_cast<dx_ifaceImg*>(e)->path); break;
break; case DRW::IMAGE:
default: dxfW->writeImage(static_cast<DRW_Image *>(e), static_cast<dx_ifaceImg *>(e)->path);
break; break;
default:
break;
} }
} }
@ -115,56 +118,66 @@ 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:
// for (auto it=cData->headerC.vars.begin(); it != cData->headerC.vars.end(); ++it) // for (auto it=cData->headerC.vars.begin(); it != cData->headerC.vars.end(); ++it)
// 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 {
for (auto *bk : cData.blocks){ // write each block
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)
writeEntity(*it); writeEntity(*it);
} }
} }
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,8 +186,9 @@ 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));
} }
@ -183,14 +197,14 @@ void dx_iface::InitHeader(VarMeasurement varMeasurement, VarInsunits varInsunits
cData.headerC.addComment("Valentina DXF File"); cData.headerC.addComment("Valentina DXF File");
// 1 = Clockwise angles, 0 = Counterclockwise // 1 = Clockwise angles, 0 = Counterclockwise
cData.headerC.addInt("$ANGDIR", 0, 70);// Qt use counterclockwise cData.headerC.addInt("$ANGDIR", 0, 70); // Qt use counterclockwise
// Sets drawing units: 0 = English; 1 = Metric // Sets drawing units: 0 = English; 1 = Metric
cData.headerC.addInt("$MEASUREMENT", static_cast<int>(varMeasurement), 70); cData.headerC.addInt("$MEASUREMENT", static_cast<int>(varMeasurement), 70);
cData.headerC.addInt("$INSUNITS", static_cast<int>(varInsunits), 70); cData.headerC.addInt("$INSUNITS", static_cast<int>(varInsunits), 70);
QString dateTime = QDateTime::currentDateTime().toString("yyyyMMdd.HHmmsszzz"); QString dateTime = QDateTime::currentDateTime().toString("yyyyMMdd.HHmmsszzz");
dateTime.chop(1);// we need hundredths of a second dateTime.chop(1); // we need hundredths of a second
cData.headerC.addStr("$TDCREATE", dateTime.toStdString(), 40); cData.headerC.addStr("$TDCREATE", dateTime.toStdString(), 40);
if (version >= DRW::AC1021) if (version >= DRW::AC1021)
@ -252,41 +266,41 @@ void dx_iface::AddAAMALayers()
{ {
DRW_Layer layer; DRW_Layer layer;
layer.name = '1';// CUT, OUTLINE layer.name = '1'; // CUT, OUTLINE
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = '8';// DRAW, INK layer.name = '8'; // DRAW, INK
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = '7';// GRAINLINE layer.name = '7'; // GRAINLINE
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
// layer.name = '6';// MIRROR LINES // layer.name = '6';// MIRROR LINES
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
layer.name = "11";// INTCUT layer.name = "11"; // INTCUT
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "13";// DRILL layer.name = "13"; // DRILL
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = '4';// NOTCH layer.name = '4'; // NOTCH
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
// Optitex doesn't like this layer // Optitex doesn't like this layer
// layer.name = "19";// TEXT // layer.name = "19";// TEXT
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
// layer.name = "26";// REF // layer.name = "26";// REF
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
} }
@ -306,99 +320,99 @@ void dx_iface::AddASTMLayers()
{ {
DRW_Layer layer; DRW_Layer layer;
layer.name = '1';// piece boundary layer.name = '1'; // piece boundary
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
// Do not support // Do not support
// layer.name = '2';// turn points // layer.name = '2';// turn points
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
// Do not support // Do not support
// layer.name = '3';// curve points // layer.name = '3';// curve points
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
layer.name = '4';// V-notch and slit notch layer.name = '4'; // V-notch and slit notch
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
// Do not support // Do not support
// layer.name = '5';// grade reference and alternate grade reference line(s) // layer.name = '5';// grade reference and alternate grade reference line(s)
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
// Do not support // Do not support
// layer.name = '6';// mirror line // layer.name = '6';// mirror line
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
layer.name = '7';// grainline layer.name = '7'; // grainline
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = '8';// internal line(s) layer.name = '8'; // internal line(s)
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
// Do not support // Do not support
// layer.name = '9';// stripe reference line(s) // layer.name = '9';// stripe reference line(s)
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
// Do not support // Do not support
// layer.name = '10';// plaid reference line(s) // layer.name = '10';// plaid reference line(s)
// layer.color = DRW::black; // layer.color = DRW::black;
// cData.layers.push_back(layer); // cData.layers.push_back(layer);
layer.name = "11";// internal cutout(s) layer.name = "11"; // internal cutout(s)
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
// Layer 12 intentionally left blank by the standard // Layer 12 intentionally left blank by the standard
layer.name = "13";// drill holes layer.name = "13"; // drill holes
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "14";// sew line(s) layer.name = "14"; // sew line(s)
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "15";// annotation text layer.name = "15"; // annotation text
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "80";// T-notch layer.name = "80"; // T-notch
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "81";// castle notch layer.name = "81"; // castle notch
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "82";// check notch layer.name = "82"; // check notch
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "83";// U-notch layer.name = "83"; // U-notch
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "84";// piece boundary quality validation curves layer.name = "84"; // piece boundary quality validation curves
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "85";// internal lines quality validation curves layer.name = "85"; // internal lines quality validation curves
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "86";// internal cutouts quality validation curves layer.name = "86"; // internal cutouts quality validation curves
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
layer.name = "87";// sew lines quality validation curves layer.name = "87"; // sew lines quality validation curves
layer.color = DRW::black; layer.color = DRW::black;
cData.layers.push_back(layer); cData.layers.push_back(layer);
} }
@ -460,7 +474,7 @@ auto dx_iface::AddFont(const QFont &f) -> UTF8STRING
ts.fontFamily += 0x1000000; ts.fontFamily += 0x1000000;
} }
for (auto it = cData.textStyles.begin() ; it !=cData.textStyles.end() ; ++it) for (auto it = cData.textStyles.begin(); it != cData.textStyles.end(); ++it)
{ {
if ((*it).name == ts.name) if ((*it).name == ts.name)
{ {
@ -482,7 +496,7 @@ 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); }