/*
 * 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.OutputHandle;
import com.sandwell.JavaSimulation.Entity;
import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation.StringInput;

/**
 * The Sensor connect the output from some other object to the DoubleCalculation components.
 * @author Harry King
 *
 */
public class Sensor extends DoubleCalculation {

	@Keyword(description = "The entity to read the output from.",
	         example = "Sensor1 Entity { StockPile2 }")
	private final EntityInput<Entity> entityInput;

	@Keyword(description = "The name of the output to read.",
	         example = "Sensor1 OutputName { 'Contents' }")
	private final StringInput outputNameInput;

	{
		inputValue.setHidden(true);

		entityInput = new EntityInput<Entity>( Entity.class, "Entity", "Key Inputs", null);
		this.addInput(entityInput, true);

		outputNameInput = new StringInput( "OutputName", "Key Inputs", null);
		this.addInput(outputNameInput, true);
	}

	@Override
	public void validate() {
		super.validate();

		// Check that the entity has been set
		if ( entityInput.getValue() == null ) {
			throw new InputErrorException( "The Entity keyword must be set." );
		}

		// Check that the output has been set
		if ( outputNameInput.getValue() == null ) {
			throw new InputErrorException( "The OutputName keyword must be set." );
		}

		// Check that the output is a double or a Double
		Entity ent = entityInput.getValue();
		String name = outputNameInput.getValue();
		OutputHandle out = ent.getOutputHandle(name);
		if (!out.isNumericValue())
			throw new InputErrorException( "The OutputName keyword must specify a floating point output." );
	}

	@Override
	public void update(double simTime) {
		double val = 0.0;
		Entity ent = entityInput.getValue();
		String name = outputNameInput.getValue();

		OutputHandle out = ent.getOutputHandle(name);
		if (out.isNumericValue())
			val = out.getValueAsDouble(simTime, 0.0d);

		// Set the present value
		this.setValue( val );
	}
}

@@ -1237,21 +1237,16 @@
 %3E entity
-Input
 ;%0A%0A%09@Key
@@ -1393,21 +1393,16 @@
 tputName
-Input
 ;%0A%0A%09%7B%0A%09%09
@@ -1438,21 +1438,16 @@
 %09%09entity
-Input
  = new E
@@ -1533,21 +1533,16 @@
 t(entity
-Input
 , true);
@@ -1555,21 +1555,16 @@
 tputName
-Input
  = new S
@@ -1636,21 +1636,16 @@
 tputName
-Input
 , true);
@@ -1756,29 +1756,24 @@
 %09if ( entity
-Input
 .getValue() 
@@ -1909,37 +1909,32 @@
 %09if ( outputName
-Input
 .getValue() == n
@@ -2085,37 +2085,32 @@
 ity ent = entity
-Input
 .getValue();%0A%09%09S
@@ -2124,37 +2124,32 @@
 ame = outputName
-Input
 .getValue();%0A%09%09O
@@ -2416,21 +2416,16 @@
 = entity
-Input
 .getValu
@@ -2455,21 +2455,16 @@
 tputName
-Input
 .getValu

Rename input objects for Sensor