|
| 1 | +/* |
| 2 | + * Copyright (C) 2014 Alfons Wirtz |
| 3 | + * website www.freerouting.net |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License at <http://www.gnu.org/licenses/> |
| 14 | + * for more details. |
| 15 | + * |
| 16 | + * AutorouteControl.java |
| 17 | + * |
| 18 | + * Created on 25. Januar 2004, 09:38 |
| 19 | + */ |
| 20 | +package autoroute; |
| 21 | + |
| 22 | +import geometry.planar.ConvexShape; |
| 23 | + |
| 24 | +import rules.ViaInfo; |
| 25 | +import rules.ViaRule; |
| 26 | + |
| 27 | +import board.RoutingBoard; |
| 28 | + |
| 29 | +/** |
| 30 | + * Structure for controlling the autoroute algorithm. |
| 31 | + * |
| 32 | + * @author Alfons Wirtz |
| 33 | + */ |
| 34 | +public class AutorouteControl |
| 35 | +{ |
| 36 | + |
| 37 | + /** Creates a new instance of AutorouteControl for the input net */ |
| 38 | + public AutorouteControl(RoutingBoard p_board, int p_net_no, interactive.Settings p_settings) |
| 39 | + { |
| 40 | + this(p_board, p_settings, p_settings.autoroute_settings.get_trace_cost_arr()); |
| 41 | + init_net(p_net_no, p_board, p_settings.autoroute_settings.get_via_costs()); |
| 42 | + } |
| 43 | + |
| 44 | + /** Creates a new instance of AutorouteControl for the input net */ |
| 45 | + public AutorouteControl(RoutingBoard p_board, int p_net_no, interactive.Settings p_settings, int p_via_costs, ExpansionCostFactor[] p_trace_cost_arr) |
| 46 | + { |
| 47 | + this(p_board, p_settings, p_trace_cost_arr); |
| 48 | + init_net(p_net_no, p_board, p_via_costs); |
| 49 | + } |
| 50 | + |
| 51 | + /** Creates a new instance of AutorouteControl */ |
| 52 | + private AutorouteControl(RoutingBoard p_board, interactive.Settings p_settings, |
| 53 | + ExpansionCostFactor[] p_trace_costs_arr) |
| 54 | + { |
| 55 | + layer_count = p_board.get_layer_count(); |
| 56 | + trace_half_width = new int[layer_count]; |
| 57 | + compensated_trace_half_width = new int[layer_count]; |
| 58 | + layer_active = new boolean[layer_count]; |
| 59 | + vias_allowed = p_settings.autoroute_settings.get_vias_allowed(); |
| 60 | + via_radius_arr = new double[layer_count]; |
| 61 | + add_via_costs = new ViaCost[layer_count]; |
| 62 | + |
| 63 | + for (int i = 0; i < layer_count; ++i) |
| 64 | + { |
| 65 | + add_via_costs[i] = new ViaCost(layer_count); |
| 66 | + layer_active[i] = p_settings.autoroute_settings.get_layer_active(i); |
| 67 | + } |
| 68 | + is_fanout = false; |
| 69 | + remove_unconnected_vias = true; |
| 70 | + with_neckdown = p_settings.get_automatic_neckdown(); |
| 71 | + tidy_region_width = Integer.MAX_VALUE; |
| 72 | + pull_tight_accuracy = 500; |
| 73 | + max_shove_trace_recursion_depth = 20; |
| 74 | + max_shove_via_recursion_depth = 5; |
| 75 | + max_spring_over_recursion_depth = 5; |
| 76 | + for (int i = 0; i < layer_count; ++i) |
| 77 | + { |
| 78 | + for (int j = 0; j < layer_count; ++j) |
| 79 | + { |
| 80 | + add_via_costs[i].to_layer[j] = 0; |
| 81 | + } |
| 82 | + } |
| 83 | + trace_costs = p_trace_costs_arr; |
| 84 | + attach_smd_allowed = false; |
| 85 | + via_lower_bound = 0; |
| 86 | + via_upper_bound = layer_count; |
| 87 | + |
| 88 | + ripup_allowed = false; |
| 89 | + ripup_costs = 1000; |
| 90 | + ripup_pass_no = 1; |
| 91 | + } |
| 92 | + |
| 93 | + private void init_net(int p_net_no, RoutingBoard p_board, int p_via_costs) |
| 94 | + { |
| 95 | + net_no = p_net_no; |
| 96 | + rules.Net curr_net = p_board.rules.nets.get(p_net_no); |
| 97 | + rules.NetClass curr_net_class; |
| 98 | + if (curr_net != null) |
| 99 | + { |
| 100 | + curr_net_class = curr_net.get_class(); |
| 101 | + trace_clearance_class_no = curr_net_class.get_trace_clearance_class(); |
| 102 | + via_rule = curr_net_class.get_via_rule(); |
| 103 | + } |
| 104 | + else |
| 105 | + { |
| 106 | + trace_clearance_class_no = 1; |
| 107 | + via_rule = p_board.rules.via_rules.firstElement(); |
| 108 | + curr_net_class = null; |
| 109 | + } |
| 110 | + for (int i = 0; i < layer_count; ++i) |
| 111 | + { |
| 112 | + if (net_no > 0) |
| 113 | + { |
| 114 | + trace_half_width[i] = p_board.rules.get_trace_half_width(net_no, i); |
| 115 | + } |
| 116 | + else |
| 117 | + { |
| 118 | + trace_half_width[i] = p_board.rules.get_trace_half_width(1, i); |
| 119 | + } |
| 120 | + compensated_trace_half_width[i] = trace_half_width[i] + p_board.rules.clearance_matrix.clearance_compensation_value(trace_clearance_class_no, i); |
| 121 | + if (curr_net_class != null && !curr_net_class.is_active_routing_layer(i)) |
| 122 | + { |
| 123 | + layer_active[i] = false; |
| 124 | + } |
| 125 | + } |
| 126 | + if (via_rule.via_count() > 0) |
| 127 | + { |
| 128 | + this.via_clearance_class = via_rule.get_via(0).get_clearance_class(); |
| 129 | + } |
| 130 | + else |
| 131 | + { |
| 132 | + this.via_clearance_class = 1; |
| 133 | + } |
| 134 | + this.via_info_arr = new ViaMask[via_rule.via_count()]; |
| 135 | + for (int i = 0; i < via_rule.via_count(); ++i) |
| 136 | + { |
| 137 | + ViaInfo curr_via = via_rule.get_via(i); |
| 138 | + if (curr_via.attach_smd_allowed()) |
| 139 | + { |
| 140 | + this.attach_smd_allowed = true; |
| 141 | + } |
| 142 | + library.Padstack curr_via_padstack = curr_via.get_padstack(); |
| 143 | + int from_layer = curr_via_padstack.from_layer(); |
| 144 | + int to_layer = curr_via_padstack.to_layer(); |
| 145 | + for (int j = from_layer; j <= to_layer; ++j) |
| 146 | + { |
| 147 | + ConvexShape curr_shape = curr_via_padstack.get_shape(j); |
| 148 | + double curr_radius; |
| 149 | + if( curr_shape != null) |
| 150 | + { |
| 151 | + curr_radius = 0.5 * curr_shape.max_width(); |
| 152 | + } |
| 153 | + else |
| 154 | + { |
| 155 | + curr_radius = 0; |
| 156 | + } |
| 157 | + this.via_radius_arr[j] = Math.max(this.via_radius_arr[j], curr_radius); |
| 158 | + } |
| 159 | + via_info_arr[i] = new ViaMask(from_layer, to_layer, curr_via.attach_smd_allowed()); |
| 160 | + } |
| 161 | + for (int j = 0; j < this.layer_count; ++j) |
| 162 | + { |
| 163 | + this.via_radius_arr[j] = Math.max(this.via_radius_arr[j], trace_half_width[j]); |
| 164 | + this.max_via_radius = Math.max(this.max_via_radius, this.via_radius_arr[j]); |
| 165 | + } |
| 166 | + double via_cost_factor = this.max_via_radius; |
| 167 | + via_cost_factor = Math.max(via_cost_factor, 1); |
| 168 | + min_normal_via_cost = p_via_costs * via_cost_factor; |
| 169 | + min_cheap_via_cost = 0.8 * min_normal_via_cost; |
| 170 | + } |
| 171 | + final int layer_count; |
| 172 | + /** The horizontal and vertical trace costs on each layer */ |
| 173 | + public final ExpansionCostFactor[] trace_costs; |
| 174 | + /** Defines for each layer, if it may used for routing. */ |
| 175 | + final boolean[] layer_active; |
| 176 | + /** The currently used net number in the autoroute algorithm */ |
| 177 | + int net_no; |
| 178 | + /** The currently used trace half widths in the autoroute algorithm on each layer */ |
| 179 | + final int[] trace_half_width; |
| 180 | + /** |
| 181 | + * The currently used compensated trace half widths in the autoroute algorithm on each layer. |
| 182 | + * Equal to trace_half_width if no clearance compensation is used. |
| 183 | + */ |
| 184 | + final int[] compensated_trace_half_width; |
| 185 | + /** The currently used clearance class for traces in the autoroute algorithm */ |
| 186 | + public int trace_clearance_class_no; |
| 187 | + /** The currently used clearance class for vias in the autoroute algorithm */ |
| 188 | + int via_clearance_class; |
| 189 | + /** The possible (partial) vias, which can be used by the autorouter */ |
| 190 | + ViaRule via_rule; |
| 191 | + /** The array of possible via ranges used bei the autorouter */ |
| 192 | + ViaMask[] via_info_arr; |
| 193 | + /** The lower bound for the first layer of vias */ |
| 194 | + int via_lower_bound; |
| 195 | + /** The upper bound for the last layer of vias */ |
| 196 | + int via_upper_bound; |
| 197 | + final double[] via_radius_arr; |
| 198 | + double max_via_radius; |
| 199 | + /** The width of the region around changed traces, where traces are pulled tight */ |
| 200 | + int tidy_region_width; |
| 201 | + /** The pull tight accuracy of traces*/ |
| 202 | + int pull_tight_accuracy; |
| 203 | + /** The maximum recursion depth for shoving traces */ |
| 204 | + int max_shove_trace_recursion_depth; |
| 205 | + /** The maximum recursion depth for shoving obstacles */ |
| 206 | + int max_shove_via_recursion_depth; |
| 207 | + /** The maximum recursion depth for traces springing over obstacles */ |
| 208 | + int max_spring_over_recursion_depth; |
| 209 | + /** True, if layer change by inserting of vias is allowed */ |
| 210 | + public boolean vias_allowed; |
| 211 | + /** True, if vias may drill to the pad of SMD pins */ |
| 212 | + public boolean attach_smd_allowed; |
| 213 | + /** the additiomal costs to min_normal via_cost for inserting a via between 2 layers */ |
| 214 | + final ViaCost[] add_via_costs; |
| 215 | + /** The minimum cost valua of all normal vias */ |
| 216 | + public double min_normal_via_cost; |
| 217 | + /** The minimal cost value of all cheap vias */ |
| 218 | + double min_cheap_via_cost; |
| 219 | + public boolean ripup_allowed; |
| 220 | + public int ripup_costs; |
| 221 | + public int ripup_pass_no; |
| 222 | + public final boolean with_neckdown; |
| 223 | + /** If true, the autoroute algorithm completes after the first drill */ |
| 224 | + public boolean is_fanout; |
| 225 | + /** |
| 226 | + * Normally true, if the autorouter contains no fanout pass |
| 227 | + */ |
| 228 | + public boolean remove_unconnected_vias; |
| 229 | + |
| 230 | + /** horizontal and vertical costs for traces on a board layer */ |
| 231 | + public static class ExpansionCostFactor |
| 232 | + { |
| 233 | + |
| 234 | + public ExpansionCostFactor(double p_horizontal, double p_vertical) |
| 235 | + { |
| 236 | + horizontal = p_horizontal; |
| 237 | + vertical = p_vertical; |
| 238 | + } |
| 239 | + /** The horizontal expansion cost factor on a layer of the board */ |
| 240 | + public final double horizontal; |
| 241 | + /** The verical expansion cost factor on a layer of the board */ |
| 242 | + public final double vertical; |
| 243 | + } |
| 244 | + |
| 245 | + /** Array of via costs from one layer to the other layers */ |
| 246 | + static class ViaCost |
| 247 | + { |
| 248 | + |
| 249 | + private ViaCost(int p_layer_count) |
| 250 | + { |
| 251 | + to_layer = new int[p_layer_count]; |
| 252 | + } |
| 253 | + public int[] to_layer; |
| 254 | + } |
| 255 | + |
| 256 | + static class ViaMask |
| 257 | + { |
| 258 | + |
| 259 | + ViaMask(int p_from_layer, int p_to_layer, boolean p_attach_smd_allowed) |
| 260 | + { |
| 261 | + from_layer = p_from_layer; |
| 262 | + to_layer = p_to_layer; |
| 263 | + attach_smd_allowed = p_attach_smd_allowed; |
| 264 | + } |
| 265 | + final int from_layer; |
| 266 | + final int to_layer; |
| 267 | + final boolean attach_smd_allowed; |
| 268 | + } |
| 269 | +} |
0 commit comments