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