svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / com / iver / cit / gvsig / gui / cad / tools / EditVertexCADTool.java @ 27026
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.impl.BaseMultiPrimitive; |
64 |
import org.gvsig.fmap.geom.handler.Handler; |
65 |
import org.gvsig.fmap.geom.operation.DrawInts; |
66 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
67 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
68 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
69 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
70 |
import org.gvsig.fmap.geom.util.Converter; |
71 |
import org.gvsig.fmap.mapcontext.ViewPort; |
72 |
import org.gvsig.fmap.mapcontext.rendering.symbols.FGraphicUtilities; |
73 |
import org.gvsig.fmap.mapcontrol.MapControl; |
74 |
|
75 |
import com.iver.andami.PluginServices; |
76 |
import com.iver.andami.messages.NotificationManager; |
77 |
import com.iver.cit.gvsig.CADExtension; |
78 |
import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
79 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
80 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext; |
81 |
import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext.EditVertexCADToolState; |
82 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
83 |
|
84 |
|
85 |
/**
|
86 |
* DOCUMENT ME!
|
87 |
*
|
88 |
* @author Vicente Caballero Navarro
|
89 |
*/
|
90 |
public class EditVertexCADTool extends DefaultCADTool { |
91 |
protected EditVertexCADToolContext _fsm;
|
92 |
protected int numSelect=0; |
93 |
protected int numHandlers; |
94 |
protected boolean addVertex=false; |
95 |
|
96 |
/**
|
97 |
* Crea un nuevo PolylineCADTool.
|
98 |
*/
|
99 |
public EditVertexCADTool() {
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
104 |
* carga previa a la utilizaci?n de la herramienta.
|
105 |
*/
|
106 |
public void init() { |
107 |
_fsm = new EditVertexCADToolContext(this); |
108 |
} |
109 |
|
110 |
/* (non-Javadoc)
|
111 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
112 |
*/
|
113 |
public void transition(double x, double y, InputEvent event) { |
114 |
_fsm.addPoint(x, y, event); |
115 |
} |
116 |
|
117 |
/* (non-Javadoc)
|
118 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
119 |
*/
|
120 |
public void transition(double d) { |
121 |
_fsm.addValue(d); |
122 |
} |
123 |
|
124 |
/* (non-Javadoc)
|
125 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
126 |
*/
|
127 |
public void transition(String s) throws CommandException { |
128 |
if (!super.changeCommand(s)){ |
129 |
_fsm.addOption(s); |
130 |
} |
131 |
} |
132 |
|
133 |
/**
|
134 |
* DOCUMENT ME!
|
135 |
*/
|
136 |
public void selection() { |
137 |
FeatureSet selection=null;
|
138 |
try {
|
139 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
140 |
|
141 |
if (selection.getSize() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
142 |
CADExtension.setCADTool("_selection",false); |
143 |
((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
144 |
"_editvertex");
|
145 |
} |
146 |
} catch (ReadException e) {
|
147 |
// TODO Auto-generated catch block
|
148 |
e.printStackTrace(); |
149 |
} catch (DataException e) {
|
150 |
// TODO Auto-generated catch block
|
151 |
e.printStackTrace(); |
152 |
} |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Equivale al transition del prototipo pero sin pasarle como par?metro el
|
157 |
* editableFeatureSource que ya estar? creado.
|
158 |
*
|
159 |
* @param x par?metro x del punto que se pase en esta transici?n.
|
160 |
* @param y par?metro y del punto que se pase en esta transici?n.
|
161 |
*/
|
162 |
public void addPoint(double x, double y,InputEvent event) { |
163 |
selectHandler(x,y); |
164 |
addVertex=false;
|
165 |
} |
166 |
|
167 |
private Geometry getSelectedGeometry() {
|
168 |
FeatureSet selection=null;
|
169 |
try {
|
170 |
selection = (FeatureSet)getVLE().getFeatureStore().getSelection(); |
171 |
|
172 |
Feature feature=null;
|
173 |
Geometry ig=null;
|
174 |
if (selection.getSize()==1){ |
175 |
feature=(Feature)selection.iterator().next(); |
176 |
ig=((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
177 |
return ig;
|
178 |
} |
179 |
} catch (ReadException e) {
|
180 |
// TODO Auto-generated catch block
|
181 |
e.printStackTrace(); |
182 |
} catch (DataException e) {
|
183 |
// TODO Auto-generated catch block
|
184 |
e.printStackTrace(); |
185 |
} |
186 |
|
187 |
return null; |
188 |
} |
189 |
|
190 |
/**
|
191 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
192 |
* encontremos.
|
193 |
*
|
194 |
* @param g Graphics sobre el que dibujar.
|
195 |
* @param x par?metro x del punto que se pase para dibujar.
|
196 |
* @param y par?metro x del punto que se pase para dibujar.
|
197 |
*/
|
198 |
public void drawOperation(Graphics g, double x, double y) { |
199 |
drawVertex(g,getCadToolAdapter().getMapControl().getViewPort()); |
200 |
} |
201 |
|
202 |
/**
|
203 |
* Add a diferent option.
|
204 |
*
|
205 |
* @param s Diferent option.
|
206 |
*/
|
207 |
public void addOption(String s) { |
208 |
EditVertexCADToolState actualState = (EditVertexCADToolState) _fsm.getPreviousState(); |
209 |
String status = actualState.getName();
|
210 |
VectorialLayerEdited vle=getVLE(); |
211 |
FeatureStore featureStore=null;
|
212 |
try {
|
213 |
featureStore = vle.getFeatureStore(); |
214 |
|
215 |
FeatureSet selection=(FeatureSet)featureStore.getSelection(); |
216 |
Feature feature=null;
|
217 |
Geometry ig=null;
|
218 |
Handler[] handlers=null; |
219 |
if (selection.getSize()==1){ |
220 |
feature = (Feature)selection.iterator().next(); |
221 |
ig=((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
222 |
handlers=ig.getHandlers(Geometry.SELECTHANDLER); |
223 |
numHandlers=handlers.length; |
224 |
if (numHandlers ==0){ |
225 |
try {
|
226 |
featureStore.delete(feature); |
227 |
} catch (ReadException e) {
|
228 |
NotificationManager.addError(e.getMessage(),e); |
229 |
} catch (DataException e) {
|
230 |
NotificationManager.addError(e.getMessage(),e); |
231 |
} |
232 |
} |
233 |
}else{
|
234 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"hay_mas_de_una_geometria_seleccionada")); |
235 |
} |
236 |
|
237 |
int dif=1;//En el caso de ser pol?gono. |
238 |
if (ig instanceof BaseMultiPrimitive){ |
239 |
dif=2;
|
240 |
} |
241 |
|
242 |
if (status.equals("EditVertex.SelectVertexOrDelete")){ |
243 |
if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.nextvertex")) || s.equals(PluginServices.getText(this,"next"))){ |
244 |
numSelect=numSelect-dif; |
245 |
if (numSelect<0){ |
246 |
numSelect=numHandlers-1+(numSelect+1); |
247 |
} |
248 |
}else if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.previousvertex")) || s.equals(PluginServices.getText(this,"previous"))){ |
249 |
numSelect=numSelect+dif; |
250 |
if (numSelect>(numHandlers-1)){ |
251 |
numSelect=numSelect-(numHandlers); |
252 |
} |
253 |
|
254 |
}else if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.delvertex")) || s.equals(PluginServices.getText(this,"del"))){ |
255 |
if (handlers!=null){ |
256 |
Geometry newGeometry=null;
|
257 |
if (ig instanceof BaseMultiPrimitive) { |
258 |
newGeometry=removeVertexGC((BaseMultiPrimitive)ig,handlers[numSelect]); |
259 |
}else {
|
260 |
newGeometry=removeVertex(ig,handlers,numSelect); |
261 |
} |
262 |
try {
|
263 |
EditableFeature eFeature=feature.getEditable(); |
264 |
eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),ig); |
265 |
featureStore.update(eFeature); |
266 |
clearSelection(); |
267 |
} catch (ReadException e) {
|
268 |
NotificationManager.addError(e.getMessage(),e); |
269 |
} |
270 |
catch (DataException e) {
|
271 |
// TODO Auto-generated catch block
|
272 |
e.printStackTrace(); |
273 |
} |
274 |
} |
275 |
}else if(s.equalsIgnoreCase(PluginServices.getText(this,"EditVertexCADTool.addvertex")) || s.equals(PluginServices.getText(this,"add"))){ |
276 |
addVertex=true;
|
277 |
} |
278 |
} |
279 |
} catch (ReadException e1) {
|
280 |
// TODO Auto-generated catch block
|
281 |
e1.printStackTrace(); |
282 |
} catch (DataException e) {
|
283 |
// TODO Auto-generated catch block
|
284 |
e.printStackTrace(); |
285 |
} |
286 |
} |
287 |
private void drawVertex(Graphics g,ViewPort vp){ |
288 |
VectorialLayerEdited vle=getVLE(); |
289 |
Iterator iterator=null; |
290 |
try {
|
291 |
iterator = ((FeatureSelection)vle.getFeatureStore().getSelection()).iterator(); |
292 |
} catch (ReadException e1) {
|
293 |
// TODO Auto-generated catch block
|
294 |
e1.printStackTrace(); |
295 |
} catch (DataException e) {
|
296 |
// TODO Auto-generated catch block
|
297 |
e.printStackTrace(); |
298 |
} |
299 |
while (iterator.hasNext()) {
|
300 |
Feature feature = (Feature) iterator.next(); |
301 |
|
302 |
Geometry ig = ((Geometry)feature.getDefaultGeometry()).cloneGeometry(); |
303 |
if (ig == null) continue; |
304 |
DrawOperationContext doc=new DrawOperationContext();
|
305 |
doc.setGraphics((Graphics2D)g);
|
306 |
doc.setViewPort(vp); |
307 |
doc.setSymbol(DefaultCADTool.geometrySelectSymbol); |
308 |
try {
|
309 |
ig.invokeOperation(DrawInts.CODE,doc); |
310 |
} catch (GeometryOperationNotSupportedException e) {
|
311 |
e.printStackTrace(); |
312 |
} catch (GeometryOperationException e) {
|
313 |
e.printStackTrace(); |
314 |
} |
315 |
Handler[] handlers=ig.getHandlers(Geometry.SELECTHANDLER); |
316 |
if (numSelect>=handlers.length)
|
317 |
numSelect=0;
|
318 |
FGraphicUtilities.DrawVertex((Graphics2D)g,vp.getAffineTransform(),handlers[numSelect]);
|
319 |
} |
320 |
} |
321 |
|
322 |
/* (non-Javadoc)
|
323 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
324 |
*/
|
325 |
public void addValue(double d) { |
326 |
} |
327 |
private Geometry removeVertex(Geometry gp,Handler[] handlers,int numHandler) { |
328 |
GeneralPathX newGp = new GeneralPathX();
|
329 |
double[] theData = new double[6]; |
330 |
|
331 |
PathIterator theIterator;
|
332 |
int theType;
|
333 |
int numParts = 0; |
334 |
|
335 |
Point2D ptSrc = new Point2D.Double(); |
336 |
boolean bFirst = false; |
337 |
|
338 |
theIterator = gp.getPathIterator(null, Converter.FLATNESS);
|
339 |
int numSegmentsAdded = 0; |
340 |
while (!theIterator.isDone()) {
|
341 |
theType = theIterator.currentSegment(theData); |
342 |
if (bFirst){
|
343 |
newGp.moveTo(theData[0], theData[1]); |
344 |
numSegmentsAdded++; |
345 |
bFirst=false;
|
346 |
theIterator.next(); |
347 |
continue;
|
348 |
} |
349 |
switch (theType) {
|
350 |
|
351 |
case PathIterator.SEG_MOVETO: |
352 |
numParts++; |
353 |
ptSrc.setLocation(theData[0], theData[1]); |
354 |
if (ptSrc.equals(handlers[numHandler].getPoint())){
|
355 |
numParts--; |
356 |
bFirst=true;
|
357 |
break;
|
358 |
} |
359 |
newGp.moveTo(ptSrc.getX(), ptSrc.getY()); |
360 |
numSegmentsAdded++; |
361 |
bFirst = false;
|
362 |
break;
|
363 |
|
364 |
case PathIterator.SEG_LINETO: |
365 |
ptSrc.setLocation(theData[0], theData[1]); |
366 |
if (ptSrc.equals(handlers[numHandler].getPoint())){
|
367 |
break;
|
368 |
} |
369 |
newGp.lineTo(ptSrc.getX(), ptSrc.getY()); |
370 |
bFirst = false;
|
371 |
numSegmentsAdded++; |
372 |
break;
|
373 |
|
374 |
case PathIterator.SEG_QUADTO: |
375 |
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
376 |
numSegmentsAdded++; |
377 |
break;
|
378 |
|
379 |
case PathIterator.SEG_CUBICTO: |
380 |
newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
381 |
numSegmentsAdded++; |
382 |
break;
|
383 |
|
384 |
case PathIterator.SEG_CLOSE: |
385 |
if (numSegmentsAdded < 3) |
386 |
newGp.lineTo(theData[0], theData[1]); |
387 |
newGp.closePath(); |
388 |
|
389 |
break;
|
390 |
} //end switch
|
391 |
|
392 |
theIterator.next(); |
393 |
} //end while loop
|
394 |
Geometry shp = null;
|
395 |
switch (gp.getType())
|
396 |
{ |
397 |
case Geometry.TYPES.POINT: //Tipo punto |
398 |
shp = createPoint(ptSrc.getX(), ptSrc.getY()); |
399 |
break;
|
400 |
|
401 |
case Geometry.TYPES.CURVE:
|
402 |
shp = createCurve(newGp); |
403 |
break;
|
404 |
case Geometry.TYPES.SURFACE:
|
405 |
shp = createSurface(newGp); |
406 |
break;
|
407 |
} |
408 |
Geometry ig=shp; |
409 |
int dif=1;//En el caso de ser pol?gono. |
410 |
numSelect=numSelect-dif; |
411 |
if (numSelect<0){ |
412 |
numSelect=numHandlers-1+(numSelect+1); |
413 |
} |
414 |
return ig;
|
415 |
} |
416 |
|
417 |
private Geometry removeVertexGC(BaseMultiPrimitive gc,Handler handler) { |
418 |
Geometry[] geoms=gc.getGeometries();
|
419 |
ArrayList geomsAux=new ArrayList(); |
420 |
int pos=-1; |
421 |
for (int i=0;i<geoms.length;i++) { |
422 |
Handler[] handlers=geoms[i].getHandlers(Geometry.SELECTHANDLER); |
423 |
for (int j=0;j<handlers.length;j++) { |
424 |
if (handlers[j].equalsPoint(handler)) {
|
425 |
geomsAux.add(geoms[i]); |
426 |
if (pos==-1) |
427 |
pos=i; |
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,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 createMultiPrimitive((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 |
} |