Skip to content

Commit

Permalink
update based on Dom's correction
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuCMira committed Oct 10, 2024
1 parent 3dcd70f commit 5d66a97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions geoh5py/groups/interpretation_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, can_add_group: bool = False, **kwargs):

self._interpretation_curves: tuple[Curve] | tuple = ()
self._interpretation_sections: tuple[InterpretationSectionParams] | tuple = ()
self._section_object_id: Slicer | None = None
self._section_object: Slicer | None = None

def _load_from_metadata(self, key: str) -> Any:
"""
Expand Down Expand Up @@ -168,8 +168,8 @@ def add_interpretation_curve(self, curves: Curve | tuple[Curve]):
self.add_children(curve)
self._interpretation_curves += (curve,)

if self.section_object_id is not None:
curve.clipping_ids = [self.section_object_id.uid]
if self.section_object is not None:
curve.clipping_ids = [self.section_object.uid]

self._update_to_metadata("Interpretation curves", self._interpretation_curves)

Expand Down Expand Up @@ -279,34 +279,34 @@ def remove_interpretation_section(
)

@property
def section_object_id(self) -> Slicer | None:
def section_object(self) -> Slicer | None:
"""
Get the section object ID.
:return: The section object ID.
"""
if self._section_object_id is None:
self.section_object_id = self._load_from_metadata("Section object ID")
if self._section_object is None:
self.section_object = self._load_from_metadata("Section object ID")

return self._section_object_id
return self._section_object

@section_object_id.setter
def section_object_id(self, slicer: Slicer | None):
@section_object.setter
def section_object(self, slicer: Slicer | None):
"""
Set the section object ID.
:param slicer: The section object ID.
"""
if slicer is None:
self._section_object_id = None
self._section_object = None
self.update_metadata({"Section object ID": None})
return

# a lot of type ignore because of circular imports
self._section_object_id = self._verify_object(slicer, "Slicer") # type: ignore
self._section_object = self._verify_object(slicer, "Slicer") # type: ignore

self.add_children(self._section_object_id) # type: ignore
self.add_children(self._section_object) # type: ignore

self.clipping_ids = [self._section_object_id.uid] # type: ignore
self.clipping_ids = [self._section_object.uid] # type: ignore

self.update_metadata({"Section object ID": self._section_object_id.uid}) # type: ignore
self.update_metadata({"Section object ID": self._section_object.uid}) # type: ignore
12 changes: 6 additions & 6 deletions tests/interpretation_section_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_create_interpretation_section(tmp_path: Path):
}

slicer = Slicer.create(workspace, name="slicer")
print(slicer._attribute_map)

# testing the removes
group.remove_interpretation_curve(curve.uid) # nothing happens
group.remove_interpretation_section(section) # nothing happens
Expand All @@ -63,9 +63,9 @@ def test_create_interpretation_section(tmp_path: Path):

assert (curve,) == group.interpretation_curves

group.section_object_id = slicer.uid
group.section_object = slicer.uid

assert slicer == group.section_object_id
assert slicer == group.section_object

assert group.metadata == {
"Interpretation curves": [str(curve.uid)],
Expand All @@ -91,7 +91,7 @@ def test_create_interpretation_section(tmp_path: Path):

assert curve.uid == group.interpretation_curves[0].uid

assert slicer.uid == group.section_object_id.uid
assert slicer.uid == group.section_object.uid

# add another object
curve2 = Curve.create(workspace, name="curve2", vertices=np.random.randn(10, 3))
Expand Down Expand Up @@ -124,8 +124,8 @@ def test_create_interpretation_section(tmp_path: Path):

assert group.interpretation_sections == ()

group.section_object_id = None
assert group.section_object_id is None
group.section_object = None
assert group.section_object is None


def test_create_interpretation_section_errors(tmp_path: Path):
Expand Down

0 comments on commit 5d66a97

Please sign in to comment.