Revision 29724
branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/SplitGeometryCADTool.java | ||
---|---|---|
59 | 59 |
import java.util.List; |
60 | 60 |
|
61 | 61 |
import org.apache.log4j.Logger; |
62 |
import org.gvsig.andami.PluginServices; |
|
63 | 62 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
64 | 63 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
65 | 64 |
import org.gvsig.editing.gui.cad.tools.smc.SplitGeometryCADToolContext; |
... | ... | |
84 | 83 |
|
85 | 84 |
import statemap.State; |
86 | 85 |
|
86 |
import com.iver.andami.PluginServices; |
|
87 |
import com.iver.andami.messages.NotificationManager; |
|
87 | 88 |
import com.vividsolutions.jts.geom.Coordinate; |
88 | 89 |
import com.vividsolutions.jts.geom.Geometry; |
89 | 90 |
import com.vividsolutions.jts.geom.GeometryCollection; |
90 | 91 |
import com.vividsolutions.jts.geom.GeometryFactory; |
91 | 92 |
import com.vividsolutions.jts.geom.LineString; |
93 |
import com.vividsolutions.jts.geom.MultiLineString; |
|
94 |
import com.vividsolutions.jts.geom.MultiPoint; |
|
95 |
import com.vividsolutions.jts.geom.MultiPolygon; |
|
96 |
import com.vividsolutions.jts.geom.Point; |
|
97 |
import com.vividsolutions.jts.geom.Polygon; |
|
92 | 98 |
import com.vividsolutions.jts.geom.PrecisionModel; |
93 | 99 |
|
94 | 100 |
|
... | ... | |
214 | 220 |
&& ((GeometryCollection)splitGeo).getNumGeometries()>1){ |
215 | 221 |
|
216 | 222 |
GeometryCollection gc = (GeometryCollection)splitGeo; |
217 |
for(int j = 0; j < gc.getNumGeometries(); j++){ |
|
218 |
Geometry g = gc.getGeometryN(j); |
|
219 |
org.gvsig.fmap.geom.Geometry fmapGeo = Converter.jtsToGeometry(g); |
|
223 |
ArrayList<Geometry> geoms0=new ArrayList<Geometry>(); |
|
224 |
ArrayList<Geometry> geoms1=new ArrayList<Geometry>(); |
|
225 |
if (gc.getNumGeometries()>2){ |
|
226 |
Geometry[] splitGroups=createSplitGroups(jtsGeo,splittingLs); |
|
227 |
if (splitGroups.length==0){ |
|
228 |
continue; |
|
229 |
} |
|
220 | 230 |
|
221 |
if (j==0){ |
|
231 |
for(int j = 0; j < gc.getNumGeometries(); j++){ |
|
232 |
Geometry g = gc.getGeometryN(j); |
|
233 |
if (splitGroups[0].contains(g)){ |
|
234 |
geoms0.add(g); |
|
235 |
}else{ |
|
236 |
geoms1.add(g); |
|
237 |
} |
|
238 |
} |
|
239 |
}else if (gc.getNumGeometries()==2){ |
|
240 |
geoms0.add(gc.getGeometryN(0)); |
|
241 |
geoms1.add(gc.getGeometryN(1)); |
|
242 |
}else{ |
|
243 |
continue; |
|
244 |
} |
|
245 |
GeometryCollection gc0=createMulti(geoms0,gc.getFactory()); |
|
246 |
|
|
247 |
|
|
248 |
// for(int j = 0; j < gc.getNumGeometries(); j++){ |
|
249 |
// Geometry g = gc.getGeometryN(j); |
|
250 |
org.gvsig.fmap.geom.Geometry fmapGeo = Converter.jtsToGeometry(gc0); |
|
251 |
|
|
252 |
// if (j==0){ |
|
222 | 253 |
EditableFeature eFeature=feature.getEditable(); |
223 | 254 |
eFeature.setGeometry(store.getDefaultFeatureType().getDefaultGeometryAttributeName(), fmapGeo); |
224 | 255 |
store.update(eFeature); |
225 |
}else{ |
|
256 |
// }else{ |
|
257 |
GeometryCollection gc1=createMulti(geoms1,gc.getFactory()); |
|
258 |
fmapGeo = Converter.jtsToGeometry(gc1); |
|
226 | 259 |
|
227 | 260 |
EditableFeature newFeature=store.createNewFeature(store.getDefaultFeatureType(), feature); |
228 | 261 |
newFeature.setGeometry(store.getDefaultFeatureType().getDefaultGeometryAttributeName(), fmapGeo); |
... | ... | |
230 | 263 |
SpatialCache spatialCache=((FLyrVect)vle.getLayer()).getSpatialCache(); |
231 | 264 |
Envelope envelope = fmapGeo.getEnvelope(); |
232 | 265 |
spatialCache.insert(envelope,fmapGeo); |
233 |
} |
|
234 |
}//for j |
|
266 |
// }
|
|
267 |
// }//for j
|
|
235 | 268 |
}//if splitGeo |
236 | 269 |
|
237 | 270 |
} |
... | ... | |
243 | 276 |
PluginServices.getLogger().error("Error splitting geom", ex); |
244 | 277 |
} |
245 | 278 |
} |
246 |
|
|
279 |
private GeometryCollection createMulti(ArrayList<Geometry> geoms,GeometryFactory factory) { |
|
280 |
if (geoms.size()==0) |
|
281 |
return null; |
|
282 |
if (geoms.get(0) instanceof Polygon){ |
|
283 |
return new MultiPolygon((Polygon[])geoms.toArray(new Polygon[0]),factory); |
|
284 |
}else if (geoms.get(0) instanceof LineString){ |
|
285 |
return new MultiLineString((LineString[])geoms.toArray(new LineString[0]),factory); |
|
286 |
}else if (geoms.get(0) instanceof Point){ |
|
287 |
return new MultiPoint((Point[])geoms.toArray(new Point[0]),factory); |
|
288 |
} |
|
289 |
return null; |
|
290 |
} |
|
291 |
private Geometry[] createSplitGroups(Geometry splitGeo, LineString splittingLs) { |
|
292 |
try{ |
|
293 |
Geometry[] geomsJTS=new Geometry[2]; |
|
294 |
Geometry r=splitGeo.getEnvelope(); |
|
295 |
Geometry splitG = SplitStrategy.splitOp(r, splittingLs); |
|
296 |
if(splitG instanceof GeometryCollection |
|
297 |
&& ((GeometryCollection)splitG).getNumGeometries()>1){ |
|
298 |
GeometryCollection gc = (GeometryCollection)splitG; |
|
299 |
for(int j = 0; j < gc.getNumGeometries(); j++){ |
|
300 |
geomsJTS[j]=gc.getGeometryN(j); |
|
301 |
} |
|
302 |
} |
|
303 |
return geomsJTS; |
|
304 |
}catch (Exception e) { |
|
305 |
NotificationManager.showMessageError(PluginServices.getText(this, "line_not_cross_rectangle"), e); |
|
306 |
} |
|
307 |
return null; |
|
308 |
} |
|
247 | 309 |
public void end(){ |
248 | 310 |
getCadToolAdapter().refreshEditedLayer(); |
249 | 311 |
init(); |
... | ... | |
324 | 386 |
} |
325 | 387 |
} |
326 | 388 |
|
389 |
private void drawRectangleOfSplit(Graphics2D g) { |
|
390 |
VectorialLayerEdited vle = getVLE(); |
|
391 |
FeatureStore store=vle.getFeatureStore(); |
|
392 |
Iterator<Feature> selected = store.getFeatureSelection().iterator(); |
|
393 |
while (selected.hasNext()) { |
|
394 |
Feature feature = (Feature) selected.next(); |
|
395 |
org.gvsig.fmap.geom.Geometry ig = feature.getDefaultGeometry(); |
|
396 |
Geometry jtsG = Converter.geometryToJts(ig); |
|
397 |
if (jtsG !=null && jtsG instanceof GeometryCollection && jtsG.getNumGeometries()>1){ |
|
398 |
org.gvsig.fmap.geom.Geometry r=ig.getEnvelope().getGeometry(); |
|
399 |
DrawOperationContext doc=new DrawOperationContext(); |
|
400 |
doc.setGraphics((Graphics2D)g); |
|
401 |
doc.setViewPort(getCadToolAdapter().getMapControl().getViewPort()); |
|
402 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
|
403 |
r.invokeOperation(Draw.CODE, doc); |
|
404 |
} |
|
405 |
} |
|
406 |
} |
|
327 | 407 |
|
328 |
|
|
329 |
|
|
330 | 408 |
public void drawOperation(Graphics g, double x, double y) { |
331 | 409 |
State actualState = _fsm.getState(); |
332 | 410 |
String status = actualState.getName(); |
333 |
|
|
411 |
drawRectangleOfSplit((Graphics2D) g); |
|
334 | 412 |
// draw splitting line |
335 | 413 |
if ((status.equals("SplitGeometry.DigitizingLine"))) { |
336 | 414 |
drawPolyLine((Graphics2D) g, x, y); |
Also available in: Unified diff