-
-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathReader.cpp
More file actions
129 lines (87 loc) · 3.6 KB
/
Reader.cpp
File metadata and controls
129 lines (87 loc) · 3.6 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
/******************************************************************************\
CAMotics is an Open-Source simulation and CAM software.
Copyright (C) 2011-2019 Joseph Coffland <joseph@cauldrondevelopment.com>
This program is free software: you can redistribute it and/or modify
it 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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
\******************************************************************************/
#include "Reader.h"
#include "Point.h"
#include "Arc.h"
#include "Line.h"
#include "PolyLine.h"
#include "Spline.h"
#include <dxflib/dl_dxf.h>
#include <cbang/log/Logger.h>
using namespace cb;
using namespace DXF;
void Reader::read(const InputSource &source) {
SmartPointer<DL_Dxf> dxf = new DL_Dxf;
if (!dxf->in(source.getStream(), this))
THROW("Failed to read '" << source << "' as DXF");
}
void Reader::addEntity(const SmartPointer<Entity> &entity) {
if (inBlock) return; // TODO handle blocks
auto layer = attributes.getLayer();
layers_t::iterator it = layers.find(layer);
if (it == layers.end())
it = layers.insert(layers_t::value_type(layer, layer_t())).first;
it->second.push_back(entity);
}
void Reader::addLayer(const DL_LayerData &data) {
LOG_DEBUG(3, "Adding DXF layer " << data.name);
layers[data.name] = layer_t();
}
void Reader::addPoint(const DL_PointData &point) {
addEntity(new Point(cb::Vector3D(point.x, point.y, point.z)));
}
void Reader::addLine(const DL_LineData &line) {
addEntity(new Line(cb::Vector3D(line.x1, line.y1, line.z1),
cb::Vector3D(line.x2, line.y2, line.z2)));
}
void Reader::addArc(const DL_ArcData &arc) {
addEntity(new Arc(cb::Vector3D(arc.cx, arc.cy, arc.cz), arc.radius,
arc.angle1, arc.angle2,
0 < getExtrusion()->getDirection()[2]));
}
void Reader::addCircle(const DL_CircleData &circle) {
addEntity(new Arc(cb::Vector3D(circle.cx, circle.cy, circle.cz),
circle.radius, 0, 360, true));
}
void Reader::addPolyline(const DL_PolylineData &polyline) {
if (!entity.isNull()) THROW("DXF Already in DXF entity");
addEntity(entity = new PolyLine(polyline.flags));
}
void Reader::addVertex(const DL_VertexData &vertex) {
if (vertex.bulge) LOG_WARNING("Cannot handle vertex with bulge");
entity->addVertex(cb::Vector3D(vertex.x, vertex.y, vertex.z));
}
void Reader::addSpline(const DL_SplineData &spline) {
if (!entity.isNull()) THROW("DXF Already in DXF entity");
addEntity(entity = new Spline(spline.degree, spline.flags));
}
void Reader::addControlPoint(const DL_ControlPointData &ctrlPt) {
entity->addVertex(cb::Vector3D(ctrlPt.x, ctrlPt.y, ctrlPt.z), ctrlPt.w);
}
void Reader::addKnot(const DL_KnotData &knot) {
entity->addKnot(knot.k);
}
void Reader::addEllipse(const DL_EllipseData &ellipse) {
if (warnEllipse) LOG_WARNING("DXF Ellipse not supported");
warnEllipse = false;
}
void Reader::add3dFace(const DL_3dFaceData &face) {
if (warn3DFace) LOG_WARNING("DXF 3D Face not supported");
warn3DFace = false;
}
void Reader::addSolid(const DL_SolidData &solid) {
if (warnSolid) LOG_WARNING("DXF Solid not supported");
warnSolid = false;
}