/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.jaamsim.CalculationObjects;

import com.jaamsim.input.Keyword;
import com.jaamsim.input.ValueInput;
import com.jaamsim.units.AngleUnit;
import com.jaamsim.units.TimeUnit;

/**
 * Super-class for wave generators that produce either sine or square waves.
 * @author Harry King
 *
 */
public abstract class WaveGenerator extends DoubleCalculation {

	@Keyword(description = "Amplitude of the generated wave",
	         example = "Wave1 Amplitude { 2.0 }")
	private final ValueInput amplitudeInput;

	@Keyword(description = "Period of the generated wave",
	         example = "Wave1 Period { 2 s }")
	private final ValueInput periodInput;

	@Keyword(description = "Initial phase angle of the generated wave",
	         example = "Wave1 PhaseAngle { 45 deg }")
	private final ValueInput phaseAngleInput;

	@Keyword(description = "Offset added to the output of the generated wave",
	         example = "Wave1 Offset { 2.0 }")
	private final ValueInput offsetInput;

	{
		inputValue.setHidden(true);

		amplitudeInput = new ValueInput( "Amplitude", "Key Inputs", 1.0d);
		amplitudeInput.setValidRange( 0.0d, Double.POSITIVE_INFINITY);
		this.addInput( amplitudeInput, true);

		periodInput = new ValueInput("Period", "Key Inputs", 1.0d);
		periodInput.setUnitType(TimeUnit.class);
		periodInput.setValidRange(0.0d, Double.POSITIVE_INFINITY);
		this.addInput(periodInput, true);

		phaseAngleInput = new ValueInput( "PhaseAngle", "Key Inputs", 0.0d);
		phaseAngleInput.setUnitType( AngleUnit.class );
		this.addInput( phaseAngleInput, true);

		offsetInput = new ValueInput( "Offset", "Key Inputs", 0.0d);
		this.addInput( offsetInput, true);
	}

	@Override
	public void earlyInit() {
		super.earlyInit();
		this.setValue( amplitudeInput.getValue() * this.getSignal( phaseAngleInput.getValue() ) );
	}

	@Override
	public void update(double simTime) {

		// Calculate the present phase angle
		double angle = 2.0 * Math.PI * simTime / periodInput.getValue() + phaseAngleInput.getValue();

		// Set the output value for the wave
		this.setValue( amplitudeInput.getValue() * this.getSignal( angle )  +  offsetInput.getValue() );
		return;
	}

	/*
	 * Calculate the current dimensionless signal for the wave.
	 */
	protected abstract double getSignal( double angle );
}

@@ -1095,21 +1095,16 @@
 mplitude
-Input
 ;%0A%0A%09@Key
@@ -1230,21 +1230,16 @@
 t period
-Input
 ;%0A%0A%09@Key
@@ -1389,21 +1389,16 @@
 aseAngle
-Input
 ;%0A%0A%09@Key
@@ -1544,21 +1544,16 @@
 t offset
-Input
 ;%0A%0A%09%7B%0A%09%09
@@ -1592,21 +1592,16 @@
 mplitude
-Input
  = new V
@@ -1656,21 +1656,16 @@
 mplitude
-Input
 .setVali
@@ -1731,21 +1731,16 @@
 mplitude
-Input
 , true);
@@ -1749,21 +1749,16 @@
 %09%09period
-Input
  = new V
@@ -1802,29 +1802,24 @@
 d);%0A%09%09period
-Input
 .setUnitType
@@ -1844,21 +1844,16 @@
 %09%09period
-Input
 .setVali
@@ -1914,21 +1914,16 @@
 t(period
-Input
 , true);
@@ -1936,21 +1936,16 @@
 aseAngle
-Input
  = new V
@@ -2002,21 +2002,16 @@
 aseAngle
-Input
 .setUnit
@@ -2062,21 +2062,16 @@
 aseAngle
-Input
 , true);
@@ -2080,21 +2080,16 @@
 %09%09offset
-Input
  = new V
@@ -2153,21 +2153,16 @@
 ( offset
-Input
 , true);
@@ -2243,37 +2243,32 @@
 Value( amplitude
-Input
 .getValue() * th
@@ -2283,37 +2283,32 @@
 gnal( phaseAngle
-Input
 .getValue() ) );
@@ -2450,21 +2450,16 @@
 / period
-Input
 .getValu
@@ -2474,21 +2474,16 @@
 aseAngle
-Input
 .getValu
@@ -2553,21 +2553,16 @@
 mplitude
-Input
 .getValu
@@ -2601,21 +2601,16 @@
   offset
-Input
 .getValu

Rename input objects for WaveGenerator