tutorials:create-groimp-plugin
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:create-groimp-plugin [2024/12/06 08:20] – [New file filter] gaetan | tutorials:create-groimp-plugin [2024/12/06 08:54] (current) – gaetan | ||
---|---|---|---|
Line 1: | Line 1: | ||
This tutorial aims at showing how to get started on GroIMP plugin development. It is assumed that you are able to compile the plugin using Maven (either the plugin alone, or the whole project). | This tutorial aims at showing how to get started on GroIMP plugin development. It is assumed that you are able to compile the plugin using Maven (either the plugin alone, or the whole project). | ||
- | In this tutorial we are going to create a new plugin (from the empty template), add a new MimeType (format of file accepted by GroIMP) for both import | + | In this tutorial we are going to create a new plugin (from the empty template), add a new MimeType (format of file accepted by GroIMP) for import, and add a menu item that run a specific command. |
See: | See: | ||
Line 253: | Line 253: | ||
requires graph; | requires graph; | ||
requires imp3d; | requires imp3d; | ||
- | requires | + | requires |
+ | requires utilities; | ||
</ | </ | ||
Line 327: | Line 328: | ||
<code xml> | <code xml> | ||
< | < | ||
- | | + | |
< | < | ||
| | ||
Line 336: | Line 337: | ||
<ref name=" | <ref name=" | ||
< | < | ||
- | < | + | < |
</ | </ | ||
</ | </ | ||
Line 343: | Line 344: | ||
</ | </ | ||
- | The first '' | + | The tag '' |
Then, the hooks > complete > project defines what happens when a GroIMP project is open. In this case at ''/ | Then, the hooks > complete > project defines what happens when a GroIMP project is open. In this case at ''/ | ||
Line 353: | Line 354: | ||
{{: | {{: | ||
+ | |||
+ | === Add an option === | ||
+ | |||
+ | The previous command is creating a chain of five cylinders. Instead of using a fixed number we can add a GroIMP option to let the user define the number. | ||
+ | |||
+ | Options are defined in the registry. In the '' | ||
+ | <code xml> | ||
+ | < | ||
+ | | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | The directory is now using the parameter // | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Now we change the java code that was creating the Cylinders to use the value of this option. In the file '' | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | import de.grogra.util.Utils; | ||
+ | |||
+ | public class Commands { | ||
+ | |||
+ | public static void randomCylinders(Item item, Object info, Context ctx) { | ||
+ | Node n = new Node(); | ||
+ | Node last = n; | ||
+ | |||
+ | Item ite = Item.resolveItem(item.getRegistry(), | ||
+ | int nbOfCylinders = (int) Utils.get(ite, | ||
+ | |||
+ | for(int i=0; | ||
+ | float length = (float) (0.5f + Math.random() * (2 - 0.5)); | ||
+ | float radius = (float) (0.1f + Math.random() * (0.4 - 0.1)); | ||
+ | Cylinder c = new Cylinder(length, | ||
+ | last.addEdgeBitsTo(c, | ||
+ | last = c; | ||
+ | } | ||
+ | IMP.addNode(null, | ||
+ | } | ||
+ | } | ||
+ | </ |
tutorials/create-groimp-plugin.1733469656.txt.gz · Last modified: 2024/12/06 08:20 by gaetan