Skip to content

Commit

Permalink
gui:
Browse files Browse the repository at this point in the history
 - displacement result can now do a phase sweep (same as sinusoidal, but it was annoying)
 - starting filter_value (currently hidden)
  • Loading branch information
SteveDoyle2 committed Dec 2, 2024
1 parent 3c424fb commit 8b35110
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,11 @@ def get_vector_result_by_scale_phase(self, itime: int, res_name: str,
"""
assert self.dim == 3, self.dim
assert len(self.xyz.shape) == 2, self.xyz.shape
if self.is_real:
dxyz, *unused_junk = self.get_vector_data_dense(itime, res_name)
deflected_xyz = self.xyz + scale * dxyz
else:
assert isinstance(itime, int), (itime, phase)
assert isinstance(phase, float), (itime, phase)
dxyz = self._get_complex_displacements_by_phase(itime, res_name, phase)
deflected_xyz = self.xyz + scale * dxyz

assert isinstance(itime, int), (itime, phase)
assert isinstance(phase, float), (itime, phase)
dxyz = self._get_complex_displacements_by_phase(itime, res_name, phase)
deflected_xyz = self.xyz + scale * dxyz
assert len(deflected_xyz.shape) == 2, deflected_xyz.shape
return self.xyz, deflected_xyz

Expand All @@ -199,8 +196,11 @@ def _get_complex_displacements_by_phase(self, itime: int, res_name: str,
assert dxyz.ndim == 2, dxyz

theta = np.radians(phase)
dxyz = dxyz.real * np.cos(theta) + dxyz.imag * np.sin(theta)
return dxyz
if self.is_real:
dxyz_out = dxyz * np.cos(theta)
else:
dxyz_out = dxyz.real * np.cos(theta) + dxyz.imag * np.sin(theta)
return dxyz_out

def __repr__(self) -> str:
"""defines str(self)"""
Expand Down
2 changes: 2 additions & 0 deletions pyNastran/converters/nastran/test_nastran_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def test_solid_shell_bar_02(self):
test.on_rcycle_results()
test.on_update_legend(
title='Title', min_value=0., max_value=1.,
filter_value=1.,
scale=0.0, phase=0.0,
arrow_scale=1.,
data_format='%.0f',
Expand All @@ -490,6 +491,7 @@ def test_solid_shell_bar_02(self):
is_shown=True, render=True)
test.on_update_legend(
title='Title', min_value=0., max_value=1.,
filter_value=None,
scale=0.0, phase=0.0,
arrow_scale=1.,
data_format='%.0f',
Expand Down
44 changes: 29 additions & 15 deletions pyNastran/gui/menus/legend/legend_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def set_legend_menu(self):
(is_method_array,
legend_title, scalar_bar, defaults_scalar_bar,
data_format, default_format,
default_title, min_value, max_value,
default_min, default_max) = self.get_legend_fringe(gui.icase_fringe)
default_title, min_value, max_value, filter_value,
default_min, default_max, default_filter_value,
) = self.get_legend_fringe(gui.icase_fringe)

nlabels, labelsize, ncolors, colormap = scalar_bar
default_nlabels, default_labelsize, default_ncolors, default_colormap = defaults_scalar_bar
Expand All @@ -90,7 +91,6 @@ def set_legend_menu(self):
#arrow_scale = None
#default_arrow_scale = None


data = {
'font_size' : self.settings.font_size,
#'icase' : self.icase,
Expand All @@ -100,14 +100,16 @@ def set_legend_menu(self):
'title' : legend_title,
'min_value' : min_value,
'max_value' : max_value,
'filter_value': filter_value,

'scale' : scale,
'arrow_scale' : arrow_scale,
'phase' : phase,
'format' : data_format,

'default_min' : default_min,
'default_max' : default_max,
'default_min': default_min,
'default_max': default_max,
'default_filter_value': default_filter_value,
'default_title' : default_title,
'default_scale' : default_scale,
'default_arrow_scale' : default_arrow_scale,
Expand Down Expand Up @@ -161,8 +163,9 @@ def set_animation_menu(self) -> None:
(is_method_array,
legend_title, scalar_bar, defaults_scalar_bar,
data_format, default_format,
default_title, min_value, max_value,
default_min, default_max) = self.get_legend_fringe(gui.icase_fringe)
default_title, min_value, max_value, filter_value,
default_min, default_max, default_filter_value,
) = self.get_legend_fringe(gui.icase_fringe)

# set the title as the default
if is_method_array and legend_title == default_title:
Expand Down Expand Up @@ -230,6 +233,7 @@ def update_legend(self,
title: str,
min_value: Optional[float],
max_value: Optional[float],
filter_value: Optional[float],
data_format: str,
scale: Optional[float],
phase: Optional[float],
Expand Down Expand Up @@ -304,8 +308,8 @@ def update_legend(self,
is_method_array,
_legend_title, scalar_bar, defaults_scalar_bar,
data_format, default_format, default_title,
_min_value, _max_value,
default_min, default_max) = out
_min_value, _max_value, _filter_value,
default_min, default_max, default_filter_value) = out
if is_method_array and title == default_title:
title = ''

Expand All @@ -314,6 +318,7 @@ def update_legend(self,
if use_fringe_internal:
min_value = _min_value
max_value = _max_value
filter_value = _filter_value
unused_legend_title = _legend_title
labelsize = _labelsize
ncolors = _ncolors
Expand Down Expand Up @@ -350,7 +355,6 @@ def update_legend(self,
#default_scale = _default_scale
#default_phase = _default_phase


_arrow_scale, default_arrow_scale = self.get_legend_vector(icase_vector)
if use_vector_internal:
arrow_scale = _arrow_scale
Expand All @@ -359,12 +363,14 @@ def update_legend(self,
#assert isinstance(scale, float), 'scale=%s' % scale
self._legend_window.update_legend(
icase_fringe, icase_disp, icase_vector,
title, min_value, max_value, data_format,
title, min_value, max_value, filter_value,
data_format,
nlabels, labelsize, ncolors, colormap, is_fringe,
scale, phase,
arrow_scale,

default_title, default_min, default_max, default_format,
default_title, default_min, default_max, default_filter_value,
default_format,
default_nlabels, default_labelsize,
default_ncolors, default_colormap,
default_scale, default_phase,
Expand All @@ -378,6 +384,7 @@ def apply_legend(self, data: dict[str, Any]) -> None:
title = data['title']
min_value = data['min_value']
max_value = data['max_value']
filter_value = data['filter_value']
scale = data['scale']
phase = data['phase']
arrow_scale = data['arrow_scale']
Expand All @@ -395,6 +402,7 @@ def apply_legend(self, data: dict[str, Any]) -> None:
self.on_update_legend(
title=title,
min_value=min_value, max_value=max_value,
filter_value=filter_value,
scale=scale, phase=phase,
arrow_scale=arrow_scale,
data_format=data_format,
Expand All @@ -409,6 +417,7 @@ def on_update_legend(self,
title: str='Title',
min_value: float=0.,
max_value: float=1.,
filter_value: Optional[float]=None,
scale: float=0.0,
phase: float=0.0,
arrow_scale: float=1.,
Expand All @@ -430,6 +439,7 @@ def on_update_legend(self,
TODO: speed up by using existing values to skip update steps
"""
assert isinstance(title, str), title
nlabels = None if nlabels == -1 else nlabels
labelsize = None if labelsize == -1 else labelsize
ncolors = None if ncolors == -1 else ncolors
Expand Down Expand Up @@ -568,7 +578,8 @@ def on_update_legend(self,
gui.Render()

msg = (
f'self.on_update_legend(title={title!r}, min_value={min_value}, max_value={max_value},\n'
f'self.on_update_legend(title={title!r}, '
f'min_value={min_value}, max_value={max_value}, filter_value={filter_value},\n'
f' scale={scale}, phase={phase},\n'
f' data_format={data_format!r}, is_low_to_high={is_low_to_high}, '
f'is_discrete={is_discrete},\n'
Expand All @@ -590,6 +601,7 @@ def get_legend_fringe(self, icase_fringe: Optional[int]) -> tuple:
legend_title = None
min_value = None
max_value = None
filter_value = None
data_format = None
scalar_bar = (None, None, None, None)
defaults_scalar_bar = (None, None, None, None)
Expand Down Expand Up @@ -624,13 +636,15 @@ def get_legend_fringe(self, icase_fringe: Optional[int]) -> tuple:
default_min, default_max = obj.get_default_min_max(i, res_name)
default_format = obj.get_default_data_format(i, res_name)

filter_value = None
default_filter_value = None
out = (
is_method_array,
legend_title,
scalar_bar, defaults_scalar_bar,
data_format, default_format,
default_title, min_value, max_value,
default_min, default_max)
default_title, min_value, max_value, filter_value,
default_min, default_max, default_filter_value)
return out

def get_legend_disp(self, icase_disp: Optional[int],
Expand Down
Loading

0 comments on commit 8b35110

Please sign in to comment.