svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / EditVertexCADTool.java @ 4637
History | View | Annotate | Download (21.5 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* 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
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.cad.tools; |
42 |
|
43 |
import java.awt.Graphics; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.event.InputEvent; |
46 |
import java.awt.geom.AffineTransform; |
47 |
import java.awt.geom.PathIterator; |
48 |
import java.awt.geom.Point2D; |
49 |
import java.awt.geom.Rectangle2D; |
50 |
import java.io.IOException; |
51 |
import java.util.ArrayList; |
52 |
|
53 |
import com.iver.andami.PluginServices; |
54 |
import com.iver.cit.gvsig.CADExtension; |
55 |
import com.iver.cit.gvsig.fmap.DriverException; |
56 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
57 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
58 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
59 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
60 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
61 |
import com.iver.cit.gvsig.fmap.core.FShape; |
62 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
63 |
import com.iver.cit.gvsig.fmap.core.GeneralPathXIterator; |
64 |
import com.iver.cit.gvsig.fmap.core.Handler; |
65 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
66 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
67 |
import com.iver.cit.gvsig.fmap.core.IRow; |
68 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
69 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
70 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
71 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
72 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
73 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
74 |
//import com.iver.cit.gvsig.fmap.layers.FBitSet;
|
75 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
76 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext; |
77 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext.EditVertexCADToolState; |
78 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
79 |
|
80 |
|
81 |
/**
|
82 |
* DOCUMENT ME!
|
83 |
*
|
84 |
* @author Vicente Caballero Navarro
|
85 |
*/
|
86 |
public class EditVertexCADTool extends DefaultCADTool { |
87 |
private EditVertexCADToolContext _fsm;
|
88 |
private int numSelect=0; |
89 |
private int numHandlers; |
90 |
private boolean addVertex=false; |
91 |
/**
|
92 |
* Crea un nuevo PolylineCADTool.
|
93 |
*/
|
94 |
public EditVertexCADTool() {
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
99 |
* carga previa a la utilizaci?n de la herramienta.
|
100 |
*/
|
101 |
public void init() { |
102 |
_fsm = new EditVertexCADToolContext(this); |
103 |
} |
104 |
|
105 |
/* (non-Javadoc)
|
106 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
107 |
*/
|
108 |
public void transition(double x, double y, InputEvent event) { |
109 |
addPoint(x, y, event); |
110 |
} |
111 |
|
112 |
/* (non-Javadoc)
|
113 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
114 |
*/
|
115 |
public void transition(double d) { |
116 |
//_fsm.addValue(sel,d);
|
117 |
} |
118 |
|
119 |
/* (non-Javadoc)
|
120 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
121 |
*/
|
122 |
public void transition(String s) { |
123 |
_fsm.addOption(s); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* DOCUMENT ME!
|
128 |
*/
|
129 |
public void selection() { |
130 |
ArrayList selectedRow=getSelectedRows();
|
131 |
if (selectedRow.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
132 |
CADExtension.setCADTool("selection");
|
133 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
134 |
"editvertex");
|
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
140 |
* editableFeatureSource que ya estar? creado.
|
141 |
*
|
142 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
143 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
144 |
*/
|
145 |
public void addPoint(double x, double y,InputEvent event) { |
146 |
selectHandler(x,y); |
147 |
addVertex=false;
|
148 |
} |
149 |
|
150 |
private IGeometry getSelectedGeometry() {
|
151 |
ArrayList selectedRows=getSelectedRows();
|
152 |
// VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
|
153 |
// FBitSet selection = vea.getSelection();
|
154 |
IRowEdited row=null;
|
155 |
IGeometry ig=null;
|
156 |
if (selectedRows.size()==1){ |
157 |
row=(DefaultRowEdited) selectedRows.get(0);
|
158 |
//row = getCadToolAdapter().getVectorialAdapter().getRow(selection.nextSetBit(0));
|
159 |
ig=((IFeature)row.getLinkedRow()).getGeometry().cloneGeometry(); |
160 |
return ig;
|
161 |
} |
162 |
|
163 |
return null; |
164 |
} |
165 |
|
166 |
/**
|
167 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
168 |
* encontremos.
|
169 |
*
|
170 |
* @param g Graphics sobre el que dibujar.
|
171 |
* @param x par?metro x del punto que se pase para dibujar.
|
172 |
* @param y par?metro x del punto que se pase para dibujar.
|
173 |
*/
|
174 |
public void drawOperation(Graphics g, double x, double y) { |
175 |
//EditVertexCADToolState actualState = ((EditVertexCADToolContext) _fsm).getState();
|
176 |
//String status = actualState.getName();
|
177 |
//VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
|
178 |
//FBitSet selection = vea.getSelection();
|
179 |
|
180 |
try {
|
181 |
drawVertex(g,getCadToolAdapter().getMapControl().getViewPort() |
182 |
.getAffineTransform()); |
183 |
} catch (DriverIOException e) {
|
184 |
e.printStackTrace(); |
185 |
} |
186 |
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* Add a diferent option.
|
191 |
*
|
192 |
* @param s Diferent option.
|
193 |
*/
|
194 |
public void addOption(String s) { |
195 |
EditVertexCADToolState actualState = (EditVertexCADToolState) _fsm.getPreviousState(); |
196 |
String status = actualState.getName();
|
197 |
VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter(); |
198 |
//FBitSet selection = vea.getSelection();
|
199 |
ArrayList selectedRows=getSelectedRows();
|
200 |
IRowEdited row=null;
|
201 |
IGeometry ig=null;
|
202 |
Handler[] handlers=null; |
203 |
if (selectedRows.size()==1){ |
204 |
row = (DefaultRowEdited) selectedRows.get(0);
|
205 |
//row = getCadToolAdapter().getVectorialAdapter().getRow(selection.nextSetBit(0));
|
206 |
ig=((IFeature)row.getLinkedRow()).getGeometry().cloneGeometry(); |
207 |
handlers=ig.getHandlers(IGeometry.SELECTHANDLER); |
208 |
numHandlers=handlers.length; |
209 |
if (numHandlers ==0){ |
210 |
try {
|
211 |
vea.removeRow(row.getIndex(),getName()); |
212 |
} catch (IOException e) { |
213 |
// TODO Auto-generated catch block
|
214 |
e.printStackTrace(); |
215 |
} catch (DriverIOException e) {
|
216 |
// TODO Auto-generated catch block
|
217 |
e.printStackTrace(); |
218 |
} |
219 |
} |
220 |
} |
221 |
int dif=1;//En el caso de ser pol?gono. |
222 |
if (ig instanceof FGeometryCollection){ |
223 |
dif=2;
|
224 |
} |
225 |
if (status.equals("EditVertex.SelectVertexOrDelete")){ |
226 |
if(s.equals("s") || s.equals("S") || s.equals("Siguiente")){ |
227 |
numSelect=numSelect-dif; |
228 |
if (numSelect<0){ |
229 |
numSelect=numHandlers-1+(numSelect+1); |
230 |
} |
231 |
}else if(s.equals("a") || s.equals("A") || s.equals("Anterior")){ |
232 |
numSelect=numSelect+dif; |
233 |
if (numSelect>(numHandlers-1)){ |
234 |
numSelect=numSelect-(numHandlers); |
235 |
} |
236 |
|
237 |
}else if(s.equals("e") || s.equals("E") || s.equals(PluginServices.getText(this,"del"))){ |
238 |
if (handlers!=null){ |
239 |
IGeometry newGeometry=removeVertex(ig,handlers[numSelect]); |
240 |
numSelect=0;
|
241 |
|
242 |
IRow newRow=new DefaultFeature(newGeometry,row.getAttributes());
|
243 |
try {
|
244 |
vea.modifyRow(row.getIndex(),newRow,getName()); |
245 |
} catch (IOException e) { |
246 |
// TODO Auto-generated catch block
|
247 |
e.printStackTrace(); |
248 |
} catch (DriverIOException e) {
|
249 |
// TODO Auto-generated catch block
|
250 |
e.printStackTrace(); |
251 |
} |
252 |
getCadToolAdapter().getMapControl().drawMap(false);
|
253 |
} |
254 |
}else if(s.equals("i") || s.equals("I") || s.equals(PluginServices.getText(this,"add"))){ |
255 |
addVertex=true;
|
256 |
} |
257 |
} |
258 |
} |
259 |
private void drawVertex(Graphics g,AffineTransform at) throws DriverIOException{ |
260 |
ArrayList selectedRows=getSelectedRows();
|
261 |
for (int i = 0; i<selectedRows.size(); |
262 |
i++) { |
263 |
DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRows |
264 |
.get(i)).getLinkedRow(); |
265 |
IGeometry ig = fea.getGeometry().cloneGeometry(); |
266 |
if (ig == null) continue; |
267 |
Handler[] handlers=ig.getHandlers(IGeometry.SELECTHANDLER); |
268 |
if (numSelect>handlers.length)
|
269 |
numSelect=0;
|
270 |
FGraphicUtilities.DrawVertex((Graphics2D)g,at,handlers[numSelect]);
|
271 |
} |
272 |
} |
273 |
|
274 |
/* (non-Javadoc)
|
275 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
276 |
*/
|
277 |
public void addValue(double d) { |
278 |
} |
279 |
private IGeometry removeVertex(IGeometry gp,Handler handler) { |
280 |
GeneralPathX newGp = new GeneralPathX();
|
281 |
double[] theData = new double[6]; |
282 |
|
283 |
GeneralPathXIterator theIterator; |
284 |
int theType;
|
285 |
int numParts = 0; |
286 |
|
287 |
Point2D ptSrc = new Point2D.Double(); |
288 |
boolean bFirst = false; |
289 |
|
290 |
theIterator = gp.getGeneralPathXIterator(); //, flatness);
|
291 |
int numSegmentsAdded = 0; |
292 |
while (!theIterator.isDone()) {
|
293 |
theType = theIterator.currentSegment(theData); |
294 |
if (bFirst){
|
295 |
newGp.moveTo(theData[0], theData[1]); |
296 |
numSegmentsAdded++; |
297 |
bFirst=false;
|
298 |
continue;
|
299 |
} |
300 |
switch (theType) {
|
301 |
|
302 |
case PathIterator.SEG_MOVETO: |
303 |
numParts++; |
304 |
ptSrc.setLocation(theData[0], theData[1]); |
305 |
if (ptSrc.equals(handler.getPoint())){
|
306 |
numParts--; |
307 |
bFirst=true;
|
308 |
break;
|
309 |
} |
310 |
newGp.moveTo(ptSrc.getX(), ptSrc.getY()); |
311 |
numSegmentsAdded++; |
312 |
bFirst = false;
|
313 |
break;
|
314 |
|
315 |
case PathIterator.SEG_LINETO: |
316 |
ptSrc.setLocation(theData[0], theData[1]); |
317 |
if (ptSrc.equals(handler.getPoint())){
|
318 |
break;
|
319 |
} |
320 |
newGp.lineTo(ptSrc.getX(), ptSrc.getY()); |
321 |
bFirst = false;
|
322 |
numSegmentsAdded++; |
323 |
break;
|
324 |
|
325 |
case PathIterator.SEG_QUADTO: |
326 |
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
327 |
numSegmentsAdded++; |
328 |
break;
|
329 |
|
330 |
case PathIterator.SEG_CUBICTO: |
331 |
newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
332 |
numSegmentsAdded++; |
333 |
break;
|
334 |
|
335 |
case PathIterator.SEG_CLOSE: |
336 |
if (numSegmentsAdded < 3) |
337 |
newGp.lineTo(theData[0], theData[1]); |
338 |
newGp.closePath(); |
339 |
|
340 |
break;
|
341 |
} //end switch
|
342 |
|
343 |
theIterator.next(); |
344 |
} //end while loop
|
345 |
FShape shp = null;
|
346 |
switch (gp.getGeometryType())
|
347 |
{ |
348 |
case FShape.POINT: //Tipo punto |
349 |
case FShape.POINT + FShape.Z:
|
350 |
shp = new FPoint2D(ptSrc.getX(), ptSrc.getY());
|
351 |
break;
|
352 |
|
353 |
case FShape.LINE:
|
354 |
case FShape.LINE + FShape.Z:
|
355 |
shp = new FPolyline2D(newGp);
|
356 |
break;
|
357 |
case FShape.POLYGON:
|
358 |
case FShape.POLYGON + FShape.Z:
|
359 |
shp = new FPolygon2D(newGp);
|
360 |
break;
|
361 |
} |
362 |
return ShapeFactory.createGeometry(shp);
|
363 |
} |
364 |
private IGeometry addVertex(IGeometry geome,Point2D p,Rectangle2D rect) { |
365 |
IGeometry geometryCloned=geome.cloneGeometry(); |
366 |
IGeometry geom1=null;
|
367 |
GeneralPathX gpxAux; |
368 |
//FGeometry geom2=null;
|
369 |
|
370 |
//if (geometryCloned.getGeometryType() == FShape.POLYGON){
|
371 |
/////////////////
|
372 |
|
373 |
GeneralPathX newGp = new GeneralPathX();
|
374 |
double[] theData = new double[6]; |
375 |
|
376 |
GeneralPathXIterator theIterator; |
377 |
int theType;
|
378 |
int numParts = 0; |
379 |
Point2D pLast=new Point2D.Double(); |
380 |
Point2D pAnt = new Point2D.Double(); |
381 |
|
382 |
theIterator = geome.getGeneralPathXIterator(); //, flatness);
|
383 |
int numSegmentsAdded = 0; |
384 |
while (!theIterator.isDone()) {
|
385 |
theType = theIterator.currentSegment(theData); |
386 |
switch (theType) {
|
387 |
case PathIterator.SEG_MOVETO: |
388 |
numParts++; |
389 |
pLast.setLocation(theData[0], theData[1]); |
390 |
|
391 |
|
392 |
gpxAux=new GeneralPathX();
|
393 |
gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
394 |
gpxAux.lineTo(pLast.getX(),pLast.getY()); |
395 |
geom1=ShapeFactory.createPolyline2D(gpxAux); |
396 |
if (geom1.intersects(rect)){
|
397 |
newGp.moveTo(p.getX(), p.getY()); |
398 |
newGp.lineTo(pLast.getX(),pLast.getY()); |
399 |
}else{
|
400 |
newGp.moveTo(pLast.getX(), pLast.getY()); |
401 |
} |
402 |
|
403 |
|
404 |
pAnt.setLocation(pLast.getX(), pLast.getY()); |
405 |
numSegmentsAdded++; |
406 |
break;
|
407 |
|
408 |
case PathIterator.SEG_LINETO: |
409 |
pLast.setLocation(theData[0], theData[1]); |
410 |
|
411 |
gpxAux=new GeneralPathX();
|
412 |
gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
413 |
gpxAux.lineTo(pLast.getX(),pLast.getY()); |
414 |
geom1=ShapeFactory.createPolyline2D(gpxAux); |
415 |
if (geom1.intersects(rect)){
|
416 |
newGp.lineTo(p.getX(), p.getY()); |
417 |
newGp.lineTo(pLast.getX(),pLast.getY()); |
418 |
}else{
|
419 |
newGp.lineTo(pLast.getX(), pLast.getY()); |
420 |
} |
421 |
|
422 |
pAnt.setLocation(pLast.getX(), pLast.getY()); |
423 |
numSegmentsAdded++; |
424 |
break;
|
425 |
|
426 |
case PathIterator.SEG_QUADTO: |
427 |
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
428 |
numSegmentsAdded++; |
429 |
break;
|
430 |
|
431 |
case PathIterator.SEG_CUBICTO: |
432 |
newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
433 |
numSegmentsAdded++; |
434 |
break;
|
435 |
|
436 |
case PathIterator.SEG_CLOSE: |
437 |
if (numSegmentsAdded < 3){ |
438 |
newGp.lineTo(theData[0], theData[1]); |
439 |
} |
440 |
newGp.closePath(); |
441 |
|
442 |
break;
|
443 |
} //end switch
|
444 |
|
445 |
theIterator.next(); |
446 |
} //end while loop
|
447 |
FShape shp = null;
|
448 |
switch (geometryCloned.getGeometryType())
|
449 |
{ |
450 |
case FShape.POINT: //Tipo punto |
451 |
case FShape.POINT + FShape.Z:
|
452 |
shp = new FPoint2D(pLast.getX(), pLast.getY());
|
453 |
break;
|
454 |
|
455 |
case FShape.LINE:
|
456 |
case FShape.LINE + FShape.Z:
|
457 |
shp = new FPolyline2D(newGp);
|
458 |
break;
|
459 |
case FShape.POLYGON:
|
460 |
case FShape.POLYGON + FShape.Z:
|
461 |
shp = new FPolygon2D(newGp);
|
462 |
break;
|
463 |
} |
464 |
return ShapeFactory.createGeometry(shp);
|
465 |
|
466 |
|
467 |
/////////////////////
|
468 |
//}else if (geometryCloned.getGeometryType() == FShape.LINE){
|
469 |
|
470 |
//}
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
/* if (geometryCloned instanceof FGeometryCollection){
|
476 |
IGeometry[] geometries=((FGeometryCollection)geometryCloned).getGeometries();
|
477 |
boolean isSelected=false;
|
478 |
for (int i=0;i<geometries.length;i++){
|
479 |
if (geometries[i].intersects(rect) && !isSelected){
|
480 |
isSelected=true;
|
481 |
Handler[] handlers=geometries[i].getHandlers(IGeometry.SELECTHANDLER);
|
482 |
|
483 |
GeneralPathX gp1=new GeneralPathX();
|
484 |
Point2D pinit1=(Point2D)handlers[0].getPoint().clone();
|
485 |
gp1.moveTo(pinit1.getX(),pinit1.getY());
|
486 |
System.out.println("Handler inicial = "+pinit1);
|
487 |
gp1.lineTo(p.getX(),p.getY());
|
488 |
System.out.println("Handler medio = "+p);
|
489 |
FPolyline2D poly1=new FPolyline2D(gp1);
|
490 |
geom1=ShapeFactory.createGeometry(poly1);
|
491 |
|
492 |
GeneralPathX gp2=new GeneralPathX();
|
493 |
gp2.moveTo(p.getX(),p.getY());
|
494 |
System.out.println("Handler medio = "+p);
|
495 |
Point2D pEnd=(Point2D)handlers[1].getPoint().clone();
|
496 |
gp2.lineTo(pEnd.getX(),pEnd.getY());
|
497 |
System.out.println("Handler final = "+pEnd);
|
498 |
FPolyline2D poly2=new FPolyline2D(gp2);
|
499 |
geom2=ShapeFactory.createGeometry(poly2);
|
500 |
|
501 |
ArrayList geomsAux=new ArrayList();
|
502 |
geometries[i]=geom1;
|
503 |
for (int j=i;j<geometries.length;j++){
|
504 |
geomsAux.add(geometries[j]);
|
505 |
}
|
506 |
|
507 |
if (i<geometries.length-1){
|
508 |
geometries[i+1]=geom2;
|
509 |
Handler[] hands=((IGeometry)geom1).getHandlers(IGeometry.SELECTHANDLER);
|
510 |
for (int h=0;h<hands.length;h++)
|
511 |
System.out.println("Handlers New Geometry = "+hands[h].getPoint());
|
512 |
Handler[] hands2=((IGeometry)geom2).getHandlers(IGeometry.SELECTHANDLER);
|
513 |
for (int h=0;h<hands2.length;h++)
|
514 |
System.out.println("Handlers New Geometry = "+hands2[h].getPoint());
|
515 |
}else{
|
516 |
geometryCloned=new FGeometryCollection(geometries);
|
517 |
((FGeometryCollection)geometryCloned).addGeometry(geom2);
|
518 |
}
|
519 |
for (int j=i+1;j<geometries.length;j++){
|
520 |
if ((j-i)<geomsAux.size()-1){
|
521 |
geometries[j+1]=(IGeometry)geomsAux.get(j-i);
|
522 |
}else{
|
523 |
geometryCloned=new FGeometryCollection(geometries);
|
524 |
((FGeometryCollection)geometryCloned).addGeometry((IGeometry)geomsAux.get(j-i));
|
525 |
|
526 |
}
|
527 |
}
|
528 |
}
|
529 |
|
530 |
}
|
531 |
}
|
532 |
return geometryCloned;
|
533 |
*/
|
534 |
} |
535 |
public String getName() { |
536 |
return PluginServices.getText(this,"edit_vertex_"); |
537 |
} |
538 |
private void selectHandler(double x, double y) { |
539 |
Point2D firstPoint = new Point2D.Double(x, y); |
540 |
ArrayList selectedRows=getSelectedRows();
|
541 |
//FBitSet selection = getCadToolAdapter().getVectorialAdapter()
|
542 |
// .getSelection();
|
543 |
double tam = getCadToolAdapter().getMapControl().getViewPort()
|
544 |
.toMapDistance(SelectionCADTool.tolerance); |
545 |
Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() - tam, |
546 |
firstPoint.getY() - tam, tam * 2, tam * 2); |
547 |
if (selectedRows.size()>0){ |
548 |
boolean isSelectedHandler=false; |
549 |
IGeometry geometry=getSelectedGeometry(); |
550 |
Handler[] handlers=geometry.getHandlers(IGeometry.SELECTHANDLER); |
551 |
for (int h=0;h<handlers.length;h++){ |
552 |
if (handlers[h].getPoint().distance(firstPoint)<tam){
|
553 |
numSelect=h; |
554 |
isSelectedHandler=true;
|
555 |
} |
556 |
} |
557 |
|
558 |
if (!isSelectedHandler){
|
559 |
boolean isSelectedGeometry=false; |
560 |
try {
|
561 |
|
562 |
VectorialEditableAdapter vea = getCadToolAdapter() |
563 |
.getVectorialAdapter(); |
564 |
String strEPSG = getCadToolAdapter().getMapControl().getViewPort()
|
565 |
.getProjection().getAbrev().substring(5);
|
566 |
IRowEdited[] feats = vea.getFeatures(rect, strEPSG);
|
567 |
|
568 |
for (int i = 0; i < feats.length; i++) { |
569 |
if (geometry.intersects(rect)) { // , 0.1)){ |
570 |
isSelectedGeometry=true;
|
571 |
} |
572 |
} |
573 |
if (isSelectedGeometry && addVertex){
|
574 |
selectedRows=getSelectedRows(); |
575 |
//selection = getCadToolAdapter().getVectorialAdapter()
|
576 |
//.getSelection();
|
577 |
DefaultFeature fea=null;
|
578 |
DefaultRowEdited row=null;
|
579 |
row=(DefaultRowEdited) selectedRows.get(0);
|
580 |
fea = (DefaultFeature) row.getLinkedRow(); |
581 |
//fea = (DefaultFeature) getCadToolAdapter()
|
582 |
//.getVectorialAdapter().getRow(selection.nextSetBit(0)).getLinkedRow();
|
583 |
Point2D posVertex=new Point2D.Double(x,y); |
584 |
IGeometry geom=addVertex(fea.getGeometry(),posVertex,rect); |
585 |
|
586 |
getCadToolAdapter() |
587 |
.getVectorialAdapter().modifyRow(row.getIndex(),new DefaultFeature(geom,fea.getAttributes()),"Add vertice"); |
588 |
|
589 |
Handler[] newHandlers=geom.getHandlers(IGeometry.SELECTHANDLER); |
590 |
for (int h=0;h<newHandlers.length;h++){ |
591 |
if (newHandlers[h].getPoint().distance(posVertex)<tam){
|
592 |
numSelect=h; |
593 |
isSelectedHandler=true;
|
594 |
} |
595 |
} |
596 |
VectorialLayerEdited vle=getVLE(); |
597 |
vle.refreshSelectionCache(firstPoint,getCadToolAdapter()); |
598 |
//getCadToolAdapter().getMapControl().drawMap(false);
|
599 |
} |
600 |
} catch (DriverException e1) {
|
601 |
e1.printStackTrace(); |
602 |
} catch (IOException e) { |
603 |
// TODO Auto-generated catch block
|
604 |
e.printStackTrace(); |
605 |
} catch (DriverIOException e) {
|
606 |
// TODO Auto-generated catch block
|
607 |
e.printStackTrace(); |
608 |
} |
609 |
|
610 |
} |
611 |
} |
612 |
|
613 |
} |
614 |
|
615 |
|
616 |
} |