-
Notifications
You must be signed in to change notification settings - Fork 1
Plugins
So you want to write some extra code for MARS? You want to add a specific new AUV? You want to add a specific new sensor that is not supported directly? Then i have some answers for you.
This is what you gonna need:
- MARS installed
- NetBeans 8.0 with JAVA 8.
So lets start. MARS uses the NetBeans Platform and its Module/Plugin feature. And since MARS offers a public API you can write your own plugins! You just install MARS and NetBeans 8.0 and you create a new module under NetBeans and select MARS as new platform. So here's a more detailed plan:
First you create a new project under NetBeans:
Select NetBeans Modules (1.) and then Module (2.):
Give your module a name (1.). Select standalone module (2.). Then go into the platform management (3.):
Add a new platform (1.):
Search for you installation directory of MARS and select it (1.). Go to next (2.). Don't forget to chose the MARS platform when you go back:
Chose a code name base (1.) and finish him! (2.). Your module/plugin will be created: IMPORTANT: When you want to use the MARS libs you have to choose "mars.(yourname)" as your codebase!
You now to set up the libs for your module. In the project tree select your module (1.) and go into the lib folder (2.). Then right click on it and add dependencys (3.):
Now search for the following libs (MARSCore,jMonkeyCore,Lookup API) (filter field:) and add them to your project (ok):
You have now successfully created you first own plugin for MARS. In the moment its doing nothing. But in the next tutorials you gonna add some life to it.
NewAUV
NewSensor
NewActuator
First your module must compile. After that you create a NBM file. Just right click on your module (1.) and then create it (2.). You can find the NBM file in the build folder of you module:
Your module is now ready to be installed into MARS. Start MARS and go into the Tools Menu (1.). Select Plugins (2.):
Then go to the Download tab(1.) and add you NBM file(2.). A Restart of MARS is recommended and so the settings in the modules properties for forcing it:
You have now successfully installed your module/plugin into MARS. Just give your NBM file other users for usage.
If you want to run your module directly from NetBeans (without installing it into MARS) you have to disable assertions! (see: http://wiki.netbeans.org/DevFaqPlatformRuntimeProperties) If you do not disable them you will encounter Assertion Problems.
To disable assertions for you module select your module first (1.). Then open the "Project Properties" (2.). Add a new line "run.args.extra=-J-da" (3.).
You can add extra files to your module (icons,images,3d-models,...) so that they will be also installed to MARS. You just need to add an "release" directory to your module (thats where the src and nbproject dir is). To access theses files you need the InstalledFileLocator from NetBeans Platform. Example usage: File file = InstalledFileLocator.getDefault().locate("Assets/Images", "mars.core", false);
The NBP Lookup System allows you to get a class from an other module. But there isn't a Central/Global Lookup for Instances. Only for TopComponents.
Heres some code for creating the CentralLookup and getting an Instance:
import mars.core.CentralLookup;
//create a search filter
Lookup.Template template = new Lookup.Template(MARS_Main.class);
//get the central lookup
CentralLookup cl = CentralLookup.getDefault();
//lookup the class
result = cl.lookup(template);
//add a listener to it
result.addLookupListener(this);
if(mars == null){// try to get mars, else its the listener
//try to get the instance
mars = cl.lookup(MARS_Main.class);
System.out.println("testnew: " + mars);
}
If you want to use the Listener your class needs to implement the LookupListener Interface.
And heres some code for adding an instance of a class to the CentralLookup:
CentralLookup.getDefault().add(somethingInstance);
Heres a list of all MARS instances registered in the CentralLookup:
# | Name | Function |
---|---|---|
1 | MARS_Main | ? |
2 | SimState | ? |
3 | AUV_Manager | ? |
4 | SimObjectManager | ? |
5 | PhysicalEnvironment | ? |
LookUpTopComponent