/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program 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 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2007, by :
* Corporate:
* EADS Astrium
* Individual:
* Claude Cazenave
*
* $Id: TransformData.java,v 1.4 2008/10/23 17:21:04 cazenave Exp $
*
* Changes
* -------
* 12 janv. 08 : Initial public release
*
*/
package jsynoptic.plugins.java3d;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import jsynoptic.plugins.java3d.util.TransformValues;
import simtools.data.DataSource;
/**
*/
public class TransformData extends DoubleDataAnimator.DoubleData {
static final long serialVersionUID = -133264739765994645L;
protected transient Transform3D trans;
protected TransformValues kind;
/**
*/
public TransformData() {
trans = new Transform3D();
kind = TransformValues.IDENTITY;
}
/**
* @param i
*/
public void setKind(TransformValues k) {
set(TransformValues.get(trans, k), null);
kind = k;
}
/**
* @return Returns the kind.
*/
public TransformValues getKind() {
return kind;
}
public void updateFrom(DataAnimator.Data dataCopy) {
super.updateFrom(dataCopy);
kind = ((TransformData) dataCopy).kind;
trans.set(((TransformData) dataCopy).trans);
apply();
}
public Object clone() throws CloneNotSupportedException {
TransformData res = (TransformData) super.clone();
res.trans = new Transform3D();
return res;
}
public void set(Values v) {
kind = ((TrValues)v).kind;
set(v.doubleValues, v.data);
}
public Values get(){
TrValues ret=new TrValues();
ret.kind=kind;
ret.doubleValues=getValues();
ret.data=getDataSources();
return ret;
}
public static class TrValues extends Values{
public TrValues(){
super(false);
kind=TransformValues.IDENTITY;
doubleValues=null;
data=null;
}
public TrValues(TrValues v){
super(false);
kind=v.kind;
if(v.doubleValues==null){
doubleValues=null;
}
else{
doubleValues=new double[v.doubleValues.length];
System.arraycopy(v.doubleValues, 0, doubleValues, 0, v.doubleValues.length);
}
if(v.data==null){
data=null;
}
else{
data=new DataSource[v.data.length];
System.arraycopy(v.data, 0, data, 0, v.data.length);
}
}
public TrValues(TransformValues k, TrValues v) {
super(false);
Transform3D trans=new Transform3D();
v.kind.set(trans, v.doubleValues);
kind=k;
doubleValues=TransformValues.get(trans,k);
data=new DataSource[doubleValues.length];
if(v.data!=null){
int i=0;
for(DataSource d : v.data){
if(d!=null && i<data.length){
data[i]=d;
}
i++;
}
}
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if(! (obj instanceof TrValues)){
return false;
}
TrValues v=(TrValues)obj;
if(v.kind!=kind){
return false;
}
if(v.kind==TransformValues.IDENTITY){
return true;
}
for(int i=0;i<v.doubleValues.length;i++){
if(v.doubleValues[i]!=doubleValues[i]){
return false;
}
if(v.data[i]!=data[i]){
return false;
}
}
return true;
}
public TransformValues kind;
}
public void apply() {
super.apply();
kind.set(trans, params);
for (GraphObjectReference o : getReferences()) {
((TransformGroup) o.getObject()).setTransform(trans);
}
}
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException {
out.defaultWriteObject();
}
private void readObject(java.io.ObjectInputStream in)
throws java.lang.ClassNotFoundException, java.io.IOException {
in.defaultReadObject();
trans = new Transform3D();
}
}