root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / BreakCADTool.java @ 5878
History | View | Annotate | Download (22.8 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 |
// VectorialLayerEdited vle = getVLE();
|
347 |
// VectorialEditableAdapter vea = vle.getVEA();
|
348 |
//
|
349 |
// int num=vea.getRowCount();
|
350 |
// DefaultFeature df1 = new DefaultFeature(geom1, dre.getAttributes(),String.valueOf(num));
|
351 |
// DefaultFeature df2 = new DefaultFeature(geom2, dre.getAttributes(),String.valueOf(num+1));
|
352 |
//
|
353 |
// vea.startComplexRow();
|
354 |
// vea.removeRow(dre.getIndex(),getName(),EditionEvent.GRAPHIC);
|
355 |
// int index1=vea.addRow(df1,PluginServices.getText(this,"parte1"),EditionEvent.GRAPHIC);
|
356 |
// int index2=vea.addRow(df2,PluginServices.getText(this,"parte2"),EditionEvent.GRAPHIC);
|
357 |
// vea.endComplexRow();
|
358 |
// ViewPort vp=CADExtension.getEditionManager().getMapControl().getViewPort();
|
359 |
// BufferedImage selectionImage = new BufferedImage(vp.getImageWidth(), vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
|
360 |
// Graphics2D gs = selectionImage.createGraphics();
|
361 |
// clearSelection();
|
362 |
// ArrayList selectedRow = vle.getSelectedRow();
|
363 |
// selectedRow.add(new DefaultRowEdited(df1, IRowEdited.STATUS_ADDED, index1));
|
364 |
// selectedRow.add(new DefaultRowEdited(df2, IRowEdited.STATUS_ADDED, index2));
|
365 |
// geom1.cloneGeometry().draw(gs, vp, CADTool.drawingSymbol);
|
366 |
// vle.drawHandlers(geom1.cloneGeometry(),gs,vp);
|
367 |
// geom2.cloneGeometry().draw(gs, vp, CADTool.drawingSymbol);
|
368 |
// vle.drawHandlers(geom2.cloneGeometry(),gs,vp);
|
369 |
// vea.setSelectionImage(selectionImage);
|
370 |
} |
371 |
} |
372 |
|
373 |
|
374 |
private void breakGeometry(DefaultRowEdited dre) throws IOException, DriverIOException { |
375 |
GeneralPathX newGp1 = new GeneralPathX();
|
376 |
GeneralPathX newGp2 = new GeneralPathX();
|
377 |
IGeometry geomAux=((DefaultFeature)rowEdited.getLinkedRow()).getGeometry(); |
378 |
PathIterator theIterator=geomAux.getPathIterator(null); |
379 |
|
380 |
double[] theData = new double[6]; |
381 |
boolean isFirstPart=true; |
382 |
int theType;
|
383 |
int numParts = 0; |
384 |
|
385 |
Point2D previous=null; |
386 |
|
387 |
while (!theIterator.isDone()) {
|
388 |
theType = theIterator.currentSegment(theData); |
389 |
switch (theType) {
|
390 |
|
391 |
case PathIterator.SEG_MOVETO: |
392 |
numParts++; |
393 |
|
394 |
previous=new Point2D.Double(theData[0], theData[1]); |
395 |
|
396 |
if (isFirstPart)
|
397 |
newGp1.moveTo(theData[0], theData[1]); |
398 |
else
|
399 |
newGp2.moveTo(theData[0], theData[1]); |
400 |
break;
|
401 |
|
402 |
case PathIterator.SEG_LINETO: |
403 |
if (previous!=null){ |
404 |
GeneralPathX gpx=new GeneralPathX();
|
405 |
gpx.moveTo(previous.getX(),previous.getY()); |
406 |
gpx.lineTo(theData[0], theData[1]); |
407 |
IGeometry geom=ShapeFactory.createPolyline2D(gpx); |
408 |
Point2D p1=getNearPoint(previous);
|
409 |
Point2D p2=getDistantPoint(previous);
|
410 |
if (intersects(geom,p1)){
|
411 |
isFirstPart=false;
|
412 |
newGp1.lineTo(p1.getX(),p1.getY()); |
413 |
newGp2.moveTo(p2.getX(),p2.getY()); |
414 |
} |
415 |
} |
416 |
previous=new Point2D.Double(theData[0], theData[1]); |
417 |
if (isFirstPart)
|
418 |
newGp1.lineTo(theData[0], theData[1]); |
419 |
else
|
420 |
newGp2.lineTo(theData[0], theData[1]); |
421 |
break;
|
422 |
|
423 |
case PathIterator.SEG_QUADTO: |
424 |
if (previous!=null){ |
425 |
GeneralPathX gpx=new GeneralPathX();
|
426 |
gpx.moveTo(previous.getX(),previous.getY()); |
427 |
gpx.quadTo(theData[0], theData[1],theData[2], theData[3]); |
428 |
IGeometry geom=ShapeFactory.createPolyline2D(gpx); |
429 |
Point2D p1=getNearPoint(previous);
|
430 |
Point2D p2=getDistantPoint(previous);
|
431 |
if (intersects(geom,p1)){
|
432 |
isFirstPart=false;
|
433 |
newGp1.lineTo(p1.getX(),p1.getY()); |
434 |
newGp2.moveTo(p2.getX(),p2.getY()); |
435 |
} |
436 |
} |
437 |
previous=new Point2D.Double(theData[0], theData[1]); |
438 |
if (isFirstPart)
|
439 |
newGp1.quadTo(theData[0], theData[1],theData[2], theData[3]); |
440 |
else
|
441 |
newGp2.quadTo(theData[0], theData[1],theData[2], theData[3]); |
442 |
|
443 |
break;
|
444 |
|
445 |
case PathIterator.SEG_CUBICTO: |
446 |
if (previous!=null){ |
447 |
GeneralPathX gpx=new GeneralPathX();
|
448 |
gpx.moveTo(previous.getX(),previous.getY()); |
449 |
gpx.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]); |
450 |
IGeometry geom=ShapeFactory.createPolyline2D(gpx); |
451 |
Point2D p1=getNearPoint(previous);
|
452 |
Point2D p2=getDistantPoint(previous);
|
453 |
if (intersects(geom,p1)){
|
454 |
isFirstPart=false;
|
455 |
newGp1.lineTo(p1.getX(),p1.getY()); |
456 |
newGp2.moveTo(p2.getX(),p2.getY()); |
457 |
} |
458 |
} |
459 |
previous=new Point2D.Double(theData[0], theData[1]); |
460 |
if (isFirstPart)
|
461 |
newGp1.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]); |
462 |
else
|
463 |
newGp2.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]); |
464 |
|
465 |
break;
|
466 |
|
467 |
case PathIterator.SEG_CLOSE: |
468 |
//if (isFirstPart)
|
469 |
// newGp1.closePath();
|
470 |
//else
|
471 |
// newGp2.closePath();
|
472 |
break;
|
473 |
} //end switch
|
474 |
|
475 |
theIterator.next(); |
476 |
} //end while loop
|
477 |
IGeometry geom1=ShapeFactory.createPolyline2D(newGp1); |
478 |
IGeometry geom2=ShapeFactory.createPolyline2D(newGp2); |
479 |
VectorialLayerEdited vle = getVLE(); |
480 |
VectorialEditableAdapter vea = vle.getVEA(); |
481 |
int num=vea.getRowCount();
|
482 |
DefaultFeature df1 = new DefaultFeature(geom1, dre.getAttributes(),String.valueOf(num)); |
483 |
DefaultFeature df2 = new DefaultFeature(geom2, dre.getAttributes(),String.valueOf(num+1)); |
484 |
|
485 |
vea.startComplexRow(); |
486 |
vea.removeRow(dre.getIndex(),getName(),EditionEvent.GRAPHIC); |
487 |
int index1=vea.addRow(df1,PluginServices.getText(this,"parte1"),EditionEvent.GRAPHIC); |
488 |
int index2=vea.addRow(df2,PluginServices.getText(this,"parte2"),EditionEvent.GRAPHIC); |
489 |
vea.endComplexRow(); |
490 |
ViewPort vp=CADExtension.getEditionManager().getMapControl().getViewPort(); |
491 |
BufferedImage selectionImage = new BufferedImage(vp.getImageWidth(), vp.getImageHeight(), BufferedImage.TYPE_INT_ARGB); |
492 |
Graphics2D gs = selectionImage.createGraphics();
|
493 |
clearSelection(); |
494 |
ArrayList selectedRow = vle.getSelectedRow();
|
495 |
selectedRow.add(new DefaultRowEdited(df1, IRowEdited.STATUS_ADDED, index1));
|
496 |
selectedRow.add(new DefaultRowEdited(df2, IRowEdited.STATUS_ADDED, index2));
|
497 |
geom1.cloneGeometry().draw(gs, vp, CADTool.drawingSymbol); |
498 |
vle.drawHandlers(geom1.cloneGeometry(),gs,vp); |
499 |
geom2.cloneGeometry().draw(gs, vp, CADTool.drawingSymbol); |
500 |
vle.drawHandlers(geom2.cloneGeometry(),gs,vp); |
501 |
vea.setSelectionImage(selectionImage); |
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 |
} |