Revision 24363 branches/v2_0_0_prep/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/BreakCADTool.java

View differences:

BreakCADTool.java
73 73
import com.iver.cit.gvsig.gui.cad.tools.smc.BreakCADToolContext.BreakCADToolState;
74 74
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
75 75

  
76

  
77 76
/**
78 77
 * Recorta una polil?nea en dos partes.
79 78
 *
80 79
 * @author Vicente Caballero Navarro
81 80
 */
82 81
public class BreakCADTool extends DefaultCADTool {
83
    private BreakCADToolContext _fsm;
84
    private Point2D firstPoint;
85
    private Point2D secondPoint;
86
    private Feature rowEdited;
87
    /**
88
     * Crea un nuevo PolylineCADTool.
89
     */
90
    public BreakCADTool() {
91
    }
82
	private BreakCADToolContext _fsm;
83
	private Point2D firstPoint;
84
	private Point2D secondPoint;
85
	private Feature rowEdited;
92 86

  
93
    /**
94
     * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
95
     * carga previa a la utilizaci?n de la herramienta.
96
     */
97
    public void init() {
98
        _fsm = new BreakCADToolContext(this);
99
        firstPoint=null;
100
        secondPoint=null;
101
    }
87
	/**
88
	 * Crea un nuevo PolylineCADTool.
89
	 */
90
	public BreakCADTool() {
91
	}
102 92

  
103
    /* (non-Javadoc)
104
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double, double)
105
     */
106
    public void transition(double x, double y, InputEvent event) {
107
        _fsm.addPoint(x, y, event);
108
    }
93
	/**
94
	 * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
95
	 * carga previa a la utilizaci?n de la herramienta.
96
	 */
97
	public void init() {
98
		_fsm = new BreakCADToolContext(this);
99
		firstPoint = null;
100
		secondPoint = null;
101
	}
109 102

  
110
    /* (non-Javadoc)
111
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, double)
112
     */
113
    public void transition(double d) {
114
        _fsm.addValue(d);
115
    }
103
	/*
104
	 * (non-Javadoc)
105
	 *
106
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
107
	 *      double, double)
108
	 */
109
	public void transition(double x, double y, InputEvent event) {
110
		_fsm.addPoint(x, y, event);
111
	}
116 112

  
117
    /* (non-Javadoc)
118
     * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet, java.lang.String)
119
     */
120
    public void transition(String s) throws CommandException {
121
        if (!super.changeCommand(s)){
122
            _fsm.addOption(s);
123
        }
124
    }
113
	/*
114
	 * (non-Javadoc)
115
	 *
116
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
117
	 *      double)
118
	 */
119
	public void transition(double d) {
120
		_fsm.addValue(d);
121
	}
125 122

  
126
    /**
127
     * DOCUMENT ME!
128
     */
129
    public void selection() {
130
        FeatureSet selection=null;
123
	/*
124
	 * (non-Javadoc)
125
	 *
126
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
127
	 *      java.lang.String)
128
	 */
129
	public void transition(String s) throws CommandException {
130
		if (!super.changeCommand(s)) {
131
			_fsm.addOption(s);
132
		}
133
	}
134

  
135
	/**
136
	 * DOCUMENT ME!
137
	 */
138
	public void selection() {
139
		FeatureSet selection = null;
131 140
		try {
132
			selection = (FeatureSet)getVLE().getFeatureStore().getSelection();
141
			selection = (FeatureSet) getVLE().getFeatureStore().getSelection();
133 142

  
134
        if (selection.getSize() == 0 && !CADExtension.getCADTool().getClass().getName().equals("com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
135
            CADExtension.setCADTool("_selection",false);
136
            ((SelectionCADTool) CADExtension.getCADTool()).setNextTool(
137
                "_break");
138
        }
143
			if (selection.getSize() == 0
144
					&& !CADExtension
145
							.getCADTool()
146
							.getClass()
147
							.getName()
148
							.equals(
149
									"com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool")) {
150
				CADExtension.setCADTool("_selection", false);
151
				((SelectionCADTool) CADExtension.getCADTool())
152
						.setNextTool("_break");
153
			}
139 154
		} catch (ReadException e) {
140 155
			// TODO Auto-generated catch block
141 156
			e.printStackTrace();
......
143 158
			// TODO Auto-generated catch block
144 159
			e.printStackTrace();
145 160
		}
146
    }
161
	}
147 162

  
148
    /**
149
     * Equivale al transition del prototipo pero sin pasarle como par?metro el
150
     * editableFeatureSource que ya estar? creado.
151
     *
152
     * @param x par?metro x del punto que se pase en esta transici?n.
153
     * @param y par?metro y del punto que se pase en esta transici?n.
154
     */
155
    public void addPoint(double x, double y,InputEvent event) {
156
    	BreakCADToolState actualState = (BreakCADToolState) _fsm.getPreviousState();
157
    	String status = actualState.getName();
163
	/**
164
	 * Equivale al transition del prototipo pero sin pasarle como par?metro el
165
	 * editableFeatureSource que ya estar? creado.
166
	 *
167
	 * @param x
168
	 *            par?metro x del punto que se pase en esta transici?n.
169
	 * @param y
170
	 *            par?metro y del punto que se pase en esta transici?n.
171
	 */
172
	public void addPoint(double x, double y, InputEvent event) {
173
		BreakCADToolState actualState = (BreakCADToolState) _fsm
174
				.getPreviousState();
175
		String status = actualState.getName();
158 176

  
159
    	if (status.equals("Break.FirstPoint")) {
160
    		// if (rowEdited!=null && intersects(((DefaultFeature)rowEdited.getLinkedRow()).getGeometry(),new Point2D.Double(x,y)))
161
    		firstPoint=new Point2D.Double(x,y);
177
		if (status.equals("Break.FirstPoint")) {
178
			// if (rowEdited!=null &&
179
			// intersects(((DefaultFeature)rowEdited.getLinkedRow()).getGeometry(),new
180
			// Point2D.Double(x,y)))
181
			firstPoint = new Point2D.Double(x, y);
162 182

  
163
    	} else if (status.equals("Break.SecondPoint")) {
164
    		// if (rowEdited !=null && intersects(((DefaultFeature)rowEdited.getLinkedRow()).getGeometry(),new Point2D.Double(x,y))){
165
    		secondPoint=new Point2D.Double(x,y);
166
    		try {
167
//  			IGeometry geom=((DefaultFeature)rowEdited.getLinkedRow()).getGeometry();
168
//  			if (geom instanceof FGeometryCollection) {
169
//  			breakGeometryGC(rowEdited);
170
//  			}else {
171
    			breakGeometry(rowEdited);
172
//  			}
173
    		} catch (ReadException e) {
174
    			NotificationManager.addError(e.getMessage(),e);
175
    		}
176
    	}
177
    	//}
178
    }
179
  /*  private void breakGeometryGC(DefaultRowEdited dre) throws IOException, DriverIOException {
180
        GeneralPathX newGp1 = new GeneralPathX();
181
        GeneralPathX newGp2 = new GeneralPathX();
182
        FGeometryCollection gc=(FGeometryCollection)((DefaultFeature)rowEdited.getLinkedRow()).getGeometry();
183
        IGeometry[] geoms=gc.getGeometries();
184
        for (int i = 0;i<geoms.length;i++) {
185
            PathIterator theIterator=geoms[i].getPathIterator(null);
186
            double[] theData = new double[6];
187
            boolean isFirstPart=true;
188
            boolean isCut=false;
189
            int theType;
190
            int numParts = 0;
183
		} else if (status.equals("Break.SecondPoint")) {
184
			// if (rowEdited !=null &&
185
			// intersects(((DefaultFeature)rowEdited.getLinkedRow()).getGeometry(),new
186
			// Point2D.Double(x,y))){
187
			secondPoint = new Point2D.Double(x, y);
188
			try {
189
				// IGeometry
190
				// geom=((DefaultFeature)rowEdited.getLinkedRow()).getGeometry();
191
				// if (geom instanceof FGeometryCollection) {
192
				// breakGeometryGC(rowEdited);
193
				// }else {
194
				breakGeometry(rowEdited);
195
				// }
196
			} catch (ReadException e) {
197
				NotificationManager.addError(e.getMessage(), e);
198
			}
199
		}
200
		// }
201
	}
191 202

  
192
            Point2D previous=null;
203
	/*
204
	 * private void breakGeometryGC(DefaultRowEdited dre) throws IOException,
205
	 * DriverIOException { GeneralPathX newGp1 = new GeneralPathX();
206
	 * GeneralPathX newGp2 = new GeneralPathX(); FGeometryCollection
207
	 * gc=(FGeometryCollection)((DefaultFeature)rowEdited.getLinkedRow()).getGeometry();
208
	 * IGeometry[] geoms=gc.getGeometries(); for (int i = 0;i<geoms.length;i++) {
209
	 * PathIterator theIterator=geoms[i].getPathIterator(null); double[] theData =
210
	 * new double[6]; boolean isFirstPart=true; boolean isCut=false; int
211
	 * theType; int numParts = 0;
212
	 *
213
	 * Point2D previous=null;
214
	 *
215
	 * while (!theIterator.isDone()) { theType =
216
	 * theIterator.currentSegment(theData); switch (theType) {
217
	 *
218
	 * case PathIterator.SEG_MOVETO: numParts++; previous=new
219
	 * Point2D.Double(theData[0], theData[1]); if (isFirstPart)
220
	 * newGp1.moveTo(theData[0], theData[1]); else newGp2.moveTo(theData[0],
221
	 * theData[1]); break;
222
	 *
223
	 * case PathIterator.SEG_LINETO: if (previous!=null){ GeneralPathX gpx=new
224
	 * GeneralPathX(); gpx.moveTo(previous.getX(),previous.getY());
225
	 * gpx.lineTo(theData[0], theData[1]); IGeometry
226
	 * geom=ShapeFactory.createPolyline2D(gpx); Point2D
227
	 * p1=getNearPoint(previous); Point2D p2=getDistantPoint(previous); if
228
	 * (intersects(geom,p1)){ isFirstPart=false;
229
	 * newGp1.lineTo(p1.getX(),p1.getY()); newGp2.moveTo(p2.getX(),p2.getY());
230
	 * isCut=true; } } previous=new Point2D.Double(theData[0], theData[1]); if
231
	 * (isFirstPart) newGp1.lineTo(theData[0], theData[1]); else
232
	 * newGp2.lineTo(theData[0], theData[1]); break;
233
	 *
234
	 * case PathIterator.SEG_QUADTO: if (previous!=null){ GeneralPathX gpx=new
235
	 * GeneralPathX(); gpx.moveTo(previous.getX(),previous.getY());
236
	 * gpx.quadTo(theData[0], theData[1],theData[2], theData[3]); IGeometry
237
	 * geom=ShapeFactory.createPolyline2D(gpx); Point2D
238
	 * p1=getNearPoint(previous); Point2D p2=getDistantPoint(previous); if
239
	 * (intersects(geom,p1)){ isFirstPart=false;
240
	 * newGp1.lineTo(p1.getX(),p1.getY()); newGp2.moveTo(p2.getX(),p2.getY());
241
	 * isCut=true; } } previous=new Point2D.Double(theData[0], theData[1]); if
242
	 * (isFirstPart) newGp1.quadTo(theData[0], theData[1],theData[2],
243
	 * theData[3]); else newGp2.quadTo(theData[0], theData[1],theData[2],
244
	 * theData[3]);
245
	 *
246
	 * break;
247
	 *
248
	 * case PathIterator.SEG_CUBICTO: if (previous!=null){ GeneralPathX gpx=new
249
	 * GeneralPathX(); gpx.moveTo(previous.getX(),previous.getY());
250
	 * gpx.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4],
251
	 * theData[5]); IGeometry geom=ShapeFactory.createPolyline2D(gpx); Point2D
252
	 * p1=getNearPoint(previous); Point2D p2=getDistantPoint(previous); if
253
	 * (intersects(geom,p1)){ isFirstPart=false;
254
	 * newGp1.lineTo(p1.getX(),p1.getY()); newGp2.moveTo(p2.getX(),p2.getY());
255
	 * isCut=true; } } previous=new Point2D.Double(theData[0], theData[1]); if
256
	 * (isFirstPart) newGp1.curveTo(theData[0], theData[1],theData[2],
257
	 * theData[3],theData[4], theData[5]); else newGp2.curveTo(theData[0],
258
	 * theData[1],theData[2], theData[3],theData[4], theData[5]);
259
	 *
260
	 * break;
261
	 *
262
	 * case PathIterator.SEG_CLOSE: //if (isFirstPart) // newGp1.closePath();
263
	 * //else // newGp2.closePath(); break; } //end switch
264
	 *
265
	 * theIterator.next(); } //end while loop
266
	 *
267
	 * if (isCut) { IGeometry geom1 = ShapeFactory.createPolyline2D(newGp1);
268
	 * IGeometry geom2 = ShapeFactory.createPolyline2D(newGp2);
269
	 * VectorialLayerEdited vle = getVLE(); VectorialEditableAdapter vea =
270
	 * vle.getVEA(); ArrayList selectedRow = vle.getSelectedRow();
271
	 * vea.startComplexRow(); vea.removeRow(dre.getIndex(), getName(),
272
	 * EditionEvent.GRAPHIC); int num = vea.getRowCount(); if (gc.isClosed()) {
273
	 * ArrayList geomsAux1 = new ArrayList(); geomsAux1.add(geom2); for (int k =
274
	 * i + 1; k < geoms.length; k++) { geomsAux1.add(geoms[k]); } for (int k =
275
	 * 0; k < i; k++) { geomsAux1.add(geoms[k]); } geomsAux1.add(geom1);
276
	 *
277
	 * DefaultFeature df1 = new DefaultFeature( new
278
	 * FGeometryCollection((IGeometry[]) geomsAux1 .toArray(new IGeometry[0])),
279
	 * dre .getAttributes(), String.valueOf(num)); int index1 = vea.addRow(df1,
280
	 * PluginServices.getText(this, "parte1"), EditionEvent.GRAPHIC);
281
	 *
282
	 * clearSelection(); selectedRow.add(new DefaultRowEdited(df1,
283
	 * IRowEdited.STATUS_ADDED, index1)); vea.endComplexRow(); return; }else {
284
	 *
285
	 * ArrayList geomsAux1 = new ArrayList(); for (int k = 0; k < i; k++) {
286
	 * geomsAux1.add(geoms[k]); } geomsAux1.add(geom1);
287
	 *
288
	 * ArrayList geomsAux2 = new ArrayList(); geomsAux2.add(geom2); for (int k =
289
	 * i + 1; k < geoms.length; k++) { geomsAux2.add(geoms[k]); }
290
	 *
291
	 * DefaultFeature df1 = new DefaultFeature( new
292
	 * FGeometryCollection((IGeometry[]) geomsAux1 .toArray(new IGeometry[0])),
293
	 * dre .getAttributes(), String.valueOf(num)); int index1 = vea.addRow(df1,
294
	 * PluginServices.getText(this, "parte1"), EditionEvent.GRAPHIC);
295
	 * DefaultFeature df2 = new DefaultFeature( new
296
	 * FGeometryCollection((IGeometry[]) geomsAux2 .toArray(new IGeometry[0])),
297
	 * dre .getAttributes(), String.valueOf(num + 1)); int index2 =
298
	 * vea.addRow(df2, PluginServices.getText(this, "parte2"),
299
	 * EditionEvent.GRAPHIC); clearSelection(); selectedRow.add(new
300
	 * DefaultRowEdited(df2, IRowEdited.STATUS_ADDED, index2));
301
	 * selectedRow.add(new DefaultRowEdited(df1, IRowEdited.STATUS_ADDED,
302
	 * index1));
303
	 *
304
	 * vea.endComplexRow(); return; }
305
	 *  } } }
306
	 */
193 307

  
194
            while (!theIterator.isDone()) {
195
                theType = theIterator.currentSegment(theData);
196
                switch (theType) {
308
	private void breakGeometry(Feature dre) throws ReadException {
309
		breakGeom(dre);
310
	}
197 311

  
198
                    case PathIterator.SEG_MOVETO:
199
                        numParts++;
200
                        previous=new Point2D.Double(theData[0], theData[1]);
201
                        if (isFirstPart)
202
                            newGp1.moveTo(theData[0], theData[1]);
203
                        else
204
                            newGp2.moveTo(theData[0], theData[1]);
205
                        break;
206

  
207
                    case PathIterator.SEG_LINETO:
208
                         if (previous!=null){
209
                                GeneralPathX gpx=new GeneralPathX();
210
                                gpx.moveTo(previous.getX(),previous.getY());
211
                                gpx.lineTo(theData[0], theData[1]);
212
                                IGeometry geom=ShapeFactory.createPolyline2D(gpx);
213
                                Point2D p1=getNearPoint(previous);
214
                                Point2D p2=getDistantPoint(previous);
215
                                if (intersects(geom,p1)){
216
                                    isFirstPart=false;
217
                                    newGp1.lineTo(p1.getX(),p1.getY());
218
                                    newGp2.moveTo(p2.getX(),p2.getY());
219
                                    isCut=true;
220
                                }
221
                            }
222
                         previous=new Point2D.Double(theData[0], theData[1]);
223
                        if (isFirstPart)
224
                            newGp1.lineTo(theData[0], theData[1]);
225
                        else
226
                            newGp2.lineTo(theData[0], theData[1]);
227
                        break;
228

  
229
                    case PathIterator.SEG_QUADTO:
230
                         if (previous!=null){
231
                                GeneralPathX gpx=new GeneralPathX();
232
                                gpx.moveTo(previous.getX(),previous.getY());
233
                                gpx.quadTo(theData[0], theData[1],theData[2], theData[3]);
234
                                IGeometry geom=ShapeFactory.createPolyline2D(gpx);
235
                                Point2D p1=getNearPoint(previous);
236
                                Point2D p2=getDistantPoint(previous);
237
                                if (intersects(geom,p1)){
238
                                    isFirstPart=false;
239
                                    newGp1.lineTo(p1.getX(),p1.getY());
240
                                    newGp2.moveTo(p2.getX(),p2.getY());
241
                                    isCut=true;
242
                                }
243
                            }
244
                         previous=new Point2D.Double(theData[0], theData[1]);
245
                        if (isFirstPart)
246
                            newGp1.quadTo(theData[0], theData[1],theData[2], theData[3]);
247
                        else
248
                            newGp2.quadTo(theData[0], theData[1],theData[2], theData[3]);
249

  
250
                        break;
251

  
252
                    case PathIterator.SEG_CUBICTO:
253
                         if (previous!=null){
254
                                GeneralPathX gpx=new GeneralPathX();
255
                                gpx.moveTo(previous.getX(),previous.getY());
256
                                gpx.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]);
257
                                IGeometry geom=ShapeFactory.createPolyline2D(gpx);
258
                                Point2D p1=getNearPoint(previous);
259
                                Point2D p2=getDistantPoint(previous);
260
                                if (intersects(geom,p1)){
261
                                    isFirstPart=false;
262
                                    newGp1.lineTo(p1.getX(),p1.getY());
263
                                    newGp2.moveTo(p2.getX(),p2.getY());
264
                                    isCut=true;
265
                                }
266
                            }
267
                         previous=new Point2D.Double(theData[0], theData[1]);
268
                        if (isFirstPart)
269
                            newGp1.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]);
270
                        else
271
                            newGp2.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]);
