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