
/* Generated by Interface Builder */

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

@implementation StocController

- init:(id)controller
{
  [super init];
  [NXApp loadNibSection:"Stochastic.nib" owner:self];
  [magWindow makeKeyAndOrderFront:self];
  topController = controller;
  iFirstFrameCoeff = iFirstFrameMag = 0;
  iLastFrameCoeff = iLastFrameMag = 40;
  fBottomDb = 0;
  fTopDb = 60;
  fBottomValue = 0;
  fTopValue = 10;  
  iLowestCoeff = 1;
  iHighestCoeff = 8;
  [leftTimeFormMag setFloatValue:0];
  [rightTimeFormMag setFloatValue:((float)iLastFrameMag/
  		[[topController getTheSmsObject] getFrameRate])];
  [leftTimeFormCoeff setFloatValue:0];
  [rightTimeFormCoeff setFloatValue:((float)iLastFrameMag/
  		[[topController getTheSmsObject] getFrameRate])];
  [bottomDbForm setFloatValue:fBottomDb];
  [topDbForm setFloatValue:fTopDb];
  [bottomCoeffForm setIntValue:iLowestCoeff];
  [topCoeffForm setIntValue:iHighestCoeff];
  [bottomValueForm setFloatValue:fBottomValue];
  [topValueForm setFloatValue:fTopValue];

  return self;
}

- displayMagnitude:sender
{
  [magView display];
  return self;
}

- displayCoefficients:sender
{
  [coeffWindow makeKeyAndOrderFront:self];
  [coeffView display];
  return self;
}

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

- (int)getLastFrameMag
{
  return iLastFrameMag;
}

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

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

  return self;
}

- (int)getFirstFrameMag
{
  return iFirstFrameMag;
}

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

- (int)getLastFrameCoeff
{
  return iLastFrameCoeff;
}

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

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

  return self;
}

- (int)getFirstFrameCoeff
{
  return iFirstFrameCoeff;
}

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

    if(theSmsObject != NULL)
    {
      int iCoeff;
      
      iCoeff = [sender intValue];
      
      if(iCoeff < 1)
      {
        iHighestCoeff = 1;
        [sender setIntValue:1];
    }
    else if(iCoeff >= [theSmsObject getNStochasticCoeff])
    {
      iHighestCoeff = [theSmsObject getNStochasticCoeff];
      [sender setIntValue:iHighestCoeff];
    }
    else 
      iHighestCoeff = iCoeff;
  }
  return self;
}

- (int)getHighestCoeff
{
  return iHighestCoeff-1;
}

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

	if(theSmsObject != NULL)
	{
		int iCoeff;
		
		iCoeff = [sender intValue];
      
		if(iCoeff < 1)
		{
			iLowestCoeff = 1;
			[sender setIntValue:1];
		}
		else if(iCoeff >= [theSmsObject getNStochasticCoeff])
		{
			iLowestCoeff = [theSmsObject getNStochasticCoeff];
			[sender setIntValue:iLowestCoeff];
		}
		else 
			iLowestCoeff = iCoeff;
	}
	return self;
}

- (int)getLowestCoeff
{
  return iLowestCoeff-1;
}

- getTheSmsObject
{
  return [topController getTheSmsObject];
} 

- setBottomDb:sender
{
    fBottomDb = [sender floatValue];
    if (fBottomDb < 0)
    {
      fBottomDb = 0;
      [sender setFloatValue:0];
    }
    return self;
}

- (float)getBottomDb
{
  return fBottomDb;
}

- setTopDb:sender
{
    fTopDb = [sender floatValue];
    return self;
}

- (float)getTopDb
{
  return fTopDb;
}

- setBottomValue:sender
{
  fBottomValue = [sender floatValue];
  return self;
}

- (float)getBottomValue
{
  return fBottomValue;
}

- setTopValue:sender
{
  fTopValue = [sender floatValue];
  return self;
}

- (float)getTopValue
{
  return fTopValue;
}

@end
