svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / EditVertexCADTool.java @ 5923
History | View | Annotate | Download (24.9 KB)
1 | 4118 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.gui.cad.tools; |
||
42 | |||
43 | import java.awt.Graphics; |
||
44 | import java.awt.Graphics2D; |
||
45 | 4313 | fjp | import java.awt.event.InputEvent; |
46 | 4118 | caballero | import java.awt.geom.AffineTransform; |
47 | import java.awt.geom.PathIterator; |
||
48 | import java.awt.geom.Point2D; |
||
49 | 4365 | caballero | import java.awt.geom.Rectangle2D; |
50 | 4118 | caballero | import java.io.IOException; |
51 | 4584 | caballero | import java.util.ArrayList; |
52 | 4118 | caballero | |
53 | 4584 | caballero | import com.iver.andami.PluginServices; |
54 | 4118 | caballero | import com.iver.cit.gvsig.CADExtension; |
55 | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
||
56 | import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
||
57 | import com.iver.cit.gvsig.fmap.core.FPoint2D; |
||
58 | import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
||
59 | import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
||
60 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
61 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
62 | import com.iver.cit.gvsig.fmap.core.Handler; |
||
63 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
64 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
65 | import com.iver.cit.gvsig.fmap.core.IRow; |
||
66 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
67 | import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
||
68 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
69 | 4584 | caballero | import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
70 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
71 | 4118 | caballero | import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
72 | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
||
73 | import com.iver.cit.gvsig.gui.cad.DefaultCADTool; |
||
74 | 5735 | caballero | import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
75 | 4118 | caballero | import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext; |
76 | import com.iver.cit.gvsig.gui.cad.tools.smc.EditVertexCADToolContext.EditVertexCADToolState; |
||
77 | 4365 | caballero | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
78 | 4118 | caballero | |
79 | |||
80 | /**
|
||
81 | * DOCUMENT ME!
|
||
82 | *
|
||
83 | * @author Vicente Caballero Navarro
|
||
84 | */
|
||
85 | public class EditVertexCADTool extends DefaultCADTool { |
||
86 | private EditVertexCADToolContext _fsm;
|
||
87 | private int numSelect=0; |
||
88 | private int numHandlers; |
||
89 | 4365 | caballero | private boolean addVertex=false; |
90 | 4118 | caballero | /**
|
91 | * Crea un nuevo PolylineCADTool.
|
||
92 | */
|
||
93 | public EditVertexCADTool() {
|
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
|
||
98 | * carga previa a la utilizaci?n de la herramienta.
|
||
99 | */
|
||
100 | public void init() { |
||
101 | _fsm = new EditVertexCADToolContext(this); |
||
102 | } |
||
103 | |||
104 | /* (non-Javadoc)
|
||
105 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
|
||
106 | */
|
||
107 | 4313 | fjp | public void transition(double x, double y, InputEvent event) { |
108 | 4365 | caballero | addPoint(x, y, event); |
109 | 4118 | caballero | } |
110 | |||
111 | /* (non-Javadoc)
|
||
112 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
|
||
113 | */
|
||
114 | public void transition(double d) { |
||
115 | 5735 | caballero | _fsm.addValue(d); |
116 | 4118 | caballero | } |
117 | |||
118 | /* (non-Javadoc)
|
||
119 | * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
|
||
120 | */
|
||
121 | 5735 | caballero | public void transition(String s) throws CommandException { |
122 | 4892 | caballero | if (!super.changeCommand(s)){ |
123 | _fsm.addOption(s); |
||
124 | } |
||
125 | 4118 | caballero | } |
126 | |||
127 | /**
|
||
128 | * DOCUMENT ME!
|
||
129 | */
|
||
130 | public void selection() { |
||
131 | 4584 | caballero | ArrayList selectedRow=getSelectedRows();
|
132 | if (selectedRow.size() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) { |
||
133 | 5071 | caballero | CADExtension.setCADTool("_selection",false); |
134 | 4584 | caballero | ((SelectionCADTool) CADExtension.getCADTool()).setNextTool( |
135 | 5071 | caballero | "_editvertex");
|
136 | 4118 | caballero | } |
137 | } |
||
138 | |||
139 | /**
|
||
140 | * Equivale al transition del prototipo pero sin pasarle como par?metro el
|
||
141 | * editableFeatureSource que ya estar? creado.
|
||
142 | *
|
||
143 | * @param x par?metro x del punto que se pase en esta transici?n.
|
||
144 | * @param y par?metro y del punto que se pase en esta transici?n.
|
||
145 | */
|
||
146 | 4365 | caballero | public void addPoint(double x, double y,InputEvent event) { |
147 | selectHandler(x,y); |
||
148 | addVertex=false;
|
||
149 | 4118 | caballero | } |
150 | |||
151 | 4313 | fjp | private IGeometry getSelectedGeometry() {
|
152 | 4584 | caballero | ArrayList selectedRows=getSelectedRows();
|
153 | // VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
|
||
154 | // FBitSet selection = vea.getSelection();
|
||
155 | 4313 | fjp | IRowEdited row=null;
|
156 | IGeometry ig=null;
|
||
157 | 4584 | caballero | if (selectedRows.size()==1){ |
158 | row=(DefaultRowEdited) selectedRows.get(0);
|
||
159 | //row = getCadToolAdapter().getVectorialAdapter().getRow(selection.nextSetBit(0));
|
||
160 | ig=((IFeature)row.getLinkedRow()).getGeometry().cloneGeometry(); |
||
161 | 4313 | fjp | return ig;
|
162 | } |
||
163 | |||
164 | return null; |
||
165 | } |
||
166 | |||
167 | /**
|
||
168 | 4118 | caballero | * M?todo para dibujar la lo necesario para el estado en el que nos
|
169 | * encontremos.
|
||
170 | *
|
||
171 | * @param g Graphics sobre el que dibujar.
|
||
172 | * @param x par?metro x del punto que se pase para dibujar.
|
||
173 | * @param y par?metro x del punto que se pase para dibujar.
|
||
174 | */
|
||
175 | public void drawOperation(Graphics g, double x, double y) { |
||
176 | 4522 | caballero | //EditVertexCADToolState actualState = ((EditVertexCADToolContext) _fsm).getState();
|
177 | //String status = actualState.getName();
|
||
178 | 4584 | caballero | //VectorialEditableAdapter vea = getCadToolAdapter().getVectorialAdapter();
|
179 | //FBitSet selection = vea.getSelection();
|
||
180 | 4118 | caballero | |
181 | try {
|
||
182 | 4584 | caballero | drawVertex(g,getCadToolAdapter().getMapControl().getViewPort() |
183 | 4118 | caballero | .getAffineTransform()); |
184 | } catch (DriverIOException e) {
|
||
185 | e.printStackTrace(); |
||
186 | } |
||
187 | 4365 | caballero | |
188 | 4118 | caballero | } |
189 | |||
190 | /**
|
||
191 | * Add a diferent option.
|
||
192 | *
|
||
193 | * @param s Diferent option.
|
||
194 | */
|
||
195 | public void addOption(String s) { |
||
196 | EditVertexCADToolState actualState = (EditVertexCADToolState) _fsm.getPreviousState(); |
||
197 | String status = actualState.getName();
|
||
198 | 4724 | caballero | VectorialLayerEdited vle=getVLE(); |
199 | VectorialEditableAdapter vea = vle.getVEA(); |
||
200 | ArrayList selectedRows=vle.getSelectedRow();
|
||
201 | 4118 | caballero | IRowEdited row=null;
|
202 | IGeometry ig=null;
|
||
203 | Handler[] handlers=null; |
||
204 | 4584 | caballero | if (selectedRows.size()==1){ |
205 | row = (DefaultRowEdited) selectedRows.get(0);
|
||
206 | 4846 | caballero | ig=((IFeature)row.getLinkedRow()).getGeometry().cloneGeometry(); |
207 | 4118 | caballero | handlers=ig.getHandlers(IGeometry.SELECTHANDLER); |
208 | numHandlers=handlers.length; |
||
209 | if (numHandlers ==0){ |
||
210 | try {
|
||
211 | 5184 | caballero | vea.removeRow(row.getIndex(),getName(),EditionEvent.GRAPHIC); |
212 | 4118 | caballero | } catch (IOException e) { |
213 | e.printStackTrace(); |
||
214 | } catch (DriverIOException e) {
|
||
215 | e.printStackTrace(); |
||
216 | } |
||
217 | } |
||
218 | } |
||
219 | int dif=1;//En el caso de ser pol?gono. |
||
220 | if (ig instanceof FGeometryCollection){ |
||
221 | dif=2;
|
||
222 | } |
||
223 | if (status.equals("EditVertex.SelectVertexOrDelete")){ |
||
224 | 4724 | caballero | if(s.equals("s") || s.equals("S") || s.equals(PluginServices.getText(this,"next"))){ |
225 | 4118 | caballero | numSelect=numSelect-dif; |
226 | if (numSelect<0){ |
||
227 | numSelect=numHandlers-1+(numSelect+1); |
||
228 | } |
||
229 | 4724 | caballero | }else if(s.equals("a") || s.equals("A") || s.equals(PluginServices.getText(this,"previous"))){ |
230 | 4118 | caballero | numSelect=numSelect+dif; |
231 | if (numSelect>(numHandlers-1)){ |
||
232 | numSelect=numSelect-(numHandlers); |
||
233 | } |
||
234 | |||
235 | 4584 | caballero | }else if(s.equals("e") || s.equals("E") || s.equals(PluginServices.getText(this,"del"))){ |
236 | 4118 | caballero | if (handlers!=null){ |
237 | 5884 | caballero | IGeometry newGeometry=null;
|
238 | if (ig instanceof FGeometryCollection) { |
||
239 | newGeometry=removeVertexGC((FGeometryCollection)ig,handlers[numSelect]); |
||
240 | }else {
|
||
241 | newGeometry=removeVertex(ig,handlers[numSelect]); |
||
242 | } |
||
243 | 4118 | caballero | numSelect=0;
|
244 | |||
245 | 5884 | caballero | IRow newRow=new DefaultFeature(newGeometry,row.getAttributes(),row.getID());
|
246 | 4118 | caballero | try {
|
247 | 5184 | caballero | vea.modifyRow(row.getIndex(),newRow,getName(),EditionEvent.GRAPHIC); |
248 | 4118 | caballero | } catch (IOException e) { |
249 | e.printStackTrace(); |
||
250 | } catch (DriverIOException e) {
|
||
251 | e.printStackTrace(); |
||
252 | } |
||
253 | 4724 | caballero | |
254 | vle.refreshSelectionCache(new Point2D.Double(0,0),getCadToolAdapter()); |
||
255 | 5923 | fjp | refresh(); |
256 | 4724 | caballero | |
257 | 4118 | caballero | } |
258 | 4584 | caballero | }else if(s.equals("i") || s.equals("I") || s.equals(PluginServices.getText(this,"add"))){ |
259 | 4365 | caballero | addVertex=true;
|
260 | 4118 | caballero | } |
261 | } |
||
262 | } |
||
263 | 4584 | caballero | private void drawVertex(Graphics g,AffineTransform at) throws DriverIOException{ |
264 | ArrayList selectedRows=getSelectedRows();
|
||
265 | for (int i = 0; i<selectedRows.size(); |
||
266 | i++) { |
||
267 | DefaultFeature fea = (DefaultFeature) ((DefaultRowEdited) selectedRows |
||
268 | .get(i)).getLinkedRow(); |
||
269 | IGeometry ig = fea.getGeometry().cloneGeometry(); |
||
270 | 4118 | caballero | if (ig == null) continue; |
271 | Handler[] handlers=ig.getHandlers(IGeometry.SELECTHANDLER); |
||
272 | 4549 | caballero | if (numSelect>handlers.length)
|
273 | numSelect=0;
|
||
274 | 4118 | caballero | FGraphicUtilities.DrawVertex((Graphics2D)g,at,handlers[numSelect]);
|
275 | } |
||
276 | } |
||
277 | 4365 | caballero | |
278 | 4118 | caballero | /* (non-Javadoc)
|
279 | * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
||
280 | */
|
||
281 | public void addValue(double d) { |
||
282 | } |
||
283 | 4365 | caballero | private IGeometry removeVertex(IGeometry gp,Handler handler) { |
284 | 4118 | caballero | GeneralPathX newGp = new GeneralPathX();
|
285 | double[] theData = new double[6]; |
||
286 | |||
287 | 4880 | fjp | PathIterator theIterator;
|
288 | 4118 | caballero | int theType;
|
289 | int numParts = 0; |
||
290 | |||
291 | Point2D ptSrc = new Point2D.Double(); |
||
292 | boolean bFirst = false; |
||
293 | |||
294 | 4880 | fjp | theIterator = gp.getPathIterator(null); //, flatness); |
295 | 4118 | caballero | int numSegmentsAdded = 0; |
296 | while (!theIterator.isDone()) {
|
||
297 | theType = theIterator.currentSegment(theData); |
||
298 | if (bFirst){
|
||
299 | newGp.moveTo(theData[0], theData[1]); |
||
300 | numSegmentsAdded++; |
||
301 | bFirst=false;
|
||
302 | continue;
|
||
303 | } |
||
304 | switch (theType) {
|
||
305 | |||
306 | case PathIterator.SEG_MOVETO: |
||
307 | numParts++; |
||
308 | ptSrc.setLocation(theData[0], theData[1]); |
||
309 | if (ptSrc.equals(handler.getPoint())){
|
||
310 | numParts--; |
||
311 | bFirst=true;
|
||
312 | break;
|
||
313 | } |
||
314 | newGp.moveTo(ptSrc.getX(), ptSrc.getY()); |
||
315 | numSegmentsAdded++; |
||
316 | bFirst = false;
|
||
317 | break;
|
||
318 | |||
319 | case PathIterator.SEG_LINETO: |
||
320 | ptSrc.setLocation(theData[0], theData[1]); |
||
321 | if (ptSrc.equals(handler.getPoint())){
|
||
322 | break;
|
||
323 | } |
||
324 | newGp.lineTo(ptSrc.getX(), ptSrc.getY()); |
||
325 | bFirst = false;
|
||
326 | numSegmentsAdded++; |
||
327 | break;
|
||
328 | |||
329 | case PathIterator.SEG_QUADTO: |
||
330 | newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
||
331 | numSegmentsAdded++; |
||
332 | break;
|
||
333 | |||
334 | case PathIterator.SEG_CUBICTO: |
||
335 | newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
||
336 | numSegmentsAdded++; |
||
337 | break;
|
||
338 | |||
339 | case PathIterator.SEG_CLOSE: |
||
340 | if (numSegmentsAdded < 3) |
||
341 | newGp.lineTo(theData[0], theData[1]); |
||
342 | newGp.closePath(); |
||
343 | |||
344 | break;
|
||
345 | } //end switch
|
||
346 | |||
347 | theIterator.next(); |
||
348 | } //end while loop
|
||
349 | FShape shp = null;
|
||
350 | switch (gp.getGeometryType())
|
||
351 | { |
||
352 | case FShape.POINT: //Tipo punto |
||
353 | case FShape.POINT + FShape.Z:
|
||
354 | shp = new FPoint2D(ptSrc.getX(), ptSrc.getY());
|
||
355 | break;
|
||
356 | |||
357 | case FShape.LINE:
|
||
358 | case FShape.LINE + FShape.Z:
|
||
359 | shp = new FPolyline2D(newGp);
|
||
360 | break;
|
||
361 | case FShape.POLYGON:
|
||
362 | case FShape.POLYGON + FShape.Z:
|
||
363 | shp = new FPolygon2D(newGp);
|
||
364 | break;
|
||
365 | } |
||
366 | return ShapeFactory.createGeometry(shp);
|
||
367 | } |
||
368 | 5884 | caballero | |
369 | private IGeometry removeVertexGC(FGeometryCollection gc,Handler handler) { |
||
370 | IGeometry[] geoms=gc.getGeometries();
|
||
371 | ArrayList geomsAux=new ArrayList(); |
||
372 | int pos=-1; |
||
373 | for (int i=0;i<geoms.length;i++) { |
||
374 | Handler[] handlers=geoms[i].getHandlers(IGeometry.SELECTHANDLER); |
||
375 | for (int j=0;j<handlers.length;j++) { |
||
376 | if (handlers[j].equalsPoint(handler)) {
|
||
377 | geomsAux.add(geoms[i]); |
||
378 | if (pos==-1) |
||
379 | pos=i; |
||
380 | } |
||
381 | } |
||
382 | } |
||
383 | int numGeomsAux=geomsAux.size();
|
||
384 | GeneralPathX gpx=new GeneralPathX();
|
||
385 | for (int i=0;i<numGeomsAux;i++) { |
||
386 | Handler[] handlers=((IGeometry)geomsAux.get(i)).getHandlers(IGeometry.SELECTHANDLER); |
||
387 | if (numGeomsAux == 2) { |
||
388 | for (int j = 0; j < handlers.length; j++) { |
||
389 | if (handlers[j].equalsPoint(handler)) {
|
||
390 | if (j == (handlers.length - 1)) { |
||
391 | Point2D ph = handlers[0].getPoint(); |
||
392 | gpx.moveTo(ph.getX(), ph.getY()); |
||
393 | } else {
|
||
394 | Point2D ph = handlers[handlers.length - 1] |
||
395 | .getPoint(); |
||
396 | gpx.lineTo(ph.getX(), ph.getY()); |
||
397 | } |
||
398 | } |
||
399 | } |
||
400 | } |
||
401 | |||
402 | } |
||
403 | ArrayList newGeoms=new ArrayList(); |
||
404 | for (int i=0;i<pos;i++) { |
||
405 | newGeoms.add(geoms[i]); |
||
406 | } |
||
407 | newGeoms.add(ShapeFactory.createPolyline2D(gpx)); |
||
408 | for (int i=pos+numGeomsAux;i<geoms.length;i++) { |
||
409 | newGeoms.add(geoms[i]); |
||
410 | } |
||
411 | |||
412 | return new FGeometryCollection((IGeometry[])newGeoms.toArray(new IGeometry[0])); |
||
413 | } |
||
414 | |||
415 | |||
416 | |||
417 | 4365 | caballero | private IGeometry addVertex(IGeometry geome,Point2D p,Rectangle2D rect) { |
418 | IGeometry geometryCloned=geome.cloneGeometry(); |
||
419 | 4522 | caballero | IGeometry geom1=null;
|
420 | GeneralPathX gpxAux; |
||
421 | 5216 | caballero | boolean finish=false; |
422 | 4522 | caballero | //FGeometry geom2=null;
|
423 | |||
424 | //if (geometryCloned.getGeometryType() == FShape.POLYGON){
|
||
425 | /////////////////
|
||
426 | |||
427 | GeneralPathX newGp = new GeneralPathX();
|
||
428 | double[] theData = new double[6]; |
||
429 | |||
430 | 4880 | fjp | PathIterator theIterator;
|
431 | 4522 | caballero | int theType;
|
432 | int numParts = 0; |
||
433 | Point2D pLast=new Point2D.Double(); |
||
434 | Point2D pAnt = new Point2D.Double(); |
||
435 | 4846 | caballero | Point2D firstPoint=null; |
436 | 4880 | fjp | theIterator = geome.getPathIterator(null); //, flatness); |
437 | 4522 | caballero | int numSegmentsAdded = 0; |
438 | while (!theIterator.isDone()) {
|
||
439 | theType = theIterator.currentSegment(theData); |
||
440 | switch (theType) {
|
||
441 | case PathIterator.SEG_MOVETO: |
||
442 | pLast.setLocation(theData[0], theData[1]); |
||
443 | 4846 | caballero | if (numParts==0) |
444 | firstPoint=(Point2D)pLast.clone();
|
||
445 | numParts++; |
||
446 | 4522 | caballero | |
447 | gpxAux=new GeneralPathX();
|
||
448 | gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
||
449 | gpxAux.lineTo(pLast.getX(),pLast.getY()); |
||
450 | geom1=ShapeFactory.createPolyline2D(gpxAux); |
||
451 | if (geom1.intersects(rect)){
|
||
452 | 5216 | caballero | finish=true;
|
453 | newGp.moveTo(pLast.getX(), pLast.getY()); |
||
454 | //newGp.lineTo(pLast.getX(),pLast.getY());
|
||
455 | 4522 | caballero | }else{
|
456 | newGp.moveTo(pLast.getX(), pLast.getY()); |
||
457 | } |
||
458 | pAnt.setLocation(pLast.getX(), pLast.getY()); |
||
459 | numSegmentsAdded++; |
||
460 | break;
|
||
461 | |||
462 | case PathIterator.SEG_LINETO: |
||
463 | pLast.setLocation(theData[0], theData[1]); |
||
464 | gpxAux=new GeneralPathX();
|
||
465 | gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
||
466 | gpxAux.lineTo(pLast.getX(),pLast.getY()); |
||
467 | geom1=ShapeFactory.createPolyline2D(gpxAux); |
||
468 | if (geom1.intersects(rect)){
|
||
469 | newGp.lineTo(p.getX(), p.getY()); |
||
470 | newGp.lineTo(pLast.getX(),pLast.getY()); |
||
471 | }else{
|
||
472 | newGp.lineTo(pLast.getX(), pLast.getY()); |
||
473 | } |
||
474 | pAnt.setLocation(pLast.getX(), pLast.getY()); |
||
475 | numSegmentsAdded++; |
||
476 | break;
|
||
477 | |||
478 | case PathIterator.SEG_QUADTO: |
||
479 | newGp.quadTo(theData[0], theData[1], theData[2], theData[3]); |
||
480 | numSegmentsAdded++; |
||
481 | break;
|
||
482 | |||
483 | case PathIterator.SEG_CUBICTO: |
||
484 | newGp.curveTo(theData[0], theData[1], theData[2], theData[3], theData[4], theData[5]); |
||
485 | numSegmentsAdded++; |
||
486 | break;
|
||
487 | |||
488 | case PathIterator.SEG_CLOSE: |
||
489 | 4846 | caballero | //if (numSegmentsAdded < 3){
|
490 | gpxAux=new GeneralPathX();
|
||
491 | gpxAux.moveTo(pAnt.getX(),pAnt.getY()); |
||
492 | gpxAux.lineTo(firstPoint.getX(),firstPoint.getY()); |
||
493 | geom1=ShapeFactory.createPolyline2D(gpxAux); |
||
494 | 5216 | caballero | if (geom1.intersects(rect)|| finish){
|
495 | 4846 | caballero | newGp.lineTo(p.getX(), p.getY()); |
496 | newGp.lineTo(pLast.getX(),pLast.getY()); |
||
497 | }else{
|
||
498 | newGp.lineTo(pLast.getX(), pLast.getY()); |
||
499 | } |
||
500 | //}
|
||
501 | 4522 | caballero | newGp.closePath(); |
502 | break;
|
||
503 | } //end switch
|
||
504 | |||
505 | theIterator.next(); |
||
506 | } //end while loop
|
||
507 | FShape shp = null;
|
||
508 | switch (geometryCloned.getGeometryType())
|
||
509 | { |
||
510 | case FShape.POINT: //Tipo punto |
||
511 | case FShape.POINT + FShape.Z:
|
||
512 | shp = new FPoint2D(pLast.getX(), pLast.getY());
|
||
513 | break;
|
||
514 | |||
515 | case FShape.LINE:
|
||
516 | case FShape.LINE + FShape.Z:
|
||
517 | shp = new FPolyline2D(newGp);
|
||
518 | break;
|
||
519 | case FShape.POLYGON:
|
||
520 | case FShape.POLYGON + FShape.Z:
|
||
521 | shp = new FPolygon2D(newGp);
|
||
522 | break;
|
||
523 | } |
||
524 | return ShapeFactory.createGeometry(shp);
|
||
525 | |||
526 | |||
527 | /////////////////////
|
||
528 | //}else if (geometryCloned.getGeometryType() == FShape.LINE){
|
||
529 | |||
530 | //}
|
||
531 | |||
532 | |||
533 | |||
534 | |||
535 | /* if (geometryCloned instanceof FGeometryCollection){
|
||
536 | 4365 | caballero | IGeometry[] geometries=((FGeometryCollection)geometryCloned).getGeometries();
|
537 | boolean isSelected=false;
|
||
538 | for (int i=0;i<geometries.length;i++){
|
||
539 | if (geometries[i].intersects(rect) && !isSelected){
|
||
540 | isSelected=true;
|
||
541 | Handler[] handlers=geometries[i].getHandlers(IGeometry.SELECTHANDLER);
|
||
542 | 4118 | caballero | |
543 | 4365 | caballero | GeneralPathX gp1=new GeneralPathX();
|
544 | Point2D pinit1=(Point2D)handlers[0].getPoint().clone();
|
||
545 | gp1.moveTo(pinit1.getX(),pinit1.getY());
|
||
546 | System.out.println("Handler inicial = "+pinit1);
|
||
547 | gp1.lineTo(p.getX(),p.getY());
|
||
548 | System.out.println("Handler medio = "+p);
|
||
549 | FPolyline2D poly1=new FPolyline2D(gp1);
|
||
550 | geom1=ShapeFactory.createGeometry(poly1);
|
||
551 | |||
552 | GeneralPathX gp2=new GeneralPathX();
|
||
553 | gp2.moveTo(p.getX(),p.getY());
|
||
554 | System.out.println("Handler medio = "+p);
|
||
555 | Point2D pEnd=(Point2D)handlers[1].getPoint().clone();
|
||
556 | gp2.lineTo(pEnd.getX(),pEnd.getY());
|
||
557 | System.out.println("Handler final = "+pEnd);
|
||
558 | FPolyline2D poly2=new FPolyline2D(gp2);
|
||
559 | geom2=ShapeFactory.createGeometry(poly2);
|
||
560 | |||
561 | ArrayList geomsAux=new ArrayList();
|
||
562 | geometries[i]=geom1;
|
||
563 | for (int j=i;j<geometries.length;j++){
|
||
564 | geomsAux.add(geometries[j]);
|
||
565 | }
|
||
566 | |||
567 | if (i<geometries.length-1){
|
||
568 | geometries[i+1]=geom2;
|
||
569 | Handler[] hands=((IGeometry)geom1).getHandlers(IGeometry.SELECTHANDLER);
|
||
570 | for (int h=0;h<hands.length;h++)
|
||
571 | System.out.println("Handlers New Geometry = "+hands[h].getPoint());
|
||
572 | Handler[] hands2=((IGeometry)geom2).getHandlers(IGeometry.SELECTHANDLER);
|
||
573 | for (int h=0;h<hands2.length;h++)
|
||
574 | System.out.println("Handlers New Geometry = "+hands2[h].getPoint());
|
||
575 | }else{
|
||
576 | geometryCloned=new FGeometryCollection(geometries);
|
||
577 | ((FGeometryCollection)geometryCloned).addGeometry(geom2);
|
||
578 | }
|
||
579 | for (int j=i+1;j<geometries.length;j++){
|
||
580 | if ((j-i)<geomsAux.size()-1){
|
||
581 | geometries[j+1]=(IGeometry)geomsAux.get(j-i);
|
||
582 | }else{
|
||
583 | geometryCloned=new FGeometryCollection(geometries);
|
||
584 | ((FGeometryCollection)geometryCloned).addGeometry((IGeometry)geomsAux.get(j-i));
|
||
585 | |||
586 | }
|
||
587 | }
|
||
588 | }
|
||
589 | |||
590 | }
|
||
591 | }
|
||
592 | return geometryCloned;
|
||
593 | 4522 | caballero | */
|
594 | 4365 | caballero | } |
595 | 5884 | caballero | private IGeometry addVertexGC(FGeometryCollection gc,Point2D p,Rectangle2D rect) { |
596 | IGeometry[] geoms=gc.getGeometries();
|
||
597 | int pos=-1; |
||
598 | for (int i=0;i<geoms.length;i++) { |
||
599 | if (geoms[i].intersects(rect)) {
|
||
600 | pos=i; |
||
601 | } |
||
602 | } |
||
603 | ArrayList newGeoms=new ArrayList(); |
||
604 | for (int i=0;i<pos;i++) { |
||
605 | newGeoms.add(geoms[i]); |
||
606 | } |
||
607 | if (pos!=-1) { |
||
608 | GeneralPathX gpx1=new GeneralPathX();
|
||
609 | GeneralPathX gpx2=new GeneralPathX();
|
||
610 | Handler[] handlers=geoms[pos].getHandlers(IGeometry.SELECTHANDLER); |
||
611 | Point2D p1=handlers[0].getPoint(); |
||
612 | Point2D p2=p;
|
||
613 | Point2D p3=handlers[handlers.length-1].getPoint(); |
||
614 | gpx1.moveTo(p1.getX(),p1.getY()); |
||
615 | gpx1.lineTo(p2.getX(),p2.getY()); |
||
616 | gpx2.moveTo(p2.getX(),p2.getY()); |
||
617 | gpx2.lineTo(p3.getX(),p3.getY()); |
||
618 | newGeoms.add(ShapeFactory.createPolyline2D(gpx1)); |
||
619 | newGeoms.add(ShapeFactory.createPolyline2D(gpx2)); |
||
620 | for (int i=pos+1;i<geoms.length;i++) { |
||
621 | newGeoms.add(geoms[i]); |
||
622 | } |
||
623 | return new FGeometryCollection((IGeometry[])newGeoms.toArray(new IGeometry[0])); |
||
624 | }else {
|
||
625 | return null; |
||
626 | } |
||
627 | } |
||
628 | 4118 | caballero | public String getName() { |
629 | 4584 | caballero | return PluginServices.getText(this,"edit_vertex_"); |
630 | 4118 | caballero | } |
631 | 4365 | caballero | private void selectHandler(double x, double y) { |
632 | Point2D firstPoint = new Point2D.Double(x, y); |
||
633 | 4846 | caballero | VectorialLayerEdited vle = getVLE(); |
634 | ArrayList selectedRows = vle.getSelectedRow();
|
||
635 | 4365 | caballero | double tam = getCadToolAdapter().getMapControl().getViewPort()
|
636 | .toMapDistance(SelectionCADTool.tolerance); |
||
637 | 4846 | caballero | Rectangle2D rect = new Rectangle2D.Double(firstPoint.getX() - tam, |
638 | firstPoint.getY() - tam, tam * 2, tam * 2); |
||
639 | if (selectedRows.size() > 0) { |
||
640 | boolean isSelectedHandler = false; |
||
641 | IGeometry geometry = getSelectedGeometry(); |
||
642 | if (geometry != null) { |
||
643 | Handler[] handlers = geometry |
||
644 | .getHandlers(IGeometry.SELECTHANDLER); |
||
645 | for (int h = 0; h < handlers.length; h++) { |
||
646 | if (handlers[h].getPoint().distance(firstPoint) < tam) {
|
||
647 | numSelect = h; |
||
648 | isSelectedHandler = true;
|
||
649 | } |
||
650 | } |
||
651 | 4365 | caballero | |
652 | 4846 | caballero | if (!isSelectedHandler) {
|
653 | boolean isSelectedGeometry = false; |
||
654 | try {
|
||
655 | 4365 | caballero | |
656 | 4971 | caballero | //VectorialEditableAdapter vea = getCadToolAdapter()
|
657 | // .getVectorialAdapter();
|
||
658 | //String strEPSG = getCadToolAdapter().getMapControl()
|
||
659 | // .getViewPort().getProjection().getAbrev()
|
||
660 | // .substring(5);
|
||
661 | 4846 | caballero | //IRowEdited[] feats = vea.getFeatures(rect, strEPSG);
|
662 | 4365 | caballero | |
663 | 4846 | caballero | //for (int i = 0; i < feats.length; i++) {
|
664 | if (geometry.intersects(rect)) { // , 0.1)){ |
||
665 | isSelectedGeometry = true;
|
||
666 | 4365 | caballero | } |
667 | 4846 | caballero | //}
|
668 | if (isSelectedGeometry && addVertex) {
|
||
669 | selectedRows = getSelectedRows(); |
||
670 | DefaultFeature fea = null;
|
||
671 | DefaultRowEdited row = null;
|
||
672 | row = (DefaultRowEdited) selectedRows.get(0);
|
||
673 | fea = (DefaultFeature) row.getLinkedRow(); |
||
674 | Point2D posVertex = new Point2D.Double(x, y); |
||
675 | 5884 | caballero | IGeometry geom1=fea.getGeometry().cloneGeometry(); |
676 | IGeometry geom=null;
|
||
677 | if (geom1 instanceof FGeometryCollection) { |
||
678 | geom = addVertexGC((FGeometryCollection)geom1, posVertex, rect); |
||
679 | }else {
|
||
680 | geom = addVertex(geom1, posVertex, rect); |
||
681 | } |
||
682 | if (geom!=null) { |
||
683 | 4846 | caballero | DefaultFeature df = new DefaultFeature(geom, fea
|
684 | 5884 | caballero | .getAttributes(),row.getID()); |
685 | int index=vle.getVEA().modifyRow(row.getIndex(), df,
|
||
686 | 5184 | caballero | PluginServices.getText(this,"add_vertex"),EditionEvent.GRAPHIC); |
687 | 4365 | caballero | |
688 | 4846 | caballero | Handler[] newHandlers = geom |
689 | .getHandlers(IGeometry.SELECTHANDLER); |
||
690 | for (int h = 0; h < newHandlers.length; h++) { |
||
691 | if (newHandlers[h].getPoint().distance(
|
||
692 | posVertex) < tam) { |
||
693 | numSelect = h; |
||
694 | isSelectedHandler = true;
|
||
695 | } |
||
696 | 4365 | caballero | } |
697 | 4846 | caballero | |
698 | 5884 | caballero | clearSelection(); |
699 | selectedRows.add(new DefaultRowEdited(df,
|
||
700 | IRowEdited.STATUS_MODIFIED, index)); |
||
701 | } |
||
702 | 4365 | caballero | } |
703 | 4846 | caballero | } catch (IOException e) { |
704 | e.printStackTrace(); |
||
705 | } catch (DriverIOException e) {
|
||
706 | e.printStackTrace(); |
||
707 | } |
||
708 | 4365 | caballero | |
709 | 4846 | caballero | } |
710 | 4724 | caballero | } |
711 | 4365 | caballero | } |
712 | |||
713 | } |
||
714 | |||
715 | 4892 | caballero | public String toString() { |
716 | return "_editvertex"; |
||
717 | } |
||
718 | 4365 | caballero | |
719 | 5170 | caballero | public boolean isApplicable(int shapeType) { |
720 | switch (shapeType) {
|
||
721 | case FShape.POINT:
|
||
722 | return false; |
||
723 | } |
||
724 | return true; |
||
725 | } |
||
726 | 4892 | caballero | |
727 | 5170 | caballero | |
728 | 4118 | caballero | } |