Skip to content

Commit

Permalink
Changed grid button to be toggleable, with initial setting of each gr…
Browse files Browse the repository at this point in the history
…aph obeying the current check state
  • Loading branch information
mlauer154 committed Jun 13, 2024
1 parent d30cfb9 commit 7e7b459
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
29 changes: 14 additions & 15 deletions pymead/gui/analysis_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@


class AnalysisGraph:
def __init__(self, theme: dict, pen=None, size: tuple = (1000, 300), background_color: str = 'w'):
def __init__(self, theme: dict, pen=None, size: tuple = (1000, 300), background_color: str = 'w',
grid: bool = False):
pg.setConfigOptions(antialias=True)

if pen is None:
Expand All @@ -20,6 +21,7 @@ def __init__(self, theme: dict, pen=None, size: tuple = (1000, 300), background_

self.v = self.w.addPlot(pen=pen)
self.v.invertY(True)
self.v.showGrid(x=grid, y=grid)
self.legend = self.v.addLegend(offset=(300, 20))
self.set_formatting(theme=theme)

Expand All @@ -45,7 +47,7 @@ def set_legend_label_format(self, theme: dict):


class ResidualGraph:
def __init__(self, theme: dict, pen=None, size: tuple = (1000, 300)):
def __init__(self, theme: dict, pen=None, size: tuple = (1000, 300), grid: bool = False):
pg.setConfigOptions(antialias=True)

if pen is None:
Expand All @@ -55,6 +57,7 @@ def __init__(self, theme: dict, pen=None, size: tuple = (1000, 300)):

self.v = self.w.addPlot(pen=pen)
self.v.setLogMode(x=False, y=True)
self.v.showGrid(x=grid, y=grid)
self.legend = self.v.addLegend(offset=(-5, 5))
target_pen = self.make_target_pen(theme)

Expand Down Expand Up @@ -108,7 +111,7 @@ def set_legend_label_format(self, theme: dict):

class SinglePolarGraph:
def __init__(self, theme: dict, graph_color_key: str, x_axis_label: str, y_axis_label: str,
pen=None, size: tuple = (350, 300)):
pen=None, size: tuple = (350, 300), grid: bool = False):
pg.setConfigOptions(antialias=True)

if pen is None:
Expand All @@ -117,6 +120,7 @@ def __init__(self, theme: dict, graph_color_key: str, x_axis_label: str, y_axis_
self.w = pg.GraphicsLayoutWidget(show=True, size=size)

self.v = self.w.addPlot(pen=pen)
self.v.showGrid(x=grid, y=grid)

# Set up the line
self.plot_items = [self.v.plot(pen=pg.mkPen(color=theme[graph_color_key]))]
Expand Down Expand Up @@ -147,16 +151,16 @@ def set_formatting(self, theme: dict):


class PolarGraphCollection(QWidget):
def __init__(self, theme: dict):
def __init__(self, theme: dict, grid: bool = False):
self.polar_graphs = [
SinglePolarGraph(theme=theme, graph_color_key="polar-color-1",
x_axis_label="&alpha; (&deg;)", y_axis_label="C<sub>l</sub>"),
x_axis_label="&alpha; (&deg;)", y_axis_label="C<sub>l</sub>", grid=grid),
SinglePolarGraph(theme=theme, graph_color_key="polar-color-2",
x_axis_label="C<sub>d</sub>", y_axis_label="C<sub>l</sub>"),
x_axis_label="C<sub>d</sub>", y_axis_label="C<sub>l</sub>", grid=grid),
SinglePolarGraph(theme=theme, graph_color_key="polar-color-3",
x_axis_label="&alpha; (&deg;)", y_axis_label="L/D"),
x_axis_label="&alpha; (&deg;)", y_axis_label="L/D", grid=grid),
SinglePolarGraph(theme=theme, graph_color_key="polar-color-4",
x_axis_label="&alpha; (&deg;)", y_axis_label="C<sub>m</sub>")
x_axis_label="&alpha; (&deg;)", y_axis_label="C<sub>m</sub>", grid=grid)
]
super().__init__(parent=None)
self.lay = QGridLayout()
Expand Down Expand Up @@ -185,11 +189,6 @@ def clear_data(self):
for polar_graph in self.polar_graphs:
polar_graph.plot_items[0].setData([], [])

