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