root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / EditVertexCADTool.java @ 33205
History | View | Annotate | Download (25.8 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 org.gvsig.editing.gui.cad.tools; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.event.InputEvent; |
45 |
import java.awt.geom.PathIterator; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import javax.swing.JOptionPane; |
51 |
|
52 |
import org.gvsig.andami.PluginServices; |
53 |
import org.gvsig.andami.messages.NotificationManager; |
54 |
import org.gvsig.editing.CADExtension; |
55 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
56 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
57 |
import org.gvsig.editing.gui.cad.tools.smc.EditVertexCADToolContext; |
58 |
import org.gvsig.editing.gui.cad.tools.smc.EditVertexCADToolContext.EditVertexCADToolState; |
59 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
60 |
import org.gvsig.fmap.dal.exception.DataException; |
61 |
import org.gvsig.fmap.dal.exception.ReadException; |
62 |
import org.gvsig.tools.dispose.DisposableIterator; |
63 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
64 |
import org.gvsig.fmap.dal.feature.Feature; |
65 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
66 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
67 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
68 |
import org.gvsig.fmap.geom.Geometry; |
69 |
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive; |
70 |
import org.gvsig.fmap.geom.handler.Handler; |
71 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
72 |
import org.gvsig.fmap.mapcontext.ViewPort; |
73 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
74 |
import org.gvsig.tools.dispose.DisposeUtils; |
75 |
|
76 |
|
77 |
|
78 |
/**
|
79 |
* DOCUMENT ME!
|
80 |
*
|
81 |
* @author Vicente Caballero Navarro
|
82 |
*/
|
83 |
public class EditVertexCADTool extends DefaultCADTool { |
84 |
protected EditVertexCADToolContext _fsm;
|
85 |
protected int numSelect=0; |
86 |
protected int numHandlers; |
87 |
protected boolean addVertex=false; |
88 |
|
89 |
/**
|
90 |
* Crea un nuevo PolylineCADTool.
|
91 |
*/
|
92 |
public EditVertexCADTool() {
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
97 |
* carga previa a la utilizaci?n de la herramienta.
|
98 |
*/
|
99 |
public void init() { |
100 |
_fsm = new EditVertexCADToolContext(this); |
101 |
} |
102 |
|
103 |
/* (non-Javadoc)
|
104 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
105 |
*/
|
106 |
public void transition(double x, double y, InputEvent event) { |
107 |
_fsm.addPoint(x, y, event); |
108 |
} |
109 |
|
110 |
/* (non-Javadoc)
|
111 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
112 |
*/
|
113 |
public void transition(double d) { |
114 |
_fsm.addValue(d); |
115 |
} |
116 |
|
117 |
/* (non-Javadoc)
|
118 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
119 |
*/
|
120 |
public void transition(String s) throws CommandException { |
121 |
if (!super.changeCommand(s)){ |
122 |
_fsm.addOption(s); |
123 |
} |
124 |
} |
125 |
|
126 |
/**
|
127 |
* DOCUMENT ME!
|
128 |
*/
|
129 |
public void selection() { |
130 |
FeatureSet selection=null;
|
131 |
try {
|
132 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
133 |
|
134 |
if (selection.getSize() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
135 |
CADExtension.setCADTool("_selection",false); |
136 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
137 |
"_editvertex");
|
138 |
} |
139 |
} catch (ReadException e) {
|
140 |
// TODO Auto-generated catch block
|
141 |
e.printStackTrace(); |
142 |
} catch (DataException e) {
|
143 |
// TODO Auto-generated catch block
|
144 |
e.printStackTrace(); |
145 |
} |
146 |
} |
147 |
|
148 |
/**
|
149 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
150 |
* editableFeatureSource que ya estar? creado.
|
151 |
*
|
152 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
153 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
154 |
*/
|
155 |
public void addPoint(double x, double y,InputEvent event) { |
156 |
selectHandler(x,y); |
157 |
addVertex=false;
|
158 |
} |
159 |
|
160 |
private Geometry getSelectedGeometry() {
|
161 |
FeatureSet selection=null;
|
162 |
DisposableIterator iterator = null;
|
163 |
try {
|
164 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
165 |
|
166 |
Feature feature=null;
|
167 |
Geometry ig=null;
|
168 |
if (selection.getSize()==1){ |
169 |
iterator = selection.iterator(); |
170 |
feature = (Feature) iterator.next(); |
171 |
ig=(feature.getDefaultGeometry()).cloneGeometry(); |
172 |
return ig;
|
173 |
} |
174 |
} catch (ReadException e) {
|
175 |
// TODO Auto-generated catch block
|
176 |
e.printStackTrace(); |
177 |
} catch (DataException e) {
|
178 |
// TODO Auto-generated catch block
|
179 |
e.printStackTrace(); |
180 |
} finally {
|
181 |
DisposeUtils.dispose(iterator); |
182 |
} |
183 |
|
184 |
return null; |
185 |
} |
186 |
|
187 |
/**
|
188 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
189 |
* encontremos.
|
190 |
*
|
191 |
* @param g Graphics sobre el que dibujar.
|
192 |
* @param x par?metro x del punto que se pase para dibujar.
|
193 |
* @param y par?metro x del punto que se pase para dibujar.
|
194 |
*/
|
195 |
public void drawOperation(MapControlDrawer renderer, double x, double y) { |
196 |
drawVertex(renderer,getCadToolAdapter().getMapControl().getViewPort()); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Add a diferent option.
|
201 |
*
|
202 |
* @param s Diferent option.
|
203 |
*/
|
204 |
public void addOption(String s) { |
205 |
EditVertexCADToolState actualState = (EditVertexCADToolState) _fsm.getPreviousState(); |
206 |
String status = actualState.getName();
|
207 |
VectorialLayerEdited vle=getVLE(); |
208 |
FeatureStore featureStore=null;
|
209 |
DisposableIterator iterator = null;
|
210 |
try {
|
211 |
featureStore = vle.getFeatureStore(); |
212 |
|
213 |
FeatureSet selection=(FeatureSet)featureStore.getSelection(); |
214 |
Feature feature=null;
|
215 |
Geometry ig=null;
|
216 |
Handler[] handlers=null; |
217 |
if (selection.getSize()==1){ |
218 |
iterator = selection.iterator(); |
219 |
feature = (Feature) iterator.next(); |
220 |
ig=(feature.getDefaultGeometry()).cloneGeometry(); |
221 |
handlers=ig.getHandlers(Geometry.SELECTHANDLER); |
222 |
numHandlers=handlers.length; |
223 |
if (numHandlers ==0){ |
224 |
try {
|
225 |
featureStore.delete(feature); |
226 |
} catch (ReadException e) {
|
227 |
NotificationManager.addError(e.getMessage(),e); |
228 |
} catch (DataException e) {
|
229 |
NotificationManager.addError(e.getMessage(),e); |
230 |
} |
231 |
} |
232 |
}else{
|
233 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"hay_mas_de_una_geometria_seleccionada")); |
234 |
} |
235 |
|
236 |
int dif=1;//En el caso de ser pol?gono. |
237 |
if (ig instanceof BaseMultiPrimitive){ |
238 |
dif=2;
|
239 |
} |
240 |
|
241 |
if (status.equals("EditVertex.SelectVertexOrDelete")){ |
242 |
if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.nextvertex")) || s.equals(PluginServices.getText(this,"next"))){ |
243 |
numSelect=numSelect-dif; |
244 |
if (numSelect<0){ |
245 |
numSelect=numHandlers-1+(numSelect+1); |
246 |
} |
247 |
}else if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.previousvertex")) || s.equals(PluginServices.getText(this,"previous"))){ |
248 |
numSelect=numSelect+dif; |
249 |
if (numSelect>(numHandlers-1)){ |
250 |
numSelect=numSelect-(numHandlers); |
251 |
} |
252 |
|
253 |
}else if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.delvertex")) || s.equals(PluginServices.getText(this,"del"))){ |
254 |
if (handlers!=null){ |
255 |
Geometry newGeometry=null;
|
256 |
if (ig instanceof BaseMultiPrimitive) { |
257 |
newGeometry=removeVertexGC((BaseMultiPrimitive)ig,handlers[numSelect]); |
258 |
}else {
|
259 |
newGeometry=removeVertex(ig,handlers,numSelect); |
260 |
} |
261 |
try {
|
262 |
EditableFeature eFeature=feature.getEditable(); |
263 |
eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),newGeometry); |
264 |
featureStore.update(eFeature); |
265 |
|
266 |
} catch (ReadException e) {
|
267 |
NotificationManager.addError(e.getMessage(),e); |
268 |
} |
269 |
catch (DataException e) {
|
270 |
// TODO Auto-generated catch block
|
271 |
e.printStackTrace(); |
272 |
} |
273 |
} |
274 |
}else if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.addvertex")) || s.equals(PluginServices.getText(this,"add"))){ |
275 |
addVertex=true;
|
276 |
} |
277 |
} |
278 |
} catch (ReadException e1) {
|
279 |
// TODO Auto-generated catch block
|
280 |
e1.printStackTrace(); |
281 |
} catch (DataException e) {
|
282 |
// TODO Auto-generated catch block
|
283 |
e.printStackTrace(); |
284 |
} finally {
|
285 |
if (iterator != null) { |
286 |
iterator.dispose(); |
287 |
} |
288 |
} |
289 |
} |
290 |
private void drawVertex(MapControlDrawer renderer,ViewPort vp){ |
291 |
VectorialLayerEdited vle=getVLE(); |
292 |
DisposableIterator iterator = null;
|
293 |
try {
|
294 |
iterator = ((FeatureSelection) vle.getFeatureStore().getSelection()) |
295 |
.iterator(); |
296 |
while (iterator.hasNext()) {
|
297 |
Feature feature = (Feature) iterator.next(); |
298 |
|
299 |
Geometry ig = (feature.getDefaultGeometry()).cloneGeometry(); |
300 |
renderer.draw(ig, mapControlManager.getGeometrySelectionSymbol()); |
301 |
|
302 |
Handler[] handlers = ig.getHandlers(Geometry.SELECTHANDLER); |
303 |
if (numSelect >= handlers.length) {
|
304 |
numSelect = 0;
|
305 |
} |
306 |
if (handlers.length==0) |
307 |
continue;
|
308 |
renderer.drawHandler(handlers[numSelect], vp.getAffineTransform()); |
309 |
} |
310 |
} catch (DataException e) {
|
311 |
// TODO Auto-generated catch block
|
312 |
e.printStackTrace(); |
313 |
} finally {
|
314 |
if (iterator != null) { |
315 |
iterator.dispose(); |
316 |
} |
317 |
} |
318 |
} |
319 |
|
320 |
/* (non-Javadoc)
|
321 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
322 |
*/
|
323 |
public void addValue(double d) { |
324 |
} |
325 |
private Geometry removeVertex(Geometry gp,Handler[] handlers,int numHandler) { |
326 |
GeneralPathX newGp = new GeneralPathX();
|
327 |
double[] theData = new double[6]; |
328 |
|
329 |
PathIterator theIterator;
|
330 |
int theType;
|
331 |
int numParts = 0; |
332 |
|
333 |
Point2D ptSrc = new Point2D.Double(); |
334 |
boolean bFirst = false; |
335 |
|
336 |
theIterator = gp.getPathIterator(null, geomManager.getFlatness());
|
337 |
int numSegmentsAdded = 0; |
338 |
while (!theIterator.isDone()) {
|
339 |
theType = theIterator.currentSegment(theData); |
340 |
if (bFirst){
|
341 |
newGp.moveTo(theData[0], theData[1]); |
342 |
numSegmentsAdded++; |
343 |
bFirst=false;
|
344 |
theIterator.next(); |
345 |
continue;
|
346 |
} |
347 |
switch (theType) {
|
348 |
|
349 |
case PathIterator.SEG_MOVETO: |
350 |
numParts++; |
351 |
ptSrc.setLocation(theData[0], theData[1]); |
352 |
if (ptSrc.equals(handlers[numHandler].getPoint())){
|
353 |
numParts--; |
354 |
bFirst=true;
|
355 |
break;
|
356 |
} |
357 |
newGp.moveTo(ptSrc.getX(), ptSrc.getY()); |
358 |
numSegmentsAdded++; |
359 |
bFirst = false;
|
360 |
break;
|
361 |
|
362 |
case PathIterator.SEG_LINETO: |
363 |
ptSrc.setLocation(theData[0], theData[1]); |
364 |
if (ptSrc.equals(handlers[numHandler].getPoint())){
|
365 |
break;
|
366 |
} |
367 |
newGp.lineTo(ptSrc.getX(), ptSrc.getY()); |
368 |
bFirst = false;
|
369 |
numSegmentsAdded++; |
370 |
break;
|
371 |
|
372 |
case PathIterator.SEG_QUADTO: |
373 |
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
374 |
numSegmentsAdded++; |
375 |
break;
|
376 |
|
377 |
case PathIterator.SEG_CUBICTO: |
378 |
newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
379 |
numSegmentsAdded++; |
380 |
break;
|
381 |
|
382 |
case PathIterator.SEG_CLOSE: |
383 |
if (numSegmentsAdded < 3) { |
384 |
newGp.lineTo(theData[0], theData[1]); |
385 |
} |
386 |
newGp.closePath(); |
387 |
|
388 |
break;
|
389 |
} //end switch
|
390 |
|
391 |
theIterator.next(); |
392 |
} //end while loop
|
393 |
Geometry shp = null;
|
394 |
switch (gp.getType())
|
395 |
{ |
396 |
case Geometry.TYPES.POINT: //Tipo punto |
397 |
shp = createPoint(ptSrc.getX(), ptSrc.getY()); |
398 |
break;
|
399 |
|
400 |
case Geometry.TYPES.CURVE:
|
401 |
shp = createCurve(newGp); |
402 |
break;
|
403 |
case Geometry.TYPES.SURFACE:
|
404 |
shp = createSurface(newGp); |
405 |
break;
|
406 |
} |
407 |
Geometry ig=shp; |
408 |
int dif=1;//En el caso de ser pol?gono. |
409 |
numSelect=numSelect-dif; |
410 |
if (numSelect<0){ |
411 |
numSelect=numHandlers-1+(numSelect+1); |
412 |
} |
413 |
return ig;
|
414 |
} |
415 |
|
416 |
private Geometry removeVertexGC(BaseMultiPrimitive gc,Handler handler) { |
417 |
Geometry[] geoms=gc.getGeometries();
|
418 |
ArrayList geomsAux=new ArrayList(); |
419 |
int pos=-1; |
420 |
for (int i=0;i<geoms.length;i++) { |
421 |
Handler[] handlers=geoms[i].getHandlers(Geometry.SELECTHANDLER); |
422 |
for (int j=0;j<handlers.length;j++) { |
423 |
if (handlers[j].equalsPoint(handler)) {
|
424 |
geomsAux.add(geoms[i]); |
425 |
if (pos==-1) { |
426 |
pos=i; |
427 |
} |
428 |
} |
429 |
} |
430 |
} |
431 |
int numGeomsAux=geomsAux.size();
|
432 |
GeneralPathX gpx=new GeneralPathX();
|
433 |
for (int i=0;i<numGeomsAux;i++) { |
434 |
Handler[] handlers=((Geometry)geomsAux.get(i)).getHandlers(Geometry.SELECTHANDLER); |
435 |
if (numGeomsAux == 2) { |
436 |
for (int j = 0; j < handlers.length; j++) { |
437 |
if (handlers[j].equalsPoint(handler)) {
|
438 |
if (j == (handlers.length - 1)) { |
439 |
Point2D ph = handlers[0].getPoint(); |
440 |
gpx.moveTo(ph.getX(), ph.getY()); |
441 |
} else {
|
442 |
Point2D ph = handlers[handlers.length - 1] |
443 |
.getPoint(); |
444 |
gpx.lineTo(ph.getX(), ph.getY()); |
445 |
} |
446 |
} |
447 |
} |
448 |
} |
449 |
|
450 |
} |
451 |
ArrayList newGeoms=new ArrayList(); |
452 |
for (int i=0;i<pos;i++) { |
453 |
newGeoms.add(geoms[i]); |
454 |
} |
455 |
newGeoms.add(createCurve(gpx)); |
456 |
for (int i=pos+numGeomsAux;i<geoms.length;i++) { |
457 |
newGeoms.add(geoms[i]); |
458 |
} |
459 |
|
460 |
|
461 |
return createMultiPrimitive((Geometry[])newGeoms.toArray(new Geometry[0])); |
462 |
} |
463 |
|
464 |
|
465 |
|
466 |
private Geometry addVertex(Geometry geome,Point2D p,Rectangle2D rect) { |
467 |
Geometry geometryCloned=geome.cloneGeometry(); |
468 |
Geometry geom1=null;
|
469 |
GeneralPathX gpxAux; |
470 |
boolean finish=false; |
471 |
//FGeometry geom2=null;
|
472 |
|
473 |
//if (geometryCloned.getGeometryType() == FShape.POLYGON){
|
474 |
/////////////////
|
475 |
|
476 |
GeneralPathX newGp = new GeneralPathX();
|
477 |
double[] theData = new double[6]; |
478 |
|
479 |
PathIterator theIterator;
|
480 |
int theType;
|
481 |
int numParts = 0; |
482 |
Point2D pLast=new Point2D.Double(); |
483 |
Point2D pAnt = new Point2D.Double(); |
484 |
Point2D firstPoint=null; |
485 |
theIterator = geome.getPathIterator(null, geomManager.getFlatness()); //, flatness); |
486 |
int numSegmentsAdded = 0; |
487 |
while (!theIterator.isDone()) {
|
488 |
theType = theIterator.currentSegment(theData); |
489 |
switch (theType) {
|
490 |
case PathIterator.SEG_MOVETO: |
491 |
pLast.setLocation(theData[0], theData[1]); |
492 |
if (numParts==0) { |
493 |
firstPoint=(Point2D)pLast.clone();
|
494 |
} |
495 |
numParts++; |
496 |
|
497 |
gpxAux=new GeneralPathX();
|
498 |
gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
499 |
gpxAux.lineTo(pLast.getX(),pLast.getY()); |
500 |
geom1=createCurve(gpxAux); |
501 |
if (geom1.intersects(rect)){
|
502 |
finish=true;
|
503 |
newGp.moveTo(pLast.getX(), pLast.getY()); |
504 |
//newGp.lineTo(pLast.getX(),pLast.getY());
|
505 |
}else{
|
506 |
newGp.moveTo(pLast.getX(), pLast.getY()); |
507 |
} |
508 |
pAnt.setLocation(pLast.getX(), pLast.getY()); |
509 |
numSegmentsAdded++; |
510 |
break;
|
511 |
|
512 |
case PathIterator.SEG_LINETO: |
513 |
pLast.setLocation(theData[0], theData[1]); |
514 |
gpxAux=new GeneralPathX();
|
515 |
gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
516 |
gpxAux.lineTo(pLast.getX(),pLast.getY()); |
517 |
geom1=createCurve(gpxAux); |
518 |
if (geom1.intersects(rect)){
|
519 |
newGp.lineTo(p.getX(), p.getY()); |
520 |
newGp.lineTo(pLast.getX(),pLast.getY()); |
521 |
}else{
|
522 |
newGp.lineTo(pLast.getX(), pLast.getY()); |
523 |
} |
524 |
pAnt.setLocation(pLast.getX(), pLast.getY()); |
525 |
numSegmentsAdded++; |
526 |
break;
|
527 |
|
528 |
case PathIterator.SEG_QUADTO: |
529 |
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
530 |
numSegmentsAdded++; |
531 |
break;
|
532 |
|
533 |
case PathIterator.SEG_CUBICTO: |
534 |
newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
535 |
numSegmentsAdded++; |
536 |
break;
|
537 |
|
538 |
case PathIterator.SEG_CLOSE: |
539 |
//if (numSegmentsAdded < 3){
|
540 |
gpxAux=new GeneralPathX();
|
541 |
gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
542 |
gpxAux.lineTo(firstPoint.getX(),firstPoint.getY()); |
543 |
geom1=createCurve(gpxAux); |
544 |
if (geom1.intersects(rect)|| finish){
|
545 |
newGp.lineTo(p.getX(), p.getY()); |
546 |
newGp.lineTo(pLast.getX(),pLast.getY()); |
547 |
}else{
|
548 |
newGp.lineTo(pLast.getX(), pLast.getY()); |
549 |
} |
550 |
//}
|
551 |
newGp.closePath(); |
552 |
break;
|
553 |
} //end switch
|
554 |
|
555 |
theIterator.next(); |
556 |
} //end while loop
|
557 |
Geometry shp = null;
|
558 |
switch (geometryCloned.getType())
|
559 |
{ |
560 |
case Geometry.TYPES.POINT: //Tipo punto |
561 |
shp = createPoint(pLast.getX(), pLast.getY()); |
562 |
break;
|
563 |
|
564 |
case Geometry.TYPES.CURVE:
|
565 |
shp = createCurve(newGp); |
566 |
break;
|
567 |
case Geometry.TYPES.SURFACE:
|
568 |
case Geometry.TYPES.CIRCLE:
|
569 |
case Geometry.TYPES.ELLIPSE:
|
570 |
shp = createSurface(newGp); |
571 |
break;
|
572 |
} |
573 |
return shp;
|
574 |
|
575 |
|
576 |
/////////////////////
|
577 |
//}else if (geometryCloned.getGeometryType() == FShape.LINE){
|
578 |
|
579 |
//}
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
/* if (geometryCloned instanceof FGeometryCollection){
|
585 |
IGeometry[] geometries=((FGeometryCollection)geometryCloned).getGeometries();
|
586 |
boolean isSelected=false;
|
587 |
for (int i=0;i<geometries.length;i++){
|
588 |
if (geometries[i].intersects(rect) && !isSelected){
|
589 |
isSelected=true;
|
590 |
Handler[] handlers=geometries[i].getHandlers(IGeometry.SELECTHANDLER);
|
591 |
|
592 |
GeneralPathX gp1=new GeneralPathX();
|
593 |
Point2D pinit1=(Point2D)handlers[0].getPoint().clone();
|
594 |
gp1.moveTo(pinit1.getX(),pinit1.getY());
|
595 |
System.out.println("Handler inicial = "+pinit1);
|
596 |
gp1.lineTo(p.getX(),p.getY());
|
597 |
System.out.println("Handler medio = "+p);
|
598 |
FPolyline2D poly1=new FPolyline2D(gp1);
|
599 |
geom1=ShapeFactory.createGeometry(poly1);
|
600 |
|
601 |
GeneralPathX gp2=new GeneralPathX();
|
602 |
gp2.moveTo(p.getX(),p.getY());
|
603 |
System.out.println("Handler medio = "+p);
|
604 |
Point2D pEnd=(Point2D)handlers[1].getPoint().clone();
|
605 |
gp2.lineTo(pEnd.getX(),pEnd.getY());
|
606 |
System.out.println("Handler final = "+pEnd);
|
607 |
FPolyline2D poly2=new FPolyline2D(gp2);
|
608 |
geom2=ShapeFactory.createGeometry(poly2);
|
609 |
|
610 |
ArrayList geomsAux=new ArrayList();
|
611 |
geometries[i]=geom1;
|
612 |
for (int j=i;j<geometries.length;j++){
|
613 |
geomsAux.add(geometries[j]);
|
614 |
}
|
615 |
|
616 |
if (i<geometries.length-1){
|
617 |
geometries[i+1]=geom2;
|
618 |
Handler[] hands=((IGeometry)geom1).getHandlers(IGeometry.SELECTHANDLER);
|
619 |
for (int h=0;h<hands.length;h++)
|
620 |
System.out.println("Handlers New Geometry = "+hands[h].getPoint());
|
621 |
Handler[] hands2=((IGeometry)geom2).getHandlers(IGeometry.SELECTHANDLER);
|
622 |
for (int h=0;h<hands2.length;h++)
|
623 |
System.out.println("Handlers New Geometry = "+hands2[h].getPoint());
|
624 |
}else{
|
625 |
geometryCloned=new FGeometryCollection(geometries);
|
626 |
((FGeometryCollection)geometryCloned).addGeometry(geom2);
|
627 |
}
|
628 |
for (int j=i+1;j<geometries.length;j++){
|
629 |
if ((j-i)<geomsAux.size()-1){
|
630 |
geometries[j+1]=(IGeometry)geomsAux.get(j-i);
|
631 |
}else{
|
632 |
geometryCloned=new FGeometryCollection(geometries);
|
633 |
((FGeometryCollection)geometryCloned).addGeometry((IGeometry)geomsAux.get(j-i));
|
634 |
|
635 |
}
|
636 |
}
|
637 |
}
|
638 |
|
639 |
}
|
640 |
}
|
641 |
return geometryCloned;
|
642 |
*/
|
643 |
} |
644 |
private Geometry addVertexGC(BaseMultiPrimitive gc,Point2D p,Rectangle2D rect) { |
645 |
Geometry[] geoms=gc.getGeometries();
|
646 |
int pos=-1; |
647 |
for (int i=0;i<geoms.length;i++) { |
648 |
if (geoms[i].intersects(rect)) {
|
649 |
pos=i; |
650 |
} |
651 |
} |
652 |
ArrayList newGeoms=new ArrayList(); |
653 |
for (int i=0;i<pos;i++) { |
654 |
newGeoms.add(geoms[i]); |
655 |
} |
656 |
if (pos!=-1) { |
657 |
GeneralPathX gpx1=new GeneralPathX();
|
658 |
GeneralPathX gpx2=new GeneralPathX();
|
659 |
Handler[] handlers=geoms[pos].getHandlers(Geometry.SELECTHANDLER); |
660 |
Point2D p1=handlers[0].getPoint(); |
661 |
Point2D p2=p;
|
662 |
Point2D p3=handlers[handlers.length-1].getPoint(); |
663 |
gpx1.moveTo(p1.getX(),p1.getY()); |
664 |
gpx1.lineTo(p2.getX(),p2.getY()); |
665 |
gpx2.moveTo(p2.getX(),p2.getY()); |
666 |
gpx2.lineTo(p3.getX(),p3.getY()); |
667 |
newGeoms.add(createCurve(gpx1)); |
668 |
newGeoms.add(createCurve(gpx2)); |
669 |
for (int i=pos+1;i<geoms.length;i++) { |
670 |
newGeoms.add(geoms[i]); |
671 |
} |
672 |
return createMultiPrimitive((Geometry[])newGeoms.toArray(new Geometry[0])); |
673 |
}else {
|
674 |
return null; |
675 |
} |
676 |
} |
677 |
public String getName() { |
678 |
return PluginServices.getText(this,"edit_vertex_"); |
679 |
} |
680 |
private void selectHandler(double x, double y) { |
681 |
Point2D firstPoint = new Point2D.Double(x, y); |
682 |
VectorialLayerEdited vle = getVLE(); |
683 |
FeatureStore featureStore=null;
|
684 |
DisposableIterator iterator = null;
|
685 |
DisposableIterator selectedIterator = null;
|
686 |
|
687 |
try {
|
688 |
featureStore = vle.getFeatureStore(); |
689 |
|
690 |
iterator = ((FeatureSelection) featureStore.getSelection()) |
691 |
.iterator(); |
692 |
double tam = getCadToolAdapter().getMapControl().getViewPort()
|
693 |
.toMapDistance(mapControlManager.getTolerance()); |
694 |
Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() - tam, |
695 |
firstPoint.getY() - tam, tam * 2, tam * 2); |
696 |
while (iterator.hasNext()) {
|
697 |
Feature feature = (Feature) iterator.next(); |
698 |
|
699 |
boolean isSelectedHandler = false; |
700 |
Geometry geometry = getSelectedGeometry(); |
701 |
if (geometry != null) { |
702 |
Handler[] handlers = geometry |
703 |
.getHandlers(Geometry.SELECTHANDLER); |
704 |
for (int h = 0; h < handlers.length; h++) { |
705 |
if (handlers[h].getPoint().distance(firstPoint) < tam) {
|
706 |
numSelect = h; |
707 |
isSelectedHandler = true;
|
708 |
} |
709 |
} |
710 |
|
711 |
if (!isSelectedHandler) {
|
712 |
boolean isSelectedGeometry = false; |
713 |
if (geometry.intersects(rect)) { // , 0.1)){ |
714 |
isSelectedGeometry = true;
|
715 |
} |
716 |
if (isSelectedGeometry && addVertex) {
|
717 |
try {
|
718 |
selectedIterator = |
719 |
featureStore.getFeatureSelection() |
720 |
.iterator(); |
721 |
Feature feat = (Feature) selectedIterator.next(); |
722 |
Point2D posVertex = new Point2D.Double(x, y); |
723 |
Geometry geom1 = (feat.getDefaultGeometry()) |
724 |
.cloneGeometry(); |
725 |
Geometry geom = null;
|
726 |
if (geom1 instanceof BaseMultiPrimitive) { |
727 |
geom = addVertexGC((BaseMultiPrimitive) geom1, |
728 |
posVertex, rect); |
729 |
} else {
|
730 |
geom = addVertex(geom1, posVertex, rect); |
731 |
} |
732 |
if (geom != null) { |
733 |
EditableFeature eFeature = feature |
734 |
.getEditable(); |
735 |
eFeature.setGeometry(featureStore |
736 |
.getDefaultFeatureType() |
737 |
.getDefaultGeometryAttributeName(), |
738 |
geom); |
739 |
featureStore.update(eFeature); |
740 |
Handler[] newHandlers = geom |
741 |
.getHandlers(Geometry.SELECTHANDLER); |
742 |
for (int h = 0; h < newHandlers.length; h++) { |
743 |
if (newHandlers[h].getPoint().distance(
|
744 |
posVertex) < tam) { |
745 |
numSelect = h; |
746 |
isSelectedHandler = true;
|
747 |
} |
748 |
} |
749 |
|
750 |
// clearSelection();
|
751 |
} |
752 |
} finally {
|
753 |
if (selectedIterator != null) { |
754 |
selectedIterator.dispose(); |
755 |
} |
756 |
} |
757 |
} |
758 |
} |
759 |
} |
760 |
} |
761 |
|
762 |
} catch (DataException e) {
|
763 |
e.printStackTrace(); |
764 |
} finally {
|
765 |
if (iterator != null) { |
766 |
iterator.dispose(); |
767 |
} |
768 |
} |
769 |
|
770 |
} |
771 |
|
772 |
public String toString() { |
773 |
return "_editvertex"; |
774 |
} |
775 |
|
776 |
public boolean isApplicable(int shapeType) { |
777 |
switch (shapeType) {
|
778 |
case Geometry.TYPES.POINT:
|
779 |
case Geometry.TYPES.MULTIPOINT:
|
780 |
return false; |
781 |
} |
782 |
return true; |
783 |
} |
784 |
|
785 |
|
786 |
} |