Class to handle plot settings object entries.

This commit is contained in:
Roman Telezhynskyi 2021-11-23 14:43:26 +02:00
parent c6bd3ae727
commit 0db9e1f728
17 changed files with 445 additions and 148 deletions

View File

@ -125,8 +125,7 @@ void dx_iface::writeHeader(DRW_Header &data){
void dx_iface::writeBlocks(){ void dx_iface::writeBlocks(){
//write each block //write each block
for (std::list<dx_ifaceBlock*>::iterator it=cData.blocks.begin(); it != cData.blocks.end(); ++it){ for (auto *bk : cData.blocks){
dx_ifaceBlock* bk = *it;
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)
@ -169,8 +168,13 @@ void dx_iface::writeDimstyles(){
dxfW->writeDimstyle(&(*it)); dxfW->writeDimstyle(&(*it));
} }
void dx_iface::writeObjects()
{
// default implementation for new DRW_Interface method
}
void dx_iface::writeAppId(){ void dx_iface::writeAppId(){
for (std::list<DRW_AppId>::iterator 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));
} }

View File

@ -116,6 +116,7 @@ public:
virtual void writeTextstyles() override; virtual void writeTextstyles() override;
virtual void writeVports() override; virtual void writeVports() override;
virtual void writeDimstyles() override; virtual void writeDimstyles() override;
virtual void writeObjects() override;
virtual void writeAppId() override; virtual void writeAppId() override;
void AddEntity(DRW_Entity* e); void AddEntity(DRW_Entity* e);

View File

@ -156,7 +156,8 @@ BAD_READ_CLASSES, /*!< error in classes read process. */
BAD_READ_TABLES, /*!< error in tables read process. */ BAD_READ_TABLES, /*!< error in tables read process. */
BAD_READ_BLOCKS, /*!< error in block read process. */ BAD_READ_BLOCKS, /*!< error in block read process. */
BAD_READ_ENTITIES, /*!< error in entities read process. */ BAD_READ_ENTITIES, /*!< error in entities read process. */
BAD_READ_OBJECTS /*!< error in objects read process. */ BAD_READ_OBJECTS, /*!< error in objects read process. */
BAD_READ_SECTION, /*!< error in sections read process. */
}; };
enum class DebugLevel { enum class DebugLevel {
@ -301,7 +302,7 @@ public:
/*!< convert to unitary vector */ /*!< convert to unitary vector */
void unitize(){ void unitize(){
double dist; double dist;
dist = sqrt(x*x + y*y + z*z); dist = hypot(hypot(x, y), z);
if (dist > 0.0) { if (dist > 0.0) {
x= x/dist; x= x/dist;
y= y/dist; y= y/dist;

View File

@ -607,7 +607,7 @@ void DRW_MText::parseCode(int code, dxfReader *reader){
text = reader->toUtf8String(text); text = reader->toUtf8String(text);
break; break;
case 11: case 11:
haveXAxis = true; hasXAxisVec = true;
DRW_Text::parseCode(code, reader); DRW_Text::parseCode(code, reader);
break; break;
case 3: case 3:
@ -681,7 +681,7 @@ void DRW_MText::parseCode(int code, dxfReader *reader){
} }
void DRW_MText::updateAngle(){ void DRW_MText::updateAngle(){
if (haveXAxis) { if (hasXAxisVec) {
angle = atan2(secPoint.y, secPoint.x)*180/M_PI; angle = atan2(secPoint.y, secPoint.x)*180/M_PI;
} }
} }

View File

@ -739,7 +739,7 @@ public:
DRW_MText() DRW_MText()
: interlin(1), : interlin(1),
haveXAxis(false)//if true needed to recalculate angle hasXAxisVec(false)//if true needed to recalculate angle
{ {
eType = DRW::MTEXT; eType = DRW::MTEXT;
alignV = static_cast<VAlign>(TopLeft); alignV = static_cast<VAlign>(TopLeft);
@ -753,7 +753,7 @@ protected:
public: public:
double interlin; /*!< width factor, code 44 */ double interlin; /*!< width factor, code 44 */
private: private:
bool haveXAxis; bool hasXAxisVec;
}; };
//! Class to handle vertex //! Class to handle vertex

View File

@ -40,6 +40,13 @@ void DRW_Header::addComment(const std::string &c){
} }
void DRW_Header::parseCode(int code, dxfReader *reader){ void DRW_Header::parseCode(int code, dxfReader *reader){
if (nullptr == curr && 9 != code) {
DRW_DBG("invalid header code: ");
DRW_DBG(code);
DRW_DBG("\n");
return;
}
switch (code) { switch (code) {
case 9: case 9:
curr = new DRW_Variant(); curr = new DRW_Variant();

View File

@ -105,7 +105,7 @@ public:
private: private:
std::string comments; std::string comments;
std::string name; std::string name;
DRW_Variant* curr; DRW_Variant* curr {nullptr};
int version; //to use on read int version; //to use on read
duint32 linetypeCtrl; duint32 linetypeCtrl;

View File

@ -24,7 +24,7 @@ QT_WARNING_DISABLE_GCC("-Wsuggest-final-types")
QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods") QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
/** /**
* Abstract class (interface) for comunicate dxfReader with the application. * Abstract class (interface) for communicate dxfReader with the application.
* Inherit your class which takes care of the entities in the * Inherit your class which takes care of the entities in the
* processed DXF file from this interface. * processed DXF file from this interface.
* *
@ -179,6 +179,11 @@ public:
*/ */
virtual void addComment(const char *) { } virtual void addComment(const char *) { }
/**
* Called for PLOTSETTINGS object definition.
*/
virtual void addPlotSettings(const DRW_PlotSettings *) {}
virtual void writeHeader(DRW_Header &) { } virtual void writeHeader(DRW_Header &) { }
virtual void writeBlocks() { } virtual void writeBlocks() { }
virtual void writeBlockRecords() { } virtual void writeBlockRecords() { }
@ -188,6 +193,7 @@ public:
virtual void writeTextstyles() { } virtual void writeTextstyles() { }
virtual void writeVports() { } virtual void writeVports() { }
virtual void writeDimstyles() { } virtual void writeDimstyles() { }
virtual void writeObjects() {}
virtual void writeAppId() { } virtual void writeAppId() { }
}; };

View File

@ -588,3 +588,28 @@ void DRW_ImageDef::parseCode(int code, dxfReader *reader){
break; break;
} }
} }
void DRW_PlotSettings::parseCode(int code, dxfReader *reader){
switch (code) {
case 5:
handle = static_cast<duint32>(reader->getHandleString());
break;
case 6:
plotViewName = reader->getUtf8String();
break;
case 40:
marginLeft = reader->getDouble();
break;
case 41:
marginBottom = reader->getDouble();
break;
case 42:
marginRight = reader->getDouble();
break;
case 43:
marginTop = reader->getDouble();
break;
default:
break;
}
}

View File

@ -35,7 +35,8 @@ namespace DRW {
VPORT, VPORT,
BLOCK_RECORD, BLOCK_RECORD,
APPID, APPID,
IMAGEDEF IMAGEDEF,
PLOTSETTINGS
}; };
//pending VIEW, UCS, APPID, VP_ENT_HDR, GROUP, MLINESTYLE, LONG_TRANSACTION, XRECORD, //pending VIEW, UCS, APPID, VP_ENT_HDR, GROUP, MLINESTYLE, LONG_TRANSACTION, XRECORD,
@ -591,6 +592,38 @@ public:
std::map<std::string,std::string> reactors; std::map<std::string,std::string> reactors;
}; };
//! Class to handle plotsettings entries
/*!
* Class to handle plot settings object entries
* @author baranovskiykonstantin@gmail.com
*/
class DRW_PlotSettings : public DRW_TableEntry {
SETOBJFRIENDS
public:
DRW_PlotSettings() {
reset();
}
void reset(){
tType = DRW::PLOTSETTINGS;
marginLeft = 0.0;
marginBottom = 0.0;
marginRight = 0.0;
marginTop = 0.0;
DRW_TableEntry::reset();
}
protected:
void parseCode(int code, dxfReader *reader);
public:
UTF8STRING plotViewName {}; /*!< Plot view name, code 6 */
double marginLeft {0.0}; /*!< Size, in millimeters, of unprintable margin on left side of paper, code 40 */
double marginBottom {0.0}; /*!< Size, in millimeters, of unprintable margin on bottom side of paper, code 41 */
double marginRight {0.0}; /*!< Size, in millimeters, of unprintable margin on right side of paper, code 42 */
double marginTop {0.0}; /*!< Size, in millimeters, of unprintable margin on top side of paper, code 43 */
};
//! Class to handle AppId entries //! Class to handle AppId entries
/*! /*!
* Class to handle AppId symbol table entries * Class to handle AppId symbol table entries

View File

@ -17,7 +17,7 @@
DRW_dbg *DRW_dbg::instance{nullptr}; DRW_dbg *DRW_dbg::instance{nullptr};
/*********private clases*************/ /*********private classes*************/
class print_debug : public DRW::DebugPrinter { class print_debug : public DRW::DebugPrinter {
public: public:
@ -76,6 +76,14 @@ void DRW_dbg::print(const std::string &s){
currentPrinter->printS(s); currentPrinter->printS(s);
} }
void DRW_dbg::print(signed char i){
currentPrinter->printI(i);
}
void DRW_dbg::print(unsigned char i){
currentPrinter->printUI(i);
}
void DRW_dbg::print(int i){ void DRW_dbg::print(int i){
currentPrinter->printI(i); currentPrinter->printI(i);
} }

View File

@ -46,6 +46,8 @@ public:
Level getLevel() const; Level getLevel() const;
static DRW_dbg *getInstance(); static DRW_dbg *getInstance();
void print(const std::string &s); void print(const std::string &s);
void print(signed char i);
void print(unsigned char i);
void print(int i); void print(int i);
void print(unsigned int i); void print(unsigned int i);
void print(long long int i); void print(long long int i);

View File

@ -70,6 +70,10 @@ bool dxfReader::readRec(int *codeData) {
readDouble(); readDouble();
else if (code < 481) else if (code < 481)
readString(); readString();
else if( 999 == code && m_bIgnoreComments) {
readString();
return readRec( codeData);
}
else if (code > 998 && code < 1009) //skip not used at the v2012 else if (code > 998 && code < 1009) //skip not used at the v2012
readString(); readString();
else if (code < 1060) //TODO this is a floating point double precision?? else if (code < 1060) //TODO this is a floating point double precision??

View File

@ -53,6 +53,7 @@ public:
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);}
std::string getCodePage() const { return decoder.getCodePage();} std::string getCodePage() const { return decoder.getCodePage();}
void setIgnoreComments(const bool bValue) {m_bIgnoreComments = bValue;}
protected: protected:
virtual bool readCode(int *code) = 0; //return true if successful (not EOF) virtual bool readCode(int *code) = 0; //return true if successful (not EOF)
@ -74,6 +75,7 @@ protected:
private: private:
Q_DISABLE_COPY(dxfReader) Q_DISABLE_COPY(dxfReader)
DRW_TextCodec decoder; DRW_TextCodec decoder;
bool m_bIgnoreComments {false};
}; };
class dxfReaderBinary : public dxfReader { class dxfReaderBinary : public dxfReader {

View File

@ -49,7 +49,7 @@ dxfRW::dxfRW(const char* name)
dimstyleStd(), dimstyleStd(),
applyExt(false), applyExt(false),
writingBlock(), writingBlock(),
elParts(128), //parts munber when convert ellipse to polyline elParts(128), //parts number when convert ellipse to polyline
blockMap(), blockMap(),
imageDef(), imageDef(),
currHandle() currHandle()
@ -80,17 +80,16 @@ void dxfRW::setDebug(DRW::DebugLevel lvl){
bool dxfRW::read(DRW_Interface *interface_, bool ext){ bool dxfRW::read(DRW_Interface *interface_, bool ext){
drw_assert(fileName.empty() == false); drw_assert(fileName.empty() == false);
bool isOk = false;
applyExt = ext; applyExt = ext;
std::ifstream filestr; std::ifstream filestr;
if ( interface_ == nullptr ) if (nullptr == interface_) {
return isOk; return setError(DRW::BAD_UNKNOWN);
}
DRW_DBG("dxfRW::read 1def\n"); DRW_DBG("dxfRW::read 1def\n");
filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary);
if (!filestr.is_open()) if (!filestr.is_open() || !filestr.good()) {
return isOk; return setError(DRW::BAD_OPEN);
if (!filestr.good()) }
return isOk;
char line[22]; char line[22];
char line2[22] = "AutoCAD Binary DXF\r\n"; char line2[22] = "AutoCAD Binary DXF\r\n";
@ -113,7 +112,7 @@ bool dxfRW::read(DRW_Interface *interface_, bool ext){
reader = new dxfReaderAscii(&filestr); reader = new dxfReaderAscii(&filestr);
} }
isOk = processDxf(); bool isOk = processDxf();
filestr.close(); filestr.close();
delete reader; delete reader;
reader = nullptr; reader = nullptr;
@ -211,6 +210,52 @@ bool dxfRW::writeEntity(DRW_Entity *ent) {
if (version > DRW::AC1014) { if (version > DRW::AC1014) {
writer->writeInt16(370, DRW_LW_Conv::lineWidth2dxfInt(ent->lWeight)); writer->writeInt16(370, DRW_LW_Conv::lineWidth2dxfInt(ent->lWeight));
} }
if (version >= DRW::AC1014) {
writeAppData(ent->appData);
}
return true;
}
bool dxfRW::writeAppData(const std::list<std::list<DRW_Variant>>& appData) {
for(const auto& group : appData) {
//Search for application name
bool found = false;
for(const auto& data : group) {
if(data.code == 102 && data.type == DRW_Variant::STRING) {
writer->writeString(102, "{" + *(data.content.s));
found = true;
break;
}
}
if(found) {
for(const auto& data : group) {
if(data.code == 102) {
continue;
}
switch(data.type) {
case DRW_Variant::STRING:
writer->writeString(data.code, *(data.content.s));
break;
case DRW_Variant::INTEGER:
writer->writeInt32(data.code, data.content.i);
break;
case DRW_Variant::DOUBLE:
writer->writeDouble(data.code, data.content.i);
break;
default:
break;
}
}
writer->writeString(102, "}");
}
}
return true; return true;
} }
@ -1813,6 +1858,8 @@ bool dxfRW::writeObjects() {
imageDef.pop_back(); imageDef.pop_back();
} }
iface->writeObjects();
return true; return true;
} }
@ -1865,49 +1912,99 @@ bool dxfRW::writeExtData(const std::vector<DRW_Variant*> &ed){
bool dxfRW::processDxf() { bool dxfRW::processDxf() {
DRW_DBG("dxfRW::processDxf() start processing dxf\n"); DRW_DBG("dxfRW::processDxf() start processing dxf\n");
int code; int code = -1;
bool more = true; bool inSection = false;
std::string sectionstr;
// section = secUnknown; reader->setIgnoreComments( false);
while (reader->readRec(&code)) { while (reader->readRec(&code)) {
DRW_DBG(code); DRW_DBG(" processDxf\n"); DRW_DBG(code); DRW_DBG(" code\n");
if (code == 999) { /* at this level we should only get:
header.addComment(reader->getString()); 999 - Comment
} else if (code == 0) { 0 - SECTION or EOF
sectionstr = reader->getString(); 2 - section name
DRW_DBG(sectionstr); DRW_DBG(" processDxf\n"); everything else between "2 - section name" and "0 - ENDSEC" is handled in process() methods
if (sectionstr == "EOF") { */
switch (code) {
case 999: // when DXF was created by libdxfrw, first record is a comment with dxfrw version info
header.addComment( reader->getString());
continue;
case 0:
// ignore further comments, as libdxfrw doesn't support comments in sections
reader->setIgnoreComments( true);
if (!inSection) {
std::string sectionstr {reader->getString()};
if ("SECTION" == sectionstr) {
DRW_DBG(sectionstr); DRW_DBG(" new section\n");
inSection = true;
continue;
}
if ("EOF" == sectionstr) {
return true; //found EOF terminate return true; //found EOF terminate
} }
if (sectionstr == "SECTION") { }
more = reader->readRec(&code); else {
DRW_DBG(code); DRW_DBG(" processDxf\n"); // in case SECTION was unknown or not supported
if (!more) if ("ENDSEC" == reader->getString()) {
return false; //wrong dxf file inSection = false;
if (code == 2) {
sectionstr = reader->getString();
DRW_DBG(sectionstr); DRW_DBG(" processDxf\n");
//found section, process it
if (sectionstr == "HEADER") {
processHeader();
} else if (sectionstr == "CLASSES") {
// processClasses();
} else if (sectionstr == "TABLES") {
processTables();
} else if (sectionstr == "BLOCKS") {
processBlocks();
} else if (sectionstr == "ENTITIES") {
processEntities(false);
} else if (sectionstr == "OBJECTS") {
processObjects();
} }
} }
break;
case 2:
if (inSection) {
bool processed {false};
std::string sectionname {reader->getString()};
DRW_DBG(sectionname); DRW_DBG(" process section\n");
if ("HEADER" == sectionname) {
processed = processHeader();
} }
else if ("TABLES" == sectionname) {
processed = processTables();
}
else if ("BLOCKS" == sectionname) {
processed = processBlocks();
}
else if ("ENTITIES" == sectionname) {
processed = processEntities(false);
}
else if ("OBJECTS" == sectionname) {
processed = processObjects();
}
else {
//TODO handle CLASSES
DRW_DBG("section unknown or not supported\n");
continue;
}
if (!processed) {
DRW_DBG(" failed\n");
return setError(DRW::BAD_READ_SECTION);
}
inSection = false;
}
continue;
default:
// landing here means an unknown or not supported SECTION
inSection = false;
break;
} }
/* if (!more) /* if (!more)
return true;*/ return true;*/
} }
if (0 == code && "EOF" == reader->getString()) {
// in case the final EOF has no newline we end up here!
// this is caused by filestr->good() which is false for missing newline on EOF
return true; return true;
}
return setError(DRW::BAD_UNKNOWN);
} }
/********* Header Section *********/ /********* Header Section *********/
@ -1925,9 +2022,14 @@ bool dxfRW::processHeader() {
iface->addHeader(&header); iface->addHeader(&header);
return true; //found ENDSEC terminate return true; //found ENDSEC terminate
} }
} else header.parseCode(code, reader); DRW_DBG("unexpected 0 code in header!\n");
return setError(DRW::BAD_READ_HEADER);
} }
return true;
header.parseCode(code, reader);
}
return setError(DRW::BAD_READ_HEADER);
} }
/********* Tables Section *********/ /********* Tables Section *********/
@ -1945,8 +2047,9 @@ bool dxfRW::processTables() {
if (sectionstr == "TABLE") { if (sectionstr == "TABLE") {
more = reader->readRec(&code); more = reader->readRec(&code);
DRW_DBG(code); DRW_DBG("\n"); DRW_DBG(code); DRW_DBG("\n");
if (!more) if (!more) {
return false; //wrong dxf file return setError(DRW::BAD_READ_TABLES); //wrong dxf file
}
if (code == 2) { if (code == 2) {
sectionstr = reader->getString(); sectionstr = reader->getString();
DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n"); DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n");
@ -1976,7 +2079,8 @@ bool dxfRW::processTables() {
} }
} }
} }
return true;
return setError(DRW::BAD_READ_TABLES);
} }
bool dxfRW::processLType() { bool dxfRW::processLType() {
@ -2003,7 +2107,8 @@ bool dxfRW::processLType() {
} else if (reading) } else if (reading)
ltype.parseCode(code, reader); ltype.parseCode(code, reader);
} }
return true;
return setError(DRW::BAD_READ_TABLES);
} }
bool dxfRW::processLayer() { bool dxfRW::processLayer() {
@ -2028,7 +2133,8 @@ bool dxfRW::processLayer() {
} else if (reading) } else if (reading)
layer.parseCode(code, reader); layer.parseCode(code, reader);
} }
return true;
return setError(DRW::BAD_READ_TABLES);
} }
bool dxfRW::processDimStyle() { bool dxfRW::processDimStyle() {
@ -2053,7 +2159,8 @@ bool dxfRW::processDimStyle() {
} else if (reading) } else if (reading)
dimSty.parseCode(code, reader); dimSty.parseCode(code, reader);
} }
return true;
return setError(DRW::BAD_READ_TABLES);
} }
bool dxfRW::processTextStyle(){ bool dxfRW::processTextStyle(){
@ -2078,7 +2185,8 @@ bool dxfRW::processTextStyle(){
} else if (reading) } else if (reading)
TxtSty.parseCode(code, reader); TxtSty.parseCode(code, reader);
} }
return true;
return setError(DRW::BAD_READ_TABLES);
} }
bool dxfRW::processVports(){ bool dxfRW::processVports(){
@ -2103,7 +2211,8 @@ bool dxfRW::processVports(){
} else if (reading) } else if (reading)
vp.parseCode(code, reader); vp.parseCode(code, reader);
} }
return true;
return setError(DRW::BAD_READ_TABLES);
} }
bool dxfRW::processAppId(){ bool dxfRW::processAppId(){
@ -2128,7 +2237,8 @@ bool dxfRW::processAppId(){
} else if (reading) } else if (reading)
vp.parseCode(code, reader); vp.parseCode(code, reader);
} }
return true;
return setError(DRW::BAD_READ_TABLES);
} }
/********* Block Section *********/ /********* Block Section *********/
@ -2149,7 +2259,8 @@ bool dxfRW::processBlocks() {
} }
} }
} }
return true;
return setError(DRW::BAD_READ_BLOCKS);
} }
bool dxfRW::processBlock() { bool dxfRW::processBlock() {
@ -2177,7 +2288,8 @@ bool dxfRW::processBlock() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_BLOCKS);
} }
@ -2187,69 +2299,74 @@ bool dxfRW::processEntities(bool isblock) {
DRW_DBG("dxfRW::processEntities\n"); DRW_DBG("dxfRW::processEntities\n");
int code; int code;
if (!reader->readRec(&code)){ if (!reader->readRec(&code)){
return false; return setError(DRW::BAD_READ_ENTITIES);
} }
bool next = true; bool next = true;
if (code == 0) { if (code == 0) {
nextentity = reader->getString(); nextentity = reader->getString();
} else if (!isblock) { } else if (!isblock) {
return false; //first record in entities is 0 return setError(DRW::BAD_READ_ENTITIES); //first record in entities is 0
} }
bool processed {false};
do { do {
if (nextentity == "ENDSEC" || nextentity == "ENDBLK") { if (nextentity == "ENDSEC" || nextentity == "ENDBLK") {
return true; //found ENDSEC or ENDBLK terminate return true; //found ENDSEC or ENDBLK terminate
} else if (nextentity == "POINT") { } else if (nextentity == "POINT") {
processPoint(); processed = processPoint();
} else if (nextentity == "LINE") { } else if (nextentity == "LINE") {
processLine(); processed = processLine();
} else if (nextentity == "CIRCLE") { } else if (nextentity == "CIRCLE") {
processCircle(); processed = processCircle();
} else if (nextentity == "ARC") { } else if (nextentity == "ARC") {
processArc(); processed = processArc();
} else if (nextentity == "ELLIPSE") { } else if (nextentity == "ELLIPSE") {
processEllipse(); processed = processEllipse();
} else if (nextentity == "TRACE") { } else if (nextentity == "TRACE") {
processTrace(); processed = processTrace();
} else if (nextentity == "SOLID") { } else if (nextentity == "SOLID") {
processSolid(); processed = processSolid();
} else if (nextentity == "INSERT") { } else if (nextentity == "INSERT") {
processInsert(); processed = processInsert();
} else if (nextentity == "LWPOLYLINE") { } else if (nextentity == "LWPOLYLINE") {
processLWPolyline(); processed = processLWPolyline();
} else if (nextentity == "POLYLINE") { } else if (nextentity == "POLYLINE") {
processPolyline(); processed = processPolyline();
} else if (nextentity == "TEXT") { } else if (nextentity == "TEXT") {
processText(); processed = processText();
} else if (nextentity == "MTEXT") { } else if (nextentity == "MTEXT") {
processMText(); processed = processMText();
} else if (nextentity == "HATCH") { } else if (nextentity == "HATCH") {
processHatch(); processed = processHatch();
} else if (nextentity == "SPLINE") { } else if (nextentity == "SPLINE") {
processSpline(); processed = processSpline();
} else if (nextentity == "3DFACE") { } else if (nextentity == "3DFACE") {
process3dface(); processed = process3dface();
} else if (nextentity == "VIEWPORT") { } else if (nextentity == "VIEWPORT") {
processViewport(); processed = processViewport();
} else if (nextentity == "IMAGE") { } else if (nextentity == "IMAGE") {
processImage(); processed = processImage();
} else if (nextentity == "DIMENSION") { } else if (nextentity == "DIMENSION") {
processDimension(); processed = processDimension();
} else if (nextentity == "LEADER") { } else if (nextentity == "LEADER") {
processLeader(); processed = processLeader();
} else if (nextentity == "RAY") { } else if (nextentity == "RAY") {
processRay(); processed = processRay();
} else if (nextentity == "XLINE") { } else if (nextentity == "XLINE") {
processXline(); processed = processXline();
} else { } else {
if (reader->readRec(&code)){ if (!reader->readRec(&code)) {
if (code == 0) return setError(DRW::BAD_READ_ENTITIES); //end of file without ENDSEC
nextentity = reader->getString();
} else
return false; //end of file without ENDSEC
} }
} while (next); if (code == 0) {
return true; nextentity = reader->getString();
}
processed = true;
}
} while (processed);
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processEllipse() { bool dxfRW::processEllipse() {
@ -2272,7 +2389,8 @@ bool dxfRW::processEllipse() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processTrace() { bool dxfRW::processTrace() {
@ -2295,7 +2413,8 @@ bool dxfRW::processTrace() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processSolid() { bool dxfRW::processSolid() {
@ -2318,7 +2437,8 @@ bool dxfRW::processSolid() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::process3dface() { bool dxfRW::process3dface() {
@ -2339,7 +2459,8 @@ bool dxfRW::process3dface() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processViewport() { bool dxfRW::processViewport() {
@ -2360,7 +2481,8 @@ bool dxfRW::processViewport() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processPoint() { bool dxfRW::processPoint() {
@ -2381,7 +2503,8 @@ bool dxfRW::processPoint() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processLine() { bool dxfRW::processLine() {
@ -2402,7 +2525,8 @@ bool dxfRW::processLine() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processRay() { bool dxfRW::processRay() {
@ -2423,7 +2547,8 @@ bool dxfRW::processRay() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processXline() { bool dxfRW::processXline() {
@ -2444,7 +2569,8 @@ bool dxfRW::processXline() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processCircle() { bool dxfRW::processCircle() {
@ -2467,7 +2593,8 @@ bool dxfRW::processCircle() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processArc() { bool dxfRW::processArc() {
@ -2490,7 +2617,8 @@ bool dxfRW::processArc() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processInsert() { bool dxfRW::processInsert() {
@ -2511,7 +2639,8 @@ bool dxfRW::processInsert() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processLWPolyline() { bool dxfRW::processLWPolyline() {
@ -2534,7 +2663,8 @@ bool dxfRW::processLWPolyline() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processPolyline() { bool dxfRW::processPolyline() {
@ -2560,7 +2690,8 @@ bool dxfRW::processPolyline() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processVertex(DRW_Polyline *pl) { bool dxfRW::processVertex(DRW_Polyline *pl) {
@ -2586,7 +2717,8 @@ bool dxfRW::processVertex(DRW_Polyline *pl) {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processText() { bool dxfRW::processText() {
@ -2607,7 +2739,8 @@ bool dxfRW::processText() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processMText() { bool dxfRW::processMText() {
@ -2629,7 +2762,8 @@ bool dxfRW::processMText() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processHatch() { bool dxfRW::processHatch() {
@ -2650,7 +2784,8 @@ bool dxfRW::processHatch() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
@ -2672,7 +2807,8 @@ bool dxfRW::processSpline() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
@ -2694,7 +2830,8 @@ bool dxfRW::processImage() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
@ -2753,7 +2890,8 @@ bool dxfRW::processDimension() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
bool dxfRW::processLeader() { bool dxfRW::processLeader() {
@ -2774,7 +2912,8 @@ bool dxfRW::processLeader() {
break; break;
} }
} }
return true;
return setError(DRW::BAD_READ_ENTITIES);
} }
@ -2783,30 +2922,37 @@ bool dxfRW::processLeader() {
bool dxfRW::processObjects() { bool dxfRW::processObjects() {
DRW_DBG("dxfRW::processObjects\n"); DRW_DBG("dxfRW::processObjects\n");
int code; int code;
if (!reader->readRec(&code)){ if (!reader->readRec(&code) || 0 != code){
return false; return setError(DRW::BAD_READ_OBJECTS); //first record in objects must be 0
}
bool next = true;
if (code == 0) {
nextentity = reader->getString();
} else {
return false; //first record in objects is 0
}
do {
if (nextentity == "ENDSEC") {
return true; //found ENDSEC terminate
} else if (nextentity == "IMAGEDEF") {
processImageDef();
} else {
if (reader->readRec(&code)){
if (code == 0)
nextentity = reader->getString();
} else
return false; //end of file without ENDSEC
} }
} while (next); bool processed = false;
return true; nextentity = reader->getString();
do {
if ("ENDSEC" == nextentity) {
return true; //found ENDSEC terminate
}
if ("IMAGEDEF" == nextentity) {
processed = processImageDef();
}
else if ("PLOTSETTINGS" == nextentity) {
processed = processPlotSettings();
}
else {
if (!reader->readRec(&code)) {
return setError(DRW::BAD_READ_OBJECTS); //end of file without ENDSEC
}
if (code == 0) {
nextentity = reader->getString();
}
processed = true;
}
}
while (processed);
return setError(DRW::BAD_READ_OBJECTS);
} }
bool dxfRW::processImageDef() { bool dxfRW::processImageDef() {
@ -2827,6 +2973,41 @@ bool dxfRW::processImageDef() {
break; break;
} }
} }
return setError(DRW::BAD_READ_OBJECTS);
}
bool dxfRW::processPlotSettings() {
DRW_DBG("dxfRW::processPlotSettings");
int code;
DRW_PlotSettings ps;
while (reader->readRec(&code)) {
DRW_DBG(code); DRW_DBG("\n");
switch (code) {
case 0: {
nextentity = reader->getString();
DRW_DBG(nextentity); DRW_DBG("\n");
iface->addPlotSettings(&ps);
return true; //found new entity or ENDSEC, terminate
}
default:
ps.parseCode(code, reader);
break;
}
}
return setError(DRW::BAD_READ_OBJECTS);
}
bool dxfRW::writePlotSettings(DRW_PlotSettings *ent) {
writer->writeString(0, "PLOTSETTINGS");
writer->writeString(5, toHexStr(++entCount));
writer->writeString(100, "AcDbPlotSettings");
writer->writeUtf8String(6, ent->plotViewName);
writer->writeDouble(40, ent->marginLeft);
writer->writeDouble(41, ent->marginBottom);
writer->writeDouble(42, ent->marginRight);
writer->writeDouble(43, ent->marginTop);
return true; return true;
} }
@ -2844,3 +3025,18 @@ std::string dxfRW::toHexStr(int n){
return Convert.str(); return Convert.str();
#endif #endif
} }
DRW::Version dxfRW::getVersion() const {
return version;
}
DRW::error dxfRW::getError() const
{
return error;
}
bool dxfRW::setError(const DRW::error lastError)
{
error = lastError;
return (DRW::BAD_NONE == error);
}

View File

@ -71,9 +71,12 @@ public:
DRW_ImageDef *writeImage(DRW_Image *ent, const std::string &name); DRW_ImageDef *writeImage(DRW_Image *ent, const std::string &name);
bool writeLeader(DRW_Leader *ent); bool writeLeader(DRW_Leader *ent);
bool writeDimension(DRW_Dimension *ent); bool writeDimension(DRW_Dimension *ent);
void setEllipseParts(int parts){elParts = parts;} /*!< set parts munber when convert ellipse to polyline */ void setEllipseParts(int parts){elParts = parts;} /*!< set parts number when convert ellipse to polyline */
bool writePlotSettings(DRW_PlotSettings *ent);
std::string ErrorString() const; std::string ErrorString() const;
DRW::Version getVersion() const;
DRW::error getError() const;
private: private:
Q_DISABLE_COPY(dxfRW) Q_DISABLE_COPY(dxfRW)
@ -116,6 +119,7 @@ private:
bool processImageDef(); bool processImageDef();
bool processDimension(); bool processDimension();
bool processLeader(); bool processLeader();
bool processPlotSettings();
// bool writeHeader(); // bool writeHeader();
bool writeEntity(DRW_Entity *ent); bool writeEntity(DRW_Entity *ent);
@ -124,9 +128,13 @@ private:
bool writeObjects(); bool writeObjects();
bool writeExtData(const std::vector<DRW_Variant*> &ed); bool writeExtData(const std::vector<DRW_Variant*> &ed);
static std::string toHexStr(int n);//RLZ removeme static std::string toHexStr(int n);//RLZ removeme
bool writeAppData(const std::list<std::list<DRW_Variant>> &appData);
bool setError(const DRW::error lastError);
private: private:
DRW::Version version; DRW::Version version;
DRW::error error {DRW::BAD_NONE};
std::string fileName; std::string fileName;
std::string codePage; std::string codePage;
bool binFile; bool binFile;
@ -141,7 +149,7 @@ private:
bool dimstyleStd; bool dimstyleStd;
bool applyExt; bool applyExt;
bool writingBlock; bool writingBlock;
int elParts; /*!< parts munber when convert ellipse to polyline */ int elParts; /*!< parts number when convert ellipse to polyline */
std::unordered_map<std::string,int> blockMap; std::unordered_map<std::string,int> blockMap;
std::vector<DRW_ImageDef*> imageDef; /*!< imageDef list */ std::vector<DRW_ImageDef*> imageDef; /*!< imageDef list */

View File

@ -5,9 +5,9 @@
* This manual documents the use of <b>libdxfrw</b>. * This manual documents the use of <b>libdxfrw</b>.
* *
* With libdxfrw you can read and write several parts of a dxf files.<p> * With libdxfrw you can read and write several parts of a dxf files.<p>
* Dxf files can be written in assci and binary form, both are supported.<p> * Dxf files can be written in ascii and binary form, both are supported.<p>
* *
* the complete documentation and examples are pending to free time, * the complete documentation and examples are pending to free time,
* but to start see DRW_Interface, dxfRW clases * but to start see DRW_Interface, dxfRW classes
*/ */