Skip to content

Commit

Permalink
Add shared abstraction for STEP assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Sep 3, 2023
1 parent 52a6e61 commit 891aadf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
run: mypy --strict
common.py
entities/*.py
cadquery_helpers.py
dfn_configs.py
generate*.py
test_entities.py
Expand Down
26 changes: 26 additions & 0 deletions cadquery_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import cadquery as cq
from OCP.Message import Message, Message_Gravity # type: ignore


class StepAssembly:
"""
A STEP assembly.
"""
def __init__(self, name: str):
self.assembly = cq.Assembly(name=name)

# Less verbose output
for printer in Message.DefaultMessenger_s().Printers():
printer.SetTraceLevel(Message_Gravity.Message_Fail)

def add_body(self, body: cq.Workplane, name: str, color: cq.Color):
"""
Add a body to the assembly.
"""
self.assembly.add(body, name=name, color=color)

def save(self, path: str):
"""
Write the STEP file to the specified path.
"""
self.assembly.save(path, 'STEP', mode='fused', write_pcurves=False)
16 changes: 6 additions & 10 deletions generate_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ def generate_3d(
config: ChipConfig,
) -> None:
import cadquery as cq
from cadquery_helpers import StepAssembly

print(f'Generating pkg 3D model "{full_name}": {uuid_3d}')

Expand Down Expand Up @@ -633,22 +634,17 @@ def generate_3d(
.translate(translation) \
.translate((edge_offset + edge / 2, 0, 0))

assembly = cq.Assembly(name=full_name) \
.add(inner, name="inner", color=cq.Color("gray16")) \
.add(left, name="left", color=cq.Color("gainsboro")) \
.add(right, name="right", color=cq.Color("gainsboro"))
assembly = StepAssembly(full_name)
assembly.add_body(inner, 'inner', cq.Color("gray16"))
assembly.add_body(left, 'left', cq.Color("gainsboro"))
assembly.add_body(right, 'right', cq.Color("gainsboro"))

dir_path = path.join('out', library, 'pkg', uuid_pkg)
if not (path.exists(dir_path) and path.isdir(dir_path)):
makedirs(dir_path)
filename = f'{uuid_3d}.step'

# Less verbose output
from OCP.Message import Message, Message_Gravity # type: ignore
for printer in Message.DefaultMessenger_s().Printers():
printer.SetTraceLevel(Message_Gravity.Message_Fail)

assembly.save(path.join(dir_path, filename), 'STEP', mode='fused', write_pcurves=False)
assembly.save(path.join(dir_path, filename))


def generate_dev(
Expand Down

0 comments on commit 891aadf

Please sign in to comment.