gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / symbology3d / fill / impl / SimpleFill3DSymbol.java @ 317
History | View | Annotate | Download (5.67 KB)
1 |
package org.gvsig.gvsig3d.impl.symbology3d.fill.impl; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.Rectangle; |
6 |
import java.awt.geom.AffineTransform; |
7 |
|
8 |
import org.gvsig.compat.print.PrintAttributes; |
9 |
import org.gvsig.fmap.dal.feature.Feature; |
10 |
import org.gvsig.fmap.geom.Geometry; |
11 |
import org.gvsig.fmap.geom.GeometryLocator; |
12 |
import org.gvsig.fmap.geom.GeometryManager; |
13 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
14 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
15 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
16 |
import org.gvsig.fmap.geom.primitive.GeneralPathXIterator; |
17 |
import org.gvsig.fmap.geom.primitive.Surface; |
18 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
19 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
20 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
21 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
22 |
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.SimpleMarker3DSymbol; |
23 |
import org.gvsig.gvsig3d.symbology3d.fill.ISimpleFill3DSymbol; |
24 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
25 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
26 |
import org.gvsig.osgvp.geometry.GeoMultiPolygon3D; |
27 |
import org.gvsig.osgvp.geometry.GeoPointArray3D; |
28 |
import org.gvsig.osgvp.geometry.GeoPolygon3D; |
29 |
import org.gvsig.osgvp.geometry.GeoPolygonList3D; |
30 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol; |
31 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
32 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol; |
33 |
import org.gvsig.tools.task.Cancellable; |
34 |
import org.gvsig.tools.util.Callable; |
35 |
import org.slf4j.Logger; |
36 |
import org.slf4j.LoggerFactory; |
37 |
|
38 |
|
39 |
/**
|
40 |
*
|
41 |
* @author jtorres
|
42 |
*
|
43 |
*/
|
44 |
|
45 |
public class SimpleFill3DSymbol extends AbstractFillSymbol implements ISimpleFill3DSymbol{ |
46 |
|
47 |
public static final String SIMPLE_FILL3D_SYMBOL_PERSISTENCE_DEFINITION_NAME = "SimpleFill3DSymbol"; |
48 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
49 |
private static final Logger LOG = LoggerFactory.getLogger(SimpleFill3DSymbol.class); |
50 |
public GeoPolygonList3D _geometry;
|
51 |
public GeoMultiPolygon3D _mpolygon;
|
52 |
|
53 |
public SimpleFill3DSymbol()
|
54 |
{ |
55 |
super();
|
56 |
try {
|
57 |
_geometry = new GeoPolygonList3D();
|
58 |
} catch (NodeException e) {
|
59 |
// TODO Auto-generated catch block
|
60 |
e.printStackTrace(); |
61 |
} |
62 |
} |
63 |
|
64 |
public ISymbol getSymbolForSelection() {
|
65 |
// TODO Auto-generated method stub
|
66 |
return null; |
67 |
} |
68 |
|
69 |
|
70 |
|
71 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
72 |
Geometry geom, Feature f, Cancellable cancel) { |
73 |
|
74 |
Color c = getFillColor();
|
75 |
//geom.getClass().getName()
|
76 |
|
77 |
|
78 |
//WAITING for gvSIG ARCHITECTS to do something with polygons with holes in shp files
|
79 |
//in the meanwhile nothing is gonna happen with this kind of polygons
|
80 |
if (geom.getGeometryType().isTypeOf(Geometry.TYPES.SURFACE))
|
81 |
{ |
82 |
Surface s = (Surface)geom.cloneGeometry(); |
83 |
_geometry.addMultiPolygon(getGeoMultiPolygon(s)); |
84 |
} |
85 |
|
86 |
|
87 |
// if (c!=null && hasFill()) {
|
88 |
// g.setColor(c);
|
89 |
//
|
90 |
//
|
91 |
//
|
92 |
// g.fill(geom.getShape(affineTransform));
|
93 |
// }
|
94 |
// Border color
|
95 |
// if (getOutline() != null && hasOutline()) {
|
96 |
// getOutline().draw(g, affineTransform, geom, f, cancel);
|
97 |
// }
|
98 |
|
99 |
} |
100 |
|
101 |
|
102 |
public GeoMultiPolygon3D getGeoMultiPolygon(Surface surface)
|
103 |
{ |
104 |
GeoMultiPolygon3D gmpoly = null;
|
105 |
GeoPolygon3D poly = null;
|
106 |
try {
|
107 |
gmpoly= new GeoMultiPolygon3D();
|
108 |
poly = new GeoPolygon3D();
|
109 |
} catch (NodeException e) {
|
110 |
// TODO Auto-generated catch block
|
111 |
e.printStackTrace(); |
112 |
} |
113 |
int numVerts = surface.getNumVertices();
|
114 |
if (surface.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D))
|
115 |
for(int i=0;i<numVerts;i++) |
116 |
poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),surface.getCoordinateAt(i, 2)); |
117 |
else
|
118 |
for(int i=0;i<numVerts;i++) |
119 |
poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),1.0); |
120 |
gmpoly.addPolygon(poly); |
121 |
|
122 |
return gmpoly;
|
123 |
} |
124 |
public GeoPolygonList3D getGeometry(){
|
125 |
return _geometry;
|
126 |
} |
127 |
public int getSymbolType() { |
128 |
// TODO Auto-generated method stub
|
129 |
return 0; |
130 |
} |
131 |
|
132 |
public void drawInsideRectangle(Graphics2D g, |
133 |
AffineTransform scaleInstance, Rectangle r, |
134 |
PrintAttributes properties) throws SymbolDrawingException {
|
135 |
|
136 |
Rectangle rect = new Rectangle(r.x, r.y, r.width, r.height); |
137 |
rect.setFrame(((int) rect.getMinX())+1, ((int) rect.getMinY())+1, ((int) rect.getWidth())-2, ((int) rect.getHeight())-2); |
138 |
Geometry geom; |
139 |
try {
|
140 |
geom = geomManager.createSurface(new GeneralPathX(rect.getPathIterator(null)), SUBTYPES.GEOM2D); |
141 |
} catch (CreateGeometryException e) {
|
142 |
LOG.error("Creating a surface", e);
|
143 |
throw new SymbolDrawingException(getSymbolType()); |
144 |
} |
145 |
|
146 |
Color c = getFillColor();
|
147 |
if (c != null && hasFill()) { |
148 |
g.setColor(c); |
149 |
g.fillRect(rect.x, rect.y, rect.width, rect.height); |
150 |
} |
151 |
// Border Polygons
|
152 |
//
|
153 |
// if (getOutline() != null && hasOutline()) {
|
154 |
// if (properties==null)
|
155 |
// getOutline().draw(g, scaleInstance, geom, null, null);
|
156 |
// else
|
157 |
// print(g, new AffineTransform(), geom, properties);
|
158 |
// }
|
159 |
|
160 |
} |
161 |
public static class RegisterSymbol implements Callable { |
162 |
|
163 |
public Object call() throws Exception { |
164 |
int[] shapeTypes; |
165 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
166 |
|
167 |
shapeTypes = |
168 |
new int[] { Geometry.TYPES.SURFACE, Geometry.TYPES.MULTISURFACE}; |
169 |
manager.registerSymbol(ISimpleFill3DSymbol.SYMBOL_NAME, |
170 |
shapeTypes, |
171 |
SimpleFill3DSymbol.class,"project.document.view3d");
|
172 |
|
173 |
return Boolean.TRUE; |
174 |
} |
175 |
|
176 |
} |
177 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
178 |
PrintAttributes properties) { |
179 |
// TODO Auto-generated method stub
|
180 |
|
181 |
} |
182 |
|
183 |
|
184 |
} |