/
Tooltable.cpp
279 lines (239 loc) · 8.9 KB
/
Tooltable.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/***************************************************************************
* Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Exception.h>
#include "Tooltable.h"
using namespace Base;
using namespace Path;
// TOOL
TYPESYSTEM_SOURCE(Path::Tool , Base::Persistence);
// Constructors & destructors
Tool::Tool(const char* name,
ToolType type,
ToolMaterial /*material*/,
double diameter,
double lengthoffset,
double flatradius,
double cornerradius,
double cuttingedgeangle,
double cuttingedgeheight)
:Name(name),Type(type),Diameter(diameter),LengthOffset(lengthoffset),
FlatRadius(flatradius),CornerRadius(cornerradius),CuttingEdgeAngle(cuttingedgeangle),
CuttingEdgeHeight(cuttingedgeheight)
{
}
Tool::Tool()
{
}
Tool::~Tool()
{
}
// Reimplemented from base class
unsigned int Tool::getMemSize (void) const
{
return 0;
}
void Tool::Save (Writer &writer) const
{
writer.Stream() << writer.ind() << "<Tool "
<< "name=\"" << Name << "\" "
<< "diameter=\"" << Diameter << "\" "
<< "length=\"" << LengthOffset << "\" "
<< "flat=\"" << FlatRadius << "\" "
<< "corner=\"" << CornerRadius << "\" "
<< "angle=\"" << CuttingEdgeAngle << "\" "
<< "height=\"" << CuttingEdgeHeight << "\" ";
if(Type == Tool::ENDMILL)
writer.Stream() << " type=\"EndMill\" ";
else if(Type == Tool::DRILL)
writer.Stream() << " type=\"Drill\" ";
else if(Type == Tool::CENTERDRILL)
writer.Stream() << " type=\"CenterDrill\" ";
else if(Type == Tool::COUNTERSINK)
writer.Stream() << " type=\"CounterSink\" ";
else if(Type == Tool::COUNTERBORE)
writer.Stream() << " type=\"CounterBore\" ";
else if(Type == Tool::REAMER)
writer.Stream() << " type=\"Reamer\" ";
else if(Type == Tool::TAP)
writer.Stream() << " type=\"Tap\" ";
else if(Type == Tool::SLOTCUTTER)
writer.Stream() << " type=\"SlotCutter\" ";
else if(Type == Tool::BALLENDMILL)
writer.Stream() << " type=\"BallEndMill\" ";
else if(Type == Tool::CHAMFERMILL)
writer.Stream() << " type=\"ChamferMill\" ";
else if(Type == Tool::CORNERROUND)
writer.Stream() << " type=\"CornerRound\" ";
else if(Type == Tool::ENGRAVER)
writer.Stream() << " type=\"Engraver\" ";
else
writer.Stream() << " type=\"Undefined\" ";
if(Material == Tool::CARBIDE)
writer.Stream() << " mat=\"Carbide\" /> ";
else if(Material == Tool::HIGHSPEEDSTEEL)
writer.Stream() << " mat=\"HighSpeedSteel\" /> ";
else if(Material == Tool::HIGHCARBONTOOLSTEEL)
writer.Stream() << " mat=\"HighCarbonToolSteel\" /> ";
else if(Material == Tool::CASTALLOY)
writer.Stream() << " mat=\"CastAlloy\" /> ";
else if(Material == Tool::CERAMICS)
writer.Stream() << " mat=\"Ceramics\" /> ";
else if(Material == Tool::DIAMOND)
writer.Stream() << " mat=\"Diamond\" /> ";
else if(Material == Tool::SIALON)
writer.Stream() << " mat=\"Sialon\" /> ";
else
writer.Stream() << " mat=\"Undefined\" /> ";
writer.Stream()<< std::endl;
}
void Tool::Restore(XMLReader &reader)
{
reader.readElement("Tool");
Name = reader.getAttribute("name");
Diameter = (double) reader.getAttributeAsFloat("diameter");
LengthOffset = (double) reader.getAttributeAsFloat("length");
FlatRadius = (double) reader.getAttributeAsFloat("flat");
CornerRadius = (double) reader.getAttributeAsFloat("corner");
CuttingEdgeAngle = (double) reader.getAttributeAsFloat("angle");
CuttingEdgeHeight = (double) reader.getAttributeAsFloat("height");
std::string type = reader.getAttribute("type");
if(type=="EndMill")
Type = Tool::ENDMILL;
else if(type=="Drill")
Type = Tool::DRILL;
else if(type=="CenterDrill")
Type = Tool::CENTERDRILL;
else if(type=="CounterSink")
Type = Tool::COUNTERSINK;
else if(type=="CounterBore")
Type = Tool::COUNTERBORE;
else if(type=="Reamer")
Type = Tool::REAMER;
else if(type=="Tap")
Type = Tool::TAP;
else if(type=="SlotCutter")
Type = Tool::SLOTCUTTER;
else if(type=="BallEndMill")
Type = Tool::BALLENDMILL;
else if(type=="ChamferMill")
Type = Tool::CHAMFERMILL;
else if(type=="CornerRound")
Type = Tool::CORNERROUND;
else if(type=="Engraver")
Type = Tool::ENGRAVER;
else
Type = Tool::UNDEFINED;
std::string mat = reader.getAttribute("mat");
if(mat=="Carbide")
Material = Tool::CARBIDE;
else if(mat=="HighSpeedSteel")
Material = Tool::HIGHSPEEDSTEEL;
else if(mat=="HighCarbonToolSteel")
Material = Tool::HIGHCARBONTOOLSTEEL;
else if(mat=="CastAlloy")
Material = Tool::CASTALLOY;
else if(mat=="Ceramics")
Material = Tool::CERAMICS;
else if(mat=="Diamond")
Material = Tool::DIAMOND;
else if(mat=="Sialon")
Material = Tool::SIALON;
else
Material = Tool::MATUNDEFINED;
}
// TOOLTABLE
TYPESYSTEM_SOURCE(Path::Tooltable , Base::Persistence);
Tooltable::Tooltable()
{
}
Tooltable::~Tooltable()
{
}
void Tooltable::addTool(const Tool &tool)
{
Tool *tmp = new Tool(tool);
if (!Tools.empty()) {
int max = 0;
for(std::map<int,Tool*>::const_iterator i = Tools.begin(); i != Tools.end(); ++i) {
int k = i->first;
if (k > max)
max = k;
}
Tools[max+1]= tmp;
} else
Tools[1] = tmp;
}
void Tooltable::setTool(const Tool &tool, int pos)
{
if (pos == -1) {
addTool(tool);
} else {
Tool *tmp = new Tool(tool);
Tools[pos] = tmp;
}
}
void Tooltable::deleteTool(int pos)
{
if (Tools.find(pos) != Tools.end()) {
Tools.erase(pos);
} else {
throw Base::Exception("Index not found");
}
}
unsigned int Tooltable::getMemSize (void) const
{
return 0;
}
void Tooltable::Save (Writer &writer) const
{
writer.Stream() << writer.ind() << "<Tooltable count=\"" << getSize() <<"\">" << std::endl;
writer.incInd();
for(std::map<int,Tool*>::const_iterator i = Tools.begin(); i != Tools.end(); ++i) {
int k = i->first;
Tool *v = i->second;
writer.Stream() << writer.ind() << "<Toolslot number=\"" << k << "\">" << std::endl;
writer.incInd();
v->Save(writer);
writer.decInd();
writer.Stream() << writer.ind() << "</Toolslot>" << std::endl;
}
writer.decInd();
writer.Stream() << writer.ind() << "</Tooltable>" << std::endl ;
}
void Tooltable::Restore (XMLReader &reader)
{
Tools.clear();
reader.readElement("Tooltable");
int count = reader.getAttributeAsInteger("count");
for (int i = 0; i < count; i++) {
reader.readElement("Toolslot");
int id = reader.getAttributeAsInteger("number");
Tool *tmp = new Tool();
tmp->Restore(reader);
Tools[id] = tmp;
}
}