More modernization and cleanups.
This commit is contained in:
parent
5f6445cf93
commit
c51d9d5b30
|
@ -51,7 +51,7 @@ void DRW_Header::parseCode(int code, dxfReader *reader){
|
||||||
case 1:
|
case 1:
|
||||||
curr->addString(reader->getUtf8String());
|
curr->addString(reader->getUtf8String());
|
||||||
if (name =="$ACADVER") {
|
if (name =="$ACADVER") {
|
||||||
reader->setVersion(curr->content.s, true);
|
reader->setVersion(*curr->content.s, true);
|
||||||
version = reader->getVersion();
|
version = reader->getVersion();
|
||||||
}
|
}
|
||||||
curr->code = code;
|
curr->code = code;
|
||||||
|
@ -67,7 +67,7 @@ void DRW_Header::parseCode(int code, dxfReader *reader){
|
||||||
case 3:
|
case 3:
|
||||||
curr->addString(reader->getUtf8String());
|
curr->addString(reader->getUtf8String());
|
||||||
if (name =="$DWGCODEPAGE") {
|
if (name =="$DWGCODEPAGE") {
|
||||||
reader->setCodePage(curr->content.s);
|
reader->setCodePage(*curr->content.s);
|
||||||
curr->addString(reader->getCodePage());
|
curr->addString(reader->getCodePage());
|
||||||
}
|
}
|
||||||
curr->code = code;
|
curr->code = code;
|
||||||
|
@ -138,7 +138,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
writer->writeString(1, varStr);
|
writer->writeString(1, varStr);
|
||||||
writer->setVersion(&varStr, true);
|
writer->setVersion(varStr, true);
|
||||||
|
|
||||||
getStr("$ACADVER", &varStr);
|
getStr("$ACADVER", &varStr);
|
||||||
getStr("$ACADMAINTVER", &varStr);
|
getStr("$ACADMAINTVER", &varStr);
|
||||||
|
@ -147,7 +147,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){
|
||||||
varStr = "ANSI_1252";
|
varStr = "ANSI_1252";
|
||||||
}
|
}
|
||||||
writer->writeString(9, "$DWGCODEPAGE");
|
writer->writeString(9, "$DWGCODEPAGE");
|
||||||
writer->setCodePage(&varStr);
|
writer->setCodePage(varStr);
|
||||||
writer->writeString(3, writer->getCodePage() );
|
writer->writeString(3, writer->getCodePage() );
|
||||||
writer->writeString(9, "$INSBASE");
|
writer->writeString(9, "$INSBASE");
|
||||||
if (getCoord("$INSBASE", &varCoord)) {
|
if (getCoord("$INSBASE", &varCoord)) {
|
||||||
|
|
|
@ -12,9 +12,10 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <memory>
|
||||||
#include "drw_dbg.h"
|
#include "drw_dbg.h"
|
||||||
|
|
||||||
DRW_dbg *DRW_dbg::instance= NULL;
|
DRW_dbg *DRW_dbg::instance{nullptr};
|
||||||
|
|
||||||
/*********private clases*************/
|
/*********private clases*************/
|
||||||
class print_none {
|
class print_none {
|
||||||
|
@ -27,54 +28,45 @@ public:
|
||||||
virtual void printB(int i){(void)i;}
|
virtual void printB(int i){(void)i;}
|
||||||
virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;}
|
virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;}
|
||||||
virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;}
|
virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;}
|
||||||
print_none(){}
|
print_none()= default;
|
||||||
virtual ~print_none(){}
|
virtual ~print_none()=default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class print_debug : public print_none {
|
class print_debug : public print_none {
|
||||||
public:
|
public:
|
||||||
virtual void printS(const std::string &s) override;
|
void printS(const std::string &s) override;
|
||||||
virtual void printI(long long int i) override;
|
void printI(long long int i) override;
|
||||||
virtual void printUI(long long unsigned int i) override;
|
void printUI(long long unsigned int i) override;
|
||||||
virtual void printD(double d) override;
|
void printD(double d) override;
|
||||||
virtual void printH(long long int i) override;
|
void printH(long long int i) override;
|
||||||
virtual void printB(int i) override;
|
void printB(int i) override;
|
||||||
virtual void printHL(int c, int s, int h) override;
|
void printHL(int c, int s, int h) override;
|
||||||
virtual void printPT(double x, double y, double z) override;
|
void printPT(double x, double y, double z) override;
|
||||||
print_debug();
|
print_debug()=default;
|
||||||
virtual ~print_debug() = default;
|
|
||||||
private:
|
private:
|
||||||
std::ios_base::fmtflags flags;
|
std::ios_base::fmtflags flags{std::cerr.flags()};
|
||||||
};
|
};
|
||||||
|
|
||||||
/********* debug class *************/
|
/********* debug class *************/
|
||||||
DRW_dbg *DRW_dbg::getInstance(){
|
DRW_dbg *DRW_dbg::getInstance(){
|
||||||
if (instance == NULL){
|
if (instance == nullptr){
|
||||||
instance = new DRW_dbg;
|
instance = new DRW_dbg;
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
DRW_dbg::DRW_dbg()
|
DRW_dbg::DRW_dbg() :
|
||||||
: level(NONE),
|
prClass(std::make_unique<print_none>())
|
||||||
flags(std::cerr.flags()),
|
|
||||||
prClass(new print_none)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DRW_dbg::~DRW_dbg()
|
|
||||||
{
|
|
||||||
delete prClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DRW_dbg::setLevel(LEVEL lvl){
|
void DRW_dbg::setLevel(LEVEL lvl){
|
||||||
level = lvl;
|
level = lvl;
|
||||||
delete prClass;
|
|
||||||
switch (level){
|
switch (level){
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
prClass = new print_debug;
|
prClass = std::make_unique<print_debug>();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
prClass = new print_none;
|
prClass = std::make_unique<print_none>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,10 +117,6 @@ void DRW_dbg::printPT(double x, double y, double z){
|
||||||
prClass->printPT(x, y, z);
|
prClass->printPT(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_debug::print_debug()
|
|
||||||
: flags(std::cerr.flags())
|
|
||||||
{}
|
|
||||||
|
|
||||||
void print_debug::printS(const std::string &s){
|
void print_debug::printS(const std::string &s){
|
||||||
std::cerr << s;
|
std::cerr << s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <memory>
|
||||||
//#include <iomanip>
|
//#include <iomanip>
|
||||||
|
|
||||||
#define DRW_DBGSL(a) DRW_dbg::getInstance()->setLevel(a)
|
#define DRW_DBGSL(a) DRW_dbg::getInstance()->setLevel(a)
|
||||||
|
@ -55,9 +56,9 @@ private:
|
||||||
DRW_dbg();
|
DRW_dbg();
|
||||||
~DRW_dbg();
|
~DRW_dbg();
|
||||||
static DRW_dbg *instance;
|
static DRW_dbg *instance;
|
||||||
LEVEL level;
|
LEVEL level{NONE};
|
||||||
std::ios_base::fmtflags flags;
|
std::ios_base::fmtflags flags{std::cerr.flags()};
|
||||||
print_none* prClass;
|
std::unique_ptr<print_none> prClass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,22 +45,20 @@ QMap<QString, QStringList> QtCodecs()
|
||||||
}
|
}
|
||||||
|
|
||||||
DRW_TextCodec::DRW_TextCodec()
|
DRW_TextCodec::DRW_TextCodec()
|
||||||
: version(DRW::AC1021),
|
: version(DRW::AC1021)
|
||||||
cp(),
|
|
||||||
conv(nullptr)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void DRW_TextCodec::setVersion(int v, bool dxfFormat){
|
void DRW_TextCodec::setVersion(int v, bool dxfFormat){
|
||||||
if (v == DRW::AC1009 || v == DRW::AC1006) {
|
if (v == DRW::AC1009 || v == DRW::AC1006) {
|
||||||
version = DRW::AC1009;
|
version = DRW::AC1009;
|
||||||
cp = "ANSI_1252";
|
cp = "ANSI_1252";
|
||||||
setCodePage(&cp, dxfFormat);
|
setCodePage(cp, dxfFormat);
|
||||||
} else if (v == DRW::AC1012 || v == DRW::AC1014
|
} else if (v == DRW::AC1012 || v == DRW::AC1014
|
||||||
|| v == DRW::AC1015 || v == DRW::AC1018) {
|
|| v == DRW::AC1015 || v == DRW::AC1018) {
|
||||||
version = DRW::AC1015;
|
version = DRW::AC1015;
|
||||||
// if (cp.empty()) { //codepage not set, initialize
|
// if (cp.empty()) { //codepage not set, initialize
|
||||||
cp = "ANSI_1252";
|
cp = "ANSI_1252";
|
||||||
setCodePage(&cp, dxfFormat);
|
setCodePage(cp, dxfFormat);
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
version = DRW::AC1021;
|
version = DRW::AC1021;
|
||||||
|
@ -68,12 +66,11 @@ void DRW_TextCodec::setVersion(int v, bool dxfFormat){
|
||||||
cp = "UTF-8";//RLZ: can be UCS2 or UTF-16 16bits per char
|
cp = "UTF-8";//RLZ: can be UCS2 or UTF-16 16bits per char
|
||||||
else
|
else
|
||||||
cp = "UTF-16";//RLZ: can be UCS2 or UTF-16 16bits per char
|
cp = "UTF-16";//RLZ: can be UCS2 or UTF-16 16bits per char
|
||||||
setCodePage(&cp, dxfFormat);
|
setCodePage(cp, dxfFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRW_TextCodec::setVersion(std::string *v, bool dxfFormat){
|
void DRW_TextCodec::setVersion(const std::string &versionStr, bool dxfFormat){
|
||||||
std::string versionStr = *v;
|
|
||||||
if (versionStr == "AC1009" || versionStr == "AC1006") {
|
if (versionStr == "AC1009" || versionStr == "AC1006") {
|
||||||
setVersion(DRW::AC1009, dxfFormat);
|
setVersion(DRW::AC1009, dxfFormat);
|
||||||
} else if (versionStr == "AC1012" || versionStr == "AC1014"
|
} else if (versionStr == "AC1012" || versionStr == "AC1014"
|
||||||
|
@ -86,8 +83,8 @@ void DRW_TextCodec::setVersion(std::string *v, bool dxfFormat){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRW_TextCodec::setCodePage(const std::string *c, bool dxfFormat){
|
void DRW_TextCodec::setCodePage(const std::string &c, bool dxfFormat){
|
||||||
cp = correctCodePage(*c);
|
cp = correctCodePage(c);
|
||||||
if (version < DRW::AC1021)
|
if (version < DRW::AC1021)
|
||||||
{
|
{
|
||||||
if (cp == "UTF-8")
|
if (cp == "UTF-8")
|
||||||
|
|
|
@ -15,10 +15,9 @@ public:
|
||||||
std::string fromUtf8(const std::string &s);
|
std::string fromUtf8(const std::string &s);
|
||||||
std::string toUtf8(const std::string &s);
|
std::string toUtf8(const std::string &s);
|
||||||
int getVersion() const {return version;}
|
int getVersion() const {return version;}
|
||||||
void setVersion(std::string *v, bool dxfFormat);
|
void setVersion(const std::string &versionStr, bool dxfFormat);
|
||||||
void setVersion(int v, bool dxfFormat);
|
void setVersion(int v, bool dxfFormat);
|
||||||
void setCodePage(const std::string *c, bool dxfFormat);
|
void setCodePage(const std::string &c, bool dxfFormat);
|
||||||
void setCodePage(const std::string &c, bool dxfFormat){setCodePage(&c, dxfFormat);}
|
|
||||||
std::string getCodePage() const {return cp;}
|
std::string getCodePage() const {return cp;}
|
||||||
|
|
||||||
static QMap<QString, QStringList> DXFCodePageMap();
|
static QMap<QString, QStringList> DXFCodePageMap();
|
||||||
|
@ -30,8 +29,8 @@ private:
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(DRW_TextCodec)
|
Q_DISABLE_COPY(DRW_TextCodec)
|
||||||
int version;
|
int version;
|
||||||
std::string cp;
|
std::string cp{};
|
||||||
QTextCodec *conv;
|
QTextCodec *conv{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DRW_TEXTCODEC_H
|
#endif // DRW_TEXTCODEC_H
|
||||||
|
|
|
@ -50,8 +50,8 @@ public:
|
||||||
unsigned long long int getInt64() const {return int64;}
|
unsigned long long int getInt64() const {return int64;}
|
||||||
bool getBool() const { return (intData==0) ? false : true;}
|
bool getBool() const { return (intData==0) ? false : true;}
|
||||||
int getVersion() const {return decoder.getVersion();}
|
int getVersion() const {return decoder.getVersion();}
|
||||||
void setVersion(std::string *v, bool dxfFormat){decoder.setVersion(v, dxfFormat);}
|
void setVersion(const std::string &v, bool dxfFormat){decoder.setVersion(v, dxfFormat);}
|
||||||
void setCodePage(std::string *c){decoder.setCodePage(c, true);}
|
void setCodePage(const std::string &c){decoder.setCodePage(c, true);}
|
||||||
std::string getCodePage() const { return decoder.getCodePage();}
|
std::string getCodePage() const { return decoder.getCodePage();}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -32,8 +32,8 @@ public:
|
||||||
virtual bool writeInt64(int code, unsigned long long int data) = 0;
|
virtual bool writeInt64(int code, unsigned long long int data) = 0;
|
||||||
virtual bool writeDouble(int code, double data) = 0;
|
virtual bool writeDouble(int code, double data) = 0;
|
||||||
virtual bool writeBool(int code, bool data) = 0;
|
virtual bool writeBool(int code, bool data) = 0;
|
||||||
void setVersion(std::string *v, bool dxfFormat){encoder.setVersion(v, dxfFormat);}
|
void setVersion(const std::string &v, bool dxfFormat){encoder.setVersion(v, dxfFormat);}
|
||||||
void setCodePage(std::string *c){encoder.setCodePage(c, true);}
|
void setCodePage(const std::string &c){encoder.setCodePage(c, true);}
|
||||||
std::string getCodePage() const {return encoder.getCodePage();}
|
std::string getCodePage() const {return encoder.getCodePage();}
|
||||||
protected:
|
protected:
|
||||||
std::ofstream *filestr;
|
std::ofstream *filestr;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user