-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fasteners class per suggestions
- Loading branch information
Showing
4 changed files
with
249 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
""" | ||
Holds fastener classes containing the information needed to generate CAD models of fasteners. | ||
""" | ||
|
||
class Fastener: | ||
""" | ||
Class that defines a generic fastener that can be used in the assembly of a device and/or rack. | ||
""" | ||
_name = None | ||
_position = (0.0, 0.0, 0.0) | ||
_explode_translation = (0.0, 0.0, 0.0) | ||
_size = "M3-0.5" | ||
_fastener_type = "iso7380_1" | ||
_direction_axis = "-Z" | ||
|
||
def __init__(self, name, position, explode_translation, size, fastener_type, direction_axis): | ||
""" | ||
Generic fastener constructor that sets common attributes for all faster types. | ||
""" | ||
self._name = name | ||
self._position = position | ||
self._explode_translation = explode_translation | ||
self._size = size | ||
self._fastener_type = fastener_type | ||
self._direction_axis = direction_axis | ||
|
||
@property | ||
def name(self): | ||
""" | ||
Getter for the name of the fastener. | ||
""" | ||
return self._name | ||
|
||
@name.setter | ||
def name(self, name): | ||
""" | ||
Setter for the name of the fastener. | ||
""" | ||
self._name = name | ||
|
||
@property | ||
def position(self): | ||
""" | ||
Getter for the position of the fastener. | ||
""" | ||
return self._position | ||
|
||
@property | ||
def explode_translation(self): | ||
""" | ||
Getter for the explosion translation of the fastener. | ||
""" | ||
return self._explode_translation | ||
|
||
@property | ||
def size(self): | ||
""" | ||
Getter for the size of the fastener. | ||
""" | ||
return self._size | ||
|
||
@property | ||
def fastener_type(self): | ||
""" | ||
Getter for the fastener_type of the fastener. | ||
""" | ||
return self._fastener_type | ||
|
||
@property | ||
def direction_axis(self): | ||
""" | ||
Getter for the direction axis of the fastener. | ||
""" | ||
return self._direction_axis | ||
|
||
|
||
class Screw(Fastener): | ||
""" | ||
Specific type of fastener that adds screw-specific parameters like length. | ||
""" | ||
_length = 6 # mm | ||
|
||
def __init__(self, name, position, explode_translation, size, fastener_type, axis, length): | ||
""" | ||
Screw constructor that additionally sets the length of the screw. | ||
""" | ||
# pylint: disable=too-many-arguments | ||
|
||
self._length = length | ||
|
||
super().__init__(name, position, explode_translation, size, fastener_type, axis) | ||
|
||
@property | ||
def length(self): | ||
""" | ||
Getter for the length of the screw. | ||
""" | ||
return self._length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import tempfile | ||
import os | ||
import pytest | ||
import cadquery as cq | ||
from nimble_build_system.cad.shelf import RaspberryPiShelf | ||
from nimble_build_system.orchestration.configuration import NimbleConfiguration | ||
|
||
|
||
def test_model_png_rendering(): | ||
""" | ||
Tests whether or not a PNG image can be output for a single part. | ||
""" | ||
|
||
# The configuration of hardware/shelves that we want to test against | ||
test_config = ["Raspberry_Pi_4B"] | ||
|
||
# Load the needed information to generate a Shelf object | ||
config = NimbleConfiguration(test_config) | ||
|
||
# Get the only shelf that we should have to deal with | ||
rpi_shelf = config.shelves[0] | ||
|
||
# Test the generated CAD assembly | ||
shelf = rpi_shelf.generate_shelf_model().cq() | ||
|
||
# Get the render of the shelf | ||
rpi_shelf.get_render(shelf, (0, 0, 0)) | ||
|
||
# temp_dir = tempfile.gettempdir() | ||
|
||
# Export the model to a PNG image | ||
# cq.exporters.export(shelf, os.path.join(temp_dir, "test_model.png")) | ||
|
||
# Check to make sure that the image was created | ||
# assert os.path.exists(os.path.join(temp_dir, "test_model.png")) | ||
assert True | ||
|
||
|
||
def test_assembly_png_rendering(): | ||
""" | ||
Tests whether or not a PNG image can be output for an entire assembly. | ||
""" | ||
|
||
# The configuration of hardware/shelves that we want to test against | ||
test_config = ["Raspberry_Pi_4B"] | ||
|
||
# Load the needed information to generate a Shelf object | ||
config = NimbleConfiguration(test_config) | ||
|
||
# Get the only shelf that we should have to deal with | ||
rpi_shelf = config.shelves[0] | ||
|
||
# Test the generated CAD assembly | ||
shelf_assy = rpi_shelf.generate_assembly_model() | ||
|
||
rpi_shelf.get_render(shelf_assy, (0, 0, 0)) | ||
|
||
# temp_dir = tempfile.gettempdir() | ||
|
||
# Export the model to a PNG image | ||
# cq.exporters.export(shelf_assy, os.path.join(temp_dir, "test_model.png")) | ||
|
||
assert True | ||
|
||
|
||
def test_annotated_assembly_png_rendering(): | ||
""" | ||
Tests whether or not a PNG image can be output for an entire assembly with | ||
annotations (i.e. assembly lines). | ||
""" | ||
assert True |