272

  
273
                        break;
274

  
275
                    case PathIterator.SEG_CLOSE:
276
                        //if (isFirstPart)
277
                        //	newGp1.closePath();
278
                        //else
279
                        //	newGp2.closePath();
280
                        break;
281
                } //end switch
282

  
283
                theIterator.next();
284
            } //end while loop
285

  
286
            if (isCut) {
287
                IGeometry geom1 = ShapeFactory.createPolyline2D(newGp1);
288
                IGeometry geom2 = ShapeFactory.createPolyline2D(newGp2);
289
                VectorialLayerEdited vle = getVLE();
290
                VectorialEditableAdapter vea = vle.getVEA();
291
                ArrayList selectedRow = vle.getSelectedRow();
292
                vea.startComplexRow();
293
                vea.removeRow(dre.getIndex(), getName(), EditionEvent.GRAPHIC);
294
                int num = vea.getRowCount();
295
                if (gc.isClosed()) {
296
                    ArrayList geomsAux1 = new ArrayList();
297
                    geomsAux1.add(geom2);
298
                    for (int k = i + 1; k < geoms.length; k++) {
299
                        geomsAux1.add(geoms[k]);
300
                    }
301
                    for (int k = 0; k < i; k++) {
302
                        geomsAux1.add(geoms[k]);
303
                    }
304
                    geomsAux1.add(geom1);
305

  
306
                    DefaultFeature df1 = new DefaultFeature(
307
                            new FGeometryCollection((IGeometry[]) geomsAux1
308
                                    .toArray(new IGeometry[0])), dre
309
                                    .getAttributes(), String.valueOf(num));
310
                    int index1 = vea.addRow(df1, PluginServices.getText(this,
311
                            "parte1"), EditionEvent.GRAPHIC);
312

  
313
                    clearSelection();
314
                    selectedRow.add(new DefaultRowEdited(df1,
315
                            IRowEdited.STATUS_ADDED, index1));
316
                    vea.endComplexRow();
317
                    return;
318
                }else {
319

  
320
                    ArrayList geomsAux1 = new ArrayList();
321
                    for (int k = 0; k < i; k++) {
322
                        geomsAux1.add(geoms[k]);
323
                    }
324
                    geomsAux1.add(geom1);
325

  
326
                    ArrayList geomsAux2 = new ArrayList();
327
                    geomsAux2.add(geom2);
328
                    for (int k = i + 1; k < geoms.length; k++) {
329
                        geomsAux2.add(geoms[k]);
330
                    }
331

  
332
                    DefaultFeature df1 = new DefaultFeature(
333
                            new FGeometryCollection((IGeometry[]) geomsAux1
334
                                    .toArray(new IGeometry[0])), dre
335
                                    .getAttributes(), String.valueOf(num));
336
                    int index1 = vea.addRow(df1, PluginServices.getText(this,
337
                            "parte1"), EditionEvent.GRAPHIC);
338
                    DefaultFeature df2 = new DefaultFeature(
339
                            new FGeometryCollection((IGeometry[]) geomsAux2
340
                                .toArray(new IGeometry[0])), dre
341
                                .getAttributes(), String.valueOf(num + 1));
342
                    int index2 = vea.addRow(df2, PluginServices.getText(this,
343
                        "parte2"), EditionEvent.GRAPHIC);
344
                    clearSelection();
345
                    selectedRow.add(new DefaultRowEdited(df2,
346
                            IRowEdited.STATUS_ADDED, index2));
347
                    selectedRow.add(new DefaultRowEdited(df1,
348
                            IRowEdited.STATUS_ADDED, index1));
349

  
350
                    vea.endComplexRow();
351
                    return;
352
                }
353

  
354
            }
