TOPdesk/subs/base.scad

394 lines
12 KiB
OpenSCAD

include <../config.scad>
include <../modules.scad>
include <../grid.scad>
module module_side(width, depth, height, screw_step) {
// same parameters as, and handed through by, module_base()
screws_per_side = grid_elements(depth, screw_step);
screw_grid_margin = grid_margin(depth, screws_per_side, screw_step);
difference() {
rotate([0, 90, 0]){
color(COLOR_WOOD){
cube([height, depth, MODULE_THICKNESS]); // main plate
}
}
// screw holes and barrel nut holes
translate([
MODULE_THICKNESS / 2,
screw_grid_margin,
0
]){
for ( xy = grid(1, screws_per_side, 1, screw_step) ) {
translate(xy){
// top
translate([
0,
0,
MODULE_THICKNESS - MODULE_SCREW_LENGTH
]) {
screw_hole();
barrel_nut_hole();
}
// bottom
translate([
0,
0,
0 - height - MODULE_THICKNESS
]) {
translate([0, 0, MODULE_SCREW_LENGTH]){
rotate([180, 0, 0]) {
screw_hole();
}
}
translate([0, 0, MODULE_SCREW_LENGTH - BARREL_NUT_DIAMETER]){
barrel_nut_hole();
}
}
}
}
}
}
}
module module_base_fit(width_inner, depth_inner, height_inner, num_screws=4) {
// shorthand to create a base module guaranteed to fit the passed dimensions
width_outer = _MODULE_RAIL_OFFSET + MODULE_SLIDE_WIDTH + MODULE_THICKNESS + width_inner + MODULE_THICKNESS + MODULE_SLIDE_WIDTH + _MODULE_RAIL_OFFSET;
depth_outer = MODULE_THICKNESS + depth_inner + MODULE_THICKNESS;
width_gridunits = grid_units_length(width_outer);
depth_gridunits = grid_units_length(depth_outer);
screw_step = floor(depth_gridunits / (num_screws));
echo("base from measurements:");
echo(width_outer);
echo(width_gridunits);
echo(depth_gridunits);
echo(screw_step);
module_base(width_gridunits, depth_gridunits, height_inner, screw_step);
}
module module_base(width_gridunits, depth_gridunits, height_inner, screw_step=3){
/* Module base. For use as basis of custom-built or designed modules.
* Aligned to fit a module_rail_set of the same gridunit dimensions.
*/
// final width and depth
//width = grid_length(width_gridunits) - ((_MODULE_RAIL_OFFSET + MODULE_SLIDE_WIDTH) * 2);
width = grid_length(width_gridunits) - _MODULE_RAIL_OFFSET - MODULE_SLIDE_WIDTH - MODULE_THICKNESS - MODULE_THICKNESS - MODULE_SLIDE_WIDTH - _MODULE_RAIL_OFFSET;
depth = grid_length(depth_gridunits);
screws_per_side = grid_elements(depth, screw_step);
screw_grid_margin = grid_margin(depth, screws_per_side, screw_step);
screw_grid = grid(1, screws_per_side, 1, screw_step);
/*
echo("=== MODULE_BASE ===");
echo(width_gridunits=width_gridunits, width=width);
echo(depth_gridunits=depth_gridunits, depth=depth);
echo(height_inner=height_inner);
echo(screw_step=screw_step);
echo(screws_per_side=screws_per_side);
echo(screw_grid_margin=screw_grid_margin);
*/
// align to rail
translate([_MODULE_RAIL_OFFSET, 0, -MODULE_RAIL_MARGIN_TOP]) {
//translate([0, 0, -MODULE_RAIL_MARGIN_TOP]) {
// top side, including slide
translate([0, 0, -MODULE_THICKNESS]){
difference(){
// main plate
color(COLOR_WOOD){
cube([
MODULE_SLIDE_WIDTH + MODULE_THICKNESS + width + MODULE_THICKNESS + MODULE_SLIDE_WIDTH,
depth,
MODULE_THICKNESS
]);
}
// screw holes
translate([
MODULE_SLIDE_WIDTH + MODULE_THICKNESS / 2,
screw_grid_margin,
MODULE_THICKNESS - MODULE_SCREW_LENGTH
]){
for ( xy = screw_grid ) {
translate(xy){
// left
screw_hole();
// right
translate([width + MODULE_THICKNESS, 0, 0]){
screw_hole();
}
}
}
}
}
}
// left side
translate([MODULE_SLIDE_WIDTH, 0, -MODULE_THICKNESS]){
module_side(width, depth, height_inner, screw_step);
}
// right side
translate([MODULE_SLIDE_WIDTH + MODULE_THICKNESS + width, 0, -MODULE_THICKNESS]){
module_side(width, depth, height_inner, screw_step);
}
// bottom side
translate([
MODULE_SLIDE_WIDTH,
0,
0 - MODULE_THICKNESS - height_inner - MODULE_THICKNESS
]){
difference() {
color(COLORSCHEME == "semantic" ? COLOR_SEMANTIC_USABLE_SURFACE : COLOR_WOOD) {
cube([ // main plate
MODULE_THICKNESS + width + MODULE_THICKNESS,
depth,
MODULE_THICKNESS
]);
}
// screw holes
translate([
MODULE_THICKNESS / 2,
screw_grid_margin,
0
]) {
for ( xy = screw_grid ) {
translate(concat(xy, MODULE_SCREW_LENGTH)){
// left
rotate([180, 0, 0]){
screw_hole();
}
// right
translate([width + MODULE_THICKNESS, 0, 0]){
rotate([180, 0, 0]){
screw_hole();
}
}
}
}
}
}
}
// screws and barrel nuts
translate([
MODULE_SLIDE_WIDTH + MODULE_THICKNESS / 2,
screw_grid_margin
]) {
for ( xy = screw_grid ) {
translate(xy){
// top
translate([
0,
0,
-MODULE_SCREW_LENGTH
]){
// left
screw();
barrel_nut();
// right
translate([width + MODULE_THICKNESS, 0]){
screw();
barrel_nut();
}
}
// bottom
translate([
0,
0,
MODULE_SCREW_LENGTH - MODULE_THICKNESS - height_inner - MODULE_THICKNESS
]){
// left
rotate([180, 0, 0]){
screw();
barrel_nut();
}
// right
translate([width + MODULE_THICKNESS, 0]){
rotate([180, 0, 0]){
screw();
barrel_nut();
}
}
}
}
}
}
} // end rail alignment translate
}
module module_rail_left(depth_gridunits, screw_step){
/* A rail that can be affixed to the underside
* of a desk and hold one side of a module.
* Aligned so 0,0,0 is the position of the first screws' center
*/
overall_height = MODULE_RAIL_MARGIN_TOP + MODULE_THICKNESS + MODULE_THICKNESS;
num_screws = grid_elements((depth_gridunits + screw_step) * GRID_SIZE, screw_step);
depth_outer = MODULE_RAIL_MARGIN_SCREW + grid_length(depth_gridunits) + MODULE_RAIL_MARGIN_SCREW;
screw_grid = grid(1, num_screws, 1, screw_step);
difference(){
color(COLORSCHEME == "semantic" ? COLOR_SEMANTIC_LOAD_BEARING : COLOR_WOOD) {
translate([-MODULE_RAIL_BASE_WIDTH / 2, -MODULE_RAIL_MARGIN_SCREW, -overall_height]){ // 0-align to top, center screw holes on x axis
translate([0, 0, MODULE_THICKNESS]){
cube([MODULE_RAIL_BASE_WIDTH, depth_outer, MODULE_THICKNESS + MODULE_RAIL_MARGIN_TOP]);
}
cube([MODULE_RAIL_BASE_WIDTH + MODULE_SLIDE_WIDTH, depth_outer, MODULE_THICKNESS]);
}
}
for ( xy = screw_grid ) {
translate(concat(xy, -MODULE_SCREW_LENGTH)){
screw_hole();
}
}
}
}
module module_rail_right(depth_gridunits, screw_step){
/* Ditto, but for the right side.
*/
mirror ([1, 0, 0]) {
module_rail_left(depth_gridunits, screw_step);
}
}
module module_rail_set(width_gridunits, depth_gridunits, screw_step){
module_rail_left(depth_gridunits, screw_step);
translate([grid_length(width_gridunits), 0]){
module_rail_right(depth_gridunits, screw_step);
}
}
// demo setup with rails
/*module_rail_left(600);
translate([
MODULE_SLIDE_WIDTH + MODULE_RAIL_BASE_WIDTH + MODULE_SLIDE_WIDTH + 800 + MODULE_SLIDE_WIDTH, // + MODULE_RAIL_MARGIN_SIDE + 800 + MODULE_RAIL_MARGIN_SIDE + MODULE_SLIDE_WIDTH + MODULE_RAIL_BASE_WIDTH,
600,
0
]){
rotate([0,0, 180]){
module_rail_left(600);
}
}
translate([MODULE_SLIDE_WIDTH - MODULE_RAIL_BASE_WIDTH / 2 + MODULE_RAIL_MARGIN_SIDE, 0, -MODULE_RAIL_MARGIN_TOP]){
module_base(800, 600, 700, 4);
}*/
//module_side(800, 600, 700, 3);
//module_base(800, 600, 700, 3);
//module_base_fit(550, 600, 700, 5);
//screw_hole();
//screw();
//barrel_nut();
/*translate([0, 0, -200]){
//module_rail_left(12, 3);
module_rail_right(12, 3);
}*/
/*module_rail_set(10, 15, 2);
module_base(10, 15, 700, 2);*/
/*for(xy = grid(15, 15, 1, 1)){
translate(xy) { screw(); }
}*/
/*module newtransl() {
translate([100, 100, 100]) {
children();
}
}
newtransl(){
screw();
}*/
// a bunch of demo instances to make reasonably sure no wonkiness occurs
module_base(8, 8, 300, 1);
module_rail_set(8, 8, 1);
translate ([1100, 0]) {
module_base(9, 9, 300, 2);
module_rail_set(9, 9, 2);
}
translate ([2200, 0]) {
module_base(13, 5, 600, 3);
module_rail_set(13, 5, 3);
}
translate ([3300, 0]){
module_base(17, 9, 200, 3);
module_rail_set(17, 9, 3);
}
translate ([0, 1000]) {
module_base(12, 17, 500, 5);
module_rail_set(12, 17, 5);
}
translate ([1100, 1000]) {
module_base(20, 20, 500, 6);
module_rail_set(20, 20, 6);
}
translate ([2200, 1000]) {
module_base(15, 30, 800, 9);
module_rail_set(15, 30, 9);
}
translate ([3300, 1000]) {
module_base(19, 17, 300, 3);
module_rail_set(19, 17, 3);
}
// try making something to fit a 19" rack
/*rack_width_gridunits = grid_units_length(550);
rack_depth_gridunits = grid_units_length(650);
module_base(rack_width_gridunits, rack_depth_gridunits, 700, 3);
module_rail_set(rack_width_gridunits, rack_depth_gridunits, 3);*/