svn-gvsig-desktop / tags / v1_0_2_Build_915 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / BreakCADTool.java @ 12217
History | View | Annotate | Download (30.9 KB)
1 |
/* 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 |
import com.hardcode.gdbms.engine.values.Value; |
54 |
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 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
63 |
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 |
import com.iver.cit.gvsig.gui.cad.exception.CommandException; |
70 |
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 |
private BreakCADToolContext _fsm;
|
82 |
private Point2D firstPoint; |
83 |
private Point2D secondPoint; |
84 |
private DefaultRowEdited rowEdited;
|
85 |
/**
|
86 |
* 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 |
_fsm.addValue(d); |
113 |
} |
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 |
public void transition(String s) throws CommandException { |
119 |
if (!super.changeCommand(s)){ |
120 |
_fsm.addOption(s); |
121 |
} |
122 |
} |
123 |
|
124 |
/**
|
125 |
* DOCUMENT ME!
|
126 |
*/
|
127 |
public void selection() { |
128 |
ArrayList selectedRow=getSelectedRows();
|
129 |
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 |
BreakCADToolState actualState = (BreakCADToolState) _fsm.getPreviousState(); |
145 |
String status = actualState.getName();
|
146 |
|
147 |
if (status.equals("Break.FirstPoint")) { |
148 |
// if (rowEdited!=null && intersects(((DefaultFeature)rowEdited.getLinkedRow()).getGeometry(),new Point2D.Double(x,y)))
|
149 |
firstPoint=new Point2D.Double(x,y); |
150 |
|
151 |
} else if (status.equals("Break.SecondPoint")) { |
152 |
// if (rowEdited !=null && intersects(((DefaultFeature)rowEdited.getLinkedRow()).getGeometry(),new Point2D.Double(x,y))){
|
153 |
secondPoint=new Point2D.Double(x,y); |
154 |
try {
|
155 |
// IGeometry geom=((DefaultFeature)rowEdited.getLinkedRow()).getGeometry();
|
156 |
// if (geom instanceof FGeometryCollection) {
|
157 |
// breakGeometryGC(rowEdited);
|
158 |
// }else {
|
159 |
breakGeometry(rowEdited); |
160 |
// }
|
161 |
} catch (IOException e) { |
162 |
e.printStackTrace(); |
163 |
} catch (DriverIOException e) {
|
164 |
e.printStackTrace(); |
165 |
} |
166 |
} |
167 |
//}
|
168 |
} |
169 |
/* private void breakGeometryGC(DefaultRowEdited dre) throws IOException, DriverIOException {
|
170 |
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 |
|
182 |
Point2D previous=null;
|
183 |
|
184 |
while (!theIterator.isDone()) {
|
185 |
theType = theIterator.currentSegment(theData);
|
186 |
switch (theType) {
|
187 |
|
188 |
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 |
|
197 |
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 |
|
219 |
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 |
|
240 |
break;
|
241 |
|
242 |
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 |
|
263 |
break;
|
264 |
|
265 |
case PathIterator.SEG_CLOSE:
|
266 |
//if (isFirstPart)
|
267 |
// newGp1.closePath();
|
268 |
//else
|
269 |
// newGp2.closePath();
|
270 |
break;
|
271 |
} //end switch
|
272 |
|
273 |
theIterator.next();
|
274 |
} //end while loop
|
275 |
|
276 |
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 |
|
296 |
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 |
|
303 |
clearSelection();
|
304 |
selectedRow.add(new DefaultRowEdited(df1,
|
305 |
IRowEdited.STATUS_ADDED, index1));
|
306 |
vea.endComplexRow();
|
307 |
return;
|
308 |
}else {
|
309 |
|
310 |
ArrayList geomsAux1 = new ArrayList();
|
311 |
for (int k = 0; k < i; k++) {
|
312 |
geomsAux1.add(geoms[k]);
|
313 |
}
|
314 |
geomsAux1.add(geom1);
|
315 |
|
316 |
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 |
|
322 |
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 |
|
340 |
vea.endComplexRow();
|
341 |
return;
|
342 |
}
|
343 |
|
344 |
}
|
345 |
}
|
346 |
}
|
347 |
*/
|
348 |
|
349 |
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 |
PathIterator theIterator=geomAux.getPathIterator(null,FConverter.FLATNESS); |
354 |
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 |
|
361 |
Point2D previous=null; |
362 |
|
363 |
while (!theIterator.isDone()) {
|
364 |
theType = theIterator.currentSegment(theData); |
365 |
switch (theType) {
|
366 |
|
367 |
case PathIterator.SEG_MOVETO: |
368 |
numParts++; |
369 |
|
370 |
previous=new Point2D.Double(theData[0], theData[1]); |
371 |
|
372 |
if (isFirstPart)
|
373 |
newGp1.moveTo(theData[0], theData[1]); |
374 |
else
|
375 |
newGp2.moveTo(theData[0], theData[1]); |
376 |
break;
|
377 |
|
378 |
case PathIterator.SEG_LINETO: |
379 |
|
380 |
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 |
|
388 |
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 |
|
396 |
} |
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 |
|
405 |
break;
|
406 |
|
407 |
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 |
|
427 |
break;
|
428 |
|
429 |
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 |
|
449 |
break;
|
450 |
|
451 |
case PathIterator.SEG_CLOSE: |
452 |
//if (isFirstPart)
|
453 |
// newGp1.closePath();
|
454 |
//else
|
455 |
// newGp2.closePath();
|
456 |
break;
|
457 |
} //end switch
|
458 |
|
459 |
theIterator.next(); |
460 |
} //end while loop
|
461 |
GeneralPathX gpx=new GeneralPathX();
|
462 |
gpx.append(geomAux.getInternalShape(),true);
|
463 |
if (gpx.isClosed()) {
|
464 |
newGp2.append(newGp1.getPathIterator(null,FConverter.FLATNESS),true); |
465 |
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 |
|
471 |
vea.startComplexRow(); |
472 |
vea.removeRow(dre.getIndex(),getName(),EditionEvent.GRAPHIC); |
473 |
int index1=vea.addRow(df1,PluginServices.getText(this,"parte1"),EditionEvent.GRAPHIC); |
474 |
vea.endComplexRow(getName()); |
475 |
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 |
geom1.cloneGeometry().draw(gs, vp, DefaultCADTool.drawingSymbol); |
483 |
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 |
|
495 |
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 |
|
500 |
vea.endComplexRow(getName()); |
501 |
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 |
geom1.cloneGeometry().draw(gs, vp, DefaultCADTool.drawingSymbol); |
510 |
vle.drawHandlers(geom1.cloneGeometry(),gs,vp); |
511 |
geom2.cloneGeometry().draw(gs, vp, DefaultCADTool.drawingSymbol); |
512 |
vle.drawHandlers(geom2.cloneGeometry(),gs,vp); |
513 |
vea.setSelectionImage(selectionImage); |
514 |
} |
515 |
} |
516 |
|
517 |
private Point2D[] getOrderPoints(IGeometry geomAux) { |
518 |
PathIterator theIterator=geomAux.getPathIterator(null,FConverter.FLATNESS); |
519 |
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 |
* 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 |
VectorialLayerEdited vle=getVLE(); |
637 |
ArrayList selectedRows=vle.getSelectedRow();
|
638 |
ViewPort vp=CADExtension.getEditionManager().getMapControl().getViewPort(); |
639 |
if (selectedRows.size()==1){ |
640 |
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 |
} |
654 |
} |
655 |
public boolean intersects(double x,double y){ |
656 |
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 |
} |
668 |
private boolean intersects(IGeometry geom, Point2D p){ |
669 |
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 |
} |
676 |
/**
|
677 |
* Add a diferent option.
|
678 |
*
|
679 |
* @param s Diferent option.
|
680 |
*/
|
681 |
public void addOption(String s) { |
682 |
if (s.equals(PluginServices.getText(this,"cancel"))|| s.equals("c")|| s.equals("C")){ |
683 |
init(); |
684 |
} |
685 |
} |
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 |
return PluginServices.getText(this,"break_"); |
693 |
} |
694 |
|
695 |
public String toString() { |
696 |
return "_break"; |
697 |
} |
698 |
|
699 |
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 |
|
708 |
|
709 |
} |