355
        }
356
    }
357
*/
358

  
359
    private void breakGeometry(Feature dre) throws ReadException {
360
        breakGeom(dre);
361
    }
362

  
363

  
364 312
	private void breakGeom(Feature dre) throws ReadException {
365
    	GeneralPathX newGp1 = new GeneralPathX();
366
        GeneralPathX newGp2 = new GeneralPathX();
367
        Geometry geomAux=(Geometry)rowEdited.getDefaultGeometry();
368
    	PathIterator theIterator=geomAux.getPathIterator(null,Converter.FLATNESS);
369
        Point2D[] pointsOrdered=getOrderPoints(geomAux);
370
        double[] theData = new double[6];
371
        boolean isFirstPart=true;
372
        boolean intersectsP2=false;
373
        int theType;
374
        int numParts = 0;
375
        boolean isBreaked=false;
376
        Point2D previous=null;
313
		GeneralPathX newGp1 = new GeneralPathX();
314
		GeneralPathX newGp2 = new GeneralPathX();
315
		Geometry geomAux = (Geometry) rowEdited.getDefaultGeometry();
316
		PathIterator theIterator = geomAux.getPathIterator(null,
317
				Converter.FLATNESS);
318
		Point2D[] pointsOrdered = getOrderPoints(geomAux);
319
		double[] theData = new double[6];
320
		boolean isFirstPart = true;
321
		boolean intersectsP2 = false;
322
		int theType;
323
		int numParts = 0;
324
		boolean isBreaked = false;
325
		Point2D previous = null;
377 326

  
378
            while (!theIterator.isDone()) {
379
                theType = theIterator.currentSegment(theData);
380
                switch (theType) {
327
		while (!theIterator.isDone()) {
328
			theType = theIterator.currentSegment(theData);
329
			switch (theType) {
381 330

  
382
                    case PathIterator.SEG_MOVETO:
383
                        numParts++;
331
			case PathIterator.SEG_MOVETO:
332
				numParts++;
384 333

  
385
                        previous=new Point2D.Double(theData[0], theData[1]);
334
				previous = new Point2D.Double(theData[0], theData[1]);
386 335

  
387
                        if (isFirstPart)
388
                            newGp1.moveTo(theData[0], theData[1]);
389
                        else
390
                            newGp2.moveTo(theData[0], theData[1]);
391
                        break;
336
				if (isFirstPart)
337
					newGp1.moveTo(theData[0], theData[1]);
338
				else
339
					newGp2.moveTo(theData[0], theData[1]);
340
				break;
392 341

  
393
                    case PathIterator.SEG_LINETO:
342
			case PathIterator.SEG_LINETO:
394 343

  
395
                        if (previous!=null){
396
                                GeneralPathX gpx=new GeneralPathX();
397
                                gpx.moveTo(previous.getX(),previous.getY());
398
                                gpx.lineTo(theData[0], theData[1]);
399
                                Geometry geom=geomFactory.createPolyline2D(gpx);
400
                                Point2D p1=pointsOrdered[0];
401
                                Point2D p2=pointsOrdered[1];
344
				if (previous != null) {
345
					GeneralPathX gpx = new GeneralPathX();
346
					gpx.moveTo(previous.getX(), previous.getY());
347
					gpx.lineTo(theData[0], theData[1]);
348
					Geometry geom = geomFactory.createPolyline2D(gpx);
349
					Point2D p1 = pointsOrdered[0];
350
					Point2D p2 = pointsOrdered[1];
402 351

  
403
                                if (intersects(geom,p1) && !isBreaked){
404
                                	isFirstPart=false;
405
                                    newGp1.lineTo(p1.getX(),p1.getY());
406
                                }
407
                                if (intersects(geom,p2) && !isBreaked) {
408
                                	isBreaked=true;
409
                                    intersectsP2=true;
410
                                    newGp2.moveTo(p2.getX(),p2.getY());
411
                                }
412
                            }
413
                         previous=new Point2D.Double(theData[0], theData[1]);
414
                        if (isFirstPart)
415
                            newGp1.lineTo(theData[0], theData[1]);
416
                        else if (intersectsP2){
417
                            newGp2.lineTo(theData[0], theData[1]);
418
                        }
352
					if (intersects(geom, p1) && !isBreaked) {
353
						isFirstPart = false;
354
						newGp1.lineTo(p1.getX(), p1.getY());
355
					}
356
					if (intersects(geom, p2) && !isBreaked) {
357
						isBreaked = true;
358
						intersectsP2 = true;
359
						newGp2.moveTo(p2.getX(), p2.getY());
360
					}
361
				}
362
				previous = new Point2D.Double(theData[0], theData[1]);
363
				if (isFirstPart)
364
					newGp1.lineTo(theData[0], theData[1]);
365
				else if (intersectsP2) {
366
					newGp2.lineTo(theData[0], theData[1]);
367
				}
419 368

  
420
                        break;
369
				break;
421 370

  
422
                    case PathIterator.SEG_QUADTO:
423
                         if (previous!=null){
424
                                GeneralPathX gpx=new GeneralPathX();
425
                                gpx.moveTo(previous.getX(),previous.getY());
426
                                gpx.quadTo(theData[0], theData[1],theData[2], theData[3]);
427
                                Geometry geom=geomFactory.createPolyline2D(gpx);
428
                                Point2D p1=pointsOrdered[0];
429
                                Point2D p2=pointsOrdered[1];
430
                                if (intersects(geom,p1) && !isBreaked){
431
                                	isFirstPart=false;
432
                                    newGp1.lineTo(p1.getX(),p1.getY());
433
                                }
434
                                if (intersects(geom,p2) && !isBreaked) {
435
                                	isBreaked=true;
436
                                    intersectsP2=true;
437
                                    newGp2.moveTo(p2.getX(),p2.getY());
371
			case PathIterator.SEG_QUADTO:
372
				if (previous != null) {
373
					GeneralPathX gpx = new GeneralPathX();
374
					gpx.moveTo(previous.getX(), previous.getY());
375
					gpx.quadTo(theData[0], theData[1], theData[2], theData[3]);
376
					Geometry geom = geomFactory.createPolyline2D(gpx);
377
					Point2D p1 = pointsOrdered[0];
378
					Point2D p2 = pointsOrdered[1];
379
					if (intersects(geom, p1) && !isBreaked) {
380
						isFirstPart = false;
381
						newGp1.lineTo(p1.getX(), p1.getY());
382
					}
383
					if (intersects(geom, p2) && !isBreaked) {
384
						isBreaked = true;
385
						intersectsP2 = true;
386
						newGp2.moveTo(p2.getX(), p2.getY());
438 387

  
439
                                }
440
                            }
441
                         previous=new Point2D.Double(theData[0], theData[1]);
442
                        if (isFirstPart)
443
                            newGp1.quadTo(theData[0], theData[1],theData[2], theData[3]);
444
                        else
445
                            newGp2.quadTo(theData[0], theData[1],theData[2], theData[3]);
388
					}
389
				}
390
				previous = new Point2D.Double(theData[0], theData[1]);
391
				if (isFirstPart)
392
					newGp1.quadTo(theData[0], theData[1], theData[2],
393
							theData[3]);
394
				else
395
					newGp2.quadTo(theData[0], theData[1], theData[2],
396
							theData[3]);
446 397

  
447
                        break;
398
				break;
448 399

  
449
                    case PathIterator.SEG_CUBICTO:
450
                         if (previous!=null){
451
                                GeneralPathX gpx=new GeneralPathX();
452
                                gpx.moveTo(previous.getX(),previous.getY());
453
                                gpx.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]);
454
                                Geometry geom=geomFactory.createPolyline2D(gpx);
455
                                Point2D p1=pointsOrdered[0];
456
                                Point2D p2=pointsOrdered[1];
457
                                if (intersects(geom,p1) && !isBreaked){
458
                                	isFirstPart=false;
459
                                    newGp1.lineTo(p1.getX(),p1.getY());
460
                                }
461
                                if (intersects(geom,p2) && !isBreaked) {
462
                                	isBreaked=true;
463
                                    intersectsP2=true;
464
                                    newGp2.moveTo(p2.getX(),p2.getY());
400
			case PathIterator.SEG_CUBICTO:
401
				if (previous != null) {
402
					GeneralPathX gpx = new GeneralPathX();
403
					gpx.moveTo(previous.getX(), previous.getY());
404
					gpx.curveTo(theData[0], theData[1], theData[2], theData[3],
405
							theData[4], theData[5]);
406
					Geometry geom = geomFactory.createPolyline2D(gpx);
407
					Point2D p1 = pointsOrdered[0];
408
					Point2D p2 = pointsOrdered[1];
409
					if (intersects(geom, p1) && !isBreaked) {
410
						isFirstPart = false;
411
						newGp1.lineTo(p1.getX(), p1.getY());
412
					}
413
					if (intersects(geom, p2) && !isBreaked) {
414
						isBreaked = true;
415
						intersectsP2 = true;
416
						newGp2.moveTo(p2.getX(), p2.getY());
465 417

  
466
                                }
467
                          }
468
                         previous=new Point2D.Double(theData[0], theData[1]);
469
                        if (isFirstPart)
470
                            newGp1.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]);
471
                        else
472
                            newGp2.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]);
418
					}
