Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1016 from ess-dmsc/ECDC-3282_box_shape_repeatable…
Browse files Browse the repository at this point in the history
…_nxdetector

ECDC-3282: Adding repetition of box shape geometry for NXdetector components
  • Loading branch information
kmurica authored Dec 19, 2022
2 parents b815d06 + ab0c87e commit d9d1195
Showing 6 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions nexus_constructor/add_component_window.py
Original file line number Diff line number Diff line change
@@ -566,6 +566,7 @@ def generate_geometry_model(
self.boxWidthLineEdit.value(),
self.boxHeightLineEdit.value(),
self.unitsLineEdit.text(),
pixel_data=pixel_data,
)
elif self.meshRadioButton.isChecked() and self.cad_file_name:
mesh_geometry = OFFGeometryNoNexus()
10 changes: 9 additions & 1 deletion nexus_constructor/model/component.py
Original file line number Diff line number Diff line change
@@ -338,7 +338,10 @@ def shape(
if SHAPE_GROUP_NAME in self:
return self[SHAPE_GROUP_NAME], None
if GEOMETRY_GROUP_NAME in self:
return self[GEOMETRY_GROUP_NAME], None
return (
self[GEOMETRY_GROUP_NAME],
self._create_transformation_vectors_for_pixel_offsets(),
)
return NoShapeGeometry(), None

def remove_shape(self):
@@ -380,9 +383,14 @@ def set_box_shape(
width: float = 1.0,
height: float = 1.0,
units: str = "m",
pixel_data=None,
) -> BoxGeometry:
self.remove_shape()
geometry = BoxGeometry(length, width, height, GEOMETRY_GROUP_NAME, units)
if isinstance(pixel_data, PixelMapping):
geometry.detector_number = get_detector_number_from_pixel_mapping(
pixel_data
)
self[GEOMETRY_GROUP_NAME] = geometry
return geometry

12 changes: 12 additions & 0 deletions nexus_constructor/model/geometry.py
Original file line number Diff line number Diff line change
@@ -178,6 +178,8 @@ class BoxGeometry(Group):
Box geometry shape.
"""

_detector: Optional[np.array] = None

def __init__(
self,
length: float,
@@ -192,6 +194,16 @@ def __init__(
self.nx_class = GEOMETRY_NX_CLASS
self._create_datasets_and_add_to_shape_group()

@property
def detector_number(self) -> List[int]:
if self._detector is None:
return None
return self._detector.tolist()

@detector_number.setter
def detector_number(self, pixel_ids: List[int]):
self._detector = np.array(pixel_ids)

def _create_datasets_and_add_to_shape_group(self):
group = Group(name=SHAPE_GROUP_NAME)
group.nx_class = SHAPE_NX_CLASS
21 changes: 13 additions & 8 deletions nexus_constructor/pixel_options.py
Original file line number Diff line number Diff line change
@@ -261,16 +261,21 @@ def _fill_entire_shape_fields(self, component_to_edit: Component):
if isinstance(shape, OFFGeometryNexus):
self._fill_off_geometry_pixel_mapping(shape)

elif not isinstance(shape, BoxGeometry):
detector_number = shape.detector_number
n_cylinders = shape.cylinders.size // 3
else:
if isinstance(shape, BoxGeometry):
detector_number = shape.detector_number
n_shapes = len(shape.size) // 3
shape_type = "box"
else:
detector_number = shape.detector_number
n_shapes = shape.cylinders.size // 3
shape_type = "cylinder"

if n_cylinders > 1:
self.create_pixel_mapping_table(n_cylinders, "cylinder")
if n_shapes > 1:
self.create_pixel_mapping_table(n_shapes, shape_type)
# TODO: Restore pixel mapping in the case of multiple cylinders

else:
self.create_pixel_mapping_table(n_cylinders, "cylinder")
self.create_pixel_mapping_table(n_shapes, shape_type)
item = QTableWidgetItem()
item.setData(Qt.DisplayRole, detector_number[0])
self.pixel_mapping_table_widget.setItem(0, 1, item)
@@ -551,7 +556,7 @@ def create_pixel_mapping_table(self, n_items: int, text: str):
Creates a table of pixel mapping widgets.
:param n_items: The number of widgets to create.
:param text: The label to be displayed next to the id cel.
This is either faces or cylinders.
This is either faces, boxes or cylinders.
"""
self.reset_pixel_mapping_table()
self.pixel_mapping_table_widget.setColumnCount(2)
2 changes: 1 addition & 1 deletion nx-class-documentation/html/index.html
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ <h1>User Manual and Reference Documentation<a class="headerlink" href="#user-man
</div>
<hr class="docutils" />
<p class="rubric">Publishing Information</p>
<p>This manual built Dec 16, 2022.</p>
<p>This manual built Dec 19, 2022.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>This document is available in these formats online:</p>
2 changes: 1 addition & 1 deletion nx-class-documentation/html/searchindex.js

Large diffs are not rendered by default.

0 comments on commit d9d1195

Please sign in to comment.