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

Commit

Permalink
Merge pull request #1007 from ess-dmsc/ECDC-3038_enable_offsets_in_tr…
Browse files Browse the repository at this point in the history
…ansforms

 ECDC-3038: Adding offset to transformations
  • Loading branch information
kmurica authored Oct 17, 2022
2 parents 75d9b7d + 74775b6 commit 84a8742
Show file tree
Hide file tree
Showing 166 changed files with 204 additions and 166 deletions.
1 change: 1 addition & 0 deletions nexus_constructor/common_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CommonAttrs:
VECTOR = "vector"
UNITS = "units"
VERTICES = "vertices"
OFFSET = "offset"


class CommonKeys:
Expand Down
9 changes: 7 additions & 2 deletions nexus_constructor/json/transformation_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
create_fw_module_object,
)
from nexus_constructor.model.transformation import Transformation
from nexus_constructor.model.value_type import VALUE_TYPE_TO_NP
from nexus_constructor.model.value_type import VALUE_TYPE_TO_NP, ValueTypes
from nexus_constructor.transformations_list import TransformationsList

TRANSFORMATION_MAP = {
Expand Down 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:
if not attribute and attribute_name not in [CommonAttrs.OFFSET]:
self.warnings.append(
TransformDependencyMissing(
f"Unable to find {attribute_name} attribute in transformation"
Expand Down Expand Up @@ -330,6 +330,11 @@ def _create_transformations(self, json_transformations: list):
depends_on=temp_depends_on,
values=values,
)
offset = self._find_attribute_in_list(CommonAttrs.OFFSET, name, attributes)
if offset:
transform.attributes.set_attribute_value(
CommonAttrs.OFFSET, offset, ValueTypes.FLOAT
)
if depends_on not in DEPENDS_ON_IGNORE:
depends_on_id = TransformId(
*get_component_and_transform_name(depends_on)
Expand Down
9 changes: 7 additions & 2 deletions nexus_constructor/model/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,19 @@ 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:
quaternion = transform.fromAxisAndAngle(
self.vector, self.ui_value * self._ui_scale_factor
self.vector, (self.ui_value + offset) * self._ui_scale_factor
)
transform.setRotation(quaternion)
elif self.transform_type == TransformationType.TRANSLATION:
transform.setTranslation(
self.vector.normalized() * self.ui_value * self._ui_scale_factor
self.vector.normalized()
* (self.ui_value + offset)
* self._ui_scale_factor
)
else:
raise (
Expand Down
15 changes: 14 additions & 1 deletion nexus_constructor/transformation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from PySide6.QtGui import QVector3D
from PySide6.QtWidgets import QFrame, QGroupBox, QWidget

from nexus_constructor.common_attrs import TransformationType
from nexus_constructor.common_attrs import CommonAttrs, TransformationType
from nexus_constructor.component_tree_model import LinkTransformation
from nexus_constructor.field_utils import find_field_type
from nexus_constructor.model.component import Component
Expand Down Expand Up @@ -60,6 +60,9 @@ def _fill_in_existing_fields(self, current_vector):
self.transformation.values, self.transformation_frame.magnitude_widget
)
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)
self.update_depends_on_ui()

def disable(self):
Expand Down Expand Up @@ -106,9 +109,17 @@ def save_transformation_name(self):
self.transformation.name = self.transformation_frame.name_line_edit.text()
self.model.signals.transformation_changed.emit()

def save_offset(self):
offset_value = self.transformation_frame.offset_box.value()
if offset_value:
self.transformation.attributes.set_attribute_value(
CommonAttrs.OFFSET, offset_value
)

def save_all_changes(self):
self.save_transformation_name()
self.save_transformation_vector()
self.save_offset()
self.save_magnitude()


Expand All @@ -120,6 +131,7 @@ def __init__(self, parent: QWidget, transformation: Transformation, model: Model
)
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)


Expand All @@ -131,6 +143,7 @@ def __init__(self, parent: QWidget, transformation: Transformation, model: Model
)
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)


Expand Down
2 changes: 1 addition & 1 deletion nx-class-documentation/html/applying-nexus.html
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion nx-class-documentation/html/authorgroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion nx-class-documentation/html/classes/applications/NXmx.html
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2022, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.2.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
</div>
</body>
</html>
Loading

0 comments on commit 84a8742

Please sign in to comment.