Work on this project has not moved over to a new project: https://github.com/rena0157/Dxflib
dxflib::cadfile c_file{"Path.dxf"}; // Load file
// Iterate through all of the hatches in the file and print
// the handle of the hatch, its perimeter and its area:
for (const auto& hatch : c_file.get_hatches())
{
std::cout << "Hatch: " << hatch.get_handle()
<< "perimeter: " << hatch.get_perimeter() <<
<< "area: " << hatch.get_area() << "\n";
}
DxfLib++ is a library that parses and extracts data from AutoCAD dxf files and builds them into C++ classes.
The dxflib::entities::entity base class is the parent class for all entities in the library. Properties and
methods:
explicit entity(entity_buffer_base&);: default dxf constructor.- This constructer uses the
entity_buffer_baseclass which is created in the parsing function during dxf
extraction. The use of this constructor out of this scope is proably not very common.
- This constructer uses the
explicit entity();: Default Constructor.
const std::string& get_handle() const: returns the entityhandle_const std::string& get_soft_pointer() const: returns the entitysoft_pointer_const std::string& get_layer() const;: returns the entitylayer_const utilities::color& get_color() const;returns the entitycolor_
std::string layer_;: The layer that the entity or derived class is on in the dxf file.std::string handle;: The handle of the entity.std::string soft_pointer_;: The soft pointer (Handle of another entity) of the entity.std::color_name_;NOT IMPLEMENTEDint raw_color_;: raw color of the entity. Extracted from a 24-bit hex color codeutilities::color color_: Color of the entity. The custom color class is used here.
Derived Class
Vertex ---> point_base
The point base class is the parent class for the vertex. There are really not that many differences between the two at this point. That said I felt that the point_base did not warrent its own subsection.
explicit vertex(double x = 0, double y = 0, double z = 0);: Default and only Constructor for the vertex class.
double x, y, z;: Cartesian Coordinates for the vertexfriend std::ostream& operator<<;: Operator overload for printing.
Derived Class
class line : public entity;
LINE is the DxfLib++ library implementation of the LINE entity in AutoCAD DXF. The line entity is a 3D line that is defined by two points.
explicit line(line_buf&): Default dxf line constructor
const vertex& get_vertex(int id) const;: returnsvertexby idvoid move_vertex(int id, const vertex& new_vertex);: moves thevertex(id) to
a new position(new_vertex). The Line will then update thelength_.double get_thickness() const;: returns the thickness of the linelwpolyline to_lwpolyline() const;converts the line into alwpolylineand then
returns a copy of thatlwpolyline. Note: Depending on the implementation and optimization
The newlwpolylinemight be moved to the new location.
vertex v0_;: The startingvertexof the line.vertex v1_;: The endingvertexof the line.double thickness_;The thickness of the line.double length_;: The total length of the line fromv0_tov1_
#include "dxflib++/cadfile.h"
int main()
{
// Create the cadfile
dxflib::cadfile c_file{"Path to DXF file"};
// extract a line from the cadfile
dxflib::entities::line line {c_file.get_lines()[0]};
}
Geoline = Geometric line. The geometric line is more or less the same as the LINE class. The only difference is that the geoline is not a derived class of the Entity class. This makes the geoline class more compact and usefull for geometric calculations. A geoline can also be polymorphic in the sense that it can either be an arc or a line.
static constexpr int bulge_null{-2};value used to determine wether a geoline is an arc or a line. if the bulge of a geoline isgeoline::bulge_null;then the geoline is a straight line.static std::vector<geoline> geoline_binder(const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& bulge, bool is_closed);: Function that takes three vectors, an x vector, a y vector and a bulge vector. The Funciton then "binds" the vectors into points and then into geolines. The return is a geoline vector.- Will throw an
std::invalid_argumentexception if the input vectors are not the same length.
- Will throw an
explicit geoline(const vertex& v0, const vertex& v1, double bulge = bulge_null);the default constructor. Takes in twovertexobjects and a default parameter
const vertex& operator[](int id) const;: Returns a vertex by its id.vertex& operator[](int id);Overload of above with a non const reference.
inline double get_length() const;: Returns the total length of the geoline.double get_bulge() const;Returns the bulge of the geolinedouble get_area() const;: Returns the area between the geoline and the x-axisinline double get_radius() const;: Returns the radius of the geoline. Will returnINFifbulge_== bulge_null.inline double get_angle() const;: Returns the total angle between the two legs of the arc. Will returnINFifbulge_ == bulge_null.std::ostream& operator<<;: Overload operator for printing geolines.
vertex v0_;: Startingvertexof the geolinevertex v1_;: Endingvertexof the geolinedouble bulge_;: Bulge of the geolinedouble length_;: Total length of the geolinedouble radius_;: Radius of the geoline if it is an arc segmentdouble total_angle_;: Total angle of the geoline if it is an arc.double area_;: Total area between the geoline and the x-axis