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

Feature priorities #244

Closed
wants to merge 3 commits into from
Closed
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,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added new `FeaturePriority` enumeration.
* Added attribute `priority` to `Feature`.

### Changed

### Removed
Expand Down
2 changes: 1 addition & 1 deletion src/compas_timber/consumers/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def result(self):

def _apply_features(self, geometry, features):
debug_info = []
for feature in features:
for feature in sorted(features, key=lambda f: f.PRIORITY):
cls = self.FEATURE_MAP.get(type(feature), None)
if not cls:
raise ValueError("No applicator found for feature type: {}".format(type(feature)))
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 @@ -3,11 +3,13 @@
from .features import DrillFeature
from .features import MillVolume
from .features import BrepSubtraction
from .features import FeaturePriority

__all__ = [
"Beam",
"CutFeature",
"DrillFeature",
"MillVolume",
"BrepSubtraction",
"FeaturePriority",
]
7 changes: 7 additions & 0 deletions src/compas_timber/parts/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def __init__(self, frame, length, width, height, **kwargs):
self.height = height
self.length = length
self.features = []
self.attributes = {}
self.attributes.update(kwargs)
self._blank_extensions = {}

@property
Expand All @@ -98,13 +100,18 @@ def __data__(self):
"width": self.width,
"height": self.height,
"length": self.length,
# joinery features are readded when deserializing via the assembly
"features": [feature for feature in self.features if not feature.is_joinery],
"attributes": self.attributes,
}
return data

@classmethod
def __from_data__(cls, data):
instance = cls(Frame.__from_data__(data["frame"]), data["length"], data["width"], data["height"])
instance.key = data["key"]
instance.features = data["features"]
instance.attributes.update(data.get("attributes", {}))
return instance

@property
Expand Down
11 changes: 10 additions & 1 deletion src/compas_timber/parts/features.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from compas.data import Data


class FeaturePriority(object):
EARLY = 0
LATER = 1


class Feature(Data):
"""

Expand All @@ -11,7 +16,9 @@ class Feature(Data):

"""

def __init__(self, name=None, is_joinery=False):
PRIORITY = FeaturePriority.EARLY

def __init__(self, name=None, is_joinery=True):
super(Feature, self).__init__(name)
self._is_joiney = is_joinery

Expand Down Expand Up @@ -59,6 +66,8 @@ class DrillFeature(Feature):

"""

PRIORITY = FeaturePriority.LATER

def __init__(self, line, diameter, length, **kwargs):
super(DrillFeature, self).__init__(**kwargs)
self.line = line
Expand Down
Loading