root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / geom / operation / DrawInts.java @ 27245
History | View | Annotate | Download (5.13 KB)
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.gvsig.fmap.geom.Geometry; |
8 |
import org.gvsig.fmap.geom.GeometryLocator; |
9 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
10 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
11 |
import org.gvsig.fmap.mapcontext.ViewPort; |
12 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
13 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
14 |
import org.gvsig.tools.task.Cancellable; |
15 |
import org.slf4j.Logger; |
16 |
import org.slf4j.LoggerFactory; |
17 |
|
18 |
public class DrawInts extends GeometryOperation { |
19 |
|
20 |
final static private Logger logger = LoggerFactory.getLogger(DrawInts.class); |
21 |
|
22 |
public static final int CODE = GeometryLocator.getGeometryManager() |
23 |
.registerGeometryOperation("drawInts", new DrawInts()); |
24 |
|
25 |
public Object invoke(Geometry geom, GeometryOperationContext ctx) { |
26 |
DrawOperationContext doc=(DrawOperationContext)ctx; |
27 |
ViewPort viewPort = doc.getViewPort(); |
28 |
ISymbol symbol = doc.getSymbol(); |
29 |
Graphics2D g=doc.getGraphics();
|
30 |
Cancellable cancel=doc.getCancellable(); |
31 |
// make the symbol to resize itself with the current rendering context
|
32 |
if (doc.hasDPI()){
|
33 |
double previousSize = ((CartographicSupport)symbol).
|
34 |
toCartographicSize(viewPort, doc.getDPI(), geom); |
35 |
// draw it as normally
|
36 |
Geometry decimatedShape = transformToInts(geom, viewPort.getAffineTransform()); |
37 |
symbol.draw(g, viewPort.getAffineTransform(), decimatedShape,cancel); |
38 |
// restore previous size
|
39 |
((CartographicSupport)symbol).setCartographicSize(previousSize, geom); |
40 |
}else{
|
41 |
Geometry decimatedShape = transformToInts(geom, viewPort.getAffineTransform()); |
42 |
symbol.draw(g, viewPort.getAffineTransform(), decimatedShape,cancel); |
43 |
} |
44 |
return null; |
45 |
} |
46 |
|
47 |
public int getOperationIndex() { |
48 |
return CODE;
|
49 |
} |
50 |
|
51 |
private 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 |
} |
115 |
newGp.closePath(); |
116 |
|
117 |
break;
|
118 |
} //end switch
|
119 |
|
120 |
theIterator.next(); |
121 |
} //end while loop
|
122 |
|
123 |
Geometry geom = null;
|
124 |
switch (gp.getType()) {
|
125 |
case Geometry.TYPES.POINT:
|
126 |
geom = UtilFunctions.createPoint(ptDst.getX(), ptDst.getY()); |
127 |
break;
|
128 |
case Geometry.TYPES.CURVE:
|
129 |
case Geometry.TYPES.ARC:
|
130 |
geom = UtilFunctions.createCurve(newGp); |
131 |
break;
|
132 |
|
133 |
case Geometry.TYPES.SURFACE:
|
134 |
case Geometry.TYPES.CIRCLE:
|
135 |
case Geometry.TYPES.ELLIPSE:
|
136 |
|
137 |
geom = UtilFunctions.createSurface(newGp); |
138 |
break;
|
139 |
} |
140 |
return geom;
|
141 |
} |
142 |
|
143 |
public static void register() { |
144 |
// Nothing to do
|
145 |
|
146 |
} |
147 |
|
148 |
|
149 |
} |