1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-09-03 12:22:46 +02:00

Compare commits

...

15 Commits

Author SHA1 Message Date
Chris Palmer
33ac3820b0 Added pose_stl() module because pose() only works for assembly views. 2025-04-09 23:29:00 +01:00
Chris Palmer
6a58d37f77 Updated changelog. 2025-04-01 09:57:15 +01:00
Chris Palmer
029abc0cf8 Merge branch 'trnila-barrel_jack_cutout' 2025-04-01 09:45:06 +01:00
Chris Palmer
4b018eb9ad Merge branch 'barrel_jack_cutout' of https://github.com/trnila/NopSCADlib into trnila-barrel_jack_cutout 2025-04-01 09:33:43 +01:00
Chris Palmer
3715585002 Made pose() work on STL renders to match the documentation. 2025-04-01 09:32:00 +01:00
Daniel Trnka
5d0eda87e4 barrel_jack: added cutout 2025-03-30 23:19:42 +02:00
Chris Palmer
ad963afb8d Updated changelog. 2025-03-27 12:25:55 +00:00
Chris Palmer
dbf8e6c7ae Merge branch 'jeroenrnl-VariableNamesWithDigitsDeprecated' 2025-03-27 12:24:15 +00:00
Chris Palmer
7d281cbcdd Merge branch 'VariableNamesWithDigitsDeprecated' of https://github.com/jeroenrnl/NopSCADlib into jeroenrnl-VariableNamesWithDigitsDeprecated 2025-03-27 12:01:05 +00:00
Chris Palmer
f1a651a2d2 Updated changelog. 2025-03-27 02:00:24 +00:00
Chris Palmer
9f9aa6723e Third attempt to fix dimension image. 2025-03-27 01:59:05 +00:00
Chris Palmer
83d2d511e3 Updated changelog. 2025-03-27 01:57:19 +00:00
Chris Palmer
6b6704b823 Second attempt to fix dimension image. 2025-03-27 01:56:05 +00:00
Chris Palmer
946a3bea1c Updated changelog. 2025-03-27 01:39:25 +00:00
Jeroen Roos
fdbe0c7a9e Change variable names that start with a digit
Change names of variables from `2a` and `2c` to `ax2` (a times 2) and
`cx2`, because variable names starting with a digit are deprecated in
OpenSCAD.
2025-03-23 10:45:33 +01:00
9 changed files with 59 additions and 16 deletions

View File

