package de.grogra.c4d;

import de.grogra.c4d.model.C4D;

public class XLObject extends BaseObject
{
	private double lastTime = 0;

	public XLObject(BaseDocument doc, long handle)
	{
		super(doc, handle);
	}

	private XLObject(BaseDocument doc)
	{
		super(Constants.ID_XL_INSTANCE, false, doc, true);
		lastTime = getTime();
	}

	public XLObject()
	{
		this(C4D.getDocumentForXLObject());
		setPosition(0, 0, 0);
	}

	public XLObject(String refObject)
	{
		this((BaseDocument) null);
		setReference(searchReferenceObject(refObject));
	}

	public XLObject(String refObject, double len, double rad)
	{
		this((BaseDocument) null);
		setReference(searchReferenceObject(refObject));
		setLength(len);
		setRadius(rad);
	}

	public XLObject(BaseObject ref)
	{
		this((BaseDocument) null);
		setReference(ref);
	}

	public void setReference(BaseObject o)
	{
		setObject(Constants.XL_OBJECT_REFERENCE, o);
	}
	
	public void setRadius(double r)
	{
		setReal(Constants.XL_OBJECT_RADIUS, r);
	}

	public double getRadius()
	{
		return getReal(Constants.XL_OBJECT_RADIUS);
	}

	public void setRadiusZ(double r)
	{
		setReal(Constants.XL_OBJECT_RADIUS_Z, r);
	}

	public double getRadiusZ()
	{
		return getReal(Constants.XL_OBJECT_RADIUS_Z);
	}

	public void setStartPosition(double p)
	{
		setReal(Constants.XL_OBJECT_START_POSITION, p);
	}

	public void setEndPosition(double p)
	{
		setReal(Constants.XL_OBJECT_END_POSITION, p);
	}

	public void setLength(double l)
	{
		setPosition(0, l, 0);
	}

	public double getLength()
	{
		return getPosition().y;
	}

	public void setRenderInstance(boolean b)
	{
		setBoolean(Constants.XL_OBJECT_RENDER_INSTANCE, b);
	}

	protected void addToPriorityList(long list, int priority)
	{
		C4D.addToPriorityList(list, getDocumentPointer(), getHandle(), priority);
	}

	public void addToExecution(long list)
	{
	}

	protected void step()
	{
	}

	public void execute(int priority, int flags)
	{
		if (priority == Constants.EXECUTE_PRIORITY)
		{
			double t = getTime();
			if (t != lastTime)
			{
				step();
				lastTime = t;
			}
		}
	}
}
