add a specific api for view options (and other options-related api suggestions)
View options
The current api to set view options is error-prone.
For example, in python:
view = gmsh.view.add(name)
index = gmsh.view.get_index(view)
gmsh.option.set_number(f"View[{index}].IntervalsType", 3)
This has two disadvantages:
- having to construct a string at runtime is annoying (especially in C).
- having to convert the tag into the index is cryptic (especially given that in many cases they used to be identical).
A clearer API could be:
view = gmsh.view.add(name)
gmsh.view.option.set_number(view, "IntervalsType", 3)
or
gmsh.view.set_number_option(view, "IntervalsType", 3)
or maybe
gmsh.option.view.number.set(view, "IntervalsType", 3)
By symmetry, there could be a similar API for mesh options but this is less problematic since the string is known:
gmsh.mesh.set_number_option("MshFileVersion", "2.0")
Color options
Also, while I'm complaining about the option API
In the "Current Options and Workspace" window (my main source of information to find option names), a color options name is something like
Mesh.Color.Triangles = {160,150,255};
which from the API, translates to:
gmsh.option.set_color("Mesh.Triangles", 160, 150, 255);
Even if it was redundant with the function name, the disappearance of Color
in the middle of the option name feels strange.
I would prefer something like,
gmsh.option.mesh.color.set("Triangles", 160, 150, 255);
or at least
gmsh.option.set_color("Mesh.Color.Triangles", 160, 150, 255);
(but this would break existing codes).
Option names discoverable from IDEs
An inconvenience of using strings to access/set the options from the API is that they are not easily discoverable and make the code completion of the editors useless. One way around this without changing the existing API (except for the view options where the string is not static), would be to define automatically generated documented static constants in the API. For example the gmsh.py file could contains something like:
gmsh.option.Mesh.Triangle = "Mesh.Triangle"
"""
Display Mesh Triangles?
"""
Then we could write
gmsh.option.set_number(gmsh.options.Mesh.Triangle, 0)
This way it would be easier to find the correct option name from our code editors (both by using code completion and by accessing the documentation of the constant).
Of course at that point, we could instead have directly in the API.
gmsh.option.mesh.triangle.set
gmsh.option.mesh.triangle.get
Which would be my preferred solution but we already had this discussion and you don't like it because it would increase the number of functions in the API.
The accessors could even be hidden in languages that support it (like python), so that the user could write directly
gmsh.option.mesh.triangle = 0
print(gmsh.option.mesh.triangle)
But then I don't know how to pass the index/tag of view options, maybe something like
gmsh.option.view.IntervalsType[view] = 3
NB: If you agree on one of those suggestion, I can write the code myself to implement them.