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