Skip to content

Commit

Permalink
added boolean subtraction feature
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Feb 14, 2024
1 parent 3aadcf0 commit f718fb6
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* (Re)added `BooleanSubtraction` feature.

### Changed

* `BeamFromCurve` GH component accepts now referenced Rhino curves, referenced Rhino object IDs and internalized lines.
Expand Down
Binary file modified examples/Grasshopper/CT_NEW_UI_Example.3dm
Binary file not shown.
Binary file modified examples/Grasshopper/CT_NEW_UI_Example.gh
Binary file not shown.
49 changes: 48 additions & 1 deletion src/compas_timber/consumers/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from compas_timber.parts import CutFeature
from compas_timber.parts import DrillFeature
from compas_timber.parts import MillVolume
from compas_timber.parts import BrepSubtraction


class FeatureApplicationError(Exception):
Expand Down Expand Up @@ -173,6 +174,47 @@ def apply(self):
)


class BrepSubtractionGeometry(FeatureApplicator):
"""Applies BrepSubtraction to beam geometry.
Parameters
----------
beam_geometry : :class:`compas.geometry.Brep`
The geometry of the beam.
feature : :class:`compas_timber.parts.BrepSubtraction`
The feature to apply.
"""

def __init__(self, beam_geometry, feature):
super(BrepSubtractionGeometry, self).__init__()
self.volume = feature.volume
self.beam_geometry = beam_geometry

def apply(self):
"""Apply the feature to the beam geometry.
Raises
------
:class:`compas_timber.consumers.FeatureApplicationError`
If the volume does not intersect with the beam geometry.
Returns
-------
:class:`compas.geometry.Brep`
The resulting geometry after processing.
"""
try:
return self.beam_geometry - self.volume
except IndexError:
raise FeatureApplicationError(
self.volume,
self.beam_geometry,
"The volume does not intersect with beam geometry.",
)


class BeamGeometry(object):
"""A data class containing the result of applying features to a beam.
Expand Down Expand Up @@ -210,7 +252,12 @@ class BrepGeometryConsumer(object):
"""

FEATURE_MAP = {CutFeature: CutFeatureGeometry, DrillFeature: DrillFeatureGeometry, MillVolume: MillVolumeGeometry}
FEATURE_MAP = {
CutFeature: CutFeatureGeometry,
DrillFeature: DrillFeatureGeometry,
MillVolume: MillVolumeGeometry,
BrepSubtraction: BrepSubtractionGeometry,
}

def __init__(self, assembly):
self.assembly = assembly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning

from compas_timber.ghpython import FeatureDefinition
from compas_timber.parts import BeamBooleanSubtraction
from compas_timber.parts import BrepSubtraction


class BrepSubtractionFeature(component):
def RunScript(self, Beam, Geometry):
if not Beam:
def RunScript(self, beam, geometry):
if not beam:
self.AddRuntimeMessage(Warning, "Input parameter Beams failed to collect data")
if not Geometry:
if not geometry:
self.AddRuntimeMessage(Warning, "Input parameter Geometry failed to collect data")
if not (Beam and Geometry):
if not (beam and geometry):
return

if not isinstance(Beam, list):
Beam = [Beam]
if not isinstance(Geometry, list):
Geometry = [Geometry]
if not isinstance(beam, list):
beam = [beam]

Feature = []
for brep in Geometry:
feature = BeamBooleanSubtraction(Brep.from_native(brep))
Feature.append(FeatureDefinition(feature, Beam))

return Feature
feature = BrepSubtraction(Brep.from_native(geometry))
return FeatureDefinition(feature, beam)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"name": "Geometry",
"description": "Brep Geometry to subtract form Beam(s) (one or more).",
"typeHintID": "brep",
"scriptParamAccess": 1
"scriptParamAccess": 0
}
],
"outputParameters": [
Expand Down
2 changes: 2 additions & 0 deletions src/compas_timber/parts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from .features import CutFeature
from .features import DrillFeature
from .features import MillVolume
from .features import BrepSubtraction

__all__ = [
"Beam",
"CutFeature",
"DrillFeature",
"MillVolume",
"BrepSubtraction",
]
21 changes: 21 additions & 0 deletions src/compas_timber/parts/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,24 @@ def __data__(self):
data_dict = {"volume": self.volume}
data_dict.update(super(MillVolume, self).__data__)
return data_dict


class BrepSubtraction(Feature):
"""Generic volume subtraction from a beam.
Parameters
----------
volume : :class:`compas.geometry.Brep`
The volume to be subtracted from the beam.
"""

def __init__(self, volume, **kwargs):
super(BrepSubtraction, self).__init__(**kwargs)
self.volume = volume

@property
def __data__(self):
data_dict = {"volume": self.volume}
data_dict.update(super(BrepSubtraction, self).__data__)
return data_dict

0 comments on commit f718fb6

Please sign in to comment.