/*
 * Part of the ROBOID project
 * Copyright (C) 2016 Kwang-Hyun Park (akaii@kw.ac.kr) and Kyoung Jin Kim
 * https://github.com/roboidstudio/embedded
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
*/

package org.roboid.studio.timeline.model;

import java.util.ArrayList;
import java.util.List;

import org.roboid.studio.timeline.TimelineFactory;

/**
 * @author Kwang-Hyun Park
 */
class LinearPoint extends ControlPoint
{
	private static final long serialVersionUID = 1L;
	private List<Object> objValues;
	private int mode;
	
	private List<Object> getObjValues()
	{
		if(objValues == null) objValues = new ArrayList<Object>();
		return objValues;
	}
	
	private int getMode()
	{
		return mode;
	}
	
	@Override
	org.roboid.studio.timeline.LinearPoint toVersion1_4(org.roboid.studio.timeline.ChannelTrack parent)
	{
		org.roboid.studio.timeline.LinearPoint newPoint = TimelineFactory.eINSTANCE.createLinearPoint();
		copyTo(newPoint);
		return newPoint;
	}
	
	@Override
	void copyTo(org.roboid.studio.timeline.ControlPoint newPoint)
	{
		super.copyTo(newPoint);
		float[] values = new float[getObjValues().size()];
		for(int i = 0; i < getObjValues().size(); i ++)
		{
			Object o = getObjValues().get(i);
			if(o instanceof Byte)
				values[i] = ((Byte)o).floatValue();
			else if(o instanceof Short)
				values[i] = ((Short)o).floatValue();
			else if(o instanceof Integer)
				values[i] = ((Integer)o).floatValue();
			else if(o instanceof Float)
				values[i] = ((Float)o).floatValue();
		}
		((org.roboid.studio.timeline.LinearPoint)newPoint).setValues(values);
		((org.roboid.studio.timeline.LinearPoint)newPoint).setMode(getMode());
	}
}