419
				}
420
				previous = new Point2D.Double(theData[0], theData[1]);
421
				if (isFirstPart)
422
					newGp1.curveTo(theData[0], theData[1], theData[2],
423
							theData[3], theData[4], theData[5]);
424
				else
425
					newGp2.curveTo(theData[0], theData[1], theData[2],
426
							theData[3], theData[4], theData[5]);
473 427

  
474
                        break;
428
				break;
475 429

  
476
                    case PathIterator.SEG_CLOSE:
477
                        //if (isFirstPart)
478
                        //	newGp1.closePath();
479
                        //else
480
                        //	newGp2.closePath();
481
                        break;
482
                } //end switch
430
			case PathIterator.SEG_CLOSE:
431
				// if (isFirstPart)
432
				// newGp1.closePath();
433
				// else
434
				// newGp2.closePath();
435
				break;
436
			} // end switch
483 437

  
484
                theIterator.next();
485
            } //end while loop
486
            GeneralPathX gpx=new GeneralPathX();
487
            gpx.append(geomAux.getInternalShape(),true);
488
            VectorialLayerEdited vle = getVLE();
489
            FeatureStore featureStore=((FLyrVect)vle.getLayer()).getFeatureStore();
490
//            VectorialEditableAdapter vea = vle.getVEA();
491
            ArrayList selectedRowAux=new ArrayList();
