# CAD

## Prep
For this guide, I'm going to be using [Onshape](https://cad.onshape.com), a free browser-based CAD software. The process is almost the same in any CAD software though.

Before we start, download step files of the components you're using in your clock, in this example that's:
- [TFT Display](https://github.com/destroyer796/BLARE-Alarm-Clock/blob/main/Display/Display%20with%20pins.step)
- Your PCB!

For any other files, such as step files, dimensions, or PCB footprints, check out [this repo](https://github.com/destroyer796/BLARE-Alarm-Clock)

## Creating a new document
1. Click the `Create` button in the top left corner of the home page.
![onshape-create](Images/onshape-create.webp)

2. Select `Document` from the dropdown.
3. Give it a name.
4. Click `OK`.
![Onshape-document](Images/Onshape-document.webp)

A new document opens with two default tabs at the bottom: a `Part Studio` and an `Assembly`. You’ll use both.

## Importing into Onshape

1. In your Onshape document, click the `+` button in the bottom left corner of the screen.
2. Select `Import`.
3. Choose the `.step` file for your part.
4. Onshape will process it and add a new tab to your document. Repeat for each component you add.

Once imported, your parts appear as 3D models you can view and reference.

## Understanding Part Studios vs Assemblies

Onshape has two main workspace types and it’s important to know the difference:

- `Assembly`: where you combine multiple parts together and check how they fit. Your imported PCB lives here.
- `Part Studio`: where you actually model and design new parts. You’ll build your case here.

You **cannot** model new geometry in an Assembly. You need a Part Studio for that.

## Step 1: Setting up your Document

**Quick note before we start** - Make sure you're not following 1:1! Your case needs to be unique!

1. Create a new document
2. Using the `+` in the bottom left, import your components: PCB with components, display, etc. This may take a minute to load. I like to click `Combine in a single Part Studio` to simplify things a bit.
3. Click on the PCB file to highlight the whole thing, and use the `Composite Part` tool to make a single part you can import to the Assembly tab. Name this something like `PCB`.

![CAD-composite](Images/CAD-composite.webp)

4. In your Assembly tab, insert your screen and PCB so you can build around them. From there, move them around to where you want them to be relative to each other, I used fastened mates here.

![CAD-Layout](Images/CAD-Layout.webp)

5. Once you've laid out the PCB and the display how you'd like them to be in the clock, search for the tool `Create Part Studio in context` to open a new part studio with the parts we just imported as context. 

![CAD-context](Images/CAD-context.webp)

This should leave you with something like this.

## Step 2: Making the Walls

1. Create a sketch on the same plane as the bottom of the display, this will serve as the base sketch for our case.

![CAD-emptysketch](Images/CAD-emptysketch.webp)

2. Using the `Corner rectangle` and `Dimension` tools, draw 2 rectangles, one offset from the PCB by at least 0.5mm (use the `Project` tool to use the PCB's geometry as a reference!), and one offset from that for the walls. I did 8mm on all sides, except for the screen I did 3mm away from the front of the screen.

![CAD-1](Images/CAD-1.webp)

3. Using the `Extrude` tool, first extrude the base down 3mm, then the walls up by 33mm.

![CAD-2](Images/CAD-2.webp)
![CAD-3](Images/CAD-3.webp)

4. Now we have a rough case, but there's no mounting for our display yet. Make a new sketch (or use the old one if you want) on the bottom of the case. Using some rectangles, create a slot that the display can slide into, leave at least 0.5mm tolerance.

![CAD-4](Images/CAD-4.webp)

## Step 3: PCB Supports

1. Now we're gonna make the support posts for the PCB. Make another sketch on the bottom of the case (or in the same one if you want), and use the `Center point circle` tool to make some 4.6mm diameter circles with the same center point as the holes on your PCB, this will fit our heatset inserts so we can screw the PCB down. (Pro tip: Use the `Equal` constraint to make all the circles the same size!) Then make some rectangles around these circles, these will be the support posts.

![CAD-5](Images/CAD-5.webp)

2. Extrude these posts up to the bottom of the PCB (You can use the `Up to face` feature in the extrude tool to make this exact!), leaving the holes.

![CAD-6](Images/CAD-6.webp)

## Step 4: Top Plate

1. Make some holes on the top of the case for some heatset inserts, this is how the top-plate will mount.

![CAD-8](Images/CAD-8.webp)

2. Next make a quick sketch for your top-plate, make some 3.2mm holes for the screws to go through, and a rectangle cutout for the keyswitches, this should be offset at least 2mm from the keyswitches. Then just extrude that up by 3mm! Make sure you select `New` in your extrude tool. The top of the plate should be about the same height as the top of your keyswitch body.

![CAD-9](Images/CAD-9.webp)
![CAD-10](Images/CAD-10.webp)

## Step 5: Display, USB, and Buzzer Cutouts

1. Now all you have left is a few simple cutouts. Make a cutout for your display:

![CAD-13](Images/CAD-13.webp)

2. USB Port:

![CAD-15](Images/CAD-15.webp)

3. And some holes for your buzzer noise to escape:

![CAD-18](Images/CAD-18.webp)

## Step 6: Finishing Up

1. Now's when you should do any cosmetic changes, like adding some fillets, chamfers, text, whatever. You should also add some color! You can change the color of your parts by navigating to the parent part studio for them (The one you imported at the start), then right click on the part in the `Parts` tab on the left panel, then selecting `Edit appearance` and choosing whatever color you want. You then have to create a new version by selecting the `Create version` button on the left sidebar, it has a little blue plus on it. This will update the Assembly so it has your changes.

2. Now just export your design, right click on your Assembly tab, click `Export`, change the format to `STEP`, and export it with whatever name you want. Make sure you add this to your GitHub!