2017-06-20 10:40:39 +02:00
|
|
|
/******************************************************************************
|
|
|
|
** libDXFrw - Library to read/write DXF files (ascii & binary) **
|
|
|
|
** **
|
2022-02-07 13:52:41 +01:00
|
|
|
** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) **
|
2017-06-20 10:40:39 +02:00
|
|
|
** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com **
|
|
|
|
** **
|
|
|
|
** This library is free software, licensed under the terms of the GNU **
|
|
|
|
** General Public License as published by the Free Software Foundation, **
|
|
|
|
** either version 2 of the License, or (at your option) any later version. **
|
|
|
|
** You should have received a copy of the GNU General Public License **
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef DRW_HEADER_H
|
|
|
|
#define DRW_HEADER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include "drw_base.h"
|
|
|
|
|
|
|
|
class dxfReader;
|
|
|
|
class dxfWriter;
|
|
|
|
|
2017-07-06 13:10:14 +02:00
|
|
|
#define SETHDRFRIENDS friend class dxfRW;
|
2017-06-20 10:40:39 +02:00
|
|
|
|
|
|
|
//! Class to handle header entries
|
|
|
|
/*!
|
|
|
|
* Class to handle header vars, to read iterate over "std::map vars"
|
|
|
|
* to write add a DRW_Variant* into "std::map vars" (do not delete it, are cleared in dtor)
|
|
|
|
* or use add* helper functions.
|
|
|
|
* @author Rallaz
|
|
|
|
*/
|
|
|
|
class DRW_Header {
|
|
|
|
SETHDRFRIENDS
|
|
|
|
public:
|
|
|
|
DRW_Header();
|
2017-07-05 18:35:34 +02:00
|
|
|
|
2017-06-20 10:40:39 +02:00
|
|
|
~DRW_Header() {
|
|
|
|
clearVars();
|
|
|
|
}
|
|
|
|
|
2017-07-05 18:35:34 +02:00
|
|
|
DRW_Header(const DRW_Header& h)
|
|
|
|
: vars(),
|
|
|
|
comments(h.comments),
|
|
|
|
name(),
|
|
|
|
curr(nullptr),
|
|
|
|
version(h.version),
|
|
|
|
linetypeCtrl(),
|
|
|
|
layerCtrl(),
|
|
|
|
styleCtrl(),
|
|
|
|
dimstyleCtrl(),
|
|
|
|
appidCtrl(),
|
|
|
|
blockCtrl(),
|
|
|
|
viewCtrl(),
|
|
|
|
ucsCtrl(),
|
|
|
|
vportCtrl(),
|
|
|
|
vpEntHeaderCtrl()
|
|
|
|
{
|
2021-11-23 10:15:11 +01:00
|
|
|
for (auto it=h.vars.begin(); it!=h.vars.end(); ++it)
|
2017-07-05 18:35:34 +02:00
|
|
|
{
|
2017-06-20 10:40:39 +02:00
|
|
|
this->vars[it->first] = new DRW_Variant( *(it->second) );
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 18:35:34 +02:00
|
|
|
DRW_Header& operator=(const DRW_Header &h)
|
|
|
|
{
|
|
|
|
if(this != &h)
|
|
|
|
{
|
2017-06-20 10:40:39 +02:00
|
|
|
clearVars();
|
|
|
|
this->version = h.version;
|
|
|
|
this->comments = h.comments;
|
2021-11-23 10:15:11 +01:00
|
|
|
for (auto it=h.vars.begin(); it!=h.vars.end(); ++it)
|
2017-07-05 18:35:34 +02:00
|
|
|
{
|
2017-06-20 10:40:39 +02:00
|
|
|
this->vars[it->first] = new DRW_Variant( *(it->second) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addDouble(std::string key, double value, int code);
|
|
|
|
void addInt(std::string key, int value, int code);
|
2022-08-08 14:25:14 +02:00
|
|
|
void addStr(std::string key, const std::string &value, int code);
|
|
|
|
void addCoord(std::string key, const DRW_Coord &value, int code);
|
2017-06-20 10:40:39 +02:00
|
|
|
std::string getComments() const {return comments;}
|
|
|
|
void write(dxfWriter *writer, DRW::Version ver);
|
2017-07-06 11:58:26 +02:00
|
|
|
void addComment(const std::string &c);
|
2017-06-20 10:40:39 +02:00
|
|
|
|
|
|
|
protected:
|
2022-02-07 13:52:41 +01:00
|
|
|
bool parseCode(int code, dxfReader *reader);
|
2017-06-20 10:40:39 +02:00
|
|
|
private:
|
2022-08-08 14:25:14 +02:00
|
|
|
bool getDouble(const std::string &key, double *varDouble);
|
|
|
|
bool getInt(const std::string &key, int *varInt);
|
|
|
|
bool getStr(const std::string &key, std::string *varStr);
|
|
|
|
bool getCoord(const std::string &key, DRW_Coord *varCoord);
|
2017-07-05 18:35:34 +02:00
|
|
|
void clearVars()
|
|
|
|
{
|
2021-11-23 10:15:11 +01:00
|
|
|
for (auto it=vars.begin(); it!=vars.end(); ++it)
|
|
|
|
{
|
2017-06-20 10:40:39 +02:00
|
|
|
delete it->second;
|
2021-11-23 10:15:11 +01:00
|
|
|
}
|
2017-06-20 10:40:39 +02:00
|
|
|
|
|
|
|
vars.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-11-23 10:15:11 +01:00
|
|
|
std::unordered_map<std::string,DRW_Variant*> vars;
|
2017-06-20 10:40:39 +02:00
|
|
|
private:
|
|
|
|
std::string comments;
|
|
|
|
std::string name;
|
2021-11-23 13:43:26 +01:00
|
|
|
DRW_Variant* curr {nullptr};
|
2017-06-20 10:40:39 +02:00
|
|
|
int version; //to use on read
|
|
|
|
|
|
|
|
duint32 linetypeCtrl;
|
|
|
|
duint32 layerCtrl;
|
|
|
|
duint32 styleCtrl;
|
|
|
|
duint32 dimstyleCtrl;
|
|
|
|
duint32 appidCtrl;
|
|
|
|
duint32 blockCtrl;
|
|
|
|
duint32 viewCtrl;
|
|
|
|
duint32 ucsCtrl;
|
|
|
|
duint32 vportCtrl;
|
|
|
|
duint32 vpEntHeaderCtrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// EOF
|