root / branches / v2_0_0_prep / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / listener / PointSelectListerner3D.java @ 29938
History | View | Annotate | Download (4.05 KB)
1 |
package org.gvsig.gvsig3dgui.listener; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
|
5 |
import org.gvsig.andami.messages.NotificationManager; |
6 |
import org.gvsig.app.project.documents.view.toolListeners.PointSelectListener; |
7 |
import org.gvsig.fmap.dal.exception.ReadException; |
8 |
import org.gvsig.fmap.mapcontext.layers.FBitSet; |
9 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
10 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
11 |
import org.gvsig.fmap.mapcontrol.MapControl; |
12 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
13 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
14 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
15 |
import org.gvsig.osgvp.core.osg.Vec3; |
16 |
import org.gvsig.osgvp.viewer.Intersections; |
17 |
|
18 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
19 |
|
20 |
public class PointSelectListerner3D extends PointSelectListener { |
21 |
|
22 |
public PointSelectListerner3D(MapControl mapCtrl) {
|
23 |
super(mapCtrl);
|
24 |
// TODO Auto-generated constructor stub
|
25 |
|
26 |
} |
27 |
|
28 |
@Override
|
29 |
public void point(PointEvent event) throws BehaviorException { |
30 |
// TODO:COMENTADO PARA LA 2.0
|
31 |
//
|
32 |
// MapContext3D mapContext = (MapContext3D) mapCtrl.getMapContext();
|
33 |
//
|
34 |
// try {
|
35 |
//
|
36 |
// Point2D p = event.getPoint();
|
37 |
// Vec3 mapPoint = coordinatesIntersection(p);
|
38 |
//
|
39 |
// // Tolerancia de 3 pixels
|
40 |
//
|
41 |
// double tol = 0.20;
|
42 |
// FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
|
43 |
// for (int i = 0; i < actives.length; i++) {
|
44 |
// if (actives[i] instanceof FLyrVect) {
|
45 |
// FLyrVect lyrVect = (FLyrVect) actives[i];
|
46 |
// Layer3DProps props = Layer3DProps.getLayer3DProps(lyrVect);
|
47 |
// float heigth = props.getHeigth();
|
48 |
// if (Math.abs(heigth - mapPoint.z()) <= 3000) {
|
49 |
//
|
50 |
// FBitSet oldBitSet =
|
51 |
// lyrVect.getSource().getRecordset()
|
52 |
// .getSelection();
|
53 |
// Point2D pointInter = new Point2D.Double();
|
54 |
// pointInter.setLocation(mapPoint.x(), mapPoint.y());
|
55 |
// FBitSet newBitSet = lyrVect.queryByPoint(pointInter,
|
56 |
// tol);
|
57 |
//
|
58 |
// if (event.getEvent().isControlDown())
|
59 |
// newBitSet.xor(oldBitSet);
|
60 |
// lyrVect.getRecordset().setSelection(newBitSet);
|
61 |
// }
|
62 |
// }
|
63 |
// }
|
64 |
//
|
65 |
// } catch (ReadException e) {
|
66 |
// throw new BehaviorException("No se pudo hacer la selecci�n");
|
67 |
// } catch (VisitorException e) {
|
68 |
// throw new BehaviorException("No se pudo hacer la selecci�n");
|
69 |
// }
|
70 |
//
|
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
75 |
// TODO Auto-generated method stub
|
76 |
// super.pointDoubleClick(event);
|
77 |
} |
78 |
|
79 |
public Vec3 coordinatesIntersection(Point2D pScreen) { |
80 |
Vec3 intersection; |
81 |
|
82 |
// System.err.println("Coordenadas de pantalla " + pScreen.getX() + ","+
|
83 |
// pScreen.getY());
|
84 |
MapContext3D mcontext = (MapContext3D) this.mapCtrl.getMapContext();
|
85 |
int heigth = mcontext.getCanvas3d().getHeight();
|
86 |
Intersections hits = mcontext.getCanvas3d().getOSGViewer().rayPick( |
87 |
(int) pScreen.getX(), (int) pScreen.getY()); |
88 |
Point2D pWorld = new Point2D.Double(); |
89 |
if (hits.containsIntersections()) {
|
90 |
// get XYZ coordinates on planet
|
91 |
Vec3 hit = hits.getFirstIntersection().getIntersectionPoint(); |
92 |
// convert to geo coordinates
|
93 |
|
94 |
// System.err.println("Interseccion de osg " + hit.x() + ","+
|
95 |
// hit.y());
|
96 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
97 |
"EPSG:4326") == 0) { |
98 |
Vec3 geoPt = mcontext.getPlanet() |
99 |
.convertXYZToLatLongHeight(hit); |
100 |
// Swap the coordinates X and Y, because they are invert.
|
101 |
intersection = new Vec3(geoPt.y(), geoPt.x(), geoPt.z());
|
102 |
// intersection = geoPt;
|
103 |
} else {
|
104 |
intersection = hit; |
105 |
} |
106 |
} else {
|
107 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
108 |
"EPSG:4326") == 0) { |
109 |
pWorld.setLocation(360, 120); |
110 |
intersection = new Vec3(360, 120, 0); |
111 |
} else {
|
112 |
intersection = new Vec3(1e100, 1e100, 0); |
113 |
// pWorld.setLocation(1e100, 1e100);
|
114 |
} |
115 |
} |
116 |
NotificationManager.addInfo("Obteniendo punto de informacion "
|
117 |
+ intersection.x() + " , " + intersection.y() + " , " |
118 |
+ intersection.z()); |
119 |
return intersection;
|
120 |
} |
121 |
|
122 |
} |