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