//Marcus Daniels, swarm-support, March 8, 1999


//Here's an example:

#import <objectbase/SwarmObject.h>
#import <analysis.h>
#include <math.h>
#import <simtools.h> //pj 2002-06-04
#import <simtoolsgui/GUISwarm.h> //pj 2002-06-04

@interface Agent: SwarmObject
- compute: xPtr: yPtr;
@end

@implementation Agent
- compute: xPtr: yPtr
{
  double x = *(double *)xPtr;
  double y = sin (x);

  *(double *)yPtr = y;
  return (id)YES;
}
@end

@interface Controller: SwarmObject
{
  id <FunctionGraph> fg;
  id <GraphElement> fe;
  id <Graph> graph;
  id agent;
  id panel;
}
- createEnd;
- graph;
- exit;
@end

@implementation Controller

- createEnd
{
  id fgd;

  agent = [Agent create: [self getZone]];

  fgd = [Frame create: [self getZone]];
  
  graph = [Graph createParent: fgd];
  [graph setWindowTitle: "FunctionGraph"];

  [graph pack];

  fe = [graph createElement];
  [fe setLabel: "myLabel"];
  [fe setColor: "red"];
  [fe setWidth: 1];    
  
  fg = [FunctionGraph createBegin: [self getZone]];
  [fg setElement: fe];
  [fg setDataFeed: agent];
  [fg setFunctionSelector: M(compute::)];
  [fg setXMin: 0.0 Max: 2.0 * M_PI Resolution: 100];
  [fg setResetFrequency: 0];
  fg = [fg createEnd]; 

  panel = [ButtonPanel createBegin: [self getZone]];
  [panel setButtonTarget: self];
  panel = [panel createEnd];
  [panel setWindowTitle: "ControlPanel"];
  [panel addButtonName: "Exit" method: @selector (exit)];

  return self;
}

- exit
{
  exit (0);
}

- graph
{
  [fg graph];

  return self;
}
@end

int
main (int argc, const char **argv)
{ 
  Controller * controller;

  initSwarm (argc, argv);

  controller = [Controller create: globalZone];
  
  [controller graph];
  
  while (1)
    {
      while (GUI_EVENT_ASYNC ()) {}
    }  
}

