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 @ 329
History | View | Annotate | Download (7.16 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 = 5; |
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 |
public void setGeometry(GeoPointArray3D geoPoint) |
72 |
{ |
73 |
_geometry= geoPoint; |
74 |
} |
75 |
|
76 |
public void previewSymbol(Graphics2D g, AffineTransform affineTransform, |
77 |
Geometry geom, Feature f, Cancellable cancel) { |
78 |
int x, y;
|
79 |
org.gvsig.fmap.geom.primitive.Point p = (org.gvsig.fmap.geom.primitive.Point)geom.cloneGeometry(); |
80 |
p.transform(affineTransform); |
81 |
|
82 |
int size = (int) getSize(); |
83 |
|
84 |
int halfSize = size/2; |
85 |
x = ((int) (p.getX() + getOffset().getX()) - halfSize);
|
86 |
y = ((int) (p.getY() + getOffset().getY()) - halfSize);
|
87 |
|
88 |
g.setColor(getColor()); |
89 |
g.setStroke(new BasicStroke(1)); |
90 |
// IMask mask = getMask();
|
91 |
// if (mask != null) {
|
92 |
// IFillSymbol maskShape = mask.getFillSymbol();
|
93 |
// // maskShape.draw(g, null, mask.getHaloShape(shp));
|
94 |
// }
|
95 |
g.fillOval(x, y, size, size); |
96 |
} |
97 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException { |
98 |
//SimpleMarkerSymbol smarker = new SimpleMarkerSymbol();
|
99 |
try {
|
100 |
if (properties==null) |
101 |
this.previewSymbol(g, scaleInstance, GeometryLocator.getGeometryManager().createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), null, null); |
102 |
else
|
103 |
{ |
104 |
double originalSize = getSize();
|
105 |
double size=originalSize;
|
106 |
int pq = properties.getPrintQuality();
|
107 |
if (pq == PrintAttributes.PRINT_QUALITY_NORMAL){
|
108 |
size *= (double) 300/72; |
109 |
}else if (pq == PrintAttributes.PRINT_QUALITY_HIGH){ |
110 |
size *= (double) 600/72; |
111 |
}else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT){ |
112 |
// d *= 72/72; // (which is the same than doing nothing)
|
113 |
} |
114 |
setSize(size); |
115 |
print(g, scaleInstance,GeometryLocator.getGeometryManager().createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), properties); |
116 |
setSize(originalSize); |
117 |
} |
118 |
|
119 |
} catch (CreateGeometryException e) {
|
120 |
// TODO Auto-generated catch block
|
121 |
e.printStackTrace(); |
122 |
} catch (LocatorException e) {
|
123 |
// TODO Auto-generated catch block
|
124 |
e.printStackTrace(); |
125 |
} |
126 |
|
127 |
} |
128 |
public void loadFromState(PersistentState state) |
129 |
throws PersistenceException {
|
130 |
// Set parent fill symbol properties
|
131 |
super.loadFromState(state);
|
132 |
// Set own properties sample
|
133 |
//thi.setStyle(state.getInt(FIELD_MARKERSTYLE));
|
134 |
} |
135 |
|
136 |
public void saveToState(PersistentState state) throws PersistenceException { |
137 |
// Save parent fill symbol properties
|
138 |
super.saveToState(state);
|
139 |
|
140 |
// Save own properties
|
141 |
// state.set(FIELD_MARKERSTYLE, getStyle());
|
142 |
} |
143 |
|
144 |
|
145 |
|
146 |
|
147 |
public static class RegisterPersistence implements Callable { |
148 |
|
149 |
public Object call() throws Exception { |
150 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
151 |
if( manager.getDefinition(SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) { |
152 |
DynStruct definition = manager.addDefinition( |
153 |
SimpleMarker3DSymbol.class, |
154 |
SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
155 |
SIMPLE_MARKER3D_SYMBOL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
156 |
null,
|
157 |
null
|
158 |
); |
159 |
// Extend the MarkerSymbol base definition
|
160 |
definition.extend(manager.getDefinition(MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME)); |
161 |
|
162 |
//Add the fields to save
|
163 |
// Marker style
|
164 |
//definition.addDynFieldInt(FIELD_MARKERSTYLE).setMandatory(true);
|
165 |
|
166 |
} |
167 |
return Boolean.TRUE; |
168 |
} |
169 |
|
170 |
} |
171 |
|
172 |
public static class RegisterSymbol implements Callable { |
173 |
|
174 |
public Object call() throws Exception { |
175 |
int[] shapeTypes; |
176 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
177 |
|
178 |
shapeTypes = |
179 |
new int[] { Geometry.TYPES.POINT, Geometry.TYPES.MULTIPOINT}; |
180 |
manager.registerSymbol(ISimpleMarker3DSymbol.SYMBOL_NAME, |
181 |
shapeTypes, |
182 |
SimpleMarker3DSymbol.class,"project.document.view3d");
|
183 |
|
184 |
return Boolean.TRUE; |
185 |
} |
186 |
|
187 |
} |
188 |
|
189 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
190 |
Geometry geom, Feature f, Cancellable cancel) { |
191 |
org.gvsig.fmap.geom.primitive.Point point = (org.gvsig.fmap.geom.primitive.Point)geom.cloneGeometry(); |
192 |
//TODO: Transform coordinates for spherical projection
|
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 |
public void setPointSize(float psize) { |
224 |
// TODO Auto-generated method stub
|
225 |
|
226 |
} |
227 |
|
228 |
} |