Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions drill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void ExcellonProcessor::export_ngc(const string of_dir, const boost::optional<st
"M2 (Program end.)\n\n");

map<int, drillbit> bits = optimize_bits();
const map<int, multi_linestring_type_fp> holes = optimize_holes(bits, onedrill, boost::none, min_milldrill_diameter);
const auto holes = optimize_holes(bits, onedrill, boost::none, min_milldrill_diameter);

//open output file
std::ofstream of;
Expand Down Expand Up @@ -573,7 +573,8 @@ void ExcellonProcessor::export_ngc(const string of_dir, const boost::optional<st
"M2 (Program end.)\n\n");

map<int, drillbit> bits = parsed_bits;
const map<int, multi_linestring_type_fp> holes = optimize_holes(bits, false, min_milldrill_diameter, boost::none);
const auto holes =
optimize_holes(bits, false, min_milldrill_diameter, boost::none);

// open output file
std::ofstream of;
Expand Down Expand Up @@ -620,7 +621,7 @@ void ExcellonProcessor::export_ngc(const string of_dir, const boost::optional<st
of << "G53 ";
}
of << "G00 Z" << target->zchange * cfactor << " (Retract to tool change height)\n"
<< "T" << (*holes.begin()).first << "\n"
<< "T" << (holes.size() > 0 ? (*holes.begin()).first : 0) << "\n"
<< "M5 (Spindle stop.)\n"
<< "G04 P" << target->spindown_time << "\n"
<< "(MSG, Change tool bit to drill size " << (bMetricOutput ? (target->tool_diameter * 25.4) : target->tool_diameter) << (bMetricOutput ? "mm" : "inch") << ")\n"
Expand Down Expand Up @@ -681,7 +682,8 @@ void ExcellonProcessor::export_ngc(const string of_dir, const boost::optional<st
*/
/******************************************************************************/
void ExcellonProcessor::save_svg(
const map<int, drillbit>& bits, const map<int, multi_linestring_type_fp>& holes,
const map<int, drillbit>& bits,
const vector<pair<int, multi_linestring_type_fp>>& holes,
const string& of_dir, const string& of_name) {
if (holes.size() == 0) {
return;
Expand Down Expand Up @@ -772,7 +774,7 @@ map<int, multi_linestring_type_fp> ExcellonProcessor::parse_holes() {
Optimisation of the hole path with a TSP Nearest Neighbour algorithm
*/
/******************************************************************************/
map<int, multi_linestring_type_fp> ExcellonProcessor::optimize_holes(
vector<pair<int, multi_linestring_type_fp>> ExcellonProcessor::optimize_holes(
map<int, drillbit>& bits, bool onedrill,
const boost::optional<Length>& min_diameter,
const boost::optional<Length>& max_diameter) {
Expand Down Expand Up @@ -836,7 +838,16 @@ map<int, multi_linestring_type_fp> ExcellonProcessor::optimize_holes(
}
}

return holes;
// Sort the holes in ascending drill size order.
// vector<pair<int, multi_linestring_type_fp>> sorted_holes(holes.cbegin(), holes.cend());
vector<pair<int, multi_linestring_type_fp>> sorted_holes(holes.cbegin(), holes.cend());

std::sort(sorted_holes.begin(), sorted_holes.end(), [&bits](const auto& a, const auto& b) {
return bits[a.first].as_length().asInch(1) < bits[b.first].as_length().asInch(1);
});


return sorted_holes;
}

/******************************************************************************/
Expand Down
10 changes: 6 additions & 4 deletions drill.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ class ExcellonProcessor
double get_yvalue(double);
std::string drill_to_string(drillbit drillbit);

std::map<int, multi_linestring_type_fp> optimize_holes(std::map<int, drillbit>& bits, bool onedrill,
const boost::optional<Length>& min_diameter,
const boost::optional<Length>& max_diameter);
std::vector<std::pair<int, multi_linestring_type_fp>> optimize_holes(
std::map<int, drillbit>& bits, bool onedrill,
const boost::optional<Length>& min_diameter,
const boost::optional<Length>& max_diameter);
std::map<int, drillbit> optimize_bits();

void save_svg(
const std::map<int, drillbit>& bits, const std::map<int, multi_linestring_type_fp>& holes,
const std::map<int, drillbit>& bits,
const std::vector<std::pair<int, multi_linestring_type_fp>>& holes,
const std::string& of_dir, const std::string& of_name);

const box_type_fp board_dimensions;
Expand Down
12 changes: 6 additions & 6 deletions testing/gerbv_example/milldrilldiatest/expected/drill.ngc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ G90 (Absolute coordinates.)
G00 S10000 (RPM spindle speed.)

G00 Z10.00000 (Retract)
T1
T9
M5 (Spindle stop.)
G04 P1.00000
(MSG, Change tool bit to drill size 0.4mm)
Expand All @@ -21,12 +21,12 @@ M3 (Spindle on clockwise.)
G0 Z1.50000
G04 P1.00000

G81 R1.50000 Z-1.75000 F100.00000 X120.00000 Y-90.00000
X120.00000 Y-92.54000
G81 R1.50000 Z-1.75000 F100.00000 X120.00000 Y-92.54000
X120.00000 Y-90.00000
G80

G00 Z10.00000 (Retract)
T3
T8
M5 (Spindle stop.)
G04 P1.00000
(MSG, Change tool bit to drill size 0.6mm)
Expand All @@ -40,7 +40,7 @@ G81 R1.50000 Z-1.75000 F100.00000 X120.00000 Y-95.08000
G80

G00 Z10.00000 (Retract)
T4
T7
M5 (Spindle stop.)
G04 P1.00000
(MSG, Change tool bit to drill size 0.8mm)
Expand All @@ -54,7 +54,7 @@ G81 R1.50000 Z-1.75000 F100.00000 X120.00000 Y-97.62000
G80

G00 Z10.00000 (Retract)
T5
T6
M5 (Spindle stop.)
G04 P1.00000
(MSG, Change tool bit to drill size 1mm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ S2000 (RPM spindle speed.)

G01 F600.00000 (Feedrate)
G00 Z10.00000 (Retract to tool change height)
T6
T5
M5 (Spindle stop.)
G04 P1.00000
(MSG, Change tool bit to drill size 1.00000mm)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions testing/gerbv_example/milldrilldiatest/milldrilldiatest.drl
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ M48
;FORMAT={-:-/ absolute / metric / decimal}
FMAT,2
METRIC,TZ
T1C0.200
T2C0.400
T3C0.600
T4C0.800
T5C1.000
T6C1.200
T7C1.400
T8C1.600
T9C1.800
T10C2.000
T10C0.200
T9C0.400
T8C0.600
T7C0.800
T6C1.000
T5C1.200
T4C1.400
T3C1.600
T2C1.800
T1C2.000
%
G90
G05
M71
T1
T10
X120.Y-90.
T2
T9
X120.Y-92.54
T3
T8
X120.Y-95.08
T4
T7
X120.Y-97.62
T5
X120.Y-100.16
T6
X120.Y-100.16
T5
X130.16Y-90.
T7
T4
X130.16Y-92.54
T8
T3
X130.16Y-95.08
T9
T2
X130.16Y-97.62
T10
T1
X130.16Y-100.16
T0
M30