root / trunk / extensions / ext3Dgui / src / com / iver / ai2 / gvsig3dgui / listener / PointSelectListerner3D.java @ 20900
History | View | Annotate | Download (4.3 KB)
1 | 18331 | jcampos | package com.iver.ai2.gvsig3dgui.listener; |
---|---|---|---|
2 | |||
3 | import java.awt.geom.Point2D; |
||
4 | |||
5 | 20900 | jcampos | import org.gvsig.osgvp.Vec3; |
6 | import org.gvsig.osgvp.viewer.Intersections; |
||
7 | |||
8 | 18331 | jcampos | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
9 | import com.iver.ai2.gvsig3d.map3d.MapContext3D; |
||
10 | 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 | |||
21 | public class PointSelectListerner3D extends PointSelectListener { |
||
22 | |||
23 | public PointSelectListerner3D(MapControl mapCtrl) {
|
||
24 | super(mapCtrl);
|
||
25 | // TODO Auto-generated constructor stub
|
||
26 | |||
27 | } |
||
28 | |||
29 | @Override
|
||
30 | 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());
|
||
70 | } |
||
71 | |||
72 | @Override
|
||
73 | public void pointDoubleClick(PointEvent event) throws BehaviorException { |
||
74 | // TODO Auto-generated method stub
|
||
75 | // super.pointDoubleClick(event);
|
||
76 | } |
||
77 | |||
78 | public Vec3 coordinatesIntersection(Point2D pScreen) { |
||
79 | Vec3 intersection; |
||
80 | |||
81 | // System.err.println("Coordenadas de pantalla " + pScreen.getX() + ","+
|
||
82 | // pScreen.getY());
|
||
83 | MapContext3D mcontext = (MapContext3D) this.mapCtrl.getMapContext();
|
||
84 | int heigth = mcontext.getCanvas3d().getHeight();
|
||
85 | Intersections hits = mcontext.getCanvas3d().getOSGViewer().rayPick( |
||
86 | (int) pScreen.getX(),(int) pScreen.getY()); |
||
87 | Point2D pWorld = new Point2D.Double(); |
||
88 | if (hits.containsIntersections()) {
|
||
89 | // get XYZ coordinates on planet
|
||
90 | Vec3 hit = hits.getFirstIntersection().getIntersectionPoint(); |
||
91 | // convert to geo coordinates
|
||
92 | |||
93 | // System.err.println("Interseccion de osg " + hit.x() + ","+
|
||
94 | // hit.y());
|
||
95 | if (mcontext.getProjection().getAbrev().compareToIgnoreCase("EPSG:4326") == 0) { |
||
96 | Vec3 geoPt = mcontext.getPlanet().convertXYZToLatLongHeight(hit); |
||
97 | // Swap the coordinates X and Y, because they are invert.
|
||
98 | intersection = new Vec3(geoPt.y(),geoPt.x(),geoPt.z());
|
||
99 | // intersection = geoPt;
|
||
100 | } else {
|
||
101 | intersection = hit; |
||
102 | } |
||
103 | } else {
|
||
104 | if (mcontext.getProjection().getAbrev().compareToIgnoreCase("EPSG:4326") == 0) { |
||
105 | 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 | } |
||
111 | } |
||
112 | NotificationManager.addInfo("Obteniendo punto de informacion "+ intersection.x() + " , " + intersection.y() +" , "+ intersection.z()); |
||
113 | return intersection;
|
||
114 | } |
||
115 | |||
116 | } |