svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / lib3DMap / src / com / iver / ai2 / gvsig3d / cacheservices / VectorCacheService.java @ 15490
History | View | Annotate | Download (22.5 KB)
1 |
package com.iver.ai2.gvsig3d.cacheservices; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.geom.PathIterator; |
6 |
import java.awt.geom.Rectangle2D; |
7 |
import java.awt.image.BufferedImage; |
8 |
import java.util.ArrayList; |
9 |
import java.util.HashMap; |
10 |
import java.util.List; |
11 |
import java.util.Map; |
12 |
|
13 |
import org.cresques.cts.ICoordTrans; |
14 |
import org.cresques.cts.IProjection; |
15 |
import org.cresques.px.Extent; |
16 |
import org.gvsig.cacheservice.CacheService; |
17 |
|
18 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
19 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
20 |
import com.iver.ai2.gvsig3d.gui.FeatureFactory; |
21 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
22 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
23 |
import com.iver.cit.gvsig.fmap.ViewPort; |
24 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
25 |
import com.iver.cit.gvsig.fmap.core.FShape; |
26 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
27 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
28 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
29 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
30 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
31 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
32 |
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
33 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
34 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
35 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
36 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
37 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
38 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
39 |
import com.iver.cit.gvsig.fmap.operations.strategies.DefaultStrategy; |
40 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
41 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
42 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
43 |
import com.iver.utiles.swing.threads.Cancellable; |
44 |
|
45 |
import es.upv.ai2.libjosg.Group; |
46 |
import es.upv.ai2.libjosg.Node; |
47 |
import es.upv.ai2.libjosg.Vec3; |
48 |
import es.upv.ai2.libjosg.Vec4; |
49 |
import es.upv.ai2.libjosg.features.PixelPoint; |
50 |
import es.upv.ai2.libjosg.planets.Planet; |
51 |
import es.upv.ai2.libjosg.planets.PlanetViewer; |
52 |
import es.upv.ai2.libjosg.planets.Planet.PlanetType; |
53 |
import es.upv.ai2.libjosg.viewer.IViewerContainer; |
54 |
|
55 |
public class VectorCacheService extends CacheService {// implements |
56 |
// ExtendsFeatureVisitor{
|
57 |
|
58 |
private IViewerContainer _canvas3D;
|
59 |
|
60 |
private PlanetViewer _planetViewer;
|
61 |
|
62 |
private Planet _planet;
|
63 |
|
64 |
private Extent _extent;
|
65 |
|
66 |
private Rectangle2D _lyrExtentRect; |
67 |
|
68 |
private FLayer _layer;
|
69 |
|
70 |
private IProjection _viewProj;
|
71 |
|
72 |
// vector caching for libJOSG
|
73 |
private Group _layerNode; |
74 |
|
75 |
private Node _currentNode;
|
76 |
|
77 |
private int _currentGeomType; |
78 |
|
79 |
private List m_labels; |
80 |
|
81 |
private float heigth = 5000; |
82 |
|
83 |
private boolean inPixels = true; |
84 |
|
85 |
private int fontSize = 14; |
86 |
|
87 |
private int n = 0; |
88 |
|
89 |
// Create a hash table
|
90 |
Map pointsMap;
|
91 |
|
92 |
private int option; |
93 |
|
94 |
private boolean primera = true; |
95 |
|
96 |
// private ISymbol _currentSymbol;
|
97 |
|
98 |
public VectorCacheService(IViewerContainer canvas3D, Planet planet,
|
99 |
String name, FLayer layer, IProjection viewProj) {
|
100 |
super(planet.getPlanetName(), name);
|
101 |
|
102 |
getNames(); |
103 |
|
104 |
_canvas3D = canvas3D; |
105 |
_planetViewer = (PlanetViewer) canvas3D.getOSGViewer(); |
106 |
_planet = planet; |
107 |
_layer = layer; |
108 |
_viewProj = viewProj; |
109 |
_layerNode = new Group(); |
110 |
_planetViewer.addSpecialNode(_layerNode); |
111 |
|
112 |
int cacheType = CacheService.GLOBAL;
|
113 |
if (planet.getType() == PlanetType.GEOCENTRIC)
|
114 |
cacheType += SPHERIC; |
115 |
else
|
116 |
cacheType += PLANE; |
117 |
setCacheType(cacheType); |
118 |
|
119 |
try {
|
120 |
_lyrExtentRect = _layer.getFullExtent(); |
121 |
} catch (ExpansionFileReadException e) {
|
122 |
// TODO Auto-generated catch block
|
123 |
e.printStackTrace(); |
124 |
} catch (ReadDriverException e) {
|
125 |
// TODO Auto-generated catch block
|
126 |
e.printStackTrace(); |
127 |
} |
128 |
|
129 |
_extent = new Extent(_lyrExtentRect);
|
130 |
|
131 |
// EJEMPLO DE COMO SE COGE LEL ITERATOR DE LA CAPA VECTORIAL
|
132 |
FLyrVect flyrVect = (FLyrVect) _layer; |
133 |
|
134 |
|
135 |
} |
136 |
|
137 |
// uses a strategy to get all features from layer and their symbols
|
138 |
// and add them to the planet
|
139 |
|
140 |
public void AddFeaturesToPlanet() { |
141 |
|
142 |
// for testing, use DefaultStrategy. Later on we can implement
|
143 |
// the optimized strategies
|
144 |
|
145 |
Strategy strat = new DefaultStrategy(_layer);
|
146 |
try {
|
147 |
pointsMap = new HashMap(); |
148 |
|
149 |
// YA NO SE USAN STRATEGYS POR LO TANTO NO EXISTE EL
|
150 |
// PROCESSWITHSYMBOLS
|
151 |
// strat.processWithSymbols(this, null /* no extent for now */,
|
152 |
// null);
|
153 |
newDraw(); |
154 |
_layerNode.addChild(FeatureFactory.insertPointS((HashMap) pointsMap));
|
155 |
getNames(); |
156 |
_canvas3D.repaint(); |
157 |
} catch (Exception e) { |
158 |
e.printStackTrace(); |
159 |
} |
160 |
} |
161 |
|
162 |
public void RefreshFeaturesToPlanet() { |
163 |
// for testing, use DefaultStrategy. Later on we can implement
|
164 |
// the optimized strategies
|
165 |
this.DeleteFeaturesToPlanet();
|
166 |
pointsMap = new HashMap(); |
167 |
_layerNode = new Group(); |
168 |
_planetViewer.addSpecialNode(_layerNode); |
169 |
_currentGeomType = -1;
|
170 |
|
171 |
// SALVA_FEATURES
|
172 |
Strategy strat = new DefaultStrategy(_layer);
|
173 |
try {
|
174 |
// YA NO SE USAN STRATEGYS POR LO TANTO NO EXISTE EL
|
175 |
// PROCESSWITHSYMBOLS
|
176 |
// strat.processWithSymbols(this, null /* no extent for now */,
|
177 |
// null);
|
178 |
newDraw(); |
179 |
_layerNode.addChild(FeatureFactory.insertPointS((HashMap) pointsMap));
|
180 |
getNames(); |
181 |
} catch (Exception e) { |
182 |
e.printStackTrace(); |
183 |
} |
184 |
} |
185 |
|
186 |
public void DeleteFeaturesToPlanet() { |
187 |
_planetViewer.removeSpecialNode(_layerNode); |
188 |
} |
189 |
|
190 |
public void refreshFeaturesToPlanet(boolean visible) { |
191 |
// _canvas3D.removeSpecialNode(_layerNode);
|
192 |
_layerNode.setEnabledNode(visible); |
193 |
} |
194 |
|
195 |
// FeatureVisitor methods
|
196 |
|
197 |
public String getProcessDescription() { |
198 |
// TODO Auto-generated method stub
|
199 |
return null; |
200 |
} |
201 |
|
202 |
public boolean start(FLayer layer) { |
203 |
_currentNode = null;
|
204 |
_currentGeomType = -1; // not set |
205 |
// _currentSymbol = null;
|
206 |
|
207 |
return true; // if everything is okay |
208 |
} |
209 |
|
210 |
// public void stop(FLayer layer) {
|
211 |
// // process of adding features is finished
|
212 |
// }
|
213 |
//
|
214 |
// public void visit(IGeometry g, int index) throws VisitException {
|
215 |
// // TODO Auto-generated method stub
|
216 |
//
|
217 |
// }
|
218 |
|
219 |
// SALVA_FEATURES
|
220 |
public void visitWithSymbol(IGeometry g, int index, ISymbol symbol) { |
221 |
|
222 |
ISymbol fsym = null;
|
223 |
Color color = null; |
224 |
int geomType;
|
225 |
// Point parameters
|
226 |
int pointSize = 15; |
227 |
// Line parameters
|
228 |
ILineStyle lineStyle; |
229 |
float lineWidth = 2; |
230 |
// Polygon parameters
|
231 |
|
232 |
if (g == null || symbol == null) |
233 |
return;
|
234 |
|
235 |
// Getting geometri
|
236 |
geomType = g.getGeometryType(); |
237 |
// Setting up geometri
|
238 |
startGeometry(geomType, symbol); |
239 |
|
240 |
// Casting to symbol type
|
241 |
|
242 |
// Point type
|
243 |
if (symbol instanceof IMarkerSymbol) { |
244 |
fsym = (IMarkerSymbol) symbol; |
245 |
color = ((IMarkerSymbol) fsym).getColor(); |
246 |
pointSize = (int) ((IMarkerSymbol) fsym).getSize();
|
247 |
// pointSize = 10;
|
248 |
|
249 |
} |
250 |
// Line Type
|
251 |
if (symbol instanceof ILineSymbol) { |
252 |
fsym = (ILineSymbol) symbol; |
253 |
color = ((ILineSymbol) fsym).getColor(); |
254 |
color = new Color(1.0f,0.0f,0.0f); |
255 |
lineStyle = ((ILineSymbol) fsym).getLineStyle(); |
256 |
lineWidth = lineStyle.getLineWidth(); |
257 |
SimpleLineSymbol a; |
258 |
} |
259 |
// Polygon type
|
260 |
if (symbol instanceof IFillSymbol) { |
261 |
fsym = (IFillSymbol) symbol; |
262 |
color = ((IFillSymbol) fsym).getFillColor(); |
263 |
|
264 |
} |
265 |
|
266 |
// TRANSFORMANDO A GEOMETRIA CON VALOR Z
|
267 |
FGeometry g3D = null;
|
268 |
if (g instanceof FGeometry) { |
269 |
g3D = (FGeometry) g; |
270 |
} |
271 |
|
272 |
// Setup point hash map
|
273 |
List pointListAux = null; |
274 |
if ((geomType & FShape.POINT) == FShape.POINT) {
|
275 |
if (pointsMap.containsKey(new Integer(pointSize))) { |
276 |
// System.out.println("ya contiene esa key");
|
277 |
pointListAux = (List) pointsMap.get(new Double(pointSize)); |
278 |
} else {
|
279 |
pointListAux = new ArrayList(); |
280 |
pointsMap.put(new Integer(pointSize), pointListAux); |
281 |
} |
282 |
|
283 |
} |
284 |
|
285 |
// if ((BasicStroke) fsym.getStroke() != null)
|
286 |
// lineSize = ((BasicStroke) fsym.getStroke()).getLineWidth();
|
287 |
// float comp[] = new float[4];
|
288 |
// Color color = ((SimpleFillSymbol) fsym).getOutline().getColor();
|
289 |
// comp = color.getColorComponents(comp);
|
290 |
// color.getColorComponents(comp);
|
291 |
|
292 |
// Getting font size
|
293 |
// Font font = fsym.getFont();
|
294 |
// if (font != null) {
|
295 |
// inPixels = fsym.isFontSizeInPixels();
|
296 |
// if (inPixels)
|
297 |
// fontSize = (int) (((fsym.getFontSize() / FConstant.FONT_HEIGHT_SCALE_FACTOR)) * 2.5);
|
298 |
// else
|
299 |
// fontSize = (int) (fsym.getFontSize() / FConstant.FONT_HEIGHT_SCALE_FACTOR);
|
300 |
// }
|
301 |
|
302 |
// float alpha = ((float) fsym.getColor().getAlpha()) / 255.0f;
|
303 |
|
304 |
float alpha = 1.0f; |
305 |
Vec4 rgba = new Vec4(color.getRed(),color.getGreen(),color.getBlue(), alpha);
|
306 |
// Vec4 rgba = new Vec4(1.0, 0.0, 0.0, alpha);
|
307 |
|
308 |
// System.out.println("Transparencia :" + fsym.getColor().getAlpha());
|
309 |
|
310 |
// Setting up heigth of feature
|
311 |
// heigth = 5000;
|
312 |
|
313 |
// Getting the Iterator
|
314 |
PathIterator theIteratorL = g.getPathIterator(null); |
315 |
|
316 |
double[] dataLine = new double[6]; |
317 |
List posi = new ArrayList(); |
318 |
int contH = 0; |
319 |
// System.out.println("ENTRO");
|
320 |
while (!theIteratorL.isDone()) {
|
321 |
// System.out.println("ITERO");
|
322 |
int type = theIteratorL.currentSegment(dataLine);
|
323 |
|
324 |
Vec3 posGeo = null;
|
325 |
Vec3 pos = null;
|
326 |
double h = 0; |
327 |
if (Layer3DProps.getLayer3DProps(_layer).isZEnable()) {
|
328 |
if ((_currentGeomType & FShape.Z) == FShape.Z) {
|
329 |
if (g3D != null) { |
330 |
// h = (g3D.getZs()[contH])
|
331 |
// * _planet.getVerticalExaggeration();
|
332 |
h = (g3D.getZs()[contH]) |
333 |
* Layer3DProps.getLayer3DProps(_layer) |
334 |
.getVerticalEx(); |
335 |
} |
336 |
} |
337 |
} else {
|
338 |
|
339 |
Layer3DProps props3D = Layer3DProps.getLayer3DProps(_layer); |
340 |
heigth = props3D.getHeigth(); |
341 |
h = heigth; |
342 |
} |
343 |
|
344 |
if (this._planet.getType() == PlanetType.GEOCENTRIC) { |
345 |
// Transform to geodesical coordinates
|
346 |
// posGeo = new Vec3(dataLine[1], dataLine[0], heigth);
|
347 |
// posReal = new Vec3(dataLine[0], dataLine[1], dataLine[2]);
|
348 |
// posGeo = _planet.convertLatLongHeightToXYZ(new Vec3(40.0,
|
349 |
// 0.0, h));
|
350 |
// posReal.setZ(posGeo.z());
|
351 |
// pos = posReal;
|
352 |
// pos.setX(posGeo.x());
|
353 |
// pos.setY(posGeo.y());
|
354 |
|
355 |
posGeo = new Vec3(dataLine[1], dataLine[0], h); |
356 |
pos = _planet.convertLatLongHeightToXYZ(posGeo); |
357 |
} else {
|
358 |
pos = new Vec3(dataLine[0], dataLine[1], h); |
359 |
} |
360 |
// System.out.println("\nPosition posicion geodesicas: " +
|
361 |
// posReal.x() + " " + posReal.y()
|
362 |
// + " " + posReal.z());
|
363 |
// System.out.println("Position cartesianas : " + pos.x() + " " +
|
364 |
// pos.y()
|
365 |
// + " " + pos.z());
|
366 |
|
367 |
// Adding points
|
368 |
switch (type) {
|
369 |
case PathIterator.SEG_MOVETO: |
370 |
// System.out.println("SEG_MOVETO");
|
371 |
Node node = _currentNode; |
372 |
|
373 |
if ((geomType & FShape.POINT) == FShape.POINT) {
|
374 |
// pointListAux.add(new Punto3D(pos, rgba, pointSize));
|
375 |
FeatureFactory.addNodeToPoint(node, pos, rgba, pointSize); |
376 |
} else if ((geomType & FShape.LINE) == FShape.LINE) { |
377 |
node = FeatureFactory.insertLine(posi, rgba, lineWidth); |
378 |
} |
379 |
if ((geomType & FShape.POLYGON) == FShape.POLYGON) {
|
380 |
node = FeatureFactory.insertPolygon(posi, rgba); |
381 |
} |
382 |
|
383 |
if ((geomType & FShape.POINT) != FShape.POINT) {
|
384 |
|
385 |
if (node != null) { |
386 |
_layerNode.addChild(node); |
387 |
posi.clear(); |
388 |
posi = new ArrayList(); |
389 |
} |
390 |
posi.add(pos); |
391 |
} |
392 |
break;
|
393 |
|
394 |
case PathIterator.SEG_LINETO: |
395 |
// System.out.println("SEG_LINETO");
|
396 |
posi.add(pos); |
397 |
break;
|
398 |
|
399 |
case PathIterator.SEG_QUADTO: |
400 |
// System.out.println("SEG_QUADTO");
|
401 |
break;
|
402 |
|
403 |
case PathIterator.SEG_CUBICTO: |
404 |
// System.out.println("SEG_CUBICTO");
|
405 |
break;
|
406 |
|
407 |
case PathIterator.SEG_CLOSE: |
408 |
// System.out.println("SEG_CLOSE");
|
409 |
break;
|
410 |
} |
411 |
contH++; |
412 |
theIteratorL.next(); |
413 |
} |
414 |
// System.out.println("Numero de puntos: " + contH);
|
415 |
|
416 |
// Adding last symbol
|
417 |
Node node = _currentNode; |
418 |
if (posi.size() > 0) { |
419 |
if ((geomType & FShape.POINT) == FShape.POINT) {
|
420 |
node = FeatureFactory.insertPoints(posi, rgba, pointSize); |
421 |
// pointListAux.add(new Punto3D(pos,rgba,size));
|
422 |
// System.out.println("entro");
|
423 |
} else if ((geomType & FShape.LINE) == FShape.LINE) { |
424 |
node = FeatureFactory.insertLine(posi, rgba, lineWidth); |
425 |
} |
426 |
if ((geomType & FShape.POLYGON) == FShape.POLYGON) {
|
427 |
node = FeatureFactory.insertPolygon(posi, rgba); |
428 |
} |
429 |
if (geomType != FShape.POINT)
|
430 |
if (node != null) { |
431 |
_layerNode.addChild(node); |
432 |
posi.clear(); |
433 |
} |
434 |
} |
435 |
|
436 |
// TODO: ADD GEOMETRY WITH SYMBOL to Planet
|
437 |
} |
438 |
|
439 |
private void startGeometry(int geomType, ISymbol symb) { |
440 |
|
441 |
// TODO: create new node if some properties change in symbol (like point
|
442 |
// size)
|
443 |
|
444 |
// if ((geomType != _currentGeomType) || ((geomType & FShape.POINT) ==
|
445 |
// FShape.POINT)) {
|
446 |
if (geomType != _currentGeomType) {
|
447 |
_currentGeomType = geomType; |
448 |
|
449 |
if ((geomType & FShape.Z) == FShape.Z)
|
450 |
geomType = geomType - FShape.Z; |
451 |
|
452 |
if (((geomType & FShape.POINT) == FShape.POINT)) {
|
453 |
Group g = new Group(); |
454 |
PixelPoint point = (PixelPoint) FeatureFactory.insertPointS(new Vec3(0.0, |
455 |
0.0, 0.0), new Vec4(1.0f, 1.0f, 1.0f, 1.0f), 100); |
456 |
_currentNode = point; |
457 |
_layerNode.addChild(g); |
458 |
g.addChild(point); |
459 |
} else if (((geomType & FShape.LINE) == FShape.LINE)) { |
460 |
; |
461 |
} else if (((geomType & FShape.POLYGON) == FShape.POLYGON)) { |
462 |
; |
463 |
} |
464 |
// switch (geomType) {
|
465 |
//
|
466 |
// case FShape.POINT:
|
467 |
// // Point point = (Point) VectorTest.insertPointS(new Vec3(0.0,
|
468 |
// // 0.0, 0.0), new Vec4(1.0f, 1.0f, 1.0f, 1.0f), 100);
|
469 |
// Group g = new Group();
|
470 |
// _currentNode = g;
|
471 |
// _layerNode.addChild(g);
|
472 |
// break;
|
473 |
// case FShape.LINE:
|
474 |
// // No set up
|
475 |
// break;
|
476 |
// case FShape.POLYGON:
|
477 |
// // No set up
|
478 |
// break;
|
479 |
//
|
480 |
// }
|
481 |
|
482 |
} |
483 |
} |
484 |
|
485 |
private void getNames() { |
486 |
|
487 |
if (_layer instanceof FLyrVect) { |
488 |
FLyrVect flyrVect = (FLyrVect) _layer; |
489 |
// REVISAR COMO SE GENERAN LOS LABELS CON LOS ITERADORES
|
490 |
|
491 |
// createLabels(flyrVect);
|
492 |
// // if (m_labels != null)
|
493 |
// if (((VectorialLegend) flyrVect.getLegend()).getLabelField() !=
|
494 |
// null)
|
495 |
// if (m_labels.size() > 0)
|
496 |
// _layerNode.addChild(VectorTest.insertLabels(
|
497 |
// this.m_labels, fontSize, this.heigth,
|
498 |
// inPixels, this._planet.getType()));
|
499 |
//
|
500 |
// } catch (DriverException e) {
|
501 |
// // TODO Auto-generated catch block
|
502 |
// e.printStackTrace();
|
503 |
// }
|
504 |
} |
505 |
|
506 |
} |
507 |
|
508 |
public void createLabels(FLyrVect lyrVect) throws DriverException { |
509 |
|
510 |
// SelectableDataSource ds = null;
|
511 |
// ds = lyrVect.getRecordset();
|
512 |
|
513 |
// try {
|
514 |
// ReadableVectorial adapter = lyrVect.getSource();
|
515 |
// adapter.start();
|
516 |
// ds.start();
|
517 |
// int sc;
|
518 |
//
|
519 |
// VectorialLegend l = (VectorialLegend) lyrVect.getLegend();
|
520 |
//
|
521 |
// if (((VectorialLegend) lyrVect.getLegend()).getLabelField() != null)
|
522 |
// {
|
523 |
// int fieldId = ds.getFieldIndexByName(((VectorialLegend) lyrVect
|
524 |
// .getLegend()).getLabelField());
|
525 |
// int idFieldHeightText = -1;
|
526 |
// int idFieldRotationText = -1;
|
527 |
//
|
528 |
// FSymbol defaultSym = (FSymbol) l.getDefaultSymbol();
|
529 |
//
|
530 |
// if (l.getLabelHeightField() != null) {
|
531 |
// idFieldHeightText = ds.getFieldIndexByName(l
|
532 |
// .getLabelHeightField());
|
533 |
// defaultSym.setFontSizeInPixels(false);
|
534 |
// }
|
535 |
//
|
536 |
// if (l.getLabelRotationField() != null) {
|
537 |
// idFieldRotationText = ds.getFieldIndexByName(l
|
538 |
// .getLabelRotationField());
|
539 |
// }
|
540 |
//
|
541 |
// sc = (int) ds.getRowCount();
|
542 |
// m_labels = new ArrayList(sc);
|
543 |
//
|
544 |
// DriverAttributes attr = adapter.getDriverAttributes();
|
545 |
// boolean bMustClone = false;
|
546 |
// if (attr != null) {
|
547 |
// if (attr.isLoadedInMemory()) {
|
548 |
// bMustClone = attr.isLoadedInMemory();
|
549 |
// }
|
550 |
// }
|
551 |
// ICoordTrans ct = lyrVect.getCoordTrans();
|
552 |
//
|
553 |
// for (int i = 0; i < sc; i++) {
|
554 |
// IGeometry geom = adapter.getShape(i);
|
555 |
//
|
556 |
// if (geom == null) {
|
557 |
// m_labels.add(null);
|
558 |
// continue;
|
559 |
// }
|
560 |
// if (ct != null) {
|
561 |
// if (bMustClone)
|
562 |
// geom = geom.cloneGeometry();
|
563 |
// geom.reProject(ct);
|
564 |
// }
|
565 |
//
|
566 |
// // TODO: El m�todo contenedor (createLabelLayer) debe
|
567 |
// // recoger
|
568 |
// // los par�metros de posicionamiento y de allowDuplicates
|
569 |
// // if (i >= 328)
|
570 |
// // System.out.println("i= " + i + " " + val.toString());
|
571 |
// Value val = ds.getFieldValue(i, fieldId);
|
572 |
//
|
573 |
// if ((val instanceof NullValue) || (val == null)) {
|
574 |
// continue;
|
575 |
// }
|
576 |
//
|
577 |
// FLabel[] lbls = geom.createLabels(0, true);
|
578 |
// for (int j = 0; j < lbls.length; j++) {
|
579 |
// if (lbls[j] != null) {
|
580 |
// lbls[j].setString(val.toString());
|
581 |
//
|
582 |
// if (idFieldHeightText != -1) {
|
583 |
// NumericValue height = (NumericValue) ds
|
584 |
// .getFieldValue(i, idFieldHeightText);
|
585 |
// lbls[j].setHeight(height.floatValue());
|
586 |
// } else {
|
587 |
// // El tama�o del texto va siempre en el
|
588 |
// // simbolo
|
589 |
// // por
|
590 |
// // defecto
|
591 |
// // cuando no hay un campo de altura de texto
|
592 |
// // TODO: Todo esto cambiar� con el nuevo
|
593 |
// // sistema
|
594 |
// // de
|
595 |
// // leyendas...
|
596 |
// if (l.getDefaultSymbol() != null) {
|
597 |
// lbls[j].setHeight(defaultSym.getFontSize());
|
598 |
// // lbls[j].setColor(defaultSym.getFontColor()
|
599 |
// // .getRGB());
|
600 |
//
|
601 |
// }
|
602 |
// }
|
603 |
//
|
604 |
// if (idFieldRotationText != -1) {
|
605 |
// DoubleValue rotation = (DoubleValue) ds
|
606 |
// .getFieldValue(i, idFieldRotationText);
|
607 |
// lbls[j].setRotation(rotation.getValue());
|
608 |
// }
|
609 |
// m_labels.add(lbls[j]);
|
610 |
//
|
611 |
// }
|
612 |
//
|
613 |
// }
|
614 |
//
|
615 |
// /*
|
616 |
// * if (lbls[0] == null) m_labels.add(null); else
|
617 |
// * m_labels.add(lbls[0].getOrig());
|
618 |
// */
|
619 |
// }
|
620 |
//
|
621 |
// }
|
622 |
// ds.stop();
|
623 |
// adapter.stop();
|
624 |
//
|
625 |
// } catch (DriverIOException e) {
|
626 |
// e.printStackTrace();
|
627 |
// throw new DriverException(e);
|
628 |
// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
629 |
// e.printStackTrace();
|
630 |
// throw new DriverException(e);
|
631 |
// }
|
632 |
|
633 |
} |
634 |
|
635 |
public void _draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
636 |
Cancellable cancel, double scale) throws ReadDriverException { |
637 |
|
638 |
FLyrVect fLyrVect = (FLyrVect) _layer; |
639 |
// FEATURE ITERATORS (TEST METHOD)
|
640 |
if (fLyrVect.isWithinScale(scale)) {
|
641 |
// Las que solo tienen etiquetado sin pintar el shape,
|
642 |
// no pasamos por ellas
|
643 |
boolean bDrawShapes = true; |
644 |
// if (legend instanceof SingleSymbolLegend) {
|
645 |
// if (legend.getDefaultSymbol().isShapeVisible() == false)
|
646 |
// bDrawShapes = false;
|
647 |
// }
|
648 |
if (bDrawShapes) {
|
649 |
try {
|
650 |
// prepareDrawing(image, g, viewPort);
|
651 |
|
652 |
ArrayList fieldList = new ArrayList(); |
653 |
|
654 |
// fields from legend
|
655 |
// String[] aux = legend.getUsedFields();
|
656 |
// for (int i = 0; i < aux.length; i++) {
|
657 |
// fieldList.add(aux[i]);
|
658 |
// }
|
659 |
|
660 |
// fields from labeling
|
661 |
// if (fLyrVect.isLabeled()) {
|
662 |
// aux = fLyrVect.getLabelingStrategy().getUsedFields();
|
663 |
// for (int i = 0; i < aux.length; i++) {
|
664 |
// fieldList.add(aux[i]);
|
665 |
// }
|
666 |
// }
|
667 |
|
668 |
IFeatureIterator it = fLyrVect.getSource() |
669 |
.getFeatureIterator(/*
|
670 |
* viewPort.getAdjustedExtent(),
|
671 |
* (String[])
|
672 |
* fieldList.toArray(new
|
673 |
* String[fieldList.size()]),
|
674 |
* getProjection()
|
675 |
*/);
|
676 |
|
677 |
ZSort zSort = ((IVectorLegend) fLyrVect.getLegend()) |
678 |
.getZSort(); |
679 |
if (zSort != null && zSort.isUsingZSort()) { |
680 |
BufferedImage[] imageLevels = new BufferedImage[zSort |
681 |
.getLevelCount() + 1];
|
682 |
// System.out.println(zSort);
|
683 |
Graphics2D[] graphics = new Graphics2D[imageLevels.length]; |
684 |
for (int i = 0; !cancel.isCanceled() |
685 |
&& i < imageLevels.length; i++) { |
686 |
imageLevels[i] = new BufferedImage( |
687 |
image.getWidth(), image.getHeight(), image |
688 |
.getType()); |
689 |
graphics[i] = imageLevels[i].createGraphics(); |
690 |
} |
691 |
while (!cancel.isCanceled() && it.hasNext()) {
|
692 |
IFeature feat = it.next(); |
693 |
IGeometry geom = feat.getGeometry(); |
694 |
|
695 |
ISymbol sym = ((IVectorLegend) fLyrVect |
696 |
.getLegend()).getSymbolByFeature(feat); |
697 |
if (sym instanceof IMultiLayerSymbol) { |
698 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
699 |
for (int i = 0; i < mlSym.getLayerCount(); i++) { |
700 |
ISymbol mySym = mlSym.getLayer(i); |
701 |
// System.out.println("drawing on level
|
702 |
// "+zSort.getSymbolLevel(mySym));
|
703 |
geom.drawInts(graphics[zSort |
704 |
.getSymbolLevel(mySym)], viewPort, |
705 |
mySym); |
706 |
} |
707 |
} else {
|
708 |
geom.drawInts(graphics[zSort |
709 |
.getSymbolLevel(sym)], viewPort, sym); |
710 |
} |
711 |
} |
712 |
|
713 |
for (int i = 0; i < imageLevels.length; i++) { |
714 |
g.drawImage(imageLevels[i], 0, 0, null); |
715 |
} |
716 |
} else {
|
717 |
|
718 |
while (!cancel.isCanceled() && it.hasNext()) {
|
719 |
IFeature feat = it.next(); |
720 |
ISymbol sym = ((IVectorLegend) fLyrVect |
721 |
.getLegend()).getSymbolByFeature(feat); |
722 |
IGeometry geom = feat.getGeometry(); |
723 |
|
724 |
geom.drawInts(g, viewPort, sym); |
725 |
} |
726 |
} |
727 |
} catch (ReadDriverException e) {
|
728 |
|
729 |
throw e;
|
730 |
} |
731 |
} |
732 |
|
733 |
} |
734 |
|
735 |
} |
736 |
|
737 |
public void newDraw() { |
738 |
FLyrVect fLyrVect = (FLyrVect) _layer; |
739 |
try {
|
740 |
|
741 |
// String[] aux;
|
742 |
// ArrayList fieldList = new ArrayList();
|
743 |
// if (fLyrVect.isLabeled()) {
|
744 |
// aux = fLyrVect.getLabelingStrategy().getUsedFields();
|
745 |
// aux = fLyrVect.getLabelingStrategy().getPlacementConstraints().getLocationsFor(geom, labelShape, exclusionZone);
|
746 |
// for (int i = 0; i < aux.length; i++) {
|
747 |
// fieldList.add(aux[i]);
|
748 |
// }
|
749 |
// }
|
750 |
|
751 |
IFeatureIterator it = fLyrVect.getSource().getFeatureIterator(); |
752 |
try {
|
753 |
while (it.hasNext()) {
|
754 |
IFeature feat = it.next(); |
755 |
ISymbol sym = ((IVectorLegend) fLyrVect.getLegend()) |
756 |
.getSymbolByFeature(feat); |
757 |
IGeometry geom = feat.getGeometry(); |
758 |
|
759 |
SimpleTextSymbol text = new SimpleTextSymbol();
|
760 |
text.setText("hola");
|
761 |
|
762 |
// text.set
|
763 |
// text.draw(g, affineTransform, shp)
|
764 |
// FShape shp = fLyrVect.getLabelingStrategy().getLabelingMethod().getDefaultLabelClass().getShape(g, at, geom);
|
765 |
// fLyrVect.getLabelingStrategy().getPlacementConstraints().getLocationsFor(geom, shp , null);
|
766 |
|
767 |
// Si no hacemos esto no se reproyecta la capa
|
768 |
ICoordTrans ct = fLyrVect.getCoordTrans(); |
769 |
|
770 |
if (ct != null) { |
771 |
geom.reProject(ct); |
772 |
} |
773 |
|
774 |
int geomType = geom.getGeometryType();
|
775 |
|
776 |
visitWithSymbol(geom, 0, sym);
|
777 |
|
778 |
} |
779 |
} catch (ExpansionFileReadException e) {
|
780 |
// TODO Auto-generated catch block
|
781 |
e.printStackTrace(); |
782 |
} |
783 |
|
784 |
} catch (ReadDriverException e) {
|
785 |
// TODO Auto-generated catch block
|
786 |
e.printStackTrace(); |
787 |
} |
788 |
|
789 |
} |
790 |
} |