Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revived Trimming Feature component #228

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 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 All @@ -20,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `BrepGeometryConsumer` continues to apply features even after the first error.
* `DrillHole` component calculates length from input line.
* `DrillHole` has default diameter proportional to beam cross-section.
* Fixed broken `TrimmingFeature` component.

### Removed

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
24 changes: 9 additions & 15 deletions src/compas_timber/ghpython/components/CT_Feature_Trim/code.py
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 BeamTrimmingFeature
from compas_timber.parts import CutFeature


class TrimmingFeature(component):
def RunScript(self, Beam, Plane):
if not Beam:
def RunScript(self, beam, plane):
if not beam:
self.AddRuntimeMessage(Warning, "Input parameter Beam failed to collect data")
if not Plane:
if not plane:
self.AddRuntimeMessage(Warning, "Input parameter Plane failed to collect data")
if not (Beam and Plane):
if not (beam and plane):
return

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

Feature = []
for plane in Plane:
feature = BeamTrimmingFeature(plane_to_compas_frame(plane))
Feature.append(FeatureDefinition(feature, Beam))

return Feature
feature = CutFeature(plane_to_compas_frame(plane))
return FeatureDefinition(feature, beam)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"name": "Plane",
"description": "Cutting plane(s).",
"typeHintID": "plane",
"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
Loading