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 @ 323
History | View | Annotate | Download (7.01 KB)
1 |
package org.gvsig.gvsig3d.impl.symbology3d.marker.impl; |
---|---|
2 |
|
3 |
|
4 |
|
5 |
import java.awt.BasicStroke; |
6 |
import java.awt.Graphics2D; |
7 |
import java.awt.Rectangle; |
8 |
import java.awt.geom.AffineTransform; |
9 |
|
10 |
import org.gvsig.compat.print.PrintAttributes; |
11 |
import org.gvsig.fmap.dal.feature.Feature; |
12 |
import org.gvsig.fmap.geom.Geometry; |
13 |
import org.gvsig.fmap.geom.GeometryLocator; |
14 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
15 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
16 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
17 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
18 |
import org.gvsig.fmap.geom.primitive.Point; |
19 |
import org.gvsig.fmap.geom.primitive.Surface; |
20 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
21 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
22 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
23 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
24 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
25 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
26 |
import org.gvsig.osgvp.geometry.GeoPointArray3D; |
27 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol; |
28 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
29 |
import org.gvsig.tools.ToolsLocator; |
30 |
import org.gvsig.tools.dynobject.DynStruct; |
31 |
import org.gvsig.tools.locator.LocatorException; |
32 |
import org.gvsig.tools.persistence.PersistenceManager; |
33 |
import org.gvsig.tools.persistence.PersistentState; |
34 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
35 |
import org.gvsig.tools.task.Cancellable; |
36 |
import org.gvsig.tools.util.Callable; |
37 |
|
38 |
|
39 |
/**
|
40 |
*
|
41 |
* @author jtorres
|
42 |
*
|
43 |
*/
|
44 |
|
45 |
public class SimpleMarker3DSymbol extends AbstractMarkerSymbol implements ISimpleMarker3DSymbol{ |
46 |
|
47 |
public static final String SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME = "SimpleMarker3DSymbol"; |
48 |
|
49 |
public GeoPointArray3D _geometry;
|
50 |
|
51 |
protected float _height = 100; |
52 |
|
53 |
public SimpleMarker3DSymbol()
|
54 |
{ |
55 |
super();
|
56 |
try {
|
57 |
_geometry = new GeoPointArray3D();
|
58 |
} catch (NodeException e) {
|
59 |
// TODO Auto-generated catch block
|
60 |
e.printStackTrace(); |
61 |
} |
62 |
} |
63 |
public ISymbol getSymbolForSelection() {
|
64 |
//TODO
|
65 |
return null; |
66 |
} |
67 |
public GeoPointArray3D getGeometry(){
|
68 |
return _geometry;
|
69 |
} |
70 |
|
71 |
|
72 |
|
73 |
public void previewSymbol(Graphics2D g, AffineTransform affineTransform, |
74 |
Geometry geom, Feature f, Cancellable cancel) { |
75 |
int x, y;
|
76 |
org.gvsig.fmap.geom.primitive.Point p = (org.gvsig.fmap.geom.primitive.Point)geom.cloneGeometry(); |
77 |
p.transform(affineTransform); |
78 |
|
79 |
int size = (int) getSize(); |
80 |
|
81 |
int halfSize = size/2; |
82 |
x = ((int) (p.getX() + getOffset().getX()) - halfSize);
|
83 |
y = ((int) (p.getY() + getOffset().getY()) - halfSize);
|
84 |
|
85 |
g.setColor(getColor()); |
86 |
g.setStroke(new BasicStroke(1)); |
87 |
// IMask mask = getMask();
|
88 |
// if (mask != null) {
|
89 |
// IFillSymbol maskShape = mask.getFillSymbol();
|
90 |
// // maskShape.draw(g, null, mask.getHaloShape(shp));
|
91 |
// }
|
92 |
g.fillOval(x, y, size, size); |
93 |
} |
94 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException { |
95 |
//SimpleMarkerSymbol smarker = new SimpleMarkerSymbol();
|
96 |
try {
|
97 |
if (properties==null) |
98 |
this.previewSymbol(g, scaleInstance, GeometryLocator.getGeometryManager().createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), null, null); |
99 |
else
|
100 |
{ |
101 |
double originalSize = getSize();
|
102 |
double size=originalSize;
|
103 |
int pq = properties.getPrintQuality();
|
104 |
if (pq == PrintAttributes.PRINT_QUALITY_NORMAL){
|
105 |
size *= (double) 300/72; |
106 |
}else if (pq == PrintAttributes.PRINT_QUALITY_HIGH){ |
107 |
size *= (double) 600/72; |
108 |
}else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT){ |
109 |
// d *= 72/72; // (which is the same than doing nothing)
|
110 |
} |
111 |
setSize(size); |
112 |
print(g, scaleInstance,GeometryLocator.getGeometryManager().createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), properties); |
113 |
setSize(originalSize); |
114 |
} |
115 |
|
116 |
} catch (CreateGeometryException e) {
|
117 |
// TODO Auto-generated catch block
|
118 |
e.printStackTrace(); |
119 |
} catch (LocatorException e) {
|
120 |
// TODO Auto-generated catch block
|
121 |
e.printStackTrace(); |
122 |
} |
123 |
|
124 |
} |
125 |
public void loadFromState(PersistentState state) |
126 |
throws PersistenceException {
|
127 |
// Set parent fill symbol properties
|
128 |
super.loadFromState(state);
|
129 |
// Set own properties sample
|
130 |
//thi.setStyle(state.getInt(FIELD_MARKERSTYLE));
|
131 |
} |
132 |
|
133 |
public void saveToState(PersistentState state) throws PersistenceException { |
134 |
// Save parent fill symbol properties
|
135 |
super.saveToState(state);
|
136 |
|
137 |
// Save own properties
|
138 |
// state.set(FIELD_MARKERSTYLE, getStyle());
|
139 |
} |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
public static class RegisterPersistence implements Callable { |
145 |
|
146 |
public Object call() throws Exception { |
147 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
148 |
if( manager.getDefinition(SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) { |
149 |
DynStruct definition = manager.addDefinition( |
150 |
SimpleMarker3DSymbol.class, |
151 |
SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
152 |
SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
153 |
null,
|
154 |
null
|
155 |
); |
156 |
// Extend the MarkerSymbol base definition
|
157 |
definition.extend(manager.getDefinition(MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME)); |
158 |
|
159 |
//Add the fields to save
|
160 |
// Marker style
|
161 |
//definition.addDynFieldInt(FIELD_MARKERSTYLE).setMandatory(true);
|
162 |
|
163 |
} |
164 |
return Boolean.TRUE; |
165 |
} |
166 |
|
167 |
} |
168 |
|
169 |
public static class RegisterSymbol implements Callable { |
170 |
|
171 |
public Object call() throws Exception { |
172 |
int[] shapeTypes; |
173 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
174 |
|
175 |
shapeTypes = |
176 |
new int[] { Geometry.TYPES.POINT, Geometry.TYPES.MULTIPOINT}; |
177 |
manager.registerSymbol(ISimpleMarker3DSymbol.SYMBOL_NAME, |
178 |
shapeTypes, |
179 |
SimpleMarker3DSymbol.class,"project.document.view3d");
|
180 |
|
181 |
return Boolean.TRUE; |
182 |
} |
183 |
|
184 |
} |
185 |
|
186 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
187 |
Geometry geom, Feature f, Cancellable cancel) { |
188 |
|
189 |
org.gvsig.fmap.geom.primitive.Point point = (org.gvsig.fmap.geom.primitive.Point)geom.cloneGeometry(); |
190 |
|
191 |
//TODO: Transform coordinates for spherical projection
|
192 |
|
193 |
if (point.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3D))
|
194 |
_geometry.addPoint(point.getX(),point.getY(),point.getCoordinateAt(2));
|
195 |
else
|
196 |
_geometry.addPoint(point.getCoordinateAt(0),point.getCoordinateAt(1),_height); |
197 |
|
198 |
|
199 |
|
200 |
// int x, y;
|
201 |
// org.gvsig.fmap.geom.primitive.Point p = (org.gvsig.fmap.geom.primitive.Point)geom.cloneGeometry();
|
202 |
// p.transform(affineTransform);
|
203 |
//
|
204 |
// int size = (int) getSize();
|
205 |
//
|
206 |
// int halfSize = size/2;
|
207 |
// x = ((int) (p.getX() + getOffset().getX()) - halfSize);
|
208 |
// y = ((int) (p.getY() + getOffset().getY()) - halfSize);
|
209 |
//
|
210 |
// g.setColor(getColor());
|
211 |
// g.setStroke(new BasicStroke(1));
|
212 |
// // IMask mask = getMask();
|
213 |
// // if (mask != null) {
|
214 |
// // IFillSymbol maskShape = mask.getFillSymbol();
|
215 |
// // // maskShape.draw(g, null, mask.getHaloShape(shp));
|
216 |
// // }
|
217 |
// g.fillOval(x, y, size, size);
|
218 |
|
219 |
} |
220 |
public void setFixedHeight(float height) { |
221 |
_height = height; |
222 |
} |
223 |
|
224 |
} |