@@ -3,6 +3,28 @@
This changelog is generated by `changelog.py` using manually added semantic version tags to classify commits as breaking changes, additions or fixes.
#### [v21.35.6](https://github.com/nophead/NopSCADlib/releases/tag/v21.35.6 "show release") Fixes [...](https://github.com/nophead/NopSCADlib/compare/v21.35.5...v21.35.6 "diff with v21.35.5")
* 2025-03-30 [`5d0eda8`](https://github.com/nophead/NopSCADlib/commit/5d0eda87e44a70fdbed51407a43555a637e064f9 "show commit") [D.T.](# "Daniel Trnka") `barrel_jack:` added cutout
#### [v21.35.5](https://github.com/nophead/NopSCADlib/releases/tag/v21.35.5 "show release") Fixes [...](https://github.com/nophead/NopSCADlib/compare/v21.35.4...v21.35.5 "diff with v21.35.4")
* 2025-04-01 [`3715585`](https://github.com/nophead/NopSCADlib/commit/3715585002ba56681103103faddd043b1553d095 "show commit") [C.P.](# "Chris Palmer") Made `pose()` work on STL renders to match the documentation.
#### [v21.35.4](https://github.com/nophead/NopSCADlib/releases/tag/v21.35.4 "show release") Fixes [...](https://github.com/nophead/NopSCADlib/compare/v21.35.3...v21.35.4 "diff with v21.35.3")
* 2025-03-23 [`fdbe0c7`](https://github.com/nophead/NopSCADlib/commit/fdbe0c7a9eba96823683b8e1161bc160bd63231e "show commit") [J.R.](# "Jeroen Roos") Change variable names that start with a digit
* Change names of variables from `2a` and `2c` to `ax2` (a times 2) and
`cx2`, because variable names starting with a digit are deprecated in
OpenSCAD.
#### [v21.35.3](https://github.com/nophead/NopSCADlib/releases/tag/v21.35.3 "show release") Fixes [...](https://github.com/nophead/NopSCADlib/compare/v21.35.2...v21.35.3 "diff with v21.35.2")
* 2025-03-27 [`9f9aa67`](https://github.com/nophead/NopSCADlib/commit/9f9aa6723eff9b7439e17758406e9f8e409828ee "show commit") [C.P.](# "Chris Palmer") Third attempt to fix dimension image.
#### [v21.35.2](https://github.com/nophead/NopSCADlib/releases/tag/v21.35.2 "show release") Fixes [...](https://github.com/nophead/NopSCADlib/compare/v21.35.1...v21.35.2 "diff with v21.35.1")
* 2025-03-27 [`6b6704b`](https://github.com/nophead/NopSCADlib/commit/6b6704b823291119697bf4993eddb3f2e6873875 "show commit") [C.P.](# "Chris Palmer") Second attempt to fix dimension image.
#### [v21.35.1](https://github.com/nophead/NopSCADlib/releases/tag/v21.35.1 "show release") Fixes [...](https://github.com/nophead/NopSCADlib/compare/v21.35.0...v21.35.1 "diff with v21.35.0")
* 2025-03-27 [`117fb62`](https://github.com/nophead/NopSCADlib/commit/117fb626e7023ca92339947a0f84a8aee5c6429e "show commit") [C.P.](# "Chris Palmer") Fixed dimension example image address.
### [v21.35.0](https://github.com/nophead/NopSCADlib/releases/tag/v21.35.0 "show release") Additions [...](https://github.com/nophead/NopSCADlib/compare/v21.34.0...v21.35.0 "diff with v21.34.0")
* 2025-03-27 [`6dc8204`](https://github.com/nophead/NopSCADlib/commit/6dc82045fffeca383381724abb6d70d7025b2ae5 "show commit") [C.P.](# "Chris Palmer") Shortened the module comments by factoring out the parameter descriptions.
Added the nut example picture.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@@ -7253,7 +7253,7 @@ allows flexible positioning of the motors.
## Dimension
Modules for adding dimensions to assembly views.
<img src="https://github.com/nophead/NopSCADlib/raw/master/docs/sliding_t_nut.png" width="500", height="378">
![](docs/sliding_t_nut_small.png)
* If `text` is empty, will display the measured distance.
* `offset` will determine how much space is between the measured point and the dimension.
@@ -7847,6 +7847,8 @@ The `pose()` module allows assembly views in the readme to be posed differently
* To get the parameter values make the GUI window square, pose the view with the mouse and then copy the viewport parameters from the Edit menu and paste them into the pose invocation.
* Two `pose()` modules can be chained to allow different poses for exploded and assembled views.
The `pose_stl()` module allows an STL child to be posed for its rendered image used in the readme for the project.
[utils/core/bom.scad](utils/core/bom.scad) Implementation.
[tests/BOM.scad](tests/BOM.scad) Code for this example.
@@ -7870,8 +7872,9 @@ The `pose()` module allows assembly views in the readme to be posed differently
| `no_explode()` | Prevent children being exploded |
| `no_pose()` | Force children not to be posed even if parent is |
| `not_on_bom(on = false)` | Specify the following child parts are not on the BOM, for example when they are on a PCB that comes assembled |
| `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. |
| `pose(a = [55, 0, 25], t = [0, 0, 0], exploded = undef, d = undef)` | Pose an 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. |
| `pose_hflip(exploded = undef)` | Pose an STL or assembly for rendering to png by flipping around the Y axis, `exploded = true for` just the exploded view or `false` for unexploded only. |
| `pose_stl(a = [70, 0, 315], t = [0, 0, 0], d = 500)` | Pose an STL for its render, `a`, `t`, & `d` are camera parameters. |
| `pose_vflip(exploded = undef)` | Pose an STL or assembly for rendering to png by flipping around the X axis, `exploded = true for` just the exploded view or `false` for unexploded only. |
| `stl(name)` | Name an stl that will appear on the BOM, there needs to a module named `<name>_stl` to make it |
| `stl_colour(colour = pp1_colour, alpha = 1)` | Colour an stl where it is placed in an assembly. `alpha` can be used to make it appear transparent. |

View File

@@ -69,7 +69,10 @@ class Part:
self.count = 1
for arg in args:
arg = arg.replace('true', 'True').replace('false', 'False').replace('undef', 'None')
exec('self.' + arg)
try:
exec('self.' + arg)
except:
print(arg)
def data(self):
return self.__dict__
@@ -107,7 +110,7 @@ class BOM:
match = re.match(r'^(.*?\.stl|.*?\.dxf|.*?\.svg)\((.*)\)$', s) #look for name.stl(...), name.dxf(...) or name.svg(...)
if match:
s = match.group(1)
args = [match.group(2)]
args = match.group(2).split('|')
if s[-4:] == ".stl":
parts = self.printed
else:

View File

@@ -61,11 +61,14 @@ def render(target, type):
things = { 'stl' : 'printed', 'dxf' : 'routed', 'svg' : 'routed' }[type]
colours = {}
cameras = {}
for ass in flat_bom:
for part in ass[things]:
obj = ass[things][part]
if "colour" in obj:
colours[part] = obj["colour"]
if "camera" in obj:
cameras[part] = obj["camera"]
#
# Remove unused png files
#
@@ -87,13 +90,16 @@ def render(target, type):
png_maker_name = tmp_dir + "/png.scad"
pp1 = [0, 146/255, 0]
colour = pp1
camera = "0,0,0,70,0,315,500"
if part in cameras:
camera = cameras[part]
if part in colours:
colour = colours[part]
if not '[' in colour:
colour = '"' + colour + '"'
with open(png_maker_name, "w") as f:
f.write('color(%s) import("%s");\n' % (colour, reltmp(part_file, target)))
cam = "--camera=0,0,0,70,0,315,500" if type == 'stl' else "--camera=0,0,0,0,0,0,500"
cam = "--camera=" + camera if type == 'stl' else "--camera=0,0,0,0,0,0,500"
render = "--preview" if type == 'stl' or colour != pp1 else "--render"
tmp_name = tmp_dir + '/' + part[:-4] + '.png'
dummy_deps_name = tmp_dir + '/tmp.deps' # work around for OpenSCAD issue #3879

View File

@@ -41,6 +41,8 @@
//! * If the `d` parameter is set to specify the camera distance then the normal `viewall` and `autocenter` options are suppressed allowing a small section to be zoomed in to fill the view.
//! * To get the parameter values make the GUI window square, pose the view with the mouse and then copy the viewport parameters from the Edit menu and paste them into the pose invocation.
//! * Two `pose()` modules can be chained to allow different poses for exploded and assembled views.
//!
//! The `pose_stl()` module allows an STL child to be posed for its rendered image used in the readme for the project.
//
function bom_mode(n = 1) = (is_undef($bom) ? 0 : $bom) >= n && (is_undef($on_bom) || $on_bom); //! Current BOM mode, 0 = none, 1 = printed and routed parts and assemblies, 2 includes vitamins as well
function exploded() = is_undef($exploded_parent) ? is_undef($explode) ? 0 : $explode : 0; //! Returns the value of `$explode` if it is defined, else `0`
@@ -73,7 +75,7 @@ module explode(d, explode_children = false, offset = [0,0,0], show_line = true)
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.
module pose(a = [55, 0, 25], t = [0, 0, 0], exploded = undef, d = undef) //! Pose an 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)
? is_undef($zoomed)
? undef
@@ -136,10 +138,15 @@ module stl_colour(colour = pp1_colour, alpha = 1) { //! Colour an stl where it i
children();
}
module pose_stl(a = [70, 0, 315], t = [0, 0, 0], d = 500) //! Pose an STL for its render, `a`, `t`, & `d` are camera parameters.
let($stl_camera = str(t.x, ",", t.y, ",", t.z, ",", a.x, ",", a.y, ",", a.z, ",", d))
children();
module stl(name) { //! Name an stl that will appear on the BOM, there needs to a module named `<name>_stl` to make it
if(bom_mode() && is_undef($in_stl)) {
colour = is_undef($stl_colour) ? pp1_colour : $stl_colour;
echo(str("~", name, ".stl(colour='", colour, "')"));
camera = is_undef($stl_camera) ? "0,0,0,70,0,315,500" : $stl_camera;
echo(str("~", name, ".stl(colour='", colour, "'| camera='", camera, "')" ));
}
if($children)
if(is_undef($pose))

View File

@@ -20,7 +20,7 @@
//
//! Modules for adding dimensions to assembly views.
//!
//! <img src="https://github.com/nophead/NopSCADlib/raw/master/docs/sliding_t_nut.png" width="500", height="378">
//! ![](docs/sliding_t_nut_small.png)
//!
//! * If `text` is empty, will display the measured distance.
//! * `offset` will determine how much space is between the measured point and the dimension.

View File

@@ -164,13 +164,13 @@ function xor(a,b) = (a && !b) || (!a && b); //! Logical exclusive OR
function cuberoot(x)= sign(x)*abs(x)^(1/3);
function quadratic_real_roots(a, b, c) = //! Returns real roots of a quadratic equation, biggest first. Returns empty list if no real roots
let(2a = 2 * a,
2c = 2 * c,
det = b^2 - 2a * 2c
let(ax2 = 2 * a,
cx2 = 2 * c,
det = b^2 - ax2 * cx2
) det < 0 ? [] :
let(r = sqrt(det),
x1 = b < 0 ? 2c / (-b + r) : (-b - r) / 2a,
x2 = b < 0 ? (-b + r) / 2a : 2c / (-b - r)
x1 = b < 0 ? cx2 / (-b + r) : (-b - r) / ax2,
x2 = b < 0 ? (-b + r) / ax2 : cx2 / (-b - r)
) [x2, x1];
function cubic_real_roots(a, b, c, d) = //! Returns real roots of cubic equation

View File

@@ -650,9 +650,11 @@ module barrel_jack(cutout = false) { //! Draw barrel power jack
contact_d = 2;
contact_w = 4;
inset = 1;
if(cutout)
;
else {
if(cutout) {
rotate([0, 90, 0])
translate([-bore_h, 0])
cylinder(d = bore_d + panel_clearance, h = 100);
} else {
color(grey(20)) rotate([0, 90, 0]) {
linear_extrude(l, center = true) {
difference() {