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