492
            featureStore.beginEditingGroup(getName());
493
            try {
494
            featureStore.delete(dre);
495
//            vea.startComplexRow();
496
            if (gpx.isClosed()) {
438
			theIterator.next();
439
		} // end while loop
440
		GeneralPathX gpx = new GeneralPathX();
441
		gpx.append(geomAux.getInternalShape(), true);
442
		VectorialLayerEdited vle = getVLE();
443
		FeatureStore featureStore = ((FLyrVect) vle.getLayer())
444
				.getFeatureStore();
445
		// VectorialEditableAdapter vea = vle.getVEA();
446
		ArrayList selectedRowAux = new ArrayList();
447
		try {
448
			featureStore.beginEditingGroup(getName());
497 449

  
498
                newGp2.append(newGp1.getPathIterator(null,Converter.FLATNESS),true);
499
                Geometry geom1=geomFactory.createPolyline2D(newGp2);
450
			featureStore.delete(dre);
451
			// vea.startComplexRow();
452
			if (gpx.isClosed()) {
500 453

  
501
//                Feature dfLine1 = dre.cloneRow();
502
	            EditableFeature eFeature=featureStore.createNewFeature(dre.getType(),dre);
503
				eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),geom1);
454
				newGp2.append(newGp1.getPathIterator(null, Converter.FLATNESS),
455
						true);
456
				Geometry geom1 = geomFactory.createPolyline2D(newGp2);
457

  
458
				// Feature dfLine1 = dre.cloneRow();
459
				EditableFeature eFeature = featureStore.createNewFeature(dre
460
						.getType(), dre);
461
				eFeature.setGeometry(featureStore.getDefaultFeatureType()
462
						.getDefaultGeometryAttributeName(), geom1);
504 463
				selectedRowAux.add(eFeature);
505 464

  
506
			 }else {
507
	            Geometry geom1=geomFactory.createPolyline2D(newGp1);
508
	            Geometry geom2=geomFactory.createPolyline2D(newGp2);
465
			} else {
466
				Geometry geom1 = geomFactory.createPolyline2D(newGp1);
467
				Geometry geom2 = geomFactory.createPolyline2D(newGp2);
509 468

  
510
//	            DefaultFeature dfLine1 = (DefaultFeature) dre.getLinkedRow().cloneRow();
511
	            EditableFeature eFeature=featureStore.createNewFeature(dre.getType(),dre);
512
				eFeature.setGeometry(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),geom2);
469
				// DefaultFeature dfLine1 = (DefaultFeature)
470
				// dre.getLinkedRow().cloneRow();
471
				EditableFeature eFeature = featureStore.createNewFeature(dre
472
						.getType(), dre);
473
				eFeature.setGeometry(featureStore.getDefaultFeatureType()
474
						.getDefaultGeometryAttributeName(), geom2);
513 475

  
514 476
				selectedRowAux.add(eFeature);
515 477

  
516
//				dre.editing();
517
//				dre.setGeometry(geom2);
518
//				DefaultFeature dfLine2 = (DefaultFeature) dre.getLinkedRow().cloneRow();
519
//		        dfLine2.setGeometry(geom2);
520
//				int indexLine2 = addGeometry(dre);
478
				// dre.editing();
