/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada Inc.
 * Copyright (C) 2018 JaamSim Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.FluidObjects;

import com.jaamsim.Graphics.LineEntity;
import com.jaamsim.Graphics.PolylineInfo;
import com.jaamsim.input.ColourInput;
import com.jaamsim.input.Input;
import com.jaamsim.input.IntegerInput;
import com.jaamsim.input.Keyword;
import com.jaamsim.input.ValueInput;
import com.jaamsim.math.Color4d;
import com.jaamsim.ui.GUIFrame;
import com.jaamsim.units.VolumeFlowUnit;

/**
 * FluidFixedFlow models a specified flow rate between a source and destination.
 * A null source is taken to be an infinite reservoir to supply fluid.
 * A null destination is taken to be an infinite reservoir to receive fluid.
 * @author Harry King
 *
 */
public class FluidFixedFlow extends FluidFlowCalculation implements LineEntity {

	@Keyword(description = "The constant volumetric flow rate from the source to the destination.",
	         exampleList = {"1.0 m3/s"})
	private final ValueInput flowRateInput;

	@Keyword(description = "The width of the pipe segments in pixels.",
	         exampleList = {"1"})
	private final IntegerInput widthInput;

	@Keyword(description = "The colour of the pipe.",
	         exampleList = {"red"})
	private final ColourInput colourInput;

	{
		flowRateInput = new ValueInput( "FlowRate", KEY_INPUTS, 0.0d);
		flowRateInput.setValidRange( 0.0d, Double.POSITIVE_INFINITY);
		flowRateInput.setUnitType( VolumeFlowUnit.class );
		this.addInput( flowRateInput);

		widthInput = new IntegerInput("LineWidth", FORMAT, 1);
		widthInput.setValidRange(1, Integer.MAX_VALUE);
		widthInput.setDefaultText("PolylineModel");
		this.addInput(widthInput);
		this.addSynonym(widthInput, "Width");

		colourInput = new ColourInput("LineColour", FORMAT, ColourInput.BLACK);
		colourInput.setDefaultText("PolylineModel");
		this.addInput(colourInput);
		this.addSynonym(colourInput, "Color");
		this.addSynonym(colourInput, "Colour");
	}

	@Override
	protected void calcFlowRate(FluidComponent source, FluidComponent destination, double dt) {

		// Update the flow rate
		this.setFlowRate( flowRateInput.getValue() );
	}

	@Override
	public void updateForInput( Input<?> in ) {
		super.updateForInput(in);

		if (in == colourInput || in == widthInput) {
			if (GUIFrame.getInstance() == null)
				return;
			GUIFrame.getInstance().updateLineButtons();
			return;
		}
	}

	@Override
	public PolylineInfo[] buildScreenPoints(double simTime) {
		int wid = -1;
		if (!widthInput.isDefault())
			wid = Math.max(1, widthInput.getValue());

		Color4d col = null;
		if (!colourInput.isDefault())
			col = colourInput.getValue();

		PolylineInfo[] ret = new PolylineInfo[1];
		ret[0] = new PolylineInfo(getCurvePoints(), col, wid);
		return ret;
	}

	@Override
	public boolean isOutlined() {
		return true;
	}

	@Override
	public int getLineWidth() {
		return widthInput.getValue();
	}

	@Override
	public Color4d getLineColour() {
		return colourInput.getValue();
	}

}

@@ -772,50 +772,8 @@
 ty;%0A
-import com.jaamsim.Graphics.PolylineInfo;%0A
 impo
@@ -2958,378 +2958,8 @@
 %09%7D%0A%0A
-%09@Override%0A%09public PolylineInfo%5B%5D buildScreenPoints(double simTime) %7B%0A%09%09int wid = -1;%0A%09%09if (!widthInput.isDefault())%0A%09%09%09wid = Math.max(1, widthInput.getValue());%0A%0A%09%09Color4d col = null;%0A%09%09if (!colourInput.isDefault())%0A%09%09%09col = colourInput.getValue();%0A%0A%09%09PolylineInfo%5B%5D ret = new PolylineInfo%5B1%5D;%0A%09%09ret%5B0%5D = new PolylineInfo(getCurvePoints(), col, wid);%0A%09%09return ret;%0A%09%7D%0A%0A
 %09@Ov

remove unnecessary buildScreenPoints method in FluidFixedFlow