Revision 3847 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/SelectionCADTool.java
SelectionCADTool.java | ||
---|---|---|
72 | 72 |
private SelectionCADToolContext _fsm; |
73 | 73 |
private Point2D firstPoint; |
74 | 74 |
private Point2D lastPoint; |
75 |
private Point2D point; |
|
76 | 75 |
private ArrayList selectedHandler = new ArrayList(); |
77 | 76 |
private ArrayList selectedRow = new ArrayList(); |
78 | 77 |
private ArrayList selectedRowIndex = new ArrayList(); |
... | ... | |
122 | 121 |
//_fsm.addOption(sel,s); |
123 | 122 |
} |
124 | 123 |
|
124 |
|
|
125 |
public boolean isSelected(double x, double y){ |
|
126 |
firstPoint=new Point2D.Double(x,y); |
|
127 |
FBitSet selection=getVectorialAdapter().getSelection(); |
|
128 |
if (selection.cardinality() > 0) { |
|
129 |
//Se comprueba si se pincha un handler. El m?s cercano (o los m?s cercanos si hay empate) |
|
130 |
selectedRow.clear(); |
|
131 |
selectedRowIndex.clear(); |
|
132 |
selectedHandler.clear(); |
|
133 |
|
|
134 |
double min = Double.MAX_VALUE; |
|
135 |
|
|
136 |
for (int i = selection.nextSetBit(0); i >= 0; |
|
137 |
i = selection.nextSetBit(i + 1)) { |
|
138 |
Handler[] handlers=null; |
|
139 |
try { |
|
140 |
handlers = getVectorialAdapter().getShape(i) |
|
141 |
.getHandlers(IGeometry.SELECTHANDLER); |
|
142 |
} catch (DriverIOException e) { |
|
143 |
// TODO Auto-generated catch block |
|
144 |
e.printStackTrace(); |
|
145 |
} |
|
146 |
|
|
147 |
DefaultFeature fea = null; |
|
148 |
|
|
149 |
for (int j = 0; j < handlers.length; j++) { |
|
150 |
Point2D handlerPoint = handlers[j].getPoint(); |
|
151 |
double distance = firstPoint.distance(handlerPoint); |
|
152 |
if ((distance <= min) && |
|
153 |
(distance < getCadToolAdapter() |
|
154 |
.getMapControl() |
|
155 |
.getViewPort() |
|
156 |
.toMapDistance(tolerance))) { |
|
157 |
if (distance < min) { |
|
158 |
selectedRow.clear(); |
|
159 |
selectedRowIndex.clear(); |
|
160 |
selectedHandler.clear(); |
|
161 |
} |
|
162 |
|
|
163 |
min = distance; |
|
164 |
|
|
165 |
if (fea == null) { |
|
166 |
IGeometry clonedGeometry=null; |
|
167 |
try { |
|
168 |
clonedGeometry = getVectorialAdapter() |
|
169 |
.getShape(i) |
|
170 |
.cloneGeometry(); |
|
171 |
} catch (DriverIOException e) { |
|
172 |
// TODO Auto-generated catch block |
|
173 |
e.printStackTrace(); |
|
174 |
} |
|
175 |
try { |
|
176 |
fea = (DefaultFeature) getVectorialAdapter() |
|
177 |
.getFeature(i); |
|
178 |
} catch (DriverException e) { |
|
179 |
// TODO Auto-generated catch block |
|
180 |
e.printStackTrace(); |
|
181 |
} |
|
182 |
selectedRow.add(new DefaultFeature(clonedGeometry,fea.getAttributes())); |
|
183 |
selectedHandler.add(clonedGeometry |
|
184 |
.getHandlers(IGeometry.SELECTHANDLER)[j]); |
|
185 |
selectedRowIndex.add(new Integer(i)); |
|
186 |
} |
|
187 |
|
|
188 |
|
|
189 |
} |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
} |
|
194 |
|
|
195 |
if ((selectedRow.size() == 0) || |
|
196 |
(selection.cardinality() == 0)) { |
|
197 |
// Se comprueba si se pincha en una gemometr?a |
|
198 |
PluginServices.getMDIManager().setWaitCursor(); |
|
199 |
|
|
200 |
double tam = getCadToolAdapter().getMapControl() |
|
201 |
.getViewPort().toMapDistance(tolerance); |
|
202 |
Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() - |
|
203 |
tam, firstPoint.getY() - tam, tam * 2, tam * 2); |
|
204 |
int[] indexes = getVectorialAdapter().getRowsIndexes(rect); |
|
205 |
|
|
206 |
selection.clear(); |
|
207 |
|
|
208 |
for (int i = 0; i < indexes.length; i++) { |
|
209 |
try { |
|
210 |
if (getVectorialAdapter().getShape(indexes[i]) |
|
211 |
.intersects(rect)) { |
|
212 |
// .intersects(rect,FLATNESS)) { |
|
213 |
selection.set(indexes[i], true); |
|
214 |
} |
|
215 |
} catch (DriverIOException e) { |
|
216 |
// TODO Auto-generated catch block |
|
217 |
e.printStackTrace(); |
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
PluginServices.getMDIManager().restoreCursor(); |
|
222 |
} |
|
223 |
return selection.cardinality()>0; |
|
224 |
} |
|
225 |
|
|
125 | 226 |
/** |
126 | 227 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el |
127 | 228 |
* editableFeatureSource que ya estar? creado. |
... | ... | |
136 | 237 |
FBitSet selection=getVectorialAdapter().getSelection(); |
137 | 238 |
try { |
138 | 239 |
if (status.equals("ExecuteMap.Initial")) { |
139 |
firstPoint = new Point2D.Double(x, y); |
|
240 |
//firstPoint = new Point2D.Double(x, y);
|
|
140 | 241 |
} else if (status.equals("ExecuteMap.First")) { |
141 | 242 |
//PluginServices.getMDIManager().setWaitCursor(); |
142 | 243 |
lastPoint = new Point2D.Double(x, y); |
... | ... | |
186 | 287 |
PluginServices.getMDIManager().restoreCursor(); |
187 | 288 |
//cardinality = selection.cardinality(); |
188 | 289 |
} else if (status.equals("ExecuteMap.Second")) { |
189 |
point = new Point2D.Double(x, y); |
|
190 |
|
|
191 |
if (selection.cardinality() > 0) { |
|
192 |
//Se comprueba si se pincha un handler. El m?s cercano (o los m?s cercanos si hay empate) |
|
193 |
selectedRow.clear(); |
|
194 |
selectedRowIndex.clear(); |
|
195 |
selectedHandler.clear(); |
|
196 |
|
|
197 |
double min = Double.MAX_VALUE; |
|
198 |
|
|
199 |
for (int i = selection.nextSetBit(0); i >= 0; |
|
200 |
i = selection.nextSetBit(i + 1)) { |
|
201 |
Handler[] handlers = getVectorialAdapter().getShape(i) |
|
202 |
.getHandlers(IGeometry.SELECTHANDLER); |
|
203 |
|
|
204 |
DefaultFeature fea = null; |
|
205 |
|
|
206 |
for (int j = 0; j < handlers.length; j++) { |
|
207 |
Point2D handlerPoint = handlers[j].getPoint(); |
|
208 |
double distance = point.distance(handlerPoint); |
|
209 |
if ((distance <= min) && |
|
210 |
(distance < getCadToolAdapter() |
|
211 |
.getMapControl() |
|
212 |
.getViewPort() |
|
213 |
.toMapDistance(tolerance))) { |
|
214 |
if (distance < min) { |
|
215 |
selectedRow.clear(); |
|
216 |
selectedRowIndex.clear(); |
|
217 |
selectedHandler.clear(); |
|
218 |
} |
|
219 |
|
|
220 |
min = distance; |
|
221 |
|
|
222 |
if (fea == null) { |
|
223 |
IGeometry clonedGeometry = getVectorialAdapter() |
|
224 |
.getShape(i) |
|
225 |
.cloneGeometry(); |
|
226 |
fea = (DefaultFeature) getVectorialAdapter() |
|
227 |
.getFeature(i); |
|
228 |
selectedRow.add(new DefaultFeature(clonedGeometry,fea.getAttributes())); |
|
229 |
selectedHandler.add(clonedGeometry |
|
230 |
.getHandlers(IGeometry.SELECTHANDLER)[j]); |
|
231 |
selectedRowIndex.add(new Integer(i)); |
|
232 |
} |
|
233 |
|
|
234 |
|
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
/* if ((selectedRow.size() == 0) || |
|
241 |
(selection.cardinality() == 0)) { |
|
242 |
// Se comprueba si se pincha en una gemometr?a |
|
243 |
PluginServices.getMDIManager().setWaitCursor(); |
|
244 |
|
|
245 |
double tam = getCadToolAdapter().getMapControl() |
|
246 |
.getViewPort().toMapDistance(tolerance); |
|
247 |
Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() - |
|
248 |
tam, firstPoint.getY() - tam, tam * 2, tam * 2); |
|
249 |
int[] indexes = getVectorialAdapter().getRowsIndexes(rect); |
|
250 |
|
|
251 |
selection.clear(); |
|
252 |
|
|
253 |
for (int i = 0; i < indexes.length; i++) { |
|
254 |
if (getVectorialAdapter().getShape(indexes[i]) |
|
255 |
.intersects(rect)) { |
|
256 |
// .intersects(rect,FLATNESS)) { |
|
257 |
selection.set(indexes[i], true); |
|
258 |
} |
|
259 |
} |
|
260 |
|
|
261 |
PluginServices.getMDIManager().restoreCursor(); |
|
262 |
cardinality = selection.cardinality(); |
|
263 |
} |
|
264 |
*/ } else if (status.equals("ExecuteMap.Third")) { |
|
265 |
for (int i = 0; i < selectedRow.size(); i++) { |
|
290 |
for (int i = 0; i < selectedRow.size(); i++) { |
|
266 | 291 |
Handler h = (Handler) selectedHandler.get(i); |
267 | 292 |
DefaultFeature row = (DefaultFeature) selectedRow.get(i); |
268 | 293 |
int index = ((Integer) selectedRowIndex.get(i)).intValue(); |
... | ... | |
271 | 296 |
//getVectorialAdapter().modifyRow(index, row); |
272 | 297 |
modifyFeature(index,row); |
273 | 298 |
} |
274 |
|
|
275 |
// ret = ret | selectionStatus.transition("done"); |
|
276 | 299 |
} |
277 | 300 |
// } catch (IOException e) { |
278 | 301 |
// TODO Auto-generated catch block |
... | ... | |
280 | 303 |
} catch (DriverIOException e) { |
281 | 304 |
// TODO Auto-generated catch block |
282 | 305 |
e.printStackTrace(); |
283 |
} catch (DriverException e) { |
|
284 |
// TODO Auto-generated catch block |
|
285 |
e.printStackTrace(); |
|
286 | 306 |
} |
287 | 307 |
} |
288 | 308 |
|
... | ... | |
318 | 338 |
ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g, |
319 | 339 |
getCadToolAdapter().getMapControl().getViewPort(), |
320 | 340 |
CADTool.selectSymbol); |
321 |
} else if (status.equals("ExecuteMap.Third")) {
|
|
341 |
} else if (status.equals("ExecuteMap.Second")) {
|
|
322 | 342 |
for (int i = 0; i < selectedRow.size(); i++) { |
323 | 343 |
Handler h = (Handler) selectedHandler.get(i); |
324 | 344 |
IGeometry geom = ((IGeometry) ((DefaultFeature)selectedRow.get(i)).getGeometry()).cloneGeometry(); |
Also available in: Unified diff