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