103091658b6cfea3f42904330cdabd53d184fb6a
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

1) /* drawing (DXF) to G-code (NGC) converter
2)  * Copyright 2013 Stefan Schuermans <stefan@schuermans.info>
Stefan Schuermans license CC-BY-SA --> GPL (m...

Stefan Schuermans authored 11 years ago

3)  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

4)  */
5) 
6) #include <dime/Input.h>
7) #include <dime/Model.h>
8) #include <iostream>
9) #include <map>
10) #include <string>
11) 
12) #include "drawing.h"
13) #include "layer.h"
14) #include "traverse.h"
15) 
16) /**
17)  * @brief clear all contents of drawing
18)  */
19) void Drawing::clear()
20) {
21)   mLayers.clear();
22) }
23) 
24) /**
25)  * @brief add a DXF file to this drawing
26)  * @param[in] strFileName name of the DXF file to read
Stefan Schuermans implement finer approximati...

Stefan Schuermans authored 11 years ago

27)  * @param[in] precision precision for entity to lines conversion
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

28)  * @return if the DXF file could be read
29)  */
Stefan Schuermans implement finer approximati...

Stefan Schuermans authored 11 years ago

30) bool Drawing::addDxf(const std::string &strFileName, double precision)
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

31) {
32)   // read DXF file
33)   dimeInput in;
34)   if (!in.setFile(strFileName.c_str())) {
35)     std::cerr << "error opening file \"" << strFileName
36)               << "\" for reading" << std::endl;
37)     return false;
38)   }
39)   dimeModel model;
40)   if (!model.read(&in)) {
41)     std::cerr << "DXF read error in line " << in.getFilePosition()
42)               << " of file \"" << strFileName << "\""
43)               << std::endl;
44)     return false;
45)   }
46) 
47)   // enumerate all entities and add them to drawing
48)   struct traverse_ctx ctx;
Stefan Schuermans implement finer approximati...

Stefan Schuermans authored 11 years ago

49)   ctx.precision = precision;
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

50)   ctx.mpDrawing = this;
51)   model.traverseEntities(traverse_entity, &ctx);
52) 
53)   return true;
54) }
55) 
56) /**
57)  * @brief load a DXF file to this drawing
58)  * @param[in] strFileName name of the DXF file to read
Stefan Schuermans implement finer approximati...

Stefan Schuermans authored 11 years ago

59)  * @param[in] precision precision for entity to lines conversion
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

60)  * @return if the DXF file could be read
61)  */
Stefan Schuermans implement finer approximati...

Stefan Schuermans authored 11 years ago

62) bool Drawing::loadDxf(const std::string &strFileName, double precision)
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

63) {
64)   clear();
Stefan Schuermans implement finer approximati...

Stefan Schuermans authored 11 years ago

65)   return addDxf(strFileName, precision);
Stefan Schuermans initial version, DXFs can b...

Stefan Schuermans authored 11 years ago

66) }
67)