46 |
46 |
import java.awt.geom.PathIterator;
|
47 |
47 |
import java.awt.geom.Point2D;
|
48 |
48 |
import java.util.ArrayList;
|
|
49 |
import java.util.List;
|
49 |
50 |
|
50 |
51 |
import javax.swing.JOptionPane;
|
51 |
52 |
|
|
53 |
import com.vividsolutions.jts.geom.GeometryCollection;
|
|
54 |
|
52 |
55 |
import org.gvsig.andami.PluginServices;
|
53 |
56 |
import org.gvsig.andami.messages.NotificationManager;
|
54 |
57 |
import org.gvsig.editing.CADExtension;
|
... | ... | |
58 |
61 |
import org.gvsig.editing.layers.VectorialLayerEdited;
|
59 |
62 |
import org.gvsig.fmap.dal.exception.DataException;
|
60 |
63 |
import org.gvsig.fmap.dal.exception.ReadException;
|
61 |
|
import org.gvsig.tools.dispose.DisposableIterator;
|
62 |
64 |
import org.gvsig.fmap.dal.feature.EditableFeature;
|
63 |
65 |
import org.gvsig.fmap.dal.feature.Feature;
|
64 |
66 |
import org.gvsig.fmap.dal.feature.FeatureSelection;
|
... | ... | |
66 |
68 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
67 |
69 |
import org.gvsig.fmap.geom.Geometry;
|
68 |
70 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
|
|
71 |
import org.gvsig.fmap.geom.aggregate.MultiSurface;
|
69 |
72 |
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive;
|
70 |
73 |
import org.gvsig.fmap.geom.primitive.GeneralPathX;
|
|
74 |
import org.gvsig.fmap.geom.primitive.Point;
|
71 |
75 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
|
|
76 |
import org.gvsig.tools.dispose.DisposableIterator;
|
72 |
77 |
import org.gvsig.tools.dispose.DisposeUtils;
|
73 |
78 |
|
74 |
|
import com.vividsolutions.jts.geom.GeometryCollection;
|
75 |
79 |
|
76 |
|
|
77 |
80 |
/**
|
78 |
81 |
* DOCUMENT ME!
|
79 |
82 |
*
|
... | ... | |
81 |
84 |
*/
|
82 |
85 |
public class InternalPolygonCADTool extends DefaultCADTool {
|
83 |
86 |
protected InternalPolygonCADToolContext _fsm;
|
84 |
|
protected ArrayList<Point2D> points=new ArrayList<Point2D>();
|
85 |
|
protected Geometry geometry=null;
|
|
87 |
protected List<Point> points = new ArrayList<Point>();
|
|
88 |
protected Geometry geometry = null;
|
86 |
89 |
|
87 |
90 |
/**
|
88 |
91 |
* Crea un nuevo PolylineCADTool.
|
... | ... | |
165 |
168 |
iterator = featureCollection.iterator();
|
166 |
169 |
Feature feature = (Feature) iterator.next();
|
167 |
170 |
geometry=(feature.getDefaultGeometry()).cloneGeometry();
|
168 |
|
if (geometry.getShape().contains(x,y)){
|
169 |
|
points.add(new Point2D.Double(x,y));
|
|
171 |
if (geometry.contains(x,y)){
|
|
172 |
points.add(createPoint(x, y));
|
170 |
173 |
}else{
|
171 |
174 |
JOptionPane.showMessageDialog(((Component)PluginServices.getMainFrame()),PluginServices.getText(this,"debe_insertar_el_punto_dentro_de_los_limites_de_la_geometria"));
|
172 |
175 |
}
|
... | ... | |
176 |
179 |
} catch (DataException e) {
|
177 |
180 |
NotificationManager.addError(e.getMessage(),e);
|
178 |
181 |
} finally {
|
179 |
|
DisposeUtils.dispose(iterator);
|
180 |
|
DisposeUtils.dispose(featureCollection);
|
|
182 |
DisposeUtils.dispose(iterator);
|
181 |
183 |
}
|
182 |
184 |
}
|
183 |
185 |
|
... | ... | |
190 |
192 |
* @param y par?metro x del punto que se pase para dibujar.
|
191 |
193 |
*/
|
192 |
194 |
public void drawOperation(MapControlDrawer renderer, double x, double y) {
|
193 |
|
Point2D[] ps=points.toArray(new Point2D[0]);
|
194 |
|
GeneralPathX gpx=new GeneralPathX();
|
195 |
|
GeneralPathX gpx1=new GeneralPathX();
|
|
195 |
GeneralPathX gpx = new GeneralPathX();
|
|
196 |
GeneralPathX gpx1 = new GeneralPathX();
|
196 |
197 |
|
197 |
|
if (ps.length>0){
|
198 |
|
for (int i=0;i<ps.length;i++){
|
|
198 |
if (points.size()>0){
|
|
199 |
for (int i=0 ; i<points.size() ; i++){
|
199 |
200 |
if (i==0){
|
200 |
|
gpx.moveTo(ps[i].getX(),ps[i].getY());
|
201 |
|
gpx1.moveTo(ps[i].getX(),ps[i].getY());
|
|
201 |
gpx.moveTo(points.get(i));
|
|
202 |
gpx1.moveTo(points.get(i));
|
202 |
203 |
}else{
|
203 |
|
gpx.lineTo(ps[i].getX(),ps[i].getY());
|
204 |
|
gpx1.lineTo(ps[i].getX(),ps[i].getY());
|
|
204 |
gpx.lineTo(points.get(i));
|
|
205 |
gpx1.lineTo(points.get(i));
|
205 |
206 |
}
|
206 |
207 |
|
207 |
208 |
}
|
208 |
|
gpx.lineTo(x,y);
|
|
209 |
gpx.lineTo(createPoint(x,y));
|
209 |
210 |
gpx.closePath();
|
210 |
211 |
gpx1.closePath();
|
211 |
212 |
|
... | ... | |
242 |
243 |
Feature feature = (Feature) iterator.next();
|
243 |
244 |
geometry = (feature.getDefaultGeometry()).cloneGeometry();
|
244 |
245 |
if (geometry instanceof GeometryCollection) {
|
245 |
|
BaseMultiPrimitive gc = (BaseMultiPrimitive) geometry;
|
246 |
|
geometry = createNewPolygonGC(gc, points
|
247 |
|
.toArray(new Point2D[0]));
|
|
246 |
MultiPrimitive gc = (MultiPrimitive) geometry;
|
|
247 |
geometry = createNewPolygonGC(gc, points);
|
248 |
248 |
} else {
|
249 |
|
geometry = createNewPolygon(geometry, points
|
250 |
|
.toArray(new Point2D[0]));
|
|
249 |
geometry = createNewPolygon(geometry, points);
|
251 |
250 |
}
|
252 |
251 |
try {
|
253 |
252 |
EditableFeature eFeature = feature.getEditable();
|
... | ... | |
284 |
283 |
*/
|
285 |
284 |
public void addValue(double d) {
|
286 |
285 |
}
|
287 |
|
private Geometry createNewPolygon(Geometry gp,Point2D[] ps) {
|
|
286 |
private Geometry createNewPolygon(Geometry geometry, List<Point> points) {
|
288 |
287 |
GeneralPathX newGp = new GeneralPathX();
|
289 |
288 |
double[] theData = new double[6];
|
290 |
289 |
|
... | ... | |
292 |
291 |
int theType;
|
293 |
292 |
int numParts = 0;
|
294 |
293 |
|
295 |
|
|
296 |
|
theIterator = gp.getPathIterator(null, geomManager.getFlatness());
|
|
294 |
theIterator = geometry.getPathIterator(null, geomManager.getFlatness());
|
297 |
295 |
while (!theIterator.isDone()) {
|
298 |
296 |
theType = theIterator.currentSegment(theData);
|
299 |
297 |
switch (theType) {
|
... | ... | |
323 |
321 |
theIterator.next();
|
324 |
322 |
} //end while loop
|
325 |
323 |
GeneralPathX gpxInternal=new GeneralPathX();
|
326 |
|
gpxInternal.moveTo(ps[ps.length-1].getX(),ps[ps.length-1].getY());
|
327 |
|
for (int i=ps.length-1;i>=0;i--){
|
328 |
|
gpxInternal.lineTo(ps[i].getX(),ps[i].getY());
|
|
324 |
gpxInternal.moveTo(points.get(points.size()-1));
|
|
325 |
for (int i=points.size()-2 ; i>=0 ; i--){
|
|
326 |
gpxInternal.lineTo(points.get(i));
|
329 |
327 |
}
|
330 |
|
gpxInternal.lineTo(ps[ps.length-1].getX(),ps[ps.length-1].getY());
|
|
328 |
gpxInternal.closePath();
|
|
329 |
|
331 |
330 |
if (!gpxInternal.isCCW()) {
|
332 |
331 |
gpxInternal.flip();
|
333 |
332 |
}
|
... | ... | |
335 |
334 |
|
336 |
335 |
return createSurface(newGp);
|
337 |
336 |
}
|
338 |
|
private Geometry createNewPolygonGC(BaseMultiPrimitive gp,Point2D[] ps) {
|
339 |
|
ArrayList geoms=new ArrayList();
|
340 |
|
Geometry[] geometries=gp.getGeometries();
|
341 |
|
for (int i = 0;i<geometries.length;i++) {
|
342 |
|
geoms.add(geometries[i]);
|
|
337 |
|
|
338 |
private Geometry createNewPolygonGC(MultiPrimitive multiPrimitive, List<Point> points) {
|
|
339 |
MultiPrimitive multiPrimitiveAux = createMultiPrimitive();
|
|
340 |
|
|
341 |
for (int i = 0 ; i<multiPrimitive.getPrimitivesNumber() ; i++) {
|
|
342 |
multiPrimitiveAux.addPrimitive(multiPrimitive.getPrimitiveAt(i));
|
343 |
343 |
}
|
|
344 |
|
344 |
345 |
GeneralPathX gpx=new GeneralPathX();
|
345 |
|
gpx.moveTo(ps[ps.length-1].getX(),ps[ps.length-1].getY());
|
346 |
|
for (int i=ps.length-2;i>=0;i--){
|
347 |
|
gpx.lineTo(ps[i].getX(),ps[i].getY());
|
348 |
|
geoms.add(createCurve(gpx));
|
349 |
|
gpx=new GeneralPathX();
|
350 |
|
gpx.moveTo(ps[i].getX(),ps[i].getY());
|
|
346 |
gpx.moveTo(points.get(points.size()-1));
|
|
347 |
for (int i=points.size()-2 ; i>=0 ; i--){
|
|
348 |
gpx.lineTo(points.get(i));
|
|
349 |
multiPrimitiveAux.addPrimitive(createCurve(gpx));
|
|
350 |
gpx = new GeneralPathX();
|
|
351 |
gpx.moveTo(points.get(i));
|
351 |
352 |
}
|
352 |
|
gpx.lineTo(ps[ps.length-1].getX(),ps[ps.length-1].getY());
|
353 |
|
geoms.add(createCurve(gpx));
|
354 |
|
MultiPrimitive gc = createMultiPrimitive(((Geometry[])geoms.toArray(new Geometry[0])));
|
355 |
|
return gc;
|
|
353 |
gpx.closePath();
|
|
354 |
multiPrimitiveAux.addPrimitive(createCurve(gpx));
|
|
355 |
|
|
356 |
return multiPrimitiveAux;
|
356 |
357 |
}
|
|
358 |
|
357 |
359 |
public String getName() {
|
358 |
360 |
return PluginServices.getText(this,"internal_polygon_");
|
359 |
361 |
}
|