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 |
package org.gvsig.gvsig3d.map3d; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
import java.io.FileNotFoundException; |
5 |
|
6 |
import org.apache.log4j.Logger; |
7 |
import org.gvsig.gvsig3d.gui.FeatureFactory; |
8 |
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 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
23 |
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 |
private PlanetViewer planetViewer;
|
35 |
|
36 |
private static Logger logger = Logger.getLogger(GraphicLayer3D.class |
37 |
.getName()); |
38 |
|
39 |
public GraphicLayer3D(PlanetViewer planetViewer, Planet planet) {
|
40 |
super();
|
41 |
this.planetViewer = planetViewer;
|
42 |
try {
|
43 |
this.especialNode = planetViewer.getSpecialNode(0); |
44 |
} catch (ChildIndexOutOfBoundsExceptions e) {
|
45 |
logger.error("Command: " + "Error Child index out of bound.", e); |
46 |
} |
47 |
this.planet = planet;
|
48 |
} |
49 |
|
50 |
public void clearAllGraphics() { |
51 |
// codigo de borrado de busquedas
|
52 |
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 |
|
59 |
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 |
} |
73 |
} |
74 |
|
75 |
public void addGraphic(FGraphic g) { |
76 |
// a�adir la etiqueta aki
|
77 |
|
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 |
if (planet.getCoordinateSystemType() == Planet.CoordinateSystemType.GEOCENTRIC) {
|
92 |
// 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 |
} else if (planet.getCoordinateSystemType() == Planet.CoordinateSystemType.PROJECTED) { |
106 |
|
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 |
Text text = (Text) FeatureFactory.insertTextoS(label.getLabel() |
113 |
.getString(), posText, new Vec4(1.0, 0.0, 0.0, 1.0), 30, true); |
114 |
|
115 |
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 |
String name = ResourcesFactory.getResourcePath("flag.ive"); |
122 |
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 |
} catch (FileNotFoundException e) { |
128 |
// TODO Auto-generated catch block
|
129 |
e.printStackTrace(); |
130 |
} |
131 |
|
132 |
// Con autotransform
|
133 |
AutoTransform trans = null;
|
134 |
try {
|
135 |
trans = new AutoTransform();
|
136 |
} catch (NodeException e1) {
|
137 |
// TODO Auto-generated catch block
|
138 |
e1.printStackTrace(); |
139 |
} |
140 |
try {
|
141 |
trans.addChild(flag); |
142 |
} catch (NodeException e) {
|
143 |
logger.error("Command: " + "Error adding new child.", e); |
144 |
} |
145 |
int scale = (int) ((20 / 4.5) * 1000); |
146 |
trans.setScale(new Vec3(scale, scale, scale));
|
147 |
trans.setPosition(posIni); |
148 |
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 |
|
155 |
// Add nodes to graph
|
156 |
// 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 |
|
164 |
} |
165 |
|
166 |
public Node getEspecialNode() {
|
167 |
return especialNode;
|
168 |
} |
169 |
|
170 |
public void setEspecialNode(Node especialNode) { |
171 |
this.especialNode = especialNode;
|
172 |
} |
173 |
|
174 |
} |