Revision 1634 branches/pilotoDWG/applications/appgvSIG/src/com/iver/cit/gvsig/gui/cad/tools/SelectionCadTool.java

View differences:

SelectionCadTool.java
63 63
import java.awt.geom.Rectangle2D;
64 64

  
65 65
import java.io.IOException;
66

  
66 67
import java.util.ArrayList;
67 68

  
68 69

  
69 70
/**
70
 * DOCUMENT ME!
71
 * Herramienta para seleccionar las geometr?as por rectangulo o por hacer un
72
 * click sobre ellas.
71 73
 *
72 74
 * @author Vicente Caballero Navarro
73 75
 */
74 76
public class SelectionCadTool extends AbstractCadTool {
75 77
	private static Status[] STATUS = {
76
			new Status(""),
77
			new Status(""),
78
			new Status(""), new Status(""),
78 79
			new Status("Siguiente punto del rect?ngulo de selecci?n"),
79
			new Status(""),
80
			new Status("Precise punto de estiramiento"),
80
			new Status(""), new Status("Precise punto de estiramiento"),
81 81
		};
82 82
	public final static int tolerance = 5;
83 83
	private Seleccion selectionStatus = new Seleccion();
......
103 103
		} else if (status == 1) {
104 104
			firstPoint = new Point2D.Double(values[0], values[1]);
105 105

  
106
			double tolerance = getCadToolAdapter().getMapControl().getViewPort().toMapDistance(SelectionCadTool.tolerance);
107
			
106
			/*double tolerance = getCadToolAdapter().getMapControl().getViewPort()
107
								   .toMapDistance(SelectionCadTool.tolerance);
108

  
108 109
			Rectangle2D r = new Rectangle2D.Double(firstPoint.getX() -
109 110
					tolerance, firstPoint.getY() - tolerance, tolerance * 2,
110 111
					tolerance * 2);
111

  
112
*/
112 113
			if (selectedGeometries.cardinality() > 0) {
113 114
				//Se comprueba si se pincha un handler. El m?s cercano (o los m?s cercanos si hay empate)
114 115
				try {
115 116
					selectedGeometry.clear();
116 117
					selectedGeometryIndex.clear();
117 118
					selectedHandler.clear();
118
					
119

  
119 120
					double min = Double.MAX_VALUE;
120 121

  
121 122
					for (int i = selectedGeometries.nextSetBit(0); i >= 0;
......
124 125
														  .getHandlers(FGeometry.SELECTHANDLER);
125 126

  
126 127
						IGeometry clonedGeometry = null;
128

  
127 129
						for (int j = 0; j < handlers.length; j++) {
128 130
							Point2D handlerPoint = handlers[j].getPoint();
129 131

  
130
//							if (r.contains(handlerPoint.getX(),
131
	//									handlerPoint.getY())) {
132
							double distance = firstPoint.distance(handlerPoint); 
133
							if ((distance <= min) && (distance < tolerance)){
134
								if (distance < min){
132
							//							if (r.contains(handlerPoint.getX(),
133
							//									handlerPoint.getY())) {
134
							double distance = firstPoint.distance(handlerPoint);
135

  
136
							if ((distance <= min) && (distance < tolerance)) {
137
								if (distance < min) {
135 138
									selectedGeometry.clear();
136 139
									selectedGeometryIndex.clear();
137 140
									selectedHandler.clear();
138 141
								}
142

  
139 143
								min = distance;
140
								if (clonedGeometry == null){
141
									clonedGeometry = editingSource.getGeometry(i).cloneGeometry();
144

  
145
								if (clonedGeometry == null) {
146
									clonedGeometry = editingSource.getGeometry(i)
147
																  .cloneGeometry();
142 148
								}
149

  
143 150
								selectedGeometry.add(clonedGeometry);
144
								selectedHandler.add(clonedGeometry.getHandlers(FGeometry.SELECTHANDLER)[j]);
151
								selectedHandler.add(clonedGeometry.getHandlers(
152
										FGeometry.SELECTHANDLER)[j]);
145 153
								selectedGeometryIndex.add(new Integer(i));
146 154
							}
147 155
						}
148 156
					}
149
					if (selectedGeometry.size() > 0)
157

  
158
					if (selectedGeometry.size() > 0) {
150 159
						ret = ret | selectionStatus.transition("handler");
160
					}
151 161
				} catch (IOException e) {
152 162
					e.printStackTrace();
153 163
				} catch (DriverIOException e) {
154 164
					e.printStackTrace();
155 165
				}
156 166
			}
157
			if ((selectedGeometry.size() == 0) || (selectedGeometries.cardinality() == 0)){
167

  
168
			if ((selectedGeometry.size() == 0) ||
169
					(selectedGeometries.cardinality() == 0)) {
158 170
				// Se comprueba si se pincha en una gemometr?a
159 171
				PluginServices.getMDIManager().setWaitCursor();
172

  
160 173
				double tam = getCadToolAdapter().getMapControl().getViewPort()
161
				 .toMapDistance(SelectionCadTool.tolerance);
162
				Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() - tam,
163
						firstPoint.getY() - tam, tam, tam);
174
								 .toMapDistance(SelectionCadTool.tolerance);
175
				Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() -
176
						tam, firstPoint.getY() - tam, tam*2, tam*2);
164 177
				int[] indexes = editingSource.getGeometriesIndexes(rect);
165
			
178

  
166 179
				selectedGeometries.clear();
167 180

  
168 181
				try {
169 182
					for (int i = 0; i < indexes.length; i++) {
170
						if (editingSource.getGeometry(indexes[i]).fastIntersects(rect.getX(),
171
									rect.getY(), rect.getWidth(), rect.getHeight())) {
183
						if (editingSource.getGeometry(indexes[i])
184
											 .fastIntersects(rect.getX(),
185
									rect.getY(), rect.getWidth(),
186
									rect.getHeight())) {
172 187
							selectedGeometries.set(indexes[i], true);
173 188
						}
174 189
					}
......
190 205
			return ret;
191 206
		} else if (status == 3) {
192 207
			PluginServices.getMDIManager().setWaitCursor();
208

  
193 209
			if (values.length != 0) {
194 210
				lastPoint = new Point2D.Double(values[0], values[1]);
195 211
			}
......
219 235
				}
220 236

  
221 237
				Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
222
				
238

  
223 239
				int[] indexes = editingSource.getGeometriesIndexes(new Rectangle2D.Double(
224 240
							x, y, w, h));
225 241

  
......
236 252
			}
237 253

  
238 254
			PluginServices.getMDIManager().restoreCursor();
255

  
239 256
			if (selectedGeometries.cardinality() > 0) {
240 257
				ret = ret | selectionStatus.transition("sel");
241 258
			} else {
......
250 267
				int index = ((Integer) selectedGeometryIndex.get(i)).intValue();
251 268

  
252 269
				h.set(values[0], values[1]);
270

  
253 271
				try {
254 272
					editingSource.modifyGeometry(index, geom);
255 273
				} catch (IOException e) {
......
257 275
				} catch (DriverIOException e) {
258 276
					e.printStackTrace();
259 277
				}
260
				
261 278
			}
279

  
262 280
			ret = ret | selectionStatus.transition("done");
263 281

  
264 282
			return ret;
......
287 305
			ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
288 306
				getCadToolAdapter().getMapControl().getViewPort(),
289 307
				CadTool.selectSymbol);
290
		}else if (status == 4) {
308
		} else if (status == 4) {
291 309
			for (int i = 0; i < selectedGeometry.size(); i++) {
292 310
				Handler h = (Handler) selectedHandler.get(i);
293 311
				IGeometry geom = ((IGeometry) selectedGeometry.get(i)).cloneGeometry();
294 312
				int index = ((Integer) selectedGeometryIndex.get(i)).intValue();
295 313
				g.setColor(Color.gray);
296 314
				h.set(x, y);
297
				geom.draw((Graphics2D)g, getCadToolAdapter().getCadMapControl().getMapControl().getViewPort(), CadTool.modifySymbol);			
315
				geom.draw((Graphics2D) g,
316
					getCadToolAdapter().getCadMapControl().getMapControl()
317
						.getViewPort(), CadTool.modifySymbol);
298 318
			}
299 319
		}
300 320
	}

Also available in: Unified diff