Skip to content

Commit 26833b9

Browse files
committed
Fix MakieExt and ControlPlotsExt define VortexStepMethod.plot_geometry for the same type
Fixes #236
1 parent 7fb28e9 commit 26833b9

3 files changed

Lines changed: 86 additions & 11 deletions

File tree

ext/VortexStepMethodControlPlotsExt.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import VortexStepMethod: calculate_filaments_for_plotting
66
export plot_wing, plot_circulation_distribution, plot_geometry, plot_distribution,
77
plot_polars, save_plot, show_plot, plot_polar_data, plot_combined_analysis
88

9+
# Set this extension as the active plotting backend when loaded
10+
function __init__()
11+
VortexStepMethod._PLOT_BACKEND[] = VortexStepMethod.ControlPlotsBackend()
12+
end
13+
914
"""
1015
set_plot_style(titel_size=16; use_tex=false)
1116
@@ -284,7 +289,8 @@ Plot wing geometry from different viewpoints and optionally save/show plots.
284289
- `use_tex`: if the external `pdflatex` command shall be used (default: false)
285290
286291
"""
287-
function VortexStepMethod.plot_geometry(body_aero::BodyAerodynamics, title;
292+
function VortexStepMethod.plot_geometry(body_aero::BodyAerodynamics, title,
293+
::VortexStepMethod.ControlPlotsBackend;
288294
data_type=".pdf",
289295
save_path=nothing,
290296
is_save=false,
@@ -342,7 +348,8 @@ Plot spanwise distributions of aerodynamic properties.
342348
- `is_show`: Whether to display plots (default: true)
343349
- `use_tex`: if the external `pdflatex` command shall be used
344350
"""
345-
function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, label_list;
351+
function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, label_list,
352+
::VortexStepMethod.ControlPlotsBackend;
346353
title="spanwise_distribution",
347354
data_type=".pdf",
348355
save_path=nothing,
@@ -547,7 +554,8 @@ Plot polar data comparing different solvers and configurations.
547554
function VortexStepMethod.plot_polars(
548555
solver_list,
549556
body_aero_list,
550-
label_list;
557+
label_list,
558+
::VortexStepMethod.ControlPlotsBackend;
551559
literature_path_list=String[],
552560
angle_range=range(0, 20, 2),
553561
angle_type="angle_of_attack",
@@ -755,7 +763,8 @@ relative to the 2d airfoil or panel chord line.
755763
- `is_show`: Whether to display plots (default: true)
756764
- `use_tex`: if the external `pdflatex` command shall be used
757765
"""
758-
function VortexStepMethod.plot_polar_data(body_aero::BodyAerodynamics;
766+
function VortexStepMethod.plot_polar_data(body_aero::BodyAerodynamics,
767+
::VortexStepMethod.ControlPlotsBackend;
759768
alphas=collect(deg2rad.(-5:0.3:25)),
760769
delta_tes = collect(deg2rad.(-5:0.3:25)),
761770
is_show = true,
@@ -827,7 +836,8 @@ See individual functions for detailed parameter descriptions.
827836
function VortexStepMethod.plot_combined_analysis(
828837
solver,
829838
body_aero,
830-
results;
839+
results,
840+
::VortexStepMethod.ControlPlotsBackend;
831841
solver_label="VSM",
832842
labels=nothing,
833843
angle_range=range(0, 20, length=20),

ext/VortexStepMethodMakieExt.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import VortexStepMethod: calculate_filaments_for_plotting
55
export plot_geometry, plot_distribution, plot_polars, save_plot, show_plot,
66
plot_polar_data, plot_combined_analysis
77

8+
# Set this extension as the active plotting backend when loaded
9+
function __init__()
10+
VortexStepMethod._PLOT_BACKEND[] = VortexStepMethod.MakieBackend()
11+
end
12+
813
# Global storage for panel mesh observables (for dynamic plotting)
914
const PANEL_MESH_OBSERVABLES = Ref{Union{Nothing,Dict}}(nothing)
1015

@@ -479,7 +484,8 @@ Plot wing geometry from different viewpoints using Makie.
479484
- `view_azimuth`: View azimuth angle in degrees (default: -120)
480485
- `use_tex`: Ignored for Makie (default: false)
481486
"""
482-
function VortexStepMethod.plot_geometry(body_aero::BodyAerodynamics, title;
487+
function VortexStepMethod.plot_geometry(body_aero::BodyAerodynamics, title,
488+
::VortexStepMethod.MakieBackend;
483489
data_type=nothing,
484490
save_path=nothing,
485491
is_save=false,
@@ -535,7 +541,8 @@ Plot spanwise distributions of aerodynamic properties using Makie.
535541
- `is_show`: Whether to display (default: true)
536542
- `use_tex`: Ignored for Makie (default: false)
537543
"""
538-
function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, label_list;
544+
function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, label_list,
545+
::VortexStepMethod.MakieBackend;
539546
title="spanwise_distribution",
540547
data_type=nothing,
541548
save_path=nothing,
@@ -700,7 +707,8 @@ Plot polar data comparing different solvers using Makie.
700707
function VortexStepMethod.plot_polars(
701708
solver_list,
702709
body_aero_list,
703-
label_list;
710+
label_list,
711+
::VortexStepMethod.MakieBackend;
704712
literature_path_list=String[],
705713
angle_range=range(0, 20, 2),
706714
angle_type="angle_of_attack",
@@ -882,7 +890,8 @@ Plot polar data (Cl, Cd, Cm) as 3D surfaces using Makie.
882890
- `is_show`: Whether to display (default: true)
883891
- `use_tex`: Ignored for Makie (default: false)
884892
"""
885-
function VortexStepMethod.plot_polar_data(body_aero::BodyAerodynamics;
893+
function VortexStepMethod.plot_polar_data(body_aero::BodyAerodynamics,
894+
::VortexStepMethod.MakieBackend;
886895
alphas=collect(deg2rad.(-5:0.3:25)),
887896
delta_tes=collect(deg2rad.(-5:0.3:25)),
888897
is_show=true,
@@ -972,7 +981,8 @@ Create combined multi-panel figure with geometry, polar data, distributions, and
972981
function VortexStepMethod.plot_combined_analysis(
973982
solver,
974983
body_aero,
975-
results;
984+
results,
985+
::VortexStepMethod.MakieBackend;
976986
solver_label="VSM",
977987
labels=nothing,
978988
angle_range=range(0, 20, length=20),

src/VortexStepMethod.jl

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,32 @@ export load_polar_data
4646
export plot_circulation_distribution, plot_combined_analysis, plot_distribution, plot_geometry,
4747
plot_polar_data, plot_polars, save_plot, show_plot
4848

49-
# the following functions are defined in ext/VortexStepMethodExt.jl
49+
# Backend dispatch types for multi-backend support (Makie and ControlPlots can coexist)
50+
abstract type PlotBackend end
51+
struct MakieBackend <: PlotBackend end
52+
struct ControlPlotsBackend <: PlotBackend end
53+
export PlotBackend, MakieBackend, ControlPlotsBackend
54+
55+
const _PLOT_BACKEND = Ref{Union{Nothing, PlotBackend}}(nothing)
56+
57+
"""
58+
set_plot_backend!(backend::PlotBackend)
59+
60+
Select the active plotting backend when both Makie and ControlPlots are loaded.
61+
62+
# Example
63+
```julia
64+
set_plot_backend!(MakieBackend())
65+
set_plot_backend!(ControlPlotsBackend())
66+
```
67+
"""
68+
function set_plot_backend!(backend::PlotBackend)
69+
_PLOT_BACKEND[] = backend
70+
end
71+
export set_plot_backend!
72+
73+
# Generic stubs — extended by MakieExt and ControlPlotsExt with a PlotBackend argument.
74+
# The no-backend-argument wrappers below route through the active backend.
5075
function plot_geometry end
5176
function plot_distribution end
5277
function plot_circulation_distribution end
@@ -56,6 +81,36 @@ function show_plot end
5681
function plot_polar_data end
5782
function plot_combined_analysis end
5883

84+
function _active_backend()
85+
b = _PLOT_BACKEND[]
86+
isnothing(b) && error(
87+
"No plotting backend loaded. Load Makie or ControlPlots first, " *
88+
"or call set_plot_backend!(MakieBackend()) / set_plot_backend!(ControlPlotsBackend()) " *
89+
"when both are loaded."
90+
)
91+
b
92+
end
93+
94+
function plot_geometry(body_aero, title; kwargs...)
95+
plot_geometry(body_aero, title, _active_backend(); kwargs...)
96+
end
97+
98+
function plot_distribution(y_coordinates_list, results_list, label_list; kwargs...)
99+
plot_distribution(y_coordinates_list, results_list, label_list, _active_backend(); kwargs...)
100+
end
101+
102+
function plot_polars(solver_list, body_aero_list, label_list; kwargs...)
103+
plot_polars(solver_list, body_aero_list, label_list, _active_backend(); kwargs...)
104+
end
105+
106+
function plot_polar_data(body_aero; kwargs...)
107+
plot_polar_data(body_aero, _active_backend(); kwargs...)
108+
end
109+
110+
function plot_combined_analysis(solver, body_aero, results; kwargs...)
111+
plot_combined_analysis(solver, body_aero, results, _active_backend(); kwargs...)
112+
end
113+
59114
"""
60115
const MVec3 = MVector{3, Float64}
61116

0 commit comments

Comments
 (0)