root / branches / 3D_Animation_prepto_osgvp_2_2_0 / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / listener / RectangleSelectListener3D.java @ 26998
History | View | Annotate | Download (3.77 KB)
1 |
package org.gvsig.gvsig3dgui.listener; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
import java.awt.geom.Rectangle2D; |
5 |
|
6 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
7 |
import org.gvsig.osgvp.core.osg.Vec3; |
8 |
import org.gvsig.osgvp.viewer.Intersections; |
9 |
|
10 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
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.RectangleSelectionListener; |
19 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
20 |
|
21 |
public class RectangleSelectListener3D extends RectangleSelectionListener { |
22 |
|
23 |
private MapControl mapControl;
|
24 |
|
25 |
public RectangleSelectListener3D(MapControl mc) {
|
26 |
super(mc);
|
27 |
// TODO Auto-generated constructor stub
|
28 |
mapControl = mc; |
29 |
} |
30 |
|
31 |
@Override
|
32 |
public void rectangle(RectangleEvent event) throws BehaviorException { |
33 |
try {
|
34 |
// mapCtrl.getMapContext().selectByRect(event.getWorldCoordRect());
|
35 |
Rectangle2D rect = event.getWorldCoordRect();
|
36 |
Point2D up = new Point2D.Double(); |
37 |
up.setLocation(rect.getX(), rect.getY()); |
38 |
Vec3 upLeft = coordinatesIntersection(up); |
39 |
// Point2D down = new Point2D.Double();
|
40 |
// down.setLocation(rect.getMaxX(), rect.getMaxY());
|
41 |
// Vec3 downRight = coordinatesIntersection(down);
|
42 |
|
43 |
Rectangle2D newRect = new Rectangle2D.Double(upLeft.x(), |
44 |
upLeft.y(), rect.getHeight(), rect.getWidth()); |
45 |
|
46 |
FLayer[] actives = mapControl.getMapContext().getLayers()
|
47 |
.getActives(); |
48 |
for (int i = 0; i < actives.length; i++) { |
49 |
if (actives[i] instanceof FLyrVect) { |
50 |
FLyrVect lyrVect = (FLyrVect) actives[i]; |
51 |
FBitSet oldBitSet = lyrVect.getSource().getRecordset() |
52 |
.getSelection(); |
53 |
// FBitSet newBitSet = lyrVect.queryByRect(newRect);
|
54 |
FBitSet newBitSet = lyrVect.queryByRect(rect); |
55 |
if (event.getEvent().isControlDown())
|
56 |
newBitSet.xor(oldBitSet); |
57 |
lyrVect.getRecordset().setSelection(newBitSet); |
58 |
} |
59 |
} |
60 |
|
61 |
} catch (ReadDriverException e) {
|
62 |
throw new BehaviorException("No se pudo hacer la selecci?n"); |
63 |
} catch (VisitorException e) {
|
64 |
throw new BehaviorException("No se pudo hacer la selecci?n"); |
65 |
} |
66 |
} |
67 |
|
68 |
public Vec3 coordinatesIntersection(Point2D pScreen) { |
69 |
Vec3 intersection; |
70 |
|
71 |
// System.err.println("Coordenadas de pantalla " + pScreen.getX() + ","+
|
72 |
// pScreen.getY());
|
73 |
MapContext3D mcontext = (MapContext3D) this.mapControl.getMapContext();
|
74 |
Intersections hits = mcontext.getCanvas3d().getOSGViewer().rayPick( |
75 |
(int) pScreen.getX(), (int) pScreen.getY()); |
76 |
Point2D pWorld = new Point2D.Double(); |
77 |
if (hits.containsIntersections()) {
|
78 |
// get XYZ coordinates on planet
|
79 |
Vec3 hit = hits.getFirstIntersection().getIntersectionPoint(); |
80 |
// convert to geo coordinates
|
81 |
|
82 |
// System.err.println("Interseccion de osg " + hit.x() + ","+
|
83 |
// hit.y());
|
84 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
85 |
"EPSG:4326") == 0) { |
86 |
Vec3 geoPt = mcontext.getPlanet() |
87 |
.convertXYZToLatLongHeight(hit); |
88 |
intersection = geoPt; |
89 |
} else {
|
90 |
intersection = hit; |
91 |
} |
92 |
} else {
|
93 |
if (mcontext.getProjection().getAbrev().compareToIgnoreCase(
|
94 |
"EPSG:4326") == 0) { |
95 |
pWorld.setLocation(360, 120); |
96 |
intersection = new Vec3(360, 120, 0); |
97 |
} else {
|
98 |
intersection = new Vec3(1e100, 1e100, 0); |
99 |
// pWorld.setLocation(1e100, 1e100);
|
100 |
} |
101 |
} |
102 |
NotificationManager.addInfo("Obteniendo punto de informacion "
|
103 |
+ intersection.x() + " , " + intersection.y() + " , " |
104 |
+ intersection.z()); |
105 |
return intersection;
|
106 |
} |
107 |
|
108 |
} |