Skip to content

Commit cca1f77

Browse files
committed
convert to solid by default
1 parent 8c94783 commit cca1f77

File tree

2 files changed

+56
-44
lines changed

2 files changed

+56
-44
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
* Changed `compas_occ.brep.OCCBrep.from_boolean_difference` to also accept a list of `A` shapes.
2626
* Changed `compas_occ.brep.OCCBrep.from_boolean_intersection` to also accept lists of shapes for `A` and `B`.
2727
* Changed `compas_occ.brep.OCCBrep.from_boolean_union` to also accept lists of shapes for `A` and `B`.
28+
* Changed `compas_occ.brep.OCCBrep.from_step` to convert shells to solid if possible by default.
29+
* Changed `compas_occ.brep.OCCBrep.from_iges` to convert shells to solid if possible by default.
2830

2931
### Removed
3032

src/compas_occ/brep/brep.py

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,16 @@ def convex_hull(self) -> Mesh:
383383
# ==============================================================================
384384

385385
@classmethod
386-
def from_step(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
386+
def from_step(cls, filename: Union[str, pathlib.Path], solid: bool = True) -> "OCCBrep":
387387
"""
388388
Conctruct a BRep from the data contained in a STEP file.
389389
390390
Parameters
391391
----------
392392
filename : str | pathlib.Path
393+
The file.
394+
solid : bool, optional
395+
If True, convert shells to solids when possible.
393396
394397
Returns
395398
-------
@@ -399,16 +402,21 @@ def from_step(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
399402
shape = DataExchange.read_step_file(str(filename))
400403
brep = cls.from_native(shape) # type: ignore
401404
brep.heal()
405+
if solid:
406+
brep.make_solid()
402407
return brep
403408

404409
@classmethod
405-
def from_iges(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
410+
def from_iges(cls, filename: Union[str, pathlib.Path], solid: bool = True) -> "OCCBrep":
406411
"""
407412
Conctruct a BRep from the data contained in a IGES file.
408413
409414
Parameters
410415
----------
411416
filename : str | pathlib.Path
417+
The file.
418+
solid : bool, optional
419+
If True, convert shells to solids when possible.
412420
413421
Returns
414422
-------
@@ -418,6 +426,8 @@ def from_iges(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
418426
shape = DataExchange.read_iges_file(str(filename))
419427
brep = cls.from_native(shape) # type: ignore
420428
brep.heal()
429+
if solid:
430+
brep.make_solid()
421431
return brep
422432

423433
def to_step(self, filepath: Union[str, pathlib.Path], schema: str = "AP203", unit: str = "MM") -> None:
@@ -1762,44 +1772,6 @@ def simplify(
17621772
shape = simplifier.Shape()
17631773
self.native_brep = shape
17641774

1765-
def transform(self, matrix: compas.geometry.Transformation) -> None:
1766-
"""
1767-
Transform this Brep.
1768-
1769-
Parameters
1770-
----------
1771-
matrix : :class:`compas.geometry.Transformation`
1772-
A transformation matrix.
1773-
1774-
Returns
1775-
-------
1776-
None
1777-
1778-
"""
1779-
trsf = compas_transformation_to_trsf(matrix)
1780-
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
1781-
shape = builder.ModifiedShape(self.occ_shape)
1782-
self._occ_shape = shape
1783-
1784-
def transformed(self, matrix: compas.geometry.Transformation) -> "OCCBrep":
1785-
"""
1786-
Return a transformed copy of the Brep.
1787-
1788-
Parameters
1789-
----------
1790-
matrix : :class:`compas.geometry.Transformation`
1791-
A transformation matrix.
1792-
1793-
Returns
1794-
-------
1795-
:class:`OCCBrep`
1796-
1797-
"""
1798-
trsf = compas_transformation_to_trsf(matrix)
1799-
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
1800-
shape = builder.ModifiedShape(self.occ_shape)
1801-
return OCCBrep.from_shape(shape)
1802-
18031775
def slice(self, plane: compas.geometry.Plane) -> Union["OCCBrep", None]:
18041776
"""Slice a BRep with a plane.
18051777
@@ -1842,15 +1814,53 @@ def split(self, other: "OCCBrep") -> list["OCCBrep"]:
18421814
splitter.AddTool(other.occ_shape)
18431815
splitter.Perform()
18441816
shape = splitter.Shape()
1845-
results = []
1817+
results: list[OCCBrep] = []
18461818
if isinstance(shape, TopoDS.TopoDS_Compound):
18471819
it = TopoDS.TopoDS_Iterator(shape)
18481820
while it.More():
1849-
results.append(it.Value())
1821+
results.append(OCCBrep.from_shape(it.Value()))
18501822
it.Next()
18511823
else:
1852-
results.append(shape)
1853-
return [OCCBrep.from_shape(result) for result in results]
1824+
results.append(OCCBrep.from_shape(shape))
1825+
return results
1826+
1827+
def transform(self, matrix: compas.geometry.Transformation) -> None:
1828+
"""
1829+
Transform this Brep.
1830+
1831+
Parameters
1832+
----------
1833+
matrix : :class:`compas.geometry.Transformation`
1834+
A transformation matrix.
1835+
1836+
Returns
1837+
-------
1838+
None
1839+
1840+
"""
1841+
trsf = compas_transformation_to_trsf(matrix)
1842+
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
1843+
shape = builder.ModifiedShape(self.occ_shape)
1844+
self._occ_shape = shape
1845+
1846+
def transformed(self, matrix: compas.geometry.Transformation) -> "OCCBrep":
1847+
"""
1848+
Return a transformed copy of the Brep.
1849+
1850+
Parameters
1851+
----------
1852+
matrix : :class:`compas.geometry.Transformation`
1853+
A transformation matrix.
1854+
1855+
Returns
1856+
-------
1857+
:class:`OCCBrep`
1858+
1859+
"""
1860+
trsf = compas_transformation_to_trsf(matrix)
1861+
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
1862+
shape = builder.ModifiedShape(self.occ_shape)
1863+
return OCCBrep.from_shape(shape)
18541864

18551865
def trim(self, plane: compas.geometry.Plane) -> None:
18561866
"""Trim a Brep with a plane.

0 commit comments

Comments
 (0)