svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / BreakCADTool.java @ 5908
History | View | Annotate | Download (22.7 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.iver.andami.PluginServices; |
54 |
import com.iver.cit.gvsig.CADExtension; |
55 |
import com.iver.cit.gvsig.fmap.ViewPort; |
56 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
57 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
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.drivers.DriverIOException; |
63 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
64 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
65 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
66 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
67 |
import com.iver.cit.gvsig.gui.cad.CADTool; |
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); |
354 |
|
355 |
double[] theData = new double[6]; |
356 |
boolean isFirstPart=true; |
357 |
int theType;
|
358 |
int numParts = 0; |
359 |
|
360 |
Point2D previous=null; |
361 |
|
362 |
while (!theIterator.isDone()) {
|
363 |
theType = theIterator.currentSegment(theData); |
364 |
switch (theType) {
|
365 |
|
366 |
case PathIterator.SEG_MOVETO: |
367 |
numParts++; |
368 |
|
369 |
previous=new Point2D.Double(theData[0], theData[1]); |
370 |
|
371 |
if (isFirstPart)
|
372 |
newGp1.moveTo(theData[0], theData[1]); |
373 |
else
|
374 |
newGp2.moveTo(theData[0], theData[1]); |
375 |
break;
|
376 |
|
377 |
case PathIterator.SEG_LINETO: |
378 |
if (previous!=null){ |
379 |
GeneralPathX gpx=new GeneralPathX();
|
380 |
gpx.moveTo(previous.getX(),previous.getY()); |
381 |
gpx.lineTo(theData[0], theData[1]); |
382 |
IGeometry geom=ShapeFactory.createPolyline2D(gpx); |
383 |
Point2D p1=getNearPoint(previous);
|
384 |
Point2D p2=getDistantPoint(previous);
|
385 |
if (intersects(geom,p1)){
|
386 |
isFirstPart=false;
|
387 |
newGp1.lineTo(p1.getX(),p1.getY()); |
388 |
newGp2.moveTo(p2.getX(),p2.getY()); |
389 |
} |
390 |
} |
391 |
previous=new Point2D.Double(theData[0], theData[1]); |
392 |
if (isFirstPart)
|
393 |
newGp1.lineTo(theData[0], theData[1]); |
394 |
else
|
395 |
newGp2.lineTo(theData[0], theData[1]); |
396 |
break;
|
397 |
|
398 |
case PathIterator.SEG_QUADTO: |
399 |
if (previous!=null){ |
400 |
GeneralPathX gpx=new GeneralPathX();
|
401 |
gpx.moveTo(previous.getX(),previous.getY()); |
402 |
gpx.quadTo(theData[0], theData[1],theData[2], theData[3]); |
403 |
IGeometry geom=ShapeFactory.createPolyline2D(gpx); |
404 |
Point2D p1=getNearPoint(previous);
|
405 |
Point2D p2=getDistantPoint(previous);
|
406 |
if (intersects(geom,p1)){
|
407 |
isFirstPart=false;
|
408 |
newGp1.lineTo(p1.getX(),p1.getY()); |
409 |
newGp2.moveTo(p2.getX(),p2.getY()); |
410 |
} |
411 |
} |
412 |
previous=new Point2D.Double(theData[0], theData[1]); |
413 |
if (isFirstPart)
|
414 |
newGp1.quadTo(theData[0], theData[1],theData[2], theData[3]); |
415 |
else
|
416 |
newGp2.quadTo(theData[0], theData[1],theData[2], theData[3]); |
417 |
|
418 |
break;
|
419 |
|
420 |
case PathIterator.SEG_CUBICTO: |
421 |
if (previous!=null){ |
422 |
GeneralPathX gpx=new GeneralPathX();
|
423 |
gpx.moveTo(previous.getX(),previous.getY()); |
424 |
gpx.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]); |
425 |
IGeometry geom=ShapeFactory.createPolyline2D(gpx); |
426 |
Point2D p1=getNearPoint(previous);
|
427 |
Point2D p2=getDistantPoint(previous);
|
428 |
if (intersects(geom,p1)){
|
429 |
isFirstPart=false;
|
430 |
newGp1.lineTo(p1.getX(),p1.getY()); |
431 |
newGp2.moveTo(p2.getX(),p2.getY()); |
432 |
} |
433 |
} |
434 |
previous=new Point2D.Double(theData[0], theData[1]); |
435 |
if (isFirstPart)
|
436 |
newGp1.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]); |
437 |
else
|
438 |
newGp2.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]); |
439 |
|
440 |
break;
|
441 |
|
442 |
case PathIterator.SEG_CLOSE: |
443 |
//if (isFirstPart)
|
444 |
// newGp1.closePath();
|
445 |
//else
|
446 |
// newGp2.closePath();
|
447 |
break;
|
448 |
} //end switch
|
449 |
|
450 |
theIterator.next(); |
451 |
} //end while loop
|
452 |
GeneralPathX gpx=new GeneralPathX();
|
453 |
gpx.append(geomAux.getInternalShape(),true);
|
454 |
if (gpx.isClosed()) {
|
455 |
newGp2.append(newGp1.getPathIterator(null),true); |
456 |
IGeometry geom1=ShapeFactory.createPolyline2D(newGp2); |
457 |
VectorialLayerEdited vle = getVLE(); |
458 |
VectorialEditableAdapter vea = vle.getVEA(); |
459 |
int num=vea.getRowCount();
|
460 |
DefaultFeature df1 = new DefaultFeature(geom1, dre.getAttributes(),String.valueOf(num)); |
461 |
|
462 |
vea.startComplexRow(); |
463 |
vea.removeRow(dre.getIndex(),getName(),EditionEvent.GRAPHIC); |
464 |
int index1=vea.addRow(df1,PluginServices.getText(this,"parte1"),EditionEvent.GRAPHIC); |
465 |
vea.endComplexRow(); |
466 |
ViewPort vp=CADExtension.getEditionManager().getMapControl().getViewPort(); |
467 |
BufferedImage selectionImage = new BufferedImage(vp.getImageWidth(), vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB); |
468 |
Graphics2D gs = selectionImage.createGraphics();
|
469 |
clearSelection(); |
470 |
ArrayList selectedRow = vle.getSelectedRow();
|
471 |
selectedRow.add(new DefaultRowEdited(df1, IRowEdited.STATUS_ADDED, index1));
|
472 |
geom1.cloneGeometry().draw(gs, vp, CADTool.drawingSymbol); |
473 |
vle.drawHandlers(geom1.cloneGeometry(),gs,vp); |
474 |
vea.setSelectionImage(selectionImage); |
475 |
}else {
|
476 |
IGeometry geom1=ShapeFactory.createPolyline2D(newGp1); |
477 |
IGeometry geom2=ShapeFactory.createPolyline2D(newGp2); |
478 |
VectorialLayerEdited vle = getVLE(); |
479 |
VectorialEditableAdapter vea = vle.getVEA(); |
480 |
int num=vea.getRowCount();
|
481 |
DefaultFeature df1 = new DefaultFeature(geom1, dre.getAttributes(),String.valueOf(num)); |
482 |
DefaultFeature df2 = new DefaultFeature(geom2, dre.getAttributes(),String.valueOf(num+1)); |
483 |
|
484 |
vea.startComplexRow(); |
485 |
vea.removeRow(dre.getIndex(),getName(),EditionEvent.GRAPHIC); |
486 |
int index1=vea.addRow(df1,PluginServices.getText(this,"parte1"),EditionEvent.GRAPHIC); |
487 |
int index2=vea.addRow(df2,PluginServices.getText(this,"parte2"),EditionEvent.GRAPHIC); |
488 |
vea.endComplexRow(); |
489 |
ViewPort vp=CADExtension.getEditionManager().getMapControl().getViewPort(); |
490 |
BufferedImage selectionImage = new BufferedImage(vp.getImageWidth(), vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB); |
491 |
Graphics2D gs = selectionImage.createGraphics();
|
492 |
clearSelection(); |
493 |
ArrayList selectedRow = vle.getSelectedRow();
|
494 |
selectedRow.add(new DefaultRowEdited(df1, IRowEdited.STATUS_ADDED, index1));
|
495 |
selectedRow.add(new DefaultRowEdited(df2, IRowEdited.STATUS_ADDED, index2));
|
496 |
geom1.cloneGeometry().draw(gs, vp, CADTool.drawingSymbol); |
497 |
vle.drawHandlers(geom1.cloneGeometry(),gs,vp); |
498 |
geom2.cloneGeometry().draw(gs, vp, CADTool.drawingSymbol); |
499 |
vle.drawHandlers(geom2.cloneGeometry(),gs,vp); |
500 |
vea.setSelectionImage(selectionImage); |
501 |
} |
502 |
} |
503 |
|
504 |
private Point2D getNearPoint(Point2D previous) { |
505 |
if (firstPoint.distance(previous)<=secondPoint.distance(previous)){
|
506 |
return firstPoint;
|
507 |
} |
508 |
return secondPoint;
|
509 |
|
510 |
} |
511 |
private Point2D getDistantPoint(Point2D previous){ |
512 |
if (firstPoint.distance(previous)>secondPoint.distance(previous)){
|
513 |
return firstPoint;
|
514 |
} |
515 |
return secondPoint;
|
516 |
} |
517 |
|
518 |
/**
|
519 |
* M?todo para dibujar la lo necesario para el estado en el que nos
|
520 |
* encontremos.
|
521 |
*
|
522 |
* @param g Graphics sobre el que dibujar.
|
523 |
* @param x par?metro x del punto que se pase para dibujar.
|
524 |
* @param y par?metro x del punto que se pase para dibujar.
|
525 |
*/
|
526 |
public void drawOperation(Graphics g, double x, double y) { |
527 |
VectorialLayerEdited vle=getVLE(); |
528 |
ArrayList selectedRows=vle.getSelectedRow();
|
529 |
ViewPort vp=CADExtension.getEditionManager().getMapControl().getViewPort(); |
530 |
if (selectedRows.size()==1){ |
531 |
if (firstPoint!=null){ |
532 |
IGeometry g1=ShapeFactory.createCircle(firstPoint,vp.toMapDistance(3));
|
533 |
IGeometry g2=ShapeFactory.createCircle(firstPoint,vp.toMapDistance(5));
|
534 |
g1.draw((Graphics2D)g,vp,DefaultCADTool.modifySymbol);
|
535 |
g2.draw((Graphics2D)g,vp,DefaultCADTool.modifySymbol);
|
536 |
} |
537 |
rowEdited = (DefaultRowEdited)((DefaultRowEdited)selectedRows.get(0));
|
538 |
//.getLinkedRow()
|
539 |
// .cloneRow();
|
540 |
IGeometry geom=((DefaultFeature)rowEdited.getLinkedRow()).getGeometry().cloneGeometry(); |
541 |
if (intersects(geom,new Point2D.Double(x,y))){ |
542 |
geom.draw((Graphics2D)g,vp,DefaultCADTool.drawingSymbol);
|
543 |
} |
544 |
} |
545 |
} |
546 |
public boolean intersects(double x,double y){ |
547 |
Point2D p = new Point2D.Double(x, y); |
548 |
VectorialLayerEdited vle = getVLE(); |
549 |
ArrayList selectedRows = vle.getSelectedRow();
|
550 |
if (selectedRows.size() == 1) { |
551 |
rowEdited = (DefaultRowEdited) ((DefaultRowEdited) selectedRows |
552 |
.get(0));
|
553 |
IGeometry g = ((DefaultFeature) rowEdited.getLinkedRow()) |
554 |
.getGeometry().cloneGeometry(); |
555 |
return intersects(g, p);
|
556 |
} |
557 |
return false; |
558 |
} |
559 |
private boolean intersects(IGeometry geom, Point2D p){ |
560 |
double tol = 1; |
561 |
tol = CADExtension.getEditionManager().getMapControl().getViewPort() |
562 |
.toMapDistance((int) tol);
|
563 |
Rectangle2D r = new Rectangle2D.Double(p.getX() - tol / 2, p.getY() |
564 |
- tol / 2, tol, tol);
|
565 |
return (geom.intersects(r) && !geom.contains(r));
|
566 |
} |
567 |
/**
|
568 |
* Add a diferent option.
|
569 |
*
|
570 |
* @param s Diferent option.
|
571 |
*/
|
572 |
public void addOption(String s) { |
573 |
if (s.equals(PluginServices.getText(this,"cancel"))|| s.equals("c")|| s.equals("C")){ |
574 |
init(); |
575 |
} |
576 |
} |
577 |
/* (non-Javadoc)
|
578 |
* @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
|
579 |
*/
|
580 |
public void addValue(double d) { |
581 |
} |
582 |
public String getName() { |
583 |
return PluginServices.getText(this,"break_"); |
584 |
} |
585 |
|
586 |
public String toString() { |
587 |
return "_break"; |
588 |
} |
589 |
|
590 |
public boolean isApplicable(int shapeType) { |
591 |
switch (shapeType) {
|
592 |
case FShape.MULTI:
|
593 |
case FShape.LINE:
|
594 |
return true; |
595 |
} |
596 |
return false; |
597 |
} |
598 |
|
599 |
|
600 |
} |