svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / DrawUtils.java @ 47790
History | View | Annotate | Download (7.31 KB)
1 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl; |
---|---|
2 |
|
3 |
import java.awt.Graphics2D; |
4 |
import java.awt.geom.AffineTransform; |
5 |
import org.gvsig.fmap.dal.feature.Feature; |
6 |
import org.gvsig.fmap.geom.Geometry; |
7 |
import org.gvsig.fmap.geom.GeometryException; |
8 |
import org.gvsig.fmap.geom.GeometryLocator; |
9 |
import org.gvsig.fmap.geom.GeometryManager; |
10 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
11 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
12 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
13 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
14 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
15 |
import org.gvsig.fmap.geom.primitive.Curve; |
16 |
import org.gvsig.fmap.geom.primitive.Surface; |
17 |
import org.gvsig.fmap.mapcontext.ViewPort; |
18 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
19 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
20 |
import org.gvsig.tools.task.Cancellable; |
21 |
|
22 |
public class DrawUtils { |
23 |
|
24 |
private static GeometryManager geometryManager = null; |
25 |
|
26 |
private static GeometryManager getGeometryManager() { |
27 |
if( geometryManager == null ) { |
28 |
geometryManager = GeometryLocator.getGeometryManager(); |
29 |
} |
30 |
return geometryManager;
|
31 |
} |
32 |
|
33 |
public static void drawInts(Graphics2D g, ViewPort viewPort, Cancellable cancel, double dpi, ISymbol symbol, Feature feature, Geometry geom) throws GeometryOperationException { |
34 |
|
35 |
try {
|
36 |
if( geom instanceof Aggregate ) { |
37 |
for( Geometry prim : (Aggregate) geom ) {
|
38 |
drawInts(g, viewPort, cancel, dpi, symbol, feature, prim); |
39 |
} |
40 |
return;
|
41 |
} |
42 |
|
43 |
((CartographicSupport) symbol).setCartographicContext(viewPort, dpi, geom); |
44 |
// draw it as normally
|
45 |
Geometry transformedGeometry; |
46 |
transformedGeometry = transformGeometry(geom.cloneGeometry(), viewPort.getAffineTransform()); |
47 |
|
48 |
// the AffineTransform has to be null because the transformToInts method reprojects the geometry
|
49 |
symbol.draw(g, null, transformedGeometry, feature, cancel);
|
50 |
|
51 |
} catch (GeometryException e) {
|
52 |
throw new GeometryOperationException(e); |
53 |
} |
54 |
} |
55 |
|
56 |
public static void drawInts(Graphics2D g, ViewPort viewPort, ISymbol symbol, Feature feature, Geometry geom) throws GeometryOperationException { |
57 |
|
58 |
try {
|
59 |
if( geom instanceof Aggregate ) { |
60 |
for( Geometry prim : (Aggregate) geom ) {
|
61 |
drawInts(g, viewPort, symbol, feature, prim); |
62 |
} |
63 |
return;
|
64 |
} |
65 |
Geometry transformedGeometry = transformGeometry(geom.cloneGeometry(), viewPort.getAffineTransform()); |
66 |
symbol.draw(g, viewPort.getAffineTransform(), transformedGeometry, feature, null);
|
67 |
|
68 |
} catch (GeometryException e) {
|
69 |
throw new GeometryOperationException(e); |
70 |
} |
71 |
} |
72 |
|
73 |
/**
|
74 |
* @param geom
|
75 |
* @param affineTransform
|
76 |
* @return
|
77 |
* @throws GeometryException
|
78 |
*/
|
79 |
private static Geometry transformGeometry(Geometry geom, AffineTransform affineTransform) throws GeometryException { |
80 |
if( geom.canBeTransformed(affineTransform) ) {
|
81 |
geom.transform(affineTransform); |
82 |
return geom;
|
83 |
} |
84 |
if( geom instanceof Curve || geom instanceof Curve ) { |
85 |
MultiLine lines = geom.toLines(); |
86 |
lines.transform(affineTransform); |
87 |
return lines;
|
88 |
} |
89 |
if( geom instanceof Surface || geom instanceof MultiSurface ) { |
90 |
MultiPolygon polygons = geom.toPolygons(); |
91 |
polygons.transform(affineTransform); |
92 |
return polygons;
|
93 |
} |
94 |
return null; |
95 |
} |
96 |
|
97 |
// private static Geometry transformToInts(Geometry gp, AffineTransform at) throws CreateGeometryException {
|
98 |
// GeneralPathX newGp = new GeneralPathX();
|
99 |
// double[] theData = new double[6];
|
100 |
// double[] aux = new double[6];
|
101 |
//
|
102 |
// // newGp.reset();
|
103 |
// PathIterator theIterator;
|
104 |
// int theType;
|
105 |
// int numParts = 0;
|
106 |
//
|
107 |
// java.awt.geom.Point2D ptDst = new java.awt.geom.Point2D.Double();
|
108 |
// java.awt.geom.Point2D ptSrc = new java.awt.geom.Point2D.Double();
|
109 |
// boolean bFirst = true;
|
110 |
// int xInt, yInt, antX = -1, antY = -1;
|
111 |
//
|
112 |
// theIterator = gp.getPathIterator(null); //, flatness);
|
113 |
// int numSegmentsAdded = 0;
|
114 |
// while( !theIterator.isDone() ) {
|
115 |
// theType = theIterator.currentSegment(theData);
|
116 |
//
|
117 |
// switch( theType ) {
|
118 |
// case PathIterator.SEG_MOVETO:
|
119 |
// numParts++;
|
120 |
// ptSrc.setLocation(theData[0], theData[1]);
|
121 |
// at.transform(ptSrc, ptDst);
|
122 |
// antX = (int) ptDst.getX();
|
123 |
// antY = (int) ptDst.getY();
|
124 |
// newGp.moveTo(antX, antY);
|
125 |
// numSegmentsAdded++;
|
126 |
// bFirst = true;
|
127 |
// break;
|
128 |
//
|
129 |
// case PathIterator.SEG_LINETO:
|
130 |
// ptSrc.setLocation(theData[0], theData[1]);
|
131 |
// at.transform(ptSrc, ptDst);
|
132 |
// xInt = (int) ptDst.getX();
|
133 |
// yInt = (int) ptDst.getY();
|
134 |
// if( (bFirst) || ((xInt != antX) || (yInt != antY)) ) {
|
135 |
// newGp.lineTo(xInt, yInt);
|
136 |
// antX = xInt;
|
137 |
// antY = yInt;
|
138 |
// bFirst = false;
|
139 |
// numSegmentsAdded++;
|
140 |
// }
|
141 |
// break;
|
142 |
//
|
143 |
// case PathIterator.SEG_QUADTO:
|
144 |
// at.transform(theData, 0, aux, 0, 2);
|
145 |
// newGp.quadTo(aux[0], aux[1], aux[2], aux[3]);
|
146 |
// numSegmentsAdded++;
|
147 |
// break;
|
148 |
//
|
149 |
// case PathIterator.SEG_CUBICTO:
|
150 |
// at.transform(theData, 0, aux, 0, 3);
|
151 |
// newGp.curveTo(aux[0], aux[1], aux[2], aux[3], aux[4], aux[5]);
|
152 |
// numSegmentsAdded++;
|
153 |
// break;
|
154 |
//
|
155 |
// case PathIterator.SEG_CLOSE:
|
156 |
// if( numSegmentsAdded < 3 ) {
|
157 |
// newGp.lineTo(antX, antY);
|
158 |
// }
|
159 |
// newGp.closePath();
|
160 |
//
|
161 |
// break;
|
162 |
// } //end switch
|
163 |
//
|
164 |
// theIterator.next();
|
165 |
// } //end while loop
|
166 |
//
|
167 |
// Geometry geom = null;
|
168 |
// GeometryType geometryType = gp.getGeometryType();
|
169 |
//
|
170 |
// if( geometryType.isTypeOf(Geometry.TYPES.POINT) ) {
|
171 |
// geom = getGeometryManager().createPoint(ptDst.getX(), ptDst.getY(), Geometry.SUBTYPES.GEOM2D);
|
172 |
// } else if( geometryType.isTypeOf(Geometry.TYPES.MULTIPOINT) ) {
|
173 |
// geom = getGeometryManager().createMultiPoint(newGp, Geometry.SUBTYPES.GEOM2D);
|
174 |
// } else if( geometryType.isTypeOf(Geometry.TYPES.CURVE) ) {
|
175 |
// geom = getGeometryManager().createCurve(newGp, Geometry.SUBTYPES.GEOM2D);
|
176 |
// } else if( geometryType.isTypeOf(Geometry.TYPES.MULTICURVE) ) {
|
177 |
// geom = getGeometryManager().createMultiCurve(newGp, Geometry.SUBTYPES.GEOM2D);
|
178 |
// } else if( geometryType.isTypeOf(Geometry.TYPES.SURFACE) ) {
|
179 |
// geom = getGeometryManager().createSurface(newGp, Geometry.SUBTYPES.GEOM2D);
|
180 |
// } else if( geometryType.isTypeOf(Geometry.TYPES.MULTISURFACE) ) {
|
181 |
// geom = getGeometryManager().createMultiSurface(newGp, Geometry.SUBTYPES.GEOM2D);
|
182 |
// }
|
183 |
// return geom;
|
184 |
// }
|
185 |
|
186 |
} |