diff --git a/nexus_constructor/field_widget.py b/nexus_constructor/field_widget.py index 37ef461ee..88947a002 100644 --- a/nexus_constructor/field_widget.py +++ b/nexus_constructor/field_widget.py @@ -438,7 +438,7 @@ def field_type_changed(self): self.edit_dialog = QDialog(parent=self) self.edit_dialog.setModal(True) self._set_up_value_validator(False) - if self.streams_widget and self.streams_widget._old_schema: + if self._node_parent and self.streams_widget and self.streams_widget._old_schema: self._node_parent.add_stream_module(self.streams_widget._old_schema) if self.field_type == FieldType.scalar_dataset: self.set_visibility(True, False, False, True) diff --git a/nexus_constructor/model/component.py b/nexus_constructor/model/component.py index c06d4d30d..5a3826067 100644 --- a/nexus_constructor/model/component.py +++ b/nexus_constructor/model/component.py @@ -243,7 +243,7 @@ def add_rotation( type=ValueTypes.DOUBLE, ), target_pos: int = -1, - offset: QVector3D = QVector3D(), + offset_vector: Optional[QVector3D] = None, ) -> Transformation: """ Note, currently assumes angle is in degrees @@ -264,7 +264,7 @@ def add_rotation( depends_on, values, target_pos, - offset, + offset_vector if offset_vector is not None else QVector3D(0., 0., 0.), ) def _create_and_add_transform( diff --git a/nexus_constructor/model/transformation.py b/nexus_constructor/model/transformation.py index 8a87c26ec..4c76b7837 100644 --- a/nexus_constructor/model/transformation.py +++ b/nexus_constructor/model/transformation.py @@ -71,7 +71,7 @@ def vector(self, new_vector: QVector3D): def offset_vector(self) -> QVector3D: vector = self.attributes.get_attribute_value(CommonAttrs.OFFSET) return ( - QVector3D(vector[0], vector[1], vector[2]) if vector is not None else None + QVector3D(vector[0], vector[1], vector[2]) if vector is not None else QVector3D(0., 0., 0.) ) @offset_vector.setter diff --git a/nexus_constructor/transformation_view.py b/nexus_constructor/transformation_view.py index b09a77913..c4f04c96a 100644 --- a/nexus_constructor/transformation_view.py +++ b/nexus_constructor/transformation_view.py @@ -127,6 +127,12 @@ def save_all_changes(self): self.save_offset() self.save_magnitude() + 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) + class EditTranslation(EditTransformation): def __init__(self, parent: QWidget, transformation: Transformation, model: Model): @@ -134,7 +140,7 @@ def __init__(self, parent: QWidget, transformation: Transformation, model: Model self.transformation_frame.magnitude_widget.unit_validator.expected_dimensionality = ( METRES ) - transformation_text(self, TransformationType.TRANSLATION) + self.transformation_text(TransformationType.TRANSLATION) class EditRotation(EditTransformation): @@ -143,14 +149,7 @@ def __init__(self, parent: QWidget, transformation: Transformation, model: Model self.transformation_frame.magnitude_widget.unit_validator.expected_dimensionality = ( RADIANS ) - 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) + self.transformation_text(TransformationType.ROTATION) def links_back_to_component(reference: Component, comparison: Component): diff --git a/tests/model/test_transformations.py b/tests/model/test_transformations.py index a5cc96d7d..b36795a92 100644 --- a/tests/model/test_transformations.py +++ b/tests/model/test_transformations.py @@ -16,11 +16,11 @@ def create_transform( name="test translation", ui_value=42.0, - vector=QVector3D(1.0, 0.0, 0.0), + vector=None, type="translation", values=Dataset(parent_node=None, name="", values=None, type=ValueTypes.DOUBLE), units="m", - offset_vector=QVector3D(0.0, 0.0, 0.0), + offset_vector=None, ): translation = Transformation( name=name, @@ -30,8 +30,8 @@ def create_transform( parent_component=None, ) - translation.vector = vector - translation.offset_vector = offset_vector + translation.vector = vector if vector is not None else QVector3D(1.0, 0.0, 0.0) + translation.offset_vector = offset_vector if offset_vector is not None else QVector3D(0.0, 0.0, 0.0) translation.transform_type = type translation.ui_value = ui_value translation.units = units diff --git a/ui_tests/test_ui_transformation_view.py b/ui_tests/test_ui_transformation_view.py index 71b535c23..d01dc086c 100644 --- a/ui_tests/test_ui_transformation_view.py +++ b/ui_tests/test_ui_transformation_view.py @@ -12,6 +12,7 @@ from nexus_constructor.model.module import Dataset, F142Stream, Link from nexus_constructor.transformation_view import EditRotation, EditTranslation from nexus_constructor.validators import FieldType +from nexus_constructor.ui_utils import qvector3d_to_numpy_array @pytest.fixture @@ -37,7 +38,7 @@ def create_corresponding_value_dataset(value: Any): def test_UI_GIVEN_scalar_vector_WHEN_creating_translation_view_THEN_ui_is_filled_correctly( qtbot, model, component ): - x = 1 + x = 0 y = 0 z = 0 value = 0.0 @@ -62,9 +63,9 @@ def test_UI_GIVEN_scalar_vector_WHEN_creating_translation_view_THEN_ui_is_filled def test_UI_GIVEN_scalar_angle_WHEN_creating_rotation_view_THEN_ui_is_filled_correctly( qtbot, model, component ): - x = 1 - y = 2 - z = 3 + x = 0 + y = 0 + z = 0 angle = 90 transform = component.add_rotation(angle=angle, axis=QVector3D(x, y, z)) @@ -93,11 +94,10 @@ def test_UI_GIVEN_a_translation_with_zero_offset_WHEN_setting_the_offset_to_nonz view = EditTranslation(parent=None, transformation=transform, model=model) qtbot.addWidget(view) - view.transformation_frame.offset_box.setValue(9) + view.transformation_frame.offset_spinboxes[0].setValue(9) view.save_offset() - - assert transform.attributes.get_attribute_value(CommonAttrs.OFFSET) == 9 - assert view.transformation_frame.offset_box.value() == 9 + assert all(transform.attributes.get_attribute_value(CommonAttrs.OFFSET) == qvector3d_to_numpy_array(QVector3D(9, 0, 0))) + assert view.transformation_frame.offset_spinboxes[0].value() == 9 def test_UI_GIVEN_a_translation_with_nonzero_offset_WHEN_setting_the_offset_to_zero_THEN_ui_is_filled_correctly( @@ -106,15 +106,15 @@ def test_UI_GIVEN_a_translation_with_nonzero_offset_WHEN_setting_the_offset_to_z transform = component.add_translation(QVector3D(0, 0, 1), name="test") transform.values = create_corresponding_value_dataset(123) view = EditTranslation(parent=None, transformation=transform, model=model) - view.transformation_frame.offset_box.setValue(10) + view.transformation_frame.offset_spinboxes[0].setValue(10) qtbot.addWidget(view) view.save_offset() - view.transformation_frame.offset_box.setValue(0) + view.transformation_frame.offset_spinboxes[0].setValue(0) view.save_offset() - assert transform.attributes.get_attribute_value(CommonAttrs.OFFSET) == 0 - assert view.transformation_frame.offset_box.value() == 0 + assert all(transform.attributes.get_attribute_value(CommonAttrs.OFFSET) == qvector3d_to_numpy_array(QVector3D(0, 0, 0))) + assert view.transformation_frame.offset_spinboxes[0].value() == 0 def test_UI_GIVEN_array_dataset_as_magnitude_WHEN_creating_translation_THEN_ui_is_filled_correctly( @@ -122,7 +122,7 @@ def test_UI_GIVEN_array_dataset_as_magnitude_WHEN_creating_translation_THEN_ui_i ): array = np.array([1, 2, 3, 4]) - x = 1 + x = 0 y = 0 z = 0 transform = component.add_translation(QVector3D(x, y, z), name="test")