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