Skip to content

Commit

Permalink
Merge pull request #116 from LibrePCB/so-3d
Browse files Browse the repository at this point in the history
so: Rework footprints & generate 3D models
  • Loading branch information
ubruhin authored Sep 24, 2023
2 parents 6d3afec + 4e983dd commit 5da0bba
Show file tree
Hide file tree
Showing 5 changed files with 2,822 additions and 947 deletions.
25 changes: 21 additions & 4 deletions cadquery_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from os import makedirs, path

from typing import Optional

import cadquery as cq
from OCP.Message import Message, Message_Gravity # type: ignore

Expand All @@ -9,6 +11,8 @@ class StepConstants:


class StepColor:
IC_BODY = cq.Color('gray16')
IC_PIN1_DOT = cq.Color('gray55')
LEAD_SMT = cq.Color('gainsboro')
LEAD_THT = cq.Color('gainsboro')

Expand All @@ -24,20 +28,33 @@ def __init__(self, name: str):
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) -> None:
def add_body(self, body: cq.Workplane, name: str, color: cq.Color,
location: Optional[cq.Location] = None) -> None:
"""
Add a body to the assembly.
Important: If the same body is added multiple times to the assembly
with different transformations, please use the `location` parameter
instead of transforming each body! This leads to much more efficient
STEP minification.
"""
self.assembly.add(body, name=name, color=color)
self.assembly.add(body, name=name, color=color, loc=location)

def save(self, out_path: str) -> None:
def save(self, out_path: str, fused: bool) -> None:
"""
Write the STEP file to the specified path.
Important: For simple bodies with (almost) no repetition (like
resistors, capacitors, ...), pass `fused=True` to get a simple,
non-hierarchical STEP file. However, for models with repetition (like
an IC with several pins), pass `fused=False` since this leads to much
more efficient STEP minification (saves several 100MB in total!).
"""
dir_path = path.dirname(out_path)
if path.exists(dir_path) and not path.isdir(dir_path):
raise RuntimeError(f'Path "{dir_path}" exists but is not a directory')
if not path.exists(dir_path):
makedirs(dir_path)

self.assembly.save(out_path, 'STEP', mode='fused', write_pcurves=False)
mode = 'fused' if fused else 'default' # type: cq.occ_impl.exporters.assembly.STEPExportModeLiterals
self.assembly.save(out_path, 'STEP', mode=mode, write_pcurves=False)
2 changes: 1 addition & 1 deletion generate_axial_tht.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def generate_3d(
assembly.add_body(leg, 'leg', StepColor.LEAD_THT)

out_path = path.join('out', library, 'pkg', uuid_pkg, f'{uuid_3d}.step')
assembly.save(out_path)
assembly.save(out_path, fused=True)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion generate_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def generate_3d(
assembly.add_body(right, 'right', StepColor.LEAD_SMT)

out_path = path.join('out', library, 'pkg', uuid_pkg, f'{uuid_3d}.step')
assembly.save(out_path)
assembly.save(out_path, fused=True)


def generate_dev(
Expand Down
Loading

0 comments on commit 5da0bba

Please sign in to comment.