1111from hexrdgui import resource_loader
1212from hexrdgui .hexrd_config import HexrdConfig
1313from hexrdgui .ui_loader import UiLoader
14+ from hexrdgui .utils import (
15+ block_signals ,
16+ euler_angles_to_exp_map ,
17+ exp_map_to_euler_angles ,
18+ )
1419from hexrdgui .utils .guess_instrument_type import guess_instrument_type
1520
1621import hexrd .resources as hexrd_resources
1722from hexrd .material import _angstroms , _kev , Material
23+ from hexrd .instrument import calc_beam_vec
1824from hexrd .instrument .constants import FILTER_DEFAULTS , PINHOLE_DEFAULTS
25+ from hexrd .rotations import rotMatOfExpMap
1926
2027
2128class PhysicsPackageManagerDialog :
@@ -41,6 +48,8 @@ def show(self, delete_if_canceled=False):
4148 self .delete_if_canceled = delete_if_canceled
4249 self .setup_form ()
4350 self .draw_diagram ()
51+ self .reset_sample_tilt ()
52+ self .update_tilt_suffixes ()
4453 self .ui .show ()
4554
4655 @property
@@ -96,6 +105,14 @@ def setup_connections(self):
96105 HexrdConfig ().detectors_changed .connect (
97106 self .initialize_detector_coatings )
98107
108+ HexrdConfig ().euler_angle_convention_changed .connect (
109+ self .on_euler_angle_convention_changed )
110+ HexrdConfig ().sample_tilt_modified .connect (
111+ self .reset_sample_tilt )
112+
113+ for w in self .sample_tilt_widgets :
114+ w .valueChanged .connect (self .update_sample_normal )
115+
99116 self .ui .accepted .connect (self .on_accepted )
100117 self .ui .rejected .connect (self .on_rejected )
101118
@@ -108,6 +125,47 @@ def on_rejected(self):
108125
109126 self .delete_if_canceled = False
110127
128+ def on_euler_angle_convention_changed (self ):
129+ self .update_tilt_suffixes ()
130+ self .reset_sample_tilt ()
131+
132+ @property
133+ def sample_tilt_widgets (self ):
134+ return [getattr (self .ui , f'sample_tilt_{ i } ' ) for i in range (3 )]
135+
136+ @property
137+ def sample_normal_widgets (self ):
138+ return [getattr (self .ui , f'sample_normal_{ i } ' ) for i in range (3 )]
139+
140+ @property
141+ def sample_rmat (self ):
142+ angles = [w .value () for w in self .sample_tilt_widgets ]
143+ return rotMatOfExpMap (euler_angles_to_exp_map (angles ))
144+
145+ def update_tilt_suffixes (self ):
146+ suffix = '' if HexrdConfig ().euler_angle_convention is None else '°'
147+ for w in self .sample_tilt_widgets :
148+ w .setSuffix (suffix )
149+
150+ def reset_sample_tilt (self ):
151+ angles = exp_map_to_euler_angles (HexrdConfig ().sample_tilt )
152+ with block_signals (* self .sample_tilt_widgets ):
153+ for w , v in zip (self .sample_tilt_widgets , angles ):
154+ w .setValue (v )
155+
156+ self .update_sample_normal ()
157+
158+ def save_sample_tilt (self ):
159+ angles = [w .value () for w in self .sample_tilt_widgets ]
160+ HexrdConfig ().sample_tilt = euler_angles_to_exp_map (angles )
161+
162+ def update_sample_normal (self ):
163+ d = HexrdConfig ().active_beam ['vector' ]
164+ bvec = calc_beam_vec (d ['azimuth' ], d ['polar_angle' ])
165+ sample_normal = np .dot (self .sample_rmat , [0. , 0. , np .sign (bvec [2 ])])
166+ for w , v in zip (self .sample_normal_widgets , sample_normal ):
167+ w .setValue (v )
168+
111169 def initialize_detector_coatings (self ):
112170 # Reset detector coatings to make sure they're in sync w/ current dets
113171 HexrdConfig ().detector_coatings_dictified = {}
@@ -295,6 +353,8 @@ def accept_changes(self):
295353
296354 HexrdConfig ().update_physics_package (** kwargs )
297355
356+ self .save_sample_tilt ()
357+
298358 if HexrdConfig ().apply_absorption_correction :
299359 # Make sure changes are reflected
300360 HexrdConfig ().deep_rerender_needed .emit ()
0 commit comments