svn-gvsig-desktop / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / ProjectView3D.java @ 25839
History | View | Annotate | Download (24.7 KB)
1 |
package org.gvsig.gvsig3dgui; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.geom.Rectangle2D; |
5 |
import java.util.Comparator; |
6 |
import java.util.HashMap; |
7 |
import java.util.Iterator; |
8 |
import java.util.TreeMap; |
9 |
import java.util.Map.Entry; |
10 |
import java.util.prefs.Preferences; |
11 |
|
12 |
import org.apache.log4j.Logger; |
13 |
import org.gvsig.cacheservice.CacheService; |
14 |
import org.gvsig.gvsig3d.gui.FeatureFactory; |
15 |
import org.gvsig.gvsig3d.gui.Hud; |
16 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
17 |
import org.gvsig.gvsig3d.map3d.layers.FLayers3D; |
18 |
import org.gvsig.gvsig3d.navigation.NavigationMode; |
19 |
import org.gvsig.gvsig3dgui.view.View3D; |
20 |
import org.gvsig.gvsig3dgui.view.ViewProperties3D; |
21 |
import org.gvsig.osgvp.Vec3; |
22 |
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions; |
23 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
24 |
import org.gvsig.osgvp.planets.Planet; |
25 |
import org.gvsig.osgvp.planets.PlanetViewer; |
26 |
import org.gvsig.osgvp.planets.exceptions.PlanetExtentException; |
27 |
import org.gvsig.osgvp.viewer.Camera; |
28 |
import org.gvsig.osgvp.viewer.CanvasViewer; |
29 |
import org.gvsig.osgvp.viewer.DisplaySettings; |
30 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
31 |
import org.gvsig.osgvp.viewer.ViewerFactory; |
32 |
import org.gvsig.osgvp.viewer.ViewerStateListener; |
33 |
|
34 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
35 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
36 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
37 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
38 |
import com.iver.andami.PluginServices; |
39 |
import com.iver.andami.ui.mdiManager.IWindow; |
40 |
import com.iver.cit.gvsig.fmap.MapContext; |
41 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
42 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
43 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
44 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
45 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
46 |
import com.iver.cit.gvsig.project.Project; |
47 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
48 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
49 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
50 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
51 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
52 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
53 |
import com.iver.cit.gvsig.project.documents.view.ProjectViewBase; |
54 |
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
55 |
import com.iver.utiles.IPersistence; |
56 |
import com.iver.utiles.StringUtilities; |
57 |
import com.iver.utiles.XMLEntity; |
58 |
|
59 |
/**
|
60 |
* Clase que representa una vista del proyecto
|
61 |
*
|
62 |
* @author Fernando Gonz�lez Cort�s
|
63 |
*/
|
64 |
public class ProjectView3D extends ProjectViewBase { |
65 |
// public static int numViews = 0;
|
66 |
|
67 |
private IViewerContainer m_canvas3d = null; |
68 |
|
69 |
private PlanetViewer m_planetViewer = null; |
70 |
|
71 |
private Planet m_planet = null; |
72 |
|
73 |
private ProjectCamera projectCamera = null; |
74 |
|
75 |
private int m_planetType = Planet.CoordinateSystemType.PROJECTED; // spheric |
76 |
// or
|
77 |
// plane
|
78 |
|
79 |
private Color backgroundColor; |
80 |
|
81 |
private float verticalExaggeration = 5; |
82 |
|
83 |
private FeatureFactory g;
|
84 |
|
85 |
private View3D m_view = null; |
86 |
|
87 |
private static Preferences prefs = Preferences.userRoot().node( |
88 |
"gvsig.configuration.3D");
|
89 |
|
90 |
private boolean prespectiveMode = true; |
91 |
|
92 |
private static Logger logger = Logger.getLogger(ProjectView3D.class |
93 |
.getName()); |
94 |
|
95 |
// private Satelite runnable;
|
96 |
|
97 |
public ProjectView3D() {
|
98 |
super();
|
99 |
backgroundColor = new Color(0, 0, 0, 255); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*
|
105 |
* @return DOCUMENT ME!
|
106 |
* @throws XMLException
|
107 |
* @throws SaveException
|
108 |
*/
|
109 |
public XMLEntity getXMLEntity() throws SaveException { |
110 |
XMLEntity xml = super.getXMLEntity();
|
111 |
// xml.putProperty("nameClass", this.getClass().getName());
|
112 |
try {
|
113 |
// Persistiendo la posicion actual de la camara
|
114 |
// TODO: remove this line where planet viewer will be test
|
115 |
// if (m_canvas3d != null) {
|
116 |
// projectCamera = new ProjectCamera();
|
117 |
// projectCamera.setDescription("Camera");
|
118 |
// projectCamera.setCamera(m_canvas3d.getOSGViewer().getCamera());
|
119 |
//
|
120 |
// xml.addChild(projectCamera.getXMLEntity());
|
121 |
// }
|
122 |
|
123 |
if (this.m_planetViewer != null) { |
124 |
projectCamera = new ProjectCamera();
|
125 |
projectCamera.setDescription("Camera");
|
126 |
projectCamera.setCamera(this.m_planetViewer.getCamera());
|
127 |
|
128 |
xml.addChild(projectCamera.getXMLEntity()); |
129 |
} |
130 |
|
131 |
int numViews = ((Integer) ProjectDocument.NUMS |
132 |
.get(ProjectView3DFactory.registerName)).intValue(); |
133 |
xml.putProperty("numViews", numViews);
|
134 |
xml.putProperty("m_selectedField", m_selectedField);
|
135 |
xml.putProperty("m_typeLink", m_typeLink);
|
136 |
xml.putProperty("m_extLink", m_extLink);
|
137 |
|
138 |
// 3D properties
|
139 |
xml.putProperty("planetType", m_planetType);
|
140 |
xml.putProperty("verticalExaggeration", verticalExaggeration);
|
141 |
|
142 |
xml.putProperty("backgroundColor", StringUtilities
|
143 |
.color2String(backgroundColor)); |
144 |
|
145 |
xml.addChild(mapContext.getXMLEntity()); |
146 |
|
147 |
if (mapOverViewContext != null) { |
148 |
if (mapOverViewContext.getViewPort() != null) { |
149 |
xml.putProperty("mapOverView", true); |
150 |
xml.addChild(mapOverViewContext.getXMLEntity()); |
151 |
} else {
|
152 |
xml.putProperty("mapOverView", false); |
153 |
} |
154 |
} else {
|
155 |
xml.putProperty("mapOverView", false); |
156 |
} |
157 |
} catch (Exception e) { |
158 |
throw new SaveException(e, this.getClass().getName()); |
159 |
} |
160 |
|
161 |
return xml;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* DOCUMENT ME!
|
166 |
*
|
167 |
* @param xml
|
168 |
* DOCUMENT ME!
|
169 |
* @param p
|
170 |
* DOCUMENT ME!
|
171 |
* @throws XMLException
|
172 |
* @throws DriverException
|
173 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
174 |
*/
|
175 |
public void setXMLEntity03(XMLEntity xml, Project p) throws XMLException { |
176 |
try {
|
177 |
super.setXMLEntity03(xml);
|
178 |
} catch (ReadDriverException e) {
|
179 |
// TODO Auto-generated catch block
|
180 |
e.printStackTrace(); |
181 |
} |
182 |
int numViews = xml.getIntProperty("numViews"); |
183 |
ProjectDocument.NUMS.put(ProjectView3DFactory.registerName, |
184 |
new Integer(numViews)); |
185 |
|
186 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
187 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
188 |
m_extLink = xml.getStringProperty("m_extLink");
|
189 |
setMapContext(MapContext3D.createFromXML03(xml.getChild(0)));
|
190 |
|
191 |
if (xml.getBooleanProperty("mapOverView")) { |
192 |
setMapOverViewContext(MapContext.createFromXML03(xml.getChild(1)));
|
193 |
} |
194 |
|
195 |
} |
196 |
|
197 |
/**
|
198 |
* DOCUMENT ME!
|
199 |
*
|
200 |
* @param xml
|
201 |
* DOCUMENT ME!
|
202 |
* @param p
|
203 |
* DOCUMENT ME!
|
204 |
* @throws XMLException
|
205 |
* @throws OpenException
|
206 |
*
|
207 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
208 |
*/
|
209 |
public void setXMLEntity(XMLEntity xml) throws XMLException, OpenException { |
210 |
try {
|
211 |
super.setXMLEntity(xml);
|
212 |
int currentChild = 0; |
213 |
|
214 |
// Read last child
|
215 |
int childNumber = currentChild;
|
216 |
|
217 |
// Get camera
|
218 |
XMLEntity xmlProp = xml.getChild(childNumber); |
219 |
if (xmlProp.contains("eyeX")) { |
220 |
try {
|
221 |
String className = xmlProp.getStringProperty("className"); |
222 |
Class classProp = Class.forName(className); |
223 |
Object obj = classProp.newInstance();
|
224 |
IPersistence objPersist = (IPersistence) obj; |
225 |
objPersist.setXMLEntity(xmlProp); |
226 |
projectCamera = (ProjectCamera) obj; |
227 |
} catch (Exception e) { |
228 |
|
229 |
} |
230 |
currentChild++; |
231 |
} |
232 |
|
233 |
int numViews = xml.getIntProperty("numViews"); |
234 |
ProjectDocument.NUMS.put(ProjectView3DFactory.registerName, |
235 |
new Integer(numViews)); |
236 |
|
237 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
238 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
239 |
m_extLink = xml.getStringProperty("m_extLink");
|
240 |
|
241 |
// 3D properties
|
242 |
m_planetType = xml.getIntProperty("planetType");
|
243 |
verticalExaggeration = xml.getFloatProperty("verticalExaggeration");
|
244 |
|
245 |
backgroundColor = StringUtilities.string2Color((xml |
246 |
.getStringProperty("backgroundColor")));
|
247 |
|
248 |
setMapContext(MapContext3D |
249 |
.createFromXML(xml.getChild(currentChild))); |
250 |
currentChild++; |
251 |
if (xml.getBooleanProperty("mapOverView")) { |
252 |
setMapOverViewContext(MapContext.createFromXML(xml |
253 |
.getChild(currentChild))); |
254 |
currentChild++; |
255 |
} |
256 |
getOrCreateView(); |
257 |
showErrors(); |
258 |
} catch (Exception e) { |
259 |
throw new OpenException(e, this.getClass().getName()); |
260 |
} |
261 |
|
262 |
} |
263 |
|
264 |
public String getFrameName() { |
265 |
return PluginServices.getText(this, "Vista3D"); |
266 |
} |
267 |
|
268 |
public IViewerContainer getOrCreateCanvas3D() {
|
269 |
// create libJOSG objects
|
270 |
if (m_canvas3d == null) { |
271 |
// AI2 objects
|
272 |
try {
|
273 |
m_planetViewer = new PlanetViewer();
|
274 |
} catch (NodeException e1) {
|
275 |
logger.error("Command: " + "Error creating planer viewer.", e1); |
276 |
} |
277 |
|
278 |
// Getting 3D preferences
|
279 |
boolean compatibilitySwing = false; |
280 |
compatibilitySwing = prefs.getBoolean("compatibilitySwing",
|
281 |
compatibilitySwing); |
282 |
|
283 |
if (compatibilitySwing) {
|
284 |
m_canvas3d = ViewerFactory.getInstance() |
285 |
.createViewer(ViewerFactory.VIEWER_TYPE.JPANEL_VIEWER, |
286 |
m_planetViewer); |
287 |
} else {
|
288 |
m_canvas3d = ViewerFactory.getInstance() |
289 |
.createViewer(ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, |
290 |
m_planetViewer); |
291 |
} |
292 |
|
293 |
this.configureProjectionViewMode();
|
294 |
// m_canvas3d = ViewerFactory.getInstance().createViewer(
|
295 |
// ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, m_planetViewer);
|
296 |
m_canvas3d.addKeyListener(new ViewerStateListener(m_canvas3d
|
297 |
.getOSGViewer())); |
298 |
|
299 |
// ViewerFactory.getInstance().startAnimator();
|
300 |
|
301 |
//
|
302 |
m_canvas3d.getOSGViewer().setDisplaySettings(new DisplaySettings());
|
303 |
|
304 |
//
|
305 |
m_planetViewer.setEnabledLighting(false);
|
306 |
ViewerFactory.getInstance().startAnimator(); |
307 |
|
308 |
// try {
|
309 |
// ((PlanetViewer) m_canvas3d.getOSGViewer()).activePlanet(0);
|
310 |
// } catch (ChildIndexOutOfBoundsExceptions e1) {
|
311 |
// // TODO Auto-generated catch block
|
312 |
// e1.printStackTrace();
|
313 |
// }
|
314 |
// ((PlanetViewer) m_canvas3d.getOSGViewer()).computeActiveCoordinateSystemNodePath();
|
315 |
|
316 |
// REPAINTING VIEWER
|
317 |
if (m_canvas3d != null) |
318 |
m_canvas3d.repaint(); |
319 |
|
320 |
if (getBackGroundColor() != null) { |
321 |
float r, g, b, a;
|
322 |
r = ((float) backgroundColor.getRed()) / 255.0f; |
323 |
g = ((float) backgroundColor.getGreen()) / 255.0f; |
324 |
b = ((float) backgroundColor.getBlue()) / 255.0f; |
325 |
a = ((float) backgroundColor.getAlpha()) / 255.0f; |
326 |
m_planetViewer.setClearColor(r, g, b, a); |
327 |
} |
328 |
try {
|
329 |
m_planet = new Planet();
|
330 |
m_planet.setCoordinateSystemType(m_planetType); |
331 |
if (m_planetType == Planet.CoordinateSystemType.PROJECTED) {
|
332 |
m_planet.setCoordinateSystemName("EPSG:23030");
|
333 |
double extent[] = new double[4]; |
334 |
extent[0] = CacheService.planeGlobalBounds.getMinX();
|
335 |
extent[1] = CacheService.planeGlobalBounds.getMinY();
|
336 |
extent[2] = CacheService.planeGlobalBounds.getMaxX();
|
337 |
extent[3] = CacheService.planeGlobalBounds.getMaxY();
|
338 |
m_planet.setExtent(extent); |
339 |
} |
340 |
} catch (NodeException e2) {
|
341 |
// TODO Auto-generated catch block
|
342 |
e2.printStackTrace(); |
343 |
} catch (PlanetExtentException e) {
|
344 |
// TODO Auto-generated catch block
|
345 |
e.printStackTrace(); |
346 |
} |
347 |
|
348 |
// canvasListener lis = new canvasListener();
|
349 |
// lis.setCanvas(m_canvas3d);
|
350 |
// m_canvas3d.addKeyListener(lis);
|
351 |
/*
|
352 |
* CODIGO DE PRUEBA PARA LA INCLUSION DE TEXTOS, POLIGONOS, LINEAS,
|
353 |
* ETC...
|
354 |
*/
|
355 |
|
356 |
double radiusEarth = m_planet.getRadiusEquatorial();
|
357 |
g = new FeatureFactory(radiusEarth, m_planet);
|
358 |
|
359 |
// g.setNodeName("VECTOR");
|
360 |
// Group root = new Group();
|
361 |
|
362 |
// root.addChild(g);
|
363 |
// root.addChild(m_planet);
|
364 |
// PositionAttitudeTransform nt = new PositionAttitudeTransform();
|
365 |
// nt.addChild(m_canvas3d.readNodeFile("c:/modelos3d/spaceship.osg"));
|
366 |
// nt.addChild(m_canvas3d.readNodeFile("c:/modelos3d/axes.osg"));
|
367 |
// nt.addChild(m_canvas3d.readNodeFile("c:/modelos3d/cow.osg"));
|
368 |
// nt.addChild(m_canvas3d.readNodeFile("c:/modelos3d/cessna.osg"));
|
369 |
// nt.setPosition(new Vec3 (0,0,0) );
|
370 |
// nt.setScale(new Vec3 (1,1,1));
|
371 |
// m_canvas3d.addSpecialNode(nt);
|
372 |
// m_canvas3d.addSpecialNode(m_canvas3d.readNodeFile("c:/modelos3d/axes.osg"));
|
373 |
// m_canvas3d.addSpecialNode(m_canvas3d.readNodeFile("c:/modelos3d/spaceship.osg"));
|
374 |
// m_canvas3d.addSpecialNode(m_canvas3d.readNodeFile("c:/modelos3d/cow.osg"));
|
375 |
// root.addChild(m_canvas3d.readNodeFile("c:/modelos3d/cow.osg"));
|
376 |
// root.addChild(m_canvas3d.readNodeFile("c:/modelos3d/cessna.osg"));
|
377 |
// m_canvas3d.setSceneData(root);
|
378 |
|
379 |
// float cenLat = (float) ((-1) *(40 * 2 * Math.PI)/360),
|
380 |
// cenLon= (float) ( (-1) *(3 * 2* Math.PI)/360);
|
381 |
//
|
382 |
// PositionAttitudeTransform rot1 = new PositionAttitudeTransform();
|
383 |
// PositionAttitudeTransform rot2 = new PositionAttitudeTransform();
|
384 |
// // cargando la bandera
|
385 |
// String name = ResourcesFactory.getResourcePath("flag.ive");
|
386 |
// rot1.addChild(this.m_canvas3d.getOSGViewer().readNodeFile(name));
|
387 |
//
|
388 |
// rot1.setAttitude(cenLon, new Vec3(0.0, 1.0, 0.0));
|
389 |
// rot1.setScale(new Vec3(600, 600, 600));
|
390 |
//
|
391 |
//
|
392 |
// rot2.addChild(rot1);
|
393 |
// rot2.setAttitude(cenLat, new Vec3(1.0, 0.0, 0.0));
|
394 |
// rot2.setPosition( new Vec3(0.0, 0.0, 0.0));
|
395 |
//
|
396 |
// root.addChild(rot2);
|
397 |
/* ************************************************************************* */
|
398 |
|
399 |
// m_planetViewer.addSpecialNode(g);
|
400 |
// List posi = new ArrayList();
|
401 |
// for (int i = 0; i < 10; i++) {
|
402 |
// Vec3 pos1 = m_planet.convertLatLongHeightToXYZ(new Vec3(0, Math
|
403 |
// .toRadians(i * 10), 0));
|
404 |
//
|
405 |
// // Vec3 pos1 = new Vec3(0, i * 10, 0);
|
406 |
// posi.add(pos1);
|
407 |
// }
|
408 |
// Vec4 rgba = new Vec4(1.0, 1.0, 1.0, 1.0);
|
409 |
// float lineWidth = 8;
|
410 |
// g.addChild(FeatureFactory.insertLine(posi, rgba, lineWidth));
|
411 |
// m_planetViewer.addSpecialNode(FeatureFactory.insertLine(posi,
|
412 |
// rgba,
|
413 |
// lineWidth));
|
414 |
// m_planetViewer.addSpecialNode(osgDB.readNodeFile(ResourcesFactory
|
415 |
// .getResourcesPath()
|
416 |
// + "../images/flag.ive"));
|
417 |
// m_canvas3d.getOSGViewer().addSpecialNode(root);
|
418 |
// Cargando el satelite
|
419 |
// m_canvas3d.addSpecialNode(sat);
|
420 |
try {
|
421 |
m_planetViewer.addPlanet(m_planet); |
422 |
} catch (NodeException e1) {
|
423 |
logger.error("Command: " + "Error adding new child node.", e1); |
424 |
} |
425 |
|
426 |
Camera cam; |
427 |
cam = new Camera();
|
428 |
if (this.projectCamera == null) { |
429 |
|
430 |
if (m_planetType == Planet.CoordinateSystemType.PROJECTED) {
|
431 |
Rectangle2D e = m_planet.getExtent();
|
432 |
// double difx = (e[1] - e[0]) / 2.0d;
|
433 |
// double dify = (e[3] - e[2]) / 2.0d;
|
434 |
// double posx = e[0] + difx;
|
435 |
// double posy = e[2] + dify;
|
436 |
|
437 |
double height;
|
438 |
height = Math.sqrt(e.getWidth() * e.getWidth()
|
439 |
+ e.getHeight() * e.getHeight()) * 10f;
|
440 |
cam.setViewByLookAt((float) e.getCenterX(), (float) e |
441 |
.getCenterY(), (float) height, (float) e |
442 |
.getCenterX(), (float) e.getCenterY(), 0f, 0f, 1f, |
443 |
0f);
|
444 |
cam.setViewByLookAt(0, 0, 5000000 * 4.6, 0, 0, 0, 0, 1, 0); |
445 |
m_planetViewer.getCustomTerrainManipulator() |
446 |
.setMinCameraDistance(10);
|
447 |
m_planetViewer.getCustomTerrainManipulator() |
448 |
.setMaxCameraDistance(5000000 * 10); |
449 |
// m_planet.setSubdivisionFactor((float) 0.45);
|
450 |
} else {
|
451 |
// cam.setViewByLookAt(m_planet.getRadiusEquatorial() * 3.0,
|
452 |
// 0, 0, 0, 0, 0, 0, 0, 1);
|
453 |
cam.setViewByLookAt(m_planet.getRadiusEquatorial() * 8.0,
|
454 |
0, 0, 0, 0, 0, 0, 0, 1); |
455 |
m_planetViewer.getCustomTerrainManipulator() |
456 |
.setMinCameraDistance(100);
|
457 |
// m_planetViewer.getCustomTerrainManipulator()
|
458 |
// .setMaxCameraDistance(
|
459 |
// m_planet.getRadiusEquatorial() * 3.0);
|
460 |
m_planetViewer.getCustomTerrainManipulator() |
461 |
.setMaxCameraDistance( |
462 |
m_planet.getRadiusEquatorial() * 10.0);
|
463 |
// cam.setViewByLookAt(100 * 2.0,
|
464 |
// 0, 0, 0, 0, 0, 0, 0, 1);
|
465 |
// m_planet.setSubdivisionFactor((float) 0.65);
|
466 |
} |
467 |
|
468 |
} else {
|
469 |
cam = projectCamera.getCamera(); |
470 |
} |
471 |
|
472 |
// m_canvas3d.getOSGViewer().setCameraManipulator(new
|
473 |
// TrackballManipulator());
|
474 |
|
475 |
m_planetViewer.setCamera(cam); |
476 |
|
477 |
Hud hud = new Hud(m_canvas3d, m_planet);
|
478 |
try {
|
479 |
m_planetViewer.addNodeToHUD(hud); |
480 |
} catch (NodeException e) {
|
481 |
logger.error("Command: " + "Error adding node to hud.", e); |
482 |
} |
483 |
|
484 |
m_planetViewer.setEnabledLighting(true);
|
485 |
|
486 |
} |
487 |
m_canvas3d.addKeyListener(new Key3DListener(this.m_planet)); |
488 |
|
489 |
return m_canvas3d;
|
490 |
} |
491 |
|
492 |
public View3D getOrCreateView() {
|
493 |
if(m_view == null) { |
494 |
m_view = new View3D();
|
495 |
|
496 |
m_view.setCanvas3d(getOrCreateCanvas3D()); |
497 |
|
498 |
m_view.setPlanet(m_planet); |
499 |
m_view.setModel(this);
|
500 |
m_view.setNavMode(new NavigationMode(((PlanetViewer) m_planetViewer)
|
501 |
.getCustomTerrainManipulator())); |
502 |
|
503 |
((MapContext3D) getMapContext()) |
504 |
.setVerticalExageration(verticalExaggeration); |
505 |
setVerticalEx(verticalExaggeration); |
506 |
} |
507 |
return m_view;
|
508 |
} |
509 |
|
510 |
public IWindow createWindow() {
|
511 |
|
512 |
// View allready exits. Return it.
|
513 |
if (m_view != null) |
514 |
return m_view;
|
515 |
|
516 |
getOrCreateView(); |
517 |
|
518 |
callCreateWindow(m_view); |
519 |
return m_view;
|
520 |
} |
521 |
|
522 |
protected void finalize() throws Throwable { |
523 |
if (m_canvas3d != null) { |
524 |
// runnable.end();
|
525 |
ViewerFactory.getInstance().stopAnimator(); |
526 |
m_planet.dispose(); |
527 |
m_planetViewer.dispose(); |
528 |
} |
529 |
} |
530 |
|
531 |
public IWindow getProperties() {
|
532 |
return new ViewProperties3D(this, false); // new ViewProperties(this); |
533 |
// TODO
|
534 |
} |
535 |
|
536 |
public void exportToXML(XMLEntity root, Project project) |
537 |
throws SaveException {
|
538 |
XMLEntity viewsRoot = project.getExportXMLTypeRootNode(root, |
539 |
ProjectViewFactory.registerName); |
540 |
viewsRoot.addChild(this.getXMLEntity());
|
541 |
this.exportToXMLLayerDependencies(this.getMapContext().getLayers(), |
542 |
root, project); |
543 |
if (this.getMapOverViewContext() != null) { |
544 |
this.exportToXMLLayerDependencies(this.getMapOverViewContext() |
545 |
.getLayers(), root, project); |
546 |
} |
547 |
} |
548 |
|
549 |
private void exportToXMLLayerDependencies(FLayer layer, XMLEntity root, |
550 |
Project project) throws SaveException {
|
551 |
|
552 |
if (layer instanceof FLayers) { |
553 |
FLayers layers = (FLayers) layer; |
554 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
555 |
this.exportToXMLLayerDependencies(layers.getLayer(i), root,
|
556 |
project); |
557 |
} |
558 |
} else {
|
559 |
if (layer instanceof AlphanumericData) { |
560 |
|
561 |
try {
|
562 |
project |
563 |
.exportToXMLDataSource(root, |
564 |
((AlphanumericData) layer).getRecordset() |
565 |
.getName()); |
566 |
} catch (ReadDriverException e) {
|
567 |
// TODO Auto-generated catch block
|
568 |
e.printStackTrace(); |
569 |
} |
570 |
|
571 |
ProjectTable pt = project.getTable((AlphanumericData) layer); |
572 |
if (pt != null) { |
573 |
pt.exportToXML(root, project); |
574 |
} |
575 |
} |
576 |
} |
577 |
} |
578 |
|
579 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot, |
580 |
int elementIndex, Project project, boolean removeDocumentsFromRoot) |
581 |
throws XMLException, OpenException {
|
582 |
XMLEntity element = typeRoot.getChild(elementIndex); |
583 |
|
584 |
this.setXMLEntity(element);
|
585 |
project.addDocument(this);
|
586 |
if (removeDocumentsFromRoot) {
|
587 |
typeRoot.removeChild(elementIndex); |
588 |
} |
589 |
|
590 |
// Cargamos las tables vinculadas:
|
591 |
|
592 |
// Recuperamos todos los nombres
|
593 |
XMLEntity tablesRoot = project.getExportXMLTypeRootNode(root, |
594 |
ProjectTableFactory.registerName); |
595 |
int childIndex;
|
596 |
XMLEntity child; |
597 |
// Lo hacemos en un map por si una vista se usa varias veces
|
598 |
HashMap tablesName = new HashMap(); |
599 |
Iterator iterTables = tablesRoot.findChildren("viewName", this |
600 |
.getName()); |
601 |
while (iterTables.hasNext()) {
|
602 |
child = (XMLEntity) iterTables.next(); |
603 |
tablesName.put(child.getStringProperty("name"), child
|
604 |
.getStringProperty("name"));
|
605 |
} |
606 |
|
607 |
XMLEntity tableXML; |
608 |
|
609 |
// Construimos un diccionario ordenado inversamente por el indice
|
610 |
// del elemento (por si se van eliminando elementos al importar) y
|
611 |
// como valor el nombre de la vista
|
612 |
TreeMap tablesToImport = new TreeMap(new Comparator() { |
613 |
|
614 |
public int compare(Object o1, Object o2) { |
615 |
|
616 |
if (((Integer) o1).intValue() > ((Integer) o2).intValue()) { |
617 |
return -1; // o1 first |
618 |
} else if (((Integer) o1).intValue() < ((Integer) o2) |
619 |
.intValue()) { |
620 |
return 1; // o1 second |
621 |
} |
622 |
return 0; |
623 |
} |
624 |
|
625 |
}); |
626 |
Iterator iterTablesName = tablesName.keySet().iterator();
|
627 |
int tableIndex;
|
628 |
String tableName;
|
629 |
while (iterTablesName.hasNext()) {
|
630 |
tableName = (String) iterTablesName.next();
|
631 |
tableIndex = tablesRoot.firstIndexOfChild("name", tableName);
|
632 |
tablesToImport.put(new Integer(tableIndex), tableName); |
633 |
} |
634 |
|
635 |
ProjectTable table; |
636 |
ProjectDocumentFactory tableFactory = project |
637 |
.getProjectDocumentFactory(ProjectTableFactory.registerName); |
638 |
|
639 |
Iterator iterTablesToImport = tablesToImport.entrySet().iterator();
|
640 |
Entry entry; |
641 |
// Nos recorremos las vistas a importar
|
642 |
while (iterTablesToImport.hasNext()) {
|
643 |
entry = (Entry) iterTablesToImport.next(); |
644 |
tableName = (String) entry.getValue();
|
645 |
tableIndex = ((Integer) entry.getKey()).intValue();
|
646 |
table = (ProjectTable) tableFactory.create(project); |
647 |
try {
|
648 |
table.importFromXML(root, tablesRoot, tableIndex, project, |
649 |
removeDocumentsFromRoot); |
650 |
} catch (ReadDriverException e) {
|
651 |
// TODO Auto-generated catch block
|
652 |
e.printStackTrace(); |
653 |
} |
654 |
} |
655 |
} |
656 |
|
657 |
public int getPlanetType() { |
658 |
return m_planetType;
|
659 |
} |
660 |
|
661 |
public void setPlanetType(int type) { |
662 |
m_planetType = type; |
663 |
} |
664 |
|
665 |
public float getVerticalExaggeration() { |
666 |
return verticalExaggeration;
|
667 |
} |
668 |
|
669 |
public void setVerticalExaggeration(float exaggeration) { |
670 |
verticalExaggeration = exaggeration; |
671 |
} |
672 |
|
673 |
public Color getBackGroundColor() { |
674 |
return backgroundColor;
|
675 |
} |
676 |
|
677 |
public void setBackGroundColor(Color backGroundColor) { |
678 |
this.backgroundColor = backGroundColor;
|
679 |
if ((this.backgroundColor != null) && (m_planetViewer != null)) { |
680 |
float r, g, b, a;
|
681 |
r = ((float) backgroundColor.getRed()) / 255.0f; |
682 |
g = ((float) backgroundColor.getGreen()) / 255.0f; |
683 |
b = ((float) backgroundColor.getBlue()) / 255.0f; |
684 |
a = ((float) backgroundColor.getAlpha()) / 255.0f; |
685 |
|
686 |
m_planetViewer.setClearColor(r, g, b, a); |
687 |
} |
688 |
} |
689 |
|
690 |
/**
|
691 |
* Method to insert text points in a position with a especific text
|
692 |
*
|
693 |
* @param nombre
|
694 |
* The text
|
695 |
* @param posicion
|
696 |
* the position
|
697 |
*/
|
698 |
public void insertaText(String nombre, Vec3 posicion) { |
699 |
// Group root = (Group) m_canvas3d.getSceneData();
|
700 |
//
|
701 |
// Group vector = (Group) root.getChild(0);
|
702 |
//
|
703 |
// if (vector.getNodeName(null).equals("VECTOR")) {
|
704 |
// VectorTest vaux = (VectorTest) vector;
|
705 |
// System.out.println("Numero de hijos " + vaux.getNumChildren());
|
706 |
// vaux.insertText(nombre, posicion);
|
707 |
// // vaux.insertPoint(posicion, new Vec4(1.0,1.0,1.0,1.0));
|
708 |
// System.out.println("Numero de hijos despues "
|
709 |
// + vaux.getNumChildren());
|
710 |
// }
|
711 |
|
712 |
// g.insertText(nombre, posicion);
|
713 |
|
714 |
// System.out.println("Nombre del nodo leido " +
|
715 |
// vector.getNodeName(null)) ;
|
716 |
|
717 |
} |
718 |
|
719 |
public Planet getPlanet() {
|
720 |
return m_planet;
|
721 |
} |
722 |
|
723 |
public void setPlanet(Planet m_planet) { |
724 |
this.m_planet = m_planet;
|
725 |
} |
726 |
|
727 |
public IViewerContainer getCanvas3d() {
|
728 |
return m_canvas3d;
|
729 |
} |
730 |
|
731 |
public void setCanvas3d(CanvasViewer m_canvas3d) { |
732 |
this.m_canvas3d = m_canvas3d;
|
733 |
} |
734 |
|
735 |
private void setVerticalEx(float exa) { |
736 |
|
737 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(
|
738 |
(FLayers3D) getMapContext().getLayers()); |
739 |
while (lyrIterator.hasNext()) {
|
740 |
FLayer lyr = lyrIterator.next(); |
741 |
|
742 |
Layer3DProps props = Layer3DProps.getLayer3DProps(lyr); |
743 |
int type = props.getType();
|
744 |
if (exa != props.getVerticalEx()) {
|
745 |
if (type == Layer3DProps.layer3DElevation) {
|
746 |
int order = props.getPlanetOrder();
|
747 |
props.setVerticalEx(exa); |
748 |
m_planet.setVerticalExaggerationLayer(order, props |
749 |
.getVerticalEx()); |
750 |
} else if (type == Layer3DProps.layer3DVector) { |
751 |
int order = props.getPlanetOrder();
|
752 |
props.setVerticalEx(exa); |
753 |
} |
754 |
} |
755 |
|
756 |
} |
757 |
} |
758 |
|
759 |
public boolean isPrespectiveModeActive() { |
760 |
return prespectiveMode;
|
761 |
} |
762 |
|
763 |
/**
|
764 |
* Active the prespective mode. If we disable the prespective mode, the
|
765 |
* ortho mode will be active
|
766 |
*
|
767 |
* @param prespectiveMode
|
768 |
* enable/disable
|
769 |
*/
|
770 |
public void setActivePrespectiveMode(boolean prespectiveMode) { |
771 |
this.prespectiveMode = prespectiveMode;
|
772 |
} |
773 |
|
774 |
private void configureProjectionViewMode() { |
775 |
if (prespectiveMode) {
|
776 |
System.out.println("Setting up prespective projection"); |
777 |
// this.m_canvas3d.getOSGViewer().setProjectionMatrixAsPerspective(
|
778 |
// arg0, arg1, arg2, arg3);
|
779 |
} else {
|
780 |
System.out.println("Setting up prespective projection"); |
781 |
this.m_canvas3d.getOSGViewer().setProjectionMatrixAsOrtho(-10, 10, |
782 |
-10, 10, 1, 1000); |
783 |
} |
784 |
} |
785 |
|
786 |
public View3D getView() {
|
787 |
return m_view;
|
788 |
} |
789 |
|
790 |
public void setView(View3D m_view) { |
791 |
this.m_view = m_view;
|
792 |
} |
793 |
|
794 |
} |