479
				// dre.setGeometry(geom2);
480
				// DefaultFeature dfLine2 = (DefaultFeature)
481
				// dre.getLinkedRow().cloneRow();
482
				// dfLine2.setGeometry(geom2);
483
				// int indexLine2 = addGeometry(dre);
521 484

  
522
//				selectedRowAux.add(new DefaultRowEdited(dfLine2,
523
//							IRowEdited.STATUS_ADDED, indexLine2));
485
				// selectedRowAux.add(new DefaultRowEdited(dfLine2,
486
				// IRowEdited.STATUS_ADDED, indexLine2));
524 487

  
525
            }
526
            } catch (DataException e) {
527
				// TODO Auto-generated catch block
528
				e.printStackTrace();
529 488
			}
530
//            vea.removeRow(dre.getIndex(), getName(), EditionEvent.GRAPHIC);
531
//  			vea.endComplexRow(getName());
532
            featureStore.endEditingGroup();
533
//			vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS, selectedRowAux);
534 489

  
535
    }
490
			// vea.removeRow(dre.getIndex(), getName(), EditionEvent.GRAPHIC);
491
			// vea.endComplexRow(getName());
492
			featureStore.endEditingGroup();
493
		} catch (DataException e) {
494
			// TODO Auto-generated catch block
495
			e.printStackTrace();
496
		}
497
		// vle.setSelectionCache(VectorialLayerEdited.NOTSAVEPREVIOUS,
498
		// selectedRowAux);
536 499

  
500
	}
