gvsig-3d / 2.1 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / symbology3d / line / impl / SimpleLine3DSymbol.java @ 385
History | View | Annotate | Download (7.83 KB)
1 |
/* gvSIG 3D extension for gvSIG
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2012 Prodevelop.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Prodevelop, S.L.
|
22 |
* Pza. Don Juan de Villarrasa, 14 - 5
|
23 |
* 46001 Valencia
|
24 |
* Spain
|
25 |
*
|
26 |
* +34 963 510 612
|
27 |
* +34 963 510 968
|
28 |
* prode@prodevelop.es
|
29 |
* http://www.prodevelop.es
|
30 |
*/
|
31 |
/*
|
32 |
* AUTHORS:
|
33 |
* 2012 AI2 - Instituto Universitario de Automatica e Informatica Industrial.
|
34 |
* Universitat Politecnica de Valencia (UPV)
|
35 |
* http://www.ai2.upv.es
|
36 |
*/
|
37 |
|
38 |
|
39 |
package org.gvsig.gvsig3d.impl.symbology3d.line.impl; |
40 |
|
41 |
import java.awt.Color; |
42 |
import java.awt.Graphics2D; |
43 |
import java.awt.Rectangle; |
44 |
import java.awt.geom.AffineTransform; |
45 |
|
46 |
import org.gvsig.compat.print.PrintAttributes; |
47 |
import org.gvsig.fmap.dal.feature.Feature; |
48 |
import org.gvsig.fmap.geom.Geometry; |
49 |
import org.gvsig.fmap.geom.GeometryLocator; |
50 |
import org.gvsig.fmap.geom.GeometryManager; |
51 |
import org.gvsig.fmap.geom.primitive.Curve; |
52 |
import org.gvsig.fmap.geom.primitive.Surface; |
53 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
54 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
55 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
56 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
57 |
import org.gvsig.gvsig3d.impl.symbology3d.fill.impl.SimpleFill3DSymbol; |
58 |
import org.gvsig.gvsig3d.symbology3d.fill.ISimpleFill3DSymbol; |
59 |
import org.gvsig.gvsig3d.symbology3d.line.ISimpleLine3DSymbol; |
60 |
import org.gvsig.osgvp.core.osg.Node; |
61 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
62 |
import org.gvsig.osgvp.geometry.GeoMultiPolygon3D; |
63 |
import org.gvsig.osgvp.geometry.GeoPolygon3D; |
64 |
import org.gvsig.osgvp.geometry.GeoPolygonList3D; |
65 |
import org.gvsig.osgvp.terrain.Terrain; |
66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol; |
67 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ILineStyle; |
68 |
import org.gvsig.tools.task.Cancellable; |
69 |
import org.gvsig.tools.util.Callable; |
70 |
import org.slf4j.Logger; |
71 |
import org.slf4j.LoggerFactory; |
72 |
|
73 |
/**
|
74 |
* @author Jesus Zarzoso- jzarzoso@ai2.upv.es
|
75 |
* @version $Id$
|
76 |
*
|
77 |
*/
|
78 |
public class SimpleLine3DSymbol extends AbstractFillSymbol implements ISimpleLine3DSymbol{ |
79 |
|
80 |
public static final String SIMPLE_FILL3D_SYMBOL_PERSISTENCE_DEFINITION_NAME = "SimpleFill3DSymbol"; |
81 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
82 |
private static final Logger LOG = LoggerFactory.getLogger(SimpleFill3DSymbol.class); |
83 |
protected GeoPolygonList3D _geometry;
|
84 |
protected GeoMultiPolygon3D _mpolygon;
|
85 |
private Terrain _terrain;
|
86 |
|
87 |
protected float _height=100; |
88 |
|
89 |
public SimpleLine3DSymbol()
|
90 |
{ |
91 |
super();
|
92 |
try {
|
93 |
_geometry = new GeoPolygonList3D();
|
94 |
} catch (NodeException e) {
|
95 |
// TODO Auto-generated catch block
|
96 |
e.printStackTrace(); |
97 |
} |
98 |
} |
99 |
|
100 |
|
101 |
public void setLineColor(Color color) { |
102 |
// TODO Auto-generated method stub
|
103 |
|
104 |
} |
105 |
|
106 |
public ILineStyle getLineStyle() {
|
107 |
// TODO Auto-generated method stub
|
108 |
return null; |
109 |
} |
110 |
|
111 |
public void setLineStyle(ILineStyle lineStyle) { |
112 |
// TODO Auto-generated method stub
|
113 |
|
114 |
} |
115 |
|
116 |
public void setLineWidth(double width) { |
117 |
// TODO Auto-generated method stub
|
118 |
|
119 |
} |
120 |
|
121 |
public double getLineWidth() { |
122 |
// TODO Auto-generated method stub
|
123 |
return 0; |
124 |
} |
125 |
|
126 |
public int getAlpha() { |
127 |
// TODO Auto-generated method stub
|
128 |
return 0; |
129 |
} |
130 |
|
131 |
public void setAlpha(int outlineAlpha) { |
132 |
// TODO Auto-generated method stub
|
133 |
|
134 |
} |
135 |
|
136 |
public ISymbol getSymbolForSelection() {
|
137 |
// TODO Auto-generated method stub
|
138 |
return null; |
139 |
} |
140 |
|
141 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
142 |
Geometry geom, Feature f, Cancellable cancel) { |
143 |
Color c = getFillColor();
|
144 |
//geom.getClass().getName()
|
145 |
|
146 |
|
147 |
//WAITING for gvSIG ARCHITECTS to do something with polygons with holes in shp files
|
148 |
//in the meanwhile nothing is gonna happen with this kind of polygons
|
149 |
if (geom.getGeometryType().isTypeOf(Geometry.TYPES.SURFACE))
|
150 |
{ |
151 |
Surface s = (Surface)geom.cloneGeometry(); |
152 |
_geometry.addMultiPolygon(getGeoMultiPolygon(s)); |
153 |
} |
154 |
if (geom.getGeometryType().isTypeOf(Geometry.TYPES.CURVE))
|
155 |
{ |
156 |
Curve s = (Curve)geom.cloneGeometry(); |
157 |
_geometry.addMultiPolygon(getGeoMultiPolygon(s)); |
158 |
} |
159 |
} |
160 |
|
161 |
public GeoMultiPolygon3D getGeoMultiPolygon(Surface surface)
|
162 |
{ |
163 |
GeoMultiPolygon3D gmpoly = null;
|
164 |
GeoPolygon3D poly = null;
|
165 |
try {
|
166 |
gmpoly= new GeoMultiPolygon3D();
|
167 |
poly = new GeoPolygon3D();
|
168 |
} catch (NodeException e) {
|
169 |
// TODO Auto-generated catch block
|
170 |
e.printStackTrace(); |
171 |
} |
172 |
int numVerts = surface.getNumVertices();
|
173 |
if (surface.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D))
|
174 |
for(int i=0;i<numVerts;i++) |
175 |
poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),surface.getCoordinateAt(i, 2)); |
176 |
else
|
177 |
for(int i=0;i<numVerts;i++) |
178 |
poly.addPoint(surface.getCoordinateAt(i, 0),surface.getCoordinateAt(i, 1),1.0); |
179 |
gmpoly.addPolygon(poly); |
180 |
|
181 |
return gmpoly;
|
182 |
} |
183 |
|
184 |
public GeoMultiPolygon3D getGeoMultiPolygon(Curve curve)
|
185 |
{ |
186 |
GeoMultiPolygon3D gmpoly = null;
|
187 |
GeoPolygon3D poly = null;
|
188 |
try {
|
189 |
gmpoly= new GeoMultiPolygon3D();
|
190 |
poly = new GeoPolygon3D();
|
191 |
} catch (NodeException e) {
|
192 |
// TODO Auto-generated catch block
|
193 |
e.printStackTrace(); |
194 |
} |
195 |
int numVerts = curve.getNumVertices();
|
196 |
if (curve.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D))
|
197 |
for(int i=0;i<numVerts;i++) |
198 |
poly.addPoint(curve.getCoordinateAt(i, 0),curve.getCoordinateAt(i, 1),curve.getCoordinateAt(i, 2)); |
199 |
else
|
200 |
for(int i=0;i<numVerts;i++) |
201 |
poly.addPoint(curve.getCoordinateAt(i, 0),curve.getCoordinateAt(i, 1),_height); |
202 |
gmpoly.addPolygon(poly); |
203 |
|
204 |
return gmpoly;
|
205 |
} |
206 |
public GeoPolygonList3D getGeometry(){
|
207 |
return _geometry;
|
208 |
} |
209 |
|
210 |
|
211 |
public int getSymbolType() { |
212 |
// TODO Auto-generated method stub
|
213 |
return 0; |
214 |
} |
215 |
|
216 |
public void drawInsideRectangle(Graphics2D g, |
217 |
AffineTransform scaleInstance, Rectangle r, |
218 |
PrintAttributes properties) throws SymbolDrawingException {
|
219 |
// TODO Auto-generated method stub
|
220 |
|
221 |
} |
222 |
|
223 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
224 |
PrintAttributes properties) { |
225 |
// TODO Auto-generated method stub
|
226 |
|
227 |
} |
228 |
public static class RegisterSymbol implements Callable { |
229 |
|
230 |
public Object call() throws Exception { |
231 |
int[] shapeTypes; |
232 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
233 |
|
234 |
shapeTypes = |
235 |
new int[] {Geometry.TYPES.CURVE, Geometry.TYPES.ARC, |
236 |
Geometry.TYPES.ELLIPTICARC, Geometry.TYPES.MULTICURVE}; |
237 |
// manager.registerSymbol(ISimpleLine3DSymbol.SYMBOL_NAME,
|
238 |
// shapeTypes,
|
239 |
// SimpleLine3DSymbol.class,"project.document.view3d");
|
240 |
manager.registerSymbol(ISimpleLine3DSymbol.SYMBOL_NAME, |
241 |
shapeTypes, |
242 |
SimpleLine3DSymbol.class); |
243 |
return Boolean.TRUE; |
244 |
} |
245 |
|
246 |
} |
247 |
public void setFixedHeight(float height) { |
248 |
_height=height; |
249 |
|
250 |
} |
251 |
|
252 |
|
253 |
public void setCoordinateSystemType(int cst) { |
254 |
// TODO Auto-generated method stub
|
255 |
|
256 |
} |
257 |
|
258 |
|
259 |
public Node getRenderNode() {
|
260 |
// TODO Auto-generated method stub
|
261 |
return null; |
262 |
} |
263 |
|
264 |
|
265 |
public void resetGeometry() { |
266 |
try {
|
267 |
_geometry = new GeoPolygonList3D();
|
268 |
} catch (NodeException e) {
|
269 |
// TODO Auto-generated catch block
|
270 |
e.printStackTrace(); |
271 |
} |
272 |
|
273 |
} |
274 |
|
275 |
|
276 |
public boolean is3D() { |
277 |
// TODO Auto-generated method stub
|
278 |
return true; |
279 |
} |
280 |
|
281 |
|
282 |
public void setTerrain(Terrain terrain) { |
283 |
_terrain = terrain; |
284 |
|
285 |
} |
286 |
|
287 |
} |