From f1aa2fede2511330a6ec6e2897981e2195bdadb0 Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Fri, 5 Apr 2024 11:52:05 +0200 Subject: [PATCH 1/8] move Makie-based visualization routines into ext/ folder --- .github/workflows/ci.yml | 2 ++ Project.toml | 10 ++++++++++ ext/HOHQMeshMakieExt.jl | 24 ++++++++++++++++++++++++ {src/Viz => ext}/VizMesh.jl | 0 {src/Viz => ext}/VizProject.jl | 0 src/HOHQMesh.jl | 24 ++++++++++++------------ src/Viz/visualization.jl | 10 ++++++++++ 7 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 ext/HOHQMeshMakieExt.jl rename {src/Viz => ext}/VizMesh.jl (100%) rename {src/Viz => ext}/VizProject.jl (100%) create mode 100644 src/Viz/visualization.jl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82c23f02..d5fcdb2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,8 @@ jobs: env: PYTHON: "" - uses: julia-actions/julia-processcoverage@v1 + with: + directories: src,examples,ext - uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Project.toml b/Project.toml index f49f5b63..bd5a5c1c 100644 --- a/Project.toml +++ b/Project.toml @@ -7,7 +7,17 @@ version = "0.2.4-pre" HOHQMesh_jll = "1d5cbd98-5122-5a8a-bea1-c186d986ee7f" Requires = "ae029012-a4dd-5104-9daa-d747884805df" +[weakdeps] +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" + +[extensions] +HOHQMeshMakieExt = "Makie" + [compat] HOHQMesh_jll = "1.0" +Makie = "0.20" Requires = "1.1.3" julia = "1.6" + +[extras] +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" diff --git a/ext/HOHQMeshMakieExt.jl b/ext/HOHQMeshMakieExt.jl new file mode 100644 index 00000000..d42597ec --- /dev/null +++ b/ext/HOHQMeshMakieExt.jl @@ -0,0 +1,24 @@ +# Package extension for adding Makie-based features to HOHQMesh.jl +module HOHQMeshMakieExt + +# Required for visualization code +if isdefined(Base, :get_extension) + using Makie +else + # Until Julia v1.9 is the minimum required version for HOHQMesh.jl, we still support Requires.jl + using ..Makie +end + +# Use all exported symbols to avoid having to rewrite all the visualization routines +using HOHQMesh + +# Use additional symbols that are not exported +using HOHQMesh: Project, hasBackgroundGrid, projectBounds, projectGrid + +# Import functions such that they can be extended with new methods +import HOHQMesh: plotProject!, updatePlot! + +include("VizMesh.jl") +include("VizProject.jl") + +end \ No newline at end of file diff --git a/src/Viz/VizMesh.jl b/ext/VizMesh.jl similarity index 100% rename from src/Viz/VizMesh.jl rename to ext/VizMesh.jl diff --git a/src/Viz/VizProject.jl b/ext/VizProject.jl similarity index 100% rename from src/Viz/VizProject.jl rename to ext/VizProject.jl diff --git a/src/HOHQMesh.jl b/src/HOHQMesh.jl index 312d4421..553c1a23 100644 --- a/src/HOHQMesh.jl +++ b/src/HOHQMesh.jl @@ -7,19 +7,13 @@ using HOHQMesh_jll: HOHQMesh_jll using Requires: @require function __init__() - # Enable features that depend on the availability of the Makie package - @require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin - using .Makie - if isdefined(Makie, :to_textsize) - @warn "You seem to be using an older version of Makie (< v0.19). Some plotting functions may not work." + # Enable features that depend on the availability of the Makie package + # Until Julia v1.9 is the minimum required version for HOHQMesh.jl, we still support Requires.jl + @static if !isdefined(Base, :get_extension) + @require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin + include("../ext/HOHQMeshMakieExt.jl") + end end - include("Viz/VizProject.jl") - include("Viz/VizMesh.jl") - # Make the actual plotting routines available - export plotProject!, updatePlot! - # Make plotting constants available for easier use - export MODEL, GRID, MESH, EMPTY, REFINEMENTS, ALL - end end # @@ -53,6 +47,9 @@ include("Project/SmootherAPI.jl") # Main routine that uses HOHQMesh to generate a mesh from an interactive `Project` include("Mesh/Meshing.jl") +# Empty routines for visualization extended in `ext/HOHQMeshMakieExt.jl` +include("Viz/visualization.jl") + # Generic main function to generate a mesh from a control file # or an interactive mesh `Project` export generate_mesh @@ -149,6 +146,9 @@ export undo, undoActionName, # Functions from `Meshing.jl`, generate_mesh is already exported export remove_mesh! +# Functions and constants for visualization purposes +export plotProject!, updatePlot! +export MODEL, GRID, MESH, EMPTY, REFINEMENTS, ALL """ generate_mesh(control_file; diff --git a/src/Viz/visualization.jl b/src/Viz/visualization.jl new file mode 100644 index 00000000..7ad77524 --- /dev/null +++ b/src/Viz/visualization.jl @@ -0,0 +1,10 @@ + +# Convenience constants to make plotting easier +const MODEL = 1; const GRID = 2; const MESH = 4; const EMPTY = 0 +const REFINEMENTS = 8; const ALL = 15 + +# Add function definitions here such that they can be exported from HOHQMesh.jl +# and extended in the HOHQMeshMakieExt package extension or by the +# Makie-specific code loaded by Requires.jl +function plotProject! end +function updatePlot! end \ No newline at end of file From d02c8e58884e359bfef4591d968c01af52700430 Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Fri, 5 Apr 2024 12:12:57 +0200 Subject: [PATCH 2/8] fix some comments --- src/HOHQMesh.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HOHQMesh.jl b/src/HOHQMesh.jl index 553c1a23..2a529a71 100644 --- a/src/HOHQMesh.jl +++ b/src/HOHQMesh.jl @@ -18,8 +18,8 @@ end # # Include interactive mesh functionality for creating, reading, and writing a model for HOHQMesh. -# Note, The visualization routines are included above in the `__init__` because -# Makie is required. +# Note, Empty visualization routines are included and exported below but are extended within +# `../ext/HOHQMeshMakieExt.jl` # # Core interactive tool routines for control file readin, curve evaluation, etc. From b46e8632fa274ee1bfb29edb995dfe033d63b61f Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Fri, 5 Apr 2024 13:08:16 +0200 Subject: [PATCH 3/8] remove unused legacy function --- ext/VizProject.jl | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ext/VizProject.jl b/ext/VizProject.jl index 718a4ffa..b2d04ac2 100644 --- a/ext/VizProject.jl +++ b/ext/VizProject.jl @@ -113,20 +113,6 @@ function plotProject!(proj::Project, plotOptions::Int = 0) end -""" - updatePlot!(proj::Project) - -This version replots the figure with the current options. Legacy. -""" -function updatePlot!(proj::Project) - if !isnothing(proj.plt) - proj.plt = Figure(size = (1000, 1000)) - plotOptions = proj.plotOptions - plotProject!(proj, plotOptions) - end -end - - """ updatePlot!(proj::Project, plotOptions::Int) From 948536484c3a3df87d8541d2cc620181a5ccd5cf Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Fri, 5 Apr 2024 13:25:58 +0200 Subject: [PATCH 4/8] cleanup to remove unused function and move docstrings --- ext/VizProject.jl | 26 -------------------------- src/Viz/visualization.jl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ext/VizProject.jl b/ext/VizProject.jl index b2d04ac2..dedeaad9 100644 --- a/ext/VizProject.jl +++ b/ext/VizProject.jl @@ -1,21 +1,4 @@ -const MODEL = 1; const GRID = 2; const MESH = 4; const EMPTY = 0 -const REFINEMENTS = 8; const ALL = 15 - - -""" - plotProject!(proj::Project, plotOptions::Int = 0) - -Plot objects specified by the `plotOptions`. Construct the `plotOptions` by the sum -of what is to be drawn from the choices `MODEL`, `GRID`, `MESH`, `REFINEMENTS`. - -Example: To plot the model and the grid, `plotOptions = MODEL + GRID`. To plot -just the mesh, `plotOptions = MESH`. - -To plot everything, `plotOptions = MODEL + GRID + MESH + REFINEMENTS` - -Contents are overlaid in the order: GRID, MESH, MODEL, REFINEMENTS -""" function plotProject!(proj::Project, plotOptions::Int = 0) if isnothing(proj.plt) @@ -113,15 +96,6 @@ function plotProject!(proj::Project, plotOptions::Int = 0) end -""" - updatePlot!(proj::Project, plotOptions::Int) - -Replot with the new plotOptions = combinations (sums) of - - GRID, MESH, MODEL, REFINEMENTS - -Example: updatePlot!(p, MESH + MODEL) -""" function updatePlot!(proj::Project, plotOptions::Int) if !isnothing(proj.plt) proj.plt = Figure(size = (1000, 1000)) diff --git a/src/Viz/visualization.jl b/src/Viz/visualization.jl index 7ad77524..397dee64 100644 --- a/src/Viz/visualization.jl +++ b/src/Viz/visualization.jl @@ -6,5 +6,35 @@ const REFINEMENTS = 8; const ALL = 15 # Add function definitions here such that they can be exported from HOHQMesh.jl # and extended in the HOHQMeshMakieExt package extension or by the # Makie-specific code loaded by Requires.jl + +""" + plotProject!(proj::Project, plotOptions::Int = 0) + +Plot objects specified by the `plotOptions`. Construct the `plotOptions` by the sum +of what is to be drawn from the choices `MODEL`, `GRID`, `MESH`, `REFINEMENTS`. + +Example: To plot the model and the grid, `plotOptions = MODEL + GRID`. To plot +just the mesh, `plotOptions = MESH`. + +To plot everything, `plotOptions = MODEL + GRID + MESH + REFINEMENTS` + +Contents are overlaid in the order: GRID, MESH, MODEL, REFINEMENTS +!!! note + The function implementation is found in `ext/VizProject.jl`. +""" function plotProject! end + + +""" + updatePlot!(proj::Project, plotOptions::Int) + +Replot with the new plotOptions = combinations (sums) of + + GRID, MESH, MODEL, REFINEMENTS + +Example: updatePlot!(p, MESH + MODEL) + +!!! note + The function implementation is found in `ext/VizProject.jl`. +""" function updatePlot! end \ No newline at end of file From 13b28f3e03382d982912e38456ccd99c3362692d Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Fri, 5 Apr 2024 13:43:45 +0200 Subject: [PATCH 5/8] remove unnecessary test --- test/test_visualization.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test_visualization.jl b/test/test_visualization.jl index a4be600e..cba854b5 100644 --- a/test/test_visualization.jl +++ b/test/test_visualization.jl @@ -87,8 +87,6 @@ using CairoMakie meshFileFormat = getMeshFileFormat(p_visu) setFileNames!(p_visu, meshFileFormat) - @test_nowarn updatePlot!(p_visu) - # Create the mesh which contains a plotting update for ISM-V2 @test_nowarn generate_mesh(p_visu) From 1b2f813ee6fb3ac9a25615596aaf8e243514709c Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Mon, 8 Apr 2024 07:03:16 +0200 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Hendrik Ranocha --- src/Viz/visualization.jl | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Viz/visualization.jl b/src/Viz/visualization.jl index 397dee64..d5b04136 100644 --- a/src/Viz/visualization.jl +++ b/src/Viz/visualization.jl @@ -18,11 +18,10 @@ just the mesh, `plotOptions = MESH`. To plot everything, `plotOptions = MODEL + GRID + MESH + REFINEMENTS` -Contents are overlaid in the order: GRID, MESH, MODEL, REFINEMENTS -!!! note - The function implementation is found in `ext/VizProject.jl`. +Contents are overlaid in the order: `GRID`, `MESH`, `MODEL`, `REFINEMENTS` """ function plotProject! end +# Note: The function implementation is found in `ext/VizProject.jl`. """ @@ -32,9 +31,7 @@ Replot with the new plotOptions = combinations (sums) of GRID, MESH, MODEL, REFINEMENTS -Example: updatePlot!(p, MESH + MODEL) - -!!! note - The function implementation is found in `ext/VizProject.jl`. +Example: `updatePlot!(p, MESH + MODEL)` """ -function updatePlot! end \ No newline at end of file +function updatePlot! end +# Note: The function implementation is found in `ext/VizProject.jl`. \ No newline at end of file From b3a6abcc004340c6373fd649d40faab649d41a81 Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Mon, 8 Apr 2024 07:09:58 +0200 Subject: [PATCH 7/8] revert to include legacy version of updatePlot function to avoid breaking changes --- ext/VizProject.jl | 11 +++++++++++ test/test_visualization.jl | 2 ++ 2 files changed, 13 insertions(+) diff --git a/ext/VizProject.jl b/ext/VizProject.jl index dedeaad9..6b2550c8 100644 --- a/ext/VizProject.jl +++ b/ext/VizProject.jl @@ -96,6 +96,17 @@ function plotProject!(proj::Project, plotOptions::Int = 0) end +# updatePlot!(proj::Project) +# This version replots the figure with the current options. Legacy. +function updatePlot!(proj::Project) + if !isnothing(proj.plt) + proj.plt = Figure(size = (1000, 1000)) + plotOptions = proj.plotOptions + plotProject!(proj, plotOptions) + end +end + + function updatePlot!(proj::Project, plotOptions::Int) if !isnothing(proj.plt) proj.plt = Figure(size = (1000, 1000)) diff --git a/test/test_visualization.jl b/test/test_visualization.jl index cba854b5..a4be600e 100644 --- a/test/test_visualization.jl +++ b/test/test_visualization.jl @@ -87,6 +87,8 @@ using CairoMakie meshFileFormat = getMeshFileFormat(p_visu) setFileNames!(p_visu, meshFileFormat) + @test_nowarn updatePlot!(p_visu) + # Create the mesh which contains a plotting update for ISM-V2 @test_nowarn generate_mesh(p_visu) From c962b9bcacc0afadba050b7a25a243a27bfe3f3e Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Tue, 9 Apr 2024 09:50:34 +0200 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: Michael Schlottke-Lakemper --- src/Viz/visualization.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Viz/visualization.jl b/src/Viz/visualization.jl index d5b04136..9a0081e5 100644 --- a/src/Viz/visualization.jl +++ b/src/Viz/visualization.jl @@ -19,6 +19,10 @@ just the mesh, `plotOptions = MESH`. To plot everything, `plotOptions = MODEL + GRID + MESH + REFINEMENTS` Contents are overlaid in the order: `GRID`, `MESH`, `MODEL`, `REFINEMENTS` + +!!! note "Requires Makie.jl" + Please note that for this function to work, you need to load Makie.jl + in your REPL (e.g., by calling `using GLMakie`). """ function plotProject! end # Note: The function implementation is found in `ext/VizProject.jl`. @@ -32,6 +36,10 @@ Replot with the new plotOptions = combinations (sums) of GRID, MESH, MODEL, REFINEMENTS Example: `updatePlot!(p, MESH + MODEL)` + +!!! note "Requires Makie.jl" + Please note that for this function to work, you need to load Makie.jl + in your REPL (e.g., by calling `using GLMakie`). """ function updatePlot! end # Note: The function implementation is found in `ext/VizProject.jl`. \ No newline at end of file