pcb_component_position() can now be passed an index to differentiate between

multiple components of the same type.

Added pcb_grid_pos() function.
This commit is contained in:
Chris Palmer 2019-11-15 13:30:27 +00:00
parent 53f416eef1
commit 6f93b6af9a
2 changed files with 13 additions and 9 deletions

View File

@ -1682,8 +1682,9 @@ PCBs and perfboard with optional components. The shape can be a rectangle with o
### Functions
| Function | Description |
|:--- |:--- |
| ```pcb_component_position(type, name)``` | Return x y position of specified component |
| ```pcb_component_position(type, name, index = 0)``` | Return x y position of specified component |
| ```pcb_coord(type, p)``` | Convert offsets from the edge to coordinates relative to the centre |
| ```pcb_grid_pos(type, x, y, z = 0)``` | Returns a pcb grid position |
| ```pcb_screw(type, cap = hs_cap)``` | Mounting screw type |
### Modules
@ -1703,7 +1704,7 @@ PCBs and perfboard with optional components. The shape can be a rectangle with o
| ```pcb_component_position(type, name)``` | Position child at the specified component position |
| ```pcb_components(type, cutouts = false, angle = undef)``` | Draw list of PCB components on the PCB |
| ```pcb_cutouts(type, angle = undef)``` | Make cut outs to clear components on a PCB |
| ```pcb_grid(type, x, y, z = 0)``` | Positions children at specified grid positions |
| ```pcb_grid(type, x, y, z = 0)``` | Positions children at specified grid position |
| ```pcb_screw_positions(type)``` | Positions children at the mounting hole positions |
| ```pcb_spacer(screw, height, wall = 1.8, taper = 0)``` | Generate STL for PCB spacer |
| ```rj45(cutout = false)``` | Draw RJ45 Ethernet connector |

View File

@ -49,9 +49,12 @@ function pcb_grid(type) = type[13]; //! Grid if a perfboard
function pcb_polygon(type) = type[14]; //! Optional outline polygon for odd shaped boards
function pcb_screw(type, cap = hs_cap) = Len(type[15]) ? type[15] : find_screw(cap, screw_smaller_than(pcb_hole_d(type))); //! Mounting screw type
module pcb_grid(type, x, y, z = 0) //! Positions children at specified grid positions
translate([-pcb_length(type) / 2 + pcb_grid(type).x + 2.54 * x,
-pcb_width(type) / 2 + pcb_grid(type).y + 2.54 * y, pcb_thickness(type) + z])
function pcb_grid_pos(type, x, y, z = 0) = //! Returns a pcb grid position
[-pcb_length(type) / 2 + pcb_grid(type).x + 2.54 * x,
-pcb_width(type) / 2 + pcb_grid(type).y + 2.54 * y, pcb_thickness(type) + z];
module pcb_grid(type, x, y, z = 0) //! Positions children at specified grid position
translate(pcb_grid_pos(type, x, y, z))
children();
// allows negative ordinates to represent offsets from the far edge
@ -730,8 +733,8 @@ module pcb_component(comp, cutouts = false, angle = undef) { //! Draw pcb compon
}
}
function pcb_component_position(type, name) = //! Return x y position of specified component
[for(comp = pcb_components(type), p = [pcb_coord(type, [comp.x, comp.y])]) if(comp[3] == name) [p.x, p.y]][0];
function pcb_component_position(type, name, index = 0) = //! Return x y position of specified component
[for(comp = pcb_components(type), p = [pcb_coord(type, [comp.x, comp.y])]) if(comp[3] == name) [p.x, p.y]][index];
module pcb_component_position(type, name) { //! Position child at the specified component position
for(comp = pcb_components(type)) {
@ -807,9 +810,9 @@ module pcb(type) { //! Draw specified PCB
pcb_screw_positions(type)
tube(or = max(pcb_land_d(type), 1) / 2, ir = pcb_hole_d(type) / 2, h = t + 2 * eps);
fr4 = pcb_colour(type) == "green";
fr4 = pcb_colour(type) != "sienna";
plating = 0.15;
color(fr4 ? "silver" : "gold")
color(pcb_colour(type) == "green" ? "silver" : "gold")
translate_z(-plating)
linear_extrude(height = fr4 ? t + 2 * plating : plating)
if(Len(grid)) {