Revision 113

View differences:

1.10/trunk/libraries/lib3DMap/src/org/gvsig/gvsig3d/map3d/layers/FLyrOSG.java
1
package org.gvsig.gvsig3d.map3d.layers;
2

  
3
import java.awt.geom.Rectangle2D;
4
import java.awt.geom.Rectangle2D.Float;
5
import java.util.Vector;
6

  
7
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
8
import org.gvsig.gvsig3d.map3d.MapContext3D;
9
import org.gvsig.osgvp.core.osg.Vec3;
10
import org.gvsig.osgvp.terrain.Terrain;
11

  
12
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
13
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
14
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
15
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
16
import com.iver.cit.gvsig.fmap.layers.XMLException;
17
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend;
18
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy;
19
import com.iver.utiles.XMLEntity;
20

  
21
public class FLyrOSG extends FLyrVect  {
22
	
23
	public FLyrOSG() {
24
		super();
25
	}
26
	
27
	public FLyrOSG(FLyrVect layerVect) {
28
		super();
29
		
30
        this.setSource(layerVect.getSource());
31
        if (layerVect.isJoined()) {
32
			this.setIsJoined(true);
33
			try {
34
				this.setRecordset(layerVect.getRecordset());
35
			} catch (ReadDriverException e) {
36
				// TODO Auto-generated catch block
37
				e.printStackTrace();
38
			}
39
		}
40
        this.setVisible(layerVect.isVisible());
41
        this.setISpatialIndex(layerVect.getISpatialIndex());
42
        this.setName(layerVect.getName());
43
        this.setCoordTrans(layerVect.getCoordTrans());
44

  
45
        try {
46
			this.setLegend((IVectorLegend)layerVect.getLegend().cloneLegend());
47
		} catch (LegendLayerException e) {
48
			// TODO Auto-generated catch block
49
			e.printStackTrace();
50
		} catch (XMLException e) {
51
			// TODO Auto-generated catch block
52
			e.printStackTrace();
53
		}
54

  
55
        this.setIsLabeled(layerVect.isLabeled());
56
        ILabelingStrategy labelingStrategy=layerVect.getLabelingStrategy();
57
        if (labelingStrategy!=null)
58
        	this.setLabelingStrategy(labelingStrategy);
59
        
60
        this.setProjection(null);
61
	}
62
	
63
	@Override
64
	public XMLEntity getXMLEntity() throws XMLException {
65
		XMLEntity xml = super.getXMLEntity();
66
		
67
		xml.putProperty("className", FLyrVect.class.getName());
68
		
69
		return xml;
70
	}
71
	
72
	@Override
73
	public Rectangle2D getFullExtent() {
74
		System.out.println("Fullextent OSG");
75
		
76
		Layer3DProps props3D = Layer3DProps.getLayer3DProps(this);	
77
		if(props3D == null) return null;
78
		
79
		OSGCacheService osgCacheService = (OSGCacheService) props3D
80
				.getCacheService();
81
		
82
		Vector<Vec3> bbox = osgCacheService.getLayerNode().getBoundingBox();
83
		
84
		System.out.println("BBOX: "+bbox.get(0).x()+" "+bbox.get(0).y()+" "+bbox.get(0).z()+" "
85
				+bbox.get(1).x()+" "+bbox.get(1).y()+" "+bbox.get(1).z());
86
		
87
		if(getMapContext() == null) return null;
88
		MapContext3D map3d = (MapContext3D) this.getMapContext();
89
		
90
		Rectangle2D extent = new Rectangle2D.Float();
91
		double x = 0, y = 0, w = 0, h = 0;
92
		
93
		if(map3d.getTerrain() == null) return null;
94
		switch(map3d.getTerrain().getCoordinateSystemType())
95
		{
96
			case Terrain.CoordinateSystemType.GEOCENTRIC:
97
				Vec3 point1 = map3d.getTerrain().convertXYZToLatLongHeight(bbox.get(0));
98
				Vec3 point2 = map3d.getTerrain().convertXYZToLatLongHeight(bbox.get(1));
99
				x = point1.y();
100
				y = point1.x();
101
				w = point2.y() - point1.y();
102
				h = point2.x() - point1.x();
103
				break;
104
			case Terrain.CoordinateSystemType.GEOGRAPHIC:
105
				x = bbox.get(0).x();
106
				y = bbox.get(0).y();
107
				w = bbox.get(1).x() - x;
108
				h = bbox.get(1).y() - y;
109
				break;
110
			case Terrain.CoordinateSystemType.PROJECTED:
111
				x = bbox.get(0).x();
112
				y = bbox.get(0).y();
113
				w = bbox.get(1).x() - x;
114
				h = bbox.get(1).y() - y;
115
				break;
116
		}
117
		
118
		extent.setRect(x, y, w, h);
119
		return extent;
120
	}
121
	
122
	
123
}
1.10/trunk/libraries/lib3DMap/src/org/gvsig/gvsig3d/map3d/layers/FLayers3D.java
1 1
package org.gvsig.gvsig3d.map3d.layers;
2 2

  
3
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG;
3 4
import org.gvsig.gvsig3d.map3d.MapContext3D;
4 5

  
6
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
5 7
import com.hardcode.gdbms.engine.data.driver.DriverException;
6 8
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
7 9
import com.iver.cit.gvsig.fmap.MapContext;
......
9 11
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
10 12
import com.iver.cit.gvsig.fmap.layers.FLayer;
11 13
import com.iver.cit.gvsig.fmap.layers.FLayers;
14
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
12 15
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
13 16
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent;
14 17
import com.iver.cit.gvsig.fmap.layers.XMLException;
......
46 49
	}
