Revision 15328

View differences:

import/ext3D/branches/ext3D_v1.1/ext3D/src/com/iver/ai2/gvsig3d/cacheservices/VectorCacheService.java
1 1
package com.iver.ai2.gvsig3d.cacheservices;
2 2

  
3
import java.awt.BasicStroke;
4 3
import java.awt.Color;
5
import java.awt.Component;
6
import java.awt.Font;
4
import java.awt.Graphics2D;
7 5
import java.awt.geom.PathIterator;
8 6
import java.awt.geom.Rectangle2D;
7
import java.awt.image.BufferedImage;
9 8
import java.util.ArrayList;
10 9
import java.util.HashMap;
11 10
import java.util.List;
12 11
import java.util.Map;
13 12

  
14
import javax.swing.JOptionPane;
15

  
16 13
import org.cresques.cts.ICoordTrans;
17 14
import org.cresques.cts.IProjection;
18
import org.cresques.geo.Point3D;
19 15
import org.cresques.px.Extent;
20 16
import org.gvsig.cacheservice.CacheService;
21 17

  
22
import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
23

  
24
import com.hardcode.gdbms.engine.values.DoubleValue;
25
import com.hardcode.gdbms.engine.values.NullValue;
26
import com.hardcode.gdbms.engine.values.NumericValue;
27
import com.hardcode.gdbms.engine.values.Value;
28
import com.iver.ai2.gvsig3d.gui.TransparencyPanel;
18
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
19
import com.hardcode.gdbms.engine.data.driver.DriverException;
29 20
import com.iver.ai2.gvsig3d.gui.VectorTest;
30
import com.iver.ai2.gvsig3d.gui.ViewProperties3D;
31 21
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
32
import com.iver.ai2.gvsig3d.utils.Punto3D;
33
import com.iver.andami.PluginServices;
34
import com.iver.andami.ui.mdiManager.IWindow;
35
import com.iver.cit.gvsig.fmap.DriverException;
22
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
23
import com.iver.cit.gvsig.fmap.ViewPort;
36 24
import com.iver.cit.gvsig.fmap.core.FGeometry;
37 25
import com.iver.cit.gvsig.fmap.core.FShape;
26
import com.iver.cit.gvsig.fmap.core.IFeature;
38 27
import com.iver.cit.gvsig.fmap.core.IGeometry;
39
import com.iver.cit.gvsig.fmap.core.ISymbol;
40
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
41
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
42
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
43
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
44
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
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;
45 37
import com.iver.cit.gvsig.fmap.layers.FLayer;
46 38
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
47
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
48
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
49
import com.iver.cit.gvsig.fmap.operations.strategies.ExtendsFeatureVisitor;
50 39
import com.iver.cit.gvsig.fmap.operations.strategies.DefaultStrategy;
51
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
52 40
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
53
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
54
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
41
import com.iver.cit.gvsig.fmap.rendering.IVectorialLegend;
42
import com.iver.cit.gvsig.fmap.rendering.ZSort;
43
import com.iver.utiles.swing.threads.Cancellable;
55 44

  
56 45
import es.upv.ai2.libjosg.Group;
57 46
import es.upv.ai2.libjosg.Node;
......
60 49
import es.upv.ai2.libjosg.features.Point;
61 50
import es.upv.ai2.libjosg.planets.Planet;
62 51
import es.upv.ai2.libjosg.planets.Planet.PlanetType;
63
import es.upv.ai2.libjosg.viewer.IViewer;
64 52
import es.upv.ai2.libjosg.viewer.IViewerContainer;
65 53

  
66
public class VectorCacheService extends CacheService implements ExtendsFeatureVisitor{
54
public class VectorCacheService extends CacheService {// implements
55
	// ExtendsFeatureVisitor{
67 56

  
68 57
	private IViewerContainer _canvas3D;
69 58

  
......
125 114

  
126 115
		try {
127 116
			_lyrExtentRect = _layer.getFullExtent();
128
		} catch (DriverException e) {
129
			return;
117
		} catch (ExpansionFileReadException e) {
118
			// TODO Auto-generated catch block
119
			e.printStackTrace();
120
		} catch (ReadDriverException e) {
121
			// TODO Auto-generated catch block
122
			e.printStackTrace();
130 123
		}
131 124

  
132 125
		_extent = new Extent(_lyrExtentRect);
133 126

  
127
		// EJEMPLO DE COMO SE COGE LEL ITERATOR DE LA CAPA VECTORIAL
128
		FLyrVect flyrVect = (FLyrVect) _layer;
129
		try {
130
			IFeatureIterator it = flyrVect.getSource().getFeatureIterator();
131

  
132
		} catch (ReadDriverException e) {
133
			// TODO Auto-generated catch block
134
			e.printStackTrace();
135
		}
136

  
134 137
	}
135 138

  
136 139
	// uses a strategy to get all features from layer and their symbols
......
144 147
		Strategy strat = new DefaultStrategy(_layer);
145 148
		try {
146 149
			pointsMap = new HashMap();
147
			strat.processWithSymbols(this, null /* no extent for now */, null);
150

  
151
			// YA NO SE USAN STRATEGYS POR LO TANTO NO EXISTE EL
152
			// PROCESSWITHSYMBOLS
153
			// strat.processWithSymbols(this, null /* no extent for now */,
154
			// null);
155
			newDraw();
148 156
			_layerNode.addChild(VectorTest.insertPointS((HashMap) pointsMap));
149 157
			getNames();
150 158
			_canvas3D.repaint();
......
154 162
	}
155 163

  
156 164
	public void RefreshFeaturesToPlanet() {
157

  
158 165
		// for testing, use DefaultStrategy. Later on we can implement
159 166
		// the optimized strategies
160 167
		this.DeleteFeaturesToPlanet();
......
166 173
		// SALVA_FEATURES
167 174
		Strategy strat = new DefaultStrategy(_layer);
168 175
		try {
169
			strat.processWithSymbols(this, null /* no extent for now */, null);
176
			// YA NO SE USAN STRATEGYS POR LO TANTO NO EXISTE EL
177
			// PROCESSWITHSYMBOLS
178
			// strat.processWithSymbols(this, null /* no extent for now */,
179
			// null);
180
			newDraw();
170 181
			_layerNode.addChild(VectorTest.insertPointS((HashMap) pointsMap));
171 182
			getNames();
172 183
		} catch (Exception e) {
......
198 209
		return true; // if everything is okay
199 210
	}
200 211

  
201
	public void stop(FLayer layer) {
202
		// process of adding features is finished
203
	}
212
	// public void stop(FLayer layer) {
213
	// // process of adding features is finished
214
	// }
215
	//
216
	// public void visit(IGeometry g, int index) throws VisitException {
217
	// // TODO Auto-generated method stub
218
	//
219
	// }
204 220

  
205
	public void visit(IGeometry g, int index) throws VisitException {
206
		// TODO Auto-generated method stub
221
	// SALVA_FEATURES
222
	public void visitWithSymbol(IGeometry g, int index, ISymbol symbol) {
207 223

  
208
	}
224
		ISymbol fsym = null;
225
		Color color = null;
226
		int geomType;
227
		// Point parameters
228
		int pointSize = 15;
229
		// Line parameters
230
		ILineStyle lineStyle;
231
		float lineWidth = 2;
232
		// Polygon parameters
209 233

  
210
	// SALVA_FEATURES
211
	public void visitWithSymbol(IGeometry g, int index, ISymbol symbol)
212
			throws VisitException {
213

  
214 234
		if (g == null || symbol == null)
215 235
			return;
216 236

  
217 237
		// Getting geometri
218
		int geomType = g.getGeometryType();
238
		geomType = g.getGeometryType();
219 239
		// Setting up geometri
220 240
		startGeometry(geomType, symbol);
221 241

  
222
		// Getting symbol
223
		FSymbol fsym = (FSymbol) symbol;
242
		// Casting to symbol type
224 243

  
244
		// Point type
245
		if (symbol instanceof IMarkerSymbol) {
246
			fsym = (IMarkerSymbol) symbol;
247
			color = ((IMarkerSymbol) fsym).getColor();
248
			pointSize = (int) ((IMarkerSymbol) fsym).getSize();
249
//			pointSize = 10;
250

  
251
		}
252
		// Line Type
253
		if (symbol instanceof ILineSymbol) {
254
			fsym = (ILineSymbol) symbol;
255
			color = ((ILineSymbol) fsym).getColor();
256
			color = new Color(1.0f,0.0f,0.0f);
257
			lineStyle = ((ILineSymbol) fsym).getLineStyle();
258
			lineWidth = lineStyle.getLineWidth();
259
			SimpleLineSymbol a;
260
		}
261
		// Polygon type
262
		if (symbol instanceof IFillSymbol) {
263
			fsym = (IFillSymbol) symbol;
264
			color = ((IFillSymbol) fsym).getFillColor();
265

  
266
		}
267

  
268
		// TRANSFORMANDO A GEOMETRIA CON VALOR Z
225 269
		FGeometry g3D = null;
226 270
		if (g instanceof FGeometry) {
227 271
			g3D = (FGeometry) g;
228 272
		}
229 273

  
230
		// Getting simbol parameters
231
		Color color = fsym.getColor();
232
		// Point size
233
		int size = fsym.getSize();
234

  
274
		// Setup point hash map
235 275
		List pointListAux = null;
236

  
237 276
		if ((geomType & FShape.POINT) == FShape.POINT) {
238
			if (pointsMap.containsKey(new Integer(size))) {
277
			if (pointsMap.containsKey(new Integer(pointSize))) {
239 278
				// System.out.println("ya contiene esa key");
240
				pointListAux = (List) pointsMap.get(new Integer(size));
279
				pointListAux = (List) pointsMap.get(new Double(pointSize));
241 280
			} else {
242 281
				pointListAux = new ArrayList();
243
				pointsMap.put(new Integer(size), pointListAux);
282
				pointsMap.put(new Integer(pointSize), pointListAux);
244 283
			}
245 284

  
246 285
		}
247 286

  
248
		// Line Size
249
		float lineSize = 0;
250
		if ((BasicStroke) fsym.getStroke() != null)
251
			lineSize = ((BasicStroke) fsym.getStroke()).getLineWidth();
252
		float comp[] = new float[4];
253
		color.getColorComponents(comp);
287
		// if ((BasicStroke) fsym.getStroke() != null)
288
		// lineSize = ((BasicStroke) fsym.getStroke()).getLineWidth();
289
		// float comp[] = new float[4];
290
		// Color color = ((SimpleFillSymbol) fsym).getOutline().getColor();
291
		// comp = color.getColorComponents(comp);
292
		// color.getColorComponents(comp);
254 293

  
255 294
		// Getting font size
256
		Font font = fsym.getFont();
257
		if (font != null) {
258
			inPixels = fsym.isFontSizeInPixels();
259
			if (inPixels)
260
				fontSize = (int) (((fsym.getFontSize() / FConstant.FONT_HEIGHT_SCALE_FACTOR))* 2.5);
261
			else
262
				fontSize = (int) (fsym.getFontSize() / FConstant.FONT_HEIGHT_SCALE_FACTOR);
263
		}
295
//		Font font = fsym.getFont();
296
//		if (font != null) {
297
//			inPixels = fsym.isFontSizeInPixels();
298
//			if (inPixels)
299
//				fontSize = (int) (((fsym.getFontSize() / FConstant.FONT_HEIGHT_SCALE_FACTOR)) * 2.5);
300
//			else
301
//				fontSize = (int) (fsym.getFontSize() / FConstant.FONT_HEIGHT_SCALE_FACTOR);
302
//		}
264 303

  
265
		float alpha = ((float) fsym.getColor().getAlpha()) / 255.0f;
304
		// float alpha = ((float) fsym.getColor().getAlpha()) / 255.0f;
266 305

  
267
		Vec4 rgba = new Vec4(comp[0], comp[1], comp[2], alpha);
306
		float alpha = 1.0f;
307
		 Vec4 rgba = new Vec4(color.getRed(),color.getGreen(),color.getBlue(), alpha);
308
//		Vec4 rgba = new Vec4(1.0, 0.0, 0.0, alpha);
268 309

  
269 310
		// System.out.println("Transparencia :" + fsym.getColor().getAlpha());
270 311

  
......
305 346
			if (this._planet.getType() == PlanetType.SPHERICAL_MODE) {
306 347
				// Transform to geodesical coordinates
307 348
				// posGeo = new Vec3(dataLine[1], dataLine[0], heigth);
349
				// posReal = new Vec3(dataLine[0], dataLine[1], dataLine[2]);
350
				// posGeo = _planet.convertLatLongHeightToXYZ(new Vec3(40.0,
351
				// 0.0, h));
352
				// posReal.setZ(posGeo.z());
353
				// pos = posReal;
354
				// pos.setX(posGeo.x());
355
				// pos.setY(posGeo.y());
356

  
308 357
				posGeo = new Vec3(dataLine[1], dataLine[0], h);
309 358
				pos = _planet.convertLatLongHeightToXYZ(posGeo);
310 359
			} else {
311 360
				pos = new Vec3(dataLine[0], dataLine[1], h);
312 361
			}
313
			// System.out.println("Position: " + posGeo.x() + " " + posGeo.y()
314
			// + " " + posGeo.z());
315
			// System.out.println("Position: " + pos.x() + " " + pos.y()
362
			// System.out.println("\nPosition posicion geodesicas: " +
363
			// posReal.x() + " " + posReal.y()
364
			// + " " + posReal.z());
365
			// System.out.println("Position cartesianas : " + pos.x() + " " +
366
			// pos.y()
316 367
			// + " " + pos.z());
317 368

  
318 369
			// Adding points
......
322 373
				Node node = _currentNode;
323 374

  
324 375
				if ((geomType & FShape.POINT) == FShape.POINT) {
325
					pointListAux.add(new Punto3D(pos, rgba, size));
326
					// VectorTest.addNodeToPoint(node, pos, rgba, size);
376
					// pointListAux.add(new Punto3D(pos, rgba, pointSize));
377
					VectorTest.addNodeToPoint(node, pos, rgba, pointSize);
327 378
				} else if ((geomType & FShape.LINE) == FShape.LINE) {
328
					node = VectorTest.insertLine(posi, rgba, lineSize);
379
					node = VectorTest.insertLine(posi, rgba, lineWidth);
329 380
				}
330 381
				if ((geomType & FShape.POLYGON) == FShape.POLYGON) {
331 382
					node = VectorTest.insertPolygon(posi, rgba);
......
368 419
		Node node = _currentNode;
369 420
		if (posi.size() > 0) {
370 421
			if ((geomType & FShape.POINT) == FShape.POINT) {
371
				// node = VectorTest.insertPoints(posi, rgba, size);
422
				node = VectorTest.insertPoints(posi, rgba, pointSize);
372 423
				// pointListAux.add(new Punto3D(pos,rgba,size));
373
//				System.out.println("entro");
424
				// System.out.println("entro");
374 425
			} else if ((geomType & FShape.LINE) == FShape.LINE) {
375
				node = VectorTest.insertLine(posi, rgba, lineSize);
426
				node = VectorTest.insertLine(posi, rgba, lineWidth);
376 427
			}
377 428
			if ((geomType & FShape.POLYGON) == FShape.POLYGON) {
378 429
				node = VectorTest.insertPolygon(posi, rgba);
......
399 450

  
400 451
			if ((geomType & FShape.Z) == FShape.Z)
401 452
				geomType = geomType - FShape.Z;
402
			switch (geomType) {
403 453

  
404
			case FShape.POINT:
405
				// Point point = (Point) VectorTest.insertPointS(new Vec3(0.0,
406
				// 0.0, 0.0), new Vec4(1.0f, 1.0f, 1.0f, 1.0f), 100);
454
			if (((geomType & FShape.POINT) == FShape.POINT)) {
407 455
				Group g = new Group();
408
				_currentNode = g;
456
				Point point = (Point) VectorTest.insertPointS(new Vec3(0.0,
457
						0.0, 0.0), new Vec4(1.0f, 1.0f, 1.0f, 1.0f), 100);
458
				_currentNode = point;
409 459
				_layerNode.addChild(g);
410
				break;
411
			case FShape.LINE:
412
				// No set up
413
				break;
414
			case FShape.POLYGON:
415
				// No set up
416
				break;
417

  
460
				g.addChild(point);
461
			} else if (((geomType & FShape.LINE) == FShape.LINE)) {
462
				;
463
			} else if (((geomType & FShape.POLYGON) == FShape.POLYGON)) {
464
				;
418 465
			}
466
			// switch (geomType) {
467
			//
468
			// case FShape.POINT:
469
			// // Point point = (Point) VectorTest.insertPointS(new Vec3(0.0,
470
			// // 0.0, 0.0), new Vec4(1.0f, 1.0f, 1.0f, 1.0f), 100);
471
			// Group g = new Group();
472
			// _currentNode = g;
473
			// _layerNode.addChild(g);
474
			// break;
475
			// case FShape.LINE:
476
			// // No set up
477
			// break;
478
			// case FShape.POLYGON:
479
			// // No set up
480
			// break;
481
			//
482
			// }
419 483

  
420 484
		}
421 485
	}
......
424 488

  
425 489
		if (_layer instanceof FLyrVect) {
426 490
			FLyrVect flyrVect = (FLyrVect) _layer;
427
			try {
428
				createLabels(flyrVect);
429
				// if (m_labels != null)
430
				if (((VectorialLegend) flyrVect.getLegend()).getLabelField() != null)
431
					if (m_labels.size() > 0)
432
						_layerNode.addChild(VectorTest.insertLabels(
433
								this.m_labels, fontSize, this.heigth,
434
								inPixels, this._planet.getType()));
491
			// REVISAR COMO SE GENERAN LOS LABELS CON LOS ITERADORES
435 492

  
436
			} catch (DriverException e) {
437
				// TODO Auto-generated catch block
438
				e.printStackTrace();
439
			}
493
			// createLabels(flyrVect);
494
			// // if (m_labels != null)
495
			// if (((VectorialLegend) flyrVect.getLegend()).getLabelField() !=
496
			// null)
497
			// if (m_labels.size() > 0)
498
			// _layerNode.addChild(VectorTest.insertLabels(
499
			// this.m_labels, fontSize, this.heigth,
500
			// inPixels, this._planet.getType()));
501
			//
502
			// } catch (DriverException e) {
503
			// // TODO Auto-generated catch block
504
			// e.printStackTrace();
505
			// }
440 506
		}
441 507

  
442 508
	}
443 509

  
444 510
	public void createLabels(FLyrVect lyrVect) throws DriverException {
445 511

  
446
		SelectableDataSource ds = null;
447
		ds = lyrVect.getRecordset();
512
		// SelectableDataSource ds = null;
513
		// ds = lyrVect.getRecordset();
448 514

  
449
		try {
450
			ReadableVectorial adapter = lyrVect.getSource();
451
			adapter.start();
452
			ds.start();
453
			int sc;
515
		// try {
516
		// ReadableVectorial adapter = lyrVect.getSource();
517
		// adapter.start();
518
		// ds.start();
519
		// int sc;
520
		//
521
		// VectorialLegend l = (VectorialLegend) lyrVect.getLegend();
522
		//
523
		// if (((VectorialLegend) lyrVect.getLegend()).getLabelField() != null)
524
		// {
525
		// int fieldId = ds.getFieldIndexByName(((VectorialLegend) lyrVect
526
		// .getLegend()).getLabelField());
527
		// int idFieldHeightText = -1;
528
		// int idFieldRotationText = -1;
529
		//
530
		// FSymbol defaultSym = (FSymbol) l.getDefaultSymbol();
531
		//
532
		// if (l.getLabelHeightField() != null) {
533
		// idFieldHeightText = ds.getFieldIndexByName(l
534
		// .getLabelHeightField());
535
		// defaultSym.setFontSizeInPixels(false);
536
		// }
537
		//
538
		// if (l.getLabelRotationField() != null) {
539
		// idFieldRotationText = ds.getFieldIndexByName(l
540
		// .getLabelRotationField());
541
		// }
542
		//
543
		// sc = (int) ds.getRowCount();
544
		// m_labels = new ArrayList(sc);
545
		//
546
		// DriverAttributes attr = adapter.getDriverAttributes();
547
		// boolean bMustClone = false;
548
		// if (attr != null) {
549
		// if (attr.isLoadedInMemory()) {
550
		// bMustClone = attr.isLoadedInMemory();
551
		// }
552
		// }
553
		// ICoordTrans ct = lyrVect.getCoordTrans();
554
		//
555
		// for (int i = 0; i < sc; i++) {
556
		// IGeometry geom = adapter.getShape(i);
557
		//
558
		// if (geom == null) {
559
		// m_labels.add(null);
560
		// continue;
561
		// }
562
		// if (ct != null) {
563
		// if (bMustClone)
564
		// geom = geom.cloneGeometry();
565
		// geom.reProject(ct);
566
		// }
567
		//
568
		// // TODO: El m�todo contenedor (createLabelLayer) debe
569
		// // recoger
570
		// // los par�metros de posicionamiento y de allowDuplicates
571
		// // if (i >= 328)
572
		// // System.out.println("i= " + i + " " + val.toString());
573
		// Value val = ds.getFieldValue(i, fieldId);
574
		//
575
		// if ((val instanceof NullValue) || (val == null)) {
576
		// continue;
577
		// }
578
		//
579
		// FLabel[] lbls = geom.createLabels(0, true);
580
		// for (int j = 0; j < lbls.length; j++) {
581
		// if (lbls[j] != null) {
582
		// lbls[j].setString(val.toString());
583
		//
584
		// if (idFieldHeightText != -1) {
585
		// NumericValue height = (NumericValue) ds
586
		// .getFieldValue(i, idFieldHeightText);
587
		// lbls[j].setHeight(height.floatValue());
588
		// } else {
589
		// // El tama�o del texto va siempre en el
590
		// // simbolo
591
		// // por
592
		// // defecto
593
		// // cuando no hay un campo de altura de texto
594
		// // TODO: Todo esto cambiar� con el nuevo
595
		// // sistema
596
		// // de
597
		// // leyendas...
598
		// if (l.getDefaultSymbol() != null) {
599
		// lbls[j].setHeight(defaultSym.getFontSize());
600
		// // lbls[j].setColor(defaultSym.getFontColor()
601
		// // .getRGB());
602
		//
603
		// }
604
		// }
605
		//
606
		// if (idFieldRotationText != -1) {
607
		// DoubleValue rotation = (DoubleValue) ds
608
		// .getFieldValue(i, idFieldRotationText);
609
		// lbls[j].setRotation(rotation.getValue());
610
		// }
611
		// m_labels.add(lbls[j]);
612
		//
613
		// }
614
		//
615
		// }
616
		//
617
		// /*
618
		// * if (lbls[0] == null) m_labels.add(null); else
619
		// * m_labels.add(lbls[0].getOrig());
620
		// */
621
		// }
622
		//
623
		// }
624
		// ds.stop();
625
		// adapter.stop();
626
		//
627
		// } catch (DriverIOException e) {
628
		// e.printStackTrace();
629
		// throw new DriverException(e);
630
		// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
631
		// e.printStackTrace();
632
		// throw new DriverException(e);
633
		// }
454 634

  
455
			VectorialLegend l = (VectorialLegend) lyrVect.getLegend();
635
	}
456 636

  
457
			if (((VectorialLegend) lyrVect.getLegend()).getLabelField() != null) {
458
				int fieldId = ds.getFieldIndexByName(((VectorialLegend) lyrVect
459
						.getLegend()).getLabelField());
460
				int idFieldHeightText = -1;
461
				int idFieldRotationText = -1;
637
	public void _draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
638
			Cancellable cancel, double scale) throws ReadDriverException {
462 639

  
463
				FSymbol defaultSym = (FSymbol) l.getDefaultSymbol();
640
		FLyrVect fLyrVect = (FLyrVect) _layer;
641
		// FEATURE ITERATORS (TEST METHOD)
642
		if (fLyrVect.isWithinScale(scale)) {
643
			// Las que solo tienen etiquetado sin pintar el shape,
644
			// no pasamos por ellas
645
			boolean bDrawShapes = true;
646
			// if (legend instanceof SingleSymbolLegend) {
647
			// if (legend.getDefaultSymbol().isShapeVisible() == false)
648
			// bDrawShapes = false;
649
			// }
650
			if (bDrawShapes) {
651
				try {
652
					// prepareDrawing(image, g, viewPort);
464 653

  
465
				if (l.getLabelHeightField() != null) {
466
					idFieldHeightText = ds.getFieldIndexByName(l
467
							.getLabelHeightField());
468
					defaultSym.setFontSizeInPixels(false);
469
				}
654
					ArrayList fieldList = new ArrayList();
470 655

  
471
				if (l.getLabelRotationField() != null) {
472
					idFieldRotationText = ds.getFieldIndexByName(l
473
							.getLabelRotationField());
474
				}
656
					// fields from legend
657
					// String[] aux = legend.getUsedFields();
658
					// for (int i = 0; i < aux.length; i++) {
659
					// fieldList.add(aux[i]);
660
					// }
475 661

  
476
				sc = (int) ds.getRowCount();
477
				m_labels = new ArrayList(sc);
662
					// fields from labeling
663
					// if (fLyrVect.isLabeled()) {
664
					// aux = fLyrVect.getLabelingStrategy().getUsedFields();
665
					// for (int i = 0; i < aux.length; i++) {
666
					// fieldList.add(aux[i]);
667
					// }
668
					// }
478 669

  
479
				DriverAttributes attr = adapter.getDriverAttributes();
480
				boolean bMustClone = false;
481
				if (attr != null) {
482
					if (attr.isLoadedInMemory()) {
483
						bMustClone = attr.isLoadedInMemory();
484
					}
485
				}
486
				ICoordTrans ct = lyrVect.getCoordTrans();
670
					IFeatureIterator it = fLyrVect.getSource()
671
							.getFeatureIterator(/*
672
												 * viewPort.getAdjustedExtent(),
673
												 * (String[])
674
												 * fieldList.toArray(new
675
												 * String[fieldList.size()]),
676
												 * getProjection()
677
												 */);
487 678

  
488
				for (int i = 0; i < sc; i++) {
489
					IGeometry geom = adapter.getShape(i);
679
					ZSort zSort = ((IVectorialLegend) fLyrVect.getLegend())
680
							.getZSort();
681
					if (zSort != null && zSort.isUsingZSort()) {
682
						BufferedImage[] imageLevels = new BufferedImage[zSort
683
								.getLevelCount() + 1];
684
						// System.out.println(zSort);
685
						Graphics2D[] graphics = new Graphics2D[imageLevels.length];
686
						for (int i = 0; !cancel.isCanceled()
687
								&& i < imageLevels.length; i++) {
688
							imageLevels[i] = new BufferedImage(
689
									image.getWidth(), image.getHeight(), image
690
											.getType());
691
							graphics[i] = imageLevels[i].createGraphics();
692
						}
693
						while (!cancel.isCanceled() && it.hasNext()) {
694
							IFeature feat = it.next();
695
							IGeometry geom = feat.getGeometry();
490 696

  
491
					if (geom == null) {
492
						m_labels.add(null);
493
						continue;
494
					}
495
					if (ct != null) {
496
						if (bMustClone)
497
							geom = geom.cloneGeometry();
498
						geom.reProject(ct);
499
					}
697
							ISymbol sym = ((IVectorialLegend) fLyrVect
698
									.getLegend()).getSymbolByFeature(feat);
699
							if (sym instanceof IMultiLayerSymbol) {
700
								IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
701
								for (int i = 0; i < mlSym.getLayerCount(); i++) {
702
									ISymbol mySym = mlSym.getLayer(i);
703
									// System.out.println("drawing on level
704
									// "+zSort.getSymbolLevel(mySym));
705
									geom.drawInts(graphics[zSort
706
											.getSymbolLevel(mySym)], viewPort,
707
											mySym);
708
								}
709
							} else {
710
								geom.drawInts(graphics[zSort
711
										.getSymbolLevel(sym)], viewPort, sym);
712
							}
713
						}
500 714

  
501
					// TODO: El m�todo contenedor (createLabelLayer) debe
502
					// recoger
503
					// los par�metros de posicionamiento y de allowDuplicates
504
					// if (i >= 328)
505
					// System.out.println("i= " + i + " " + val.toString());
506
					Value val = ds.getFieldValue(i, fieldId);
715
						for (int i = 0; i < imageLevels.length; i++) {
716
							g.drawImage(imageLevels[i], 0, 0, null);
717
						}
718
					} else {
507 719

  
508
					if ((val instanceof NullValue) || (val == null)) {
509
						continue;
720
						while (!cancel.isCanceled() && it.hasNext()) {
721
							IFeature feat = it.next();
722
							ISymbol sym = ((IVectorialLegend) fLyrVect
723
									.getLegend()).getSymbolByFeature(feat);
724
							IGeometry geom = feat.getGeometry();
725

  
726
							geom.drawInts(g, viewPort, sym);
727
						}
510 728
					}
729
				} catch (ReadDriverException e) {
511 730

  
512
					FLabel[] lbls = geom.createLabels(0, true);
513
					for (int j = 0; j < lbls.length; j++) {
514
						if (lbls[j] != null) {
515
							lbls[j].setString(val.toString());
731
					throw e;
732
				} catch (ExpansionFileReadException e) {
516 733

  
517
							if (idFieldHeightText != -1) {
518
								NumericValue height = (NumericValue) ds
519
										.getFieldValue(i, idFieldHeightText);
520
								lbls[j].setHeight(height.floatValue());
521
							} else {
522
								// El tama�o del texto va siempre en el
523
								// simbolo
524
								// por
525
								// defecto
526
								// cuando no hay un campo de altura de texto
527
								// TODO: Todo esto cambiar� con el nuevo
528
								// sistema
529
								// de
530
								// leyendas...
531
								if (l.getDefaultSymbol() != null) {
532
									lbls[j].setHeight(defaultSym.getFontSize());
533
//									lbls[j].setColor(defaultSym.getFontColor()
534
//											.getRGB());
734
					// throw new DriverException(e);
735
					// TODO throw a correct exception (??? ReadDriverException
736
					// ???)
737
					e.printStackTrace();
738
				}
739
			}
535 740

  
536
								}
537
							}
741
		}
538 742

  
539
							if (idFieldRotationText != -1) {
540
								DoubleValue rotation = (DoubleValue) ds
541
										.getFieldValue(i, idFieldRotationText);
542
								lbls[j].setRotation(rotation.getValue());
543
							}
544
							m_labels.add(lbls[j]);
743
	}
545 744

  
546
						}
745
	public void newDraw() {
746
		FLyrVect fLyrVect = (FLyrVect) _layer;
747
		try {
748
			
749
//			String[] aux;
750
//			ArrayList fieldList = new ArrayList();
751
//			if (fLyrVect.isLabeled()) {
752
//				aux = fLyrVect.getLabelingStrategy().getUsedFields();
753
//				aux = fLyrVect.getLabelingStrategy().getPlacementConstraints().getLocationsFor(geom, labelShape, exclusionZone);
754
//				for (int i = 0; i < aux.length; i++) {
755
//					fieldList.add(aux[i]);
756
//				}
757
//			}
547 758

  
759
			IFeatureIterator it = fLyrVect.getSource().getFeatureIterator();
760
			try {
761
				while (it.hasNext()) {
762
					IFeature feat = it.next();
763
					ISymbol sym = ((IVectorialLegend) fLyrVect.getLegend())
764
							.getSymbolByFeature(feat);
765
					IGeometry geom = feat.getGeometry();
766
					
767
					SimpleTextSymbol text = new SimpleTextSymbol();
768
					text.setText("hola");
769
					
770
//					text.set
771
//					text.draw(g, affineTransform, shp)
772
//					FShape shp = fLyrVect.getLabelingStrategy().getLabelingMethod().getDefaultLabelClass().getShape(g, at, geom);
773
//					fLyrVect.getLabelingStrategy().getPlacementConstraints().getLocationsFor(geom, shp , null);
774

  
775
					// Si no hacemos esto no se reproyecta la capa
776
					ICoordTrans ct = fLyrVect.getCoordTrans();
777

  
778
					if (ct != null) {
779
						geom.reProject(ct);
548 780
					}
549 781

  
550
					/*
551
					 * if (lbls[0] == null) m_labels.add(null); else
552
					 * m_labels.add(lbls[0].getOrig());
553
					 */
782
					int geomType = geom.getGeometryType();
783

  
784
					visitWithSymbol(geom, 0, sym);
785
				
554 786
				}
555

  
787
			} catch (ExpansionFileReadException e) {
788
				// TODO Auto-generated catch block
789
				e.printStackTrace();
556 790
			}
557
			ds.stop();
558
			adapter.stop();
559 791

  
560
		} catch (DriverIOException e) {
792
		} catch (ReadDriverException e) {
793
			// TODO Auto-generated catch block
561 794
			e.printStackTrace();
562
			throw new DriverException(e);
563
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
564
			e.printStackTrace();
565
			throw new DriverException(e);
566 795
		}
567 796

  
568 797
	}

Also available in: Unified diff