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

FreeContour BTLxProcessing #382

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

FreeContour BTLxProcessing #382

wants to merge 19 commits into from

Conversation

obucklin
Copy link
Contributor

@obucklin obucklin commented Jan 30, 2025

This adds the FreeContour BTLx Processing and updates the Plate element to function as a BTLx Part. The Plate.geometry is now created with FreeContour (and other) processings. The SurfaceModel and SurfaecModel.Window have been updated to generate FreeContour features and output BTLx files with all elements.

image
image
image
image
image

What type of change is this?

  • Bug fix in a backwards-compatible manner.
  • New feature in a backwards-compatible manner.
  • Breaking change: bug fix or new feature that involve incompatible API changes.
  • Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas_timber.datastructures.Beam.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

@obucklin obucklin marked this pull request as ready for review January 31, 2025 13:52
@obucklin obucklin linked an issue Jan 31, 2025 that may be closed by this pull request
Copy link
Contributor

@chenkasirer chenkasirer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments.
if @papachap can have a look it would be great

src/compas_timber/fabrication/btlx.py Outdated Show resolved Hide resolved
src/compas_timber/fabrication/btlx.py Show resolved Hide resolved
src/compas_timber/fabrication/free_contour.py Show resolved Hide resolved
src/compas_timber/fabrication/btlx.py Show resolved Hide resolved
# create subprocessing elements
if self.subprocessings:
for subprocessing in self.subprocessings:
processing_element.append(self._create_processing(subprocessing))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as BTLxWriter_create_processing() gets removed, recursively call create_processing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@papachap can you confirm that this works as currently written? is there a processing we could test this on?

CHANGELOG.md Show resolved Hide resolved
@obucklin obucklin mentioned this pull request Feb 6, 2025
10 tasks
@obucklin
Copy link
Contributor Author

obucklin commented Feb 6, 2025

I responded to @chenkasirer s comments. Will wait for @papachap :-)

@@ -155,8 +155,8 @@ def _create_project_element(self, model):
# create parts element
parts_element = ET.SubElement(project_element, "Parts")
# create part elements for each beam
for i, beam in enumerate(model.beams): # TODO: we need to add at least Plates to this too.
part_element = self._create_part(beam, i)
for i, element in enumerate(list(model.beams) + list(model.plates)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe update the _create_part() method as well to accept an element instead of a beam and adjust the docstring.

processings : list
A list of the processings applied to the beam.
et_element : :class:`~xml.etree.ElementTree.Element`
The ET element of the BTLx part.

"""

def __init__(self, beam, order_num):
self.beam = beam
def __init__(self, element, order_num):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the docstring accordingly.

)
# create parameter subelements
for key, value in self.params_dict.items():
print(key, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove print

@@ -177,7 +193,7 @@ def compute_aabb(self, inflate=0.0):
box.zsize += inflate
return box

def compute_obb(self, inflate=0.0):
def compute_obb(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update docstring

@property
def blank_length(self):
return self._blank.xsize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the docstring here as well

@@ -62,6 +63,10 @@ def __init__(self, outline, thickness, vector=None, frame=None, **kwargs):
self.attributes = {}
self.attributes.update(kwargs)
self.debug_info = []
self._ref_frame = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it redundant to have both a vector and frame argument?

Comment on lines +68 to +69
contour_feature = FreeContour.from_polyline_and_element(self.outline.points, self, interior=False)
self.add_feature(contour_feature)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to add a contour feature by default? maybe consider making this optional if not always needed.

Copy link
Contributor

@papachap papachap Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels there are a lot of hiddent dependencies in this code where properties are set implicitly. For example, the blank property is set when the compute_obb() method is called, which happens when ref_frame is accessed, and ref_frame is triggered when the FreeContour processing is instantiated.

All this creates an extensive chain of implicit side effects that we need to reduce by explicitly setting some of these properties.

Comment on lines +165 to +169
for feature in self.features:
try:
plate_geo = feature.apply(plate_geo, self)
except FeatureApplicationError as error:
self.debug_info.append(error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you want to completely remove the posibility of computing the geometry without the features (which in this case you should remove the include_features argument), add an additional if statement for that.

Comment on lines +82 to +84
@property
def params_dict(self):
return FreeCountourParams(self).as_dict()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the use of this property anymore since the create_processing() doesn't access it and instead it directly creates the XML elements for the processing.

Comment on lines +157 to +182
def create_processing(self):
"""Creates a processing element. This method creates the subprocess elements and appends them to the processing element.
NOTE: moved to BTLxProcessing because some processings are significantly different and need to be overridden.

Parameters
----------
processing : :class:`~compas_timber.fabrication.btlx.BTLxProcessing`
The processing object.

Returns
-------
:class:`~xml.etree.ElementTree.Element`
The processing element.

"""
# create processing element
processing_element = ET.Element(
self.PROCESSING_NAME,
self.header_attributes,
)
contour_element = ET.SubElement(processing_element, "Contour", self.contour_attributes)
ET.SubElement(contour_element, "StartPoint", BTLxPart.et_point_vals(self.contour_points[0]))
for pt in self.contour_points[1:]:
point_element = ET.SubElement(contour_element, "Line") # TODO: consider implementing arcs. maybe as tuple? (Point,Point)
point_element.append(ET.Element("EndPoint", BTLxPart.et_point_vals(pt)))
return processing_element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this is a completely different BTLx processing and requires a different approach. However, I'm not a huge fan of mixing XML generation with the core logic. This approach bypasses the parameters dictionary for this class. I wonder if we can refactor the FreeContourParams class to achieve what we need. Perhaps we could use a similar approach to the House BTLx processing, where we nest processings.

@papachap
Copy link
Contributor

@obucklin @chenkasirer I added some comments as well. If you want we can sit have a look at it together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BTLx contour processing for plates
3 participants