Full Code of mrWheel/YAPP_Box for AI

main f9400c419ef1 cached
55 files
13.9 MB
213.3k tokens
1 requests
Download .txt
Showing preview only (793K chars total). Download the full file or copy to clipboard to get everything.
Repository: mrWheel/YAPP_Box
Branch: main
Commit: f9400c419ef1
Files: 55
Total size: 13.9 MB

Directory structure:
gitextract_i9f70_ot/

├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── STL/
│   ├── MODELS/
│   │   ├── Arduino_Uno_model.stl
│   │   └── virtualP1Cable_v10_model.stl
│   ├── YAPP_ArduinoClone_v30.stl
│   ├── YAPP_Demo_buttons_v30.stl
│   └── YAPP_Demo_lightTubes_v30.stl
├── YAPP_Template_v3.scad
├── YAPPgenerator_v3.scad
└── examples/
    ├── ESP32-CAM-USB-FISH_v30.scad
    ├── ESP32-CAM-USB_v30.scad
    ├── GateAlarm_Sample_v30.scad
    ├── Multiple_PCB_v30.scad
    ├── PoolMonitor_v30.scad
    ├── RidgeExtDemo_v30.scad
    ├── WaterHeaterMonitor_v3.scad
    ├── YAPP_ArduinoClone_v30.scad
    ├── YAPP_Connector_Demo.scad
    ├── YAPP_Countersink Sample_v3.scad
    ├── YAPP_Demo_DisplayMount_LCD2004.scad
    ├── YAPP_Demo_DisplayMount_v31.scad
    ├── YAPP_Demo_Joystick_Paddle Controller_v30.scad
    ├── YAPP_Demo_Labels_v3.scad
    ├── YAPP_Demo_RealBox_v30.scad
    ├── YAPP_Demo_RealBox_v31.scad
    ├── YAPP_Demo_boxMounts_v30.scad
    ├── YAPP_Demo_boxMounts_v31.scad
    ├── YAPP_Demo_buttons2_v30.scad
    ├── YAPP_Demo_buttons2_v31.scad
    ├── YAPP_Demo_buttons_v30.scad
    ├── YAPP_Demo_buttons_v31.scad
    ├── YAPP_Demo_connectors_v33.scad
    ├── YAPP_Demo_cutout_yappRing_v30.scad
    ├── YAPP_Demo_cutout_yappRing_v31.scad
    ├── YAPP_Demo_cutout_yappSphere_v30.scad
    ├── YAPP_Demo_cutouts_all_coord_systems_v30.scad
    ├── YAPP_Demo_cutouts_all_coord_systems_v31.scad
    ├── YAPP_Demo_cutouts_masks_v30.scad
    ├── YAPP_Demo_cutouts_v30.scad
    ├── YAPP_Demo_imagesPlane_v3.scad
    ├── YAPP_Demo_lightTubes_v30.scad
    ├── YAPP_HookTest_v30.scad
    ├── YAPP_Reference_Masks_v30.scad
    ├── YAPP_Reference_Shapes_v30.scad
    ├── YAPP_RidgeExtDemo_v30.scad
    ├── YAPP_RidgeExtDemo_v31.scad
    ├── YAPP_TEST_BoxTypes_v32.scad
    ├── YAPP_Test_SnapJoints_v30.scad
    ├── YAPP_ViewShapes_v30.scad
    ├── YAPP_WemosD1mini_v30.scad
    ├── YAPP_connectors_v30.scad
    ├── YAPP_cutouts_from_inside_v30.scad
    └── pcbStandTest.scad

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================


================================================
FILE: CHANGELOG.md
================================================
# YAPP Change Log

## Rev. v3.0.1 (2024-01-15)
* Re-organzie Git repo to maintain only the latest version in the `main` branch.
* The core files (`YAPP_Template_v3.scad`, `YAPPgenerator_v3.scad`) now keep only a major version in their filename, and live in the root of the repo.

## Rev. 3.0.0  (2023-12-01)

Lead Developer for v3.0: <a href="https://github.com/rosenhauer">Dave Rosenhauer</a>
Dave added new functionality, fixed many bugs, is the creator of the v3.0 API and did a lot of code cleanup.
He made more than 20 merge requests in three weeks.

**New functionality**
<pre>
Cutout Shapes
	Cutouts now support more shapes.
		yappRectangle	    : Rectangle with size 'width' x 'length' 
		yappCircle	    : Circle with radius of 'radius'
		yappRoundedRect	    : Rectangle with size 'width' x 'length' and corner 
                                      radius of 'radius'
		yappPolygon	    : User defined polygon. Three standard shapes are 
                                      included for use/reference - 'shapeIsoTriangle', 
                                      'shapeHexagon', 'shape6ptStar' 
		yappCircleWithFlats : Circle with radius of 'radius' with the sides 
                                      clipped to width (length is not used)
    		yappCircleWithKey   : Circle with radius of 'radius' with a rectangular 
                                      key of width x length (length is key depth)

Cutout Masks

Fillets
	Fillets are automatically added to all appropriate items.  
	This can be overridden with the yappNoFillet option.  
	Fillet radius can also be changed from default (same as connected wall thickness) 
	with the filletRadius parameter.

Ridge Extension
  Extension from the lid into the case for adding split opening at various heights

//========= HOOK dummy 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.

//===========================================================
// origin = box(0,0,0)
module hookLidInside()
{
} // hookLidInside()
  
//===========================================================
// origin = box(0,0,shellHeight)
module hookLidOutside()
{
} // hookLidOutside()

//===========================================================
// origin = box(0,0,0)
module hookBaseInside()
{
} // hookBaseInside()

//===========================================================
// origin = box(0,0,0)
module hookBaseOutside()
{
} // hookBaseOutside()

//===========================================================
//===========================================================
</pre>

**Updated definition standards:**
<pre>
     Parameters:
	p(0,1 ...) = a 'p' with a number between parentheses indicates a 
	                    'positional' parameter.
	n(a,b ...) = a 'n' with a letter between parentheses indicates an 
	                    optional, 'non-positional' parameter must be after 
	                    the required parameters.
	{ yappParameter }
	&lt;Default value&gt;
	| means one or more values from the list are allowed
	, means only one value from the list is allowed
</pre>

**This version breaks with the API for the following objects:**

<pre>
===================================================================
  *** 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 = defaultStandoffHeight
  p(3) = standoffDiameter    = defaultStandoffDiameter;
  p(4) = standoffPinDiameter = defaultStandoffPinDiameter;
  p(5) = standoffHoleSlack   = defaultStandoffHoleSlack;
  p(6) = filletRadius (0 = auto size)
  n(a) = { &lt;yappBoth&gt; | yappLidOnly | yappBaseOnly }
  n(b) = { &lt;yappPin&gt;, yappHole } : Baseplate support treatment
  n(c) = { &lt;yappAllCorners&gt; | yappFrontLeft | yappFrontRight | yappBackLeft | yappBackRight }
  n(d) = { &lt;yappCoordPCB&gt;, yappCoordBox }  
  n(e) = { yappNoFillet }
</pre>

<pre>
===================================================================
  *** Connectors ***
  Standoffs with hole through base and socket in lid for screw type connections.
-------------------------------------------------------------------
Default origin = yappCoordBox: box[0,0,0]
  
Parameters:
 Required:
  p(0) = posx
  p(1) = posy
  p(2) = pcbStandHeight
  p(3) = screwDiameter
  p(4) = screwHeadDiameter : (don't forget to add extra for the fillet)
  p(5) = insertDiameter
  p(6) = outsideDiameter
 Optional:
  p(7) = filletRadius : Default = 0/Auto(0 = auto size)
  n(a) = { &lt;yappAllCorners&gt; | yappFrontLeft | yappFrontRight | yappBackLeft | yappBackRight }
  n(b) = { &lt;yappCoordBox&gt;, yappCoordPCB }
  n(c) = { yappNoFillet }
</pre>

<pre>
===================================================================
  *** Base Mounts ***
  Mounting tabs on the outside of the box
-------------------------------------------------------------------
Default origin = yappCoordBox: box[0,0,0]

Parameters:
 Required:
  p(0) = pos
  p(1) = screwDiameter
  p(2) = width
  p(3) = height
 Optional:
  p(4) = filletRadius : Default = 0/Auto(0 = auto size)
  n(a) = { yappLeft | yappRight | yappFront | yappBack } : (one or more)
  n(b) = { yappNoFillet }
</pre>

<pre>
===================================================================
  *** Cutouts ***
  There are 6 cutouts one for each surface:
    cutoutsBase, cutoutsLid, cutoutsFront, cutoutsBack, cutoutsLeft, cutoutsRight
-------------------------------------------------------------------
Default origin = yappCoordBox: box[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
--------------------+-----------------------+---------------+------------------------------------

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) = { &lt;yappCoordBox&gt;, yappCoordPCB }
  n(d) = { &lt;yappOrigin&gt;, yappCenter }
  n(e) = { &lt;yappGlobalOrigin&gt;, yappLeftOrigin } : Only affects Top, Back and Right Faces
</pre>

<pre>
===================================================================
  *** 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) = { &lt;yappOrigin&gt;, yappCenter }
  n(b) = { yappSymmetric }
  n(c) = { yappRectangle } == Make a diamond shape snap
</pre>

<pre>
===================================================================
  *** 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 = defaultStandoffHeight+pcbThickness
  p(9) = filletRadius : Default = 0/Auto 
  n(a) = { &lt;yappCoordPCB&gt;, yappCoordBox }
  n(b) = { yappNoFillet }
</pre>

<pre>
===================================================================
  *** Push Buttons ***
-------------------------------------------------------------------
Default origin = yappCoordPCB: PCB[0,0,0]

Parameters:
 Required:
  p(0) = posx
  p(1) = posy
  p(2) = capLength for yappRectangle, capDiameter for yappCircle
  p(3) = capWidth for yappRectangle, not used for yappCircle
  p(4) = capAboveLid
  p(5) = switchHeight
  p(6) = switchTravel
  p(7) = poleDiameter
 Optional:
  p(8) = Height to top of PCB : Default = defaultStandoffHeight + pcbThickness
  p(9) = { &lt;yappRectangle&gt;, yappCircle } : buttonType, Default = yappRectangle
  p(10) = filletRadius : Default = 0/Auto 
</pre>

## Rev. 2.0  (21-05-2023)

**New functionality *lightTubes* **

With the **lightTubes** array you can define where you want tubes for LED's and NeoPixles**

<pre>
//-- lightTubes  -- origin is pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = tubeLength
// (3) = tubeWidth
// (4) = tubeWall
// (5) = abovePcb
// (6) = tubeType  {yappCircle|yappRectangle}
lightTubes = [
              //--- 0,    1, 2, 3, 4, 5, 6
                  [84.5, 21, 3, 6, 1, 4, yappRectangle]
                , [30,   21, 5, 0, 1, 2, yappCircle]
              ];     
</pre>

