mkeeter / antimony

CAD from a parallel universe
2.1k stars 159 forks source link

[Feature request] Add custom nodes to 'Add' and right-click menus #217

Open Faberix opened 4 years ago

Faberix commented 4 years ago

It would be great to have an option to save (custom) nodes that you often need and then be able to access them using the Menu. This would be a lot more convenient than having to create a new script node (or whatever other base node you are using) and then copy the code you want or write new code each time you need it. Adding a node to the saved nodes could be done using a GUI like in the sketch below: Antimony custom node in menu proposal GUI sketch It could be accessed using a new entry in the right click menu when right clicked on a node and/or using a new entry (e.g. "Edit available nodes") in either the "Edit" or the "Add" menu.

Implementing the dynamic addition/removal of menu items should not be difficult; it can be done using QMenu.addAction, QMenu.removeAction and QMenu.insertAction (of course, the nodes and the order would have to be saved in the program data and the menus would have to be adjusted accordingly on each program startup).

Saving the additional nodes in the program data should also not be a problem, as the nodes should actually be fully defined by their Python code snippet.

One node that would be useful to have accessible would be the following node (that evaluates an arbitrary mathematical expression in Python code):

import fab
import math

varTuple = ('a', 'b')

title('formula')
for v in varTuple:
    input(v, float)
input('formula', str)

out = eval(formula)
output('out', out)
mkeeter commented 4 years ago

It's already possible to install (global) custom nodes: when populating the node menu here, we search for files in the nodes subfolder of AppDataLocation, which is platform-specific.

Does that accomplish what you're looking for, or do you specifically want to store extra nodes on a per-file basis? It would also be useful to have a UI for saving a new global node, which would be welcome in a PR.

Faberix commented 4 years ago

Does that accomplish what you're looking for, or do you specifically want to store extra nodes on a per-file basis?

Yes, it does. As for the UI, I will not have time for that any time soon (I already have too many other projects running). In case anyone else wants to implement it: I noticed that the nodes are stored in /usr/share/antimony (at least in Ubuntu), which is read-only (except for root, of course). So, if a node should be stored from GUI, QStandardPaths::writableLocation should be used for all custom nodes.

I will leave this issue open, as the GUI would still be useful (especially because the option of manually creating the files will probably not be discovered by most users). Feel free to close it, though.