Revision 21100

View differences:

branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/geom/operation/DrawOperationContext.java
1
package org.gvsig.fmap.geom.operation;
2

  
3
import java.awt.Graphics2D;
4

  
5
import org.gvsig.fmap.mapcontext.ViewPort;
6
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
7

  
8
import com.iver.utiles.swing.threads.Cancellable;
9

  
10
public class DrawOperationContext extends GeometryOperationContext{
11
	private ISymbol symbol=null;
12
	private Graphics2D graphics=null;
13
	private Cancellable cancellable;
14
	private double dpi;
15
	private boolean hasDPI=false;
16
	private ViewPort viewPort;
17
	public ViewPort getViewPort() {
18
		return viewPort;
19
	}
20
	public void setViewPort(ViewPort viewPort) {
21
		this.viewPort = viewPort;
22
	}
23
	public Graphics2D getGraphics() {
24
		return graphics;
25
	}
26
	public void setGraphics(Graphics2D graphics) {
27
		this.graphics = graphics;
28
	}
29
	public ISymbol getSymbol() {
30
		return symbol;
31
	}
32
	public void setSymbol(ISymbol symbol) {
33
		this.symbol = symbol;
34
	}
35
	public void setCancellable(Cancellable cancel) {
36
		this.cancellable=cancel;
37

  
38
	}
39
	public Cancellable getCancellable() {
40
		return cancellable;
41
	}
42
	public void setDPI(double dpi) {
43
		this.hasDPI=true;
44
		this.dpi=dpi;
45
	}
46
	public double getDPI(){
47
		return dpi;
48
	}
49
	public boolean hasDPI() {
50
		return hasDPI;
51
	}
52

  
53
}
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/geom/operation/DrawInts.java
1
package org.gvsig.fmap.geom.operation;
2

  
3
import java.awt.Graphics2D;
4
import java.awt.geom.AffineTransform;
5
import java.awt.geom.PathIterator;
6

  
7
import org.apache.log4j.Logger;
8
import org.gvsig.fmap.geom.Geometry;
9
import org.gvsig.fmap.geom.GeometryManager;
10
import org.gvsig.fmap.geom.primitive.Curve2D;
11
import org.gvsig.fmap.geom.primitive.GeneralPathX;
12
import org.gvsig.fmap.geom.primitive.Surface2D;
13
import org.gvsig.fmap.mapcontext.ViewPort;
14
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
15
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
16

  
17
import com.iver.utiles.swing.threads.Cancellable;
18

  
19
public class DrawInts extends GeometryOperation {
20

  
21
	private static Logger logger = Logger.getLogger(DrawInts.class);
22

  
23
	public static final int CODE = GeometryManager.getInstance()
24
			.registerGeometryOperation("drawInts", new DrawInts());
25

  
26
	public Object invoke(Geometry geom, GeometryOperationContext ctx) {
27
		DrawOperationContext doc=(DrawOperationContext)ctx;
28
		ViewPort viewPort = doc.getViewPort();
29
		ISymbol symbol = doc.getSymbol();
30
		Graphics2D g=doc.getGraphics();
31
		Cancellable cancel=doc.getCancellable();
32
//		 make the symbol to resize itself with the current rendering context
33
		if (doc.hasDPI()){
34
			double previousSize = ((CartographicSupport)symbol).
35
			toCartographicSize(viewPort, doc.getDPI(), geom);
36
			// draw it as normally
37
			Geometry decimatedShape = transformToInts(geom, viewPort.getAffineTransform());
38
			symbol.draw(g, viewPort.getAffineTransform(), decimatedShape,cancel);
39
			// restore previous size
40
			((CartographicSupport)symbol).setCartographicSize(previousSize, geom);
41
		}else{
42
			Geometry decimatedShape = transformToInts(geom, viewPort.getAffineTransform());
43
			symbol.draw(g, viewPort.getAffineTransform(), decimatedShape,cancel);
44
		}
45
		return null;
46
	}
47

  
48
	public int getOperationIndex() {
49
		return CODE;
50
	}
51
	private static Geometry transformToInts(Geometry gp, AffineTransform at) {
52
	        GeneralPathX newGp = new GeneralPathX();
53
	        double[] theData = new double[6];
54
	        double[] aux = new double[6];
55

  
56
	        // newGp.reset();
57
	        PathIterator theIterator;
58
	        int theType;
59
	        int numParts = 0;
60

  
61
	        java.awt.geom.Point2D ptDst = new java.awt.geom.Point2D.Double();
62
	        java.awt.geom.Point2D ptSrc = new java.awt.geom.Point2D.Double();
63
	        boolean bFirst = true;
64
	        int xInt, yInt, antX = -1, antY = -1;
65

  
66

  
67
	        theIterator = gp.getPathIterator(null); //, flatness);
68
	        int numSegmentsAdded = 0;
69
	        while (!theIterator.isDone()) {
70
	            theType = theIterator.currentSegment(theData);
71

  
72
	            switch (theType) {
73
	                case PathIterator.SEG_MOVETO:
74
	                    numParts++;
75
	                    ptSrc.setLocation(theData[0], theData[1]);
76
	                    at.transform(ptSrc, ptDst);
77
	                    antX = (int) ptDst.getX();
78
	                    antY = (int) ptDst.getY();
79
	                    newGp.moveTo(antX, antY);
80
	                    numSegmentsAdded++;
81
	                    bFirst = true;
82
	                    break;
83

  
84
	                case PathIterator.SEG_LINETO:
85
	                    ptSrc.setLocation(theData[0], theData[1]);
86
	                    at.transform(ptSrc, ptDst);
87
	                    xInt = (int) ptDst.getX();
88
	                    yInt = (int) ptDst.getY();
89
	                    if ((bFirst) || ((xInt != antX) || (yInt != antY)))
90
	                    {
91
	                        newGp.lineTo(xInt, yInt);
92
	                        antX = xInt;
93
	                        antY = yInt;
94
	                        bFirst = false;
95
	                        numSegmentsAdded++;
96
	                    }
97
	                    break;
98

  
99
	                case PathIterator.SEG_QUADTO:
100
	                    at.transform(theData,0,aux,0,2);
101
	                    newGp.quadTo(aux[0], aux[1], aux[2], aux[3]);
102
	                    numSegmentsAdded++;
103
	                    break;
104

  
105
	                case PathIterator.SEG_CUBICTO:
106
	                    at.transform(theData,0,aux,0,3);
107
	                    newGp.curveTo(aux[0], aux[1], aux[2], aux[3], aux[4], aux[5]);
108
	                    numSegmentsAdded++;
109
	                    break;
110

  
111
	                case PathIterator.SEG_CLOSE:
112
	                    if (numSegmentsAdded < 3)
113
	                        newGp.lineTo(antX, antY);
114
	                    newGp.closePath();
115

  
116
	                    break;
117
	            } //end switch
118

  
119
	            theIterator.next();
120
	        } //end while loop
121

  
122
	        Geometry geom = null;
123
	        switch (gp.getType())
124
	        {
125
	            case Geometry.TYPES.POINT: //Tipo punto
126
	            case Geometry.TYPES.POINT + Geometry.TYPES.Z:
127
	                geom = new org.gvsig.fmap.geom.primitive.Point2D(null, null, ptDst.getX(), ptDst.getY());
128
	                break;
129

  
130
	            case Geometry.TYPES.CURVE:
131
	            case Geometry.TYPES.CURVE + Geometry.TYPES.Z:
132
	            case Geometry.TYPES.ARC:
133
	            	geom = new Curve2D(null, null, newGp);
134
	                break;
135

  
136
	            case Geometry.TYPES.SURFACE:
137
	            case Geometry.TYPES.SURFACE + Geometry.TYPES.Z:
138
	            case Geometry.TYPES.CIRCLE:
139
	            case Geometry.TYPES.ELLIPSE:
140

  
141
	                geom = new Surface2D(null, null, newGp);
142
	                break;
143
	        }
144
	        return geom;
145
	    }
146

  
147

  
148
}
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/core/geometries/utils/FLabel.java
55 55
import java.awt.geom.Rectangle2D;
56 56

  
57 57
import org.apache.batik.ext.awt.geom.PathLength;
58
import org.gvsig.fmap.core.shapes.FMultiPoint2D;
59
import org.gvsig.fmap.core.shapes.FPoint2D;
60
import org.gvsig.fmap.core.shapes.FShape;
58
import org.gvsig.fmap.geom.aggregate.MultiPoint2D;
59
import org.gvsig.fmap.geom.primitive.FShape;
60
import org.gvsig.fmap.geom.util.Converter;
61 61
import org.gvsig.fmap.mapcontext.ViewPort;
62 62
import org.gvsig.fmap.mapcontext.rendering.symbols.FGraphicUtilities;
63 63
import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol;
......
299 299
	 *
