|
17 | 17 |
|
18 | 18 | import org.nlogo.api.*; |
19 | 19 | import org.nlogo.api.Argument; |
20 | | -import org.nlogo.api.CommandTask; |
21 | 20 | import org.nlogo.api.Context; |
22 | 21 | import org.nlogo.app.App; |
23 | 22 | import org.nlogo.api.ExtensionObject; |
|
29 | 28 | import org.nlogo.api.Syntax; |
30 | 29 | import org.nlogo.app.ToolsMenu; |
31 | 30 | import org.nlogo.nvm.*; |
| 31 | +import org.nlogo.nvm.ReporterTask; |
32 | 32 | import org.nlogo.window.SpeedSliderPanel; |
33 | 33 | import org.nlogo.window.ViewUpdatePanel; |
34 | 34 |
|
@@ -80,6 +80,7 @@ public void load(PrimitiveManager primitiveManager) throws ExtensionException { |
80 | 80 | primitiveManager.addPrimitive("of-descendant", new HierarchicalOf()); |
81 | 81 | primitiveManager.addPrimitive("uses-level-space?", new UsesLevelSpace()); |
82 | 82 | primitiveManager.addPrimitive("_model-procedures", new ModelProcedures()); |
| 83 | + primitiveManager.addPrimitive("to-OTPL", new ToOTPL()); |
83 | 84 |
|
84 | 85 |
|
85 | 86 | if (useGUI()) { |
@@ -384,6 +385,26 @@ public Object report(Argument[] args, Context arg1) |
384 | 385 |
|
385 | 386 | } |
386 | 387 |
|
| 388 | + public static class ToOTPL extends DefaultReporter { |
| 389 | + public Syntax getSyntax(){ |
| 390 | + return Syntax.reporterSyntax(new int[] {Syntax.CommandTaskType() | Syntax.ReporterTaskType() }, |
| 391 | + Syntax.StringType()); |
| 392 | + } |
| 393 | + @Override |
| 394 | + public Object report(Argument[] args, Context arg1) |
| 395 | + throws ExtensionException, LogoException { |
| 396 | + Object task = args[0].get(); |
| 397 | + if (task instanceof ReporterTask) { |
| 398 | + ReporterTask rTask = (ReporterTask) task; |
| 399 | + return rTask.body().agentClassString; |
| 400 | + } else { |
| 401 | + org.nlogo.nvm.CommandTask cTask = (org.nlogo.nvm.CommandTask) task; |
| 402 | + return cTask.procedure().syntax().agentClassString(); |
| 403 | + } |
| 404 | + } |
| 405 | + |
| 406 | + } |
| 407 | + |
387 | 408 |
|
388 | 409 | public static class CloseModel extends DefaultCommand { |
389 | 410 | public Syntax getSyntax() { |
|
0 commit comments