| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef DRW_HEADER_H |
| #define DRW_HEADER_H |
|
|
|
|
| #include <unordered_map> |
| #include "drw_base.h" |
|
|
| class dxfReader; |
| class dxfWriter; |
| class dwgBuffer; |
|
|
| #define SETHDRFRIENDS friend class dxfRW; \ |
| friend class dwgReader; |
|
|
| |
| |
| |
| |
| |
| |
| |
| class DRW_Header : public DRW_ParseableEntity{ |
| SETHDRFRIENDS |
| public: |
| DRW_Header(); |
| ~DRW_Header() override { |
| clearVars(); |
| } |
|
|
| enum Units { |
| |
| None = 0, |
| Inch = 1, |
| Foot = 2, |
| Mile = 3, |
| Millimeter = 4, |
| Centimeter = 5, |
| Meter = 6, |
| Kilometer = 7, |
| Microinch = 8, |
| Mil = 9, |
| Yard = 10, |
| Angstrom = 11, |
| Nanometer = 12, |
| Micron = 13, |
| Decimeter = 14, |
| Decameter = 15, |
| Hectometer = 16, |
| Gigameter = 17, |
| Astro = 18, |
| Lightyear = 19, |
| Parsec = 20, |
| UnitCount = 21, |
|
|
| |
| English = 0, |
| Metric = 1, |
| }; |
|
|
| DRW_Header(const DRW_Header& h){ |
| this->version = h.version; |
| this->comments = h.comments; |
| for (auto it=h.vars.begin(); it!=h.vars.end(); ++it){ |
| this->vars[it->first] = new DRW_Variant( *(it->second) ); |
| } |
| for (auto it=h.customVars.begin(); it!=h.customVars.end(); ++it){ |
| this->customVars[it->first] = new DRW_Variant( *(it->second) ); |
| } |
| this->curr = nullptr; |
| } |
| DRW_Header& operator=(const DRW_Header &h) { |
| if(this != &h) { |
| clearVars(); |
| this->version = h.version; |
| this->comments = h.comments; |
| for (auto it=h.vars.begin(); it!=h.vars.end(); ++it){ |
| this->vars[it->first] = new DRW_Variant( *(it->second) ); |
| } |
|
|
| for (auto it=h.customVars.begin(); it!=h.customVars.end(); ++it){ |
| this->customVars[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); |
| void addStr(std::string key, std::string value, int code); |
| void addCoord(std::string key, DRW_Coord value, int code); |
| std::string getComments() const {return comments;} |
| void write(dxfWriter *writer, DRW::Version ver); |
| void addComment(std::string c); |
| bool parseCode(int code, dxfReader *reader) override; |
| std::unordered_map<std::string,DRW_Variant*> vars; |
| std::unordered_map<std::string,DRW_Variant*> customVars; |
| static int measurement(const int unit); |
| protected: |
| void writeVar(dxfWriter* writer, std::string name, double defaultValue, int varCode = 40); |
| void writeVar(dxfWriter* writer, std::string name, int defaultValue, int varCode = 70); |
| void writeVar(dxfWriter* writer, DRW::Version ver, std::string name, std::string defaultValue="", int varCode = 1); |
| void writeDimVars(dxfWriter* writer, DRW::Version ver); |
| bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf, duint8 mv=0); |
| private: |
| std::string comments; |
| std::string name; |
| DRW_Variant* curr {nullptr}; |
| enum WaitingFor { |
| VARIABLE_VALUE, |
| CUSTOM_VAR_NAME, |
| CUSTOM_VAR_VALUE |
| }; |
| WaitingFor waitingFor = VARIABLE_VALUE; |
| std::string currentCustomVarName{""}; |
| int version; |
|
|
| duint32 linetypeCtrl; |
| duint32 layerCtrl; |
| duint32 styleCtrl; |
| duint32 dimstyleCtrl; |
| duint32 appidCtrl; |
| duint32 blockCtrl; |
| duint32 viewCtrl; |
| duint32 ucsCtrl; |
| duint32 vportCtrl; |
| duint32 vpEntHeaderCtrl; |
|
|
| bool getDouble(std::string key, double *varDouble); |
| bool getInt(std::string key, int *varInt); |
| bool getStr(std::string key, std::string *varStr); |
| bool getCoord(std::string key, DRW_Coord *varStr); |
|
|
| void clearVars(){ |
| for (auto it=vars.begin(); it!=vars.end(); ++it) |
| delete it->second; |
|
|
| vars.clear(); |
|
|
| for (auto it=customVars.begin(); it!=customVars.end(); ++it) |
| delete it->second; |
|
|
| customVars.clear(); |
| } |
| }; |
|
|
| #endif |
|
|