1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-01-16 13:08:15 +01:00

Module blurb parenthesis parsing is now greedy to handle args that default to function calls.

This means that library modules cannot be one liners.
This commit is contained in:
Chris Palmer 2021-09-27 16:17:08 +01:00
parent c6b280f0e8
commit 4993c3e82d
12 changed files with 86 additions and 36 deletions

View File

@ -50,9 +50,10 @@ eps = 1/128; // small fudge factor to stop CSG barfing on coincident faces.
$fa = 6;
$fs = extrusion_width / 2;
function round_to_layer(z) = ceil(z / layer_height) * layer_height;
function round_to_layer(z) = ceil(z / layer_height) * layer_height; //! Round up to a multiple of layer_height.
// Some additional named colours
function grey(n) = [0.01, 0.01, 0.01] * n; //! Generate a shade of grey to pass to color().
function grey(n) = [0.01, 0.01, 0.01] * n; //! Generate a shade of grey to pass to color().
silver = [0.75, 0.75, 0.75];
gold = [255, 215, 0] / 255;
brass = [255, 220, 100] / 255;

View File

@ -588,9 +588,26 @@ module box_back_blank(type, sheet = false) { //! Generates a 2D template for the
sheet_2D(subst_sheet(type, sheet), box_width(type) - sheet_reduction(type), box_height(type) - sheet_reduction(type), 1);
}
module box_base(type) render_2D_sheet(box_base_sheet(type)) box_base_blank(type); //! Default base, can be overridden to customise
module box_top(type) render_2D_sheet(box_top_sheet(type)) box_top_blank(type); //! Default top, can be overridden to customise
module box_back(type) render_2D_sheet(box_sheets(type)) box_back_blank(type); //! Default back, can be overridden to customise
module box_front(type) render_2D_sheet(box_sheets(type)) box_front_blank(type); //! Default front, can be overridden to customise
module box_left(type) render_2D_sheet(box_sheets(type)) box_left_blank(type); //! Default left side, can be overridden to customise
module box_right(type) render_2D_sheet(box_sheets(type)) box_right_blank(type); //! Default right side, can be overridden to customise
module box_base(type) //! Default base, can be overridden to customise
render_2D_sheet(box_base_sheet(type))
box_base_blank(type);
module box_top(type) //! Default top, can be overridden to customise
render_2D_sheet(box_top_sheet(type))
box_top_blank(type);
module box_back(type) //! Default back, can be overridden to customise
render_2D_sheet(box_sheets(type))
box_back_blank(type);
module box_front(type) //! Default front, can be overridden to customise
render_2D_sheet(box_sheets(type))
box_front_blank(type);
module box_left(type) //! Default left side, can be overridden to customise
render_2D_sheet(box_sheets(type))
box_left_blank(type);
module box_right(type) //! Default right side, can be overridden to customise
render_2D_sheet(box_sheets(type))
box_right_blank(type);

View File

