Skip to content

Commit

Permalink
added parameters class
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Jul 24, 2024
1 parent d01155c commit aec2795
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/compas_timber/_fabrication/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .btlx_process import BTLxProcess
from .btlx_process import OrientationType
from .jack_cut import JackRafterCut
from .jack_cut import JackRafterCutParams


__all__ = ["JackRafterCut", "BTLxProcess", "OrientationType"]
__all__ = ["JackRafterCut", "BTLxProcess", "OrientationType", "JackRafterCutParams"]
65 changes: 59 additions & 6 deletions src/compas_timber/_fabrication/btlx_process.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections import OrderedDict

from compas.data import Data


Expand All @@ -8,27 +10,78 @@ class BTLxProcess(Data):
----------
ref_side_index : int
The reference side, zero-based, index of the beam to be cut. 0-5 correspond to RS1-RS6.
priority : int
The priority of the process.
process_id : int
The process ID.
PROCESS_NAME : str
The name of the process.
"""

@property
def __data__(self):
return {"ref_side_index": self.ref_side_index}
return {"ref_side_index": self.ref_side_index, "priority": self.priority, "process_id": self.process_id}

def __init__(self, ref_side_index):
def __init__(self, ref_side_index, priority=0, process_id=0):
super(BTLxProcess, self).__init__()
self.ref_side_index = ref_side_index
self._priority = priority
self._process_id = process_id

@property
def priority(self):
return self._priority

@property
def process_id(self):
return self._process_id

@property
def PROCESS_NAME(self):
raise NotImplementedError("PROCESS_NAME must be implemented as class attribute in subclasses!")


class BTLxProcessParams(object):
"""Base class for BTLx process parameters. This creates the dictionary of key-value pairs for the process as expected by the BTLx file format.
Parameters
----------
instance : :class:`BTLxProcess`
The instance of the process to create parameters for.
"""

def __init__(self, instance):
self._instance = instance

def as_dict(self):
"""Returns the process parameters as a dictionary.
Returns
-------
dict
The process parameters as a dictionary.
"""
result = OrderedDict()
result["Name"] = self._instance.PROCESS_NAME
result["Process"] = "yes"
result["Priority"] = str(self._instance.priority)
result["ProcessID"] = str(self._instance.process_id)
result["ReferencePlaneID"] = str(self._instance.ref_side_index + 1)
return result


class OrientationType(object):
"""Enum for the orientation of the cut.
Attributes
----------
START : int
START : literal("start")
The start of the beam is cut away.
END : int
END : literal("end")
The end of the beam is cut away.
"""

START = 0
END = 1
START = "start"
END = "end"
40 changes: 40 additions & 0 deletions src/compas_timber/_fabrication/jack_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
from compas.geometry import distance_point_point
from compas.geometry import intersection_line_plane
from compas.geometry import is_point_behind_plane
from compas.tolerance import TOL

from compas_timber.elements import FeatureApplicationError

from .btlx_process import BTLxProcess
from .btlx_process import BTLxProcessParams
from .btlx_process import OrientationType


Expand All @@ -37,6 +39,8 @@ class JackRafterCut(BTLxProcess):
"""

PROCESS_NAME = "JackRafterCut" # type: ignore

@property
def __data__(self):
data = super(JackRafterCut, self).__data__
Expand Down Expand Up @@ -68,6 +72,10 @@ def __init__(self, orientation, start_x=0.0, start_y=0.0, start_depth=0.0, angle
# Properties
########################################################################

@property
def params_dict(self):
return JackRafterCutParams(self).as_dict()

@property
def orientation(self):
return self._orientation
Expand Down Expand Up @@ -272,3 +280,35 @@ def plane_from_params_and_beam(self, beam):
else:
plane_normal = -cutting_plane.xaxis
return Plane(cutting_plane.point, plane_normal)


class JackRafterCutParams(BTLxProcessParams):
"""A class to store the parameters of a Jack Rafter Cut feature.
Parameters
----------
instance : :class:`~compas_timber._fabrication.JackRafterCut`
The instance of the Jack Rafter Cut feature.
"""

def __init__(self, instance):
# type: (JackRafterCut) -> None
super(JackRafterCutParams, self).__init__(instance)

def as_dict(self):
"""Returns the parameters of the Jack Rafter Cut feature as a dictionary.
Returns
-------
dict
The parameters of the Jack Rafter Cut feature as a dictionary.
"""
# type: () -> OrderedDict
result = super(JackRafterCutParams, self).as_dict()
result["Orientation"] = self._instance.orientation
result["StartX"] = "{:.{prec}f}".format(self._instance.start_x, prec=TOL.precision)
result["StartY"] = "{:.{prec}f}".format(self._instance.start_y, prec=TOL.precision)
result["StartDepth"] = "{:.{prec}f}".format(self._instance.start_depth, prec=TOL.precision)
result["Angle"] = "{:.{prec}f}".format(self._instance.angle, prec=TOL.precision)
result["Inclination"] = "{:.{prec}f}".format(self._instance.inclination, prec=TOL.precision)
return result
19 changes: 19 additions & 0 deletions tests/compas_timber/test_btlx.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,22 @@ def test_jack_rafter_cut_data(tol):
assert copied_instance.angle == instance.angle
assert copied_instance.inclination == instance.inclination
assert copied_instance.ref_side_index == instance.ref_side_index


def test_jack_rafter_params_obj():
instance = JackRafterCut(OrientationType.START, 14.23, 0.22, 42, 123.555, 95.2, ref_side_index=3)

params = instance.params_dict

assert params["Name"] == "JackRafterCut"
assert params["Process"] == "yes"
assert params["Priority"] == "0"
assert params["ProcessID"] == "0"
assert params["ReferencePlaneID"] == "4"

assert params["Orientation"] == "start"
assert params["StartX"] == "14.230"
assert params["StartY"] == "0.220"
assert params["StartDepth"] == "42.000"
assert params["Angle"] == "123.555"
assert params["Inclination"] == "95.200"

0 comments on commit aec2795

Please sign in to comment.