![lightTube_top](https://github.com/mrWheel/YAPP_Box/assets/5585427/fe4eba60-416b-4b35-b0f3-4e3df204a900)
![lightTube_a](https://github.com/mrWheel/YAPP_Box/assets/5585427/6c79d4ff-faff-4e8d-8283-2d2a5d49d4d8)

<pre>
posx        - the position of the center of the led on the X-axes of the PCB
posy        - the position of the center of the led on the Y-axes of the PCB
tubeLength  - the length of the tube (if yappRectangle) or the diameter of the tube (if yappCircle)
tubeWidth   - the width of the tube (not used if yappCircle)
tubeWall    - the width of the wall around the led
abovePcp    - how hight the tube will begin with respect to the top of the PCB
tubeType    - whether the led shows as a circle (yappCircle) or a rectangle (yappRectangle)
</pre>


**New functionality *pushButtons* (experimental)**

With the **pushButtons** array you can define where you want button guides for tactile switches.</br>

<pre>
//-- pushButtons  -- origin is pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = capLength
// (3) = capWidth
// (4) = capAboveLid
// (5) = switchHeight
// (6) = switchTrafel
// (7) = poleDiameter
// (8) = buttonType  {yappCircle|yappRectangle}
pushButtons = [
                 [15, 30, 8, 8, 0, 1,   1, 3.5, yappCircle]
               , [15, 10, 8, 6, 2, 4.5, 1, 3.5, yappRectangle]
              ];
</pre>

![buttonGuides](https://github.com/mrWheel/YAPP_Box/assets/5585427/7940ec0e-10a3-408b-8c11-4d811efb7720)

The "Plate" has to be glued to the "Pole".

<pre>
posx         - the position of the center of the tacktile switch on the PCB
posy         - the position of the center of the tacktile switch on the PCB
capLength    - the length of the button (if yappRectangle) or the diameter (if yappCircle)
capWidth     - the width of the button (if yappRectangle, otherwise ignored)
capAboveLid  - how much the button cap is above the lid
switchHeight - the height of the tactile switch
switchTrafel - the distance the button has to trafel to activate the tacktile switch
poleDiameter - the diameter of the pole that connects the button cap with the plate
buttonType   - either yappCircle or yappRectangle
</pre>

<hr>

## Rev. 1.8  (22-02-2023)

**This version breaks with the API for the following array's:**

* pcbStand[..] (extra parameter for standoffHeight)
* connectors[..] (extra parameter for baseConnector Height)

<pre>
//-- pcb_standoffs  -- origin is pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = standoffHeight
// (3) = flangeHeight
// (4) = flangeDiameter
// (5) = { yappBoth | yappLidOnly | yappBaseOnly }
// (6) = { yappHole, YappPin }
// (7) = { yappAllCorners | yappFrontLeft | yappFrontRight | yappBackLeft | yappBackRight }
pcbStands = [
                [3,  3, 5, 3, 11, yappBoth, yappPin, yappAllCorners]
               ,[5,  5, 5, 4, 10, yappBoth, yappPin, yappBackLeft, yappFrontRight]
               ,[8,  8, 5, 4, 11, yappBoth, yappPin]
               ,[pcbLength-15, pcbWidth-15, 8, 4, 12, yappBoth, yappPin]
             ];
</pre>
<pre>
//-- connectors
//-- normal         : origen = box[0,0,0]
//-- yappConnWithPCB: origen = pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = pcbStandHeight
// (3) = screwDiameter
// (4) = screwHeadDiameter
// (5) = insertDiameter
// (6) = outsideDiameter
// (7) = flangeHeight
// (8) = flangeDiam
// (9) = { yappConnWithPCB }
// (10) = { yappAllCorners | yappFrontLeft | yappFrontRight | yappBackLeft | yappBackRight }
connectors   =  [
                    [ 8,  8, 5, 2.5, 2.8, 3.8, 6, 6, 15, yappAllCorners]
                  , [28, 58, 5, 2.5, 2.8, 3.8, 6, 6, 25, yappConnWithPCB]
                ];

</pre>

<hr>

## Rev. 1.7

**This version breaks with the API for the following array's:**

* pcbStand[..] (extra parameter for flange)
* connectors[..] (huge change lots of extra parameters)
* connectosPCB[..] (removed)

<pre>
//-- pcb_standoffs  -- origin is pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = flangeHeight
// (3) = flangeDiameter
// (4) = { yappBoth | yappLidOnly | yappBaseOnly }
// (5) = { yappHole, YappPin }
// (6) = { yappAllCorners | yappFrontLeft | yappFrontRight | yappBackLeft | yappBackRight }
pcbStands = [
                [3,  3, 3, 11, yappBoth, yappPin, yappAllCorners]
               ,[5,  5, 4, 10, yappBoth, yappPin, yappBackLeft, yappFrontRight]
               ,[8,  8, 4, 11, yappBoth, yappPin]
               ,[pcbLength-15, pcbWidth-15, 4, 12, yappBoth, yappPin]
             ];
</pre>
<pre>
//-- connectors
//-- normal         : origen = box[0,0,0]
//-- yappConnWithPCB: origen = pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = screwDiameter
// (3) = screwHeadDiameter
// (4) = insertDiameter
// (5) = outsideDiameter
// (6) = flangeHeight
// (7) = flangeDiam
// (8) = { yappConnWithPCB }
// (9) = { yappAllCorners | yappFrontLeft | yappFrontRight | yappBackLeft | yappBackRight }
connectors   =  [
                    [8, 8, 2.5, 2.8, 3.8, 6, 6, 15, yappAllCorners]
                  , [28, 58, 2.5, 2.8, 3.8, 6, 6, 25, yappConnWithPCB]
                ];

</pre>

The depth of the screw in the connectors is now depending on the standoffHeight so the
screw size does not change anymore.
![YAPP_connectorRevised](https://user-images.githubusercontent.com/5585427/220582716-41c8d56b-0782-42ce-937f-401495f3889b.png)


<hr>

## Rev. 1.6

- new cutoutGrills array
<pre>
//-- cutoutGrills    -- origin is box[x0,y0]
// (0) = xPos
// (1) = yPos
// (2) = grillWidth
// (3) = grillLength
// (4) = gWidth
// (5) = gSpace
// (6) = gAngle
// (7) = plane [ "base" | "lid" ]
// (8) = {polygon points} (optional)


cutoutGrills = [
                 [22, 22, 90, 90, 2, 3, 50, "base", [  [0,15],[20,15],[30,0],[40,15],[60,15]
                                                      ,[50,30],[60,45], [40,45],[30,60]
                                                      ,[20,45], [0,45],[10,30] ]
                 ]
                ,[15, 10, 50, 10, 2, 3, -20, "base"]
                ,[15, 15, 10, 50, 2, 3, -45, "lid"]
                ,[15, 85, 50, 10, 2, 3,  20, "base"]
                ,[85, 15, 10, 50, 2, 3,  45, "lid"]
               ];
</pre>
![cutoutGrills-v16](https://user-images.githubusercontent.com/5585427/192301088-056f7f9c-f89f-40a2-a7ba-f4496d4e722c.png)

**Be aware**: this functionality needs a **huge** amount of rendering elements.

You can set this at `Preferences->Advanced->Turn of rendering at 100000 elements`
<hr>

## Rev. 1.5

- Various bug-fixes
- Connectors now have a flange at the basePlane and lidPlane for a better adhesion

*This release breaks with previous releases in the extra parm "**depth**" in the labels array!!*

The labels now have this syntax:
<pre>
//-- origin of labels is box [0,0,0]
// (0) = posx
// (1) = posy/z
// (2) = orientation
// (3) = depth
// (4) = plane {lid | base | left | right | front | back }
// (5) = font
// (6) = size
// (7) = "label text"
</pre>

Example:
<pre>
labelsPlane = [
                [10,  10,   0, 0.6, "lid",   "Liberation Mono:style=bold", 15, "YAPP" ]
               ,[100, 90, 180, 0.8, "base",  "Liberation Mono:style=bold", 11, "Base" ]
               ,[8,    8,   0, 1.0, "left",  "Liberation Mono:style=bold",  7, "Left" ]
               ,[10,   5,   0, 1.2, "right", "Liberation Mono:style=bold",  7, "Right" ]
               ,[40,  23,   0, 1.5, "front", "Liberation Mono:style=bold",  7, "Front" ]
               ,[5,    5,   0, 2.0, "back",  "Liberation Mono:style=bold",  8, "Back" ]
              ];
</pre>

For your box to work with this release as before you have to add this extra 
parm (as "wallThickness/2", "basePlaneThickness/2" or "lidPlaneThickness/2").

Thanks to *Keith Hadley*

There now is a new array for connectors that holds the PCB. This array is called "**connectorsPCB**".
<pre>
//-- connectorsPCB -- origin = pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = screwDiameter
// (3) = insertDiameter
// (4) = outsideDiameter
// (5) = { yappAllCorners }
</pre>

Example:
<pre>
connectorsPCB = [
                  [pcbLength/2, 10, 2.5, 3.8, 5]
                 ,[pcbLength/2, pcbWidth-10, 2.5, 3.8, 5]
                ];
</pre>
It takes in account the "**pcbThickness**" to calculate the hight of the lid-connector.

Thanks to *Oliver Grafe*

![connectorTypes](https://user-images.githubusercontent.com/5585427/192100231-b6df4e7d-50e8-4b75-8e8b-85a4b2d3e3b7.png)


<hr>

## Rev. 1.4

*This release breaks with previous releases in the extra parm "**angle**" in all the cutouts array's!!!*

All plane array's now have this syntax:

<pre>
//-- plane    -- origin is pcb[0,0,0]
// (0) = posx
// (1) = posy
// (2) = width
// (3) = length
// (4) = angle
// (5) = { yappRectangle | yappCircle }
// (6) = { yappCenter }
</pre>

For your box to work with this release you have to add this extra parm (as "***0***") to all your cutOut-array-row's



================================================
FILE: LICENSE
================================================
MIT License

Copyright (c) 2022 Willem Aandewiel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
# YAPP_Box
Yet Another Parametric Projectbox generator

This OpenSCAD project can be used to create extremely comprehensive and customizable project boxes/enclosures using OpenSCAD.

The [complete and official documentation gitbook](https://mrwheel-docs.gitbook.io/yappgenerator_en/) explains the entire API.

You can open Issues here, but please also place them in a comment at one of the following blog posts:
* "<a href="https://willem.aandewiel.nl/index.php/2022/01/02/yet-another-parametric-projectbox-generator/">Yet Another Parametric Projectbox generator blog post</a>" (English)
* "<a href="https://willem.aandewiel.nl/index.php/2022/01/01/nog-een-geparameteriseerde-projectbox-generator/">Nog een geparametriseerde projectbox generator</a>" (Dutch).

<hr>

I have done my best, but it can probably be done simpler. 
If you think you can help, please contact me or make a Pull Request.

## How to program your Project Box
It all starts with the dimensions of the PCB going inside your Project Box, as well as a few other dimensions:

```openscad
printBaseShell      = true;
printLidShell       = true;

// Edit these parameters for your own board dimensions
wallThickness       = 1.0;
basePlaneThickness  = 1.0;
lidPlaneThickness   = 1.0;

// Total height of box = basePlaneThickness + lidPlaneThickness 
//                     + baseWallHeight + lidWallHeight

baseWallHeight      = 7;
lidWallHeight       = 4;

pcbLength           = 88;
pcbWidth            = 49;
pcbThickness        = 1.5;
                            
// padding between pcb and inside wall
paddingFront        = 4;
paddingBack         = 1;
paddingRight        = 1;
paddingLeft         = 1;

// ridge where Base- and Lid- off the box can overlap
// Make sure this isn't less than lidWallHeight
ridgeHeight         = 3;
ridgeSlack          = 0.2;
roundRadius         = 2.0;  // don't make this to big..

//-- How much the PCB needs to be raised from the base
//-- to leave room for solderings and whatnot
standoffHeight      = 5.0;
pinDiameter         = 1.0;
pinHoleSlack        = 0.5;
standoffDiameter    = 4;
```

You probably want some cutouts in your box for connectors and stuff.
For every plane (side) of the Project Box, there is an array that holds the cutouts for that plane.

A picture is worth a thousand words ...

### Cutouts in the *Right* Plane:
![YAPP_cutoutsRight](https://user-images.githubusercontent.com/5585427/150956351-cef4fc0e-474d-4b44-b667-1a4d227400b6.png)

### Cutouts in the *Left* Plane:
![YAPP_cutoutsLeft](https://user-images.githubusercontent.com/5585427/150956356-ec4d5e17-c78e-41ae-bcd7-be8710f5a32c.png)

### Cutouts in the *Back* Plane:
![YAPP_cutoutsBack](https://user-images.githubusercontent.com/5585427/150956361-aa0c924f-ddc3-4260-a999-be9cd5b80b2e.png)

### Cutouts in the *Front* Plane:
![YAPP_cutoutsFront](https://user-images.githubusercontent.com/5585427/150956366-d5ca6715-7bdf-4ce7-bae7-1d8c79737eb6.png)

### Cutouts in the *Base*:
![YAPP_cutoutsBase](https://user-images.githubusercontent.com/5585427/150956371-8ed2d85a-3c49-48c6-b0db-1742053f2455.png)

### Cutouts in the *Lid*:
![YAPP_cutoutsLid](https://user-images.githubusercontent.com/5585427/150956374-c0de9d91-03a4-4ee3-8475-fecb251e9bca.png)

### Using the *angle* param (rotate around the x/y corner):
![yappRectangle40dgrs](https://user-images.githubusercontent.com/5585427/157865661-02407bfe-fada-4528-b25c-ea83c94b9467.png)

#### With `yappCenter`, the rectangle will rotate around its center point:
![yappRectangleCenter10dgrs](https://user-images.githubusercontent.com/5585427/157865668-2b10bbe0-6223-4e6e-b74b-b81fb919f3da.png)

### Base mounts:
![Screenshot 2022-01-25 at 11 25 46](https://user-images.githubusercontent.com/5585427/150959614-b0d07141-27aa-4df3-b45e-09e662bacde9.png)

### `pcbStands`:
`pcbStands` fixate the PCB between the base and the lid.
![YAPP_pcbStands](https://user-images.githubusercontent.com/5585427/150956378-ccdcdd88-9f0c-44cd-986f-70db3bf6d8e2.png)

### Connectors between *Base* and *Lid*:
![YAPP_connectors](https://user-images.githubusercontent.com/5585427/150956348-cfb4f550-a261-493a-9b86-6175e169b2bc.png)

### ConnectorsPCB between *Base* and *Lid* that fixates the PCB:
![connectorTypes](https://user-images.githubusercontent.com/5585427/192100231-b6df4e7d-50e8-4b75-8e8b-85a4b2d3e3b7.png)

![YAPP_connector_D](https://user-images.githubusercontent.com/5585427/150956341-5c087f45-c228-46db-8eb1-b3add2e9afca.png)

Inserts are great for making a screw connection between the base and the lid.
![Ruthex-insert-a](https://user-images.githubusercontent.com/5585427/150959697-beaf6a25-b1df-4a1d-901b-dbcdf486b612.png)


### Snap Joins:
![snapJoins1](https://user-images.githubusercontent.com/5585427/153425134-ec2348cd-45a7-4e2d-8cb6-2f69e6f7f80b.png)

![snapJoins2](https://user-images.githubusercontent.com/5585427/153425125-04daa8ca-1126-4467-94a8-245c584d2333.png)

#### Snap Joins *Symmetrical*:
![snapJoinsSymetric](https://user-images.githubusercontent.com/5585427/153425131-df24321f-9cc6-4dd6-aff6-41627915afa7.png)

### (more) Base Mounts:
![yappBaseStand](https://user-images.githubusercontent.com/5585427/153425136-9bc916a2-1245-4b3e-9072-8dd7ed8c3df6.png)

![yappBaseStand3D](https://user-images.githubusercontent.com/5585427/153425139-0b27f2f0-f12c-4d89-b394-70ebcf3e1c4f.png)

### Hooks:
There are two type of "hooks"; at the inside of the box or at the outside of the box
#### `baseHookOutside()`:
![baseHookOutside](https://user-images.githubusercontent.com/5585427/153425144-9401e969-8988-47e6-9c12-a3eaf052bfca.png)

![baseHookOutside3D](https://user-images.githubusercontent.com/5585427/153425145-ecd9bebd-82ba-4ab0-9685-9bf1c9b9273f.png)
#### `lidHookInside()`:
![lidHooksInside1](https://user-images.githubusercontent.com/5585427/153425146-485d8cde-c530-4ab6-879d-3958ca5384ba.png)

![lidHooksInside3Db](https://user-images.githubusercontent.com/5585427/153425147-831b7f9c-1c74-4c58-8a3d-11b96aaf3107.png)

![lidHooksInside3Da](https://user-images.githubusercontent.com/5585427/153426442-6a05f787-8897-4610-8411-bb7279269980.png)

<hr>

## Buy me a coffee (please)!

If you like this project or it saved you time, you can give me a cup of coffee :)

<p>
  <a href="https://www.paypal.me/WillemAandewiel/3">
      <img width="300" alt="bmc-button-75" src="https://user-images.githubusercontent.com/5585427/192536527-306e1082-7d4e-402c-b024-658d9e334356.png" alt="Coffee">
  </a>
</p>

## Versioning
* All major releases (v1, v2, v3) are intended to be compatible with all files previously designed for v3 (e.g., the v3.1 release will not remove features or make any breaking changes, compared to v3.0).
* The filename of the library (e.g., `YAPPgenerator_v3.scad`) will thus have only the major version in its filename.
* When a new major version is released, a branch will be created from the `main` branch at the last commit before work is started on the next major version. This branch can be used to fix bugs and add features to the old release version, if desired. These lineage branches will not be merged to `main`, and will continue on their own path.
* All future tagged versions will have GitHub Releases created for them, which will include the changelog for the release. The `YAPP_Template_vx.scad` and `YAPPgenerator_vx.scad` files will also be attached to the release.
* The ISO8601 international standard date format (yyyy-mm-dd) will be used for documenting dates.


================================================
FILE: STL/MODELS/virtualP1Cable_v10_model.stl
================================================
[File too large to display: 13.1 MB]

================================================
FILE: YAPP_Template_v3.scad
================================================
//-----------------------------------------------------------------------
// Yet Another Parameterized Projectbox generator
//
//  This is a box for <template>
//
//  Version 3.3.7 (2025-04-17)
//
// This design is parameterized based on the size of a PCB.
//
// For many/complex cutoutGrills, you might need to adjust
//  the max number of elements in OpenSCAD:
//
//      Preferences->Advanced->Turn off rendering at 250000 elements
//                                                   ^^^^^^
//
//-----------------------------------------------------------------------

include <./YAPPgenerator_v3.scad>

//---------------------------------------------------------
// This design is parameterized based on the size of a PCB.
//---------------------------------------------------------
// Note: length/lengte refers to X axis, 
//       width/breedte refers to Y axis,
//       height/hoogte refers to Z axis

/*
      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;

// ********************************************************************
// 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           = 150; // front to back (X axis)
pcbWidth            = 100; // 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 and whatnot
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 = Height to bottom of PCB from the inside of the base
//             negative measures from inside of the lid to the top of the PCB
//    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 elsewhere in the script - not in pcb definition. 
//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]
];

//-------------------------------------------------------------------                            
//-- padding between pcb and inside wall
paddingFront        = 2;
paddingBack         = 2;
paddingRight        = 2;
paddingLeft         = 2;

//-- 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) - (standoffHeight+pcbThickness)
baseWallHeight      = 25;
lidWallHeight       = 23;

//-- ridge where base and lid off box can overlap
//-- Make sure this isn't less than lidWallHeight
ridgeHeight         = 5.0;
ridgeSlack          = 0.3; // Gap between the inside of the lid and the outside of the base
//New in v3.3.7 
ridgeGap            = 0.5; // Gap between the bottom of the base ridge and the bottom of the lid when assembled.
roundRadius         = 3.0;

// Box Types are 0-4 with 0 as the default
// 0 = All edges rounded with radius (roundRadius) above
// 1 = All edges sqrtuare
// 2 = All edges chamfered by (roundRadius) above 
// 3 = Square top and bottom edges (the ones that touch the build plate) and rounded vertical edges
// 4 = Square top and bottom edges (the ones that touch the build plate) and chamfered vertical edges
// 5 = Chanfered top and bottom edges (the ones that touch the build plate) and rounded vertical edges
boxType             = 0; // Default type 0

// Set the layer height of your printer
printerLayerHeight  = 0.2;


//---------------------------
//--     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
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     --
//---------------------------

//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Start of Debugging config (used if not overridden in template)
// ------------------------------------------------------------------
// ------------------------------------------------------------------

//==================================================================
//  *** Shapes ***
//------------------------------------------------------------------
//  There are a view pre defines shapes and masks
//  shapes:
//      shapeIsoTriangle, shapeHexagon, shape6ptStar
//
//  masks:
//      maskHoneycomb, maskHexCircles, maskBars, maskOffsetBars
//
//------------------------------------------------------------------
// 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]]];
// To see how to add your own shapes and mask see the YAPPgenerator program
//------------------------------------------------------------------


// Show sample of a Mask
//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 from inside of base: Default = standoffHeight
//             negative measures from inside of the lid to the top of the PCB
//    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
//             yappTopPin = 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"]
//    n(g) = yappSelfThreading : make the hole a self threading hole 
//             This ignores the holeSlack and would only be usefull 
//             if the opposing stand if deleted see sample in Demo_Connectors
//-------------------------------------------------------------------
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 or specify yappNoInternalFillet)
//    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 } : Don't add fillets
//    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}
//    n(g) = {yappSelfThreading} : Make the insert self threading specify the Screw Diameter in the insertDiameter
//    n(h) = { yappNoInternalFillet } : Don't add internal fillets (external fillets can still be added)

//-------------------------------------------------------------------
connectors   =
[
];


//===================================================================
//  *** Cutouts ***
//    There are 6 cutouts one for each surface:
//      cutoutsBase (Bottom), cutoutsLid (Top), cutoutsFront, cutoutsBack, cutoutsLeft, cutoutsRight
//-------------------------------------------------------------------
//  Default origin = yappCoordBox: box[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
//                      |                       |               |  (negative indicates outside of circle)
//  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
//  yappSphere          | width, radius         |               | Width = Sphere center distance from
//                      |                       |               |   center of depth.  negative = below
//                      |                       |               | radius = sphere radius
//----------------------+-----------------------+---------------+------------------------------------
//
//  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 | yappSphere }
//  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;
//    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> } 
//   p(12) = Character Spacing multiplier (1.0 = normal)
//-------------------------------------------------------------------
labelsPlane =
[
];


//===================================================================
//  *** 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) = { yappAltOrigin, <yappGlobalOrigin> } // 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.
//-------------------------------------------------------------------
ridgeExtLeft =
[
];

ridgeExtRight =
[
];

ridgeExtFront =
[
];

ridgeExtBack =
[
];


//===================================================================
//  *** 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 towards outside of pins to move the post for the display to sit on - 0 = centered : pin Diameter will move the post to align to the outside of the pin (moves it half the distance specified for compatability : -pinDiameter will move it in.
//    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"]
//    n(e) = {yappSelfThreading} : Replace the pins with self threading holes
//-------------------------------------------------------------------
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 hookLidInside()
{
  //if (printMessages) echo("hookLidInside() ..");
  
} // hookLidInside()
  

//===========================================================
// origin = box(0,0,shellHeight)
module hookLidOutside()
{
  //if (printMessages) echo("hookLidOutside() ..");
  
} // hookLidOutside()

//===========================================================
//===========================================================
// origin = box(0,0,0)
module hookBaseInside()
{
  //if (printMessages) echo("hookBaseInside() ..");
  
} // hookBaseInside()

//===========================================================
// origin = box(0,0,0)
module hookBaseOutside()
{
  //if (printMessages) echo("hookBaseOutside() ..");
  
} // hookBaseInside()

// **********************************************************
// **********************************************************
// **********************************************************
// *************** END OF TEMPLATE SECTION ******************
// **********************************************************
// **********************************************************
// **********************************************************

//---- This is where the magic happens ----
YAPPgenerate();


================================================
FILE: YAPPgenerator_v3.scad
================================================
/*
***************************************************************************  
**  Yet Another Parameterised Projectbox generator
**
*/

Version="v3.3.8 (2025-10-24)";

/*
**
**  Copyright (c) 2021, 2022, 2023, 2024, 2025 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 = Height to bottom of PCB from the inside of the base
//             negative measures from inside of the lid to the top of the PCB
//    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.8;
basePlaneThickness  = 1.6;
lidPlaneThickness   = 1.6;

//-- 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.2; // Gap between the inside of the lid and the outside of the base
//New in v3.3.7 
ridgeGap            = 0.5; // Gap between the bottom of the base ridge and the bottom of the lid when assembled.

//-- Radius of the shell corners
roundRadius         = wallThickness + 1;  // Default to 1 more than the wall thickness

// Box Types are 0-5 with 0 as the default
// 0 = All edges rounded with radius (roundRadius) above
// 1 = All edges square
// 2 = All edges chamfered by (roundRadius) above 
// 3 = Square top and bottom edges (the ones that touch the build plate) and rounded vertical edges
// 4 = Square top and bottom edges (the ones that touch the build plate) and chamfered vertical edges
// 5 = Chamfered top and bottom edges (the ones that touch the build plate) and rounded vertical edges
boxType = 5; // Default type 0


//---------------------------
//--     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;
yappSphere              = -30007; //-- New 3.3

// NEW for 3.x 
// Edge Shapes
yappEdgeRounded         = -30090;
yappEdgeSquare          = -30091;
yappEdgeChamfered       = -30092;

//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
yappSelfThreading       = -30602;  // connectors, displayMounts
yappNoInternalFillet    = -30603;  // connectors
yappHalfSelfThreading   = -30604;  // displayMounts

// 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);

//-- For New boxTypes (Default to all edges rounded)
//-- options: 
//--    yappEdgeRounded - rounded using roundRadius
//--    yappEdgeSquare - squared corners
//--    yappEdgeChamfered - chamfered with roundRadius sides

boxStyles = [
  [0, yappEdgeRounded, yappEdgeRounded],
  [1, yappEdgeSquare, yappEdgeSquare],
  [2, yappEdgeChamfered, yappEdgeChamfered],
  [3, yappEdgeSquare, yappEdgeRounded],
  [4, yappEdgeSquare, yappEdgeChamfered],
  [5, yappEdgeChamfered, yappEdgeRounded],
];

shellEdgeTopBottom = boxStyles[boxType][1];
shellEdgeVert = boxStyles[boxType][2];

//-------------------------------------------------------------------
// 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],
  ];

//-- Define 3 optional custom masks that can be defined in the script
maskCustom1 = [];
maskCustom2 = [];
maskCustom3 = [];


//-- 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 from inside of base: Default = standoffHeight
//             negative measures from inside of the lid to the top of the PCB
//    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
//             yappTopPin = 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"]
//    n(g) = yappSelfThreading : make the hole a self threading hole 
//             This ignores the holeSlack and would only be usefull 
//             if the opposing stand if deleted see sample in Demo_Connectors
//-------------------------------------------------------------------
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 or specify yappNoInternalFillet)
//    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 } : Don't add fillets
//    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}
//    n(g) = {yappSelfThreading} : Make the insert self threading specify the Screw Diameter in the insertDiameter
//    n(h) = { yappNoInternalFillet } : Don't add internal fillets (external fillets can still be added)

//-------------------------------------------------------------------
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
//                      |                       |               |  (negative indicates outside of circle)
//  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
//  yappSphere          | width, radius         |               | Width = Sphere center distance from
//                      |                       |               |   center of depth.  negative = below
//                      |                       |               | radius = sphere radius
//----------------------+-----------------------+---------------+------------------------------------
//
//  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 | yappSphere }
//  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> } 
//   p(12) = Character Spacing multiplier (1.0 = normal)
//-------------------------------------------------------------------
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 towards outside of pins to move the post for the display to sit on - 0 = centered : pin Diameter will move the post to align to the outside of the pin (moves it half the distance specified for compatability : -pinDiameter will move it in.
//    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

//    p[18] : snapSlack : default = 0.05

//    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"]
//    n(e) = {yappSelfThreading} : Replace the pins with self threading holes
//-------------------------------------------------------------------
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
        mountToPart = (isTrue(yappLid, bm)) ? yappLid : yappBase; 
        
        mountOffsetZ = (mountToPart==yappBase) ? 0 : -shellHeight + (mountHeight*2);
        mountFlipZ = (mountToPart==yappBase) ? 0 : 1;
        
        translate([0,0,mountOffsetZ])
        {
          mirror([0,0,mountFlipZ])
          {
            difference()
            {
              //-- Mounting tab
              color("red")
              roundedRect([bmX1pos,bmX2pos,bmYpos1,bmLen,mountHeight], outRadius);
              translate([0, (bmYpos + mountOpeningDiameter), -1])
              {
                //-- Slot
                color("blue")
                hull() 
                {
                  linear_extrude(mountHeight*2)
                  {
                  // translate([scrwX1pos - mountPos,0, 0]) 
                    translate([scrwX1pos,scrwY1pos, 0]) 
                      color("blue")
                      {
                        circle(mountOpeningDiameter/2);
                      }
                  // translate([scrwX2pos - mountPos, 0, 0]) 
                    translate([scrwX2pos, scrwY2pos, 0]) 
                      color("blue")
                        circle(mountOpeningDiameter/2);
                  } // extrude
                } // hull
              } // translate
            
            } // difference..
            
            //-- add fillet
            if (!isTrue(yappNoFillet, bm))
            {
              filletRad = min(filletRadius, -bmYpos/4);
              color ("red")
              union()
              {
              translate([scrwX1pos -mountOpeningDiameter,0,0])  // x, Y, Z
              {
                linearFillet((scrwX2pos-scrwX1pos)+(mountOpeningDiameter*2), filletRad, 180);
              }
              translate([scrwX1pos -mountOpeningDiameter,0,-(roundRadius-mountHeight+filletRadius)])  // x, Y, Z
              {
                cube([(scrwX2pos-scrwX1pos)+(mountOpeningDiameter*2), roundRadius,roundRadius-mountHeight+filletRadius]);
              }
            }
            } // Fillet
          } // difference
        } //mirror
      } //-- oneMount()
      
    //--------------------------------------------------------------------
    function maxWidth(w, r, l) = (w>(l-(r*4)))        ? l-(r*4)      : w;
    //--------------------------------------------------------------------

    //--------------------------------------------------------
    //-- position is: [(shellLength/2), 
    //--               shellWidth/2, 
    //--               (baseWallHeight+basePlaneThickness)]
    //--------------------------------------------------------
    //-- back to [0,0,0]
    translate([(shellLength/2)*-1,
                (shellWidth/2)*-1,
                (baseWallHeight+basePlaneThickness)*-1])
    {
      for (bm = boxMounts)
      {    
        mountPos = is_list(bm[0]) ? bm[0][0] : bm[0]; // = posx
        mountHeight = bm[3];
        mountLength = bm[2]<0 ? 0 : bm[2];
        
        
        originLLOpt = isTrue(yappAltOrigin, bm);

        if (isTrue(yappLeft, bm))
        {
          translate([mountLength,0, mountHeight])
          rotate([0,180,0])
          {
            oneMount(bm, shellLength, false, false);
          }
        } //  if yappLeft
        
        if (isTrue(yappRight, bm))
        {
          translate([0,shellWidth, mountHeight])
          rotate([0,180,180])
          {
            oneMount(bm, shellLength, originLLOpt, true);
          }
        } //  if yappRight
        
        if (isTrue(yappFront, bm))
        {
          translate([shellLength,mountLength, mountHeight])
          rotate([0,180,90])
          {
            oneMount(bm, shellWidth, false, false);
          }
        } //  if yappFront
        
        if (isTrue(yappBack, bm))
        {
          translate([0,0, mountHeight])
          rotate([0,180,-90])
          {
            oneMount(bm, shellWidth, originLLOpt, true);
          }
        } //  if yappBack
      } // for ..
  } //  translate to [0,0,0]
} //-- printBoxMounts()


//===========================================================
module printSnapJoins(casePart)
{
  if (casePart == yappPartBase) 
  {
    //--   The snap itself
    if (len(snapJoins) > 0) 
    {
      assert ((ridgeHeight >= (wallThickness*wallToRidgeRatio)), str("ridgeHeight < ", wallToRidgeRatio, " times wallThickness: no SnapJoins possible"));
    }

    for (snj = snapJoins)
    {
      useCenter = (isTrue(yappCenter, snj));
      diamondshape = isTrue(yappRectangle, snj);

      snapDiam   = (!diamondshape) ? wallThickness : (wallThickness/sqrt(2));  // fixed
      sideLength = ((isTrue(yappLeft, snj)) || (isTrue(yappRight, snj))) ? shellLength : shellWidth;
      snapWidth  = snj[1];
      snapStart  = (useCenter) ? snj[0] - snapWidth/2 : snj[0];
      snapZpos = (!diamondshape) ? 
                  (basePlaneThickness+baseWallHeight)-((wallThickness/2)) 
                : (basePlaneThickness+baseWallHeight)-((wallThickness));
      tmpAmin    = (roundRadius)+(snapWidth/2);
      tmpAmax    = sideLength - tmpAmin;
      tmpA       = max(snapStart+(snapWidth/2), tmpAmin);
      snapApos   = min(tmpA, tmpAmax);
      
      if(!diamondshape)
      {
        if (isTrue(yappLeft, snj))
        {
          translate([snapApos-(snapWidth/2),
                        wallThickness/2,
                        snapZpos])
          {
            rotate([0,90,0])
              color("blue") cylinder(d=snapDiam, h=snapWidth);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(snapApos+(snapWidth/2)),
                        wallThickness/2,
                        snapZpos])
            {
              rotate([0,90,0])
                color("blue") cylinder(d=snapDiam, h=snapWidth);
            }
            
          } // yappSymmetric
        } // yappLeft
        
        if (isTrue(yappRight, snj))
        {
          translate([snapApos-(snapWidth/2),
                        shellWidth-(wallThickness/2),
                        snapZpos])
          {
            rotate([0,90,0])
              color("blue") cylinder(d=snapDiam, h=snapWidth);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(snapApos+(snapWidth/2)),
                        shellWidth-(wallThickness/2),
                        snapZpos])
            {
              rotate([0,90,0])
                color("blue") cylinder(d=snapDiam, h=snapWidth);
            }
            
          } // yappSymmetric
        } // yappRight
        
        if (isTrue(yappBack, snj))
        {
          translate([(wallThickness/2),
                        snapApos-(snapWidth/2),
                        snapZpos])
          {
            rotate([270,0,0])
              color("blue") cylinder(d=snapDiam, h=snapWidth);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([(wallThickness/2),
                          shellWidth-(snapApos+(snapWidth/2)),
                          snapZpos])
            {
              rotate([270,0,0])
                color("blue") cylinder(d=snapDiam, h=snapWidth);
            }
            
          } // yappSymmetric
        } // yappBack
        
        if (isTrue(yappFront, snj))
        {
          translate([shellLength-(wallThickness/2),
                        snapApos-(snapWidth/2),
                        snapZpos])
          {
            rotate([270,0,0])
              color("blue") cylinder(d=snapDiam, h=snapWidth);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(wallThickness/2),
                          shellWidth-(snapApos+(snapWidth/2)),
                          snapZpos])
            {
              rotate([270,0,0])
                color("blue") cylinder(d=snapDiam, h=snapWidth);
            }
            
          } // yappSymmetric
        } // yappFront
      }
      else 
      {
        //-- Use Diamond shaped snaps
        
        if (isTrue(yappLeft, snj))
        {
          translate([snapApos-(snapWidth/2), (wallThickness/2)+0.15, snapZpos])
          {
            scale([1,.60, 1])
              rotate([45,0,0])
                color("blue") cube([snapWidth, snapDiam, snapDiam]);

          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(snapApos+(snapWidth/2)),
                        (wallThickness/2)+0.15,
                        snapZpos])
            {
            scale([1,.60, 1])
              rotate([45,0,0])
                color("blue") cube([snapWidth, snapDiam, snapDiam]);
            }
            
          } // yappSymmetric
        } // yappLeft
        
        if (isTrue(yappRight, snj))
        {
          translate([snapApos-(snapWidth/2),
                        shellWidth-((wallThickness/2)+0.15),
                        snapZpos])
          {
            scale([1,.60, 1])
              rotate([45,0,0])
                color("blue") cube([snapWidth, snapDiam, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(snapApos+(snapWidth/2)),
                        shellWidth-((wallThickness/2)+0.15),
                        snapZpos])
            {
              scale([1,.60, 1])
                rotate([45,0,0])
                  color("blue") cube([snapWidth, snapDiam, snapDiam]);

            }
            
          } // yappSymmetric
        } // yappRight
        
        if (isTrue(yappBack, snj))
        {
          translate([((wallThickness/2)+0.15),
                        snapApos-(snapWidth/2),
                        snapZpos])
          {
            scale([.60,1, 1])
              rotate([45,0,90])
               color("blue") cube([snapWidth, snapDiam, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([((wallThickness/2)+0.15),
                          shellWidth-(snapApos+(snapWidth/2)),
                          snapZpos])
            {
              scale([.60,1, 1])
                rotate([45,0,90])
                  color("blue") cube([snapWidth, snapDiam, snapDiam]);
            }
            
          } // yappCenter
        } // yappBack
        
        if (isTrue(yappFront, snj))
        {
          translate([shellLength-((wallThickness/2)+0.15),
                        snapApos-(snapWidth/2),
                        snapZpos])
          {
            scale([.60, 1, 1])
              rotate([45,0,90])
                color("blue") cube([snapWidth, snapDiam, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-((wallThickness/2)+0.15),
                          shellWidth-(snapApos+(snapWidth/2)),
                          snapZpos])
            {
              scale([.60, 1, 1])
                rotate([45,0,90])
                  color("blue") cube([snapWidth, snapDiam, snapDiam]);
            }          
          } // yappCenter
        } // yappFront
      } // diamondshape
    } // for snj .. 
  } //  Base

  if (casePart == yappPartLid) 
  {
    //-- The cutout/reciever 
    if (len(snapJoins) > 0) 
    {
      assert ((ridgeHeight >= (wallThickness*wallToRidgeRatio)), str("ridgeHeight < ", wallToRidgeRatio, " times wallThickness: no SnapJoins possible"));
    }
    
    for (snj = snapJoins)
    {
      useCenter = (isTrue(yappCenter, snj));
      diamondshape = isTrue(yappRectangle, snj);
      
      sideLength = ((isTrue(yappLeft, snj)) || (isTrue(yappRight, snj))) ? shellLength : shellWidth;
      snapWidth  = snj[1]+1;
      snapStart  = (useCenter) ? (snj[0] - snapWidth/2) : (snj[0]) - 0.5;
      snapDiam   = (!diamondshape) ? (wallThickness*1.0) : wallThickness/sqrt(2);
      snapZpos = (!diamondshape) 
                  ? ((lidPlaneThickness+lidWallHeight)*-1)-(wallThickness*1.0)
                  : ((lidPlaneThickness+lidWallHeight)*-1)-(wallThickness);
      tmpAmin    = (roundRadius)+(snapWidth/2);
      tmpAmax    = sideLength - tmpAmin;
      tmpA       = max(snapStart+(snapWidth/2), tmpAmin);
      snapApos   = min(tmpA, tmpAmax);

      if(!diamondshape)
      {
        if (isTrue(yappLeft, snj))
        {
          translate([snapApos-(snapWidth/2), -0.02, snapZpos])
          {
            color("blue") cube([snapWidth, wallThickness+0.04, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(snapApos+(snapWidth/2)), -0.02, snapZpos])
            {
              color("blue") cube([snapWidth, wallThickness+0.04, snapDiam]);
            }
          } // yappSymmetric
        } // yappLeft
        
        if (isTrue(yappRight, snj))
        {
          translate([snapApos-(snapWidth/2),shellWidth-wallThickness-0.02, snapZpos])
          {
            color("blue") cube([snapWidth, wallThickness+0.04, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(snapApos+(snapWidth/2)), shellWidth-wallThickness-0.02, snapZpos])
            {
              color("blue") cube([snapWidth, wallThickness+0.04, snapDiam]);
            } 
          } // yappSymmetric
        } // yappRight
        
        if (isTrue(yappBack, snj))
        {
          translate([-0.02, snapApos-(snapWidth/2), snapZpos])
          {
            color("blue") cube([wallThickness+0.04, snapWidth, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([-0.02, shellWidth-(snapApos+(snapWidth/2)), snapZpos])
            {
              color("blue") cube([wallThickness+0.04, snapWidth, snapDiam]);
            }
          } // yappSymmetric
        } // yappBack
        
        if (isTrue(yappFront, snj))
        {
          translate([shellLength-wallThickness-0.02, snapApos-(snapWidth/2), snapZpos])
          {
            color("blue") cube([wallThickness+0.04, snapWidth, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-wallThickness-0.02, shellWidth-(snapApos+(snapWidth/2)), snapZpos])
            {
              color("blue") cube([wallThickness+0.04, snapWidth, snapDiam]);
            }
          } // yappSymmetric
        } // yappFront
      }
      else
      // Use the Diamond Shape
      {
        if (printMessages) echo ("making Diamond shaped snaps");
        if (isTrue(yappLeft, snj))
        {
          translate([snapApos-(snapWidth/2)-0.5, (wallThickness/2)+0.15, snapZpos])
          {
            scale([1,.60, 1])
                rotate([45,0,0])
            color("blue") cube([snapWidth+1, snapDiam, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
          //  translate([shellLength-(snapApos+(snapWidth/2)+0.5), (wallThickness/2)+0.04, snapZpos])
            translate([shellLength-(snapApos+(snapWidth/2)+0.5), (wallThickness/2)+0.15, snapZpos])
            {
              scale([1,.60, 1])
                rotate([45,0,0])
              color("blue") cube([snapWidth+1, snapDiam, snapDiam]);
            }
          } // yappSymmetric
        } // yappLeft
        
        if (isTrue(yappRight, snj))
        {
          translate([snapApos-(snapWidth/2)-0.5, shellWidth-(wallThickness/2)-0.15, snapZpos])
          {
            scale([1,.60, 1])
                rotate([45,0,0])
            color("blue") cube([snapWidth+1, snapDiam, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-(snapApos+(snapWidth/2)+0.5), shellWidth-(wallThickness/2)-0.15, snapZpos])
            {
              scale([1,.60, 1])
                rotate([45,0,0])
              color("blue") cube([snapWidth+1, snapDiam, snapDiam]);
            } 
          } // yappSymmetric
        } // yappRight
        
        if (isTrue(yappBack, snj))
        {
          translate([(wallThickness/2)+0.15, snapApos-(snapWidth/2)-0.5, snapZpos])
          {
            scale([0.6, 1, 1])
             rotate([45,0,90])
              color("blue") 
               cube([snapWidth+1, snapDiam, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([(wallThickness/2)+0.15, shellWidth-(snapApos+(snapWidth/2))-0.5, snapZpos])
            {
              scale([0.6, 1, 1])
              rotate([45,0,90])
                 color("blue") 
                   cube([snapWidth+1, snapDiam, snapDiam]);
            }
            
          } // yappSymmetric
        } // yappBack
        
        if (isTrue(yappFront, snj))
        {
          translate([shellLength-((wallThickness/2)+0.15), snapApos-(snapWidth/2)-0.5, snapZpos])
          {
              scale([0.6, 1, 1])
                rotate([45,0,90])
            color("blue") cube([snapWidth+1, snapDiam, snapDiam]);
          }
          if (isTrue(yappSymmetric, snj))
          {
            translate([shellLength-((wallThickness/2)+0.15),  shellWidth-(snapApos+(snapWidth/2))-0.5,  snapZpos])
            {
              scale([0.6, 1, 1])
                rotate([45,0,90])
              color("blue") cube([snapWidth+1, snapDiam, snapDiam]);
            }     
          } // yappSymmetric
        } // yappFront      
      }
    } // for snj .. 
  } //  Lid()
} //-- printSnapJoins()

  //--------------------------------------------------------
  module minkowskiOuterBox(L, W, H, oRad, plane, wall)
  {    
    if ((shellEdgeTopBottom == yappEdgeRounded) && (shellEdgeVert == yappEdgeRounded))
    { 
      minkowski()
      {
        cube([L+(wall*2)-(oRad*2), W+(wall*2)-(oRad*2), (H*2)+(plane*2)-(oRad*2)], center=true);
        sphere(oRad*minkowskiErrorCorrection); // Compensate for minkowski error
      }
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeSquare))
    {
      cube([L+(wall*2), W+(wall*2), (H*2)+(plane*2)], center=true);
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeRounded))
    {
      linear_extrude((H*2)+(plane*2),center=true)
//      roundedRectangle2D(width=L+(wall*2),length=W+(wall*2),radius=(iRad*2)-wall/2);
      roundedRectangle2D(width=L+(wall*2),length=W+(wall*2),radius=oRad);
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeChamfered))
    {
      linear_extrude((H*2)+(plane*2),center=true)
      chamferedRectangle2D(L+(wall*2),W+(wall*2),oRad);
    } 
    else if ((shellEdgeTopBottom == yappEdgeChamfered) && (shellEdgeVert == yappEdgeChamfered))
    {
      chamferCube3D(L+(wall*2),W+(wall*2),(H*2)+(plane*2),(oRad),(oRad),(oRad));
    } 
    
    // BoxType=5
    else if ((shellEdgeTopBottom == yappEdgeChamfered) && (shellEdgeVert == yappEdgeRounded))
    {
      //--bottom
      translate([0,0,-((H*2)+(plane*2)-((oRad)))/2])
      mirror([0,0,1])
      linear_extrude(((oRad)), scale = [1-(((oRad))/(L+(wall*2))*2),1-(((oRad))/(W+(wall*2))*2)],center=true)
      roundedRectangle2D(width=L+(wall*2),length=W+(wall*2),radius=(oRad));

      //--main
      linear_extrude((H*2)+(plane*2)-(((oRad))*2) + 0.02,center=true)
      roundedRectangle2D(width=L+(wall*2),length=W+(wall*2),radius=(oRad));

      //--top
      translate([0,0,((H*2)+(plane*2)-((oRad)))/2])
      linear_extrude(((oRad)), scale = [1-(((oRad))/(L+(wall*2))*2),1-(((oRad))/(W+(wall*2))*2)],center=true)
      roundedRectangle2D(width=L+(wall*2),length=W+(wall*2),radius=(oRad));
    } 
    else 
    {
      assert(false, "Unsupported edge combination");
    } 
  } //-- minkowskiOuterBox()

  module minkowskiCutBox(L, W, H, cRad, plane, wall)
  {
    if ((shellEdgeTopBottom == yappEdgeRounded) && (shellEdgeVert == yappEdgeRounded))
    { 
      minkowski()
      {
        cube([L+(wall)-(cRad*2), W+(wall)-(cRad*2), (H*2)+(plane)-(cRad*2)], center=true);
        sphere(cRad*minkowskiErrorCorrection); // Compensate for minkowski error
      }
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeSquare))
    {
      cube([L+(wall), W+(wall), (H*2)+(plane)], center=true);
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeRounded))
    {
      linear_extrude((H*2)+(plane),center=true)
      roundedRectangle2D(width=L+(wall),length=W+(wall),radius=cRad);
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeChamfered))
    {
      linear_extrude((H*2)+(plane),center=true)
      chamferedRectangle2D(L+(wall),W+(wall),(cRad));
    } 
    else if ((shellEdgeTopBottom == yappEdgeChamfered) && (shellEdgeVert == yappEdgeChamfered))
    {
      chamferCube3D(L+(wall),W+(wall),(H*2)+(plane),(cRad),(cRad),(cRad*sqrt(2)));
    } 

    // BoxType=5
    else if ((shellEdgeTopBottom == yappEdgeChamfered) && (shellEdgeVert == yappEdgeRounded))
    {
      //--bottom
      translate([0,0,-((H*2)+(plane*1)-((cRad)))/2])
      mirror([0,0,1])
      linear_extrude(((cRad)), scale = [1-(((cRad))/(L+(wall*1))*2),1-(((cRad))/(W+(wall*1))*2)],center=true)
      roundedRectangle2D(width=L+(wall*1),length=W+(wall*1),radius=(cRad));

      //--main
      linear_extrude((H*2)+(plane*1)-(((cRad))*2) + 0.02,center=true)
      roundedRectangle2D(width=L+(wall*1),length=W+(wall*1),radius=(cRad));

      //--top
      translate([0,0,((H*2)+(plane*1)-((cRad)))/2])
      linear_extrude(((cRad)), scale = [1-(((cRad))/(L+(wall*1))*2),1-(((cRad))/(W+(wall*1))*2)],center=true)
      roundedRectangle2D(width=L+(wall*1),length=W+(wall*1),radius=(cRad));
    } 

    else 
    {
      assert(false, "Unsupported edge combination");
    }
  } //-- minkowskiCutBox()
  
  //--------------------------------------------------------
  module minkowskiInnerBox(L, W, H, iRad, plane, wall)
  {
    if ((shellEdgeTopBottom == yappEdgeRounded) && (shellEdgeVert == yappEdgeRounded))
    { 
      minkowski()
      {
        cube([L-((iRad*2)), W-((iRad*2)), (H*2)-((iRad*2))], center=true);
        sphere(iRad*minkowskiErrorCorrection); // Compensate for minkowski error
      }
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeSquare))
    {
      cube([L, W, (H*2)], center=true);
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeRounded))
    {
      linear_extrude(H*2,center=true)
      roundedRectangle2D(width=L,length=W,radius=iRad);
    } 
    else if ((shellEdgeTopBottom == yappEdgeSquare) && (shellEdgeVert == yappEdgeChamfered))
    {
      linear_extrude(H*2,center=true)
      chamferedRectangle2D(L,W,iRad);
    } 
    else if ((shellEdgeTopBottom == yappEdgeChamfered) && (shellEdgeVert == yappEdgeChamfered))
    {
      chamferCube3D(L,W,H*2,iRad,iRad,iRad);
    } 

    // BoxType=5
    else if ((shellEdgeTopBottom == yappEdgeChamfered) && (shellEdgeVert == yappEdgeRounded))
    {
      //--bottom
      translate([0,0,-((H*2)+(plane*0)-((iRad)))/2])
      mirror([0,0,1])
      linear_extrude(((iRad)), scale = [1-(((iRad))/(L+(wall*0))*2),1-(((iRad))/(W+(wall*0))*2)],center=true)
      roundedRectangle2D(width=L+(wall*0),length=W+(wall*0),radius=(iRad));

      //--main
      linear_extrude((H*2)+(plane*0)-(((iRad))*2) + 0.02,center=true)
      roundedRectangle2D(width=L+(wall*0),length=W+(wall*0),radius=(iRad));

      //--top
      translate([0,0,((H*2)+(plane*0)-((iRad)))/2])
      linear_extrude(((iRad)), scale = [1-(((iRad))/(L+(wall*0))*2),1-(((iRad))/(W+(wall*0))*2)],center=true)
      roundedRectangle2D(width=L+(wall*0),length=W+(wall*0),radius=(iRad));
    } 

    else 
    {
      assert(false, "Unsupported edge combination");
    } 
  } //-- minkowskiInnerBox()


//===========================================================
module minkowskiBox(shell, L, W, H, rad, plane, wall, preCutouts)
{
  iRad = getMinRad(rad, wall);
  cRad = (rad + iRad)/2;
  oRad = rad;
    
  
  //--------------------------------------------------------
  
  if (preCutouts) 
  {
    if (shell==yappPartBase)
    {
      if (len(boxMounts) > 0)
      {
        difference()
        {
          printBoxMounts();
          minkowskiCutBox(L, W, H, cRad, plane, wall);
        } // difference()
      } // if (len(boxMounts) > 0)
     
      //-- Objects to be cut to outside the box       
      //color("Orange")
      difference()
      {
        //-- move it to the origin of the base
        translate ([-L/2, -W/2, -H])
          hookBaseOutsidePre();    
        minkowskiCutBox(L, W, H, cRad, plane, wall);
      } // difference()
    
      //-- draw stuff inside the box
      //color("LightBlue")
      intersection()
      {
        minkowskiCutBox(L, W, H, cRad, plane, wall);
        translate ([-L/2, -W/2, -H]) //-baseWallHeight])
          hookBaseInsidePre();
      } // intersection()

      //-- The actual box
      color(colorBase, alphaBase)
      difference()
      {
        minkowskiOuterBox(L, W, H, rad, plane, wall);
        minkowskiInnerBox(L, W, H, iRad, plane, wall);
      } // difference
   
      //-- Draw the labels that are added (raised) from the case
      color("DarkGreen") drawLabels(yappPartBase, false);
      color("DarkGreen") drawImages(yappPartBase, false);

    } // if (shell==yappPartBase)
    else
    {
      //-- Lid
      if (len(boxMounts) > 0)
      {
        difference()
        {
          printBoxMounts();
          minkowskiCutBox(L, W, H, cRad, plane, wall);
        } // difference()
      } // if (len(boxMounts) > 0)

      //color("Red")
      difference()
      {
        //-- Objects to be cut to outside the box 
        //-- move it to the origin of the base
        translate ([-L/2, -W/2, H])
        hookLidOutsidePre();
        minkowskiCutBox(L, W, H, cRad, plane, wall);
      } // difference()
      
      //-- draw stuff inside the box
      //color("LightGreen")
      intersection()
      {
        minkowskiCutBox(L, W, H, cRad, plane, wall);
        translate ([-L/2, -W/2, H])
          hookLidInsidePre();
      } //intersection()

      //-- The actual box
      color(colorLid, alphaLid)
      difference()
      {
        minkowskiOuterBox(L, W, H, rad, plane, wall);
        minkowskiInnerBox(L, W, H, iRad, plane, wall);
      } // difference  

      //-- Draw the labels that are added (raised) from the case
      color("DarkGreen") drawLabels(yappPartLid, false);
      color("DarkGreen") drawImages(yappPartLid, false);
    }
  }
  else // preCutouts
  {
    //-- Only add the Post hooks
    if (shell==yappPartBase)
    {
      //color("Orange")
      difference()
      {
        // Objects to be cut to outside the box       
        // move it to the origin of the base
        translate ([-L/2, -W/2, -H]) 
          hookBaseOutside();
        minkowskiCutBox(L, W, H, cRad, plane, wall);
      } // difference()

      //draw stuff inside the box
      //color("LightBlue")
      intersection()
      {
        minkowskiCutBox(L, W, H, cRad, plane, wall);
      
        translate ([-L/2, -W/2, -H])
          hookBaseInside();
      } // intersection()
    } // if (shell==yappPartBase)
    else
    {
      //Lid      
      //color("Red")
      difference()
      {
        //-- Objects to be cut to outside the box 
        //-- move it to the origin of the base
        translate ([-L/2, -W/2, H])
        hookLidOutside();
        minkowskiCutBox(L, W, H, cRad, plane, wall);
      } // difference()

      //-- draw stuff inside the box
      //color("LightGreen")
      intersection()
      {
        translate ([-L/2, -W/2, H])
          hookLidInside();
        minkowskiCutBox(L, W, H, cRad, plane, wall);
      }
    }
  } //preCutouts
} //-- minkowskiBox()


//===========================================================
module showPCBMarkers(thePCB)
{  
  pcb_Length     = pcbLength(thePCB[0]); 
  pcb_Width      = pcbWidth(thePCB[0]); 
  pcb_Thickness  = pcbThickness(thePCB[0]); 

  posX          = translate2Box_X(0, yappBase, [yappCoordPCB, yappGlobalOrigin, thePCB[0]]);
  posY          = translate2Box_Y(0, yappBase, [yappCoordPCB, yappGlobalOrigin, thePCB[0]]);
  posZ          = translate2Box_Z(0, yappBase, [yappCoordPCB, yappGlobalOrigin, thePCB[0]]);

  {
    markerHeight=shellHeight+onLidGap+10;
    //-- Back Left 
    translate([0, 0, (markerHeight/2) -posZ - 5]) 
      color("red",0.50)
        %cylinder(
          r = .5,
          h = markerHeight,
          center = true);

    translate([0, pcb_Width, (markerHeight/2) -posZ - 5]) 
      color("red",0.50)
        %cylinder(
          r = .5,
          h = markerHeight,
          center = true);

    translate([pcb_Length, pcb_Width, (markerHeight/2) -posZ - 5]) 
      color("red",0.50)
        %cylinder(
          r = .5,
          h = markerHeight,
          center = true);

    translate([pcb_Length, 0, (markerHeight/2) -posZ - 5]) 
      color("red",0.50)
        %cylinder(
          r = .5,
          h = markerHeight,
          center = true);

    translate([(shellLength/2)-posX, 0, pcb_Thickness])
      rotate([0,90,0])
        color("red",0.50)
          %cylinder(
            r = .5,
            h = shellLength+(wallThickness*2)+paddingBack,
            center = true);

    translate([(shellLength/2)-posX, pcb_Width, pcb_Thickness])
      rotate([0,90,0])
        color("red",0.50)
          %cylinder(
            r = .5,
            h = shellLength+(wallThickness*2)+paddingBack,
            center = true);

    translate([0, (shellWidth/2)-posY, pcb_Thickness])
      rotate([90,90,0])
        color("red",0.50)
          %cylinder(
            r = .5,
            h = shellWidth+(wallThickness*2)+paddingLeft,
            center = true);

    translate([pcb_Length, (shellWidth/2)-posY, pcb_Thickness])
      rotate([90,90,0])
        color("red",0.50)
          %cylinder(
            r = .5,
            h = shellWidth+(wallThickness*2)+paddingLeft,
            center = true);
            
  } // show_markers   
} //-- showMarkersPCB()


//===========================================================
module printPCB(thePCB) //posX, posY, posZ, length, width, thickness)
{
  pcbName = thePCB[0];
  
  posX = translate2Box_X(0, yappBase, [yappCoordPCB,yappGlobalOrigin, pcbName]);
  posY = translate2Box_Y(0, yappBase, [yappCoordPCB,yappGlobalOrigin, pcbName]);
  posZ = translate2Box_Z(0, yappBase, [yappCoordPCB,yappGlobalOrigin, pcbName]);
  
  //-- Adjust to the bottom of the PCB is at posZ
  translate([posX,posY,posZ-pcbThickness(pcbName)])
  
  {
    //-- Draw the PCB 
    color("red", 0.5)
//      cube([thePCB[1], thePCB[2], thePCB[5]]);
      cube([pcbLength(pcbName), pcbWidth(pcbName), pcbThickness(pcbName)]);
  
//    hshift = (thePCB[1] > thePCB[2]) ? 0 : 4;
    hshift = (thePCB[1] > thePCB[2]) ? 0 : 4;
    //-- Add the name
//    linear_extrude(thePCB[5]+ 0.04) 
    linear_extrude(pcbThickness(pcbName)+ 0.04) 
    {
      translate([2+hshift,3,0])
//      rotate([0,0,(thePCB[1] > thePCB[2]) ? 0 : 90])
      rotate([0,0,(pcbLength(pcbName) > pcbWidth(pcbName)) ? 0 : 90])
//      text(thePCB[0]
      text(pcbName
            , size=3
            , direction="ltr"
            , halign="left"
            , valign="bottom");
    } // rotate
        
    if (showSwitches)
    {
      drawSwitchOnPCB(thePCB);
    }
    
    if (showMarkersPCB) 
    {
      showPCBMarkers(thePCB);
    }
  }
} //-- printPCB()


//===========================================================
//-- Place the standoffs and through-PCB pins in the base Box
module pcbHolders() 
{        
  for ( stand = pcbStands )
  {
    //-- Get the PCBinfo 
    thePCBName = getPCBName(yappPCBName, stand);
   
    pcb_Length = pcbLength(thePCBName);
    pcb_Width = pcbWidth(thePCBName);
    pcb_Thickness = pcbThickness(thePCBName);
    standoff_Height = standoffHeight(thePCBName);
    pcbStandHeight  = getParamWithDefault(stand[2], standoff_Height);
    filletRad = getParamWithDefault(stand[7],0);
  //  standType = isTrue(yappHole, stand) ? yappHole : yappPin;
    standType = 
			isTrue(yappHole, stand) ? yappHole : 
			isTrue(yappTopPin, stand) ? yappTopPin : 
			yappPin;

//    p(8) = Pin Length : Default = 0
//    pinLength = getParamWithDefault(stand[8],0);
    

    //-- Calculate based on the Coordinate system
    coordSystem = getCoordSystem(stand, yappCoordPCB);
    
    
    offsetX   = translate2Box_X(0, yappBase, coordSystem);
    offsetY   = translate2Box_Y(0, yappBase, coordSystem);
    
    connX   = stand[0];
    connY   = stand[1];
    
    lengthX   = coordSystem[0]==yappCoordPCB ? pcb_Length 
              : coordSystem[0]==yappCoordBox ? shellLength 
              : coordSystem[0]==yappCoordBoxInside ? shellInsideLength 
              : undef;
              
    lengthY   = coordSystem[0]==yappCoordPCB ? pcb_Width 
              : coordSystem[0]==yappCoordBox ? shellWidth 
              : coordSystem[0]==yappCoordBoxInside ? shellInsideWidth 
              : undef;
        
    allCorners = (isTrue(yappAllCorners, stand)) ? true : false;
    primeOrigin = (!isTrue(yappBackLeft, stand) && !isTrue(yappFrontLeft, stand) && !isTrue(yappFrontRight, stand) && !isTrue(yappBackRight, stand) && !isTrue(yappAllCorners, stand) ) ? true : false;

    if (!isTrue(yappLidOnly, stand))
    {
      if (primeOrigin || allCorners || isTrue(yappBackLeft, stand))
         translate([offsetX+connX, offsetY + connY, basePlaneThickness])
          pcbStandoff(yappPartBase, pcbStandHeight, filletRad, standType, "green", !isTrue(yappNoFillet, stand),stand);

      if (allCorners || isTrue(yappFrontLeft, stand))
         translate([offsetX + lengthX - connX, offsetY + connY, basePlaneThickness])
          pcbStandoff(yappPartBase, pcbStandHeight, filletRad, standType, "green", !isTrue(yappNoFillet, stand),stand);

      if (allCorners || isTrue(yappFrontRight, stand))
        translate([offsetX + lengthX - connX, offsetY + lengthY - connY, basePlaneThickness])
          pcbStandoff(yappPartBase, pcbStandHeight, filletRad, standType, "green", !isTrue(yappNoFillet, stand),stand);

      if (allCorners || isTrue(yappBackRight, stand))
        translate([offsetX + connX, offsetY + lengthY - connY, basePlaneThickness])
          pcbStandoff(yappPartBase, pcbStandHeight, filletRad, standType, "green", !isTrue(yappNoFillet, stand),stand);
    } //if
  } //for  
} //-- pcbHolders()



//===========================================================
// Place the Pushdown in the Lid
module pcbPushdowns() 
{        
 for ( pushdown = pcbStands )
  {
    //-- Get the PCBinfo 
    thePCB = getPCBInfo(yappPCBName, pushdown);
   
    pcb_Length       = pcbLength(thePCB[0]); 
    pcb_Width        = pcbWidth(thePCB[0]);
    pcb_Thickness    = pcbThickness(thePCB[0]);
    standoff_Height  = standoffHeight(thePCB[0]);
  
    //-- Calculate based on the Coordinate system
    coordSystem = getCoordSystem(pushdown, yappCoordPCB);

    offsetX   = translate2Box_X(0, yappBase, coordSystem);
    offsetY   = translate2Box_Y(0, yappBase, coordSystem);

    //-- Calculate based on the Coordinate system
    usePCBCoord = (coordSystem[0] == yappCoordPCB) ? true : false;
    
    pcbGapTmp = getParamWithDefault(pushdown[3],-1);
    pcbGap = (pcbGapTmp == -1 ) ? (usePCBCoord) ? pcb_Thickness : 0 : pcbGapTmp;

    filletRad = getParamWithDefault(pushdown[7],0);
     
    standType = 
			isTrue(yappHole, pushdown) ? yappHole : 
			isTrue(yappTopPin, pushdown) ? yappTopPin : 
			yappPin;
  
    pcbStandHeightTemp  = getParamWithDefault(pushdown[2], standoff_Height);
    
    pcbStandHeight=(baseWallHeight+lidWallHeight)
                     -(pcbStandHeightTemp+pcbGap);

    pcbZlid = (baseWallHeight+lidWallHeight+lidPlaneThickness)
                    -(pcbStandHeightTemp+pcbGap);

    connX   = pushdown[0];
    connY   = pushdown[1];
    lengthX   = usePCBCoord ? pcb_Length : shellLength;
    lengthY   = usePCBCoord ? pcb_Width : shellWidth;

    allCorners = (isTrue(yappAllCorners, pushdown)) ? true : false;
    primeOrigin = (!isTrue(yappBackLeft, pushdown) && !isTrue(yappFrontLeft, pushdown) && !isTrue(yappFrontRight, pushdown) && !isTrue(yappBackRight, pushdown) && !isTrue(yappAllCorners, pushdown) ) ? true : false;

    if (!isTrue(yappBaseOnly, pushdown))
    {
      if (primeOrigin || allCorners || isTrue(yappBackLeft, pushdown))
      {
        translate([offsetX + connX, offsetY + connY, pcbZlid*-1])
          pcbStandoff(yappPartLid, pcbStandHeight, filletRad, standType, "yellow", !isTrue(yappNoFillet, pushdown),pushdown);
      }
      if (allCorners || isTrue(yappFrontLeft, pushdown))
      {
        translate([offsetX + lengthX - connX, offsetY + connY, pcbZlid*-1])
          pcbStandoff(yappPartLid, pcbStandHeight, filletRad, standType, "yellow", !isTrue(yappNoFillet, pushdown),pushdown);
      }
      if (allCorners || isTrue(yappFrontRight, pushdown))
      {
         translate([offsetX + lengthX - connX, offsetY + lengthY - connY, pcbZlid*-1])
          pcbStandoff(yappPartLid, pcbStandHeight, filletRad, standType, "yellow", !isTrue(yappNoFillet, pushdown),pushdown);
      }
      if (allCorners || isTrue(yappBackRight, pushdown))
      {
        translate([offsetX + connX, offsetY + lengthY - connY, pcbZlid*-1])
          pcbStandoff(yappPartLid, pcbStandHeight, filletRad, standType, "yellow", !isTrue(yappNoFillet, pushdown),pushdown);
      }
    }
  }  
} //-- pcbPushdowns()

//===========================================================
module sanityCheckList(theList, theListName, minCount, shapeParam=undef, validShapes = []) 
  {    
    if (printMessages) echo("Sanity Checking ", theListName, theList);
      
    if (is_list(theList))
    {
      if (len(theList)>0)
      {
        //-- Go throught the vector checking each one
        for(pos = [0 : len(theList)-1])
        {
          item = theList[pos];
          //-- Check that there are at least the minimun elements
          //-- Cutouts require 9 elements
          assert((len(item) >= minCount), str(theListName, " item ", pos, " require ", minCount, " parameters at a minimum.") );
            
          if (shapeParam!=undef)
          {
            theShape = item[shapeParam];
            
            assert((isTrue(theShape,validShapes)), str(theListName, " item ", pos, " Shape (param ",shapeParam,") required to be one of the following ", validShapes) );
          }
        }
      }
      else
      {
        if (printMessages) echo (str(theListName, " is empty"));
      }
    } 
    else
    {
      if (printMessages) echo (theListName, " is not defined");
    }
  } //-- sanityCheckCutoutList()

//===========================================================
//-- Master module to process the 4 ridge extension for the box faces
module makeRidgeExt(type, subtract)
{      
  if (printMessages) echo("***** Process RidgeExt *****");
  processFaceList(yappLeft,    ridgeExtLeft, type, "ridgeExt", subtract);
  processFaceList(yappRight,   ridgeExtRight, type, "ridgeExt", subtract);
  processFaceList(yappFront,   ridgeExtFront, type, "ridgeExt", subtract);
  processFaceList(yappBack,    ridgeExtBack, type, "ridgeExt", subtract);
} //-- makeRidgeExt()



//===========================================================
//-- Master module to process the 6 vectors for the box faces
module makeCutouts(type)
{      
  if (type==yappPartBase)
  { 
    //-- The bottom plane is only on the Base
    processFaceList(yappBase,  cutoutsBase, type, "cutout", true); 
  }
  else
  {
    //-- The bottom plane is only on the Lid
    processFaceList(yappLid,     cutoutsLid, type, "cutout", true);
  }
  //-- All others can cross bewteen the two
  processFaceList(yappLeft,    cutoutsLeft, type, "cutout", true);
  processFaceList(yappRight,   cutoutsRight, type, "cutout", true);
  processFaceList(yappFront,   cutoutsFront, type, "cutout", true);
  processFaceList(yappBack,    cutoutsBack, type, "cutout", true);

} //-- makeCutouts()


//===========================================================
module processCutoutList_Mask(cutOut, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth,base_pos_H, base_pos_V, base_width, base_height, base_depth, base_angle, pos_X, pos_Y, invertZ, zAdjustForCutFromInside)
{
  //-- Check if there is a mask
  theMask = getVector(yappMaskDef, cutOut);    
  theMaskVector = getVectorInVector(yappMaskDef, cutOut);
  useMask = ((!theMask==false) || (!theMaskVector==false));
 
  if (printMessages) echo("processCutoutList_Mask",base_depth=base_depth, zAdjustForCutFromInside=zAdjustForCutFromInside);

  if (useMask) 
  {
    maskDef      = (theMask != false) ? theMask :(theMaskVector!=false) ? theMaskVector[0][1] : undefined;
    maskhOffset  = (theMask != false) ? 0 : (theMaskVector!=false) ? getParamWithDefault(theMaskVector[1],0) : undefined;
    maskvOffset  = (theMask != false) ? 0 : (theMaskVector!=false) ? getParamWithDefault(theMaskVector[2],0) : undefined;
    maskRotation = (theMask != false) ? 0 : (theMaskVector!=false) ? getParamWithDefault(theMaskVector[3],0) : undefined;

    intersection()
    {
      //shape
      processCutoutList_Shape(cutOut, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth,base_pos_H, base_pos_V, base_width, base_height, base_depth, base_angle, pos_X, pos_Y, invertZ, zAdjustForCutFromInside);
      
      centeroffsetH = (isTrue(yappCenter, cutOut)) ? 0 : base_width / 2;
      centeroffsetV = (isTrue(yappCenter, cutOut)) ? 0 : base_height / 2;
      zShift = invertZ ? -base_depth - zAdjustForCutFromInside : zAdjustForCutFromInside;
			
      translate([offset_x, offset_y, offset_z]) 
      {
        rotate([rot_X, rot_Y, rot_Z])
        {
           translate([base_pos_H + centeroffsetH, base_pos_V+centeroffsetV, wallDepth + zShift - 0.02])
          color("Fuchsia")
          genMaskfromParam(maskDef, base_width, base_height, base_depth, maskhOffset, maskvOffset, maskRotation);
        }// rotate
      } //translate
    } // intersection
  } // Use Mask
  else
  {
    processCutoutList_Shape(cutOut, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth,base_pos_H, base_pos_V, base_width, base_height, base_depth, base_angle, pos_X, pos_Y, invertZ, zAdjustForCutFromInside);
  }
} //-- processCutoutList_Mask()

//===========================================================
//-- Process the list passeed in
module processCutoutList_Shape(cutOut, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth,base_pos_H, base_pos_V, base_width, base_height, base_depth, base_angle, pos_X, pos_Y, invertZ, zAdjustForCutFromInside)
{
  theRadius = cutOut[4];
  theShape = cutOut[5];
  theAngle = getParamWithDefault(cutOut[7],0);
  
  zShift = invertZ ? -base_depth - zAdjustForCutFromInside : zAdjustForCutFromInside;
  
  //-- Output all of the current parameters
  if (printMessages) echo("base_pos_H",base_pos_H);
  if (printMessages) echo("base_pos_V",base_pos_V);
  if (printMessages) echo("base_width",base_width);
  if (printMessages) echo("base_height",base_height);
  if (printMessages) echo("base_depth",base_depth);
  if (printMessages) echo("wallDepth",wallDepth);

  if (printMessages) echo ("rot_X", rot_X); 
  if (printMessages) echo ("rot_Y", rot_Y); 
  if (printMessages) echo ("rot_Z", rot_Z); 
  if (printMessages) echo ("offset_x", offset_x); 
  if (printMessages) echo ("offset_y", offset_y); 
  if (printMessages) echo ("offset_z", offset_z); 
  if (printMessages) echo ("pos_X", pos_X); 
  if (printMessages) echo ("pos_Y", pos_Y); 
  if (printMessages) echo ("base_depth", base_depth); 
  if (printMessages) echo ("base_angle", base_angle);
  if (printMessages) echo ("invertZ", invertZ); 
  if (printMessages) echo ("zShift", zShift); 
  
  thePolygon = getVector(yappPolygonDef, cutOut);
  if (printMessages) echo("Polygon Definition", thePolygon=thePolygon);

  translate([offset_x, offset_y, offset_z]) 
  {
    rotate([rot_X, rot_Y, rot_Z])
    {
      translate([pos_X, pos_Y, wallDepth + zShift - 0.02]) 
      {
        if (printMessages) echo("Drawing cutout shape");
        // Draw the shape
          color("Fuchsia")
            generateShape (theShape,(isTrue(yappCenter, cutOut)), base_width, base_height, base_depth + 0.04, theRadius, theAngle, thePolygon);
      } //translate
    }// rotate
  } //translate
  
  if (printMessages) echo ("------------------------------");
    
} //-- processCutoutList_Shape()


//===========================================================
// Process the list passeed in
module processCutoutList_Face(face, cutoutList, casePart, swapXY, swapWH, invertZ, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth)
{
  for ( cutOut = cutoutList )
  {
    //-- Get the desired coordinate system    
    theCoordSystem = getCoordSystem(cutOut, yappCoordPCB);   
   
    theX = translate2Box_X (cutOut[0], face, theCoordSystem);
    theY = translate2Box_Y (cutOut[1], face, theCoordSystem);
    theWidth = cutOut[2];
    theLength = cutOut[3];
    theRadius = cutOut[4];
    theShape = cutOut[5];
    theDepth = getParamWithDefault(cutOut[6],0);
    theAngle = getParamWithDefault(cutOut[7],0);

    useCenterCoordinates = isTrue(yappCenter, cutOut);
    
    if (printMessages) echo("useCenterCoordinates", useCenterCoordinates);
    if (printMessages) echo("processCutoutList_Face", cutOut);

    //-- Calc H&W if only Radius is given
    tempWidth = (theShape == yappCircle) ?theRadius*2 : theWidth;
    tempLength = (theShape == yappCircle) ? theRadius*2 : theLength;
    
    base_width  = (swapWH) ? tempLength : tempWidth;
    base_height = (swapWH) ? tempWidth : tempLength;
    
    base_pos_H  = ((!swapXY) ? theY : theX);
    base_pos_V  = ((!swapXY) ? theX : theY);
  
		
    //-- Add 0.04 to the depth - we will shift by 0.02 later to center it on the wall
    base_depth  = (theDepth == 0) ? wallDepth + 0.04 : abs(theDepth) + 0.04;
    base_angle  = theAngle;

		//--Check for negative depth
		zAdjustForCutFromInside = !isTrue(yappFromInside, cutOut) ? 0 : wallDepth - base_depth;

    if (printMessages) echo ("---Box---");
    pos_X = base_pos_H;
    pos_Y = base_pos_V;
    
		processCutoutList_Mask(cutOut, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth, base_pos_H, base_pos_V, base_width, base_height, base_depth, base_angle, pos_X, pos_Y, invertZ, zAdjustForCutFromInside);
		
  } //for ( cutOut = cutoutList )
} //-- processCutoutList_Face()


//===========================================================
// Process the list passeed in
module processRidgeExtList_Face(face, ridgeExtList, casePart, swapXY, swapWH, invertZ, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth, subtract)
{
  for ( ridgeExt = ridgeExtList )
  {
    //-- Calculate based on the Coordinate system (test for Box override) thus defaulting to PCB
    theCoordSystem = getCoordSystem(ridgeExt, yappCoordPCB);
    thePCBName = getPCBName(yappPCBName, ridgeExt);

    useCenterCoordinates = isTrue(yappCenter, ridgeExt); 
    
    //-- Convert x pos if needed
    theX = translate2Box_X (ridgeExt[0], face, theCoordSystem);  
    theY =  baseWallHeight+basePlaneThickness;// RidgePos
    theWidth = ridgeExt[1];
    theLength = translate2Box_Y (ridgeExt[2], face, theCoordSystem); //ridgeExt[2];
    
    originLLOpt = isTrue(yappAltOrigin, ridgeExt);
    
    //-- Calc H&W if only Radius is given
    //-- add slack for the part connected to the lid
    tempWidth = (subtract) ? theWidth : theWidth - ridgeSlack*2;
    
    //-- Shift so that 0 aligns with the original seam
    tempLength = theY - theLength;
    
    base_width  = (swapWH) ? tempLength : tempWidth;
    base_height = (swapWH) ? tempWidth : tempLength;
    
    base_pos_H  = ((!swapXY) ? theY : theX);
    base_pos_V  = ((!swapXY) ? theX : theY);

    base_depth  = wallDepth;
    base_angle  = 0;

    //-- Only adjust the H Pos for centering
    pos_X = base_pos_H;
    pos_Y = (useCenterCoordinates) ? base_pos_V - (base_height/2) : base_pos_V + ((subtract) ? 0 : ridgeSlack);

    adjustedHeight = (base_width > 0) ? base_width : base_width-ridgeHeight;
    
    processRidgeExtList(subtract, ridgeExt, casePart, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth, base_pos_H, base_pos_V, adjustedHeight, base_height, base_depth, base_angle, pos_X, pos_Y, invertZ);
  } //for ( ridgeExt = ridgeExtList )
} //-- processRidgeExtList_Face()


//===========================================================
//-- Process the list passeed in
module processRidgeExtList(subtract, ridgeExt, casePart, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth,base_pos_H, base_pos_V, base_width, base_height, base_depth, base_angle, pos_X, pos_Y, invertZ)
{
  apply = 
          ((base_width >= 0) && (casePart == yappPartLid) && ( subtract)) ? false :
          ((base_width >= 0) && (casePart == yappPartLid) && (!subtract)) ? true :
          ((base_width >= 0) && (casePart != yappPartLid) && ( subtract)) ? true :
          ((base_width >= 0) && (casePart != yappPartLid) && (!subtract)) ? false :
          ((base_width <  0) && (casePart == yappPartLid) && ( subtract)) ? true :
          ((base_width <  0) && (casePart == yappPartLid) && (!subtract)) ? false :
          ((base_width <  0) && (casePart != yappPartLid) && ( subtract)) ? false :
          ((base_width <  0) && (casePart != yappPartLid) && (!subtract)) ? true : undef;
    
  if (apply && (base_width!=0))
  {
    drawWidth = (base_width >= 0) ? base_width : -base_width;
    drawOffset = (base_width >= 0) ? -base_width : -ridgeHeight;
    
    translate([offset_x, offset_y, offset_z]) 
    {
      rotate([rot_X, rot_Y, rot_Z])
      {
        translate([pos_X, pos_Y, 0]) 
        {
          color((subtract) 
          ? "teal" 
          : (casePart == yappPartLid) ? colorLid : colorBase,
          (subtract) 
          ? 1
          : (casePart == yappPartLid) ? alphaLid : alphaBase)
            translate([drawOffset,0,((invertZ) ? wallDepth-base_depth : wallDepth) + ((subtract) ? -0.02 : 0)])
              cube([drawWidth+0.02,base_height,base_depth + ((subtract) ? 0.04 : 0)]);  
        } //translate
      }// rotate
    } //translate
  } // apply
  
  
  else if (base_width <  ridgeHeight) 
  {
    //-- Special Case
    drawWidth = (base_width > 0) 
      ? ridgeHeight-base_width        //-- Positive
      : ridgeHeight+base_width;       //-- Negative
    
    drawOffset = (base_width > 0) 
      ? -ridgeHeight                  //-- Positive
      : -ridgeHeight-base_width;      //-- Negative
  
    translate([offset_x, offset_y, offset_z]) 
    {
      rotate([rot_X, rot_Y, rot_Z])
      {
        translate([pos_X, pos_Y, 0]) 
        {
          color((subtract) 
          ? "teal" 
          : (casePart == yappPartLid) ? colorLid : colorBase,
          (subtract) 
          ? 1
          : (casePart == yappPartLid) ? alphaLid : alphaBase)
            translate([drawOffset,0,((invertZ) ? wallDepth-base_depth : wallDepth) + ((subtract) ? -0.02 : 0)])
              cube([drawWidth+0.02,base_height,base_depth + ((subtract) ? 0.04 : 0)]);  
        } //translate
      }// rotate
    } //translate
  }
} //-- processRidgeExtList()


//===========================================================
// Process the list passeed in for the face
module processFaceList(face, list, casePart, listType, subtract)
{
  assert(!is_undef(listType), "processFaceList: listType must be passed in");
  assert(!is_undef(subtract), "processFaceList: subtract must be passed in");
  
    //
    //      [0]pos_x->|
    //                |
    //  L  |          +-----------+  ^ 
    //  E  |          |           |  |
    //  F  |          |<[2]length>|  [3]height
    //  T  |          +-----------+  v   
    //     |            ^
    //     |            | [1]pos_y
    //     |            v
    //     |   +----------------------------- pcb(0,0)
    //     |
    //     +--------------------------------- box(0,0)

  if (printMessages) echo ("------------------------------"); 
  if (printMessages) echo ("processCutoutList started"); 

  // Setup translations for the requested face
  if (face == yappLeft) 
  { 
    if (printMessages) echo(str("Process ", listType, " on Left Face"));
    rot_X = 90;      // Y
    rot_Y = -90;     // X
    rot_Z = 180;     // Z    
    offset_x = 0;
    offset_y = -wallThickness;
    offset_z = (casePart==yappPartLid) ? -shellHeight : 0;
    
    wallDepth = wallThickness;
    if (listType=="cutout") 
    {
      processCutoutList_Face(face, list, casePart, false, true, false, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth);
    } //-- listType=="cutout"
    else if (listType=="ridgeExt")
    {
      processRidgeExtList_Face(face, list, casePart, false, true, false, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth, subtract);
      
    } //-- (listType=="ridgeExt") 
  }
  else if (face == yappRight) 
  {  
    if (printMessages) echo(str("Process ", listType, " on Right Face"));
    rot_X = 90;      //-- Y
    rot_Y = -90;     //-- X
    rot_Z = 180;     //-- Z
    offset_x = 0;
    offset_y = shellWidth - (wallThickness);
    offset_z = (casePart==yappPartLid) ? -shellHeight : 0;
    wallDepth = wallThickness;
    if (listType=="cutout") 
    {
      processCutoutList_Face(face, list, casePart, false, true, true, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth);
    } // listType=="cutout"
    else if (listType=="ridgeExt")
    {
      processRidgeExtList_Face(face, list, casePart, false, true, true, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth, subtract);
      
    } // (listType=="ridgeExt") 
  }
  else if (face == yappFront) 
  {
    if (printMessages) echo(str("Process ", listType, " on Front Face"));
    rot_X = 0;      //-- Y
    rot_Y = -90;    //-- X
    rot_Z = 0;      //-- Z
    offset_x = shellLength + wallThickness;
    offset_y = 0;
    offset_z = (casePart==yappPartLid) ? -shellHeight : 0;
    wallDepth = wallThickness;
    if (listType=="cutout") 
    {
      processCutoutList_Face(face, list, casePart, false, true, false, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth);
    } //-- listType=="cutout"
    else if (listType=="ridgeExt")
    {
      processRidgeExtList_Face(face, list, casePart, false, true, false, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth, subtract);
      
    } //-- (listType=="ridgeExt") 
  }
  else if (face == yappBack) 
  {
    if (printMessages) echo(str("Process ", listType, " on Back Face"));
    rot_X = 0;      //-- Y
    rot_Y = -90;    //-- X
    rot_Z = 0;      ///-- Z
    offset_x = wallThickness; 
    offset_y = 0;
    offset_z = (casePart==yappPartLid) ? -shellHeight : 0;
    wallDepth = wallThickness;
    if (listType=="cutout") 
    {
      processCutoutList_Face(face, list, casePart, false, true, true, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth);
    } //-- listType=="cutout"
    else if (listType=="ridgeExt")
    {
      processRidgeExtList_Face(face, list, casePart, false, true, true, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth, subtract);
      
    } //-- (listType=="ridgeExt") 
  }
  else if (face == yappLid) 
  {
    if (printMessages) echo(str("Process ", listType, " on Lid Face"));
    rot_X = 0;
    rot_Y = 0;
    rot_Z = 0;
    offset_x = 0;
    offset_y = 0;
    offset_z = -lidPlaneThickness;
    wallDepth = lidPlaneThickness;
    if (listType=="cutout") 
    {
      processCutoutList_Face(face, list, casePart, true, false, true, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth);
    } //-- listType=="cutout"
  }
  else if (face == yappBase) 
  {
    if (printMessages) echo(str("Process ", listType, " on Base Face"));
    rot_X = 0;
    rot_Y = 0;
    rot_Z = 0;
    offset_x = 0;
    offset_y = 0;
    offset_z = -basePlaneThickness;
    wallDepth = basePlaneThickness;
    if (listType=="cutout") 
    {
      processCutoutList_Face(face, list, casePart, true, false, false, rot_X, rot_Y, rot_Z, offset_x, offset_y, offset_z, wallDepth);
    } //-- listType=="cutout"
  } 
} //-- processFaceList()


//===========================================================
//--
//--        -->|             |<-- tubeLength and tubeWidth-->
//--    --------             ----------------------------------------------------
//--                                         # lidPlaneThickness             Leave .5mm is not yappThroughLid 
//--    ----+--+             +--+---------------------------------------      
//--        |  |             |  |   ^                    
//--        |  |             |  |   |
//--        |  |             |  |   #Tube Height
//--        |  |             |  |   |
//--        |  |             |  |   |
//--        |  |             |  |   |
//--        |  |             |  |   v
//--        +--+             +--+   
//--
//--       #tAbvPcb
//--        
//--   +------------------------------------ topPcb 
//--   |  # pcb_Thickness
//--   +-+--+-------------------------------
//--     |  | # standoff_Height
//-- ----+  +-------------------------------------
//--              # basePlaneThickness
//-- ---------------------------------------------
//-- 
module lightTubeCutout()
{
  for(tube=lightTubes)
  {
    if (printMessages) echo ("Tube Def",tube=tube);
    //-- Get the desired coordinate system    
    theCoordSystem = getCoordSystem(tube, yappCoordPCB);  
  
    standoff_Height = standoffHeight(theCoordSystem[2]);
    pcb_Thickness = pcbThickness(theCoordSystem[2]);
    
    xPos = translate2Box_X (tube[0], yappLid, theCoordSystem);
    yPos = translate2Box_Y (tube[1], yappLid, theCoordSystem);
    
    tLength         = tube[2];
    tWidth          = tube[3];
    tWall           = tube[4];
    tAbvPcb         = tube[5];
    shape           = tube[6];
    lensThickness   = getParamWithDefault(tube[7],0);
    toTopOfPCB      = getParamWithDefault(tube[8], standoff_Height+pcb_Thickness);

    cutoutDepth = lidPlaneThickness-lensThickness;
    
    pcbTop2Lid = (baseWallHeight+lidWallHeight+lidPlaneThickness)-(toTopOfPCB+tAbvPcb);
    
    tmpArray = [[xPos, yPos, tWidth, tLength, tLength/2, shape, 0, 0, yappCoordBox, yappCenter]];
   
    if (printMessages) echo ("Tube tempArray",tmpArray);
    translate([0,0,-lensThickness])
    {
      processFaceList(yappLid, tmpArray, yappPartLid, "cutout", true);
    }
  } //-- for tubes
} //-- lightTubeCutout()


//===========================================================
module buildLightTubes()
{
  for(tube=lightTubes)
  {
    //-- Get the desired coordinate system    
    theCoordSystem = getCoordSystem(tube, yappCoordPCB);    
   
    standoff_Height = standoffHeight(theCoordSystem[2]);
    pcb_Thickness = pcbThickness(theCoordSystem[2]);
    
    xPos = translate2Box_X (tube[0], yappLid, theCoordSystem);
    yPos = translate2Box_Y (tube[1], yappLid, theCoordSystem);

    tLength       = tube[2];
    tWidth        = tube[3];
    tWall         = tube[4];
    tAbvPcb       = tube[5];
    tubeType      = tube[6];
    lensThickness = getParamWithDefault(tube[7],0);
    filletRad     = getParamWithDefault(tube[9],0);
    toTopOfPCB    = getParamWithDefault(tube[8], standoff_Height+pcb_Thickness);
    
    pcbTop2Lid = (shellHeight) - (basePlaneThickness + lidPlaneThickness + toTopOfPCB + tAbvPcb);
     
    if (printMessages) echo("buildLightTubes", tubeType=tubeType); 
    if (printMessages) echo (baseWallHeight=baseWallHeight, lidWallHeight=lidWallHeight, lidPlaneThickness=lidPlaneThickness, toTopOfPCB=toTopOfPCB, tAbvPcb=tAbvPcb);
    if (printMessages) echo (pcbTop2Lid=pcbTop2Lid);
    
    translate([xPos, yPos, ((pcbTop2Lid)/-2)-lidPlaneThickness])
    {
      if (tubeType == yappCircle)
      {
        difference()
        {
          color("red") 
            cylinder(h=pcbTop2Lid, d=max(tWidth,tLength)+(tWall*2), center=true);
          
          translate([0,0,-lensThickness - 0.02])
            color("blue") 
              cylinder(h=pcbTop2Lid + lidPlaneThickness +0.02, d=tWidth, center=true);
        }
        if (!isTrue(yappNoFillet, tube))
        {
          filletRadius = (filletRad==0) ? lidPlaneThickness : filletRad; 
          translate([0,0,(pcbTop2Lid/2)])
          color("red") pinFillet(-(tWidth+(tWall*2))/2, filletRadius);
        } // ifFillet
      }
      else
      {
        difference()
        {
          color("red") 
            cube([tWidth+(tWall*2), tLength+(tWall*2), pcbTop2Lid], center=true);
          
          translate([0,0,tWall*-1])
            color("green") 
              cube([tWidth, tLength, pcbTop2Lid], center=true);
          translate([0,0, +lensThickness])
            color("blue") 
              cube([tWidth, tLength, pcbTop2Lid+lensThickness], center=true);
        }
        if ((!isTrue(yappNoFillet, tube)))
        {
          filletRadius = (filletRad==0) ? lidPlaneThickness : filletRad; 
          translate([0,0,(pcbTop2Lid/2)])
          color("red") rectangleFillet(tWidth+(tWall*2), tLength+(tWall*2),filletRadius, 1);
        } // ifFillet
      }
    }
  } //--for(..)
  
} //-- buildLightTubes()


//===========================================================
//-- Create the cut through the lid
module buttonCutout()
{
  for(button=pushButtons)
  {
    // Get the desired coordinate system    
    theCoordSystem = getCoordSystem(button, yappCoordPCB);    
   
    xPos = translate2Box_X (button[0], yappLid, theCoordSystem);
    yPos = translate2Box_Y (button[1], yappLid, theCoordSystem);
    cWidth    = button[2];    
    cLength   = button[3];
    cRadius   = button[4];    
    shape     = getShapeWithDefault(button[10],yappRectangle);
    angle     = getParamWithDefault(button[11],0);
    buttonSlack = getParamWithDefault(button[15],buttonSlack); 
     
    thePolygon = getVectorBase(yappPolygonDef, button);
     
    tmpArray = [[xPos, 
                  yPos, 
                  cWidth + buttonSlack*2, 
                  cLength + buttonSlack*2,
                  cRadius + buttonSlack, 
                  shape, 
                  0, 
                  angle , 
                  yappCenter,
                  yappCoordBox, // Coordinates are already translated to yappCoordBox
                  thePolygon// Polygon
                ]];
     processFaceList(yappLid, tmpArray, yappPartLid, "cutout", true);
  } //-- for buttons
  
} //-- buttonCutout()


//===========================================================
//-- Create the cavity for the button
module buildButtons(preCuts)
{
  if (printMessages) echo("buildButtons(): process ", len(pushButtons)," buttons");

  // Use an index so we can offset the buttons outside the shell
  if(len(pushButtons) > 0)
  {
    for(i=[0:len(pushButtons)-1])  
    {
      button=pushButtons[i];

      // Get the desired coordinate system    
      theCoordSystem = getCoordSystem(button, yappCoordPCB);    
      standoff_Height=standoffHeight(theCoordSystem[2]);
      pcb_Thickness=pcbThickness(theCoordSystem[2]);      
      
      // Get all of the parameters
      xPos = translate2Box_X (button[0], yappLid, theCoordSystem);
      yPos = translate2Box_Y (button[1], yappLid, theCoordSystem);
           
      cLength     = button[2];
      cWidth      = button[3];
      cRadius     = button[4];  // New
      aboveLid    = button[5];
      swHeight    = button[6];
      swTravel    = max(button[7],0.5);
      pDiam       = button[8];
      toTopOfPCB  = getParamWithDefault(button[9], (standoff_Height+pcb_Thickness));
      shape       = getShapeWithDefault(button[10],yappRectangle);
      angle       = getParamWithDefault(button[11],0);
      filletRad   = getParamWithDefault(button[12],0);
      
      // Enable overriding the defaults
      thebuttonWall = getParamWithDefault(button[13],buttonWall);
      thebuttonPlateThickness = getParamWithDefault(button[14],buttonPlateThickness);
      thebuttonSlack = getParamWithDefault(button[15],buttonSlack);
      theSnapSlack = getParamWithDefault(button[16],0.05);
      thePolygon = getVector(yappPolygonDef, button); 

              //
              //        -->|             |<-- LxW or Diameter
              //
              //            +-----------+                                                     -----    
              //    -------+|           |+------------------------------------------    -----   ^
              //           ||           ||               # lidPlaneThickness              ^     Button Thickness
              //    ----+  ||           ||  +---------------------------------------      |     v
              //        |  |+---+   +---+|  |   ^                    ^                    |   -----
              //        |  |    |   |    |  |   |-- buttonCupDepth   |                    |
              //        |  |    |   |    |  |   v                    |                    |
              //        |  |    |   |    |  |   ^                    |-- cupDepth         |
              //        |  |    |   |    |  |   |-- switchTravel     |                    |
              //        |  |    |   |    |  |   v                    v                    |
              //        |  +---+|   |+---+  |  ---                  ---                   |
              //        |      ||   ||      |                                             |
              //        +---+  ||   ||  +---+                          poleHolderLength --|
              //            |  ||   ||  |                                                 |
              //            |  ||   ||  |  >--<-- buttonWall                              v
              //            +--+|   |+--+                                         -----------
              //                |   |
              //                +---+
              //         -->|  |<-- buttonWall
              //            -->|     |<-- poleDiam
              //        
              //   +------------------------------------ topPcb 
              //   +-+--+-------------------------------
              //     |  | # standoffHeight
              //-----+  +-------------------------------------
              //              # basePlaneThickness
              //---------------------------------------------
      buttonCapNetThickness = 0.5;        
      pcbTop2Lid        = (baseWallHeight+lidWallHeight)-(toTopOfPCB);
      
      buttonTopOffset     = ((aboveLid > 0) ? aboveLid : 0);
      cupExtraDepth       = ((aboveLid < 0) ? -aboveLid : 0);
      buttonTopThickness  = lidPlaneThickness + buttonTopOffset;

      buttonCupDepth      = cupExtraDepth + swTravel + thebuttonSlack*2;

      buttonTop2Lid       = pcbTop2Lid-swHeight;
      
      holderLength        = 
        buttonTop2Lid 
        - buttonCupDepth 
        - thebuttonWall 
        - thebuttonPlateThickness 
        - thebuttonSlack
        ;
      
     // check if there is enough room for the button
      assert(holderLength>=0, str("Processing pushButtons[", i, "] Not enough space to add button number ", i, " increase case height above the PCB by ", -holderLength));
      
      // Create the Holder on the lid
      if (preCuts)
      {
     //   color("blue") 
        translate([xPos, yPos, -lidPlaneThickness])
        {
          difference()
          {
            union()
            {
              // Outside of CUP
              // Other shapes don't get a base fillet (for now)
              //module generateShape (Shape, useCenter, Width, Length, Thickness, Radius, Rotation, Polygon)
              translate([0, 0, -(buttonCupDepth + thebuttonWall)])
              {
                filletRadius = (filletRad==0) ? lidPlaneThickness : filletRad; 
                color("green")
                if (!isTrue(yappNoFillet, button))
                {
                  generateShapeFillet (shape, true, cLength, cWidth, buttonCupDepth + thebuttonWall, filletRadius, 0, cRadius, angle, thePolygon, thebuttonWall);
                }
                else
                {
                  generateShape (shape, true, cLength, cWidth, buttonCupDepth + thebuttonWall, cRadius, angle, thePolygon, thebuttonWall);
                } // fillet

              } //translate
              
              //-------- outside pole holder -- Always a cylinder
              translate([0, 0,  -thebuttonWall-buttonCupDepth-holderLength+0.01])
              {
                union()
                {
                  color("gray") cylinder(h=holderLength+0.02, d=pDiam+thebuttonSlack+thebuttonWall);
                  if (!isTrue(yappNoFillet, button))
                  {
                    filletRadius = (filletRad==0) ? lidPlaneThickness : filletRad;
                    // Limit the fillet to the height of the pole or the width of the shelf 
                    maxFillet = min(holderLength, filletRadius);                   
                    translate([0, 0, holderLength])
                    color("violet") pinFillet(-(pDiam+thebuttonSlack+thebuttonWall)/2,maxFillet);
                  } // ifFillet
                } // union
              } // translate
            } //-- union()
            
            // Hollow out the inside
            
            //-------- inside Cap 
            translate([0, 0, -(buttonCupDepth-0.02)])
            {
              color("blue")                       
                generateShape (shape, true, cLength+thebuttonSlack*2, cWidth+thebuttonSlack*2, buttonCupDepth+ 0.02, (cRadius+thebuttonSlack), angle, thePolygon);
            }

            //-- inside pole holder - extenderPole geleider --
            translate([0, 0,  -(holderLength/2) - buttonCupDepth -(thebuttonWall/2) + 0.01]) 
            {
              color("orange") 
                cylinder(h=holderLength+thebuttonWall+0.04, d=pDiam+thebuttonSlack*2, center=true);
            }
          } // difference()
        } //-- translate()
      } 
      else // Post Cuts
      {
        // Create the button extension
        if (printSwitchExtenders)  // only add to render if they are turned on
        {
          // possible location of the SwitchExtender and plate
          // In lid (true)
          //    If preview and lidOnBox
          // In row next to lid (false)
          //    anything else
          externderPos = ($preview) ? (showSideBySide) ? false : true : false; 
           
//          extHeight = buttonTop2Lid + lidPlaneThickness - thebuttonPlateThickness -buttonCapNetThickness -((aboveLid < 0) ? -aboveLid : 0);
          extHeight = buttonTop2Lid -buttonCapNetThickness -cupExtraDepth;
          
          xOff = max(cLength, cWidth);
          
          // Determine where to show them for Lid on case or off
          extPosX = (externderPos) ? xPos : -40 ;
          extPosY = (externderPos) ? yPos : shellWidth*2 - (i* 20);
          extPosZ = (externderPos) ? aboveLid - (showButtonsDepressed ? swTravel :0) : 0 ;
          extRot  = (externderPos) ? angle : 0 ;

          platePosX = (externderPos) ? xPos : -20 ;
          platePosY = (externderPos) ? yPos : shellWidth*2 - (i* 20);
          platePosZ = (externderPos) ? 
          + thebuttonPlateThickness/2 - lidPlaneThickness - buttonTop2Lid  - (showButtonsDepressed ? swTravel :0)
          : -thebuttonPlateThickness/2;
          
          plateRot  = (externderPos) ? 180 : 0 ;
          
          color("red")
          translate ([extPosX,extPosY,extPosZ]) 
          {
            rotate ([0,0,extRot])
            {
              makeSwitchExtender(shape, cLength-thebuttonSlack, cWidth-thebuttonSlack, cRadius, buttonTopThickness, pDiam, extHeight, aboveLid, thePolygon, thebuttonSlack);
            }
          } // translate extender
          color("green")
          translate ([platePosX,platePosY,platePosZ]) 
          {
            rotate ([plateRot,0,0])
            {
              makeSwitchPlate(pDiam, thebuttonPlateThickness, thebuttonSlack, theSnapSlack);
            } 
          } // translate plate
        } // printSwitchExtenders
      } // Post Cuts
    } //-- for buttons ..
  } //-- len(pushButtons) > 0
} //-- buildButtons()


//===========================================================
module drawLabels(casePart, subtract)
{
	function textDirection(code) = 
		(code == yappTextRightToLeft) ? "rtl" :
		(code == yappTextTopToBottom) ? "ttb" :
		(code == yappTextBottomToTop) ? "btt" :
		"ltr";
		
	function textHalign(code) = 
		(code == yappTextHAlignCenter) ? "center" :
		(code == yappTextHAlignRight) ? "right" :
		"left";
		
	function textValign(code) = 
		(code == yappTextVAlignTop) ? "top" :
		(code == yappTextVAlignCenter) ? "center" :
		(code == yappTextVAlignBaseLine) ? "baseline" :
		"bottom";
		

  for ( label = labelsPlane )
  {    
    // If we are adding to the lid  we need to shift it because we are drawing before the lid is positioned
    shiftX = (!subtract) ? -shellLength/2 : 0 ;
    shiftY = (!subtract) ? -shellWidth/2 : 0 ;
        
    shiftZ = (!subtract) 
      ? (casePart== yappPartLid) 
        ? (lidWallHeight + lidPlaneThickness) 
        : -baseWallHeight - basePlaneThickness
      : 0 ;
        
    //-- Optional:
    expandBy = getParamWithDefault(label[8],0);

		//-- Add additional text properties
    theDirection = getYappValueWithDefault(label[9], yappTextLeftToRight);
    theHalign = getYappValueWithDefault(label[10], yappTextHAlignLeft);
    theValign = getYappValueWithDefault(label[11], yappTextVAlignBottom);
    theSpacing = getParamWithDefault(label[12], 1);

		color("red")
    translate([shiftX, shiftY, shiftZ])
    {
    //-- Check if the label is valid for the for subtract value 
    if (((label[3] > 0) && subtract) || ((label[3] < 0) && !subtract))
    {
      theDepth = (subtract) ? label[3] : -label[3];
        
      if ((casePart== yappPartLid) && (label[4]==yappLid))
      {
        if (printMessages) echo ("Draw text on Lid (top)");
        offset_depth = (subtract) ?  0.01 : theDepth -0.01;
        
        translate([label[0], label[1], offset_depth - theDepth]) 
        {
          rotate([0,0,label[2]])
          { 
            linear_extrude(theDepth) 
            {
              offset(r=expandBy)
              text(label[7]
                    , font=label[5]
                    , size=label[6]
                    , direction=textDirection(theDirection)
                    , halign=textHalign(theHalign)
                    , valign=textValign(theValign)
										, spacing=theSpacing);
            } // rotate
          } // extrude
        } // translate
      } //  if lid/lid
      
      if ((casePart== yappPartBase) && (label[4]==yappBase))
      {
        if (printMessages) echo ("Draw text on Base (bottom)");
        offset_depth = (subtract) ?  -0.01 : -theDepth + 0.01;
        
        translate([label[0], shellWidth-label[1], offset_depth]) 
        {
          rotate([0,0,180-label[2]])
          {
            mirror([1,0,0]) 
            linear_extrude(theDepth) 
            {
              {
                offset(r=expandBy)
                text(label[7]
                      , font=label[5]
                      , size=label[6]
											, direction=textDirection(theDirection)
											, halign=textHalign(theHalign)
											, valign=textValign(theValign)
											, spacing=theSpacing);
              } // mirror..
            } // rotate
          } // extrude
        } // translate
      } //  if base/base

      if (label[4]==yappFront)
      {
        if (printMessages) echo ("Draw text on Front");
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  0.01 : theDepth - 0.01;

        translate([shellLength - theDepth + offset_depth, label[0], offset_v + label[1]]) 
        {
          rotate([90,0-label[2],90])
          {
            linear_extrude(theDepth) 
            {
              offset(r=expandBy)
              text(label[7]
                      , font=label[5]
                      , size=label[6]
											, direction=textDirection(theDirection)
											, halign=textHalign(theHalign)
											, valign=textValign(theValign)
											, spacing=theSpacing);
            } // extrude
          } // rotate
        } // translate
      } //  if base/front
      if (label[4]==yappBack)
      {
        if (printMessages) echo ("Draw text on Back", casePart);
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  -0.01 : -theDepth + 0.01;

        translate([offset_depth, shellWidth-label[0], offset_v + label[1]]) 
        {
          rotate([90,0+label[2],90])
          mirror([1,0,0])
          {
            linear_extrude(theDepth) 
            {
              offset(r=expandBy)
              text(label[7]
                      , font=label[5]
                      , size=label[6]
											, direction=textDirection(theDirection)
											, halign=textHalign(theHalign)
											, valign=textValign(theValign)
											, spacing=theSpacing);
            } // extrude
          } // rotate
        } // translate
      } //  if base/back
      
      if (label[4]==yappLeft)
      {
        if (printMessages) echo ("Draw text on Left", casePart);
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  -0.01 : -theDepth + 0.01;
        translate([label[0], theDepth+offset_depth, offset_v + label[1]]) 
        {
          rotate([90,-label[2],0])
          {
            linear_extrude(theDepth) 
            {
              offset(r=expandBy)
              text(label[7]
                    , font=label[5]
                    , size=label[6]
										, direction=textDirection(theDirection)
										, halign=textHalign(theHalign)
										, valign=textValign(theValign)
										, spacing=theSpacing);
            } // extrude
          } // rotate
        } // translate
      } //  if..base/left
      
      if (label[4]==yappRight)
      {
        if (printMessages) echo ("Draw text on Right");
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  0.01 : theDepth - 0.01;
        // Not sure why this is off by 1.5!!!
        translate([shellLength-label[0], shellWidth + offset_depth, -1.5 + offset_v + label[1]]) 
        {
          rotate([90,label[2],0])
          {
            mirror([1,0,0])
            linear_extrude(theDepth) 
            {
              offset(r=expandBy)
              text(label[7]
                    , font=label[5]
                    , size=label[6]
										, direction=textDirection(theDirection)
										, halign=textHalign(theHalign)
										, valign=textValign(theValign)
										, spacing=theSpacing);
            } // extrude
          } // rotate
        } // translate
      } //  if..base/right
    } // Valid check
    } // Translate
  } // for labels
  
} //-- drawLabels()


//===========================================================
module drawImages(casePart, subtract)
{
  for ( image = imagesPlane )
  {
    // If we are adding to the lid  we need to shift it because we are drawing before the lid is positioned
    shiftX = (!subtract) ? -shellLength/2 : 0 ;
    shiftY = (!subtract) ? -shellWidth/2 : 0 ;

    shiftZ = (!subtract)
      ? (casePart== yappPartLid)
        ? (lidWallHeight + lidPlaneThickness)
        : -baseWallHeight - basePlaneThickness
      : 0 ;


    //   Optional:
    scaleBy = getParamWithDefault(image[6],1.0);



    translate([shiftX, shiftY, shiftZ])
    {
    // Check if the image is valid for the for subtract value
    if (((image[3] > 0) && subtract) || ((image[3] < 0) && !subtract))
    {
      theDepth = (subtract) ? image[3] : -image[3];

      if ((casePart== yappPartLid) && (image[4]==yappLid))
      {
        if (printMessages) echo ("Draw image on Lid (top)");
        offset_depth = (subtract) ?  0.01 : theDepth -0.01;

        translate([image[0], image[1], offset_depth - theDepth])
        {
          rotate([0,0,image[2]])
          {
            linear_extrude(theDepth)
            {
              scale(scaleBy)
              import(file = image[5], center = true);
            } // rotate
          } // extrude
        } // translate
      } //  if lid/lid

      if ((casePart== yappPartBase) && (image[4]==yappBase))
      {
        if (printMessages) echo ("Draw image on Base (bottom)");
        offset_depth = (subtract) ?  -0.01 : -theDepth + 0.01;

        translate([image[0], shellWidth-image[1], offset_depth])
        {
          rotate([0,0,180-image[2]])
          {
            mirror([1,0,0]) color("red")
            linear_extrude(theDepth)
            {
              {
                scale(scaleBy)
                import(file = image[5], center = true);
              } // mirror..
            } // rotate
          } // extrude
        } // translate
      } //  if base/base

      if (image[4]==yappFront)
      {
        if (printMessages) echo ("Draw image on Front");
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  0.01 : theDepth - 0.01;

        translate([shellLength - theDepth + offset_depth, image[0], offset_v + image[1]])
        {
          rotate([90,0-image[2],90])
          {
            linear_extrude(theDepth)
            {
              scale(scaleBy)
              import(file = image[5], center = true);
            } // extrude
          } // rotate
        } // translate
      } //  if base/front
      if (image[4]==yappBack)
      {
        if (printMessages) echo ("Draw image on Back", casePart);
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  -0.01 : -theDepth + 0.01;

        translate([offset_depth, shellWidth-image[0], offset_v + image[1]])
        {
          rotate([90,0+image[2],90])
          mirror([1,0,0])
          {
            linear_extrude(theDepth)
            {
              scale(scaleBy)
              import(file = image[5], center = true);
            } // extrude
          } // rotate
        } // translate
      } //  if base/back

      if (image[4]==yappLeft)
      {
        if (printMessages) echo ("Draw image on Left", casePart);
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  -0.01 : -theDepth + 0.01;
        translate([image[0], theDepth+offset_depth, offset_v + image[1]])
        {
          rotate([90,-image[2],0])
          {
            linear_extrude(theDepth)
            {
              scale(scaleBy)
              import(file = image[5], center = true);
            } // extrude
          } // rotate
        } // translate
      } //  if..base/left

      if (image[4]==yappRight)
      {
        if (printMessages) echo ("Draw image on Right");
        offset_v = (casePart==yappPartLid) ? -shellHeight : 0;
        offset_depth = (subtract) ?  0.01 : theDepth - 0.01;
        // Not sure why this is off by 1.5!!!
        translate([shellLength-image[0], shellWidth + offset_depth, -1.5 + offset_v + image[1]])
        {
          rotate([90,image[2],0])
          {
            mirror([1,0,0])
            linear_extrude(theDepth)
            {
              scale(scaleBy)
              import(file = image[5], center = true);
            } // extrude
          } // rotate
        } // translate
      } //  if..base/right
    } // Valid check
    } // Translate
  } // for images

} //  drawImages()


//===========================================================
module baseShell()
{
    //-------------------------------------------------------------------
    module subtrbaseRidge(L, W, H, posZ, rad)
    {
      wall = (wallThickness/2)+(ridgeSlack/2);  // 26-02-2022
      
      oRad = rad;
      iRad = getMinRad(oRad, wallThickness);
      cRad = (rad + iRad)/2;
      bRad = (rad + (wallThickness/2)) /2;
      
      difference()
      {
        translate([0,0,posZ])
        {
          //-- The outside doesn't need to be a minkowski form so just use a cube
          translate([-L ,-W, 0]) {
            cube([L*2, W*2, shellHeight]);
          }
        }
        
        //-- hollow inside
        translate([0, 0, posZ])
        {
          linear_extrude(shellHeight+1)
          {
            if (shellEdgeVert == yappEdgeRounded)
            { 
              //-- Changed to RoundedRectangle 
              roundedRectangle2D(width=L-ridgeSlack,length=W-ridgeSlack,radius=cRad-(ridgeSlack/4));
            }
            else if (shellEdgeVert == yappEdgeSquare)
            { 
              square([(L-ridgeSlack), (W-ridgeSlack)], center=true);
            }
            else if (shellEdgeVert == yappEdgeChamfered)
            { 
            chamferedRectangle2D((L-ridgeSlack), (W-ridgeSlack), bRad - (ridgeSlack/4));
            }
            else 
            {
              assert(false, "Unsupported edge combination");
            } 
          } // linear_extrude..
        } // translate()
      } // diff
    } //-- subtrbaseRidge()

//-------------------------------------------------------------------
   
  posZ00 = (baseWallHeight) + basePlaneThickness;
  
  translate([(shellLength/2), shellWidth/2, posZ00])
  {
    difference()  //(b) Remove the yappPartLid from the base
    {
      union()
      {
        //-- Create the shell and add the Mounts and Hooks
        minkowskiBox(yappPartBase, shellInsideLength, shellInsideWidth, baseWallHeight, roundRadius, basePlaneThickness, wallThickness, true);
        
        
        if ($preview) 
        {
          translate([-shellLength/2, -shellWidth/2, -baseWallHeight-basePlaneThickness])    
          drawCenterMarkers();
        }
      } // union
      if ($preview && showSideBySide==false && hideBaseWalls)
      {
        //--- wall's
        translate([0,0,shellHeight/2])
        {
          color(colorBase, alphaBase)
          cube([shellLength*2, shellWidth*2, 
                shellHeight+((baseWallHeight*2)-(basePlaneThickness+roundRadius))], 
                center=true);
        } // translate
      } // hideBaseWalls=true
      else  //-- normal
      {
        color(colorBase, alphaBase)
        union()
        {
          //--- only cutoff upper half
          translate([0,0,shellHeight/2])
          {
            cube([shellLength*2, shellWidth*2, shellHeight], center=true);
          } // translate
          
          //-- Create ridge
          subtrbaseRidge(shellInsideLength+wallThickness, 
                          shellInsideWidth+wallThickness, 
                          ridgeHeight, 
                          (ridgeHeight*-1), roundRadius);
        } //union
      } // hideBaseWalls=false
    } // difference(b)  
  } // translate
  
  //-- Draw the objects that connect to the Base
  pcbHolders();
  printSnapJoins(yappPartBase);

  //--Only generate the cut box if we have connectors to add
  if (len(connectors) >0)
  {
    intersection()
    {  
      iRad = getMinRad(roundRadius, wallThickness);
      cRad = (roundRadius + iRad)/2;
      
      translate([shellLength/2, shellWidth/2, posZ00])
      minkowskiCutBox(shellInsideLength-ridgeSlack, shellInsideWidth-ridgeSlack, baseWallHeight, cRad, lidPlaneThickness, wallThickness);
      
      shellConnectors(yappPartBase, false);
    } //intersection()
  }// have connectors
  makeRidgeExt(yappPartBase, false);
} //-- baseShell()


//===========================================================
module lidShell()
{
  //--Added configurable gap
  function newRidge(p1) = (p1>ridgeGap) ? p1-ridgeGap : p1;
  //-------------------------------------------------------------------
  module removeLidRidge(L, W, H, rad)
  {
    wall = (wallThickness/2);
    oRad = rad;
    iRad = getMinRad(oRad, wall);
     
    iRad2 = getMinRad(oRad, wallThickness);
    cRad = (rad + iRad2)/2;      
    bRad = (rad + (wallThickness/2)) /2;
    
    //-- hollow inside
    translate([0,0,-H-shellHeight])
    {
      linear_extrude(H+shellHeight)
      {
        if (shellEdgeVert == yappEdgeRounded)
        { 
            //-- Changed to RoundedRectangle 
            roundedRectangle2D(width=L+ridgeSlack,length=W+ridgeSlack,radius=cRad+(ridgeSlack/4));
        }
        else if (shellEdgeVert == yappEdgeSquare)
        { 
          square([(L+ridgeSlack), (W+ridgeSlack)], center=true);
        }
        else if (shellEdgeVert == yappEdgeChamfered)
        { 
          chamferedRectangle2D((L+ridgeSlack), (W+ridgeSlack), bRad + (ridgeSlack/4));
        }
        else 
        {
          assert(false, "Unsupported edge combination");
        } 
      } // linear_extrude
    } //  translate  
  } //-- removeLidRidge()
 
  //-------------------------------------------------------------------

  posZ00 = lidWallHeight+lidPlaneThickness;    
  translate([(shellLength/2), shellWidth/2, posZ00*-1])
  {
    difference() //d1
    {
      union()
      {
        minkowskiBox(yappPartLid, shellInsideLength,shellInsideWidth, lidWallHeight, roundRadius, lidPlaneThickness, wallThickness, true);
        if ($preview) 
        {
          translate([-shellLength/2, -shellWidth/2, -(shellHeight-lidWallHeight-lidPlaneThickness)])
          drawCenterMarkers();
        }
      } // Union
      
      if ($preview && showSideBySide==false && hideLidWalls)
      {
        //--- cutoff wall
        translate([-shellLength,-shellWidth,shellHeight*-1])
        {
          color(colorLid, alphaLid)
          cube([shellLength*2, shellWidth*2, shellHeight+(lidWallHeight+lidPlaneThickness-roundRadius)], 
                  center=false);
        } // translate
      }
      else  //-- normal
      {
        color(colorLid, alphaLid)
        union()
        {
          //--- cutoff lower half
          // Leave the Ridge height so we can trim out the part we don't want
          translate([-shellLength,-shellWidth,-shellHeight - newRidge(ridgeHeight)])
          {
            cube([(shellLength)*2, (shellWidth)*2, shellHeight], center=false);
          } // translate
          
          //-- remove the ridge
          removeLidRidge(shellInsideLength+wallThickness, 
                      shellInsideWidth+wallThickness, 
                      newRidge(ridgeHeight), 
                      roundRadius);
        }
      } // if normal
    } // difference(d1)
  } // translate

  // Draw the objects that connect to the Lid
  makeRidgeExt(yappPartLid, false);
  pcbPushdowns();
  
  //--Only generate the cut box if we have connectors to add
  if (len( connectors) >0)
  {
    intersection()
    {  
      iRad = getMinRad(roundRadius, wallThickness);
      cRad = (roundRadius + iRad)/2;

      translate([(shellLength/2), shellWidth/2, posZ00*-1])
      minkowskiCutBox(shellInsideLength, shellInsideWidth, lidWallHeight, cRad, lidPlaneThickness, wallThickness);
      
      shellConnectors(yappPartLid, false);
    } //intersection()
  }// have connectors
  buildLightTubes();
  buildButtons(true);
} //-- lidShell()


        
//===========================================================
module pcbStandoff(plane, pcbStandHeight, filletRad, type, color, useFillet, configList) 
{
  //-- Get the PCBinfo (defaults)
  thePCB = getPCBInfo(yappPCBName, configList);
 
  pcb_Length       = pcbLength(thePCB[0]); 
  pcb_Width        = pcbWidth(thePCB[0]);
  pcb_Thickness    = pcbThickness(thePCB[0]);
  standoff_Height  = standoffHeight(thePCB[0]);
  standoff_Diameter  = standoffDiameter(thePCB[0]);
  standoff_PinDiameter  = standoffPinDiameter(thePCB[0]);
  standoff_HoleSlack  = (standoffHoleSlack(thePCB[0]) != undef) ? standoffHoleSlack(thePCB[0]) : 0.4;
  
  usePCBCoord = isTrue(yappCoordBox, configList) ? false : true;
    
  pcbGapTmp = getParamWithDefault(configList[3],-1);
  pcbGap = (pcbGapTmp == -1 ) ? (usePCBCoord) ? pcb_Thickness : 0 : pcbGapTmp;

  thestandoff_Diameter = getParamWithDefault(configList[4],standoff_Diameter);
  thestandoff_PinDiameter = getParamWithDefault(configList[5],standoff_PinDiameter);
  thestandoff_HoleSlack = getParamWithDefault(configList[6],standoff_HoleSlack);

  //Sanity Check the diameters
   assert((thestandoff_PinDiameter < thestandoff_Diameter), str("Pin Diameter [", thestandoff_PinDiameter, "] is larger than PCB stand Diameter [", thestandoff_Diameter, "]" ));
  
   assert((thestandoff_PinDiameter+thestandoff_HoleSlack < thestandoff_Diameter), str("Pin Diameter [", thestandoff_PinDiameter, "] with Slack [", thestandoff_HoleSlack, "] is larger than PCB stand Diameter [", thestandoff_Diameter, "]" ));
  
  useSelfThreading = isTrue(yappSelfThreading, configList) ? true : false;

  pinLengthParam = getParamWithDefault(configList[8],0);
  
  pinLength = (pinLengthParam == 0) 
    ? pcbGap + pcbStandHeight + thestandoff_PinDiameter 
    : pcbStandHeight + pinLengthParam ;
  
  

    // **********************
		//-- Use boxPart to determine where to place it
    module standoff(boxPart, color)
    {      
      color(color,1.0)
        cylinder(d = thestandoff_Diameter, h = pcbStandHeight, center = false);
      //-- flange --
      if (boxPart == yappPartBase)
      {
        if (useFillet) 
        {
          filletRadius = (filletRad==0) ? basePlaneThickness : filletRad; 
          color(color,1.0) pinFillet(thestandoff_Diameter/2, filletRadius);
        } // ifFillet
      }
      if (boxPart == yappPartLid)
      {
        if (useFillet) 
        {
          filletRadius = (filletRad==0) ? lidPlaneThickness : filletRad; 
          translate([0,0,pcbStandHeight])
            color(color,1.0) pinFillet(-thestandoff_Diameter/2, filletRadius);
        } // ifFillet
      }
    } //-- standoff()
        
    // **********************
    module standPin(boxPart, color, pinLength)
    {
			pinZOffset = (boxPart == yappPartBase)
				? 0
				: pcbStandHeight-pinLength;
		
			tipZOffset = (boxPart == yappPartBase)
				? 0
				: pinLength;
				
			translate([0,0,pinZOffset])
			{
				color(color, 1.0)
				union() 
				{
				  if (useFillet) 
					{
						translate([0,0,pinLength-tipZOffset]) 
						sphere(d = thestandoff_PinDiameter);
					} // if (useFillet)
				cylinder(
					d = thestandoff_PinDiameter,
					h = pinLength,
					center = false); 
				} //union
			} // translate
    } //-- standPin()
    
    // **********************
		//-- Use boxPart to determine where to place it
    module standHole(boxPart, color, useSelfThreading)
    {
      if (useFillet) 
      {
      
        //--add option for no internal fillet
        noIntFillet = isTrue(yappNoInternalFillet, configList);
      
        filletZ = (boxPart == yappPartBase)
					? -pcbGap :
					pcbStandHeight-pcbGap;
				
				filletDiameter = (boxPart == yappPartBase)
					? -(thestandoff_PinDiameter+thestandoff_HoleSlack)/2
					: (thestandoff_PinDiameter+thestandoff_HoleSlack)/2;
				
        holeZ = (boxPart == yappPartBase)
					? + 0.02 
					: -0.02;

				color(color, 1.0)
				difference() 
				{
					//--The Actual Hole
					translate([0,0,holeZ]) 
            
            if (!useSelfThreading)
            {   
                cylinder(
                    d = thestandoff_PinDiameter+thestandoff_HoleSlack,
                    h = pcbStandHeight+0.02,
                    //h = pcbStandHeight+0.02-thestandoff_PinDiameter/2,
                    center = false);
            } 
            else
            {
                self_forming_screw(h=pcbStandHeight+0.02, d=thestandoff_PinDiameter,center=false);   
            }
                        
            if (!noIntFillet) {
              //-- The Fillet		
              filletRadius = (filletRad==0) ? basePlaneThickness : filletRad; 
              translate([0,0,filletZ+pcbGap]) 
              color(color,1.0) 
              pinFillet(-filletDiameter, -filletRadius);
            }
				} // difference
      } //if (useFillet) 
      else
      {
        color(color, 1.0)
        translate([0,0,-0.01])

        if (!useSelfThreading)
        {
          cylinder(
            d = thestandoff_PinDiameter+thestandoff_HoleSlack,
            h = (pcbGap*2)+pcbStandHeight+0.02,
            center = false);
        } // Self Threading
        else
        {
          self_forming_screw(
            d=thestandoff_PinDiameter,
            h=pcbStandHeight+0.02, 
            center=false);   
        } // Not Self Threading
      } //if (useFillet) else 
    } //-- standhole()
    
		
	//--------------------------------------------------
	//-- Add the Standoff to the part.
	if (type == yappPin)  
	{
		//-- pin - Place Pin in Lid and Hole in Base
		//standoff(plane, color);
		if (plane == yappPartBase) 
		{
			if (printMessages) echo("yappPin - Add Pin to Base");
			standoff(plane, color);
			standPin(plane, color, pinLength);
		} //yappPartBase  
		else 
		{
			if (printMessages) echo("yappPin - Add Hole to Lid");
			difference()
			{
				standoff(plane, color);
				standHole(plane, color, useSelfThreading);
			}   
		} // yappPartLid
	} //type == yappPin
	
	if (type == yappHole)                  //-- hole
	{
		//-- pin - Place Hole in Lid and Hole in Base	
		if (plane == yappPartBase) 
		{
			if (printMessages) echo("yappHole - Add Hole to Base");
			difference() 
			{
				standoff(plane, color);
				standHole(plane, color, useSelfThreading);
			}
		} //yappPartBase
		else
		{
			if (printMessages) echo("yappHole - Add Hole to Lid");
			difference() 
			{
				standoff(plane, color);
				standHole(plane, color, useSelfThreading);
			}
		} //yappPartLid
	} // type == yappHole

	if (type == yappTopPin)                  //-- TopPin
	{
		//-- pin - Place Hole in Lid and Pin in Base
		if (plane == yappPartLid) 
		{
			if (printMessages) echo("yappTopPin - Add Pin to Lid");
			standoff(plane, color);
			standPin(plane, color, pinLength);
		} // yappPartLid 
		else 
		{
			if (printMessages) echo("yappTopPin - Add Hole to Base");
			difference()
			{
				standoff(plane, color);
				standHole(plane, color, useSelfThreading);
			}   
		} //yappPartBase
	} // type == yappTopPin
} //-- pcbStandoff()

        
//===========================================================
module connectorNew(shellPart, theCoordSystem, x, y, conn, outD, subtract) 
{
  face = (shellPart==yappPartBase) ? yappBase : yappLid ;
  faceThickness = (shellPart==yappPartBase) ? basePlaneThickness : lidPlaneThickness ;
  connHeightRaw = translate2Box_Z (conn[2], face, theCoordSystem);
  
  pcb_Thickness = pcbThickness(theCoordSystem[2]);
  
  connHeight =  connHeightRaw;

  diam1 = conn[3]; //-- screw Diameter
  diam2 = conn[4]; //-- screwHead Diameter
  diam3 = conn[5]; //-- insert Diameter
  diam4 = outD;
  
  
  screwHoleHeight = connHeight;
  
//  echo("%^%^%^%^%", ((diam4-diam2)/2));
//  echo(faceThickness=faceThickness);
  
  screwHeadHeight = connHeight - max((((diam4-diam2)/2)), faceThickness );  
//  screwHeadHeight = connHeight - 2;  
  
  insertHeight = getParamWithDefault(conn[7],undef);
  
  pcbGapTmp = getParamWithDefault(conn[8],undef);
  
  fR = getParamWithDefault(conn[9],0); //-- filletRadius
 
  pcbGap = (pcbGapTmp == undef ) ? ((theCoordSystem[0]==yappCoordPCB) ? pcb_Thickness : 0) : pcbGapTmp;
  
  if (printMessages) echo("connectorNew", pcbGap=pcbGap,connHeightRaw=connHeightRaw,connHeight=connHeight,shellHeight=shellHeight);
   
  if (shellPart==yappPartBase)
  {
//    color("Yellow")
    translate([x, y, 0])
    {
      hb = connHeight; 
      if (connHeight >= faceThickness) 
      {  
        union()
        {
          //-- Do the add part
          if (!subtract) 
          //difference()
          {
            union()
            {
              //-- outerCylinder --
              color("orange")
              translate([0,0,0.02])
              linear_extrude(hb-0.02)
                circle(d = diam4); //-- outside Diam
                
              //--Add outer Fillet
              if (!isTrue(yappNoFillet, conn))
              {
                filletRadius = (fR == 0) ? faceThickness : fR; 
                filletRad = min(filletRadius,connHeight - faceThickness);
                if (hb>faceThickness)
                {
                  translate([0,0,(faceThickness)])
                  {
                    color("violet")
                    pinFillet(diam4/2, filletRad);
                  }
                }
              }// ifFillet
            }
          }
          else
          //-- Remove part
          {
            difference()
            {
              union()
              {
                //-- screw head Hole --
                color("Cyan") 
                if (!isTrue(yappCountersink, conn))
                {
                  translate([0,0,-0.01]) 
                    cylinder(h=screwHeadHeight+0.02, d=diam2);
                }
                else
                {
                  translate([0,0, -0.01])
                  union()
                  {
                    cylinder(h=countersinkHeight(conn), d1=diam2, d2=0);
                  }
                } // Countersunk
                
                
                //-- screwHole --
                translate([0,0,-0.01])  
                  color("blue") 
                    cylinder(h=screwHoleHeight+0.02, d=diam1);
                
              }//Union
              //-- Internal fillet
              if (!isTrue(yappNoFillet, conn) && !isTrue(yappCountersink, conn))
              {
                if (!isTrue(yappNoInternalFillet, conn)) 
                {
                  filletRadius = (diam2-diam1)/4; // 1/2 the width of the screw flange
                  
                  filletRad = min (filletRadius, (diam4-diam1)/2);
                  translate([0,0, screwHeadHeight+0.01])
                  {
                    color("Red")
                    pinFillet(-diam2/2-0.01, -filletRad);
                  }
                }// internal fillet allowed
              }// ifFillet
            } //  difference
          }// Remove Part
        } // union
      } // Height > plane thickness
    } //  translate
  } //  if base
  
  if (shellPart==yappPartLid)
  {
    //-- calculate the Z-position for the lid connector.
    //-- for a PCB connector, start the connector on top of the PCB to push it down.
    
    heightTemp = shellHeight-connHeight-pcbGap;
    zOffset = -heightTemp;

 //   color("Yellow")
    translate([x, y, zOffset])
    {
      ht=(heightTemp);
      union()
      {
        //-- Do the add part
        if (!subtract) 
        {
          union()
          {
            //-- outside Diameter --
            color("orange")
            linear_extrude(ht-0.01)
                circle(d = diam4);
            //-- flange --
            if (!isTrue(yappNoFillet, conn))
            {
              filletRadius = (fR == 0) ? lidPlaneThickness : fR;
              translate([0,0,ht-lidPlaneThickness]) 
              {
                pinFillet(-diam4/2, filletRadius);
              }
            } // ifFillet
          } 
        } // Add Part
        else
        { // Subtract part
          adjustedHeight = 
          (!is_undef(insertHeight) && (insertHeight < (ht-lidPlaneThickness))) 
            ? insertHeight - lidPlaneThickness + 0.02
            : ht - lidPlaneThickness + 0.02  
          ;
        
          //-- insert --
          difference()
          {
            color("red")
            translate([0, 0, -0.01])
            if (!isTrue(yappSelfThreading, conn))
            {
              //linear_extrude(ht - lidPlaneThickness + 0.02)
              linear_extrude(adjustedHeight)
                circle(d = diam3);
            } else {
              self_forming_screw(h=adjustedHeight, d=dia
Download .txt
gitextract_i9f70_ot/

├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── STL/
│   ├── MODELS/
│   │   ├── Arduino_Uno_model.stl
│   │   └── virtualP1Cable_v10_model.stl
│   ├── YAPP_ArduinoClone_v30.stl
│   ├── YAPP_Demo_buttons_v30.stl
│   └── YAPP_Demo_lightTubes_v30.stl
├── YAPP_Template_v3.scad
├── YAPPgenerator_v3.scad
└── examples/
    ├── ESP32-CAM-USB-FISH_v30.scad
    ├── ESP32-CAM-USB_v30.scad
    ├── GateAlarm_Sample_v30.scad
    ├── Multiple_PCB_v30.scad
    ├── PoolMonitor_v30.scad
    ├── RidgeExtDemo_v30.scad
    ├── WaterHeaterMonitor_v3.scad
    ├── YAPP_ArduinoClone_v30.scad
    ├── YAPP_Connector_Demo.scad
    ├── YAPP_Countersink Sample_v3.scad
    ├── YAPP_Demo_DisplayMount_LCD2004.scad
    ├── YAPP_Demo_DisplayMount_v31.scad
    ├── YAPP_Demo_Joystick_Paddle Controller_v30.scad
    ├── YAPP_Demo_Labels_v3.scad
    ├── YAPP_Demo_RealBox_v30.scad
    ├── YAPP_Demo_RealBox_v31.scad
    ├── YAPP_Demo_boxMounts_v30.scad
    ├── YAPP_Demo_boxMounts_v31.scad
    ├── YAPP_Demo_buttons2_v30.scad
    ├── YAPP_Demo_buttons2_v31.scad
    ├── YAPP_Demo_buttons_v30.scad
    ├── YAPP_Demo_buttons_v31.scad
    ├── YAPP_Demo_connectors_v33.scad
    ├── YAPP_Demo_cutout_yappRing_v30.scad
    ├── YAPP_Demo_cutout_yappRing_v31.scad
    ├── YAPP_Demo_cutout_yappSphere_v30.scad
    ├── YAPP_Demo_cutouts_all_coord_systems_v30.scad
    ├── YAPP_Demo_cutouts_all_coord_systems_v31.scad
    ├── YAPP_Demo_cutouts_masks_v30.scad
    ├── YAPP_Demo_cutouts_v30.scad
    ├── YAPP_Demo_imagesPlane_v3.scad
    ├── YAPP_Demo_lightTubes_v30.scad
    ├── YAPP_HookTest_v30.scad
    ├── YAPP_Reference_Masks_v30.scad
    ├── YAPP_Reference_Shapes_v30.scad
    ├── YAPP_RidgeExtDemo_v30.scad
    ├── YAPP_RidgeExtDemo_v31.scad
    ├── YAPP_TEST_BoxTypes_v32.scad
    ├── YAPP_Test_SnapJoints_v30.scad
    ├── YAPP_ViewShapes_v30.scad
    ├── YAPP_WemosD1mini_v30.scad
    ├── YAPP_connectors_v30.scad
    ├── YAPP_cutouts_from_inside_v30.scad
    └── pcbStandTest.scad
Condensed preview — 55 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (810K chars).
[
  {
    "path": ".gitignore",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "CHANGELOG.md",
    "chars": 18460,
    "preview": "# YAPP Change Log\n\n## Rev. v3.0.1 (2024-01-15)\n* Re-organzie Git repo to maintain only the latest version in the `main` "
  },
  {
    "path": "LICENSE",
    "chars": 1073,
    "preview": "MIT License\n\nCopyright (c) 2022 Willem Aandewiel\n\nPermission is hereby granted, free of charge, to any person obtaining "
  },
  {
    "path": "README.md",
    "chars": 7429,
    "preview": "# YAPP_Box\nYet Another Parametric Projectbox generator\n\nThis OpenSCAD project can be used to create extremely comprehens"
  },
  {
    "path": "YAPP_Template_v3.scad",
    "chars": 26575,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "YAPPgenerator_v3.scad",
    "chars": 221094,
    "preview": "/*\n***************************************************************************  \n**  Yet Another Parameterised Projectbo"
  },
  {
    "path": "examples/ESP32-CAM-USB-FISH_v30.scad",
    "chars": 14203,
    "preview": "//---------------------------------------------------------\n// Yet Another Parameterized Projectbox generator\n//\n//  Thi"
  },
  {
    "path": "examples/ESP32-CAM-USB_v30.scad",
    "chars": 14042,
    "preview": "//---------------------------------------------------------\n// Yet Another Parameterized Projectbox generator\n//\n//  Thi"
  },
  {
    "path": "examples/GateAlarm_Sample_v30.scad",
    "chars": 16833,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/Multiple_PCB_v30.scad",
    "chars": 24888,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/PoolMonitor_v30.scad",
    "chars": 19221,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/RidgeExtDemo_v30.scad",
    "chars": 12507,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/WaterHeaterMonitor_v3.scad",
    "chars": 25650,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_ArduinoClone_v30.scad",
    "chars": 11116,
    "preview": "//---------------------------------------------------------\n// Yet Another Parameterized Projectbox generator\n//\n//  Thi"
  },
  {
    "path": "examples/YAPP_Connector_Demo.scad",
    "chars": 27643,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Countersink Sample_v3.scad",
    "chars": 21777,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_DisplayMount_LCD2004.scad",
    "chars": 10234,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_DisplayMount_v31.scad",
    "chars": 8941,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_Joystick_Paddle Controller_v30.scad",
    "chars": 15878,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_Labels_v3.scad",
    "chars": 11266,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_RealBox_v30.scad",
    "chars": 11854,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_RealBox_v31.scad",
    "chars": 11854,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_boxMounts_v30.scad",
    "chars": 6692,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_boxMounts_v31.scad",
    "chars": 6704,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_buttons2_v30.scad",
    "chars": 10718,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_buttons2_v31.scad",
    "chars": 10718,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_buttons_v30.scad",
    "chars": 7297,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_buttons_v31.scad",
    "chars": 8474,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_connectors_v33.scad",
    "chars": 9602,
    "preview": "/*\n***************************************************************************  \n**  Yet Another Parameterised Projectbo"
  },
  {
    "path": "examples/YAPP_Demo_cutout_yappRing_v30.scad",
    "chars": 7829,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_cutout_yappRing_v31.scad",
    "chars": 7829,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_cutout_yappSphere_v30.scad",
    "chars": 14685,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_cutouts_all_coord_systems_v30.scad",
    "chars": 8992,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_cutouts_all_coord_systems_v31.scad",
    "chars": 8978,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_cutouts_masks_v30.scad",
    "chars": 9049,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_cutouts_v30.scad",
    "chars": 10612,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_imagesPlane_v3.scad",
    "chars": 8034,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Demo_lightTubes_v30.scad",
    "chars": 11330,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_HookTest_v30.scad",
    "chars": 11076,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Reference_Masks_v30.scad",
    "chars": 9536,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_Reference_Shapes_v30.scad",
    "chars": 11317,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_RidgeExtDemo_v30.scad",
    "chars": 13989,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_RidgeExtDemo_v31.scad",
    "chars": 13983,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_TEST_BoxTypes_v32.scad",
    "chars": 1910,
    "preview": "include <../YAPPgenerator_v3.scad>\n\n\n//-- Edit these parameters for your own box dimensions\nwallThickness       = 2.6;\nb"
  },
  {
    "path": "examples/YAPP_Test_SnapJoints_v30.scad",
    "chars": 5816,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/YAPP_ViewShapes_v30.scad",
    "chars": 570,
    "preview": "\ninclude <../YAPPgenerator_v3.scad>\n\n\n\nif(len(preDefinedShapes) > 0)\n{\n  for(i=[0:len(preDefinedShapes)-1])  \n  {\n    sh"
  },
  {
    "path": "examples/YAPP_WemosD1mini_v30.scad",
    "chars": 8364,
    "preview": "//---------------------------------------------------------\n// This design is parameterized based on the size of a PCB.\n"
  },
  {
    "path": "examples/YAPP_connectors_v30.scad",
    "chars": 5396,
    "preview": "/*\n***************************************************************************  \n**  Yet Another Parameterised Projectbo"
  },
  {
    "path": "examples/YAPP_cutouts_from_inside_v30.scad",
    "chars": 11328,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  },
  {
    "path": "examples/pcbStandTest.scad",
    "chars": 9444,
    "preview": "//-----------------------------------------------------------------------\n// Yet Another Parameterized Projectbox genera"
  }
]

// ... and 5 more files (download for full content)

About this extraction

This page contains the full source code of the mrWheel/YAPP_Box GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 55 files (13.9 MB), approximately 213.3k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!