Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Assembly Creation and Rendering #89

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nimble_build_system/cad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This directory holds CAD files that are used to generate Nimble racks.

Standard dimension names are needed to ensure proper orientation of the shelf, hardware and rack models, and the diagram below outlines the system employed for the Nimble rack and shelf CAD. When creating new CAD models, or adding data for existing hardware to the database, please follow these conventions.

![Nimble Dimension Naming Diagram](./images/nimble_dimension_name_diagram.png)
![Nimble Dimension Naming Diagram](../../assets/img/nimble_dimension_name_diagram.png)
51 changes: 31 additions & 20 deletions nimble_build_system/cad/shelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,19 @@
from nimble_build_system.orchestration.device import Device
from nimble_build_system.orchestration.paths import REL_MECH_DIR

#TODO: I think here we need a function that picks the class we use?
#
# For example something like `create_shelf_for(device)` which then
# uses the variants list to choose which self class?

class Shelf():
"""
Base shelf class that can be interrogated to get all of the renders and docs.
"""

variants = {
"generic": "A generic cable tie shelf",
"stuff": "A shelf for general stuff such as wires. No access to the front",
"stuff-thin": "A thin version of the stuff shelf",
"nuc": "A shelf for an Intel NUC",
"usw-flex": "A shelf for a Ubiquiti USW-Flex",
"usw-flex-mini": "A shelf for a Ubiquiti Flex Mini",
"anker-powerport5": "A shelf for an Anker PowerPort 5",
"anker-a2123": "A shelf for an Anker 360 Charger 60W (a2123)",
"anker-atom3slim": "A shelf for an Anker PowerPort Atom III Slim (AK-194644090180)",
"hdd35": "A shelf for an 3.5\" HDD",
"dual-ssd": "A shelf for 2x 2.5\" SSD",
"raspi": "A shelf for a Raspberry Pi",
}
_variant = None
_device = None
_device_model = None
_assembled_shelf = None
_unit_width = 6 # 6 or 10 inch rack

def __init__(self,
device: Device,
device_id: str,
assembly_key: str,
position: tuple[float],
color: str):
Expand Down Expand Up @@ -278,3 +259,33 @@ def generate_assembly_model(self,
assy.add(device_model, name="device", color=cq.Color(0.565, 0.698, 0.278, 1.0))

return assy


# Allows information to be tracked about the different types of shelves, including
# the class that should be used to generate the shelf.
variants = {
"generic": "A generic cable tie shelf",
"stuff": "A shelf for general stuff such as wires. No access to the front",
"stuff-thin": "A thin version of the stuff shelf",
"nuc": "A shelf for an Intel NUC",
"usw-flex": "A shelf for a Ubiquiti USW-Flex",
"usw-flex-mini": "A shelf for a Ubiquiti Flex Mini",
"anker-powerport5": "A shelf for an Anker PowerPort 5",
"anker-a2123": "A shelf for an Anker 360 Charger 60W (a2123)",
"anker-atom3slim": "A shelf for an Anker PowerPort Atom III Slim (AK-194644090180)",
"hdd35": "A shelf for an 3.5\" HDD",
"dual-ssd": "A shelf for 2x 2.5\" SSD",
"raspi": { "description": "A shelf for a Raspberry Pi", "class": RaspberryPiShelf },
}


def create_shelf_for_device(device_id: str, assembly_key: str, position: tuple[float], color: str):
"""
Create a shelf for a given device.
"""

# Check to make sure that the variant exists
if device_id not in variants or device_id == "generic":
return Shelf(device_id, assembly_key=assembly_key, position=position, color=color)
else:
return variants[device_id]["class"](device_id, assembly_key=assembly_key, position=position, color=color)
4 changes: 2 additions & 2 deletions nimble_build_system/orchestration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Assembly)

from nimble_build_system.cad import RackParameters
from nimble_build_system.cad.shelf import Shelf
from nimble_build_system.cad.shelf import create_shelf_for_device
from nimble_build_system.orchestration.device import Device
from nimble_build_system.orchestration.paths import MODULE_PATH, REL_MECH_DIR

Expand Down Expand Up @@ -294,7 +294,7 @@ def _generate_shelf_list(self):
y_pos = -self._rack_params.rack_width / 2.0
z_pos = z_offset + height_in_u * self._rack_params.mounting_hole_spacing
color = 'dodgerblue1' if i%2 == 0 else 'deepskyblue1'
shelf = Shelf(device=device,
shelf = create_shelf_for_device(device_id=device.shelf_id,
assembly_key=f"shelf_{i}",
position=(x_pos, y_pos, z_pos),
color=color)
Expand Down
9 changes: 2 additions & 7 deletions tests/test_cad.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from nimble_build_system.cad.shelf import Shelf, RaspberryPiShelf
from nimble_build_system.cad.shelf import create_shelf_for_device
from nimble_build_system.orchestration.configuration import NimbleConfiguration

def test_generating_raspberry_pi_shelf():
Expand All @@ -16,10 +16,5 @@ def test_generating_raspberry_pi_shelf():

# Make sure that each shelf can generate the proper files
for i, shelf in enumerate(config.shelves):
# Find the matching device for the shelf
device = config.devices[i]

# Generate the right type of shelf based on the name
if "raspberry" in shelf.name.lower():
shelf = RaspberryPiShelf(shelf, device)
assert shelf.name == "Raspberry Pi 4B shelf"
create_shelf_for_device(shelf.device.shelf_id, assembly_key=shelf.assembled_shelf.key, position=shelf.assembled_shelf.data["position"], color=shelf.assembled_shelf.data["color"])
Loading