/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2009-2011 Ausenco Engineering Canada Inc.
 * Copyright (C) 2017-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.Graphics;

import com.jaamsim.DisplayModels.DisplayModel;
import com.jaamsim.DisplayModels.PolylineModel;
import com.jaamsim.input.ColourInput;
import com.jaamsim.input.Input;
import com.jaamsim.input.IntegerInput;
import com.jaamsim.input.Keyword;
import com.jaamsim.input.Vec3dInput;
import com.jaamsim.math.Color4d;
import com.jaamsim.math.Vec3d;
import com.jaamsim.ui.GUIFrame;
import com.jaamsim.units.DistanceUnit;

public class Arrow extends DisplayEntity implements LineEntity {

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

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

	@Keyword(description = "A set of (x, y, z) numbers that define the size of the arrowhead.",
	         exampleList = {"0.165 0.130 0.0 m"})
	private final Vec3dInput arrowHeadSize;

	{
		displayModelListInput.addValidClass(PolylineModel.class);

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

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

		arrowHeadSize = new Vec3dInput( "ArrowHeadSize", FORMAT, new Vec3d(0.1d, 0.1d, 0.0d) );
		arrowHeadSize.setUnitType(DistanceUnit.class);
		arrowHeadSize.setDefaultText("PolylineModel");
		this.addInput( arrowHeadSize );
		this.addSynonym(arrowHeadSize, "ArrowSize");
	}

	public Arrow() {}

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

		if (in == pointsInput) {
			invalidateScreenPoints();
			return;
		}
		if (in == color || in == width) {
			if (GUIFrame.getInstance() == null)
				return;
			GUIFrame.getInstance().updateLineButtons();
			return;
		}
	}

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

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

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

	public PolylineModel getPolylineModel() {
		DisplayModel dm = displayModelListInput.getValue().get(0);
		if (dm instanceof PolylineModel)
			return (PolylineModel) dm;
		return null;
	}

	public Vec3d getArrowHeadSize() {
		PolylineModel plModel = getPolylineModel();
		if (arrowHeadSize.isDefault() && plModel != null)
			return plModel.getArrowHeadSize();
		return arrowHeadSize.getValue();
	}

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

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

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

}

@@ -2728,356 +2728,8 @@
 %09%7D%0A%0A
-%09@Override%0A%09public PolylineInfo%5B%5D buildScreenPoints(double simTime) %7B%0A%09%09int wid = -1;%0A%09%09if (!width.isDefault())%0A%09%09%09wid = Math.max(1, width.getValue());%0A%0A%09%09Color4d col = null;%0A%09%09if (!color.isDefault())%0A%09%09%09col = color.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
 %09pub

remove unnecessary buildScreenPoints method in Arrow