537 501

  
538
    private Point2D[] getOrderPoints(Geometry geomAux) {
539
    	PathIterator theIterator=geomAux.getPathIterator(null,Converter.FLATNESS);
540
    	double[] theData = new double[6];
541
        Point2D previous=null;
542
        ArrayList points =new ArrayList();
543
        boolean isFirstPointBreak=false;
544
        boolean isSecondPointBreak=false;
545
        while (!theIterator.isDone()) {
546
            int theType = theIterator.currentSegment(theData);
547
            switch (theType) {
502
	private Point2D[] getOrderPoints(Geometry geomAux) {
503
		PathIterator theIterator = geomAux.getPathIterator(null,
504
				Converter.FLATNESS);
505
		double[] theData = new double[6];
506
		Point2D previous = null;
507
		ArrayList points = new ArrayList();
508
		boolean isFirstPointBreak = false;
509
		boolean isSecondPointBreak = false;
510
		while (!theIterator.isDone()) {
511
			int theType = theIterator.currentSegment(theData);
512
			switch (theType) {
548 513

  
549
                case PathIterator.SEG_MOVETO:
550
                    previous=new Point2D.Double(theData[0], theData[1]);
551
                    break;
514
			case PathIterator.SEG_MOVETO:
515
				previous = new Point2D.Double(theData[0], theData[1]);
516
				break;
552 517

  
553
                case PathIterator.SEG_LINETO:
518
			case PathIterator.SEG_LINETO:
554 519

  
555
                    if (previous!=null){
556
                            GeneralPathX gpx=new GeneralPathX();
557
                            gpx.moveTo(previous.getX(),previous.getY());
558
                            gpx.lineTo(theData[0], theData[1]);
559
                            Geometry geom=geomFactory.createPolyline2D(gpx);
560
                            boolean intersectFirst=intersects(geom,firstPoint);
561
                            boolean intersectSecond=intersects(geom,secondPoint);
562
                            if (intersectFirst && intersectSecond && !isFirstPointBreak){
563
                            	isFirstPointBreak=true;
564
                            	isSecondPointBreak=true;
565
                            	points.add(getNearPoint(previous));
566
                                points.add(getDistantPoint(previous));
567
                                return (Point2D[])points.toArray(new Point2D[0]);
568
                            }else if (intersectFirst && !isFirstPointBreak) {
569
                            	isFirstPointBreak=true;
570
                                points.add(firstPoint);
571
                            }else if (intersectSecond && !isSecondPointBreak) {
572
                            	isSecondPointBreak=true;
573
                            	points.add(secondPoint);
574
                            }
575
                        }
576
                     previous=new Point2D.Double(theData[0], theData[1]);
577
                                      break;
520
				if (previous != null) {
521
					GeneralPathX gpx = new GeneralPathX();
522
					gpx.moveTo(previous.getX(), previous.getY());
523
					gpx.lineTo(theData[0], theData[1]);
524
					Geometry geom = geomFactory.createPolyline2D(gpx);
525
					boolean intersectFirst = intersects(geom, firstPoint);
526
					boolean intersectSecond = intersects(geom, secondPoint);
527
					if (intersectFirst && intersectSecond && !isFirstPointBreak) {
528
						isFirstPointBreak = true;
529
						isSecondPointBreak = true;
530
						points.add(getNearPoint(previous));
531
						points.add(getDistantPoint(previous));
532
						return (Point2D[]) points.toArray(new Point2D[0]);
533
					} else if (intersectFirst && !isFirstPointBreak) {
534
						isFirstPointBreak = true;
535
						points.add(firstPoint);
536
					} else if (intersectSecond && !isSecondPointBreak) {
537
						isSecondPointBreak = true;
538
						points.add(secondPoint);
539
					}
540
				}
541
				previous = new Point2D.Double(theData[0], theData[1]);
542
				break;
578 543

  
579
                case PathIterator.SEG_QUADTO:
580
                     if (previous!=null){
581
                            GeneralPathX gpx=new GeneralPathX();
582
                            gpx.moveTo(previous.getX(),previous.getY());
583
                            gpx.quadTo(theData[0], theData[1],theData[2], theData[3]);
584
                            Geometry geom=geomFactory.createPolyline2D(gpx);
585
                            boolean intersectFirst=intersects(geom,firstPoint);
586
                            boolean intersectSecond=intersects(geom,secondPoint);
587
                            if (intersectFirst && intersectSecond && !isFirstPointBreak){
588
                            	isFirstPointBreak=true;
589
                            	isSecondPointBreak=true;
590
                                points.add(getNearPoint(previous));
591
                                points.add(getDistantPoint(previous));
592
                                return (Point2D[])points.toArray(new Point2D[0]);
593
                            }else if (intersectFirst && !isFirstPointBreak){
594
                            	isFirstPointBreak=true;
595
                            	points.add(firstPoint);
596
                            }else if (intersectSecond && !isSecondPointBreak){
597
                            	isSecondPointBreak=true;
598
                            	points.add(secondPoint);
599
                            }
600
                     }
601
                     previous=new Point2D.Double(theData[0], theData[1]);
544
			case PathIterator.SEG_QUADTO:
545
				if (previous != null) {
546
					GeneralPathX gpx = new GeneralPathX();
547
					gpx.moveTo(previous.getX(), previous.getY());
548
					gpx.quadTo(theData[0], theData[1], theData[2], theData[3]);
549
					Geometry geom = geomFactory.createPolyline2D(gpx);
550
					boolean intersectFirst = intersects(geom, firstPoint);
551
					boolean intersectSecond = intersects(geom, secondPoint);
552
					if (intersectFirst && intersectSecond && !isFirstPointBreak) {
553
						isFirstPointBreak = true;
554
						isSecondPointBreak = true;
555
						points.add(getNearPoint(previous));
556
						points.add(getDistantPoint(previous));
557
						return (Point2D[]) points.toArray(new Point2D[0]);
558
					} else if (intersectFirst && !isFirstPointBreak) {
559
						isFirstPointBreak = true;
560
						points.add(firstPoint);
561
					} else if (intersectSecond && !isSecondPointBreak) {
562
						isSecondPointBreak = true;
563
						points.add(secondPoint);
564
					}
565
				}
566
				previous = new Point2D.Double(theData[0], theData[1]);
602 567

  
603
                    break;
568
				break;
604 569

  
605
                case PathIterator.SEG_CUBICTO:
606
                     if (previous!=null){
607
                            GeneralPathX gpx=new GeneralPathX();
608
                            gpx.moveTo(previous.getX(),previous.getY());
609
                            gpx.curveTo(theData[0], theData[1],theData[2], theData[3],theData[4], theData[5]);
610
                            Geometry geom=geomFactory.createPolyline2D(gpx);
611
                            boolean intersectFirst=intersects(geom,firstPoint);
612
                            boolean intersectSecond=intersects(geom,secondPoint);
613
                            if (intersectFirst && intersectSecond && !isFirstPointBreak){
614
                            	isFirstPointBreak=true;
615
                            	isSecondPointBreak=true;
616
                            	points.add(getNearPoint(previous));
617
                                points.add(getDistantPoint(previous));
618
                                return (Point2D[])points.toArray(new Point2D[0]);
619
                            }else if (intersectFirst && !isFirstPointBreak){
620
                            	isFirstPointBreak=true;
621
                            	points.add(firstPoint);
622
                            }else if (intersectSecond && !isSecondPointBreak){
623
                            	isSecondPointBreak=true;
624
                                points.add(secondPoint);
625
                            }
626
                     }
627
                     previous=new Point2D.Double(theData[0], theData[1]);
570
			case PathIterator.SEG_CUBICTO:
571
				if (previous != null) {
572
					GeneralPathX gpx = new GeneralPathX();
573
					gpx.moveTo(previous.getX(), previous.getY());
574
					gpx.curveTo(theData[0], theData[1], theData[2], theData[3],
575
							theData[4], theData[5]);
576
					Geometry geom = geomFactory.createPolyline2D(gpx);
577
					boolean intersectFirst = intersects(geom, firstPoint);
578
					boolean intersectSecond = intersects(geom, secondPoint);
579
					if (intersectFirst && intersectSecond && !isFirstPointBreak) {
580
						isFirstPointBreak = true;
581
						isSecondPointBreak = true;
582
						points.add(getNearPoint(previous));
583
						points.add(getDistantPoint(previous));
584
						return (Point2D[]) points.toArray(new Point2D[0]);
585
					} else if (intersectFirst && !isFirstPointBreak) {
586
						isFirstPointBreak = true;
587
						points.add(firstPoint);
588
					} else if (intersectSecond && !isSecondPointBreak) {
589
						isSecondPointBreak = true;
590
						points.add(secondPoint);
591
					}
592
				}
593
				previous = new Point2D.Double(theData[0], theData[1]);
628 594

  
629
                    break;
595
				break;
630 596

  
631
                case PathIterator.SEG_CLOSE:
632
                    //if (isFirstPart)
633
                    //	newGp1.closePath();
634
                    //else
635
                    //	newGp2.closePath();
636
                    break;
637
            } //end switch
597
			case PathIterator.SEG_CLOSE:
598
				// if (isFirstPart)
599
				// newGp1.closePath();
600
				// else
601
				// newGp2.closePath();
602
				break;
603
			} // end switch
638 604

  
639
            theIterator.next();
640
        } //end while loop
605
			theIterator.next();
606
		} // end while loop
641 607

  
642
        return (Point2D[])points.toArray(new Point2D[0]);
643
    }
644
    private Point2D getDistantPoint(Point2D previous){
645
        if (firstPoint.distance(previous)>secondPoint.distance(previous)){
646
            return firstPoint;
647
        }
648
        return secondPoint;
649
    }
650
private Point2D getNearPoint(Point2D previous) {
651
	if (firstPoint.distance(previous)<=secondPoint.distance(previous)){
652
        return firstPoint;
653
    }
654
    return secondPoint;
655
}
656
    /**
657
     * M?todo para dibujar la lo necesario para el estado en el que nos
658
     * encontremos.
659
     *
660
     * @param g Graphics sobre el que dibujar.
661
     * @param x par?metro x del punto que se pase para dibujar.
662
     * @param y par?metro x del punto que se pase para dibujar.
663
     */
664
    public void drawOperation(Graphics g, double x, double y) {
665
    	VectorialLayerEdited vle=getVLE();
666
    	FeatureSet selection=null;
667
    	try {
668
    		selection = (FeatureSet)vle.getFeatureStore().getSelection();
608
		return (Point2D[]) points.toArray(new Point2D[0]);
609
	}
669 610

  
670
    		ViewPort vp=CADExtension.getEditionManager().getMapControl().getViewPort();
671
    		if (selection.getSize()==1){
672
    			if (firstPoint!=null){
673
    				Geometry g1=geomFactory.createCircle(firstPoint,vp.toMapDistance(3));
674
    				Geometry g2=geomFactory.createCircle(firstPoint,vp.toMapDistance(5));
611
	private Point2D getDistantPoint(Point2D previous) {
612
		if (firstPoint.distance(previous) > secondPoint.distance(previous)) {
613
			return firstPoint;
614
		}
615
		return secondPoint;
616
	}
675 617

  
676
    				DrawOperationContext doc=new DrawOperationContext();
677
    				doc.setGraphics((Graphics2D)g);
678
    				doc.setViewPort(vp);
679
    				doc.setSymbol(DefaultCADTool.axisReferencesSymbol);
680
    				try {
681
    					g1.invokeOperation(Draw.CODE,doc);
682
    					g2.invokeOperation(Draw.CODE,doc);
683
    				} catch (GeometryOperationNotSupportedException e) {
684
    					e.printStackTrace();
685
    				} catch (GeometryOperationException e) {
686
    					e.printStackTrace();
687
    				}
618
	private Point2D getNearPoint(Point2D previous) {
619
		if (firstPoint.distance(previous) <= secondPoint.distance(previous)) {
620
			return firstPoint;
621
		}
622
		return secondPoint;
623
	}
688 624

  
625
	/**
626
	 * M?todo para dibujar la lo necesario para el estado en el que nos
627
	 * encontremos.
628
	 *
629
	 * @param g
630
	 *            Graphics sobre el que dibujar.
631
	 * @param x
632
	 *            par?metro x del punto que se pase para dibujar.
633
	 * @param y
634
	 *            par?metro x del punto que se pase para dibujar.
635
	 */
636
	public void drawOperation(Graphics g, double x, double y) {
637
		VectorialLayerEdited vle = getVLE();
638
		FeatureSet selection = null;
639
		try {
640
			selection = (FeatureSet) vle.getFeatureStore().getSelection();
689 641

  
642
			ViewPort vp = CADExtension.getEditionManager().getMapControl()
643
					.getViewPort();
644
			if (selection.getSize() == 1) {
645
				if (firstPoint != null) {
646
					Geometry g1 = geomFactory.createCircle(firstPoint, vp
647
							.toMapDistance(3));
648
					Geometry g2 = geomFactory.createCircle(firstPoint, vp
649
							.toMapDistance(5));
690 650

  
691
//  				g1.draw((Graphics2D)g,vp,DefaultCADTool.axisReferencesSymbol);
692
//  				g2.draw((Graphics2D)g,vp,DefaultCADTool.axisReferencesSymbol);
693
    			}
694
    			rowEdited = (Feature)selection.iterator().next();
695
    			//.getLinkedRow()
696
    			//	.cloneRow();
697
    			Geometry geom=((Geometry)rowEdited.getDefaultGeometry()).cloneGeometry();
698
    			if (intersects(geom,new Point2D.Double(x,y))){
699
    				DrawOperationContext doc=new DrawOperationContext();
700
    				doc.setGraphics((Graphics2D)g);
701
    				doc.setViewPort(vp);
702
    				doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
703
    				try {
704
    					geom.invokeOperation(Draw.CODE,doc);
705
    				} catch (GeometryOperationNotSupportedException e) {
706
    					e.printStackTrace();
707
    				} catch (GeometryOperationException e) {
708
    					e.printStackTrace();
709
    				}
651
					DrawOperationContext doc = new DrawOperationContext();
652
					doc.setGraphics((Graphics2D) g);
653
					doc.setViewPort(vp);
654
					doc.setSymbol(DefaultCADTool.axisReferencesSymbol);
655
					try {
656
						g1.invokeOperation(Draw.CODE, doc);
657
						g2.invokeOperation(Draw.CODE, doc);
658
					} catch (GeometryOperationNotSupportedException e) {
659
						e.printStackTrace();
660
					} catch (GeometryOperationException e) {
661
						e.printStackTrace();
662
					}
710 663

  
711
//  				geom.draw((Graphics2D)g,vp,DefaultCADTool.geometrySelectSymbol);
712
    			}
713
    		}
714
    	} catch (ReadException e1) {
715
    		// TODO Auto-generated catch block
716
    		e1.printStackTrace();
717
    	} catch (DataException e) {
664
					// g1.draw((Graphics2D)g,vp,DefaultCADTool.axisReferencesSymbol);
665
					// g2.draw((Graphics2D)g,vp,DefaultCADTool.axisReferencesSymbol);
666
				}
667
				rowEdited = (Feature) selection.iterator().next();
668
				// .getLinkedRow()
669
				// .cloneRow();
670
				Geometry geom = ((Geometry) rowEdited.getDefaultGeometry())
671
						.cloneGeometry();
672
				if (intersects(geom, new Point2D.Double(x, y))) {
673
					DrawOperationContext doc = new DrawOperationContext();
674
					doc.setGraphics((Graphics2D) g);
675
					doc.setViewPort(vp);
676
					doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
677
					try {
678
						geom.invokeOperation(Draw.CODE, doc);
679
					} catch (GeometryOperationNotSupportedException e) {
680
						e.printStackTrace();
681
					} catch (GeometryOperationException e) {
682
						e.printStackTrace();
683
					}
684

  
685
					// geom.draw((Graphics2D)g,vp,DefaultCADTool.geometrySelectSymbol);
686
				}
687
			}
688
		} catch (ReadException e1) {
718 689
			// TODO Auto-generated catch block
690
			e1.printStackTrace();
691
		} catch (DataException e) {
692
			// TODO Auto-generated catch block
719 693
			e.printStackTrace();
720 694
		}
721
    }
722
    public boolean intersects(double x,double y){
723
    	Point2D p = new Point2D.Double(x, y);
724
    	VectorialLayerEdited vle = getVLE();
725
    	FeatureSet selection=null;
726
    	try {
727
    		selection = (FeatureSet)vle.getFeatureStore().getSelection();
695
	}
728 696

  
729
    		if (selection.getSize() == 1) {
730
    			rowEdited = (Feature)selection.iterator().next();
731
    			Geometry g = ((Geometry)rowEdited.getDefaultGeometry()).cloneGeometry();
732
    			return intersects(g, p);
733
    		}
734
    	} catch (ReadException e) {
735
    		// TODO Auto-generated catch block
736
    		e.printStackTrace();
737
    	} catch (DataException e) {
697
	public boolean intersects(double x, double y) {
698
		Point2D p = new Point2D.Double(x, y);
699
		VectorialLayerEdited vle = getVLE();
700
		FeatureSet selection = null;
701
		try {
702
			selection = (FeatureSet) vle.getFeatureStore().getSelection();
703

  
704
			if (selection.getSize() == 1) {
705
				rowEdited = (Feature) selection.iterator().next();
706
				Geometry g = ((Geometry) rowEdited.getDefaultGeometry())
707
						.cloneGeometry();
708
				return intersects(g, p);
709
			}
710
		} catch (ReadException e) {
738 711
			// TODO Auto-generated catch block
739 712
			e.printStackTrace();
713
		} catch (DataException e) {
714
			// TODO Auto-generated catch block
715
			e.printStackTrace();
740 716
		}
741
    	return false;
742
    }
743
    private boolean intersects(Geometry geom, Point2D p){
744
        double tol = 1;
745
        tol = CADExtension.getEditionManager().getMapControl().getViewPort()
746
                .toMapDistance((int) tol);
747
        Rectangle2D r = new Rectangle2D.Double(p.getX() - tol / 2, p.getY()
748
                - tol / 2, tol, tol);
749
        return (geom.intersects(r) && !geom.contains(r));
750
    }
751
    /**
752
     * Add a diferent option.
753
     *
754
     * @param s Diferent option.
755
     */
756
    public void addOption(String s) {
757
        if (s.equals(PluginServices.getText(this,"cancel"))|| s.equals("c")|| s.equals("C")){
758
            init();
759
        }
760
    }
761
    /* (non-Javadoc)
762
     * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
763
     */
764
    public void addValue(double d) {
765
    }
766
    public String getName() {
767
        return PluginServices.getText(this,"break_");
768
    }
717
		return false;
718
	}
769 719

  
770
    public String toString() {
771
        return "_break";
772
    }
720
	private boolean intersects(Geometry geom, Point2D p) {
721
		double tol = 1;
722
		tol = CADExtension.getEditionManager().getMapControl().getViewPort()
723
				.toMapDistance((int) tol);
724
		Rectangle2D r = new Rectangle2D.Double(p.getX() - tol / 2, p.getY()
725
				- tol / 2, tol, tol);
726
		return (geom.intersects(r) && !geom.contains(r));
727
	}
773 728

  
774
    public boolean isApplicable(int shapeType) {
775
        switch (shapeType) {
776
        case Geometry.TYPES.GEOMETRY:
777
        case Geometry.TYPES.CURVE:
778
            return true;
779
        }
780
        return false;
781
    }
729
	/**
730
	 * Add a diferent option.
731
	 *
732
	 * @param s
733
	 *            Diferent option.
734
	 */
735
	public void addOption(String s) {
736
		if (s.equals(PluginServices.getText(this, "cancel")) || s.equals("c")
737
				|| s.equals("C")) {
738
			init();
739
		}
740
	}
782 741

  
742
	/*
743
	 * (non-Javadoc)
744
	 *
745
	 * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
746
	 */
747
	public void addValue(double d) {
748
	}
783 749

  
750
	public String getName() {
751
		return PluginServices.getText(this, "break_");
752
	}
753

  
754
	public String toString() {
755
		return "_break";
756
	}
757

  
758
	public boolean isApplicable(int shapeType) {
759
		switch (shapeType) {
760
		case Geometry.TYPES.GEOMETRY:
761
		case Geometry.TYPES.CURVE:
762
			return true;
763
		}
764
		return false;
765
	}
766

  
784 767
}

Also available in: Unified diff