From a9ba6dfa63e9a62585e1721149a090a5707f1c7a Mon Sep 17 00:00:00 2001 From: George O'Neill Date: Fri, 13 Oct 2023 13:53:05 +0200 Subject: [PATCH] test fixing --- nexus_constructor/json/transformation_reader.py | 2 +- nexus_constructor/model/transformation.py | 17 ++++++++--------- tests/json/test_transformation_reader.py | 6 ++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/nexus_constructor/json/transformation_reader.py b/nexus_constructor/json/transformation_reader.py index 5d0f10e8a..39b87b5ad 100644 --- a/nexus_constructor/json/transformation_reader.py +++ b/nexus_constructor/json/transformation_reader.py @@ -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: self.warnings.append( TransformDependencyMissing( f"Unable to find {attribute_name} attribute in transformation" diff --git a/nexus_constructor/model/transformation.py b/nexus_constructor/model/transformation.py index fc5896661..6324b8de4 100644 --- a/nexus_constructor/model/transformation.py +++ b/nexus_constructor/model/transformation.py @@ -115,23 +115,22 @@ def qmatrix(self) -> QMatrix4x4: """ transform = Qt3DCore.QTransform() transform.matrix() - offset = QVector3D() # self.attributes.get_attribute_value(CommonAttrs.OFFSET) - # if not offset: - # offset = 0.0 if self.transform_type == TransformationType.ROTATION: - # noramlise offset to get axis, then apply a rotation offset first to translate it, and then apply rotation - # try setTranslation (to modify ({}.4)) - # ORRRR - # self.vector + offset + # apply offset first to translate it, and then apply rotation + transform.setTranslation( + self.offset_vector + ) quaternion = transform.fromAxisAndAngle( - self.vector, self.ui_value * self._ui_scale_factor #(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( self.vector.normalized() - * (self.ui_value) # + offset) + * self.ui_value * self._ui_scale_factor + + self.offset_vector ) else: raise ( diff --git a/tests/json/test_transformation_reader.py b/tests/json/test_transformation_reader.py index c4b9d6847..d276b3f41 100644 --- a/tests/json/test_transformation_reader.py +++ b/tests/json/test_transformation_reader.py @@ -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) @@ -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) )