Skip to content

Commit

Permalink
Merge pull request #25 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Develop general updates
  • Loading branch information
shimwell authored Sep 8, 2022
2 parents b1cc4de + 3959e29 commit afcc8d4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions brep_part_finder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from .core import (
get_brep_part_properties,
get_brep_part_properties_from_shape,
get_part_id,
get_part_ids,
get_dict_of_part_ids,
Expand Down
28 changes: 20 additions & 8 deletions brep_part_finder/core.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import warnings
from collections.abc import Iterable
from typing import Tuple

from typing import Tuple, Union
from os import PathLike
import numpy as np
from cadquery import *
from cadquery.occ_impl.shapes import Shape


def get_brep_part_properties(filename: str):
"""Imports a Brep CAD file and returns the contents as a CadQuery Shape
object
def get_brep_part_properties_from_shape(shapes: Shape):
"""Accepts a cadquery.occ_impl.shapes object and returns the unique
identify details of each Solid
Args:
filename: the filename of the brep file
"""

brep_shapes = Shape.importBrep(filename)

my_brep_part_details = {}
for counter, part in enumerate(brep_shapes.Solids(), 1):
for counter, part in enumerate(shapes.Solids(), 1):
part_details = {}
part_details["Center.x"] = part.Center().x
part_details["Center.y"] = part.Center().y
Expand All @@ -38,6 +36,20 @@ def get_brep_part_properties(filename: str):
return my_brep_part_details


def get_brep_part_properties(filename: Union[str, PathLike]):
"""Imports a Brep CAD file and returns the unique identify details of each Solid
Args:
filename: the filename of the brep file
"""

shapes = Shape.importBrep(filename)

my_brep_part_details = get_brep_part_properties_from_shape(shapes)

return my_brep_part_details


def get_part_id(
brep_part_properties: dict,
volume: float = None,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_loading_from_file_vs_shape_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import brep_part_finder as bpf
from cadquery.occ_impl.shapes import Shape


def test_input_methods_get_same_results():

filename = "examples/ball_reactor.brep"
part_properties_from_file = bpf.get_brep_part_properties(filename)

shapes = Shape.importBrep(filename)
part_properties_from_shape = bpf.get_brep_part_properties_from_shape(shapes)

assert part_properties_from_shape == part_properties_from_file

0 comments on commit afcc8d4

Please sign in to comment.