/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2014 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.BasicObjects;

import com.jaamsim.input.Keyword;
import com.sandwell.JavaSimulation.BooleanInput;
import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation3D.DisplayEntity;

public class EntitySignal extends LinkedComponent {

	@Keyword(description = "The EntityGate controlled by this Signal.",
	         example = "EntitySignal1 TargetGate { Gate1 }")
	private final EntityInput<EntityGate> targetGate;

	@Keyword(description = "The new state for the target EntityGate: TRUE = Open, FALSE = Closed.",
	         example = "EntitySignal1 NewState { FALSE }")
	private final BooleanInput newState;

	{
		operatingThresholdList.setHidden(true);

		targetGate = new EntityInput<EntityGate>( EntityGate.class, "TargetGate", "Key Inputs", null);
		this.addInput( targetGate);

		newState = new BooleanInput( "NewState", "Key Inputs", true);
		this.addInput( newState);
	}

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

		// Confirm that the target gate has been specified
		if( targetGate.getValue() == null ) {
			throw new InputErrorException( "The keyword TargetGate must be set." );
		}
	}

	/**
	 * Add a DisplayEntity from upstream
	 * @param ent = entity to be added
	 */
	@Override
	public void addDisplayEntity( DisplayEntity ent ) {
		super.addDisplayEntity(ent);

		// Signal the target gate
		targetGate.getValue().setState(newState.getValue());

		// Send the entity to the next component
		this.sendToNextComponent( ent );
	}

}

@@ -630,16 +630,63 @@
 jects;%0A%0A
+import com.jaamsim.Thresholds.SignalThreshold;%0A
 import c
@@ -999,26 +999,25 @@
  = %22The 
-EntityGate
+Threshold
  control
@@ -1083,74 +1083,112 @@
 rget
-Gate %7B Gate1 %7D%22)%0A%09private final EntityInput%3CEntityGate%3E targetGate
+SignalThreshold %7B SignalThreshold1 %7D%22)%0A%09private final EntityInput%3CSignalThreshold%3E targetSignalThreshold
 ;%0A%0A%09
@@ -1240,26 +1240,31 @@
  target 
-EntityGate
+SignalThreshold
 : TRUE =
@@ -1437,20 +1437,31 @@
 %09%09target
-Gate
+SignalThreshold
  = new E
@@ -1475,50 +1475,71 @@
 put%3C
-EntityGate%3E( EntityGate.class, %22TargetGate
+SignalThreshold%3E( SignalThreshold.class, %22TargetSignalThreshold
 %22, %22
@@ -1581,20 +1581,31 @@
 ( target
-Gate
+SignalThreshold
 );%0A%0A%09%09ne
@@ -1783,20 +1783,25 @@
  target 
-gate
+threshold
  has bee
@@ -1820,28 +1820,39 @@
 %09%09if( target
-Gate
+SignalThreshold
 .getValue() 
@@ -1916,20 +1916,25 @@
 d Target
-Gate
+Threshold
  must be
@@ -2158,25 +2158,41 @@
 get 
-gate%0A%09%09targetGate
+threshold%0A%09%09targetSignalThreshold
 .get
@@ -2202,21 +2202,20 @@
 ue().set
-State
+Open
 (newStat

Connect EntitySignal to SignalThreshold