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

Commit

Permalink
review additions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoneiESS committed Oct 13, 2023
1 parent 7751656 commit 7f9ceee
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion nexus_constructor/field_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions nexus_constructor/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion nexus_constructor/model/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions nexus_constructor/transformation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,20 @@ 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):
super().__init__(parent, transformation, model)
self.transformation_frame.magnitude_widget.unit_validator.expected_dimensionality = (
METRES
)
transformation_text(self, TransformationType.TRANSLATION)
self.transformation_text(TransformationType.TRANSLATION)


class EditRotation(EditTransformation):
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/model/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions ui_tests/test_ui_transformation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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(
Expand All @@ -106,23 +106,23 @@ 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(
qtbot, component, model
):
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")
Expand Down

0 comments on commit 7f9ceee

Please sign in to comment.