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