001 /*
002 * TrackManager.java
003 *
004 * The Salamander Project - 2D and 3D graphics libraries in Java
005 * Copyright (C) 2004 Mark McKay
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020 *
021 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
022 * projects can be found at http://www.kitfox.com
023 *
024 * Created on September 21, 2004, 11:34 PM
025 */
026
027 package com.kitfox.svg.animation;
028
029 import com.kitfox.svg.xml.StyleAttribute;
030 import java.awt.geom.*;
031 import java.util.*;
032
033 import com.kitfox.svg.*;
034 import com.kitfox.svg.xml.*;
035
036 /**
037 * A track holds the animation events for a single parameter of a single SVG
038 * element. It also contains the default value for the element, should the
039 * user want to see the 'unanimated' value.
040 *
041 * @author Mark McKay
042 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
043 */
044 public class TrackMotion extends TrackBase
045 {
046 public TrackMotion(AnimationElement ele) throws SVGElementException
047 {
048 //The motion element implies a CSS attribute of transform
049 // super(ele.getParent(), "transform", AnimationElement.AT_CSS);
050 super(ele.getParent(), ele);
051 }
052
053 public boolean getValue(StyleAttribute attrib, double curTime) throws SVGException
054 {
055 AffineTransform retVal = new AffineTransform();
056 retVal = getValue(retVal, curTime);
057 // AffineTransform val = getValue(curTime);
058 // if (val == null) return false;
059
060 double[] mat = new double[6];
061 retVal.getMatrix(mat);
062 attrib.setStringValue("matrix(" + mat[0] + " " + mat[1] + " " + mat[2] + " " + mat[3] + " " + mat[4] + " " + mat[5] + ")");
063 return true;
064 }
065
066 public AffineTransform getValue(AffineTransform retVal, double curTime) throws SVGException
067 {
068 //Init transform with default state
069 StyleAttribute attr = null;
070 switch (attribType)
071 {
072 case AnimationElement.AT_CSS:
073 attr = parent.getStyleAbsolute(attribName);
074 retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue()));
075 break;
076 case AnimationElement.AT_XML:
077 attr = parent.getPresAbsolute(attribName);
078 retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue()));
079 break;
080 case AnimationElement.AT_AUTO:
081 attr = parent.getStyleAbsolute(attribName);
082 if (attr == null) attr = parent.getPresAbsolute(attribName);
083 retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue()));
084 break;
085 }
086
087
088 //Update transform with time based information
089 AnimationTimeEval state = new AnimationTimeEval();
090 AffineTransform xform = new AffineTransform();
091 // boolean pastEnd = true;
092
093 for (Iterator it = animEvents.iterator(); it.hasNext();)
094 {
095 AnimateMotion ele = (AnimateMotion)it.next();
096 ele.evalParametric(state, curTime);
097
098 //Go to next element if this one does not affect processing
099 if (Double.isNaN(state.interp)) continue;
100
101 switch (ele.getAdditiveType())
102 {
103 case AnimationElement.AD_SUM:
104 retVal.concatenate(ele.eval(xform, state.interp));
105 break;
106 case AnimationElement.AD_REPLACE:
107 retVal.setTransform(ele.eval(xform, state.interp));
108 break;
109 }
110
111 //Evaluate accumulation if applicable
112 /*
113 if (state.rep > 0)
114 {
115 switch (ele.getAccumulateType())
116 {
117 case AnimationElement.AC_SUM:
118 retVal += ele.repeatSkipSize(state.rep);
119 break;
120 }
121
122 }
123 */
124 }
125
126 return retVal;
127 }
128 }