def toggle_grid(self):
def toggle_grid(self, checked: bool):
for polar_graph in self.polar_graphs:
x_state = polar_graph.v.ctrl.xGridCheck.checkState()
y_state = polar_graph.v.ctrl.yGridCheck.checkState()
if x_state or y_state:
polar_graph.v.showGrid(x=False, y=False)
else:
polar_graph.v.showGrid(x=True, y=True)
polar_graph.v.showGrid(x=checked, y=checked)
31 changes: 23 additions & 8 deletions pymead/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,11 @@ def single_airfoil_inviscid_analysis(self, plot_cp: bool):
return

if self.analysis_graph is None:
self.analysis_graph = AnalysisGraph(theme=self.themes[self.current_theme],
background_color=self.themes[self.current_theme]["graph-background-color"])
self.analysis_graph = AnalysisGraph(
theme=self.themes[self.current_theme],
background_color=self.themes[self.current_theme]["graph-background-color"],
grid=self.main_icon_toolbar.buttons["grid"]["button"].isChecked()
)
self.add_new_tab_widget(self.analysis_graph.w, "Analysis")
name = f"[{self.n_analyses}] P ({selected_airfoil_name}, \u03b1 = {alpha:.1f}\u00b0)"
pg_plot_handle = self.analysis_graph.v.plot(pen=pg.mkPen(color=self.pen(self.n_converged_analyses)[0],
Expand Down Expand Up @@ -1362,8 +1365,11 @@ def single_airfoil_viscous_analysis(self):
if aero_data['converged'] and not aero_data['errored_out'] and not aero_data['timed_out']:
if self.analysis_graph is None:
# TODO: Need to set analysis_graph to None if analysis window is closed! Might also not want to allow geometry docking window to be closed
self.analysis_graph = AnalysisGraph(theme=self.themes[self.current_theme],
background_color=self.themes[self.current_theme]["graph-background-color"])
self.analysis_graph = AnalysisGraph(
theme=self.themes[self.current_theme],
background_color=self.themes[self.current_theme]["graph-background-color"],
grid=self.main_icon_toolbar.buttons["grid"]["button"].isChecked()
)
self.add_new_tab_widget(self.analysis_graph.w, "Analysis")

if xfoil_settings["visc"]:
Expand Down Expand Up @@ -1543,8 +1549,11 @@ def display_svg():
def plot_mses_pressure_coefficient_distribution(self, aero_data: dict, mea: MEA, mses_settings: dict):
if self.analysis_graph is None:
# Need to set analysis_graph to None if analysis window is closed
self.analysis_graph = AnalysisGraph(theme=self.themes[self.current_theme],
background_color=self.themes[self.current_theme]["graph-background-color"])
self.analysis_graph = AnalysisGraph(
theme=self.themes[self.current_theme],
background_color=self.themes[self.current_theme]["graph-background-color"],
grid=self.main_icon_toolbar.buttons["grid"]["button"].isChecked()
)
self.add_new_tab_widget(self.analysis_graph.w, "Analysis")

# Get the maximum physical extent of the airfoil system in the x-direction (used to prevent showing
Expand Down Expand Up @@ -1933,7 +1942,10 @@ def progress_update(self, status: str, data: object):
self.switch_to_tab("Residuals")
elif status == "mses_residual" and isinstance(data, tuple):
if self.residual_graph is None:
self.residual_graph = ResidualGraph(theme=self.themes[self.current_theme])
self.residual_graph = ResidualGraph(
theme=self.themes[self.current_theme],
grid=self.main_icon_toolbar.buttons["grid"]["button"].isChecked()
)
self.add_new_tab_widget(self.residual_graph.w, "Residuals")
self.switch_to_tab("Residuals")

Expand Down Expand Up @@ -1962,7 +1974,10 @@ def progress_update(self, status: str, data: object):
self.polar_graph_collection.clear_data()
elif status == "plot_polars" and isinstance(data, dict):
if self.polar_graph_collection is None:
self.polar_graph_collection = PolarGraphCollection(theme=self.themes[self.current_theme])
self.polar_graph_collection = PolarGraphCollection(
theme=self.themes[self.current_theme],
grid=self.main_icon_toolbar.buttons["grid"]["button"].isChecked()
)
self.add_new_tab_widget(self.polar_graph_collection, "Polars")
self.switch_to_tab("Polars")
self.polar_graph_collection.set_data(data)
Expand Down

0 comments on commit 7e7b459

Please sign in to comment.