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 / marker / impl / SimpleMarker3DSymbol.java @ 370
History | View | Annotate | Download (10 KB)
1 |
package org.gvsig.gvsig3d.impl.symbology3d.marker.impl; |
---|---|
2 |
|
3 |
import java.awt.BasicStroke; |
4 |
import java.awt.Color; |
5 |
import java.awt.Graphics2D; |
6 |
import java.awt.Rectangle; |
7 |
import java.awt.geom.AffineTransform; |
8 |
|
9 |
import org.gvsig.compat.print.PrintAttributes; |
10 |
import org.gvsig.fmap.dal.feature.Feature; |
11 |
import org.gvsig.fmap.geom.Geometry; |
12 |
import org.gvsig.fmap.geom.GeometryLocator; |
13 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
14 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
15 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
16 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
17 |
import org.gvsig.fmap.geom.primitive.Point; |
18 |
import org.gvsig.fmap.geom.primitive.Surface; |
19 |
import org.gvsig.fmap.mapcontext.MapContext; |
20 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
21 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
22 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
23 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
24 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
25 |
import org.gvsig.gvsig3d.impl.layers.FLayers3DImpl; |
26 |
import org.gvsig.gvsig3d.impl.map3d.MapContext3DImpl; |
27 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
28 |
import org.gvsig.osgvp.core.osg.Node; |
29 |
import org.gvsig.osgvp.core.osg.Vec3; |
30 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
31 |
import org.gvsig.osgvp.geometry.GeoPointArray3D; |
32 |
import org.gvsig.osgvp.symbology.ISymbol3D; |
33 |
import org.gvsig.osgvp.symbology.marker.IMarker; |
34 |
import org.gvsig.osgvp.symbology.marker.SimpleMarker; |
35 |
import org.gvsig.osgvp.terrain.Terrain; |
36 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol; |
37 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol; |
38 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dynobject.DynStruct; |
41 |
import org.gvsig.tools.locator.LocatorException; |
42 |
import org.gvsig.tools.persistence.PersistenceManager; |
43 |
import org.gvsig.tools.persistence.PersistentState; |
44 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
45 |
import org.gvsig.tools.task.Cancellable; |
46 |
import org.gvsig.tools.util.Callable; |
47 |
import org.gvsig.tools.util.Caller; |
48 |
import org.gvsig.tools.util.impl.DefaultCaller; |
49 |
|
50 |
/**
|
51 |
*
|
52 |
* @author jtorres
|
53 |
*
|
54 |
*/
|
55 |
|
56 |
public class SimpleMarker3DSymbol extends AbstractMarkerSymbol implements |
57 |
ISimpleMarker3DSymbol { |
58 |
|
59 |
public static final String SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME = "SimpleMarker3DSymbol"; |
60 |
|
61 |
public GeoPointArray3D _geometry;
|
62 |
|
63 |
private Terrain _terrain;
|
64 |
|
65 |
protected float _height = 5; |
66 |
|
67 |
Vec3 _auxVect; |
68 |
|
69 |
ISymbol3D sm; |
70 |
|
71 |
protected int _coordinateSystemType; |
72 |
|
73 |
public SimpleMarker3DSymbol() {
|
74 |
super();
|
75 |
try {
|
76 |
sm = new SimpleMarker();
|
77 |
} catch (NodeException e1) {
|
78 |
// TODO Auto-generated catch block
|
79 |
e1.printStackTrace(); |
80 |
} |
81 |
(((IMarker) sm)).setPointSize((float) this.getSize()); |
82 |
sm.setColor(this.getColor());
|
83 |
try {
|
84 |
_geometry = new GeoPointArray3D();
|
85 |
_auxVect = new Vec3();
|
86 |
} catch (NodeException e) {
|
87 |
// TODO Auto-generated catch block
|
88 |
e.printStackTrace(); |
89 |
} |
90 |
|
91 |
} |
92 |
|
93 |
public void setColor(Color color) { |
94 |
super.setColor(color);
|
95 |
sm.setColor(this.getColor());
|
96 |
} |
97 |
|
98 |
public void setSize(double size) { |
99 |
super.setSize(size);
|
100 |
((IMarker) sm).setPointSize((float) this.getSize()); |
101 |
} |
102 |
|
103 |
public void resetGeometry() { |
104 |
_geometry.dispose(); |
105 |
try {
|
106 |
_geometry = new GeoPointArray3D();
|
107 |
} catch (NodeException e) {
|
108 |
// TODO Auto-generated catch block
|
109 |
e.printStackTrace(); |
110 |
} |
111 |
} |
112 |
|
113 |
public ISymbol getSymbolForSelection() {
|
114 |
// TODO
|
115 |
return null; |
116 |
} |
117 |
|
118 |
public GeoPointArray3D getGeometry() {
|
119 |
return _geometry;
|
120 |
} |
121 |
|
122 |
public void setGeometry(GeoPointArray3D geoPoint) { |
123 |
_geometry = geoPoint; |
124 |
} |
125 |
|
126 |
public void previewSymbol(Graphics2D g, AffineTransform affineTransform, |
127 |
Geometry geom, Feature f, Cancellable cancel) { |
128 |
int x, y;
|
129 |
org.gvsig.fmap.geom.primitive.Point p = (org.gvsig.fmap.geom.primitive.Point) geom |
130 |
.cloneGeometry(); |
131 |
p.transform(affineTransform); |
132 |
|
133 |
int size = (int) getSize(); |
134 |
|
135 |
int halfSize = size / 2; |
136 |
x = ((int) (p.getX() + getOffset().getX()) - halfSize);
|
137 |
y = ((int) (p.getY() + getOffset().getY()) - halfSize);
|
138 |
|
139 |
g.setColor(getColor()); |
140 |
g.setStroke(new BasicStroke(1)); |
141 |
// IMask mask = getMask();
|
142 |
// if (mask != null) {
|
143 |
// IFillSymbol maskShape = mask.getFillSymbol();
|
144 |
// // maskShape.draw(g, null, mask.getHaloShape(shp));
|
145 |
// }
|
146 |
g.fillOval(x, y, size, size); |
147 |
} |
148 |
|
149 |
public void drawInsideRectangle(Graphics2D g, |
150 |
AffineTransform scaleInstance, Rectangle r, |
151 |
PrintAttributes properties) throws SymbolDrawingException {
|
152 |
// SimpleMarkerSymbol smarker = new SimpleMarkerSymbol();
|
153 |
try {
|
154 |
if (properties == null) |
155 |
this.previewSymbol(
|
156 |
g, |
157 |
scaleInstance, |
158 |
GeometryLocator.getGeometryManager() |
159 |
.createPoint(r.getCenterX(), r.getCenterY(), |
160 |
SUBTYPES.GEOM2D), null, null); |
161 |
else {
|
162 |
double originalSize = getSize();
|
163 |
double size = originalSize;
|
164 |
int pq = properties.getPrintQuality();
|
165 |
if (pq == PrintAttributes.PRINT_QUALITY_NORMAL) {
|
166 |
size *= (double) 300 / 72; |
167 |
} else if (pq == PrintAttributes.PRINT_QUALITY_HIGH) { |
168 |
size *= (double) 600 / 72; |
169 |
} else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT) { |
170 |
// d *= 72/72; // (which is the same than doing nothing)
|
171 |
} |
172 |
setSize(size); |
173 |
print(g, |
174 |
scaleInstance, |
175 |
GeometryLocator.getGeometryManager() |
176 |
.createPoint(r.getCenterX(), r.getCenterY(), |
177 |
SUBTYPES.GEOM2D), properties); |
178 |
setSize(originalSize); |
179 |
} |
180 |
|
181 |
} catch (CreateGeometryException e) {
|
182 |
// TODO Auto-generated catch block
|
183 |
e.printStackTrace(); |
184 |
} catch (LocatorException e) {
|
185 |
// TODO Auto-generated catch block
|
186 |
e.printStackTrace(); |
187 |
} |
188 |
|
189 |
} |
190 |
|
191 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
192 |
Geometry geom, Feature f, Cancellable cancel) { |
193 |
org.gvsig.fmap.geom.primitive.Point point = (org.gvsig.fmap.geom.primitive.Point) geom |
194 |
.cloneGeometry(); |
195 |
// TODO: Transform coordinates for spherical projection
|
196 |
|
197 |
if (_coordinateSystemType == Terrain.CoordinateSystemType.PROJECTED) {
|
198 |
if (point.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D))
|
199 |
_geometry.addPoint(point.getX(), point.getY(), |
200 |
point.getCoordinateAt(2));
|
201 |
else
|
202 |
_geometry.addPoint(point.getCoordinateAt(0),
|
203 |
point.getCoordinateAt(1), _height);
|
204 |
} |
205 |
if (_coordinateSystemType == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
206 |
|
207 |
if (point.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D)) {
|
208 |
_auxVect.set(point.getX(), point.getY(), |
209 |
point.getCoordinateAt(2));
|
210 |
Vec3 converted = _terrain.convertLatLongHeightToXYZ(_auxVect); |
211 |
_geometry.addPoint(converted.x(), converted.y(), converted.z()); |
212 |
} else {
|
213 |
_auxVect.set(point.getX(), point.getY(), _height); |
214 |
Vec3 converted = _terrain.convertLatLongHeightToXYZ(_auxVect); |
215 |
_geometry.addPoint(converted.x(), converted.y(), converted.z()); |
216 |
} |
217 |
} |
218 |
|
219 |
// int x, y;
|
220 |
// org.gvsig.fmap.geom.primitive.Point p =
|
221 |
// (org.gvsig.fmap.geom.primitive.Point)geom.cloneGeometry();
|
222 |
// p.transform(affineTransform);
|
223 |
//
|
224 |
// int size = (int) getSize();
|
225 |
//
|
226 |
// int halfSize = size/2;
|
227 |
// x = ((int) (p.getX() + getOffset().getX()) - halfSize);
|
228 |
// y = ((int) (p.getY() + getOffset().getY()) - halfSize);
|
229 |
//
|
230 |
// g.setColor(getColor());
|
231 |
// g.setStroke(new BasicStroke(1));
|
232 |
// // IMask mask = getMask();
|
233 |
// // if (mask != null) {
|
234 |
// // IFillSymbol maskShape = mask.getFillSymbol();
|
235 |
// // // maskShape.draw(g, null, mask.getHaloShape(shp));
|
236 |
// // }
|
237 |
// g.fillOval(x, y, size, size);
|
238 |
|
239 |
} |
240 |
|
241 |
public void setFixedHeight(float height) { |
242 |
_height = height; |
243 |
} |
244 |
|
245 |
public void setPointSize(float psize) { |
246 |
super.setSize(psize);
|
247 |
((SimpleMarker) (sm)).setPointSize(psize); |
248 |
} |
249 |
|
250 |
public void setCoordinateSystemType(int cst) { |
251 |
_coordinateSystemType = cst; |
252 |
} |
253 |
|
254 |
public boolean is3D() { |
255 |
return true; |
256 |
} |
257 |
|
258 |
public Node getRenderNode() {
|
259 |
System.out.println("geometry talla" + _geometry.getSize()); |
260 |
return sm.buildSceneGraph(_geometry);
|
261 |
} |
262 |
|
263 |
public void loadFromState(PersistentState state) |
264 |
throws PersistenceException {
|
265 |
// Set parent fill symbol properties
|
266 |
super.loadFromState(state);
|
267 |
|
268 |
// // Set own properties
|
269 |
// setStyle(state.getInt(FIELD_MARKERSTYLE));
|
270 |
// setOutlined(state.getBoolean(FIELD_OUTLINED));
|
271 |
// if (isOutlined()) {
|
272 |
// setOutlineColor((Color) state.get(FIELD_OUTLINECOLOR));
|
273 |
// setOutlineSize(state.getDouble(FIELD_OUTLINESIZE));
|
274 |
// }
|
275 |
} |
276 |
|
277 |
public void saveToState(PersistentState state) throws PersistenceException { |
278 |
// Save parent fill symbol properties
|
279 |
super.saveToState(state);
|
280 |
|
281 |
// Save own properties
|
282 |
// state.set(FIELD_MARKERSTYLE, getStyle());
|
283 |
// state.set(FIELD_OUTLINED, isOutlined());
|
284 |
// if (isOutlined()) {
|
285 |
// state.set(FIELD_OUTLINECOLOR, getOutlineColor());
|
286 |
// state.set(FIELD_OUTLINESIZE, getOutlineSize());
|
287 |
// }
|
288 |
} |
289 |
|
290 |
public static class RegisterPersistence implements Callable { |
291 |
|
292 |
public Object call() throws Exception { |
293 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
294 |
if (manager.getDefinition("Symbol") == null) { |
295 |
Caller caller = new DefaultCaller();
|
296 |
caller.add(new AbstractSymbol.RegisterPersistence());
|
297 |
caller.call(); |
298 |
} |
299 |
|
300 |
if (manager.getDefinition("MarkerSymbol") == null) { |
301 |
Caller caller = new DefaultCaller();
|
302 |
caller.add(new AbstractMarkerSymbol.RegisterPersistence());
|
303 |
caller.call(); |
304 |
} |
305 |
|
306 |
|
307 |
DynStruct definition = manager.addDefinition( |
308 |
SimpleMarker3DSymbol.class, "SimpleMarker3DSymbol",
|
309 |
"SimpleMarker3DSymbol Persistence definition", null, null); |
310 |
|
311 |
|
312 |
|
313 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, |
314 |
"MarkerSymbol");
|
315 |
|
316 |
return Boolean.TRUE; |
317 |
} |
318 |
} |
319 |
|
320 |
public static class RegisterSymbol implements Callable { |
321 |
|
322 |
public Object call() throws Exception { |
323 |
int[] shapeTypes; |
324 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
325 |
|
326 |
shapeTypes = new int[] { Geometry.TYPES.POINT, |
327 |
Geometry.TYPES.MULTIPOINT }; |
328 |
manager.registerSymbol(ISimpleMarker3DSymbol.SYMBOL_NAME, |
329 |
shapeTypes, SimpleMarker3DSymbol.class, |
330 |
"project.document.view3d");
|
331 |
|
332 |
return Boolean.TRUE; |
333 |
} |
334 |
|
335 |
} |
336 |
|
337 |
public void setTerrain(Terrain terrain) { |
338 |
_terrain = terrain; |
339 |
|
340 |
} |
341 |
|
342 |
} |