24 |
24 |
import java.awt.Component;
|
25 |
25 |
import java.awt.event.InputEvent;
|
26 |
26 |
import java.awt.event.MouseEvent;
|
27 |
|
import java.awt.geom.PathIterator;
|
28 |
27 |
import java.util.ArrayList;
|
29 |
28 |
import java.util.List;
|
30 |
29 |
|
... | ... | |
32 |
31 |
|
33 |
32 |
import com.vividsolutions.jts.geom.GeometryCollection;
|
34 |
33 |
|
|
34 |
import org.slf4j.Logger;
|
|
35 |
import org.slf4j.LoggerFactory;
|
|
36 |
|
35 |
37 |
import org.gvsig.andami.PluginServices;
|
36 |
38 |
import org.gvsig.andami.messages.NotificationManager;
|
37 |
39 |
import org.gvsig.editing.CADExtension;
|
... | ... | |
48 |
50 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
49 |
51 |
import org.gvsig.fmap.geom.Geometry;
|
50 |
52 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
|
|
53 |
import org.gvsig.fmap.geom.aggregate.MultiSurface;
|
|
54 |
import org.gvsig.fmap.geom.operation.GeometryOperationException;
|
|
55 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
|
51 |
56 |
import org.gvsig.fmap.geom.primitive.GeneralPathX;
|
52 |
57 |
import org.gvsig.fmap.geom.primitive.Point;
|
|
58 |
import org.gvsig.fmap.geom.primitive.Surface;
|
53 |
59 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
|
54 |
60 |
import org.gvsig.tools.dispose.DisposableIterator;
|
55 |
61 |
import org.gvsig.tools.dispose.DisposeUtils;
|
... | ... | |
60 |
66 |
* @author Vicente Caballero Navarro
|
61 |
67 |
*/
|
62 |
68 |
public class InternalPolygonCADTool extends DefaultCADTool {
|
|
69 |
private static final Logger LOG = LoggerFactory
|
|
70 |
.getLogger(InternalPolygonCADTool.class);
|
63 |
71 |
|
64 |
72 |
protected InternalPolygonCADToolContext _fsm;
|
65 |
73 |
protected List<Point> points = new ArrayList<Point>();
|
... | ... | |
290 |
298 |
public void addValue(double d) {
|
291 |
299 |
}
|
292 |
300 |
|
293 |
|
private Geometry createNewPolygon(Geometry geometry, List<Point> points) {
|
294 |
|
GeneralPathX newGp = new GeneralPathX();
|
295 |
|
double[] theData = new double[6];
|
296 |
|
|
297 |
|
PathIterator theIterator;
|
298 |
|
int theType;
|
299 |
|
int numParts = 0;
|
300 |
|
|
301 |
|
theIterator = geometry.getPathIterator(null, geomManager.getFlatness());
|
302 |
|
while (!theIterator.isDone()) {
|
303 |
|
theType = theIterator.currentSegment(theData);
|
304 |
|
switch (theType) {
|
305 |
|
|
306 |
|
case PathIterator.SEG_MOVETO:
|
307 |
|
numParts++;
|
308 |
|
newGp.moveTo(theData[0], theData[1]);
|
309 |
|
break;
|
310 |
|
|
311 |
|
case PathIterator.SEG_LINETO:
|
312 |
|
newGp.lineTo(theData[0], theData[1]);
|
313 |
|
break;
|
314 |
|
|
315 |
|
case PathIterator.SEG_QUADTO:
|
316 |
|
newGp.quadTo(theData[0], theData[1], theData[2], theData[3]);
|
317 |
|
break;
|
318 |
|
|
319 |
|
case PathIterator.SEG_CUBICTO:
|
320 |
|
newGp.curveTo(theData[0], theData[1], theData[2], theData[3],
|
321 |
|
theData[4], theData[5]);
|
322 |
|
break;
|
323 |
|
|
324 |
|
case PathIterator.SEG_CLOSE:
|
325 |
|
newGp.closePath();
|
326 |
|
break;
|
327 |
|
} // end switch
|
328 |
|
|
329 |
|
theIterator.next();
|
330 |
|
} // end while loop
|
|
301 |
private Geometry createNewPolygon(Geometry geometry, List<Point> points) {
|
|
302 |
Geometry newGeometry = geometry.cloneGeometry();
|
|
303 |
|
331 |
304 |
GeneralPathX gpxInternal = new GeneralPathX();
|
332 |
305 |
gpxInternal.moveTo(points.get(points.size() - 1));
|
333 |
306 |
for (int i = points.size() - 2; i >= 0; i--) {
|
... | ... | |
338 |
311 |
if (!gpxInternal.isCCW()) {
|
339 |
312 |
gpxInternal.flip();
|
340 |
313 |
}
|
341 |
|
newGp.append(gpxInternal.getPathIterator(null), false);
|
|
314 |
|
|
315 |
if (newGeometry.getGeometryType().isTypeOf(Geometry.TYPES.SURFACE)){
|
|
316 |
GeneralPathX newGp = newGeometry.getGeneralPath();
|
|
317 |
newGp.append(gpxInternal.getPathIterator(null), false);
|
|
318 |
}else if (newGeometry.getGeometryType().isTypeOf(Geometry.TYPES.MULTISURFACE)){
|
|
319 |
MultiSurface multiSurface = (MultiSurface)newGeometry;
|
|
320 |
for (int i=0 ; i<multiSurface.getPrimitivesNumber() ; i++){
|
|
321 |
Surface surcafe = multiSurface.getSurfaceAt(i);
|
|
322 |
try {
|
|
323 |
if (createSurface(gpxInternal).intersects(surcafe)){
|
|
324 |
GeneralPathX newGp = surcafe.getGeneralPath();
|
|
325 |
newGp.append(gpxInternal.getPathIterator(null), false);
|
|
326 |
}
|
|
327 |
} catch (GeometryOperationNotSupportedException e) {
|
|
328 |
LOG.error("Erro calculating the intersection", e);
|
|
329 |
} catch (GeometryOperationException e) {
|
|
330 |
LOG.error("Erro calculating the intersection", e);
|
|
331 |
}
|
|
332 |
}
|
|
333 |
}
|
342 |
334 |
|
343 |
|
return createSurface(newGp);
|
|
335 |
return newGeometry;
|
344 |
336 |
}
|
345 |
337 |
|
346 |
338 |
private Geometry createNewPolygonGC(MultiPrimitive multiPrimitive,
|