-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHoleClass.cpp
More file actions
155 lines (130 loc) · 3.84 KB
/
HoleClass.cpp
File metadata and controls
155 lines (130 loc) · 3.84 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
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
/*
* HoleClass.cpp
____ ________.___._______ .___ ____ ___ _____
\ \/ /\__ | |\ \ | | | \/ \
\ / / | |/ | \| | | / \ / \
/ \ \____ / | \ | | / Y \
/___/\ \ / ______\____|__ /___|______/\____|__ /
\_/ \/ \/ \/
Mai 2018
convertis les fichiers Gerber en Gcode
Po les fichiers issu de kicad
Traite le fichier .drl carte de percage
*/
#include "PNGerber.hpp"
#include <string.h>
#include <vector>
using namespace std;
cHole::cHole(void) {
iHasDrill = 1;
iMirror = MIRROR;
dpO= {0,0};
dpE= {0,0};
}
//Lit le fichier and build a vector of x y pos
// return 0 si OK or error code else
int cHole::ReadDrl(string filename) {
string sLgnChamp[40];
double daTool[NAPPERT]; // Aperture a 7 champs
char cL;
string linebuffer;
unsigned int iPos, iType, iOrder;
int iTool;
int iHasBeenTiTd;
string sX, sY;
string sXX, sYY;
std::size_t found;
std::ifstream infile(filename.c_str()); // open an input file stream
iTool = 0;
while (infile && getline(infile, linebuffer)) {
if (linebuffer.length() == 0)
continue;
for (int ic = 0; ic < 10; ic++)
sLgnChamp[ic] = "";
iPos = 0; // num ordre char dans la lgn
iType = 2; // type Change d'etat selon Fig / Num ou %
iOrder = 0; // numero d'ordre du champ sur la lgn
sLgnChamp[0] = "";
while (iPos < linebuffer.size()) { // parse
cL = linebuffer[iPos];
if ((cL == '%') && (iPos == 0)) {
sLgnChamp[iOrder] = cL;
//iOrder++; le champ % ne sert a rien les commandes se distinguent seule
sLgnChamp[iOrder] = "";
} else {
if (((cL < 58) && (cL > 47)) || (cL == '-') || (cL == '+')) { // Numeric
if (iType == 0) {
iOrder++; // chg de champ
sLgnChamp[iOrder] = "";
}
iType = 1;
sLgnChamp[iOrder] += (cL);
} else {
if (iType == 1) {
iOrder++; // chg de champ
sLgnChamp[iOrder] = "";
}
iType = 0;
sLgnChamp[iOrder] += cL;
}
}
iPos++;
} // fin du parsing dans le tab sLgnChamp les differants champs de la lgn en char ou num
iHasBeenTiTd = 0;
found = sLgnChamp[0].find("METRIC");
if (found != std::string::npos) {
iHasBeenTiTd = 1;
std::cout << "in drill file METRIC OK" << std::endl;
}
found = sLgnChamp[0].find("INCH");
if (found != std::string::npos) {
iHasBeenTiTd = 1;
std::cout << std::endl << "Drill file in INCH no one use it" << std::endl;
return 1;
}
if (sLgnChamp[0][0] == 'T') { //Si T contien diam percage
iHasBeenTiTd = 1;
iTool = stoi(sLgnChamp[1]);
if (sLgnChamp[2] == "C") { // declaration d'un diametre
sX = sLgnChamp[3] + "." + sLgnChamp[5];
daTool[iTool] = stod(sX);
}
}
if ((sLgnChamp[0][0] == 'M') && (sLgnChamp[1][0] == '3') && (sLgnChamp[1][1] == '0')) { //M30 fin drill file
iHasBeenTiTd = 1;
std::cout << std::endl << "End of drill file reached" << std::endl;
return 0;
}
if (sLgnChamp[0][0] == 'X') { // lgn de coordonée enregistre les coord
string sXN, sYN;
Row tery;
iHasBeenTiTd = 1;
sX = sLgnChamp[1] + "." + sLgnChamp[3];
sY = sLgnChamp[5] + "." + sLgnChamp[7];
double dXb = stod(sX);
double dYb = stod(sY);
dXb -= dpO.dXp;
tery.push_back(dXb);
if (iMirror == 0)
dYb = dYb - dpO.dYp;
else
dYb = dpE.dYp - dYb;
tery.push_back(dYb);
tery.push_back(daTool[iTool]);
mdHole.push_back(tery);
}
if (iHasBeenTiTd == 0) { // La lgn n'as pas été traitée pb
//debug std::cout << "Ligne drill non Traitée : " << linebuffer << std::endl;
//return 1;
}
}
return 1;
}
// find if a drill at pos dX dY return diamter or 0 if not
double cHole::DrillAtPos(double dX, double dY) {
for (unsigned int in = 0; in < mdHole.size(); in++) {
if ((fabs(mdHole[in][0] - dX) < DHOLETOL) && (fabs(mdHole[in][1] - dY) < DHOLETOL))
return mdHole[in][2];
}
return 0.0;
}