
/* Generated by Interface Builder */

#import "AsciiController.h"
#import "SmsObject.h"
#import <appkit/appkit.h>

@implementation AsciiController


- init:(id)controller
{
  [super init];
  [NXApp loadNibSection:"Ascii.nib" owner:self];
  [textWindow makeKeyAndOrderFront:self];
  topController = controller;
  iFirstFrame =  0;
  iLastFrame = 40;
  iLowestTraj = 0;
  iHighestTraj = 20;
  iDeterministicMagState = 1;
  iDeterministicFreqState = 1;
  iStochasticState = 1;
  [highestTrajForm setIntValue:iHighestTraj];
  [lowestTrajForm setIntValue:iLowestTraj];
  [leftTimeForm setFloatValue:0];
  [rightTimeForm setFloatValue:((float)iLastFrame/
  		[[topController getTheSmsObject] getFrameRate])];
  [deterministicMagSwitch setState:iDeterministicMagState];
  [deterministicFreqSwitch setState:iDeterministicFreqState];  
  [stochasticSwitch setState:iStochasticState]; 
     
  return self;
}

- displayData:sender
{
  [textWindow makeKeyAndOrderFront:self];
  [textView display];
  return self;
}

- getTheSmsObject
{
  return [topController getTheSmsObject];
} 

- setLastFrame:sender
{
  id theSmsObject = [topController getTheSmsObject];
  
  if(theSmsObject != NULL)
  {
    int iFrame;
      
    iFrame = [sender floatValue] * [theSmsObject getFrameRate];
      
    if(iFrame < 0)
    {
      iLastFrame = 0;
      [sender setFloatValue:0];
    }
    else if(iFrame >= [theSmsObject getNRecords])
    {
      iLastFrame = [theSmsObject getNRecords];
      [sender setFloatValue:(float)iLastFrame/[theSmsObject getFrameRate]];
    }
    else
      iLastFrame = iFrame;
  }
  return self;
}

- (int)getLastFrame
{
  return iLastFrame;
}

- setFirstFrame:sender
{
  id theSmsObject = [topController getTheSmsObject];

  if(theSmsObject != NULL)
  {
    int iFrame;
      
    iFrame = [sender floatValue] * [theSmsObject getFrameRate];
      
    if(iFrame < 0)
    {
      iFirstFrame = 0;
      [sender setFloatValue:0];
    }
    else if(iFrame >= [theSmsObject getNRecords])
    {
      iFirstFrame = [theSmsObject getNRecords];
      [sender setFloatValue:(float)iFirstFrame/[theSmsObject getFrameRate]];
    }
    else
      iFirstFrame = iFrame;
  }

  return self;
}

- (int)getFirstFrame
{
  return iFirstFrame;
}

- setHighestTraj:sender
{
  id theSmsObject = [topController getTheSmsObject];

  if(theSmsObject != NULL)
  {
    int iTraj;
      
    iTraj = [sender intValue];
    if (iTraj < 0)
    {
      iHighestTraj = 0;
      [sender setIntValue:0];
    }
    else if (iTraj >= [theSmsObject getNTrajectories])
    {
      iHighestTraj = [theSmsObject getNTrajectories] - 1;
      [sender setIntValue:iHighestTraj];
    }
    else
      iHighestTraj = iTraj;
  }
  return self;
}

- (int)getHighestTraj
{
  return iHighestTraj;
}

- setLowestTraj:sender
{
  id theSmsObject = [topController getTheSmsObject];

  if(theSmsObject != NULL)
  {
    int iTraj;
      
    iTraj = [sender intValue];
    if (iTraj < 0)
    {
      iLowestTraj = 0;
      [sender setIntValue:0];
    }
    else if (iTraj >= [theSmsObject getNTrajectories])
    {
      iLowestTraj = [theSmsObject getNTrajectories] - 1;
      [sender setIntValue:iLowestTraj];
    }
    else
      iLowestTraj = iTraj;
  }
  return self;
}

- (int)getLowestTraj
{
  return iLowestTraj;
}

- setDeterministicMagState:sender
{
  iDeterministicMagState = [sender intValue];
  return self;
}

- (int)getDeterministicMagState
{
  return iDeterministicMagState;
}

- setDeterministicFreqState:sender
{
  iDeterministicFreqState = [sender intValue];
  return self;
}

- (int)getDeterministicFreqState
{
  return iDeterministicFreqState;
}

- setStochasticState:sender
{
  iStochasticState = [sender intValue];
  return self;
}

- (int)getStochasticState
{
  return iStochasticState;
}

@end