47 50

  
48 51
	// overrides for layer collection events
52
	
53
	@Override
54
	public void addLayer(FLayer layer) {
55
		if(layer instanceof FLyrVect){
56
			FLyrVect vectLayer = (FLyrVect) layer;
57
			try {
58
				if ((layer instanceof FLyrVect) && (vectLayer.getRecordset().getDriver() instanceof GvsigDriverOSG)) {
59
					// This is a little hack, so you need to set a parent to avoid a exception
60
					super.addLayer(new FLyrOSG(vectLayer));
61
					vectLayer.setProjection(null);
62
					return;
63
				}
64
			} catch (ReadDriverException e) {
65
				// TODO Auto-generated catch block
66
				e.printStackTrace();
67
			}
68
		}
69
		super.addLayer(layer);
70
	}
49 71

  
50 72
	protected void callLayerAdded(LayerCollectionEvent event) {
51 73
		if (isHooked()) {
......
116 138
		if (((MapContext3D)fmap).getLayers()==this) // this is the root FLayers3D
117 139
			((MapContext3D)fmap).setLoading(false);
118 140
	}
141
	
142
	/*public Rectangle2D getFullExtent() {
143
		
144
		Rectangle2D rAux = null;
145
		boolean first = true;
119 146

  
147

  
148
		for (Iterator iter = layers.iterator(); iter.hasNext();) {
149
			FLayer capa = (FLayer) iter.next();
150
			try{
151
				if (first) {
152
					rAux = capa.getFullExtent();
153
					first=false;
154
				} else {
155
					rAux.add(capa.getFullExtent());
156
				}
157
			}catch (Exception e) {
158
				e.printStackTrace();//TODO hay que revisar para determinar el comportamiento que espera el usuario.
159
			}
160
		}
161

  
162
		return rAux;
163
	}*/
164

  
120 165
}
1.10/trunk/libraries/lib3DMap/src/org/gvsig/gvsig3d/map3d/MapContext3D.java
472 472
			}
473 473
		}
474 474

  
475
		PrintDebugLayers();
475
		//PrintDebugLayers();
476 476
	}
477 477

  
478 478
	public void layerRemoved(FLayers3D parent, FLayer layer) {
......
1016 1016
	 *            The extent to zoom to.
1017 1017
	 */
1018 1018
	public void zoomToExtent(Rectangle2D geoExtent) {
1019
		
1020
		if(geoExtent == null) return;
1021
		
1019 1022
		double maxHeight = 0.0;
1020 1023

  
1021 1024
		// Getting extent positions

Also available in: Unified diff