forked from LibreCAD/libdxfrw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dx_iface.cpp
131 lines (125 loc) · 4.4 KB
/
dx_iface.cpp
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
/******************************************************************************
** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) **
** **
** Copyright (C) 2015 José F. Soriano, [email protected] **
** **
** 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/>. **
******************************************************************************/
#include <iostream>
#include <algorithm>
#include "dx_iface.h"
#include "libdwgr.h"
#include "libdxfrw.h"
bool dx_iface::fileImport(const std::string& fileI, dx_data *fData, bool debug){
unsigned int found = fileI.find_last_of(".");
std::string fileExt = fileI.substr(found+1);
std::transform(fileExt.begin(), fileExt.end(),fileExt.begin(), ::toupper);
cData = fData;
currentBlock = cData->mBlock;
if (fileExt == "DXF"){
//loads dxf
dxfRW* dxf = new dxfRW(fileI.c_str());
if (debug) {
dxf->setDebug(DRW::DebugLevel::Debug);
}
bool success = dxf->read(this, false);
if (!success) {
std::cout << "DXF file error: format " << dxf->getVersion() << " error " << dxf->getError() << std::endl;
}
delete dxf;
return success;
} else if (fileExt == "DWG"){
//loads dwg
dwgR* dwg = new dwgR(fileI.c_str());
if (debug) {
dwg->setDebug(DRW::DebugLevel::Debug);
}
bool success = dwg->read(this, false);
if (!success) {
std::cout << "DWG file error: format " << dwg->getVersion() << " error " << dwg->getError() << std::endl;
}
delete dwg;
return success;
}
std::cout << "file extension can be dxf or dwg" << std::endl;
return false;
}
bool dx_iface::fileExport(const std::string& file, DRW::Version v, bool binary, dx_data *fData, bool debug){
cData = fData;
dxfW = new dxfRW(file.c_str());
if (debug) {
dxfW->setDebug(DRW::DebugLevel::Debug);
}
bool success = dxfW->write(this, v, binary);
delete dxfW;
return success;
}
void dx_iface::writeEntity(DRW_Entity* e){
switch (e->eType) {
case DRW::POINT:
dxfW->writePoint(static_cast<DRW_Point*>(e));
break;
case DRW::LINE:
dxfW->writeLine(static_cast<DRW_Line*>(e));
break;
case DRW::CIRCLE:
dxfW->writeCircle(static_cast<DRW_Circle*>(e));
break;
case DRW::ARC:
dxfW->writeArc(static_cast<DRW_Arc*>(e));
break;
case DRW::SOLID:
dxfW->writeSolid(static_cast<DRW_Solid*>(e));
break;
case DRW::ELLIPSE:
dxfW->writeEllipse(static_cast<DRW_Ellipse*>(e));
break;
case DRW::LWPOLYLINE:
dxfW->writeLWPolyline(static_cast<DRW_LWPolyline*>(e));
break;
case DRW::POLYLINE:
dxfW->writePolyline(static_cast<DRW_Polyline*>(e));
break;
case DRW::SPLINE:
dxfW->writeSpline(static_cast<DRW_Spline*>(e));
break;
// case RS2::EntitySplinePoints:
// writeSplinePoints(static_cast<DRW_Point*>(e));
// break;
// case RS2::EntityVertex:
// break;
case DRW::INSERT:
dxfW->writeInsert(static_cast<DRW_Insert*>(e));
break;
case DRW::MTEXT:
dxfW->writeMText(static_cast<DRW_MText*>(e));
break;
case DRW::TEXT:
dxfW->writeText(static_cast<DRW_Text*>(e));
break;
case DRW::DIMLINEAR:
case DRW::DIMALIGNED:
case DRW::DIMANGULAR:
case DRW::DIMANGULAR3P:
case DRW::DIMRADIAL:
case DRW::DIMDIAMETRIC:
case DRW::DIMORDINATE:
dxfW->writeDimension(static_cast<DRW_Dimension*>(e));
break;
case DRW::LEADER:
dxfW->writeLeader(static_cast<DRW_Leader*>(e));
break;
case DRW::HATCH:
dxfW->writeHatch(static_cast<DRW_Hatch*>(e));
break;
case DRW::IMAGE:
dxfW->writeImage(static_cast<DRW_Image*>(e), static_cast<dx_ifaceImg*>(e)->path);
break;
default:
break;
}
}