/*
 * Copyright 1993 by Cub'x Systemes
 * 
 * All Rights Reserved
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for the  purpose of making new intuitiv'3d modules.
 * This copyright notice must appears in all copies that you distribute.
 * The name of Cub'x Systeme should not be used in advertising or publicity
 * without specific, written prior permission. 
 * CUB'X SYSTEMES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 * CUB'X SYSTEMES BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

/*****************************************************************************
 *
 *  CustomObject module
 *  -------------------
 *
 * File: TorusWaveInsp.m
 *
 * Contents:  An inspector for the TorusWave
 *           
 *
 *****************************************************************************/

#import "TorusWaveInsp.h"
#import "TorusWave.h"
#import <appkit/Control.h>

@implementation TorusWaveInsp:InspectorView
{
    id	thetamaxSlider;
    id	thetamaxTextfield;
    id	waveCountSlider;
    id	waveCountTextfield;
    id  radiusTextfield;
    id  radiusSlider;
}

/*******************************************************************************
 *                                                                             *
 *                                Class methods                                *
 *                                                                             *
 *******************************************************************************/
/*
 *  This method should return the name of the nib file that you want to
 *  use with the inspector.
 */
+ (const char*)nibName
{
  return "TorusWaveInsp";
}

/*******************************************************************************
 *                                                                             *
 *                               Instance methods                              *
 *                                                                             *
 *******************************************************************************/
/*
 *  Target / action methods. Please see DistortedCubeInsp.nib
 * 
 * Please notice macro usage for real-time if needed.
 */

- thetamaxChange:sender
{
  float v = [sender floatValue];
  if( v < 1.0 )
    v = 1.0;
  else if( v > 360.0 )
    v = 360.0;
  [thetamaxSlider setFloatValue: v];
  [thetamaxTextfield setFloatValue:v];
  UPDATE_OBJECT_IF_NEED(setThetamax:,v);
  return self;
}
- waveCountChange:sender
{
  int v = [sender intValue];

  if( v < 1 )
    v = 1;

  [waveCountTextfield setIntValue: v];
  [waveCountSlider    setIntValue: v];
  UPDATE_OBJECT_IF_NEED(setWaveCount:,(unsigned int) v);
  return self;
}

- radiusChange:sender
{
  float v = [sender floatValue];

  if( v < .01 )
    v = .01;

  [radiusTextfield setFloatValue: v];
  [radiusSlider    setFloatValue: v];

  UPDATE_OBJECT_IF_NEED( setRadius:, v );
  return self;
}

/*
 *  Instance methods to be compatible with intuitiv'3d's inspector protocol.
 */
/*
 *  This method should send all inspector values to the object
 *  This method is called when the user presses the Ok button.
 */
- sendAllValueToObject: anObject
{
  /*
   *  Note that the textfield is used to get the interface value.    */
  [anObject setWaveCount: [waveCountTextfield intValue]]; 
  [anObject setThetamax:  [thetamaxTextfield  floatValue]];
  [anObject setRadius:    [radiusTextfield floatValue]];
  return self;
}

/*
 *  This method should set the inspector's interface to the 
 *  value of anObject. This method is called when there is
 *  a new object selection or when the user presses the
 *  revert button.
 */
- receiveAllValueFromObject: anObject
{
  int waveCount = [anObject waveCount];
  float thetamax= [anObject thetamax];
  float radius  = [anObject radius];

  [waveCountTextfield setIntValue: waveCount];
  [waveCountSlider    setIntValue: waveCount];
  [thetamaxTextfield  setFloatValue: thetamax];
  [thetamaxSlider     setFloatValue: thetamax];
  [radiusTextfield    setFloatValue: radius];
  [radiusSlider       setFloatValue: radius];
  return self;
}


/*
 *   This method should return the name of the inspector
 */
- (const char*) title
{
  return "TorusWave inspector";
}

@end

