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