-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdrw_header.h
More file actions
141 lines (124 loc) · 4.95 KB
/
drw_header.h
File metadata and controls
141 lines (124 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/******************************************************************************
** libDXFrw - Library to read/write DXF files (ascii & binary) **
** **
** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) **
** 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 <memory>
#include <unordered_map>
#include "drw_base.h"
class dxfReader;
class dxfWriter;
class dwgBuffer;
#define SETHDRFRIENDS friend class dxfRW; \
friend class dwgReader;
//! Class to handle header entries
/*!
* Class to handle header vars, to read iterate over "std::unordered_map vars"
* to write add a DRW_Variant* into "std::unordered_map vars" (do not delete it, are cleared in dtor)
* or use add* helper functions.
* @author Rallaz
*/
class DRW_Header {
SETHDRFRIENDS
public:
DRW_Header();
~DRW_Header() {
clearVars();
}
enum Units {
/** $ISUNITS header variable, since ACAD2000/AC1015 */
None = 0, ///< No unit (unit from parent)
Inch = 1, ///< 25.4 mm
Foot = 2, ///< 12 Inches = 0.3048 m
Mile = 3, ///< 1760 Yards = 1609 m
Millimeter = 4, ///< 0.001 m
Centimeter = 5, ///< 0.01 m
Meter = 6,
Kilometer = 7, ///< 1000 m
Microinch = 8, ///< 0.000001 Inch = 0.0000254 mm = 25.4 Nanometer
Mil = 9, ///< 0.001 Inch = 0.0254 mm = 25.4 Micron
Yard = 10, ///< 3 Feet = 0.9144 m
Angstrom = 11, ///< 10^-10 m
Nanometer = 12, ///< 10^-9 m
Micron = 13, ///< 10^-6 m
Decimeter = 14, ///< 0.1 m
Decameter = 15, ///< 10 m
Hectometer = 16, ///< 100 m
Gigameter = 17, ///< 10^9 m
Astro = 18, ///< ~149.6 x 10^9 m
Lightyear = 19, ///< ~9.46 x 10^15 m
Parsec = 20, ///< ~3.0857 x 10^16 m
UnitCount = 21, ///< Used to iterate through units
/** $MEASUREMENT header variable, since R14/AC1014 */
English = 0, ///< English/Imperial drawing */
Metric = 1, ///< Metric drawing */
};
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) );
}
this->curr = NULL;
}
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) );
}
}
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(const std::unique_ptr<dxfWriter>& writer, DRW::Version ver);
void addComment(std::string c);
protected:
bool parseCode(int code, const std::unique_ptr<dxfReader>& reader);
bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf, duint8 mv=0);
private:
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();
}
public:
std::unordered_map<std::string,DRW_Variant*> vars;
private:
std::string comments;
std::string name;
DRW_Variant* curr {nullptr};
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;
int measurement(const int unit);
};
#endif
// EOF