@ -198,12 +198,29 @@ module bbox_back_blank(type, sheet = false) { //! 2D template for the back
}
}
module bbox_base(type) render_2D_sheet(bbox_base_sheet(type)) bbox_base_blank(type); //! Default base, can be overridden to customise
module bbox_top(type) render_2D_sheet(bbox_top_sheet(type)) bbox_top_blank(type); //! Default top, can be overridden to customise
module bbox_back(type) render_2D_sheet(bbox_sheets(type)) bbox_back_blank(type); //! Default back, can be overridden to customise
module bbox_front(type) render_2D_sheet(bbox_sheets(type)) bbox_front_blank(type); //! Default front, can be overridden to customise
module bbox_left(type) render_2D_sheet(bbox_sheets(type)) bbox_left_blank(type); //! Default left side, can be overridden to customise
module bbox_right(type) render_2D_sheet(bbox_sheets(type)) bbox_right_blank(type); //! Default right side, can be overridden to customise
module bbox_base(type) //! Default base, can be overridden to customise
render_2D_sheet(bbox_base_sheet(type))
bbox_base_blank(type);
module bbox_top(type) //! Default top, can be overridden to customise
render_2D_sheet(bbox_top_sheet(type))
bbox_top_blank(type);
module bbox_back(type) //! Default back, can be overridden to customise
render_2D_sheet(bbox_sheets(type))
bbox_back_blank(type);
module bbox_front(type) //! Default front, can be overridden to customise
render_2D_sheet(bbox_sheets(type))
bbox_front_blank(type);
module bbox_left(type) //! Default left side, can be overridden to customise
render_2D_sheet(bbox_sheets(type))
bbox_left_blank(type);
module bbox_right(type) //! Default right side, can be overridden to customise
render_2D_sheet(bbox_sheets(type))
bbox_right_blank(type);
module _bbox_assembly(type, top = true, base = true, left = true, right = true, back = true, front = true) { //! The box assembly, wrap with a local copy without parameters
width = bbox_width(type);

View File

@ -105,7 +105,8 @@ module fixing_block(screw = def_screw) { //! Generate the STL
}
}
module fixing_block_assembly(screw = def_screw) pose([55, 180, 25], [0, 4.8, 4.8]) //! Printed part with the inserts inserted
module fixing_block_assembly(screw = def_screw) //! Printed part with the inserts inserted
pose([55, 180, 25], [0, 4.8, 4.8])
assembly(str("fixing_block_M", 20 * screw_radius(screw)), ngb = true) {
translate_z(fixing_block_height(screw))
rotate([0, 180, 0])

View File

@ -79,7 +79,8 @@ module handle_stl() { //! generate the STL
//
//! Place inserts in the bottom of the posts and push them home with a soldering iron with a conical bit heated to 200°C.
//
module handle_assembly() pose([225, 0, 150], [0, 0, 14]) //! Printed part with inserts in place
module handle_assembly() //! Printed part with inserts in place
pose([225, 0, 150], [0, 0, 14])
assembly("handle", ngb = true) {
translate_z(handle_height())
stl_colour(pp1_colour) vflip() handle_stl();

View File

@ -81,8 +81,9 @@ module ribbon_clamp(ways, screw = screw) { //! Generate STL for given number of
}
}
module ribbon_clamp_assembly(ways, screw = screw) pose([55, 180, 25]) //! Printed part with inserts in place
assembly(let(screw_d = screw_radius(screw) * 2)str("ribbon_clamp_", ways, screw_d != 3 ? str("_", screw_d) : ""), ngb = true) {
module ribbon_clamp_assembly(ways, screw = screw) //! Printed part with inserts in place
pose([55, 180, 25])
assembly(let(screw_d = screw_radius(screw) * 2)str("ribbon_clamp_", ways, screw_d != 3 ? str("_", screw_d) : ""), ngb = true) {
h = ribbon_clamp_height(screw);
insert = screw_insert(screw);

View File

@ -71,8 +71,8 @@ A list of changes classified as breaking, additions or fixes is maintained in [C
### Modules
| Module | Description |
|:--- |:--- |
| `7_segment_digit(type, colour = grey(95)` | Draw the specified 7 segment digit |
| `7_segment_digits(type, n, colour = grey(70)` | Draw n digits side by side |
| `7_segment_digit(type, colour = grey(95), pin_length = 6.4)` | Draw the specified 7 segment digit |
| `7_segment_digits(type, n, colour = grey(70), pin_length = 6.4, cutout = false)` | Draw n digits side by side |
![7_segments](tests/png/7_segments.png)
@ -343,7 +343,7 @@ Individual teeth are not drawn, instead they are represented by a lighter colour
### Modules
| Module | Description |
|:--- |:--- |
| `belt(type, points, belt_colour = grey(20)` | Draw a belt path given a set of points and pitch radii where the pulleys are. Closed loop unless open is specified |
| `belt(type, points, belt_colour = grey(20), tooth_colour = grey(50), open = false, twist = undef, auto_twist = false, start_twist = false)` | Draw a belt path given a set of points and pitch radii where the pulleys are. Closed loop unless open is specified |
![belts](tests/png/belts.png)
@ -909,7 +909,7 @@ Dual inline IC packages and sockets
| Module | Description |
|:--- |:--- |
| `dip(n, part, size, w, pitch, pin)` | Draw DIP package |
| `pdip(pins, part, socketed, w = inch(0.3)` | Draw standard 0.1" PDIP IC package |
| `pdip(pins, part, socketed, w = inch(0.3), pitch = inch(0.1))` | Draw standard 0.1" PDIP IC package |
| `pdip_pin(type, l, end)` | Draw a pin |
![dip](tests/png/dip.png)
@ -3013,10 +3013,10 @@ Linear rails with carriages.
### Modules
| Module | Description |
|:--- |:--- |
| `carriage(type, end_colour = grey(20)` | Draw the specified carriage |
| `carriage(type, end_colour = grey(20), wiper_colour = grey(20))` | Draw the specified carriage |
| `carriage_hole_positions(type)` | Position children over screw holes |
| `rail(type, length, colour = grey(90)` | Draw the specified rail |
| `rail_assembly(carriage, length, pos, carriage_end_colour = grey(20)` | Rail and carriage assembly |
| `rail(type, length, colour = grey(90), use_polycircles = false)` | Draw the specified rail |
| `rail_assembly(carriage, length, pos, carriage_end_colour = grey(20), carriage_wiper_colour = grey(20))` | Rail and carriage assembly |
| `rail_hole_positions(type, length, first = 0, screws = 100, both_ends = true)` | Position children over screw holes |
| `rail_screws(type, length, thickness, screws = 100, index_screws = undef)` | Place screws in the rail |
@ -4977,7 +4977,7 @@ The ring spacing as well as the number of spokes can be specified, if zero a gas
### Modules
| Module | Description |
|:--- |:--- |
| `fan_guard(type, name = false, thickness = fan_guard_thickness()` | Generate the STL |
| `fan_guard(type, name = false, thickness = fan_guard_thickness(), spokes = 4, finger_width = 7, grill = false, screws = true)` | Generate the STL |
![fan_guard](tests/png/fan_guard.png)
@ -6467,7 +6467,7 @@ Simple tube or ring
| `rectangular_tube(size, center = true, thickness = 1, fillet = 0.5)` | Create a rectangular tube with filleted corners |
| `ring(or, ir)` | Create a ring with specified external and internal radii |
| `tube(or, ir, h, center = true)` | Create a tube with specified external and internal radii and height `h` |
| `woven_tube(or, ir, h, center= true, colour = grey(30)` | Create a woven tube with specified external and internal radii, height `h`, colours, warp and weft |
| `woven_tube(or, ir, h, center= true, colour = grey(30), colour2, warp = 2, weft)` | Create a woven tube with specified external and internal radii, height `h`, colours, warp and weft |
![tube](tests/png/tube.png)

View File

@ -81,7 +81,7 @@ def scrape_code(scad_file):
match = re.match(r'^function (.*?\(.*?\)).*?(?://! ?(.*))$', line)
if match:
functions[match.group(1)] = match.group(2)
match = re.match(r'^module (.*?\(.*?\)).*?(?://! ?(.*))$', line)
match = re.match(r'^module (.*?\(.*\)).*?(?://! ?(.*))$', line)
if match:
modules[match.group(1)] = match.group(2)

View File

@ -46,7 +46,9 @@ function bom_mode(n = 1) = (is_undef($bom) ? 0 : $bom) >= n && (is_undef($on_bom
function exploded() = is_undef($exploded_parent) ? is_undef($explode) ? 0 : $explode : 0; //! Returns the value of `$explode` if it is defined, else `0`
function show_supports() = !$preview || exploded(); //! True if printed support material should be shown
module no_explode() let($exploded_parent = true) children(); //! Prevent children being exploded
module no_explode() //! Prevent children being exploded
let($exploded_parent = true) children();
module explode(d, explode_children = false, offset = [0,0,0]) { //! Explode children by specified Z distance or vector `d`, option to explode grand children
v = is_list(d) ? d : [0, 0, d];
o = is_list(offset) ? offset : [0, 0, offset];
@ -67,7 +69,8 @@ module explode(d, explode_children = false, offset = [0,0,0]) { //! Explode
children();
}
module no_pose() let($posed = true, $zoomed = undef) children(); //! Force children not to be posed even if parent is
module no_pose() //! Force children not to be posed even if parent is
let($posed = true, $zoomed = undef) children();
module pose(a = [55, 0, 25], t = [0, 0, 0], exploded = undef, d = undef) //! Pose an STL or assembly for rendering to png by specifying rotation `a`, translation `t` and optionally `d`, `exploded = true for` just the exploded view or `false` for unexploded only.
let($zoomed = is_undef(d)

View File

@ -38,10 +38,17 @@ function r2sides(r) = $fn ? $fn : ceil(max(min(360/ $fa, r * 2 * PI / $fs), 5));
function r2sides4n(r) = floor((r2sides(r) + 3) / 4) * 4; //! Round up the number of sides to a multiple of 4 to ensure points land on all axes
function limit(x, min, max) = max(min(x, max), min); //! Force x in range min <= x <= max
module translate_z(z) translate([0, 0, z]) children(); //! Shortcut for Z only translations
module vflip(flip=true) rotate([flip ? 180 : 0, 0, 0]) children(); //! Invert children by doing a 180&deg; flip around the X axis
module hflip(flip=true) rotate([0, flip ? 180: 0, 0]) children(); //! Invert children by doing a 180&deg; flip around the Y axis
module ellipse(xr, yr) scale([1, yr / xr]) circle4n(xr); //! Draw an ellipse
module translate_z(z) //! Shortcut for Z only translations
translate([0, 0, z]) children();
module vflip(flip=true) //! Invert children by doing a 180&deg; flip around the X axis
rotate([flip ? 180 : 0, 0, 0]) children();
module hflip(flip=true) //! Invert children by doing a 180&deg; flip around the Y axis
rotate([0, flip ? 180: 0, 0]) children();
module ellipse(xr, yr) //! Draw an ellipse
scale([1, yr / xr]) circle4n(xr);
function slice_str(str, start, end, s ="") = start >= end ? s : slice_str(str, start + 1, end, str(s, str[start])); // Helper for slice()

View File

@ -1109,7 +1109,8 @@ module pcb_grid_components(type, components, cutouts = false, angle = undef) //!
}
module pcb_cutouts(type, angle = undef) pcb_components(type, true, angle); //! Make cut outs to clear components on a PCB
module pcb_cutouts(type, angle = undef) //! Make cut outs to clear components on a PCB
pcb_components(type, true, angle);
module pcb_grid_positions(type) {
grid = pcb_grid(type);

View File

@ -141,7 +141,8 @@ module vero_components(type, cutouts = false, angle = undef)
translate_z(vero_thickness(type))
pcb_component(comp, cutouts, angle);
module vero_cutouts(type, angle = undef) vero_components(type, true, angle); //! Make cutouts to clear components
module vero_cutouts(type, angle = undef) //! Make cutouts to clear components
vero_components(type, true, angle);
module veroboard_assembly(type, height, thickness, flip = false, ngb = false) //! Draw the assembly with components and fasteners in place
assembly(vero_assembly(type), ngb = ngb) {