forked from mrWheel/YAPP_Box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YAPPgenerator_v3.scad
5589 lines (4885 loc) · 195 KB
/
YAPPgenerator_v3.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
***************************************************************************
** Yet Another Parameterised Projectbox generator
**
*/
Version="v3.1.2 (2024-04-12)";
/*
**
** Copyright (c) 2021, 2022, 2023, 2024 Willem Aandewiel
**
** With help from:
** - Keith Hadley (parameterized label depth)
** - Oliver Grafe (connectorsPCB)
** - Juan Jose Chong (dynamic standoff flange)
** - Dan Drum (cleanup code)
** - Dave Rosenhauer (fillets and a lot more)
**
**
** for many or complex cutouts you might need to adjust
** the number of elements:
**
** Preferences->Advanced->Turn off rendering at 250000 elements
** ^^^^^^
**
** TERMS OF USE: MIT License. See base offile.
***************************************************************************
*/
// If set to true will generate the sample box at every save
debug = false;
printMessages = debug;
//---------------------------------------------------------
// This design is parameterized based on the size of a PCB.
//---------------------------------------------------------
// Note: length/lengte refers to X axis,
// width/breedte to Y,
// height/hoogte to Z
/*
padding-back|<------pcb length --->|<padding-front
RIGHT
0 X-axis --->
+----------------------------------------+ ---
| | ^
| | padding-right
Y | | v
| | -5,y +----------------------+ | ---
B a | | 0,y x,y | | ^ F
A x | | | | | R
C i | | | | | pcb width O
K s | | | | | N
| | 0,0 x,0 | | v T
^ | -5,0 +----------------------+ | ---
| | | padding-left
0 +----------------------------------------+ ---
0 X-as --->
LEFT
*/
//-- which part(s) do you want to print?
printBaseShell = true;
printLidShell = true;
printSwitchExtenders = true;
printDisplayClips = true;
shiftLid = 10; // Set the distance between the lid and base when rendered or previewed side by side
//-- padding between pcb and inside wall
paddingFront = 1;
paddingBack = 1;
paddingRight = 1;
paddingLeft = 1;
// ********************************************************************
// The Following will be used as the first element in the pbc array
//Defined here so you can define the "Main" PCB using these if wanted
pcbLength = 120; // front to back (X axis)
pcbWidth = 50; // side to side (Y axis)
pcbThickness = 1.6;
standoffHeight = 1.0; //-- How much the PCB needs to be raised from the base to leave room for solderings
standoffDiameter = 7;
standoffPinDiameter = 2.4;
standoffHoleSlack = 0.4;
//===================================================================
// *** PCBs ***
// Printed Circuit Boards
//-------------------------------------------------------------------
// Default origin = yappCoordPCB : yappCoordBoxInside[0,0,0]
//
// Parameters:
// Required:
// p(0) = name
// p(1) = length
// p(2) = width
// p(3) = posx
// p(4) = posy
// p(5) = Thickness
// p(6) = standoff_Height
// p(7) = standoff_Diameter
// p(8) = standoff_PinDiameter
// Optional:
// p(9) = standoff_HoleSlack (default to 0.4)
//The following can be used to get PCB values. If "PCB Name" is omitted then "Main" is used
// pcbLength --> pcbLength("PCB Name")
// pcbWidth --> pcbWidth("PCB Name")
// pcbThickness --> pcbThickness("PCB Name")
// standoffHeight --> standoffHeight("PCB Name")
// standoffDiameter --> standoffDiameter("PCB Name")
// standoffPinDiameter --> standoffPinDiameter("PCB Name")
// standoffHoleSlack --> standoffHoleSlack("PCB Name")
pcb =
[
//-- Default Main PCB - DO NOT REMOVE the "Main" line.
["Main", pcbLength,pcbWidth, 0,0, pcbThickness, standoffHeight, standoffDiameter, standoffPinDiameter, standoffHoleSlack]
];
//-------------------------------------------------------------------
//-- Edit these parameters for your own box dimensions
wallThickness = 2.0;
basePlaneThickness = 1.5;
lidPlaneThickness = 1.5;
//-- Total height of box = lidPlaneThickness
// + lidWallHeight
// + baseWallHeight
// + basePlaneThickness
//-- space between pcb and lidPlane :=
//-- (bottonWallHeight+lidWallHeight) - (standoff_Height+pcb_Thickness)
baseWallHeight = 10;
lidWallHeight = 10;
//-- ridge where base and lid off box can overlap
//-- Make sure this isn't less than lidWallHeight
// or 1.8x wallThickness if using snaps
ridgeHeight = 5.0;
ridgeSlack = 0.3;
//-- Radius of the shell corners
roundRadius = wallThickness + 1;
//---------------------------
//-- MISC Options --
//---------------------------
//-- Cone aperture in degrees for countersunk-head screws
countersinkAngle = 90; //-- metric: 90
// Set the layer height of your printer
printerLayerHeight = 0.2;
// Set the ratio between the wall thickness and the ridge height.
// Recommended to be left at 1.8 but for strong snaps.
wallToRidgeRatio = 1.8;
//---------------------------
//-- C O N T R O L --
//---------------------------
// -- Render --
renderQuality = 8; //-> from 1 to 32, Default = 8
// --Preview --
previewQuality = 5; //-> from 1 to 32, Default = 5
showSideBySide = true; //-> Default = true
onLidGap = 0; // tip don't override to animate the lid opening
//onLidGap = ((ridgeHeight) - (ridgeHeight * abs(($t-0.5)*2)))*2; // tip don't override to animate the lid opening/closing
colorLid = "YellowGreen";
alphaLid = 1;
colorBase = "BurlyWood";
alphaBase = 1;
hideLidWalls = false; //-> Remove the walls from the lid : only if preview and showSideBySide=true
hideBaseWalls = false; //-> Remove the walls from the base : only if preview and showSideBySide=true
showOrientation = true; //-> Show the Front/Back/Left/Right labels : only in preview
showPCB = false; //-> Show the PCB in red : only in preview
showSwitches = false; //-> Show the switches (for pushbuttons) : only in preview
showButtonsDepressed = false; //-> Should the buttons in the Lid On view be in the pressed position
showOriginCoordBox = false; //-> Shows red bars representing the origin for yappCoordBox : only in preview
showOriginCoordBoxInside = false; //-> Shows blue bars representing the origin for yappCoordBoxInside : only in preview
showOriginCoordPCB = false; //-> Shows blue bars representing the origin for yappCoordBoxInside : only in preview
showMarkersPCB = false; //-> Shows black bars corners of the PCB : only in preview
showMarkersCenter = false; //-> Shows magenta bars along the centers of all faces
inspectX = 0; //-> 0=none (>0 from Back)
inspectY = 0; //-> 0=none (>0 from Right)
inspectZ = 0; //-> 0=none (>0 from Bottom)
inspectXfromBack = true; //-> View from the inspection cut foreward
inspectYfromLeft = true; //-> View from the inspection cut to the right
inspectZfromBottom = true; //-> View from the inspection cut up
//---------------------------
//-- C O N T R O L --
//---------------------------
// ******************************
// REMOVE BELOW FROM TEMPLATE
// Set the glogal for the quality
facetCount = $preview ? previewQuality*4 : renderQuality*4;
//-- better leave these ----------
buttonWall = 2.0;
buttonPlateThickness= 2.5;
buttonSlack = 0.25;
//-- constants, do not change (shifted to large negative values so another element in the
//-- array won't match
// Define some alternates to undef
yappDefault = undef;
default = undef;
// Shapes
yappRectangle = -30000;
yappCircle = -30001;
yappPolygon = -30002;
yappRoundedRect = -30003;
yappCircleWithFlats = -30004;
yappCircleWithKey = -30005;
yappRing = -30006;
//Shell options
yappBoth = -30100;
yappLidOnly = -30101;
yappBaseOnly = -30102;
//PCB standoff typrs
yappHole = -30200;
yappPin = -30201;
yappTopPin = -30202;
// Faces
yappLeft = -30300;
yappRight = -30301;
yappFront = -30302;
yappBack = -30303;
yappLid = -30304;
yappBase = -30305;
yappPartBase = -30306;
yappPartLid = -30307;
//-- Placement Options
yappCenter = -30400; // Cutouts, boxMounts, lightTubes, pushButtons, pcbStands, Connectors
yappOrigin = -30401; // Cutouts, boxMounts, lightTubes, pushButtons, pcbStands, Connectors
yappSymmetric = -30402; // snapJoins
yappAllCorners = -30403; // pcbStands, Connectors
yappFrontLeft = -30404; // pcbStands, Connectors
yappFrontRight = -30405; // pcbStands, Connectors
yappBackLeft = -30406; // pcbStands, Connectors
yappBackRight = -30407; // pcbStands, Connectors
yappFromInside = -30410; // Cutouts
yappTextLeftToRight = -30470;
yappTextRightToLeft = -30471;
yappTextTopToBottom = -30472;
yappTextBottomToTop = -30473;
yappTextHAlignLeft = -30474;
yappTextHAlignCenter = -30475;
yappTextHAlignRight = -30476;
yappTextVAlignTop = -30477;
yappTextVAlignCenter = -30478;
yappTextVAlignBaseLine = -30479;
yappTextVAlignBottom = -30480;
// Lightube options
yappThroughLid = -30500; // lightTubes
// Misc Options
yappNoFillet = -30600; // pcbStands, Connectors, lightTubes, pushButtons
yappCountersink = -30601; // connectors
// Coordinate options
yappCoordPCB = -30700; // pcbStands, connectors, Cutouts, boxMounts, lightTubes, pushButtons
yappCoordBox = -30701; // pcbStands, connectors, Cutouts, boxMounts, lightTubes, pushButtons
yappCoordBoxInside = -30702; // pcbStands, connectors, Cutouts, boxMounts, lightTubes, pushButtons
yappAltOrigin = -30710; // pcbStands, connectors, Cutouts, boxMounts, lightTubes, pushButtons
yappGlobalOrigin = -30711; // pcbStands, connectors, Cutouts, boxMounts, lightTubes, pushButtons
//yappConnWithPCB - Depreciated use yappCoordPCB
//yappLeftOrigin - Depreciated use yappAltOrigin
// Grid options
yappPatternSquareGrid = -30800;
yappPatternHexGrid = -30801;
yappMaskDef = -30900;
yappPolygonDef = -30901;
yappPCBName = -30902;
minkowskiErrorCorrection = $preview ? 1.0125 : 1;
boxLength = maxLength(pcb);
boxWidth = maxWidth(pcb);
//-------------------------------------------------------------------
// Misc internal values
shellInsideWidth = boxWidth+paddingLeft+paddingRight;
shellInsideLength = boxLength+paddingFront+paddingBack;
shellInsideHeight = baseWallHeight+lidWallHeight;
shellWidth = shellInsideWidth+(wallThickness*2);
shellLength = shellInsideLength+(wallThickness*2);
shellHeight = basePlaneThickness+shellInsideHeight+lidPlaneThickness;
// REMOVE ABOVE FROM TEMPLATE
// ******************************
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Start of Debugging config (used if not overridden in template)
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// ==================================================================
// Shapes
// ------------------------------------------------------------------
// Shapes should be defined to fit into a 1x1 box (+/-0.5 in X and Y) - they will be scaled as needed.
// defined as a vector of [x,y] vertices pairs.(min 3 vertices)
// for example a triangle could be [yappPolygonDef,[[-0.5,-0.5],[0,0.5],[0.5,-0.5]]];
// Pre-defined shapes
shapeIsoTriangle = [yappPolygonDef,[[-0.5,-sqrt(3)/4],[0,sqrt(3)/4],[0.5,-sqrt(3)/4]]];
shapeIsoTriangle2 = [yappPolygonDef,[[0,+sqrt(1/3)],[+0.5,-sqrt(1/12)],[-0.5,-sqrt(1/12)]]];
shapeHexagon = [yappPolygonDef,[[-0.50,0],[-0.25,+0.433012],[+0.25,+0.433012],[+0.50 ,0],[+0.25,-0.433012],[-0.25,-0.433012]]];
shape6ptStar = [yappPolygonDef,[[-0.50,0],[-0.25,+0.144338],[-0.25,+0.433012],[0,+0.288675],[+0.25,+0.433012],[+0.25,+0.144338],[+0.50 ,0],[+0.25,-0.144338],[+0.25,-0.433012],[0,-0.288675],[-0.25,-0.433012],[-0.25,-0.144338]]];
shapeTriangle = [yappPolygonDef,[[-0.5,-1/3],[0,+2/3],[+0.5,-1/3]]];
shapeTriangle2 = [yappPolygonDef,[[-0.5,-0.5],[0,0.5],[0.5,-0.5]]];
shapeArrow = [yappPolygonDef,[[-1/3,+0.5],[0.166667,+0.5],[+2/3,0],[0.166667,-0.5],[-1/3,-0.5]]];
preDefinedShapes=[
["shapeIsoTriangle", shapeIsoTriangle],
["shapeIsoTriangle2", shapeIsoTriangle2],
["shapeHexagon", shapeHexagon],
["shape6ptStar", shape6ptStar],
["shapeTriangle", shapeTriangle],
["shapeTriangle2",shapeTriangle2],
["shapeArrow", shapeArrow],
];
//==================================================================
// *** Masks ***
//------------------------------------------------------------------
// Parameters:
// maskName = [yappMaskDef,[
// p(0) = Grid pattern :{ yappPatternSquareGrid, yappPatternHexGrid }
// p(1) = horizontal Repeat : if yappPatternSquareGrid then 0 = no repeat one
// shape per column, if yappPatternHexGrid 0 is not valid
// p(2) = vertical Repeat : if yappPatternSquareGrid then 0 = no repeat one shape
// per row, if yappPatternHexGrid 0 is not valid
// p(3) = grid rotation
// p(4) = openingShape : {yappRectangle | yappCircle | yappPolygon | yappRoundedRect}
// p(5) = openingWidth, : if yappPatternSquareGrid then 0 = no repeat one shape per
// column, if yappPatternHexGrid 0 is not valid
// p(6) = openingLength, if yappPatternSquareGrid then 0 = no repeat one shape per
// row, if yappPatternHexGrid 0 is not valid
// p(7) = openingRadius
// p(8) = openingRotation
// p(9) = shape polygon : Required if openingShape = yappPolygon
// ]];
//------------------------------------------------------------------
maskHoneycomb = [yappMaskDef,[
yappPatternHexGrid, // pattern
5, // hRepeat
5, // vRepeat
0, // rotation
yappPolygon, // openingShape
4, // openingWidth,
4, // openingLength,
0, // openingRadius
30, // openingRotation
shapeHexagon]];
maskHexCircles = [yappMaskDef,[
yappPatternHexGrid, // pattern
5, // hRepeat
5, // vRepeat
30, // rotation
yappCircle, // openingShape
0, // openingWidth,
0, // openingLength,
2, // openingRadius
0 // openingRotation
]];
maskCircles = [yappMaskDef,[
yappPatternSquareGrid, // pattern
5, // hRepeat
5, // vRepeat
0, // rotation
yappCircle, // openingShape
0, // openingWidth,
0, // openingLength,
2, // openingRadius
0 // openingRotation
]
];
maskSquares = [yappMaskDef,[
yappPatternSquareGrid, // pattern
4, // hRepeat
4, // vRepeat
0, // rotation
yappRectangle, // openingShape
2, // openingWidth,
2, // openingLength,
0, // openingRadius
0 // openingRotation
]
];
maskBars = [yappMaskDef,[
yappPatternSquareGrid, // pattern
0, // hRepeat 0= Default to opening width - no repeat
4, // vRepeat
0, // rotation
yappRectangle, // openingShape
0, // openingWidth, 0= Default to opening width - no repeat
2, // openingLength,
2.5, // openingRadius
0 // openingRotation
]
];
maskOffsetBars = [yappMaskDef,[
yappPatternHexGrid, // pattern
7, // hRepeat
2*sqrt(3), // vRepeat
-30, // rotation
yappRoundedRect, // openingShape
10, // openingWidth,
2, // openingLength,
1, // openingRadius
30 // openingRotation
]
];
preDefinedMasks=[
["maskHoneycomb", maskHoneycomb],
["maskHexCircles", maskHexCircles],
["maskCircles", maskCircles],
["maskSquares", maskSquares],
["maskBars", maskBars],
["maskOffsetBars", maskOffsetBars],
];
//-- Show sample of a Mask.in the negative X,Y quadrant
//SampleMask(maskHoneycomb);
//===================================================================
// *** PCB Supports ***
// Pin and Socket standoffs
//-------------------------------------------------------------------
// Default origin = yappCoordPCB : pcb[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx
// p(1) = posy
// Optional:
// p(2) = Height to bottom of PCB : Default = standoffHeight
// p(3) = PCB Gap : Default = -1 : Default for yappCoordPCB=pcbThickness, yappCoordBox=0
// p(4) = standoffDiameter Default = standoffDiameter;
// p(5) = standoffPinDiameter Default = standoffPinDiameter;
// p(6) = standoffHoleSlack Default = standoffHoleSlack;
// p(7) = filletRadius (0 = auto size)
// p(8) = Pin Length : Default = 0 -> PCB Gap + standoff_PinDiameter
// Indicated length of pin without the half sphere tip.
// Example : pcbThickness() only leaves the half sphere tip above the PCB
// n(a) = { <yappBoth> | yappLidOnly | yappBaseOnly }
// n(b) = { <yappPin>, yappHole, yappTopPin }
// yappPin = Pin on Base and Hole on Lid
// yappHole = Hole on Both
// yappHole = Hole on Base and Pin on Lid
// n(c) = { yappAllCorners, yappFrontLeft | <yappBackLeft> | yappFrontRight | yappBackRight }
// n(d) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(e) = { yappNoFillet } : Removes the internal and external fillets and the Rounded tip on the pins
// n(f) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
//-------------------------------------------------------------------
pcbStands =
[
];
//===================================================================
// *** Connectors ***
// Standoffs with hole through base and socket in lid for screw type connections.
//-------------------------------------------------------------------
// Default origin = yappCoordPCB : pcb[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx
// p(1) = posy
// p(2) = StandHeight : From specified origin
// p(3) = screwDiameter
// p(4) = screwHeadDiameter (don't forget to add extra for the fillet)
// p(5) = insertDiameter
// p(6) = outsideDiameter
// Optional:
// p(7) = insert Depth : default to entire connector
// p(8) = PCB Gap : Default if yappCoordPCB then pcbThickness else 0
// p(9) = filletRadius : Default = 0/Auto(0 = auto size)
// n(a) = { yappAllCorners, yappFrontLeft | <yappBackLeft> | yappFrontRight | yappBackRight }
// n(b) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(c) = { yappNoFillet }
// n(d) = { yappCountersink }
// n(e) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
// n(f) = { yappThroughLid = changes the screwhole to the lid and the socket to the base}
//-------------------------------------------------------------------
connectors =
[
];
//===================================================================
// *** Cutouts ***
// There are 6 cutouts one for each surface:
// cutoutsBase (Bottom), cutoutsLid (Top), cutoutsFront, cutoutsBack, cutoutsLeft, cutoutsRight
//-------------------------------------------------------------------
// Default origin = yappCoordPCB : pcb[0,0,0]
//
// Required Not Used Note
//----------------------+-----------------------+---------------+------------------------------------
// yappRectangle | width, length | radius |
// yappCircle | radius | width, length |
// yappRoundedRect | width, length, radius | |
// yappCircleWithFlats | width, radius | length | length=distance between flats
// yappCircleWithKey | width, length, radius | | width = key width length=key depth
// yappPolygon | width, length | radius | yappPolygonDef object must be
// | | | provided
// yappRing | width, length, radius | | radius = outer radius,
// | | | length = inner radius
// | | | width = connection between rings
// | | | 0 = No connectors
// | | | positive = 2 connectors
// | | | negative = 4 connectors
//----------------------+-----------------------+---------------+------------------------------------
//
// Parameters:
// Required:
// p(0) = from Back
// p(1) = from Left
// p(2) = width
// p(3) = length
// p(4) = radius
// p(5) = shape : { yappRectangle | yappCircle | yappPolygon | yappRoundedRect
// | yappCircleWithFlats | yappCircleWithKey }
// Optional:
// p(6) = depth : Default = 0/Auto : 0 = Auto (plane thickness)
// p(7) = angle : Default = 0
// n(a) = { yappPolygonDef } : Required if shape = yappPolygon specified -
// n(b) = { yappMaskDef } : If a yappMaskDef object is added it will be used as a mask
// for the cutout.
// n(c) = { [yappMaskDef, hOffset, vOffset, rotation] } : If a list for a mask is added
// it will be used as a mask for the cutout. With the Rotation
// and offsets applied. This can be used to fine tune the mask
// placement within the opening.
// n(d) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(e) = { <yappOrigin>, yappCenter }
// n(f) = { <yappGlobalOrigin>, yappAltOrigin } // Only affects Top(lid), Back and Right Faces
// n(g) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
// n(h) = { yappFromInside } Make the cut from the inside towards the outside
//-------------------------------------------------------------------
cutoutsBase =
[
];
cutoutsLid =
[
];
cutoutsFront =
[
];
cutoutsBack =
[
];
cutoutsLeft =
[
];
cutoutsRight =
[
];
//===================================================================
// *** Snap Joins ***
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx | posy
// p(1) = width
// p(2) = { yappLeft | yappRight | yappFront | yappBack } : one or more
// Optional:
// n(a) = { <yappOrigin>, yappCenter }
// n(b) = { yappSymmetric }
// n(c) = { yappRectangle } == Make a diamond shape snap
//-------------------------------------------------------------------
snapJoins =
[
];
//===================================================================
// *** Box Mounts ***
// Mounting tabs on the outside of the box
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Parameters:
// Required:
// p(0) = pos : position along the wall : [pos,offset] : vector for position and offset X.
// Position is to center of mounting screw in leftmost position in slot
// p(1) = screwDiameter
// p(2) = width of opening in addition to screw diameter
// (0=Circular hole screwWidth = hole twice as wide as it is tall)
// p(3) = height
// n(a) = { yappLeft | yappRight | yappFront | yappBack } : one or more
// Optional:
// p(4) = filletRadius : Default = 0/Auto(0 = auto size)
// n(b) = { yappNoFillet }
// n(c) = { <yappBase>, yappLid }
// n(d) = { yappCenter } : shifts Position to be in the center of the opening instead of
// the left of the opening
// n(e) = { <yappGlobalOrigin>, yappAltOrigin } : Only affects Back and Right Faces
//-------------------------------------------------------------------
boxMounts =
[
];
//===================================================================
// *** Light Tubes ***
//-------------------------------------------------------------------
// Default origin = yappCoordPCB: PCB[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx
// p(1) = posy
// p(2) = tubeLength
// p(3) = tubeWidth
// p(4) = tubeWall
// p(5) = gapAbovePcb
// p(6) = { yappCircle | yappRectangle } : tubeType
// Optional:
// p(7) = lensThickness (how much to leave on the top of the lid for the
// light to shine through 0 for open hole : Default = 0/Open
// p(8) = Height to top of PCB : Default = standoffHeight+pcbThickness
// p(9) = filletRadius : Default = 0/Auto
// n(a) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(b) = { <yappGlobalOrigin>, yappAltOrigin }
// n(c) = { yappNoFillet }
// n(d) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
//-------------------------------------------------------------------
lightTubes =
[
];
//===================================================================
// *** Push Buttons ***
//-------------------------------------------------------------------
// Default origin = yappCoordPCB: PCB[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx
// p(1) = posy
// p(2) = capLength
// p(3) = capWidth
// p(4) = capRadius
// p(5) = capAboveLid
// p(6) = switchHeight
// p(7) = switchTravel
// p(8) = poleDiameter
// Optional:
// p(9) = Height to top of PCB : Default = standoffHeight + pcbThickness
// p(10) = { yappRectangle | yappCircle | yappPolygon | yappRoundedRect
// | yappCircleWithFlats | yappCircleWithKey } : Shape, Default = yappRectangle
// p(11) = angle : Default = 0
// p(12) = filletRadius : Default = 0/Auto
// p(13) = buttonWall : Default = 2.0;
// p(14) = buttonPlateThickness : Default= 2.5;
// p(15) = buttonSlack : Default= 0.25;
// p(16) = snapSlack : Default= 0.20;
// n(a) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(b) = { <yappGlobalOrigin>, yappAltOrigin }
// n(c) = { yappNoFillet }
// n(d) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
//-------------------------------------------------------------------
pushButtons =
[
];
//===================================================================
// *** Labels ***
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Parameters:
// p(0) = posx
// p(1) = posy/z
// p(2) = rotation degrees CCW
// p(3) = depth : positive values go into case (Remove) negative values are raised (Add)
// p(4) = { yappLeft, yappRight, yappFront, yappBack, yappLid, yappBase } : plane
// p(5) = font
// p(6) = size
// p(7) = "label text"
// Optional:
// p(8) = Expand : Default = 0 : mm to expand text by (making it bolder)
// p(9) = Direction : { <yappTextLeftToRight>, yappTextRightToLeft, yappTextTopToBottom, yappTextBottomToTop }
// p(10) = Horizontal alignment : { <yappTextHAlignLeft>, yappTextHAlignCenter, yappTextHAlignRight }
// p(11) = Vertical alignment : { yappTextVAlignTop, yappTextVAlignCenter, yappTextVAlignBaseLine, <yappTextVAlignBottom> }
//-------------------------------------------------------------------
labelsPlane =
[
];
//===================================================================
// *** Images ***
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Parameters:
// p(0) = posx
// p(1) = posy/z
// p(2) = rotation degrees CCW
// p(3) = depth : positive values go into case (Remove) negative values are raised (Add)
// p(4) = { yappLeft, yappRight, yappFront, yappBack, yappLid, yappBase } : plane
// p(5) = "image filename.svg"
// Optional:
// p(6) = Scale : Default = 1 : ratio to scale image by (making it larger or smaller)
//-------------------------------------------------------------------
imagesPlane =
[
];
//===================================================================
// *** Ridge Extension ***
// Extension from the lid into the case for adding split opening at various heights
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Parameters:
// Required:
// p(0) = pos
// p(1) = width
// p(2) = height : Where to relocate the seam : yappCoordPCB = Above (positive) the PCB
// yappCoordBox = Above (positive) the bottom of the shell (outside)
// Optional:
// n(a) = { <yappOrigin>, yappCenter }
// n(b) = { <yappCoordPCB> | yappCoordBox | yappCoordBoxInside }
// n(c) = { <yappGlobalOrigin>, yappAltOrigin } // Only affects Top(lid), Back and Right Faces
// n(d) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
//
// Note: Snaps should not be placed on ridge extensions as they remove the ridge to place them.
//-------------------------------------------------------------------
ridgeExtFront =
[
];
ridgeExtBack =
[
];
ridgeExtLeft =
[
];
ridgeExtRight =
[
];
//===================================================================
// *** Display Mounts ***
// add a cutout to the lid with mounting posts for a display
//-------------------------------------------------------------------
// Default origin = yappCoordBox: box[0,0,0]
//
// Parameters:
// Required:
// p(0) = posx
// p(1) = posy
// p[2] : displayWidth = overall Width of the display module
// p[3] : displayHeight = overall Height of the display module
// p[4] : pinInsetH = Horizontal inset of the mounting hole
// p[5] : pinInsetV = Vertical inset of the mounting hole
// p[6] : pinDiameter,
// p[7] : postOverhang = Extra distance on outside of pins for the display to sit on - pin Diameter is a good value
// p[8] : walltoPCBGap = Distance from the display PCB to the surface of the screen
// p[9] : pcbThickness = Thickness of the display module PCB
// p[10] : windowWidth = opening width for the screen
// p[11] : windowHeight = Opening height for the screen
// p[12] : windowOffsetH = Horizontal offset from the center for the opening
// p[13] : windowOffsetV = Vertical offset from the center for the opening
// p[14] : bevel = Apply a 45degree bevel to the opening
// Optionl:
// p[15] : rotation
// p[16] : snapDiameter : default = pinDiameter*2
// p[17] : lidThickness : default = lidPlaneThickness
// n(a) = { <yappOrigin>, yappCenter }
// n(b) = { <yappCoordBox> | yappCoordPCB | yappCoordBoxInside }
// n(c) = { <yappGlobalOrigin>, yappAltOrigin } // Only affects Top(lid), Back and Right Faces
// n(d) = [yappPCBName, "XXX"] : Specify a PCB. Defaults to [yappPCBName, "Main"]
//-------------------------------------------------------------------
displayMounts =
[
];
//========= HOOK functions ============================
//-- Hook functions allow you to add 3d objects to the case.
//-- Lid/Base = Shell part to attach the object to.
//-- Inside/Outside = Join the object from the midpoint of the shell to the inside/outside.
//-- Pre = Attach the object Pre before doing Cutouts/Stands/Connectors.
//===========================================================
//-- origin = box(0,0,0)
module hookLidInsidePre()
{
//if (printMessages) echo("hookLidInsidePre() ..");
} //-- hookLidInsidePre()
//===========================================================
//-- origin = box(0,0,0)
module hookLidInside()
{
//if (printMessages) echo("hookLidInside() ..");
} //-- hookLidInside()
//===========================================================
//===========================================================
//-- origin = box(0,0,shellHeight)
module hookLidOutsidePre()
{
//if (printMessages) echo("hookLidOutsidePre() ..");
} //-- hookLidOutsidePre()
//===========================================================
//-- origin = box(0,0,shellHeight)
module hookLidOutside()
{
//if (printMessages) echo("hookLidOutside() ..");
} //-- hookLidOutside()
//===========================================================
//===========================================================
//-- origin = box(0,0,0)
module hookBaseInsidePre()
{
//if (printMessages) echo("hookBaseInsidePre() ..");
} //-- hookBaseInsidePre()
//===========================================================
//-- origin = box(0,0,0)
module hookBaseInside()
{
//if (printMessages) echo("hookBaseInside() ..");
} //-- hookBaseInside()
//===========================================================
//===========================================================
//-- origin = box(0,0,0)
module hookBaseOutsidePre()
{
//if (printMessages) echo("hookBaseOutsidePre() ..");
} //-- hookBaseOutsidePre()
//===========================================================
//-- origin = box(0,0,0)
module hookBaseOutside()
{
//if (printMessages) echo("hookBaseOutside() ..");
} //-- hookBaseOutside()
//===========================================================
//===========================================================
//-- **********************************************************
//-- **********************************************************
//-- **********************************************************
//-- *************** END OF TEMPLATE SECTION ******************
//-- **********************************************************
//-- **********************************************************
//-- **********************************************************
//===========================================================
module printBoxMounts()
{
//-------------------------------------------------------------------
module roundedRect(size, radius)
{
x1 = size[0];
x2 = size[1];
y = size[2];
l = size[3];
h = size[4];
linear_extrude(h)
{
hull()
{
// place 4 circles in the corners, with the given radius
translate([(x1+radius), (y+radius), 0])
circle(r=radius);
translate([(x1+radius), (y+l)+radius, 0])
circle(r=radius);
translate([(x2+radius), (y+l)+radius, 0])
circle(r=radius);
translate([(x2+radius), (y+radius), 0])
circle(r=radius);
}
} // linear_extrude
} //-- roundRect()
//-------------------------------------------------------------------
module oneMount(bm, maxLength, originLLOpt, invertX)
{
isCenter = isTrue(yappCenter, bm);
mountPosRaw1 = is_list(bm[0]) ? bm[0][0] : bm[0]; //-- = posx
mountOpeningDiameter = bm[1]; //-- = screwDiameter
mountWidthRaw = bm[2]; //-- = width
mountHeight = bm[3]; //-- = Height
filletRad = getParamWithDefault(bm[4],0); //-- fillet radius
bmYpos = is_list(bm[0])
? (mountOpeningDiameter*-2) - bm[0][1]
: (mountOpeningDiameter*-2);
slotOrientation = mountWidthRaw<0 ? false : true;
mountWidth = slotOrientation ? mountWidthRaw : 0;
mountLength = slotOrientation ? 0 : mountWidthRaw;
//-- Adjust for centered mounts
mountPosRaw2 = (isCenter) ? mountPosRaw1 - (mountWidth/2) : mountPosRaw1;
//-- Adjust for inverted axis
mountPosRaw = invertX ? mountPosRaw2 : -mountPosRaw2;
//-- Adjust for LowerLeft Origin
mountPos = originLLOpt ? maxLength - mountPosRaw - mountWidth : mountPosRaw;
totalmountWidth = mountWidth+mountOpeningDiameter*2;
newWidth = maxWidth(mountWidth, mountOpeningDiameter, maxLength);
scrwX1pos = mountPos;
scrwX2pos = scrwX1pos + newWidth;
newLength = maxWidth(mountLength, mountOpeningDiameter, maxLength);
scrwY1pos = 0;
scrwY2pos = scrwY1pos + newLength;
filletRadius = (filletRad==0) ? mountHeight/4 : filletRad;
outRadius = mountOpeningDiameter;
bmX1pos = scrwX1pos-mountOpeningDiameter;
bmX2pos = scrwX2pos-outRadius;
bmYpos1 = (slotOrientation) ? bmYpos : bmYpos + newLength;
bmLen = -bmYpos1+roundRadius;
//-- Get where to connect the mount defaulting to base