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