Skip to content

Commit

Permalink
gui:
Browse files Browse the repository at this point in the history
 - plotel color fixed
 - aero flag
  • Loading branch information
SteveDoyle2 committed Nov 4, 2024
1 parent 8be0939 commit 1c3e80e
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 43 deletions.
65 changes: 31 additions & 34 deletions pyNastran/converters/nastran/gui/nastran_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,12 @@ def make_caeros(self, model: BDF) -> tuple[np.ndarray, int, int, int, int, bool,
list of panels used by each aero panel
"""
gui: MainWindow = self.gui
nastran_settings: NastranSettings = gui.settings.nastran_settings
is_aero = nastran_settings.is_aero

# when caeros is empty, SPLINEx/AESURF cannot be defined
if not self.create_secondary_actors or len(model.caeros) == 0:
if not is_aero or len(model.caeros) == 0:
caero_points = np.empty((0, 3))
has_caero = False
ncaeros = 0
Expand All @@ -978,7 +982,6 @@ def make_caeros(self, model: BDF) -> tuple[np.ndarray, int, int, int, int, bool,
return out

all_control_surface_name, caero_control_surfaces, out = build_caero_paneling(model)
gui: MainWindow = self.gui
if all_control_surface_name:
gui.create_alternate_vtk_grid(
'caero_control_surfaces', color=PINK_FLOAT, line_width=5, opacity=1.0,
Expand Down Expand Up @@ -1149,7 +1152,7 @@ def set_caero_control_surface_grid(self, name: str, cs_box_ids: list[int],
"""
gui: MainWindow = self.gui
log = gui.log
log: SimpleLogger = gui.log
boxes_to_show, stored_msg = check_for_missing_control_surface_boxes(
name, cs_box_ids, box_id_to_caero_element_map, log,
store_msg=store_msg)
Expand Down Expand Up @@ -2015,42 +2018,36 @@ def _build_plotels(self, model: BDF) -> None:
representation = 'surface'

name = 'plotel'
color = RED_FLOAT
nastran_settings: NastranSettings = self.settings.nastran_settings
color = nastran_settings.plotel_color
gui.create_alternate_vtk_grid(
name, color=color, line_width=2, opacity=0.8,
point_size=5, representation=representation, is_visible=True)
point_size=5, representation=representation,
is_visible=True)

alt_grid: vtkUnstructuredGrid = gui.alt_grids[name]
if 1:
vtk_points: vtkPoints = alt_grid.GetPoints()

stacked_nids = np.hstack([
nids.ravel() for nids in elements_list])
unids = np.unique(stacked_nids)

nnodes = len(unids)
xyz_cid0 = np.zeros((nnodes, 3))
for inid, nid in enumerate(unids):
node = model.nodes[nid]
xyz_cid0[inid, :] = node.get_position()

elements_list2 = [np.searchsorted(unids, nids)
for nids in elements_list]
print(xyz_cid0)
print(elements_list2)
create_vtk_cells_of_constant_element_types(
alt_grid, elements_list2, etypes_list)
#gui.follower_nodes[name] = unids
vtk_points: vtkPoints = alt_grid.GetPoints()

xyz_cid0 = gui.scale_length(xyz_cid0)
#vtk_points.SetNumberOfPoints(nnodes)
vtk_points = numpy_to_vtk_points(xyz_cid0, points=vtk_points)
alt_grid.SetPoints(vtk_points)
else:
lines = np.array(lines, dtype='int32')
self._add_nastran_lines_to_grid(name, lines, model)
#print(alt_grid)
#print(vtk_points)
stacked_nids = np.hstack([
nids.ravel() for nids in elements_list])
unids = np.unique(stacked_nids)

nnodes = len(unids)
xyz_cid0 = np.zeros((nnodes, 3))
for inid, nid in enumerate(unids):
node = model.nodes[nid]
xyz_cid0[inid, :] = node.get_position()

elements_list2 = [np.searchsorted(unids, nids)
for nids in elements_list]
create_vtk_cells_of_constant_element_types(
alt_grid, elements_list2, etypes_list)
#gui.follower_nodes[name] = unids

xyz_cid0 = gui.scale_length(xyz_cid0)
#vtk_points.SetNumberOfPoints(nnodes)
vtk_points = numpy_to_vtk_points(xyz_cid0, points=vtk_points)
alt_grid.SetPoints(vtk_points)

