svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCAD / src / com / iver / cit / gvsig / layers / VectorialLayerEdited.java @ 23657
History | View | Annotate | Download (25.7 KB)
1 | 4144 | fjp | package com.iver.cit.gvsig.layers; |
---|---|---|---|
2 | |||
3 | 4637 | caballero | import java.awt.Graphics2D; |
4 | import java.awt.Image; |
||
5 | 4366 | caballero | import java.awt.geom.Point2D; |
6 | 4637 | caballero | import java.awt.image.BufferedImage; |
7 | 4366 | caballero | import java.util.ArrayList; |
8 | 5018 | caballero | import java.util.EmptyStackException; |
9 | 21668 | vcaballero | import java.util.Iterator; |
10 | 4366 | caballero | |
11 | 12739 | caballero | import org.cresques.cts.ICoordTrans; |
12 | 22986 | vcaballero | import org.gvsig.fmap.data.DataException; |
13 | 21911 | jmvivo | import org.gvsig.fmap.data.ReadException; |
14 | 22360 | jmvivo | import org.gvsig.fmap.data.feature.Feature; |
15 | import org.gvsig.fmap.data.feature.FeatureCollection; |
||
16 | import org.gvsig.fmap.data.feature.FeatureStore; |
||
17 | 21668 | vcaballero | import org.gvsig.fmap.geom.handler.Handler; |
18 | 22025 | jmvivo | import org.gvsig.fmap.geom.operation.Draw; |
19 | import org.gvsig.fmap.geom.operation.DrawOperationContext; |
||
20 | 21668 | vcaballero | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
21 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
22 | import org.gvsig.fmap.geom.operation.tojts.ToJTS; |
||
23 | 23086 | vcaballero | import org.gvsig.fmap.geom.primitive.DefaultEnvelope; |
24 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
25 | 21668 | vcaballero | import org.gvsig.fmap.mapcontext.ViewPort; |
26 | import org.gvsig.fmap.mapcontext.layers.CancelationException; |
||
27 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
28 | import org.gvsig.fmap.mapcontext.layers.LayerDrawEvent; |
||
29 | import org.gvsig.fmap.mapcontext.layers.LayerDrawingListener; |
||
30 | import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
||
31 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
32 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
33 | import org.gvsig.fmap.mapcontext.rendering.symbols.FGraphicUtilities; |
||
34 | 23657 | vcaballero | import org.gvsig.fmap.mapcontrol.MapControl; |
35 | 23066 | jmvivo | import org.gvsig.tools.observer.Observable; |
36 | import org.gvsig.tools.observer.Observer; |
||
37 | 12739 | caballero | |
38 | 5018 | caballero | import com.iver.andami.PluginServices; |
39 | 12739 | caballero | import com.iver.andami.messages.NotificationManager; |
40 | 10836 | caballero | import com.iver.andami.ui.mdiManager.IWindow; |
41 | 5018 | caballero | import com.iver.cit.gvsig.CADExtension; |
42 | 5208 | caballero | import com.iver.cit.gvsig.StartEditing; |
43 | 5084 | caballero | import com.iver.cit.gvsig.ViewCommandStackExtension; |
44 | 4637 | caballero | import com.iver.cit.gvsig.gui.cad.CADTool; |
45 | 4366 | caballero | import com.iver.cit.gvsig.gui.cad.CADToolAdapter; |
46 | 11434 | caballero | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
47 | 4366 | caballero | import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
48 | 10836 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
49 | 4717 | caballero | import com.vividsolutions.jts.geom.Geometry; |
50 | 4144 | fjp | |
51 | 23646 | vcaballero | public class VectorialLayerEdited extends DefaultLayerEdited implements |
52 | LayerDrawingListener, Observer {
|
||
53 | 4366 | caballero | private ArrayList selectedHandler = new ArrayList(); |
54 | 4708 | caballero | private Point2D lastPoint; |
55 | private Point2D firstPoint; |
||
56 | 23646 | vcaballero | private CADTool cadtool = null; |
57 | 5906 | caballero | |
58 | 23646 | vcaballero | // private ArrayList snappers = new ArrayList();
|
59 | // private ArrayList layersToSnap = new ArrayList();
|
||
60 | 11558 | jaume | private ILegend legend;
|
61 | 23646 | vcaballero | /** Selecci?n previa* */
|
62 | private ArrayList previousRowSelection = new ArrayList(); |
||
63 | private ArrayList previousHandlerSelection = new ArrayList(); |
||
64 | 21668 | vcaballero | private Image imageSelection; |
65 | private Image imageHandlers; |
||
66 | 23646 | vcaballero | public static final boolean SAVEPREVIOUS = true; |
67 | public static final boolean NOTSAVEPREVIOUS = false; |
||
68 | 4366 | caballero | |
69 | 23646 | vcaballero | public VectorialLayerEdited(FLayer lyr) {
|
70 | 4147 | fjp | super(lyr);
|
71 | 6881 | cesar | lyr.getMapContext().addLayerDrawingListener(this);
|
72 | 5813 | fjp | // Por defecto, siempre hacemos snapping sobre la capa en edici?n.
|
73 | 23646 | vcaballero | lyr.getMapContext().getLayersToSnap().add(lyr); |
74 | 9814 | caballero | try {
|
75 | 23646 | vcaballero | ((FLyrVect) lyr).getFeatureStore().addObserver(this);
|
76 | 21668 | vcaballero | } catch (ReadException e) {
|
77 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
78 | 9814 | caballero | } |
79 | 4144 | fjp | } |
80 | 4366 | caballero | |
81 | public ArrayList getSelectedHandler() { |
||
82 | return selectedHandler;
|
||
83 | } |
||
84 | |||
85 | 21668 | vcaballero | public void clearSelection(boolean savePrevious) throws ReadException { |
86 | 23646 | vcaballero | if (getFeatureStore() == null) |
87 | 23086 | vcaballero | return;
|
88 | 23646 | vcaballero | FeatureCollection selection = (FeatureCollection) getFeatureStore() |
89 | .getSelection(); |
||
90 | if (!selection.isEmpty() && savePrevious) {
|
||
91 | 8940 | caballero | previousRowSelection.clear(); |
92 | previousHandlerSelection.clear(); |
||
93 | } |
||
94 | if (savePrevious) {
|
||
95 | 21668 | vcaballero | previousRowSelection.addAll(selection); |
96 | 8940 | caballero | previousHandlerSelection.addAll(selectedHandler); |
97 | } |
||
98 | 4366 | caballero | selectedHandler.clear(); |
99 | 21668 | vcaballero | selection.clear(); |
100 | 4366 | caballero | } |
101 | 23646 | vcaballero | |
102 | 21668 | vcaballero | public void restorePreviousSelection() throws ReadException { |
103 | 23646 | vcaballero | FeatureCollection selection = (FeatureCollection) getFeatureStore() |
104 | .getSelection(); |
||
105 | 8940 | caballero | selection.clear(); |
106 | selectedHandler.clear(); |
||
107 | 21668 | vcaballero | selection.addAll(previousRowSelection); |
108 | 8940 | caballero | selectedHandler.addAll(previousHandlerSelection); |
109 | 23646 | vcaballero | // VectorialEditableAdapter vea=getVEA();
|
110 | // FBitSet selection=vea.getSelection();
|
||
111 | //
|
||
112 | // selection.clear();
|
||
113 | // selectedRow.clear();
|
||
114 | // selectedHandler.clear();
|
||
115 | //
|
||
116 | // selectedRow.addAll(previousRowSelection);
|
||
117 | // selectedHandler.addAll(previousHandlerSelection);
|
||
118 | // for (int i = 0;i < selectedRow.size(); i++) {
|
||
119 | // IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
||
120 | // selection.set(edRow.getIndex());
|
||
121 | // }
|
||
122 | 8940 | caballero | |
123 | previousRowSelection.clear(); |
||
124 | previousHandlerSelection.clear(); |
||
125 | } |
||
126 | 23646 | vcaballero | |
127 | public void selectWithPoint(double x, double y, boolean multipleSelection) { |
||
128 | 21668 | vcaballero | try {
|
129 | 23646 | vcaballero | firstPoint = new Point2D.Double(x, y); |
130 | FeatureStore featureStore = getFeatureStore(); |
||
131 | FeatureCollection selection = (FeatureCollection) featureStore |
||
132 | .getSelection(); |
||
133 | if (!multipleSelection) {
|
||
134 | clearSelection(SAVEPREVIOUS); |
||
135 | } |
||
136 | // Se comprueba si se pincha en una gemometr?a
|
||
137 | ViewPort vp = getLayer().getMapContext().getViewPort(); |
||
138 | 23657 | vcaballero | double tol = vp.toMapDistance(MapControl.tolerance);
|
139 | 10626 | caballero | |
140 | 23646 | vcaballero | FeatureCollection newSelection = ((FLyrVect) getLayer()) |
141 | .queryByPoint(firstPoint, tol, getFeatureStore() |
||
142 | .getDefaultFeatureType()); |
||
143 | 4637 | caballero | |
144 | 23646 | vcaballero | String strEPSG = vp.getProjection().getAbrev();
|
145 | BufferedImage selectionImage = new BufferedImage( |
||
146 | vp.getImageWidth(), vp.getImageHeight(), |
||
147 | BufferedImage.TYPE_INT_ARGB);
|
||
148 | Graphics2D gs = selectionImage.createGraphics();
|
||
149 | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
||
150 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
151 | Graphics2D gh = handlersImage.createGraphics();
|
||
152 | Iterator iterator = newSelection.iterator();
|
||
153 | while (iterator.hasNext()) {
|
||
154 | Feature feature = (Feature) iterator.next(); |
||
155 | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
||
156 | .getDefaultGeometry(); |
||
157 | 14586 | vcaballero | if (geom == null) { |
158 | continue;
|
||
159 | } |
||
160 | 23646 | vcaballero | org.gvsig.fmap.geom.Geometry geomReproject = geom |
161 | .cloneGeometry(); |
||
162 | // if (ct!=null)
|
||
163 | // geomReproject.reProject(ct);
|
||
164 | // if (geomReproject.intersects(new
|
||
165 | // Rectangle2D.Double(rect.getMinimum(0),rect.getMaximum(0),rect.getMinimum(1)-rect.getMinimum(0),rect.getMaximum(1)-rect.getMaximum(0))))
|
||
166 | // { // , 0.1)){
|
||
167 | selection.add(feature); |
||
168 | // selection.set(feats[i].getIndex(), true);
|
||
169 | // selectedRow.add(feats[i]);
|
||
170 | DrawOperationContext doc = new DrawOperationContext();
|
||
171 | doc.setGraphics(gs); |
||
172 | doc.setViewPort(vp); |
||
173 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
174 | drawHandlers(geomReproject.cloneGeometry(), gh, vp); |
||
175 | geomReproject.invokeOperation(Draw.CODE, doc);// cloneGeometry().draw(gs,
|
||
176 | // vp,
|
||
177 | // DefaultCADTool.selectionSymbol);
|
||
178 | 23535 | vcaballero | |
179 | 23646 | vcaballero | } |
180 | 21668 | vcaballero | setSelectionImage(selectionImage); |
181 | setHandlersImage(handlersImage); |
||
182 | } catch (ReadException e) {
|
||
183 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
184 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
185 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
186 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
187 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
188 | 14586 | vcaballero | } |
189 | 4637 | caballero | } |
190 | 21668 | vcaballero | |
191 | 23646 | vcaballero | public void selectWithSecondPoint(double x, double y) { |
192 | 10626 | caballero | try {
|
193 | 23646 | vcaballero | FeatureStore featureStore = getFeatureStore(); |
194 | 10626 | caballero | |
195 | 23646 | vcaballero | lastPoint = new Point2D.Double(x, y); |
196 | clearSelection(SAVEPREVIOUS); |
||
197 | 21668 | vcaballero | |
198 | 23646 | vcaballero | ViewPort vp = getLayer().getMapContext().getViewPort(); |
199 | double x1;
|
||
200 | double y1;
|
||
201 | double w1;
|
||
202 | double h1;
|
||
203 | 4637 | caballero | |
204 | 23646 | vcaballero | if (firstPoint.getX() < lastPoint.getX()) {
|
205 | x1 = firstPoint.getX(); |
||
206 | w1 = lastPoint.getX() - firstPoint.getX(); |
||
207 | } else {
|
||
208 | x1 = lastPoint.getX(); |
||
209 | w1 = firstPoint.getX() - lastPoint.getX(); |
||
210 | } |
||
211 | 4637 | caballero | |
212 | 23646 | vcaballero | if (firstPoint.getY() < lastPoint.getY()) {
|
213 | y1 = firstPoint.getY(); |
||
214 | h1 = lastPoint.getY() - firstPoint.getY(); |
||
215 | } else {
|
||
216 | y1 = lastPoint.getY(); |
||
217 | h1 = firstPoint.getY() - lastPoint.getY(); |
||
218 | } |
||
219 | 4637 | caballero | |
220 | 23646 | vcaballero | Envelope envelope = new DefaultEnvelope(x1, y1, x1 + w1, y1 + h1);
|
221 | String strEPSG = vp.getProjection().getAbrev();
|
||
222 | BufferedImage selectionImage = new BufferedImage( |
||
223 | vp.getImageWidth(), vp.getImageHeight(), |
||
224 | BufferedImage.TYPE_INT_ARGB);
|
||
225 | 4637 | caballero | Graphics2D gs = selectionImage.createGraphics();
|
226 | 23646 | vcaballero | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
227 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
228 | 4637 | caballero | Graphics2D gh = handlersImage.createGraphics();
|
229 | 23646 | vcaballero | ICoordTrans ct = getLayer().getCoordTrans(); |
230 | |||
231 | Iterator iterator = ((FLyrVect) getLayer()).queryByEnvelope(
|
||
232 | envelope, featureStore.getDefaultFeatureType()).iterator(); |
||
233 | DrawOperationContext doc = new DrawOperationContext();
|
||
234 | 21668 | vcaballero | doc.setGraphics(gs); |
235 | doc.setViewPort(vp); |
||
236 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
237 | while (iterator.hasNext()) {
|
||
238 | 23646 | vcaballero | Feature feature = (Feature) iterator.next(); |
239 | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
||
240 | 21668 | vcaballero | .getDefaultGeometry(); |
241 | |||
242 | 14586 | vcaballero | if (geom == null) { |
243 | continue;
|
||
244 | } |
||
245 | 23646 | vcaballero | org.gvsig.fmap.geom.Geometry geomReproject = geom |
246 | .cloneGeometry(); |
||
247 | if (ct != null) |
||
248 | 12739 | caballero | geomReproject.reProject(ct); |
249 | 21668 | vcaballero | |
250 | 4637 | caballero | if (firstPoint.getX() < lastPoint.getX()) {
|
251 | 23646 | vcaballero | if (envelope.contains(geomReproject.getEnvelope())) {
|
252 | 21668 | vcaballero | featureStore.getSelection().add(feature); |
253 | 23646 | vcaballero | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
254 | drawHandlers(geom.cloneGeometry(), gh, vp); |
||
255 | 4637 | caballero | } |
256 | } else {
|
||
257 | 23646 | vcaballero | if (geomReproject.intersects(envelope.getGeometry()
|
258 | .getBounds2D())) { // , 0.1)){
|
||
259 | 21668 | vcaballero | featureStore.getSelection().add(feature); |
260 | 23646 | vcaballero | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
261 | drawHandlers(geom.cloneGeometry(), gh, vp); |
||
262 | 4637 | caballero | } |
263 | } |
||
264 | } |
||
265 | 21668 | vcaballero | setSelectionImage(selectionImage); |
266 | setHandlersImage(handlersImage); |
||
267 | } catch (ReadException e) {
|
||
268 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
269 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
270 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
271 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
272 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
273 | 14586 | vcaballero | } |
274 | 4637 | caballero | } |
275 | 21668 | vcaballero | |
276 | 23646 | vcaballero | public void selectInsidePolygon(org.gvsig.fmap.geom.Geometry polygon) { |
277 | 10626 | caballero | try {
|
278 | 23646 | vcaballero | FeatureStore featureStore = getFeatureStore(); |
279 | clearSelection(SAVEPREVIOUS); |
||
280 | ViewPort vp = getLayer().getMapContext().getViewPort(); |
||
281 | Envelope envelope = polygon.getEnvelope(); |
||
282 | 10626 | caballero | |
283 | 23646 | vcaballero | String strEPSG = vp.getProjection().getAbrev();
|
284 | BufferedImage selectionImage = new BufferedImage( |
||
285 | vp.getImageWidth(), vp.getImageHeight(), |
||
286 | BufferedImage.TYPE_INT_ARGB);
|
||
287 | Graphics2D gs = selectionImage.createGraphics();
|
||
288 | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
||
289 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
290 | Graphics2D gh = handlersImage.createGraphics();
|
||
291 | ICoordTrans ct = getLayer().getCoordTrans(); |
||
292 | Iterator iterator = ((FLyrVect) getLayer()).queryByEnvelope(
|
||
293 | envelope, featureStore.getDefaultFeatureType()).iterator(); |
||
294 | DrawOperationContext doc = new DrawOperationContext();
|
||
295 | doc.setGraphics(gs); |
||
296 | doc.setViewPort(vp); |
||
297 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
298 | while (iterator.hasNext()) {
|
||
299 | Feature feature = (Feature) iterator.next(); |
||
300 | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
||
301 | .getDefaultGeometry(); |
||
302 | 14586 | vcaballero | if (geom == null) { |
303 | continue;
|
||
304 | } |
||
305 | 23646 | vcaballero | org.gvsig.fmap.geom.Geometry geomReproject = geom |
306 | .cloneGeometry(); |
||
307 | if (ct != null) |
||
308 | 12739 | caballero | geomReproject.reProject(ct); |
309 | 23646 | vcaballero | if (contains(polygon, geomReproject)) {
|
310 | 21668 | vcaballero | featureStore.getSelection().add(feature); |
311 | 23646 | vcaballero | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
312 | drawHandlers(geom.cloneGeometry(), gh, vp); |
||
313 | 12739 | caballero | } |
314 | 4708 | caballero | } |
315 | 21668 | vcaballero | setSelectionImage(selectionImage); |
316 | setHandlersImage(handlersImage); |
||
317 | } catch (ReadException e) {
|
||
318 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
319 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
320 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
321 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
322 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
323 | 14586 | vcaballero | } |
324 | 4708 | caballero | } |
325 | |||
326 | 21668 | vcaballero | public void selectCrossPolygon(org.gvsig.fmap.geom.Geometry polygon) { |
327 | 10626 | caballero | try {
|
328 | 23646 | vcaballero | FeatureStore featureStore = getFeatureStore(); |
329 | clearSelection(SAVEPREVIOUS); |
||
330 | ViewPort vp = getLayer().getMapContext().getViewPort(); |
||
331 | Envelope envelope = polygon.getEnvelope(); |
||
332 | 10626 | caballero | |
333 | 23646 | vcaballero | String strEPSG = vp.getProjection().getAbrev();
|
334 | BufferedImage selectionImage = new BufferedImage( |
||
335 | vp.getImageWidth(), vp.getImageHeight(), |
||
336 | BufferedImage.TYPE_INT_ARGB);
|
||
337 | Graphics2D gs = selectionImage.createGraphics();
|
||
338 | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
||
339 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
340 | Graphics2D gh = handlersImage.createGraphics();
|
||
341 | ICoordTrans ct = getLayer().getCoordTrans(); |
||
342 | Iterator iterator = ((FLyrVect) getLayer()).queryByEnvelope(
|
||
343 | envelope, featureStore.getDefaultFeatureType()).iterator(); |
||
344 | 4708 | caballero | |
345 | 23646 | vcaballero | DrawOperationContext doc = new DrawOperationContext();
|
346 | doc.setGraphics(gs); |
||
347 | doc.setViewPort(vp); |
||
348 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
349 | while (iterator.hasNext()) {
|
||
350 | Feature feature = (Feature) iterator.next(); |
||
351 | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
||
352 | .getDefaultGeometry(); |
||
353 | 14586 | vcaballero | if (geom == null) { |
354 | continue;
|
||
355 | } |
||
356 | 23646 | vcaballero | org.gvsig.fmap.geom.Geometry geomReproject = geom |
357 | .cloneGeometry(); |
||
358 | if (ct != null) |
||
359 | 12739 | caballero | geomReproject.reProject(ct); |
360 | 23646 | vcaballero | if (contains(polygon, geomReproject)
|
361 | || intersects(polygon, geomReproject)) { |
||
362 | 21668 | vcaballero | featureStore.getSelection().add(feature); |
363 | 23646 | vcaballero | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
364 | drawHandlers(geom.cloneGeometry(), gh, vp); |
||
365 | 12739 | caballero | } |
366 | 4708 | caballero | } |
367 | 21668 | vcaballero | setSelectionImage(selectionImage); |
368 | setHandlersImage(handlersImage); |
||
369 | } catch (ReadException e) {
|
||
370 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
371 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
372 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
373 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
374 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
375 | 14586 | vcaballero | } |
376 | 4708 | caballero | } |
377 | |||
378 | 21668 | vcaballero | public void selectOutPolygon(org.gvsig.fmap.geom.Geometry polygon) { |
379 | 10626 | caballero | try {
|
380 | 23646 | vcaballero | FeatureStore featureStore = getFeatureStore(); |
381 | clearSelection(SAVEPREVIOUS); |
||
382 | ViewPort vp = getLayer().getMapContext().getViewPort(); |
||
383 | Envelope envelope = polygon.getEnvelope(); |
||
384 | 4708 | caballero | |
385 | 23646 | vcaballero | String strEPSG = vp.getProjection().getAbrev();
|
386 | BufferedImage selectionImage = new BufferedImage( |
||
387 | vp.getImageWidth(), vp.getImageHeight(), |
||
388 | BufferedImage.TYPE_INT_ARGB);
|
||
389 | Graphics2D gs = selectionImage.createGraphics();
|
||
390 | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
||
391 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
392 | Graphics2D gh = handlersImage.createGraphics();
|
||
393 | ICoordTrans ct = getLayer().getCoordTrans(); |
||
394 | Iterator iterator = ((FLyrVect) getLayer()).queryByEnvelope(
|
||
395 | envelope, featureStore.getDefaultFeatureType()).iterator(); |
||
396 | 21668 | vcaballero | |
397 | 23646 | vcaballero | DrawOperationContext doc = new DrawOperationContext();
|
398 | doc.setGraphics(gs); |
||
399 | doc.setViewPort(vp); |
||
400 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
401 | while (iterator.hasNext()) {
|
||
402 | Feature feature = (Feature) iterator.next(); |
||
403 | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
||
404 | .getDefaultGeometry(); |
||
405 | 14586 | vcaballero | if (geom == null) { |
406 | continue;
|
||
407 | } |
||
408 | 23646 | vcaballero | org.gvsig.fmap.geom.Geometry geomReproject = geom |
409 | .cloneGeometry(); |
||
410 | if (ct != null) |
||
411 | 12739 | caballero | geomReproject.reProject(ct); |
412 | 23646 | vcaballero | if (!contains(polygon, geomReproject)
|
413 | && !intersects(polygon, geomReproject)) { |
||
414 | 21668 | vcaballero | featureStore.getSelection().add(feature); |
415 | 23646 | vcaballero | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
416 | drawHandlers(geom.cloneGeometry(), gh, vp); |
||
417 | 12739 | caballero | } |
418 | 4708 | caballero | } |
419 | 21668 | vcaballero | setSelectionImage(selectionImage); |
420 | setHandlersImage(handlersImage); |
||
421 | } catch (ReadException e) {
|
||
422 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
423 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
424 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
425 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
426 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
427 | 14586 | vcaballero | } |
428 | 4708 | caballero | } |
429 | 21668 | vcaballero | |
430 | 23646 | vcaballero | public void selectAll() { |
431 | 10626 | caballero | try {
|
432 | 23646 | vcaballero | FeatureStore featureStore = getFeatureStore(); |
433 | clearSelection(SAVEPREVIOUS); |
||
434 | ViewPort vp = getLayer().getMapContext().getViewPort(); |
||
435 | BufferedImage selectionImage = new BufferedImage( |
||
436 | vp.getImageWidth(), vp.getImageHeight(), |
||
437 | BufferedImage.TYPE_INT_ARGB);
|
||
438 | 4708 | caballero | Graphics2D gs = selectionImage.createGraphics();
|
439 | 23646 | vcaballero | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
440 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
441 | 4708 | caballero | Graphics2D gh = handlersImage.createGraphics();
|
442 | 23646 | vcaballero | ICoordTrans ct = getLayer().getCoordTrans(); |
443 | FeatureCollection fCollection = (FeatureCollection) featureStore |
||
444 | .getDataCollection(); |
||
445 | Iterator iterator = fCollection.iterator();
|
||
446 | 21668 | vcaballero | featureStore.setSelection(fCollection); |
447 | |||
448 | 23646 | vcaballero | DrawOperationContext doc = new DrawOperationContext();
|
449 | 21668 | vcaballero | doc.setGraphics(gs); |
450 | doc.setViewPort(vp); |
||
451 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
452 | |||
453 | while (iterator.hasNext()) {
|
||
454 | Feature feature = (Feature) iterator.next(); |
||
455 | 23646 | vcaballero | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
456 | .getDefaultGeometry(); |
||
457 | if (ct != null) |
||
458 | 12739 | caballero | geom.reProject(ct); |
459 | 23646 | vcaballero | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
460 | drawHandlers(geom.cloneGeometry(), gh, vp); |
||
461 | 4708 | caballero | } |
462 | 21668 | vcaballero | setSelectionImage(selectionImage); |
463 | setHandlersImage(handlersImage); |
||
464 | } catch (ReadException e) {
|
||
465 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
466 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
467 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
468 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
469 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
470 | 22986 | vcaballero | } catch (DataException e) {
|
471 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
472 | 14586 | vcaballero | } |
473 | 4708 | caballero | } |
474 | |||
475 | 23646 | vcaballero | public void refreshSelectionCache(Point2D firstPoint, CADToolAdapter cta) { |
476 | 10626 | caballero | try {
|
477 | clearSelection(SAVEPREVIOUS); |
||
478 | 23646 | vcaballero | double min = java.lang.Double.MAX_VALUE;
|
479 | ViewPort vp = getLayer().getMapContext().getViewPort(); |
||
480 | BufferedImage selectionImage = new BufferedImage( |
||
481 | vp.getImageWidth(), vp.getImageHeight(), |
||
482 | BufferedImage.TYPE_INT_ARGB);
|
||
483 | Graphics2D gs = selectionImage.createGraphics();
|
||
484 | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
||
485 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
486 | Graphics2D gh = handlersImage.createGraphics();
|
||
487 | FeatureStore featureStore = getFeatureStore(); |
||
488 | 21668 | vcaballero | |
489 | 23646 | vcaballero | Iterator iterator = featureStore.getSelection().iterator();
|
490 | 21668 | vcaballero | |
491 | 23646 | vcaballero | DrawOperationContext doc = new DrawOperationContext();
|
492 | doc.setGraphics(gs); |
||
493 | doc.setViewPort(vp); |
||
494 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
495 | while (iterator.hasNext()) {
|
||
496 | Feature feature = (Feature) iterator.next(); |
||
497 | Handler[] handlers = null; |
||
498 | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
||
499 | .getDefaultGeometry(); |
||
500 | handlers = geom |
||
501 | .getHandlers(org.gvsig.fmap.geom.Geometry.SELECTHANDLER); |
||
502 | 21668 | vcaballero | |
503 | 23646 | vcaballero | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
504 | drawHandlers(geom.cloneGeometry(), gh, vp); |
||
505 | 4366 | caballero | // y miramos los handlers de cada entidad seleccionada
|
506 | 23646 | vcaballero | min = cta.getMapControl().getViewPort().toMapDistance( |
507 | 23657 | vcaballero | MapControl.tolerance); |
508 | 4366 | caballero | for (int j = 0; j < handlers.length; j++) { |
509 | Point2D handlerPoint = handlers[j].getPoint();
|
||
510 | double distance = firstPoint.distance(handlerPoint);
|
||
511 | if (distance <= min) {
|
||
512 | min = distance; |
||
513 | selectedHandler.add(handlers[j]); |
||
514 | } |
||
515 | } |
||
516 | 21668 | vcaballero | |
517 | 23646 | vcaballero | } |
518 | 21668 | vcaballero | |
519 | 23646 | vcaballero | setSelectionImage(selectionImage); |
520 | setHandlersImage(handlersImage); |
||
521 | 21668 | vcaballero | } catch (ReadException e) {
|
522 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
523 | 21668 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
524 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
525 | 21668 | vcaballero | } catch (GeometryOperationException e) {
|
526 | 23646 | vcaballero | NotificationManager.addError(e.getMessage(), e); |
527 | 21668 | vcaballero | } |
528 | 4366 | caballero | } |
529 | 4637 | caballero | |
530 | 23646 | vcaballero | public void drawHandlers(org.gvsig.fmap.geom.Geometry geom, Graphics2D gs, |
531 | ViewPort vp) { |
||
532 | // if (!(getLayer() instanceof FLyrAnnotation)){
|
||
533 | Handler[] handlers = geom |
||
534 | .getHandlers(org.gvsig.fmap.geom.Geometry.SELECTHANDLER); |
||
535 | FGraphicUtilities.DrawHandlers(gs, vp.getAffineTransform(), handlers, |
||
536 | DefaultCADTool.handlerSymbol); |
||
537 | // }
|
||
538 | 4637 | caballero | } |
539 | 23646 | vcaballero | |
540 | public Image getSelectionImage() { |
||
541 | 21668 | vcaballero | return imageSelection;
|
542 | 4637 | caballero | } |
543 | 23646 | vcaballero | |
544 | public void setSelectionImage(Image image) { |
||
545 | imageSelection = image; |
||
546 | 21668 | vcaballero | } |
547 | 23646 | vcaballero | |
548 | 4637 | caballero | public Image getHandlersImage() { |
549 | 21668 | vcaballero | return imageHandlers;
|
550 | 4637 | caballero | } |
551 | 23646 | vcaballero | |
552 | public void setHandlersImage(Image image) { |
||
553 | imageHandlers = image; |
||
554 | 4637 | caballero | } |
555 | |||
556 | public void beforeLayerDraw(LayerDrawEvent e) throws CancelationException { |
||
557 | 23646 | vcaballero | FeatureStore featureStore = null;
|
558 | 23086 | vcaballero | try {
|
559 | featureStore = getFeatureStore(); |
||
560 | } catch (ReadException e2) {
|
||
561 | // TODO Auto-generated catch block
|
||
562 | e2.printStackTrace(); |
||
563 | } |
||
564 | 21668 | vcaballero | if (featureStore.isEditing()) {
|
565 | 23646 | vcaballero | // VectorialEditableAdapter vea = (VectorialEditableAdapter)
|
566 | // ((FLyrVect) getLayer())
|
||
567 | // .getSource();
|
||
568 | 6881 | cesar | ViewPort vp = getLayer().getMapContext().getViewPort(); |
569 | 4637 | caballero | BufferedImage selectionImage = new BufferedImage( |
570 | vp.getImageWidth(), vp.getImageHeight(), |
||
571 | BufferedImage.TYPE_INT_ARGB);
|
||
572 | BufferedImage handlersImage = new BufferedImage(vp.getImageWidth(), |
||
573 | vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
574 | Graphics2D gs = selectionImage.createGraphics();
|
||
575 | Graphics2D gh = handlersImage.createGraphics();
|
||
576 | 23646 | vcaballero | Iterator iterator = featureStore.getSelection().iterator();
|
577 | 21668 | vcaballero | while (iterator.hasNext()) {
|
578 | Feature feature = (Feature) iterator.next(); |
||
579 | |||
580 | 23646 | vcaballero | // }
|
581 | // for (int i = 0; i < selectedRow.size(); i++) {
|
||
582 | // IFeature feat = (IFeature) ((IRowEdited) selectedRow.get(i))
|
||
583 | // .getLinkedRow();
|
||
584 | org.gvsig.fmap.geom.Geometry geom = (org.gvsig.fmap.geom.Geometry) feature |
||
585 | .getDefaultGeometry(); |
||
586 | 23086 | vcaballero | |
587 | 23646 | vcaballero | DrawOperationContext doc = new DrawOperationContext();
|
588 | doc.setGraphics(gs); |
||
589 | doc.setViewPort(vp); |
||
590 | doc.setSymbol(DefaultCADTool.selectionSymbol); |
||
591 | try {
|
||
592 | geom.cloneGeometry().invokeOperation(Draw.CODE, doc); |
||
593 | 23086 | vcaballero | } catch (GeometryOperationNotSupportedException e1) {
|
594 | e1.printStackTrace(); |
||
595 | } catch (GeometryOperationException e1) {
|
||
596 | e1.printStackTrace(); |
||
597 | } |
||
598 | 4637 | caballero | drawHandlers(geom.cloneGeometry(), gh, vp); |
599 | } |
||
600 | 23535 | vcaballero | setSelectionImage(selectionImage); |
601 | setHandlersImage(handlersImage); |
||
602 | 4637 | caballero | } |
603 | } |
||
604 | |||
605 | public void afterLayerDraw(LayerDrawEvent e) throws CancelationException { |
||
606 | } |
||
607 | |||
608 | 23646 | vcaballero | public void beforeGraphicLayerDraw(LayerDrawEvent e) |
609 | throws CancelationException {
|
||
610 | 4637 | caballero | } |
611 | |||
612 | 23646 | vcaballero | public void afterLayerGraphicDraw(LayerDrawEvent e) |
613 | throws CancelationException {
|
||
614 | 4637 | caballero | } |
615 | 23646 | vcaballero | |
616 | private static boolean contains(org.gvsig.fmap.geom.Geometry g1, |
||
617 | org.gvsig.fmap.geom.Geometry g2) { |
||
618 | try {
|
||
619 | Geometry geometry1 = (Geometry) g1 |
||
620 | .invokeOperation(ToJTS.CODE, null);
|
||
621 | Geometry geometry2 = (Geometry) g2 |
||
622 | .invokeOperation(ToJTS.CODE, null);
|
||
623 | if (geometry1 == null || geometry2 == null) |
||
624 | return false; |
||
625 | 21668 | vcaballero | return geometry1.contains(geometry2);
|
626 | } catch (GeometryOperationNotSupportedException e) {
|
||
627 | e.printStackTrace(); |
||
628 | } catch (GeometryOperationException e) {
|
||
629 | e.printStackTrace(); |
||
630 | } |
||
631 | return false; |
||
632 | 4717 | caballero | } |
633 | 23646 | vcaballero | |
634 | private static boolean intersects(org.gvsig.fmap.geom.Geometry g1, |
||
635 | org.gvsig.fmap.geom.Geometry g2) { |
||
636 | try {
|
||
637 | Geometry geometry1 = (Geometry) g1 |
||
638 | .invokeOperation(ToJTS.CODE, null);
|
||
639 | Geometry geometry2 = (Geometry) g2 |
||
640 | .invokeOperation(ToJTS.CODE, null);
|
||
641 | if (geometry1 == null || geometry2 == null) |
||
642 | return false; |
||
643 | 21668 | vcaballero | return geometry1.intersects(geometry2);
|
644 | } catch (GeometryOperationNotSupportedException e) {
|
||
645 | e.printStackTrace(); |
||
646 | } catch (GeometryOperationException e) {
|
||
647 | e.printStackTrace(); |
||
648 | } |
||
649 | return false; |
||
650 | 4717 | caballero | } |
651 | 5018 | caballero | |
652 | public void activationGained(LayerEvent e) { |
||
653 | 23646 | vcaballero | if (ViewCommandStackExtension.csd != null) { |
654 | 23086 | vcaballero | try {
|
655 | 23646 | vcaballero | ViewCommandStackExtension.csd.setModel(((FLyrVect) getLayer()) |
656 | .getFeatureStore().getCommandsRecord()); |
||
657 | 23086 | vcaballero | } catch (ReadException e1) {
|
658 | // TODO Auto-generated catch block
|
||
659 | e1.printStackTrace(); |
||
660 | } |
||
661 | 5084 | caballero | } |
662 | 23646 | vcaballero | IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
663 | if (window instanceof View) { |
||
664 | View view = (View) window; |
||
665 | if (e.getSource().isEditing()) {
|
||
666 | 10836 | caballero | view.showConsole(); |
667 | } |
||
668 | } |
||
669 | 23646 | vcaballero | if (cadtool != null) { |
670 | 5018 | caballero | CADExtension.getCADToolAdapter().setCadTool(cadtool); |
671 | PluginServices.getMainFrame().setSelectedTool(cadtool.toString()); |
||
672 | 23646 | vcaballero | StartEditing.startCommandsApplicable(null, (FLyrVect) getLayer());
|
673 | 5257 | caballero | CADExtension.initFocus(); |
674 | 5018 | caballero | } |
675 | 5227 | caballero | |
676 | 5018 | caballero | } |
677 | |||
678 | public void activationLost(LayerEvent e) { |
||
679 | 23646 | vcaballero | try {
|
680 | cadtool = CADExtension.getCADTool(); |
||
681 | IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
||
682 | if (window instanceof View) { |
||
683 | View view = (View) window; |
||
684 | 10836 | caballero | view.hideConsole(); |
685 | } |
||
686 | 23646 | vcaballero | } catch (EmptyStackException e1) { |
687 | cadtool = new SelectionCADTool();
|
||
688 | 5018 | caballero | cadtool.init(); |
689 | } |
||
690 | |||
691 | } |
||
692 | 5261 | fjp | |
693 | 23646 | vcaballero | // public ArrayList getSnappers() {
|
694 | // return snappers;
|
||
695 | // }
|
||
696 | //
|
||
697 | // public ArrayList getLayersToSnap() {
|
||
698 | // return layersToSnap;
|
||
699 | // }
|
||
700 | //
|
||
701 | // public void setLayersToSnap(ArrayList layersToSnap) {
|
||
702 | // this.layersToSnap = layersToSnap;
|
||
703 | //
|
||
704 | // }
|
||
705 | 5906 | caballero | |
706 | 23646 | vcaballero | // public void setSelectionCache(boolean savePrevious,ArrayList
|
707 | // selectedRowAux) {
|
||
708 | // try {
|
||
709 | // clearSelection(savePrevious);
|
||
710 | // VectorialEditableAdapter vea=getVEA();
|
||
711 | // FBitSet selection=vea.getSelection();
|
||
712 | // selectedRow.addAll(selectedRowAux);
|
||
713 | // for (int i = 0;i < selectedRow.size(); i++) {
|
||
714 | // IRowEdited edRow = (IRowEdited) selectedRow.get(i);
|
||
715 | // selection.set(edRow.getIndex());
|
||
716 | // }
|
||
717 | // FLyrVect active = (FLyrVect)getLayer();
|
||
718 | // active.getRecordset().getSelectionSupport().fireSelectionEvents();
|
||
719 | // } catch (ReadException e) {
|
||
720 | // NotificationManager.addError(e.getMessage(),e);
|
||
721 | // }
|
||
722 | // }
|
||
723 | 5813 | fjp | |
724 | 11558 | jaume | public void setLegend(ILegend legend) { |
725 | 23646 | vcaballero | this.legend = legend;
|
726 | 6312 | caballero | } |
727 | 23646 | vcaballero | |
728 | 11558 | jaume | public ILegend getLegend() {
|
729 | 6312 | caballero | return legend;
|
730 | } |
||
731 | 8940 | caballero | |
732 | 23646 | vcaballero | // public void addSelectionCache(DefaultRowEdited edited) {
|
733 | // selectedRow.add(edited);
|
||
734 | // }
|
||
735 | 8940 | caballero | |
736 | public boolean getPreviousSelection() { |
||
737 | 23086 | vcaballero | try {
|
738 | 23646 | vcaballero | return !((FLyrVect) getLayer()).getFeatureStore().getSelection()
|
739 | .isEmpty(); |
||
740 | 23086 | vcaballero | } catch (ReadException e) {
|
741 | // TODO Auto-generated catch block
|
||
742 | e.printStackTrace(); |
||
743 | } |
||
744 | return false; |
||
745 | 8940 | caballero | } |
746 | 23646 | vcaballero | |
747 | public FeatureStore getFeatureStore() throws ReadException { |
||
748 | return ((FLyrVect) getLayer()).getFeatureStore();
|
||
749 | 22986 | vcaballero | } |
750 | 9814 | caballero | |
751 | 21668 | vcaballero | public void update(Observable observable, Object notification) { |
752 | 10626 | caballero | try {
|
753 | 22986 | vcaballero | if (getFeatureStore().getSelection().isEmpty())
|
754 | 10626 | caballero | clearSelection(NOTSAVEPREVIOUS); |
755 | 21668 | vcaballero | } catch (ReadException e1) {
|
756 | 23646 | vcaballero | NotificationManager.addError(e1.getMessage(), e1); |
757 | 10626 | caballero | } |
758 | 21668 | vcaballero | |
759 | 9814 | caballero | } |
760 | 4144 | fjp | } |