Statistics
| Revision:

svn-gvsig-desktop / tags / 3D_Animation_v1_0alpha_Build_5 / libraries / lib3DMap / src / org / gvsig / gvsig3d / map3d / GraphicLayer3D.java @ 25534

History | View | Annotate | Download (5.17 KB)

1 21940 jcampos
package org.gvsig.gvsig3d.map3d;
2 15236 julio
3
import java.awt.geom.Point2D;
4 21908 jcampos
import java.io.FileNotFoundException;
5 15236 julio
6 20893 jcampos
import org.apache.log4j.Logger;
7 21940 jcampos
import org.gvsig.gvsig3d.gui.FeatureFactory;
8 20893 jcampos
import org.gvsig.osgvp.AutoTransform;
9
import org.gvsig.osgvp.Group;
10
import org.gvsig.osgvp.Node;
11
import org.gvsig.osgvp.Vec3;
12
import org.gvsig.osgvp.Vec4;
13
import org.gvsig.osgvp.osgDB;
14
import org.gvsig.osgvp.exceptions.InvalidValueException;
15
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions;
16
import org.gvsig.osgvp.exceptions.node.LoadNodeException;
17
import org.gvsig.osgvp.exceptions.node.NodeException;
18
import org.gvsig.osgvp.features.Text;
19
import org.gvsig.osgvp.planets.Planet;
20
import org.gvsig.osgvp.planets.PlanetViewer;
21
22 22171 jcampos
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
23 15236 julio
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
24
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
25
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
26
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel;
27
28
public class GraphicLayer3D extends GraphicLayer {
29
30
        private Node especialNode;
31
32
        private Planet planet;
33
34 15441 julio
        private PlanetViewer planetViewer;
35
36 20893 jcampos
        private static Logger logger = Logger.getLogger(GraphicLayer3D.class
37
                        .getName());
38
39 15441 julio
        public GraphicLayer3D(PlanetViewer planetViewer, Planet planet) {
40 15236 julio
                super();
41 15441 julio
                this.planetViewer = planetViewer;
42 20893 jcampos
                try {
43
                        this.especialNode = planetViewer.getSpecialNode(0);
44
                } catch (ChildIndexOutOfBoundsExceptions e) {
45
                        logger.error("Command: " + "Error Child index out of bound.", e);
46
                }
47 15236 julio
                this.planet = planet;
48
        }
49
50
        public void clearAllGraphics() {
51
                // codigo de borrado de busquedas
52 20893 jcampos
                Group grupo = null;
53
                try {
54
                        grupo = (Group) planetViewer.getSpecialNode(0);
55
                } catch (ChildIndexOutOfBoundsExceptions e) {
56
                        logger.error("Command: " + "Error child index out of bound.", e);
57
                }
58 15242 julio
59 20893 jcampos
                while (grupo.getNumChildren() > 0) {
60
                        Node node;
61
                        try {
62
                                node = grupo.getChild(0);
63
                                grupo.removeChild(node);
64
                        } catch (ChildIndexOutOfBoundsExceptions e) {
65
                                logger
66
                                                .error("Command: " + "Error Child index out of bound.",
67
                                                                e);
68
                        } catch (NodeException e) {
69
                                logger.error("Command: " + "Error removing Child from group.",
70
                                                e);
71
                        }
72 15242 julio
                }
73 15236 julio
        }
74
75
        public void addGraphic(FGraphic g) {
76 15587 rgaitan
                // a�adir la etiqueta aki
77 15236 julio
78
                FGraphicLabel label = (FGraphicLabel) g;
79
80
                FLabel lab = label.getLabel();
81
                Point2D p = lab.getOrig();
82
83
                System.out.println("etiqueta ::: " + label.getLabel().getString());
84
85
                // Variable declaration
86
                Vec3 posI = null, posE = null, posT = null;
87
                Vec3 posIni = null, posEnd = null, posText = null, pos1 = null, pos2 = null;
88
89
                // search for Gazetteer
90
                // There are two gazetteer modes SPHERICAL and PLANE mode
91 15587 rgaitan
                if (planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) {
92 15236 julio
                        // For spheriacl mode
93
94
                        // Geodesical coordinates
95
                        posI = new Vec3(p.getY(), p.getX(), 0);
96
                        posE = new Vec3(p.getY(), p.getX(), 10000);
97
                        posT = new Vec3(p.getY(), p.getX(), 50000); // Text position
98
99
                        // To convert coordinate to cartesian
100
                        posIni = planet.convertLatLongHeightToXYZ(posI);
101
                        posEnd = planet.convertLatLongHeightToXYZ(posE);
102
103
                        posText = planet.convertLatLongHeightToXYZ(posT);
104
105 15587 rgaitan
                } else if (planet.getCoordinateSystemType() == Planet.CoordinateSystemType.PROJECTED) {
106 15236 julio
107
                        // For plane mode
108
                        posIni = new Vec3(p.getX(), p.getY(), 0);
109
                        posText = new Vec3(p.getX(), p.getY(), 50000); // Text position
110
                }
111
                // To display text in gazetteer
112 20893 jcampos
                Text text = (Text) FeatureFactory.insertTextoS(label.getLabel()
113
                                .getString(), posText, new Vec4(1.0, 0.0, 0.0, 1.0), 30, true);
114 15236 julio
115 20893 jcampos
                Group grupo = null;
116
                try {
117
                        grupo = (Group) planetViewer.getSpecialNode(0);
118
                } catch (ChildIndexOutOfBoundsExceptions e) {
119
                        logger.error("Command: " + "Error Child index out of bound.", e);
120
                }
121 15236 julio
                String name = ResourcesFactory.getResourcePath("flag.ive");
122 20893 jcampos
                Node flag = null;
123
                try {
124
                        flag = osgDB.readNodeFile(name);
125
                } catch (LoadNodeException e) {
126
                        logger.error("Command: " + "Error reading file from system.", e);
127 21908 jcampos
                } catch (FileNotFoundException e) {
128
                        // TODO Auto-generated catch block
129
                        e.printStackTrace();
130 20893 jcampos
                }
131 15236 julio
132
                // Con autotransform
133 21908 jcampos
                AutoTransform trans = null;
134 20893 jcampos
                try {
135 21908 jcampos
                        trans = new AutoTransform();
136
                } catch (NodeException e1) {
137
                        // TODO Auto-generated catch block
138
                        e1.printStackTrace();
139
                }
140
                try {
141 20893 jcampos
                        trans.addChild(flag);
142
                } catch (NodeException e) {
143
                        logger.error("Command: " + "Error adding new child.", e);
144
                }
145 15236 julio
                int scale = (int) ((20 / 4.5) * 1000);
146
                trans.setScale(new Vec3(scale, scale, scale));
147
                trans.setPosition(posIni);
148 20893 jcampos
                try {
149
                        trans
150
                                        .setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA);
151
                } catch (InvalidValueException e) {
152
                        logger.error("Command: " + "Error setting new camera property.", e);
153
                }
154 15236 julio
155 15242 julio
                // Add nodes to graph
156 20893 jcampos
                // grupo.setNodeName("gazetteer");
157
                try {
158
                        grupo.addChild(trans);
159
                        grupo.addChild(text);
160
                } catch (NodeException e) {
161
                        logger.error("Command: " + "Error adding new child.", e);
162
                }
163 15236 julio
164
        }
165
166
        public Node getEspecialNode() {
167
                return especialNode;
168
        }
169
170
        public void setEspecialNode(Node especialNode) {
171
                this.especialNode = especialNode;
172
        }
173
174
}