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