|
28 | 28 | import org.nlogo.api.Syntax; |
29 | 29 | import org.nlogo.app.ToolsMenu; |
30 | 30 | import org.nlogo.nvm.*; |
| 31 | +import org.nlogo.nvm.ReporterTask; |
31 | 32 | import org.nlogo.window.SpeedSliderPanel; |
32 | 33 | import org.nlogo.window.ViewUpdatePanel; |
33 | 34 |
|
@@ -74,10 +75,12 @@ public void load(PrimitiveManager primitiveManager) throws ExtensionException { |
74 | 75 | primitiveManager.addPrimitive("hide", new Hide()); |
75 | 76 | primitiveManager.addPrimitive("_list-breeds", new ListBreeds()); |
76 | 77 | primitiveManager.addPrimitive("_globals", new Globals()); |
77 | | -// primitiveManager.addPrimitive("_breeds-own", new BreedsOwns()); |
78 | 78 | primitiveManager.addPrimitive("ask-descendant", new HierarchicalAsk()); |
79 | 79 | primitiveManager.addPrimitive("of-descendant", new HierarchicalOf()); |
80 | 80 | primitiveManager.addPrimitive("uses-level-space?", new UsesLevelSpace()); |
| 81 | + primitiveManager.addPrimitive("_model-procedures", new ModelProcedures()); |
| 82 | + primitiveManager.addPrimitive("to-OTPL", new ToOTPL()); |
| 83 | + |
81 | 84 |
|
82 | 85 | if (useGUI()) { |
83 | 86 | // Adding event listener to Halt for halting child models |
@@ -242,7 +245,7 @@ public void perform(Argument[] args, Context context) throws LogoException, Exte |
242 | 245 | String command = args[1].getString(); |
243 | 246 | Object[] actuals = getActuals(args, 2); |
244 | 247 | for (ChildModel model : toModelList(args[0])) { |
245 | | - model.ask(command, actuals); |
| 248 | + model.ask(command, actuals); |
246 | 249 | } |
247 | 250 | } |
248 | 251 | } |
@@ -381,6 +384,26 @@ public Object report(Argument[] args, Context arg1) |
381 | 384 |
|
382 | 385 | } |
383 | 386 |
|
| 387 | + public static class ToOTPL extends DefaultReporter { |
| 388 | + public Syntax getSyntax(){ |
| 389 | + return Syntax.reporterSyntax(new int[] {Syntax.CommandTaskType() | Syntax.ReporterTaskType() }, |
| 390 | + Syntax.StringType()); |
| 391 | + } |
| 392 | + @Override |
| 393 | + public Object report(Argument[] args, Context arg1) |
| 394 | + throws ExtensionException, LogoException { |
| 395 | + Object task = args[0].get(); |
| 396 | + if (task instanceof ReporterTask) { |
| 397 | + ReporterTask rTask = (ReporterTask) task; |
| 398 | + return rTask.body().agentClassString; |
| 399 | + } else { |
| 400 | + org.nlogo.nvm.CommandTask cTask = (org.nlogo.nvm.CommandTask) task; |
| 401 | + return cTask.procedure().syntax().agentClassString(); |
| 402 | + } |
| 403 | + } |
| 404 | + |
| 405 | + } |
| 406 | + |
384 | 407 |
|
385 | 408 | public static class CloseModel extends DefaultCommand { |
386 | 409 | public Syntax getSyntax() { |
@@ -460,6 +483,18 @@ public Object report(Argument[] args, Context context) throws ExtensionException |
460 | 483 | } |
461 | 484 | } |
462 | 485 |
|
| 486 | + // this returns the path of the model |
| 487 | + public static class ModelProcedures extends DefaultReporter{ |
| 488 | + public Syntax getSyntax(){ |
| 489 | + return Syntax.reporterSyntax(new int[] {Syntax.NumberType()}, |
| 490 | + Syntax.ListType()); |
| 491 | + } |
| 492 | + public Object report(Argument[] args, Context context) throws ExtensionException, LogoException { |
| 493 | + int modelNumber = args[0].getIntValue(); |
| 494 | + return getModel(modelNumber).getProcedures(); |
| 495 | + } |
| 496 | + } |
| 497 | + |
463 | 498 | public static class SetName extends DefaultCommand { |
464 | 499 |
|
465 | 500 | @Override |
@@ -506,34 +541,6 @@ public Object report(Argument args[], Context context) |
506 | 541 | } |
507 | 542 | } |
508 | 543 |
|
509 | | - |
510 | | - public static class BreedsOwns extends DefaultReporter { |
511 | | - public Syntax getSyntax() { |
512 | | - return Syntax.reporterSyntax( |
513 | | - // we take in int[] {modelNumber, varName} |
514 | | - new int[] { Syntax.NumberType() }, |
515 | | - // and return a number |
516 | | - Syntax.ListType()); |
517 | | - } |
518 | | - |
519 | | - public Object report(Argument args[], Context context) |
520 | | - throws ExtensionException, org.nlogo.api.LogoException { |
521 | | - // get model number from args |
522 | | - int modelNumber = (int) args[0].getDoubleValue(); |
523 | | - |
524 | | - // find the model. if it exists, get all breeds + owns |
525 | | - if(models.containsKey(modelNumber)) |
526 | | - { |
527 | | - ChildModel theModel = models.get(modelNumber); |
528 | | - return theModel.listBreedsOwns(); |
529 | | - |
530 | | - } |
531 | | - else{ |
532 | | - return false; |
533 | | - } |
534 | | - |
535 | | - } |
536 | | - } |
537 | 544 | public static class ListBreeds extends DefaultReporter { |
538 | 545 | public Syntax getSyntax() { |
539 | 546 | return Syntax.reporterSyntax( |
|
0 commit comments