Revision 37138 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/SelectionCADTool.java
SelectionCADTool.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
|
2 | 2 |
* |
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 | 8 |
* as published by the Free Software Foundation; either version 2 |
8 | 9 |
* of the License, or (at your option) any later version. |
9 |
* |
|
10 |
*
|
|
10 | 11 |
* This program is distributed in the hope that it will be useful, |
11 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 14 |
* GNU General Public License for more details. |
14 |
* |
|
15 |
*
|
|
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
40 | 21 |
*/ |
41 | 22 |
package org.gvsig.editing.gui.cad.tools; |
42 | 23 |
|
... | ... | |
73 | 54 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
74 | 55 |
import org.gvsig.tools.dispose.DisposableIterator; |
75 | 56 |
|
76 |
|
|
77 | 57 |
/** |
78 | 58 |
* DOCUMENT ME! |
79 |
* |
|
59 |
*
|
|
80 | 60 |
* @author Vicente Caballero Navarro |
81 | 61 |
*/ |
82 | 62 |
public class SelectionCADTool extends DefaultCADTool { |
... | ... | |
91 | 71 |
protected String nextState; |
92 | 72 |
// Registros de los que se ha seleccionado alg?n handler. |
93 | 73 |
protected ArrayList rowselectedHandlers = new ArrayList(); |
94 |
protected String type = PluginServices.getText(this,"simple"); |
|
74 |
protected String type = PluginServices.getText(this, "simple");
|
|
95 | 75 |
|
96 |
protected boolean multipleSelection=false;
|
|
76 |
protected boolean multipleSelection = false;
|
|
97 | 77 |
|
98 | 78 |
/** |
99 | 79 |
* Crea un nuevo SelectionCADTool. |
... | ... | |
109 | 89 |
public void init() { |
110 | 90 |
_fsm = new SelectionCADToolContext(this); |
111 | 91 |
setNextTool("selection"); |
112 |
setType(PluginServices.getText(this,"simple")); |
|
92 |
setType(PluginServices.getText(this, "simple"));
|
|
113 | 93 |
} |
114 | 94 |
|
115 | 95 |
public void transition(double x, double y, InputEvent event) { |
116 |
LOG.debug("TRANSICION DESDE ESTADO {}", _fsm.getState() |
|
117 |
+ " x= " + x + " y=" + y);
|
|
118 |
try{ |
|
96 |
LOG.debug("TRANSICION DESDE ESTADO {}", _fsm.getState() + " x= " + x
|
|
97 |
+ " y=" + y); |
|
98 |
try {
|
|
119 | 99 |
_fsm.addPoint(x, y, event); |
120 |
}catch (Exception e) { |
|
100 |
} catch (Exception e) {
|
|
121 | 101 |
init(); |
122 | 102 |
PluginServices.getMDIManager().restoreCursor(); |
123 | 103 |
} |
... | ... | |
129 | 109 |
} |
130 | 110 |
|
131 | 111 |
public void transition(String s) throws CommandException { |
132 |
if (!super.changeCommand(s)){ |
|
112 |
if (!super.changeCommand(s)) {
|
|
133 | 113 |
_fsm.addOption(s); |
134 | 114 |
} |
135 | 115 |
} |
... | ... | |
145 | 125 |
/** |
146 | 126 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el |
147 | 127 |
* editableFeatureSource que ya estar? creado. |
148 |
* |
|
128 |
*
|
|
149 | 129 |
* @param selection |
150 | 130 |
* Bitset con las geometr?as que est?n seleccionadas. |
151 | 131 |
* @param x |
... | ... | |
154 | 134 |
* par?metro y del punto que se pase en esta transici?n. |
155 | 135 |
*/ |
156 | 136 |
public void addPoint(double x, double y, InputEvent event) { |
157 |
SelectionCADToolState actualState = (SelectionCADToolState) _fsm.getPreviousState(); |
|
137 |
SelectionCADToolState actualState = |
|
138 |
(SelectionCADToolState) _fsm.getPreviousState(); |
|
158 | 139 |
String status = actualState.getName(); |
159 | 140 |
LOG.debug("PREVIOUSSTATE = {}", status); |
160 |
VectorialLayerEdited vle = getVLE();
|
|
161 |
try {
|
|
141 |
VectorialLayerEdited vle = getVLE(); |
|
142 |
try { |
|
162 | 143 |
LOG.debug("STATUS ACTUAL = {}", _fsm.getTransition()); |
163 | 144 |
if (status.equals("Selection.FirstPoint")) { |
164 |
firstPoint = new Point2D.Double(x, y); |
|
165 |
} else if (status.equals("Selection.SecondPoint")) { |
|
166 |
} else if (status.equals("Selection.WithFeatures")) { |
|
167 |
} else if (status.equals("Selection.WithHandlers")) { |
|
168 |
addPointWithHandlers(x, y, vle.getFeatureStore(), vle.getSelectedHandler()); |
|
169 |
} |
|
145 |
firstPoint = new Point2D.Double(x, y); |
|
146 |
} else |
|
147 |
if (status.equals("Selection.SecondPoint")) { |
|
148 |
} else |
|
149 |
if (status.equals("Selection.WithFeatures")) { |
|
150 |
} else |
|
151 |
if (status.equals("Selection.WithHandlers")) { |
|
152 |
addPointWithHandlers(x, y, vle.getFeatureStore(), |
|
153 |
vle.getSelectedHandler()); |
|
154 |
} |
|
170 | 155 |
} catch (DataException e) { |
171 | 156 |
LOG.error("Error reding the store", e); |
172 | 157 |
} |
... | ... | |
174 | 159 |
|
175 | 160 |
/** |
176 | 161 |
* AddPoint method for the WithHandlers option |
162 |
* |
|
177 | 163 |
* @param x |
178 |
* selected x coordinate. |
|
164 |
* selected x coordinate.
|
|
179 | 165 |
* @param y |
180 |
* selected y coordinate. |
|
166 |
* selected y coordinate.
|
|
181 | 167 |
* @param featureStore |
182 |
* the selected feature store. |
|
168 |
* the selected feature store.
|
|
183 | 169 |
* @param selectedHandlers |
184 |
* the selected handlers |
|
170 |
* the selected handlers
|
|
185 | 171 |
*/ |
186 |
protected void addPointWithHandlers(double x, double y, FeatureStore featureStore, ArrayList selectedHandlers){ |
|
172 |
protected void addPointWithHandlers(double x, double y, |
|
173 |
FeatureStore featureStore, ArrayList selectedHandlers) { |
|
187 | 174 |
String description = PluginServices.getText(this, "move_handlers"); |
188 | 175 |
DisposableIterator iterator = null; |
189 | 176 |
try { |
190 |
featureStore.beginEditingGroup(description);
|
|
177 |
featureStore.beginEditingGroup(description); |
|
191 | 178 |
|
192 |
iterator = ((FeatureSelection) featureStore.getSelection()).fastIterator(); |
|
179 |
iterator = |
|
180 |
((FeatureSelection) featureStore.getSelection()).fastIterator(); |
|
193 | 181 |
|
194 | 182 |
while (iterator.hasNext()) { |
195 | 183 |
Feature feature = (Feature) iterator.next(); |
196 | 184 |
|
197 |
Geometry geometry = (feature.getDefaultGeometry()).cloneGeometry(); |
|
185 |
Geometry geometry = |
|
186 |
(feature.getDefaultGeometry()).cloneGeometry(); |
|
198 | 187 |
|
199 | 188 |
// Movemos los handlers que hemos seleccionado |
200 | 189 |
// previamente dentro del m?todo select() |
201 |
Handler[] handlers = geometry.getHandlers(Geometry.SELECTHANDLER); |
|
190 |
Handler[] handlers = |
|
191 |
geometry.getHandlers(Geometry.SELECTHANDLER); |
|
202 | 192 |
for (int k = 0; k < selectedHandlers.size(); k++) { |
203 | 193 |
Handler h = (Handler) selectedHandlers.get(k); |
204 | 194 |
for (int j = 0; j < handlers.length; j++) { |
... | ... | |
216 | 206 |
firstPoint = new Point2D.Double(x, y); |
217 | 207 |
|
218 | 208 |
featureStore.endEditingGroup(); |
219 |
} catch (DataException e1) {
|
|
209 |
} catch (DataException e1) { |
|
220 | 210 |
LOG.error("Error reading the store", e1); |
221 | 211 |
} finally { |
222 | 212 |
if (iterator != null) { |
... | ... | |
227 | 217 |
|
228 | 218 |
/** |
229 | 219 |
* Receives second point |
220 |
* |
|
230 | 221 |
* @param x |
231 | 222 |
* @param y |
232 | 223 |
* @return numFeatures selected |
... | ... | |
234 | 225 |
public long selectWithSecondPoint(double x, double y, InputEvent event) { |
235 | 226 |
VectorialLayerEdited vle = getVLE(); |
236 | 227 |
PluginServices.getMDIManager().setWaitCursor(); |
237 |
vle.selectWithSecondPoint(x,y); |
|
238 |
FeatureSet selection=null;
|
|
228 |
vle.selectWithSecondPoint(x, y);
|
|
229 |
FeatureSet selection = null;
|
|
239 | 230 |
try { |
240 |
selection = (FeatureSet)vle.getFeatureStore().getSelection(); |
|
231 |
selection = (FeatureSet) vle.getFeatureStore().getSelection();
|
|
241 | 232 |
PluginServices.getMDIManager().restoreCursor(); |
242 |
long countSel=selection.getSize();
|
|
233 |
long countSel = selection.getSize();
|
|
243 | 234 |
if (countSel > 0) { |
244 | 235 |
nextState = "Selection.WithSelectedFeatures"; |
245 | 236 |
} else { |
... | ... | |
258 | 249 |
/** |
259 | 250 |
* M?todo para dibujar la lo necesario para el estado en el que nos |
260 | 251 |
* encontremos. |
261 |
* |
|
252 |
*
|
|
262 | 253 |
* @param g |
263 | 254 |
* Graphics sobre el que dibujar. |
264 | 255 |
* @param selectedGeometries |
... | ... | |
276 | 267 |
return; |
277 | 268 |
} |
278 | 269 |
ArrayList selectedHandler = vle.getSelectedHandler(); |
279 |
ViewPort vp=vle.getLayer().getMapContext().getViewPort();
|
|
270 |
ViewPort vp = vle.getLayer().getMapContext().getViewPort();
|
|
280 | 271 |
if (status.equals("Selection.SecondPoint")) { |
281 | 272 |
// Dibuja el rect?ngulo de selecci?n |
282 | 273 |
Curve curve = createCurve(); |
283 |
curve.addMoveToVertex(createPoint(firstPoint.getX(), firstPoint.getY())); |
|
274 |
curve.addMoveToVertex(createPoint(firstPoint.getX(), |
|
275 |
firstPoint.getY())); |
|
284 | 276 |
curve.addVertex(createPoint(x, firstPoint.getY())); |
285 | 277 |
curve.addVertex(createPoint(x, y)); |
286 | 278 |
curve.addVertex(createPoint(firstPoint.getX(), y)); |
287 | 279 |
curve.addVertex(createPoint(firstPoint.getX(), firstPoint.getY())); |
288 | 280 |
|
289 |
renderer.draw(curve, mapControlManager.getGeometrySelectionSymbol()); |
|
281 |
renderer |
|
282 |
.draw(curve, mapControlManager.getGeometrySelectionSymbol()); |
|
290 | 283 |
|
291 | 284 |
return; |
292 |
}else if (status.equals("Selection.WithHandlers")) { |
|
293 |
// Movemos los handlers que hemos seleccionado |
|
294 |
// previamente dentro del m?todo select() |
|
295 |
double xPrev=0; |
|
296 |
double yPrev=0; |
|
297 |
for (int k = 0; k < selectedHandler.size(); k++) { |
|
298 |
Handler h = (Handler)selectedHandler.get(k); |
|
299 |
xPrev=h.getPoint().getX(); |
|
300 |
yPrev=h.getPoint().getY(); |
|
301 |
h.set(x, y); |
|
302 |
} |
|
303 |
// Y una vez movidos los v?rtices (handles) |
|
304 |
// redibujamos la nueva geometr?a. |
|
305 |
for (int i = 0; i < rowselectedHandlers.size(); i++) { |
|
306 |
Feature feature=(Feature)rowselectedHandlers.get(i); |
|
285 |
} else |
|
286 |
if (status.equals("Selection.WithHandlers")) { |
|
287 |
// Movemos los handlers que hemos seleccionado |
|
288 |
// previamente dentro del m?todo select() |
|
289 |
double xPrev = 0; |
|
290 |
double yPrev = 0; |
|
291 |
for (int k = 0; k < selectedHandler.size(); k++) { |
|
292 |
Handler h = (Handler) selectedHandler.get(k); |
|
293 |
xPrev = h.getPoint().getX(); |
|
294 |
yPrev = h.getPoint().getY(); |
|
295 |
h.set(x, y); |
|
296 |
} |
|
297 |
// Y una vez movidos los v?rtices (handles) |
|
298 |
// redibujamos la nueva geometr?a. |
|
299 |
for (int i = 0; i < rowselectedHandlers.size(); i++) { |
|
300 |
Feature feature = (Feature) rowselectedHandlers.get(i); |
|
307 | 301 |
|
308 |
Geometry geom=(feature.getDefaultGeometry()).cloneGeometry(); |
|
309 |
renderer.setColor(Color.gray); |
|
310 |
renderer.draw(geom, mapControlManager.getAxisReferenceSymbol()); |
|
302 |
Geometry geom = |
|
303 |
(feature.getDefaultGeometry()).cloneGeometry(); |
|
304 |
renderer.setColor(Color.gray); |
|
305 |
renderer.draw(geom, |
|
306 |
mapControlManager.getAxisReferenceSymbol()); |
|
307 |
} |
|
308 |
for (int k = 0; k < selectedHandler.size(); k++) { |
|
309 |
Handler h = (Handler) selectedHandler.get(k); |
|
310 |
h.set(xPrev, yPrev); |
|
311 |
} |
|
312 |
return; |
|
311 | 313 |
} |
312 |
for (int k = 0; k < selectedHandler.size(); k++) { |
|
313 |
Handler h = (Handler)selectedHandler.get(k); |
|
314 |
h.set(xPrev, yPrev); |
|
315 |
} |
|
316 |
return; |
|
317 |
} |
|
318 | 314 |
} |
319 | 315 |
|
320 | 316 |
/** |
321 | 317 |
* Add a diferent option. |
322 |
* |
|
318 |
*
|
|
323 | 319 |
* @param sel |
324 | 320 |
* DOCUMENT ME! |
325 | 321 |
* @param s |
326 | 322 |
* Diferent option. |
327 | 323 |
*/ |
328 | 324 |
public void addOption(String s) { |
329 |
SelectionCADToolState actualState = (SelectionCADToolState) _fsm
|
|
330 |
.getPreviousState(); |
|
325 |
SelectionCADToolState actualState = |
|
326 |
(SelectionCADToolState) _fsm.getPreviousState();
|
|
331 | 327 |
String status = actualState.getName(); |
332 | 328 |
LOG.debug("PREVIOUSSTATE = {}", status); |
333 | 329 |
LOG.debug("STATUS ACTUAL = {}", _fsm.getTransition()); |
334 |
if (s.equals(PluginServices.getText(this,"cancel"))){
|
|
330 |
if (s.equals(PluginServices.getText(this, "cancel"))) {
|
|
335 | 331 |
init(); |
336 | 332 |
return; |
337 | 333 |
} |
... | ... | |
344 | 340 |
|
345 | 341 |
/* |
346 | 342 |
* (non-Javadoc) |
347 |
* |
|
343 |
*
|
|
348 | 344 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double) |
349 | 345 |
*/ |
350 | 346 |
public void addValue(double d) { |
... | ... | |
352 | 348 |
|
353 | 349 |
public String getStatus() { |
354 | 350 |
try { |
355 |
SelectionCADToolState actualState = (SelectionCADToolState) _fsm
|
|
356 |
.getPreviousState(); |
|
351 |
SelectionCADToolState actualState = |
|
352 |
(SelectionCADToolState) _fsm.getPreviousState();
|
|
357 | 353 |
String status = actualState.getName(); |
358 | 354 |
|
359 | 355 |
return status; |
... | ... | |
364 | 360 |
|
365 | 361 |
public void end() { |
366 | 362 |
if (!getNextTool().equals("selection")) { |
367 |
CADExtension.setCADTool(getNextTool(),false); |
|
363 |
CADExtension.setCADTool(getNextTool(), false);
|
|
368 | 364 |
} |
369 | 365 |
} |
370 | 366 |
|
371 | 367 |
public String getName() { |
372 |
return PluginServices.getText(this,"selection_"); |
|
368 |
return PluginServices.getText(this, "selection_");
|
|
373 | 369 |
} |
374 | 370 |
|
375 | 371 |
public boolean selectFeatures(double x, double y, InputEvent event) { |
... | ... | |
396 | 392 |
} |
397 | 393 |
FeatureSet selection = null; |
398 | 394 |
try { |
399 |
selection = (FeatureSet)vle.getFeatureStore().getSelection(); |
|
400 |
long countSel=selection.getSize();
|
|
395 |
selection = (FeatureSet) vle.getFeatureStore().getSelection();
|
|
396 |
long countSel = selection.getSize();
|
|
401 | 397 |
if (countSel > 0) { |
402 | 398 |
nextState = "Selection.WithSelectedFeatures"; |
403 | 399 |
return true; |
... | ... | |
421 | 417 |
|
422 | 418 |
VectorialLayerEdited vle = getVLE(); |
423 | 419 |
ArrayList selectedHandler = vle.getSelectedHandler(); |
424 |
FeatureSet selection=null;
|
|
420 |
FeatureSet selection = null;
|
|
425 | 421 |
DisposableIterator iterator = null; |
426 | 422 |
try { |
427 |
selection = (FeatureSet)vle.getFeatureStore().getSelection(); |
|
423 |
selection = (FeatureSet) vle.getFeatureStore().getSelection();
|
|
428 | 424 |
|
429 | 425 |
long countSel = selection.getSize(); |
430 | 426 |
LOG.debug("DENTRO DE selectHandlers. selectedRow.size = {}", |
... | ... | |
434 | 430 |
// Se comprueba si se pincha en una gemometr?a |
435 | 431 |
PluginServices.getMDIManager().setWaitCursor(); |
436 | 432 |
|
437 |
double tam = getCadToolAdapter().getMapControl().getViewPort() |
|
438 |
.toMapDistance(mapControlManager.getTolerance()); |
|
433 |
double tam = |
|
434 |
getCadToolAdapter().getMapControl().getViewPort() |
|
435 |
.toMapDistance(mapControlManager.getTolerance()); |
|
439 | 436 |
|
440 | 437 |
Handler[] handlers = null; |
441 | 438 |
rowselectedHandlers.clear(); |
442 | 439 |
iterator = selection.fastIterator(); |
443 | 440 |
while (iterator.hasNext()) { |
444 | 441 |
Feature feature = (Feature) iterator.next(); |
445 |
handlers = (feature.getDefaultGeometry()).getHandlers(Geometry.SELECTHANDLER); |
|
442 |
handlers = |
|
443 |
(feature.getDefaultGeometry()) |
|
444 |
.getHandlers(Geometry.SELECTHANDLER); |
|
446 | 445 |
|
447 | 446 |
// y miramos los handlers de cada entidad seleccionada |
448 | 447 |
double min = tam; |
... | ... | |
451 | 450 |
Point2D handlerPoint = handlers[j].getPoint(); |
452 | 451 |
double distance = auxPoint.distance(handlerPoint); |
453 | 452 |
if (distance <= min) { |
454 |
min = distance;
|
|
453 |
min = distance; |
|
455 | 454 |
selectedHandler.add(handlers[j]); |
456 | 455 |
rowselectedHandlers.add(feature); |
457 | 456 |
} |
... | ... | |
474 | 473 |
} |
475 | 474 |
|
476 | 475 |
public void setType(String type) { |
477 |
if (type.equals("S") || type.equals("s")){ |
|
478 |
this.type=PluginServices.getText(this,"simple");
|
|
479 |
}else{
|
|
476 |
if (type.equals("S") || type.equals("s")) {
|
|
477 |
this.type = PluginServices.getText(this, "simple");
|
|
478 |
} else {
|
|
480 | 479 |
this.type = type; |
481 | 480 |
} |
482 | 481 |
} |
... | ... | |
486 | 485 |
} |
487 | 486 |
|
488 | 487 |
public void multipleSelection(boolean b) { |
489 |
multipleSelection=b;
|
|
488 |
multipleSelection = b;
|
|
490 | 489 |
|
491 | 490 |
} |
492 | 491 |
} |
Also available in: Unified diff