Skip to content

Commit

Permalink
convert to solid by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Jan 15, 2025
1 parent 8c94783 commit cca1f77
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 44 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed `compas_occ.brep.OCCBrep.from_boolean_difference` to also accept a list of `A` shapes.
* Changed `compas_occ.brep.OCCBrep.from_boolean_intersection` to also accept lists of shapes for `A` and `B`.
* Changed `compas_occ.brep.OCCBrep.from_boolean_union` to also accept lists of shapes for `A` and `B`.
* Changed `compas_occ.brep.OCCBrep.from_step` to convert shells to solid if possible by default.
* Changed `compas_occ.brep.OCCBrep.from_iges` to convert shells to solid if possible by default.

### Removed

Expand Down
98 changes: 54 additions & 44 deletions src/compas_occ/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,16 @@ def convex_hull(self) -> Mesh:
# ==============================================================================

@classmethod
def from_step(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
def from_step(cls, filename: Union[str, pathlib.Path], solid: bool = True) -> "OCCBrep":
"""
Conctruct a BRep from the data contained in a STEP file.
Parameters
----------
filename : str | pathlib.Path
The file.
solid : bool, optional
If True, convert shells to solids when possible.
Returns
-------
Expand All @@ -399,16 +402,21 @@ def from_step(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
shape = DataExchange.read_step_file(str(filename))
brep = cls.from_native(shape) # type: ignore
brep.heal()
if solid:
brep.make_solid()
return brep

@classmethod
def from_iges(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
def from_iges(cls, filename: Union[str, pathlib.Path], solid: bool = True) -> "OCCBrep":
"""
Conctruct a BRep from the data contained in a IGES file.
Parameters
----------
filename : str | pathlib.Path
The file.
solid : bool, optional
If True, convert shells to solids when possible.
Returns
-------
Expand All @@ -418,6 +426,8 @@ def from_iges(cls, filename: Union[str, pathlib.Path]) -> "OCCBrep":
shape = DataExchange.read_iges_file(str(filename))
brep = cls.from_native(shape) # type: ignore
brep.heal()
if solid:
brep.make_solid()
return brep

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

def transform(self, matrix: compas.geometry.Transformation) -> None:
"""
Transform this Brep.
Parameters
----------
matrix : :class:`compas.geometry.Transformation`
A transformation matrix.
Returns
-------
None
"""
trsf = compas_transformation_to_trsf(matrix)
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
shape = builder.ModifiedShape(self.occ_shape)
self._occ_shape = shape

def transformed(self, matrix: compas.geometry.Transformation) -> "OCCBrep":
"""
Return a transformed copy of the Brep.
Parameters
----------
matrix : :class:`compas.geometry.Transformation`
A transformation matrix.
Returns
-------
:class:`OCCBrep`
"""
trsf = compas_transformation_to_trsf(matrix)
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
shape = builder.ModifiedShape(self.occ_shape)
return OCCBrep.from_shape(shape)

def slice(self, plane: compas.geometry.Plane) -> Union["OCCBrep", None]:
"""Slice a BRep with a plane.
Expand Down Expand Up @@ -1842,15 +1814,53 @@ def split(self, other: "OCCBrep") -> list["OCCBrep"]:
splitter.AddTool(other.occ_shape)
splitter.Perform()
shape = splitter.Shape()
results = []
results: list[OCCBrep] = []
if isinstance(shape, TopoDS.TopoDS_Compound):
it = TopoDS.TopoDS_Iterator(shape)
while it.More():
results.append(it.Value())
results.append(OCCBrep.from_shape(it.Value()))
it.Next()
else:
results.append(shape)
return [OCCBrep.from_shape(result) for result in results]
results.append(OCCBrep.from_shape(shape))
return results

def transform(self, matrix: compas.geometry.Transformation) -> None:
"""
Transform this Brep.
Parameters
----------
matrix : :class:`compas.geometry.Transformation`
A transformation matrix.
Returns
-------
None
"""
trsf = compas_transformation_to_trsf(matrix)
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
shape = builder.ModifiedShape(self.occ_shape)
self._occ_shape = shape

def transformed(self, matrix: compas.geometry.Transformation) -> "OCCBrep":
"""
Return a transformed copy of the Brep.
Parameters
----------
matrix : :class:`compas.geometry.Transformation`
A transformation matrix.
Returns
-------
:class:`OCCBrep`
"""
trsf = compas_transformation_to_trsf(matrix)
builder = BRepBuilderAPI.BRepBuilderAPI_Transform(self.occ_shape, trsf, True)
shape = builder.ModifiedShape(self.occ_shape)
return OCCBrep.from_shape(shape)

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

0 comments on commit cca1f77

Please sign in to comment.