1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-13 10:53:59 +02: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

@@ -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()