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

ECDC-3526-NXtransformations_offsets #1042

Merged
merged 43 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
847b38a
updated text fields
ggoneiESS Oct 9, 2023
c6c4645
updated text
ggoneiESS Oct 9, 2023
d07ed1f
vector for offset
ggoneiESS Oct 9, 2023
778ca02
working vector for offset
ggoneiESS Oct 9, 2023
3bd3b61
magic missing widgets
ggoneiESS Oct 9, 2023
54a6636
fixed typo
ggoneiESS Oct 9, 2023
d8f5f3f
no crashes stash
ggoneiESS Oct 10, 2023
528b920
Merge branch 'main' into ECDC-3526-NXtransformations_offsets
ggoneiESS Oct 10, 2023
95bfcb5
latest changes stash
ggoneiESS Oct 12, 2023
56691af
fixed translation issue
ggoneiESS Oct 12, 2023
de34010
Update NeXus HTML documentation
cow-bot Oct 12, 2023
01690fc
Merge branch 'ECDC-3621-move-object' into ECDC-3526-NXtransformations…
ggoneiESS Oct 12, 2023
cb9fb09
offset vector
ggoneiESS Oct 12, 2023
f2bf8ff
offset working in appearance but not adjjustment
ggoneiESS Oct 12, 2023
090f3aa
triggers all working
ggoneiESS Oct 13, 2023
a9ba6df
test fixing
ggoneiESS Oct 13, 2023
3fe8960
tests fixed
ggoneiESS Oct 13, 2023
0e0b063
Merge commit 'fd997d62aab03717d872720095a28ce2b4a71291' into HEAD
yashikno Oct 13, 2023
1c50f1b
GO FORMAT YOURSELF (black)
cow-bot Oct 13, 2023
09c2d07
Update NeXus HTML documentation
cow-bot Oct 13, 2023
7751656
small refactor
ggoneiESS Oct 13, 2023
7f9ceee
review additions
ggoneiESS Oct 13, 2023
39b9863
missed qvector 3D
ggoneiESS Oct 16, 2023
e2d8d0f
GO FORMAT YOURSELF (black)
cow-bot Oct 16, 2023
da60c44
Update NeXus HTML documentation
cow-bot Oct 16, 2023
f5c7407
the WORKING units commit
ggoneiESS Oct 17, 2023
674e553
Working units with validator
ggoneiESS Oct 18, 2023
43bedad
json complete but units written twice
ggoneiESS Oct 18, 2023
6db3e97
Update NeXus HTML documentation
cow-bot Oct 18, 2023
2c9eb8a
offset_units read correctly
ggoneiESS Oct 24, 2023
5cce655
removed passing of current_vector
ggoneiESS Oct 24, 2023
30a1d08
fixed one test but why not the other
ggoneiESS Oct 24, 2023
f10cddc
GO FORMAT YOURSELF (black)
cow-bot Oct 24, 2023
76fd2a1
Update NeXus HTML documentation
cow-bot Oct 24, 2023
1402616
working tests
ggoneiESS Oct 24, 2023
8f4b165
fix for exporting offset only if present
ggoneiESS Oct 24, 2023
6c21773
small test change since zero offset not saved
ggoneiESS Oct 24, 2023
62c683a
Merge remote-tracking branch 'refs/remotes/origin/ECDC-3526-NXtransfo…
ggoneiESS Oct 24, 2023
97cc1f2
flake fix
ggoneiESS Oct 25, 2023
a39b9cf
GO FORMAT YOURSELF (black)
cow-bot Oct 25, 2023
e568035
Update NeXus HTML documentation
cow-bot Oct 25, 2023
a5e93cc
post-review commit
ggoneiESS Oct 25, 2023
499df19
initialise _ui_offset_scale_factor
ggoneiESS Oct 25, 2023
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
26 changes: 14 additions & 12 deletions nexus_constructor/field_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(
self.unit_validator = UnitValidator()
self.units_line_edit.setValidator(self.unit_validator)
self.units_line_edit.setMinimumWidth(20)
self.units_line_edit.setMaximumWidth(50)
# self.units_line_edit.setMaximumWidth(50)
unit_size_policy = QSizePolicy()
unit_size_policy.setHorizontalPolicy(QSizePolicy.Preferred)
unit_size_policy.setHorizontalStretch(1)
Expand All @@ -133,16 +133,15 @@ def __init__(
partial(validate_line_edit, self.units_line_edit)
)
self.units_line_edit.setPlaceholderText(CommonAttrs.UNITS)
fix_horizontal_size = QSizePolicy()
fix_horizontal_size.setHorizontalPolicy(QSizePolicy.Fixed)

self.field_type_combo: QComboBox = QComboBox()
self.field_type_combo.addItems([item.value for item in FieldType])
self.field_type_combo.currentIndexChanged.connect(self.field_type_changed)
self.field_type_combo.currentTextChanged.connect(
self._open_edit_dialog_if_stream
)

fix_horizontal_size = QSizePolicy()
fix_horizontal_size.setHorizontalPolicy(QSizePolicy.Fixed)
self.field_type_combo.setSizePolicy(fix_horizontal_size)

self.value_type_combo: QComboBox = QComboBox()
Expand Down Expand Up @@ -179,14 +178,17 @@ def __init__(
self.attrs_button.clicked.connect(self.show_attrs_dialog)

self.layout = QHBoxLayout()
self.layout.addWidget(self.field_name_edit)
self.layout.addWidget(self.field_type_combo)
self.layout.addWidget(self.value_line_edit)
self.layout.addWidget(self.nx_class_combo)
self.layout.addWidget(self.edit_button)
self.layout.addWidget(self.value_type_combo)
self.layout.addWidget(self.units_line_edit)
self.layout.addWidget(self.attrs_button)
for widget in [
self.field_name_edit,
self.field_type_combo,
self.value_line_edit,
self.nx_class_combo,
self.edit_button,
self.value_type_combo,
self.units_line_edit,
self.attrs_button,
]:
self.layout.addWidget(widget)

self.layout.setAlignment(Qt.AlignLeft)
self.setLayout(self.layout)
Expand Down
16 changes: 10 additions & 6 deletions nexus_constructor/json/transformation_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _find_attribute_in_list(
:return: The value of the attribute if is is found in the list, otherwise the failure value is returned.
"""
attribute = _find_attribute_from_list_or_dict(attribute_name, attributes_list)
if not attribute and attribute_name not in [CommonAttrs.OFFSET]:
if not attribute:
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
self.warnings.append(
TransformDependencyMissing(
f"Unable to find {attribute_name} attribute in transformation"
Expand Down Expand Up @@ -301,6 +301,9 @@ def _create_transformations(self, json_transformations: list):
vector = self._find_attribute_in_list(
CommonAttrs.VECTOR, name, attributes, [0.0, 0.0, 0.0]
)
offset_vector = self._find_attribute_in_list(
CommonAttrs.OFFSET, name, attributes, [0.0, 0.0, 0.0]
)
# This attribute is allowed to be missing, missing is equivalent to the value "." which means
# depends on origin (end of dependency chain)
depends_on = _find_attribute_from_list_or_dict(
Expand Down Expand Up @@ -337,12 +340,13 @@ def _create_transformations(self, json_transformations: list):
vector=QVector3D(*vector),
depends_on=None,
values=values,
offset_vector=QVector3D(*offset_vector),
)
offset = self._find_attribute_in_list(CommonAttrs.OFFSET, name, attributes)
if offset:
transform.attributes.set_attribute_value(
CommonAttrs.OFFSET, offset, ValueTypes.FLOAT
)
# offset = self._find_attribute_in_list(CommonAttrs.OFFSET, name, attributes)
# if offset:
# transform.attributes.set_attribute_value(
# CommonAttrs.OFFSET, offset, ValueTypes.FLOAT
# )
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
if depends_on not in DEPENDS_ON_IGNORE:
depends_on_id = TransformId(
*get_component_and_transform_name(depends_on)
Expand Down
4 changes: 4 additions & 0 deletions nexus_constructor/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def add_rotation(
type=ValueTypes.DOUBLE,
),
target_pos: int = -1,
offset: QVector3D = QVector3D(),
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
) -> Transformation:
"""
Note, currently assumes angle is in degrees
Expand All @@ -263,6 +264,7 @@ def add_rotation(
depends_on,
values,
target_pos,
offset,
)

def _create_and_add_transform(
Expand All @@ -275,6 +277,7 @@ def _create_and_add_transform(
depends_on: Transformation,
values: Union[Dataset, Group, StreamModule],
target_pos: int = -1,
offset_vector: QVector3D = QVector3D(),
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
) -> Transformation:
if name is None:
name = _generate_incremental_name(transformation_type, self.transforms)
Expand All @@ -297,6 +300,7 @@ def _create_and_add_transform(
transform.ui_value = angle_or_magnitude
transform.units = units
transform.vector = vector
transform.offset_vector = offset_vector
transform.depends_on = depends_on
transform.parent_component = self
if target_pos:
Expand Down
25 changes: 18 additions & 7 deletions nexus_constructor/model/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def vector(self, new_vector: QVector3D):
vector_as_np_array = np.array([new_vector.x(), new_vector.y(), new_vector.z()])
self.attributes.set_attribute_value(CommonAttrs.VECTOR, vector_as_np_array)

@property
def offset_vector(self) -> QVector3D:
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
vector = self.attributes.get_attribute_value(CommonAttrs.OFFSET)
return (
QVector3D(vector[0], vector[1], vector[2]) if vector is not None else None
)

@offset_vector.setter
def offset_vector(self, new_vector: QVector3D):
vector_as_np_array = np.array([new_vector.x(), new_vector.y(), new_vector.z()])
self.attributes.set_attribute_value(CommonAttrs.OFFSET, vector_as_np_array)

@property
def ui_value(self) -> float:
try:
Expand Down Expand Up @@ -103,19 +115,18 @@ def qmatrix(self) -> QMatrix4x4:
"""
transform = Qt3DCore.QTransform()
transform.matrix()
offset = self.attributes.get_attribute_value(CommonAttrs.OFFSET)
if not offset:
offset = 0.0
if self.transform_type == TransformationType.ROTATION:
# apply offset first to translate it, and then apply rotation
transform.setTranslation(self.offset_vector)
quaternion = transform.fromAxisAndAngle(
self.vector, (self.ui_value + offset) * self._ui_scale_factor
self.vector, self.ui_value * self._ui_scale_factor
)

transform.setRotation(quaternion)
elif self.transform_type == TransformationType.TRANSLATION:
transform.setTranslation(
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
self.vector.normalized()
* (self.ui_value + offset)
* self._ui_scale_factor
self.vector.normalized() * self.ui_value * self._ui_scale_factor
+ self.offset_vector
)
else:
raise (
Expand Down
38 changes: 22 additions & 16 deletions nexus_constructor/transformation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, parent: QWidget, transformation: Transformation, model: Model
self.transformation_parent = transformation.parent_component
current_vector = self.transformation.vector
self._fill_in_existing_fields(current_vector)
self._fill_in_existing_fields(self.transformation.offset_vector)
self.transformation_frame.depends_on_text_box.setEnabled(False)
self.disable()
self._init_connections()
Expand All @@ -37,9 +38,12 @@ def _init_connections(self):
self.save_transformation_name
)

for box in self.transformation_frame.spinboxes[:-1]:
for box in self.transformation_frame.spinboxes:
box.textChanged.connect(self.save_transformation_vector)

for box in self.transformation_frame.offset_spinboxes:
box.textChanged.connect(self.save_offset)

self.transformation_frame.magnitude_widget.value_line_edit.textChanged.connect(
self.save_magnitude
)
Expand All @@ -61,8 +65,10 @@ def _fill_in_existing_fields(self, current_vector):
)
self.transformation_frame.magnitude_widget.units = self.transformation.units
offset = self.transformation.attributes.get_attribute_value(CommonAttrs.OFFSET)
if offset:
self.transformation_frame.offset_box.setValue(offset)
if offset is not None:
self.transformation_frame.x_spinbox_offset.setValue(offset[0])
self.transformation_frame.y_spinbox_offset.setValue(offset[1])
self.transformation_frame.z_spinbox_offset.setValue(offset[2])
self.update_depends_on_ui()

def disable(self):
Expand Down Expand Up @@ -110,11 +116,10 @@ def save_transformation_name(self):
self.model.signals.transformation_changed.emit()

def save_offset(self):
offset_value = self.transformation_frame.offset_box.value()
if offset_value is not None:
self.transformation.attributes.set_attribute_value(
CommonAttrs.OFFSET, offset_value
)
self.transformation.offset_vector = QVector3D(
*[spinbox.value() for spinbox in self.transformation_frame.offset_spinboxes]
)
self.model.signals.transformation_changed.emit()

def save_all_changes(self):
self.save_transformation_name()
Expand All @@ -129,10 +134,7 @@ def __init__(self, parent: QWidget, transformation: Transformation, model: Model
self.transformation_frame.magnitude_widget.unit_validator.expected_dimensionality = (
METRES
)
self.transformation_frame.vector_label.setText("Direction")
self.transformation_frame.value_label.setText("Distance (m)")
self.transformation_frame.offset_label.setText("Offset (m)")
self.setTitle(TransformationType.TRANSLATION)
transformation_text(self, TransformationType.TRANSLATION)


class EditRotation(EditTransformation):
Expand All @@ -141,10 +143,14 @@ def __init__(self, parent: QWidget, transformation: Transformation, model: Model
self.transformation_frame.magnitude_widget.unit_validator.expected_dimensionality = (
RADIANS
)
self.transformation_frame.vector_label.setText("Rotation Axis")
self.transformation_frame.value_label.setText("Angle (°)")
self.transformation_frame.offset_label.setText("Offset (°)")
self.setTitle(TransformationType.ROTATION)
transformation_text(self, TransformationType.ROTATION)


def transformation_text(self, transformation_type):
self.transformation_frame.vector_label.setText("Vector")
self.transformation_frame.value_label.setText("Magnitude")
self.transformation_frame.offset_label.setText("Offset")
self.setTitle(transformation_type)
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved


def links_back_to_component(reference: Component, comparison: Component):
Expand Down
2 changes: 1 addition & 1 deletion nx-class-documentation/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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 Oct 12, 2023.</p>
<p>This manual built Oct 13, 2023.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>This document is available in these formats online:</p>
Expand Down
2 changes: 1 addition & 1 deletion nx-class-documentation/html/searchindex.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/json/test_transformation_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ def test_GIVEN_all_information_present_WHEN_attempting_to_create_translation_THE
2.0,
3.0,
]
transformation_json["children"][0]["attributes"][2]["offset"] = offset_vector = [
4.0,
5.0,
6.0,
]
depends_on = None

values = _create_transformation_dataset(angle_or_magnitude, "double", name)
Expand All @@ -345,6 +350,7 @@ def test_GIVEN_all_information_present_WHEN_attempting_to_create_translation_THE
vector=QVector3D(*vector),
depends_on=depends_on,
values=values,
offset_vector=QVector3D(*offset_vector),
)


Expand Down
2 changes: 2 additions & 0 deletions tests/model/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def create_transform(
type="translation",
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
values=Dataset(parent_node=None, name="", values=None, type=ValueTypes.DOUBLE),
units="m",
offset_vector=QVector3D(0.0, 0.0, 0.0),
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
):
translation = Transformation(
name=name,
Expand All @@ -30,6 +31,7 @@ def create_transform(
)

translation.vector = vector
translation.offset_vector = offset_vector
translation.transform_type = type
translation.ui_value = ui_value
translation.units = units
Expand Down
52 changes: 43 additions & 9 deletions ui/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,25 @@ def setup_ui(self, transformation):
hide_name_field=True,
show_only_f142_stream=True,
)
self.magnitude_widget.field_type_combo.setMaximumWidth(0)
self.magnitude_widget.value_type_combo.setMaximumWidth(0)
self.magnitude_widget.attrs_button.setMaximumWidth(0)
self.magnitude_widget.setFrameShape(QFrame.NoFrame)
self.magnitude_widget.setMinimumHeight(40)

self.ui_placeholder_layout = QVBoxLayout()

self.offset_box = QDoubleSpinBox(transformation)
self.offset_box.setToolTip("Offset to the transformation.")
self.offset_box.setMinimumWidth(100)
self.offset_box.setMinimum(-1000)
self.offset_box.setDecimals(5)
# self.offset_box = QDoubleSpinBox(transformation)
# self.offset_box.setToolTip("Offset to the transformation.")
# self.offset_box.setMinimumWidth(100)
# self.offset_box.setMinimum(-1000)
# self.offset_box.setDecimals(5)
offset_font = QFont()
offset_font.setBold(True)
self.offset_label = QLabel("Offset")
self.offset_label.setFont(offset_font)
self.ui_placeholder_layout.addWidget(self.offset_label)
self.ui_placeholder_layout.addWidget(self.offset_box)
# self.ui_placeholder_layout.addWidget(self.offset_label)
# self.ui_placeholder_layout.addWidget(self.offset_box)
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved

self.depends_on_text_box = QLineEdit(transformation)
self.depends_on_text_box.setToolTip("depends_on for transformation.")
Expand All @@ -79,6 +82,7 @@ def setup_ui(self, transformation):

self.setup_name_layout()
self.setup_vector_layout(transformation)
self.setup_offset_layout(transformation)
self.setup_value_and_magnitude()
self.set_spinbox_ranges()

Expand All @@ -97,6 +101,11 @@ def setup_vector_layout(self, transformation):
self._set_up_vector_box(transformation)
self._add_line()

def setup_offset_layout(self, transformation):
self.main_layout.addWidget(self.offset_label)
self._set_up_vector_box_offset(transformation)
self._add_line()

def setup_name_layout(self):
self.name_layout.addWidget(self.name_label)
self.name_layout.addWidget(self.name_line_edit)
Expand All @@ -123,6 +132,26 @@ def _set_up_vector_box(self, transformation):

self.main_layout.addLayout(self.xyz_layout)

def _set_up_vector_box_offset(self, transformation):
self.xyz_layout_offset = QHBoxLayout()

self.x_layout_offset = QFormLayout()
self.x_spinbox_offset = QDoubleSpinBox(transformation)
self.x_layout_offset.addRow("x:", self.x_spinbox_offset)
self.xyz_layout_offset.addLayout(self.x_layout_offset)

self.y_layout_offset = QFormLayout()
self.y_spinbox_offset = QDoubleSpinBox(transformation)
self.y_layout_offset.addRow("y:", self.y_spinbox_offset)
self.xyz_layout_offset.addLayout(self.y_layout_offset)

self.z_layout_offset = QFormLayout()
self.z_spinbox_offset = QDoubleSpinBox(transformation)
self.z_layout_offset.addRow("z:", self.z_spinbox_offset)
self.xyz_layout_offset.addLayout(self.z_layout_offset)

self.main_layout.addLayout(self.xyz_layout_offset)

def _add_line(self):
line = QFrame()
line.setFrameShape(QFrame.HLine)
Expand All @@ -133,9 +162,14 @@ def set_spinbox_ranges(self):
self.spinboxes = [
self.x_spinbox,
self.y_spinbox,
self.z_spinbox,
self.z_spinbox
]
self.offset_spinboxes = [
self.x_spinbox_offset,
self.y_spinbox_offset,
self.z_spinbox_offset,
]
for spinbox in self.spinboxes:
for spinbox in self.spinboxes + self.offset_spinboxes:
spinbox.setRange(-10000000, 10000000)
spinbox.setDecimals(5)

Expand Down
Loading