1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-01 05:00:14 +02:00

Fixed cable_bundle() bugs and added test.

Added cable_bundle_positions().
Can now mark cables as ribbon to force a flat layout.
This commit is contained in:
Chris Palmer
2022-02-11 09:07:34 +00:00
parent 14ba135169
commit ed46cbb147
4 changed files with 41 additions and 11 deletions

View File

@@ -4391,7 +4391,9 @@ Just a BOM entry at the moment and cable bundle size functions for holes, plus c
| Function | Description |
|:--- |:--- |
| `cable_bundle(cable)` | Arrangement of a bundle in a flat cable clip |
| `cable_bundle_positions(cable)` | Positions of wires in a bundle to go through a cable strip |
| `cable_height(cable)` | Height in flat clip |
| `cable_is_ribbon(cable)` | Is a ribbon cable? |
| `cable_radius(cable)` | Radius of a bundle of wires, see <http://mathworld.wolfram.com/CirclePacking.html>. |
| `cable_width(cable)` | Width in flat clip |
| `cable_wire_size(cable)` | Size of each wire in a bundle |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 128 KiB

View File

@@ -25,13 +25,15 @@ bundle = [7, 1.4];
bundle_r = cable_radius(bundle);
thickness = 2;
w = 50;
w = 60;
d = 20;
h = 40;
wire_l = 90;
mouse_y = 10;
cable_pitch = 7;
module wires() {
translate_z(bundle_r)
translate([0, mouse_y, bundle_r])
rotate([0, 90, 0]) {
n = cable_wires(bundle);
d = cable_wire_size(bundle);
@@ -58,24 +60,39 @@ module wires() {
rotate([90, 0, 90])
linear_extrude(thickness)
difference() {
translate([-w / 2, 0])
square([w, h]);
square([w, h]);
mouse_hole(bundle, 0, true);
translate([mouse_y, 0])
mouse_hole(bundle, 0, true);
for(i = [1 : 6])
let(cable = [i, 1.4], bundle = cable_bundle(cable))
translate([mouse_y + cable_pitch * i - bundle.x / 2, -eps])
square([bundle.x, bundle.y]);
}
translate_z(-thickness)
linear_extrude(thickness)
difference() {
translate([thickness -d, -w / 2])
translate([thickness -d, 0])
square([d, w]);
translate([-15, 0])
translate([-15, mouse_y])
cable_tie_holes(bundle_r, 0);
}
}
translate([-15, 0])
translate([-15, mouse_y])
cable_tie(bundle_r, thickness);
for(i = [1 : 6]) let(cable = [i, 1.4])
translate([0, mouse_y + cable_pitch * i])
let(positions = cable_bundle_positions(cable))
for(i = [0 : len(positions) - 1])
let(p = positions[i])
translate([0, p.x, p.y])
rotate([0, 90, 0])
color([grey(10), "blue", "red", "orange", "yellow", "green"][i])
cylinder(d = cable_wire_size(cable), h = 60, center = true);
}
if($preview)

View File

@@ -34,6 +34,7 @@ module ribbon_cable(ways, length) //! Add ribbon cable to the
//
function cable_wires(cable) = cable[0]; //! Number of wires in a bundle
function cable_wire_size(cable) = cable[1]; //! Size of each wire in a bundle
function cable_is_ribbon(cable) = len(cable) > 2 && cable[2]; //! Is a ribbon cable?
// numbers from http://mathworld.wolfram.com/CirclePacking.html
function cable_radius(cable) = [0, 1, 2, 2.15, 2.41, 2.7, 3, 3, 3.3][cable_wires(cable)] * cable_wire_size(cable) / 2; //! Radius of a bundle of wires, see <http://mathworld.wolfram.com/CirclePacking.html>.
@@ -41,10 +42,20 @@ function cable_radius(cable) = [0, 1, 2, 2.15, 2.41, 2.7, 3, 3, 3.3][cable_wires
function wire_hole_radius(cable) = ceil(4 * cable_radius(cable) + 1) / 4; //! Radius of a hole to accept a bundle of wires, rounded up to standard metric drill size
function cable_bundle(cable) = //! Arrangement of a bundle in a flat cable clip
[[0,0], [1,1], [2,1], [2, 0.5 + sin(60)], [2,2], [3, 0.5 + sin(60)], [3,2]][cable_wires(cable)];
(cable_is_ribbon(cable) ? [cable_wires(cable), 1] :
[[0,0], [1,1], [2,1], [2, 1 + sin(60)], [2,2], [3, 1 + sin(60)], [3,2]][cable_wires(cable)]) * cable_wire_size(cable);
function cable_width(cable) = cable_bundle(cable)[0] * cable_wire_size(cable); //! Width in flat clip
function cable_height(cable) = cable_bundle(cable)[1] * cable_wire_size(cable); //! Height in flat clip
function cable_bundle_positions(cable) = let( //! Positions of wires in a bundle to go through a cable strip
wires = cable_wires(cable),
bottom = cable_is_ribbon(cable) ? wires : wires < 3 ? wires : ceil(wires / 2),
top = wires - bottom
)
[for(i = [0 : 1 : bottom - 1]) [i - (bottom - 1) / 2, 0.5],
for(i = [0 : 1 : top - 1]) [i - (top - 1) / 2, top == bottom ? 1.5 : 0.5 + sin(60)]
] * cable_wire_size(cable);
function cable_width(cable) = cable_bundle(cable).x; //! Width in flat clip
function cable_height(cable) = cable_bundle(cable).y; //! Height in flat clip
module mouse_hole(cable, h = 100, teardrop = false) { //! A mouse hole to allow a panel to go over a wire bundle.
r = wire_hole_radius(cable);