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 84% rename from src/Viz/VizProject.jl rename to ext/VizProject.jl index 718a4ffa..6b2550c8 100644 --- a/src/Viz/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,11 +96,8 @@ function plotProject!(proj::Project, plotOptions::Int = 0) end -""" - updatePlot!(proj::Project) - -This version replots the figure with the current options. Legacy. -""" +# 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)) @@ -127,15 +107,6 @@ function updatePlot!(proj::Project) 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/HOHQMesh.jl b/src/HOHQMesh.jl index 312d4421..2a529a71 100644 --- a/src/HOHQMesh.jl +++ b/src/HOHQMesh.jl @@ -7,25 +7,19 @@ 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 # # 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. @@ -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..9a0081e5 --- /dev/null +++ b/src/Viz/visualization.jl @@ -0,0 +1,45 @@ + +# 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 + +""" + 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 "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`. + + +""" + updatePlot!(proj::Project, plotOptions::Int) + +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