Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libAnimation3D / src / main / java / com / iver / cit / gvsig / animation / animationType / AnimationLayer3DFlat.java @ 22949

History | View | Annotate | Download (6.08 KB)

1
package com.iver.cit.gvsig.animation.animationType;
2

    
3
//import org.gvsig.gvsig3dgui.view.View3D;
4

    
5
import org.gvsig.osgvp.viewer.IViewerContainer;
6

    
7
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
8
import com.iver.andami.PluginServices;
9
import com.iver.andami.ui.mdiManager.IWindow;
10
import com.iver.cit.gvsig.animation.IAnimationType;
11
import com.iver.cit.gvsig.animation.animatedObject.AnimationObject3DFlat;
12
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject;
13
import com.iver.cit.gvsig.animation.interpolator.Interpolator3DFlat;
14
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame3DFlat;
15
import com.iver.cit.gvsig.animation.keyframe.IAnimationTypeKeyFrame;
16
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory;
17
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator;
18
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion;
19
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
20
import com.iver.utiles.IPersistence;
21
import com.iver.utiles.XMLEntity;
22

    
23
public class AnimationLayer3DFlat implements IAnimationTypeKeyFrame {
24

    
25
        private String className = this.getClass().getName();
26
        private String description = "Animacion basada en encuadres para vista 3D plana";
27
        private String name = "Animacion vista 3D plana";
28
        private int typeTrack = IAnimationType.TIME_TYPE_TRACK;
29
        private IInterpolator interpolator;
30
        private String nameClassView;
31
        
32
        private IAnimatedObject animationObject3DFlat = new AnimationObject3DFlat() ;
33
        private String titleWindow;
34

    
35
        public AnimationLayer3DFlat() {
36
                this.interpolator = new Interpolator3DFlat();
37
        }
38

    
39
        public String getClassName() {
40
                return className;
41
        }
42

    
43
        public String getDescription() {
44
                return description;
45
        }
46

    
47
        public String getName() {
48
                return name;
49
        }
50

    
51
        public void setClassName(String className) {
52
                this.className = className;
53
        }
54

    
55
        public void setDescription(String description) {
56
                this.description = description;
57
        }
58

    
59
        public void setName(String name) {
60
                this.name = name;
61
        }
62

    
63
        public void AppliesToObject(Object animated) {
64

    
65
                // TODO implementar esta funcion para vistas 3D esfericas.
66
                KeyFrame3DFlat keyf = (KeyFrame3DFlat) animated;
67
                ProjectCamera projectCamera = (ProjectCamera) keyf.getAnimatedObject();
68
                
69
                IViewerContainer m_canvas3d = (IViewerContainer) ((AnimationObject3DFlat)animationObject3DFlat).getAnimatedCanvas3D();
70
                m_canvas3d.getOSGViewer().setCamera(projectCamera.getCamera());
71
                
72
        //        View3D  view3D = (View3D) animationObject3DFlat.getAnimatedObject("view");
73
        //        view3D.setCamera(projectCamera.getCamera());        
74
                
75
//                Hud hud = (Hud) view.getCanvas3d().getOSGViewer().getNodeFromHUD(0);
76
//                hud.setAnimationTime(AnimationPlayer.getCurrentTime()/1000);
77
//                hud.updateHud();
78
                
79
                
80
                //view3D.getCanvas3d().repaint();
81
                m_canvas3d.repaint();
82
        }
83

    
84
        public int getTypeTrack() {
85
                return typeTrack;
86
        }
87

    
88
        public void setTypeTrack(int typeTrack) {
89
                this.typeTrack = typeTrack;
90

    
91
        }
92

    
93
        public IInterpolator getInterpolator() {
94
                return this.interpolator;
95
        }
96

    
97
        public void setInterpolator(IInterpolator interpolator) {
98
                this.interpolator = interpolator;
99

    
100
        }
101

    
102
        public Object getAnimatedObject() {
103
                // if animated object is null.
104
                if(this.animationObject3DFlat != null){
105
                        // getting all objects.
106
                        try{
107
                                IWindow[] viewArray = PluginServices.getMDIManager().getAllWindows();
108
                                for (int i = 0; i < viewArray.length; i++) {
109
                                        IWindow window = viewArray[i];
110
                                        if (window.getClass().getName().equals(this.nameClassView)){
111
                                                // get the actual name of the view, and compare it with the view saved in xml.
112
                                                if(window.getWindowInfo().getTitle().equals(this.titleWindow)){
113
                                                        BaseView newView = (BaseView)window;
114
                                                        this.animationObject3DFlat.addAnimatedObject("view", newView);
115
//                                                        this.animationObject3DFlat.setAnimatedView(newView);
116
                                                        this.setAnimatedObject(this.animationObject3DFlat);
117
                                                        IInterpolatorTimeFuntion function = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
118
                                                        this.interpolator.setFuntion(function);
119
                                                }
120
                                        }
121
                                }
122
                        }catch(Exception e) {
123
                                e.printStackTrace();
124
                        }
125
                }
126
                return this.animationObject3DFlat;
127
        }
128

    
129
        public void setAnimatedObject(Object object) {
130
                this.animationObject3DFlat = (IAnimatedObject) object;
131

    
132
        }
133

    
134
        public XMLEntity getXMLEntity() {
135
                
136
        //        View3D myActualView = null;
137
                
138
                XMLEntity xml = new XMLEntity();
139
                xml.putProperty("className", this.getClassName());
140
                xml.putProperty("description", description);
141
                xml.putProperty("animationTrackTipe", typeTrack);
142
                
143
                IViewerContainer m_canvas3d = (IViewerContainer) ((AnimationObject3DFlat)animationObject3DFlat).getAnimatedCanvas3D();
144
                
145
        //        View3D myActualView = (View3D) animationObject3DFlat.getAnimatedObject("view");
146
        //        xml.putProperty("nameClassView", myActualView.getClass().getName());
147
                
148
                //myActualView = (View3D) ((AnimationObject3DFlat)animationObject3DFlat).getAnimatedView();
149
        //        m_canvas3d.g
150
                //titleWindow = myActualView.getWindowInfo().getTitle();
151
                xml.putProperty("titleWindow", titleWindow);
152
                xml.addChild(((IPersistence)this.interpolator).getXMLEntity());
153
                return xml;
154
        }
155

    
156
        public void setXMLEntity(XMLEntity xml) {
157
//                if (xml.contains("className"))
158
//                        this.className=        xml.getStringProperty("className");
159
                if (xml.contains("animationTrackTipe"))
160
                        this.typeTrack = xml.getIntProperty("animationTrackTipe");
161
                if (xml.contains("nameClassView"))
162
                        this.nameClassView = xml.getStringProperty("nameClassView");
163
                if (xml.contains("titleWindow"))
164
                        this.titleWindow = xml.getStringProperty("titleWindow");
165
                
166
                XMLEntity xmlInterpolator = xml.getChild(0);
167
                
168
                try {
169
                        String class_name = xmlInterpolator.getStringProperty("className");
170
                        Class classInterpolator = Class.forName(class_name);
171
                        Object obj = classInterpolator .newInstance();
172
                        IPersistence objPersist = (IPersistence) obj;
173
                        objPersist.setXMLEntity(xmlInterpolator);
174
                        this.interpolator = (IInterpolator) obj;
175
                        this.setInterpolator(interpolator);
176
                        
177
                } catch (Exception e) {
178
                        e.printStackTrace();
179
                }
180
        }
181
}