Hey Jake,


I'll try to provide a little information here, but a couple quick items to 
keep in mind:

   - NetLogo generally doesn't well-support dynamic modification of models 
   outside of its built-in tools, and it's not easy to work with the model 
   data (like the interface/widgets) outside of the model file format.
   - I've worked with some of these items in the past, but there is a lot 
   about them I don't know, so I may be missing simpler solutions. It's worth 
   diving into the NetLogo codebase and trying things out on your own to 
   double-check my answers here.

If you're talking about doing this from within a NetLogo model, then no, 
there is not really a way to do handle either task (changing widget types 
or import/export of interface). The closest you could get would be to use 
the export-the extension to export-the:model, but that exports the whole 
model text file, including the widgets section as defined in the NetLogo 
file format 
<https://github.com/NetLogo/NetLogo/wiki/File-%28.nlogo%29-and-Widget-Format>. 
You'd have to write code to parse the result to get just the widgets 
section for the interface. There is no way at the moment to do any kind of 
import of a model or model interface/widgets from within a NetLogo model.


If you're talking about doing these tasks from a NetLogo extension or from 
a program using the controlling API, then there are more possibilities.


For extending the list of elements available within the interface - if you 
mean adding a new type of widget, then this is going to require modifying 
the NetLogo source code. At the moment the list of known widgets is static, 
and defined in code. There needs to be a reader and writer for each widget 
you define, and those are all defined at compile-time.


If you mean you want to modify something about a widget - say extending the 
options in a chooser widget, that is possible, and has even been done 
before. The Goo Extension <https://github.com/NetLogo/Goo-Extension> had 
primitives to do just that. You might check out its source code for 
inspiration, but it only supported NetLogo 5 (and is now archived), meaning 
things will have changed for NetLogo 6.1. You can seethe transition guide 
<https://github.com/NetLogo/NetLogo/wiki/6.0-Extension-and-Controlling-API-Transition-Guide>
 for 
more on the changes, which may help when looking through the Goo Extension 
code.


The Goo Extension also had code to list the widgets from the GUI, which 
might be one way to do an "interface export", but it's definitely not 
straightforward.


If you can get ahold of the org.nlogo.core.Model instance for your model, 
it has a widgets property that would also get you the interface information 
in an easy to read format, which you could then export as you wish. I tried 
finding a nice way to do that, and unfortunately I really didn't come up 
with anything. If you can get access to a Pico container instance, you can 
pull the currentModel off of the ModelSaver instance like this 
<https://github.com/NetLogo/NetLogo/blob/hexy/netlogo-gui/src/main/app/App.scala#L616>,
 
but that's pretty ugly.


The next best bet is to just look for a way to export the model nlogo text, 
and use that as the exporting, splitting it up for just the interface 
information, again using the NetLogo file format 
<https://github.com/NetLogo/NetLogo/wiki/File-%28.nlogo%29-and-Widget-Format> 
as 
a guide.  The source code for the ExportThe extension would be helpful here.


For importing an interface/widgets, if you're doing your work from an 
extension, then unfortunately I don't have any good tips, but I would be 
very interested in seeing the solution if you came up with one!


If you're just using the controlling API from an outside program, things 
are much easier. If you have the model nlogo text, as suggested above, you 
can just change the widgets section to whatever you want, and then re-load 
your model using that text and you'll have "imported" the interface.


Sorry I can't think of more straightforward ways to handle your use cases! 
 I hope that's helpful.


-Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netlogo-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netlogo-devel/22158335-de7c-4bf4-acf8-f746bb6b1ba6%40googlegroups.com.

Reply via email to