def _map_elements1_no_quality(self,
model: BDF,
Expand Down
1 change: 0 additions & 1 deletion pyNastran/dev/bdf_vectorized3/alt_actor_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ def create_caero(gui: MainWindow,
_build_quads(gui, name,
aero_xyz, aero_elements,
line_width=5, color=YELLOW_FLOAT,
#representation='wire+surf',
representation='wire',
is_visible=False)
create_aesurf(gui, model,
Expand Down
7 changes: 2 additions & 5 deletions pyNastran/gui/gui_objects/alt_geometry_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ def __init__(self, parent, name: str,
valid_keys.sort()
raise RuntimeError('%r is not a valid representation\nvalid=[%s]' % (
representation, ', '.join(valid_keys)))

if line_width is None:
line_width = 1
if opacity is None:
opacity = 1.0
assert isinstance(line_width, int), line_width
assert isinstance(opacity, float), opacity
if label_actors is None:
label_actors = []

Expand Down
26 changes: 25 additions & 1 deletion pyNastran/gui/gui_objects/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from pyNastran.gui.qt_files.colors import (
BLACK_FLOAT, WHITE_FLOAT, GREY_FLOAT, ORANGE_FLOAT, HOT_PINK_FLOAT,
RED_FLOAT,
YELLOW_FLOAT, LIGHT_GREEN_FLOAT,
)
if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -105,12 +106,16 @@
MAGNIFY_MIN = 1
MAGNIFY_MAX = 10

PLOTEL_COLOR = RED_FLOAT
CAERO_COLOR = YELLOW_FLOAT
RBE_LINE_COLOR = LIGHT_GREEN_FLOAT
DISPLACEMENT_MODEL_SCALE = 0.1

NASTRAN_VERSIONS = ['Guess', 'MSC', 'NX', 'Optistruct']
NASTRAN_COLOR_KEYS = ['nastran_caero_color', 'nastran_rbe_line_color']
NASTRAN_COLOR_KEYS = [
'nastran_caero_color', 'nastran_rbe_line_color',
'nastran_plotel_color',
]
NASTRAN_STR_KEYS = ['nastran_version']
NASTRAN_BOOL_KEYS = [
'nastran_create_coords',
Expand All @@ -122,6 +127,7 @@
'nastran_is_constraints',
'nastran_is_shell_mcids',
'nastran_is_rbe',
'nastran_is_aero',

'nastran_displacement', 'nastran_velocity',
'nastran_acceleration', 'nastran_eigenvector', 'nastran_temperature',
Expand Down Expand Up @@ -240,6 +246,8 @@ def reset_settings(self):
self.is_bar_axes = True
self.is_shell_mcids = True
self.is_rbe = True
self.is_aero = True
self.is_plotel = True

self.stress = True
self.spring_stress = True
Expand Down Expand Up @@ -288,6 +296,7 @@ def reset_settings(self):
# colors
self.caero_color = CAERO_COLOR
self.rbe_line_color = RBE_LINE_COLOR
self.plotel_color = PLOTEL_COLOR

# ------------------------------------------------------

Expand Down Expand Up @@ -343,6 +352,21 @@ def set_rbe_line_color(self, color: ColorFloat, render: bool=True) -> None:
parent.vtk_interactor.Render()
parent.log_command('self.settings.nastran_settings.set_rbe_line_color(%s, %s, %s)' % color)

def set_plotel_color(self, color: ColorFloat, render: bool=True) -> None:
"""
Set the PLOTEL line color
Parameters
----------
color : ColorFloat
RGB values as floats
"""
self.plotel_color = color
parent = self.parent
if render:
parent.vtk_interactor.Render()
parent.log_command('self.settings.nastran_settings.set_plotel_color(%s, %s, %s)' % color)

def __repr__(self) -> str:
msg = '<NastranSettings>\n'
keys = object_attributes(self, mode='public', keys_to_skip=['parent'])
Expand Down
32 changes: 31 additions & 1 deletion pyNastran/gui/menus/preferences/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def __init__(self, data, win_parent=None):
data['caero_color'])
self.rbe_line_color_float, self.rbe_line_color_int = check_color(
data['rbe_line_color'])
self.plotel_color_float, self.plotel_color_int = check_color(
data['plotel_color'])

#self._shear_moment_torque_opacity = data['shear_moment_torque_opacity']
#self._shear_moment_torque_point_size = data['shear_moment_torque_point_size']
Expand All @@ -181,6 +183,7 @@ def __init__(self, data, win_parent=None):
self._nastran_create_coords = data['nastran_create_coords']
self._nastran_is_shell_mcids = data['nastran_is_shell_mcids']
self._nastran_is_rbe = data['nastran_is_rbe']
self._nastran_is_aero = data['nastran_is_aero']

self._nastran_stress = data['nastran_stress']
self._nastran_plate_stress = data['nastran_plate_stress']
Expand Down Expand Up @@ -433,6 +436,10 @@ def _set_widgets_nastran(self):
self.nastran_is_rbe_checkbox.setToolTip('Create MPC/RBE2/RBE3 dependent and indepdent nodes and lines')
self.nastran_is_rbe_checkbox.setChecked(self._nastran_is_rbe)

self.nastran_is_aero_checkbox = QCheckBox('Aero')
self.nastran_is_aero_checkbox.setToolTip('Create aero panel (CAERO/SPLINE/SET) visualization')
self.nastran_is_aero_checkbox.setChecked(self._nastran_is_aero)

self.nastran_create_coords_checkbox = QCheckBox('Coords')
self.nastran_create_coords_checkbox.setChecked(self._nastran_create_coords)

Expand Down Expand Up @@ -505,7 +512,11 @@ def _set_widgets_nastran(self):

self.rbe_line_color_label = QLabel("Default RBE2/RBE3 line color:")
self.rbe_line_color_edit = QPushButtonColor(self.rbe_line_color_int)
self.rbe_line_color_edit.setToolTip('Sets the color for the RBE2/RBE3 line colo')
self.rbe_line_color_edit.setToolTip('Sets the color for the RBE2/RBE3 lines')

self.plotel_color_label = QLabel("Default PLOTEL color:")
self.plotel_color_edit = QPushButtonColor(self.plotel_color_int)
self.plotel_color_edit.setToolTip('Sets the color for the PLOTELs')

#-----------------------------------------------------------------------
# closing
Expand Down Expand Up @@ -837,6 +848,9 @@ def _get_nastran_vboxs(self) -> tuple[QVBoxLayout, QVBoxLayout, QVBoxLayout]:
irow += 1
grid_nastran_actors.addWidget(self.rbe_line_color_label, irow, 0)
grid_nastran_actors.addWidget(self.rbe_line_color_edit, irow, 1)
irow += 1
grid_nastran_actors.addWidget(self.plotel_color_label, irow, 0)
grid_nastran_actors.addWidget(self.plotel_color_edit, irow, 1)

vbox_nastran_actors = QVBoxLayout()
self.nastran_actors_label = QLabel('Nastran Actors:')
Expand Down Expand Up @@ -864,6 +878,7 @@ def _get_grid_nastran_layout(self) -> QGridLayout:
irow += 1

grid_nastran.addWidget(self.nastran_is_shell_mcids_checkbox, irow, 0)
grid_nastran.addWidget(self.nastran_is_aero_checkbox, irow, 1)
irow += 1

grid_nastran.addWidget(self.nastran_is_bar_axes_checkbox, irow, 0)
Expand Down Expand Up @@ -959,6 +974,7 @@ def _set_nastran_connections(self):
self.nastran_is_bar_axes_checkbox.clicked.connect(partial(on_nastran, self, 'is_bar_axes'))
self.nastran_create_coords_checkbox.clicked.connect(partial(on_nastran, self, 'create_coords'))
self.nastran_is_shell_mcids_checkbox.clicked.connect(partial(on_nastran, self, 'is_shell_mcids'))
self.nastran_is_aero_checkbox.clicked.connect(partial(on_nastran, self, 'is_aero'))
self.nastran_is_rbe_checkbox.clicked.connect(partial(on_nastran, self, 'is_rbe'))
self.nastran_is_constraints_checkbox.clicked.connect(partial(on_nastran, self, 'is_constraints'))

Expand All @@ -985,6 +1001,7 @@ def _set_nastran_connections(self):
# colors
self.caero_color_edit.clicked.connect(self.on_caero_color)
self.rbe_line_color_edit.clicked.connect(self.on_rbe_line_color)
self.plotel_color_edit.clicked.connect(self.on_plotel_color)

def set_connections(self):
"""creates the actions for the menu"""
Expand Down Expand Up @@ -1251,6 +1268,18 @@ def on_rbe_line_color(self) -> None:
self.rbe_line_color_int = rgb_color_ints
self.rbe_line_color_float = rgb_color_floats

def on_plotel_color(self) -> None:
""" Choose an RBE color"""
title = "Choose a default PLOTEL line color"
rgb_color_ints = self.plotel_color_int
color_edit = self.plotel_color_edit
func_name = 'set_plotel_color'
passed, rgb_color_ints, rgb_color_floats = self._load_nastran_color(
title, color_edit, rgb_color_ints, func_name)
if passed:
self.plotel_color_int = rgb_color_ints
self.plotel_color_float = rgb_color_floats

def on_highlight_color(self) -> None:
""" Choose a highlight color"""
title = "Choose a highlight color"
Expand Down Expand Up @@ -1596,6 +1625,7 @@ def main(): # pragma: no cover

'caero_color': (0.2, 0.7, 0.4),
'rbe_line_color': (0.5, 0.6, 0.7),
'plotel_color': (0.5, 0.6, 0.7),
'nastran_version' : 'MSC',

'min_clip' : 0.,
Expand Down
1 change: 1 addition & 0 deletions pyNastran/gui/menus/preferences/preferences_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def set_preferences_menu(self) -> None:

'caero_color' : nastran_settings.caero_color,
'rbe_line_color': nastran_settings.rbe_line_color,
'plotel_color': nastran_settings.plotel_color,

'use_startup_directory': settings.use_startup_directory,

Expand Down
2 changes: 1 addition & 1 deletion pyNastran/gui/qt_files/mouse_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def on_area_pick_callback(self, eids: list[int],

def on_area_pick(self, is_eids: bool=True,
is_nids: bool=True,
representation: str='wire+points',
representation: str='wire+point',
name=None,
callback: Optional[Callable]=None,
cleanup: bool=True,
Expand Down
1 change: 1 addition & 0 deletions pyNastran/gui/utils/qt/qsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class QSettingsLike2:
'corner_text_color', 'annotation_color',
'screen_shape', 'screen_position',
'nastran_caero_color', 'nastran_rbe_line_color',
'nastran_plotel_color',
'cart3d_fluent_include', 'cart3d_fluent_remove',
'units_model_in',
}
Expand Down

0 comments on commit 1c3e80e

Please sign in to comment.