300 300
	 * @return nuevo FLabel creado.
301 301
	 */
302
	public static FLabel createFLabel(FShape shp) {
302
	public static FLabel createFLabel(org.gvsig.fmap.geom.Geometry geom) {
303 303
		float angle;
304
		Point2D pAux = createLabelPoint(shp);
304
		Point2D pAux = createLabelPoint(geom);
305 305

  
306 306
		FLabel label = new FLabel();
307 307
		label.setOrig(pAux);
308
		switch (shp.getShapeType()) {
309
			case FShape.LINE:
310
            case FShape.LINE + FShape.Z:
311
				PathLength pathLen = new PathLength(shp);
308
		switch (geom.getType()) {
309
			case org.gvsig.fmap.geom.Geometry.TYPES.CURVE:
310
            case org.gvsig.fmap.geom.Geometry.TYPES.CURVE + org.gvsig.fmap.geom.Geometry.TYPES.Z:
311
				PathLength pathLen = new PathLength(geom);
312 312
				float midDistance = pathLen.lengthOfPath() / 2;
313 313
				angle = pathLen.angleAtLength(midDistance);
314 314

  
......
324 324

  
325 325
		return label;
326 326
	}
327
	public static Point2D createLabelPoint(Shape shp) {
327
	public static Point2D createLabelPoint(org.gvsig.fmap.geom.Geometry geom) {
328 328
		Point2D pAux = null;
329
		if (shp instanceof FShape){
330
		switch (((FShape)shp).getShapeType()) {
331
			case FShape.POINT:
332
            case FShape.POINT + FShape.Z:
333
				pAux = new Point2D.Double(((FPoint2D) shp).getX(),
334
						((FPoint2D) shp).getY());
329
		switch (geom.getType()) {
330
			case org.gvsig.fmap.geom.Geometry.TYPES.POINT:
331
            case org.gvsig.fmap.geom.Geometry.TYPES.POINT + org.gvsig.fmap.geom.Geometry.TYPES.Z:
332
				pAux = new Point2D.Double(((org.gvsig.fmap.geom.primitive.Point2D) geom).getX(),
333
						((org.gvsig.fmap.geom.primitive.Point2D) geom).getY());
335 334
				return pAux;
336 335

  
337
			case FShape.LINE:
338
            case FShape.LINE + FShape.Z:
339
				PathLength pathLen = new PathLength(shp);
336
			case org.gvsig.fmap.geom.Geometry.TYPES.CURVE:
337
            case org.gvsig.fmap.geom.Geometry.TYPES.CURVE + org.gvsig.fmap.geom.Geometry.TYPES.Z:
338
				PathLength pathLen = new PathLength(geom);
340 339

  
341 340
				// if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
342 341
				float midDistance = pathLen.lengthOfPath() / 2;
343 342
				pAux = pathLen.pointAtLength(midDistance);
344 343
				return pAux;
345 344

  
346
			case FShape.POLYGON:
347
            case FShape.POLYGON + FShape.Z:
348
				Geometry geo = FConverter.java2d_to_jts((FShape)shp);
345
			case org.gvsig.fmap.geom.Geometry.TYPES.SURFACE:
346
            case org.gvsig.fmap.geom.Geometry.TYPES.SURFACE + org.gvsig.fmap.geom.Geometry.TYPES.Z:
347
				Geometry geo = Converter.java2d_to_jts((FShape)geom);
349 348

  
350 349
				if (geo == null) {
351 350
					return null;
......
354 353
				Point pJTS = geo.getCentroid();
355 354

  
356 355
				if (pJTS != null) {
357
					FShape pLabel = FConverter.jts_to_java2d(pJTS);
358
					return new Point2D.Double(((FPoint2D) pLabel).getX(),
359
							((FPoint2D) pLabel).getY());
356
					FShape pLabel = Converter.jts_to_java2d(pJTS);
357
					return new Point2D.Double(((org.gvsig.fmap.geom.primitive.Point2D) pLabel).getX(),
358
							((org.gvsig.fmap.geom.primitive.Point2D) pLabel).getY());
360 359
				}
360
				break;
361
            case org.gvsig.fmap.geom.Geometry.TYPES.MULTIPOINT:
362
            	int num=((MultiPoint2D)geom).getPrimitivesNumber();
363
    			Rectangle2D r=null;
364
    			if (num>0){
365
    				r= ((MultiPoint2D)geom).getPoint(0).getBounds2D();
366
    				for (int i=1;i<num;i++){
367
    					org.gvsig.fmap.geom.primitive.Point2D fp=((MultiPoint2D)geom).getPoint(i);
368
    					r.add(new Point2D.Double(fp.getX(),fp.getY()));
369
    				}
370
    			}
371
    			if (r!=null)
372
    			return new Point2D.Double(r.getCenterX(),r.getCenterY());
373
    			break;
374

  
361 375
		} // switch
362
		}else if (shp instanceof FMultiPoint2D){
363
			int num=((FMultiPoint2D)shp).getNumPoints();
364
			Rectangle2D r=null;
365
			if (num>0){
366
				r= ((FMultiPoint2D)shp).getPoint(0).getBounds2D();
367
				for (int i=1;i<num;i++){
368
					FPoint2D fp=((FMultiPoint2D)shp).getPoint(i);
369
					r.add(new Point2D.Double(fp.getX(),fp.getY()));
370
				}
371
			}
372
			if (r!=null)
373
			return new Point2D.Double(r.getCenterX(),r.getCenterY());
374
		}
375 376
				return null;
376 377
	}
377 378
	public void setTypeFont(String t) {
......
425 426
	 */
426 427
	public void draw(Graphics2D g, AffineTransform affineTransform, Shape theShape, ISymbol theSymbol) {
427 428
        FGraphicUtilities.DrawLabel(g, affineTransform,
428
                (FShape) theShape, (FSymbol) theSymbol, this);
429
                (org.gvsig.fmap.geom.Geometry) theShape, (FSymbol) theSymbol, this);
429 430

  
430 431

  
431 432
	}
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/core/shapes/adapters/CircleAdapter.java
46 46
import java.awt.geom.Ellipse2D;
47 47
import java.awt.geom.Point2D;
48 48

  
49
import org.gvsig.fmap.core.shapes.FPolygon2D;
50
import org.gvsig.fmap.core.shapes.FShape;
51
import org.gvsig.fmap.core.shapes.GeneralPathX;
49
import org.gvsig.fmap.geom.Geometry;
50
import org.gvsig.fmap.geom.primitive.GeneralPathX;
51
import org.gvsig.fmap.geom.primitive.Surface2D;
52 52
import org.gvsig.fmap.mapcontext.rendering.symbols.IFillSymbol;
53 53
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
54 54
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleLineSymbol;
......
70 70
     *
71 71
     * @return DOCUMENT ME!
72 72
     */
73
    public FShape getShape(AffineTransform at) {
74
    	GeneralPathX polyLine = new GeneralPathX(new FPolygon2D(getGPX()));
73
    public Geometry getGeometry(AffineTransform at) {
74
    	GeneralPathX polyLine = new GeneralPathX(new Surface2D(getGPX()));
75 75
    	polyLine.transform(at);
76
    	return new FPolygon2D(polyLine);
76
    	return new Surface2D(polyLine);
77 77
    }
78 78

  
79 79
    /**
......
84 84
     * @param symbol DOCUMENT ME!
85 85
     */
86 86
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
87
    	FShape shapeAux=getShape(at);
87
    	Geometry shapeAux=getGeometry(at);
88 88
    	symbol.draw(g,at,shapeAux, null);
89 89
        // FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
90 90
    }
......
114 114
            symbol.setOutlineColor(Color.red);
115 115
            symbol.setColor(null);
116 116
            */
117
            FShape shapeAux=getShape(at);
117
            Geometry shapeAux=getGeometry(at);
118 118

  
119 119
            // jaume: move to ISymbol
120 120
            IFillSymbol symbol = SymbologyFactory.createDefaultFillSymbol();
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/core/shapes/adapters/RectangleAdapter.java
42 42

  
43 43
import java.awt.geom.Point2D;
44 44

  
45
import org.gvsig.fmap.core.shapes.GeneralPathX;
45
import org.gvsig.fmap.geom.primitive.GeneralPathX;
46 46

  
47

  
48

  
49 47
/**
50 48
 * DOCUMENT ME!
51 49
 *
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/core/shapes/adapters/PolygonAdapter.java
44 44
import java.awt.geom.AffineTransform;
45 45
import java.awt.geom.Point2D;
46 46

  
47
import org.gvsig.fmap.core.shapes.FPolygon2D;
48
import org.gvsig.fmap.core.shapes.FShape;
49
import org.gvsig.fmap.core.shapes.GeneralPathX;
47
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.geom.primitive.GeneralPathX;
49
import org.gvsig.fmap.geom.primitive.Surface2D;
50 50
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
51 51

  
52 52

  
......
91 91
     *
92 92
     * @return DOCUMENT ME!
93 93
     */
94
    public FShape getShape() {
95
        return new FPolygon2D(getGPX());
94
    public Geometry getGeometry() {
95
        return new Surface2D(getGPX());
96 96
    }
97 97

  
98 98
    /**
......
103 103
     * @param symbol DOCUMENT ME!
104 104
     */
105 105
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
106
        GeneralPathX rectangle = new GeneralPathX(getShape());
106
        GeneralPathX rectangle = new GeneralPathX(getGeometry());
107 107
        rectangle.transform(at);
108 108

  
109
        FShape shapeAux = new FPolygon2D(rectangle);
109
        Geometry shapeAux = new Surface2D(rectangle);
110 110
        symbol.draw(g,at,shapeAux, null);
111 111
    }
112 112
}
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/core/shapes/adapters/PointAdapter.java
43 43
import java.awt.Graphics2D;
44 44
import java.awt.geom.AffineTransform;
45 45

  
46
import org.gvsig.fmap.core.shapes.FPoint2D;
47
import org.gvsig.fmap.core.shapes.FShape;
48
import org.gvsig.fmap.core.shapes.GeneralPathX;
46
import org.gvsig.fmap.geom.Geometry;
47
import org.gvsig.fmap.geom.primitive.GeneralPathX;
48
import org.gvsig.fmap.geom.primitive.Point2D;
49 49
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
50 50

  
51 51

  
......
65 65
     * @param symbol DOCUMENT ME!
66 66
     */
67 67
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
68
        GeneralPathX point = new GeneralPathX(getShape());
68
        GeneralPathX point = new GeneralPathX(getGeometry());
69 69
        point.transform(at);
70 70

  
71
        FShape shapeAux = new FPoint2D(point.getCurrentPoint());
71
        Geometry shapeAux = new Point2D(point.getCurrentPoint());
72 72
        symbol.draw(g,at,shapeAux, null);
73 73
        // FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
74 74
    }
......
78 78
     *
79 79
     * @return DOCUMENT ME!
80 80
     */
81
    public FShape getShape() {
82
        return new FPoint2D(getGPX().getCurrentPoint());
81
    public Geometry getGeometry() {
82
        return new Point2D(getGPX().getCurrentPoint());
83 83
    }
84 84
}
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/core/shapes/adapters/GeometryAdapter.java
46 46
import java.awt.geom.Rectangle2D;
47 47
import java.util.ArrayList;
48 48

  
49
import org.gvsig.fmap.core.shapes.FShape;
50
import org.gvsig.fmap.core.shapes.GeneralPathX;
49
import org.gvsig.fmap.geom.Geometry;
50
import org.gvsig.fmap.geom.primitive.GeneralPathX;
51 51
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
52 52

  
53 53
import com.iver.utiles.XMLEntity;
......
153 153
     *
154 154
     * @return FShape.
155 155
     */
156
    public abstract FShape getShape(AffineTransform at);
156
    public abstract Geometry getGeometry(AffineTransform at);
157 157

  
158 158
    /**
159 159
     * Returns all the points of Geometry.
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/core/shapes/adapters/PolyLineAdapter.java
45 45
import java.awt.geom.AffineTransform;
46 46
import java.awt.geom.Point2D;
47 47

  
48
import org.gvsig.fmap.core.shapes.FPolyline2D;
49
import org.gvsig.fmap.core.shapes.FShape;
50
import org.gvsig.fmap.core.shapes.GeneralPathX;
48
import org.gvsig.fmap.geom.Geometry;
49
import org.gvsig.fmap.geom.primitive.Curve2D;
50
import org.gvsig.fmap.geom.primitive.GeneralPathX;
51 51
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol;
52 52
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
53 53
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
......
95 95
     *
96 96
     * @return DOCUMENT ME!
97 97
     */
98
    public FShape getShape(AffineTransform at) {
99
    	 GeneralPathX polyLine = new GeneralPathX(new FPolyline2D(getGPX()));
98
    public Geometry getGeometry(AffineTransform at) {
99
    	 GeneralPathX polyLine = new GeneralPathX(new Curve2D(getGPX()));
100 100
         polyLine.transform(at);
101 101

  
102
        return new FPolyline2D(polyLine);
102
        return new Curve2D(polyLine);
103 103
    }
104 104

  
105 105
    /**
......
110 110
     * @param symbol DOCUMENT ME!
111 111
     */
112 112
    public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
113
    	FShape shapeAux =getShape(at);
113
    	Geometry shapeAux =getGeometry(at);
114 114
    	symbol.draw(g,at,shapeAux, null);
115 115
    	// FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
116 116
    }
......
127 127
            obtainShape(pointPosition);
128 128
        }
129 129

  
130
        FShape shapeAux=getShape(at);
130
        Geometry shapeAux=getGeometry(at);
131 131
        //ISymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
132 132
        ILineSymbol symbol = SymbologyFactory.createDefaultLineSymbol();
133 133
        symbol.setLineColor(Color.RED);

Also available in: Unified diff