Revision 36203

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/layout/fframes/FFrameView.java
363 363
					// Dibujamos en pantalla
364 364
					
365 365
					double scale1_1 = MapContext.getScreenDPI() / 2.54;
366
					double visible__factor = at.getScaleX() / scale1_1;
366
					// compute zoom factor
367
					double zf = at.getScaleX() / scale1_1;
367 368
					
368 369
					Rectangle rclip = null;
369 370
					if (g.getClipBounds()!=null)
......
373 374

  
374 375
					if (getQuality() == PRESENTACION) {
375 376
						if (rv.intersects(r)) {
376
							ViewPort viewPort = this.getMapContext()
377
							.getViewPort();
377
							ViewPort viewPort = this.getMapContext().getViewPort();
378
							viewPort.setZoomFactor(zf);
379
							
378 380
							Color theBackColor = viewPort.getBackColor();
379 381

  
380 382
							if (origin != null
......
434 436
										e.printStackTrace();
435 437
									}
436 438
									g.translate(r.getX(), r.getY());
439
									
440
									viewp.setZoomFactor(1);
437 441

  
438 442
								} else {
439 443
									viewPort.setOffset(
......
452 456
									try {
453 457
										MapContext mapContext = getMapContext();
454 458
										mapContext.getMapContextDrawer().clean();
455
										mapContext.draw(m_image, gimg, getScale(),
456
												MapContext.getScreenDPI() * visible__factor);
459
										mapContext.draw(m_image, gimg, getScale());
457 460
									} catch (ReadDriverException e) {
458 461
										e.printStackTrace();
459 462
									}
......
472 475
								origin = (Point) getLayout().getLayoutControl().getRectOrigin();
473 476
								setRefresh(false);
474 477
							}
478
							
479
							viewPort.setZoomFactor(1);
475 480
						}
476 481
					} else {
477 482
						drawDraft(g);
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/CartographicSupportToolkit.java
62 62
	 * (printer, screen, etc)
63 63
	 * @return The distance in pixels corresponding to the provided length
64 64
	 */
65
	public static double getCartographicLength(CartographicSupport cartographicElement, double length, ViewPort viewPort, double dpi) {
65
	public static double getCartographicLength(
66
			CartographicSupport cartographicElement,
67
			double length,
68
			ViewPort viewPort,
69
			double _dpi) {
70
		
66 71
		int unit = cartographicElement.getUnit();
67 72
		double lengthInPixel = length;
73
		
74
		double zoomed_dpi = viewPort.getZoomFactor() * _dpi;
68 75

  
69 76
		if (unit != -1) {
70 77
			double[] trans2Meter=MapContext.getDistanceTrans2Meter();
......
74 81
				lengthInPixel = realWidthMeter/dist1PixelInMeters;
75 82
			} else if (cartographicElement.getReferenceSystem() == CartographicSupport.PAPER) {
76 83
				double lengthInInches = 1/trans2Meter[7]*trans2Meter[unit]*length;
77
				lengthInPixel = lengthInInches*dpi;
84
				lengthInPixel = lengthInInches*zoomed_dpi;
85
				// double physical_dpi = getDpiFromViewPort(viewPort); 
86
				// lengthInPixel = lengthInInches*physical_dpi;
78 87
			}
79 88
		} else{
80
			double scale=dpi/72;
89
			double scale=zoomed_dpi/72;
81 90
			lengthInPixel=lengthInPixel*scale;
82 91
		}
83 92
		return  (lengthInPixel);
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/ViewPort.java
1278 1278
		}
1279 1279

  
1280 1280
		xml.putProperty("scale", scale);
1281
		xml.putProperty("zoomFactor", getZoomFactor());
1281 1282

  
1282 1283
		return xml;
1283 1284
	}
......
1412 1413
			vp.proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
1413 1414
		}
1414 1415

  
1416
		if (xml.contains("zoomFactor")) {
1417
			vp.setZoomFactor(xml.getDoubleProperty("zoomFactor"));
1418
		}
1419

  
1415 1420
		//vp.setScale(xml.getDoubleProperty("scale"));
1416 1421
		vp.refreshExtent();
1417 1422
		return vp;
......
1509 1514
	protected void updateDrawVersion(){
1510 1515
		this.drawVersion++;
1511 1516
	}
1517
	
1518
	
1519
	private double zoomFactor = 1d;
1512 1520

  
1521
	public double getZoomFactor() {
1522
		return zoomFactor;
1523
	}
1524

  
1525
	public void setZoomFactor(double z) {
1526
		this.zoomFactor = z;
1527
	}
1528
	
1529

  
1513 1530
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/MapContext.java
1117 1117
		System.gc();
1118 1118
	}
1119 1119
	
1120
	
1121
	
1122 1120
	/**
1123
	 * <p>Draws this map if its {@link ViewPort ViewPort} has an extent defined:<br>
1124
	 * <ol>
1125
	 * <li>Selects only the layers that have to be drawn: {@linkplain #prepareDrawing(BufferedImage, Graphics2D, double)}.
1126
	 * <li>Sets quality: antialiasing by text and images, and quality rendering.
1127
	 * <li>Draws the layers.
1128
	 * <li>Fires a <code>LayerDrawEvent.GRAPHICLAYER_BEFORE_DRAW</code>.
1129
	 * <li>Draws the graphic layer.
1130
	 * <li>Fires a <code>LayerDrawEvent.GRAPHICLAYER_AFTER_DRAW</code>.
1131
	 * <li>Invokes the garbage collector and memory clean.
1132
	 * </ol></p>
1133
	 *
1134
	 * @param image buffer used sometimes instead <code>g</code> to accelerate the draw. For example, if two points are as closed that can't be distinguished, draws only one.
1135
	 * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
1136
	 * @param cancel shared object that determines if this layer can continue being drawn
1137
	 * @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
1138
	 * @throws ReadDriverException if fails reading with the driver.
1139
	 */
1140
	public void draw(BufferedImage image, Graphics2D g, Cancellable cancel,
1141
			double scale, double _dpi) throws ReadDriverException {
1142
		if (viewPort.getExtent() == null) {
1143
			// System.err.println("viewPort.getExtent() = null");
1144
			return;
1145
		}
1146
		System.out.println("Viewport despues: " + viewPort.toString());
1147
		/*
1148
		 * if ((viewPort.getImageWidth() <=0) || (viewPort.getImageHeight() <=
1149
		 * 0)) { return; }
1150
		 */
1151

  
1152
//		prepareDrawing(image, g, scale);
1153

  
1154
		// M�s c�lidad al texto
1155
		RenderingHints renderHints = new RenderingHints(
1156
				RenderingHints.KEY_ANTIALIASING,
1157
				RenderingHints.VALUE_ANTIALIAS_ON);
1158
		renderHints.put(RenderingHints.KEY_RENDERING,
1159
				RenderingHints.VALUE_RENDER_QUALITY);
1160
		renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
1161
				RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
1162
		g.setRenderingHints(renderHints);
1163

  
1164
		long t1 = System.currentTimeMillis();
1165
//		layers.draw(image, g, viewPort, cancel, scale);
1166

  
1167
		this.getMapContextDrawer().draw(this.layers, image, g, cancel, scale, _dpi);
1168

  
1169
		LayerDrawEvent beforeTracLayerEvent = new LayerDrawEvent(tracLayer,
1170
				g, viewPort, LayerDrawEvent.GRAPHICLAYER_BEFORE_DRAW);
1171
		fireLayerDrawingEvent(beforeTracLayerEvent);
1172
		tracLayer.draw(image, g, viewPort, cancel, scale);
1173
		LayerDrawEvent afterTracLayerEvent = new LayerDrawEvent(tracLayer,
1174
				g, viewPort, LayerDrawEvent.GRAPHICLAYER_AFTER_DRAW);
1175
		fireLayerDrawingEvent(afterTracLayerEvent);
1176

  
1177
		//layers.setDirty(false);
1178
		long t2 = System.currentTimeMillis();
1179
		System.err.println("Tiempo de dibujado:" + (t2 - t1) +
1180
				" mseg. Memoria libre:" + Runtime.getRuntime().freeMemory() / 1024  + " KB");
1181
		/*
1182
		 * g.setColor(Color.BLUE); GeneralPath shpR = new
1183
		 * GeneralPath(viewPort.getExtent());
1184
		 * shpR.transform(viewPort.getAffineTransform()); g.draw(shpR);
1185
		 */
1186
		System.gc();
1187
	}
1188

  
1189
	/**
1190 1121
	 * <p>Draws only the internal graphic layer using the information of the {@link ViewPort ViewPort} of this map.</p>
1191 1122
	 *
1192 1123
	 * @param image image used to accelerate the screen draw
......
1234 1165
		}, scale);
1235 1166
	}
1236 1167

  
1237
	
1238
	/**
1239
	 * <p>Like {@linkplain MapContext#draw(BufferedImage, Graphics2D, Cancellable, double)}, but creating
1240
	 *  the task as cancellable.</p>
1241
	 *
1242
	 * @param image buffer used sometimes instead <code>g</code> to accelerate the draw. For example, if two points are as closed that can't be distinguished, draws only one.
1243
	 * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
1244
	 * @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
1245
	 *
1246
	 * @throws ReadDriverException if the driver fails reading.
1247
	 *
1248
	 * @see #draw(BufferedImage, Graphics2D, Cancellable, double)
1249
	 */
1250
	public void draw(BufferedImage image, Graphics2D g, double scale, double _dpi)
1251
			throws ReadDriverException {
1252
//		layers.setDirty(true);
1253
		draw(image, g, new Cancellable() {
1254
			/**
1255
			 * @see com.iver.utiles.swing.threads.Cancellable#isCanceled()
1256
			 */
1257
			public boolean isCanceled() {
1258
				return false;
1259
			}
1260 1168

  
1261
			public void setCanceled(boolean canceled) {
1262
				// TODO Auto-generated method stub
1263

  
1264
			}
1265
		}, scale, _dpi);
1266
	}
1267
	
1268
	
1269 1169
	/**
1270 1170
	 * <p>Gets the {@link ViewPort ViewPort} associated to this map.</p>
1271 1171
	 *
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/MapContextDrawer.java
15 15
	public void setViewPort(ViewPort viewPort);
16 16
	public void draw(FLayers root, BufferedImage image, Graphics2D g, Cancellable cancel,
17 17
			double scale) throws ReadDriverException;
18

  
19

  
20
	/**
21
	 * Alternative draw method, used when DPI in real world is different,
22
	 * for example, when you create a map and zoom in or out in it.
23
	 * The method takes in consideration the "physical_dpi" especailly
24
	 * to draw fonts in correct size.
25
	 * 
26
	 * @param root
27
	 * @param image
28
	 * @param g
29
	 * @param cancel
30
	 * @param scale
31
	 * @param physical_dpi
32
	 * @throws ReadDriverException
33
	 */
34
	public void draw(FLayers root, BufferedImage image, Graphics2D g, Cancellable cancel,
35
			double scale, double physical_dpi) throws ReadDriverException;
36 18
	public void print(FLayers root, Graphics2D g, Cancellable cancel,
37 19
			double scale, PrintRequestAttributeSet properties) throws ReadDriverException;
38 20
	public void dispose();
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/DefaultMapContextDrawer.java
190 190

  
191 191
	}
192 192
	
193
	
194

  
195
	public void draw(FLayers root, BufferedImage image, Graphics2D g, Cancellable cancel,
196
			double scale, double _dpi) throws ReadDriverException {
197

  
198
		this.checkIntilalized();
199

  
200
		boolean needToPaintAll = false;
201

  
202
		DrawList drawList = this.createDrawList(root, cancel,scale);
203
		if (cancel.isCanceled()){
204
			return;
205
		}
206

  
207
		if (cachedImage == null){
208
			needToPaintAll=true;
209
		} else if (!cachedImage.isValid(mapContext, viewPort, drawList.getFirstLayerToDraw())){
210
				needToPaintAll=true;
211
			}
212

  
213

  
214
		int firstLayer= 0;
215
		if (!needToPaintAll){
216
			firstLayer = cachedImage.getListPosition()+1;
217
//			System.out.println("=======Pintando a partir de la pos "+ firstLayer+"============");
218
			g.drawImage(cachedImage.getImage(), 0, 0, null);
219
//			System.out.println("=======Pintando imagen ============");
220

  
221
		} else{
222
			this.cachedImage = null;
223
//			System.out.println("=======Pintando todo============");
224
		}
225

  
226

  
227
		boolean cached=false;
228
		ComposedLayer composed = null;
229
		int pos;
230
		int layerPos= -1;
231
		FLayer layer;
232
		Object obj;
233
		LayersGroupEvent event;
234
		for (pos=0; pos < drawList.size(); pos++){
235
			if (cancel.isCanceled()){
236
				return;
237
			}
238

  
239
			obj = drawList.get(pos);
240

  
241
			// *** Gestion de eventos de pintado de grupos ***
242
			if (obj instanceof LayersGroupEvent){
243
				event = (LayersGroupEvent) obj;
244
				if (event.type == LayersGroupEvent.IN_Event){
245
//					System.out.println("=======Empiza a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============");
246
					event.group.beginDraw(g, viewPort);
247
				} else{
248
					event.group.endDraw(g, viewPort);
249
//					System.out.println("=======Fin a pintar grupo de capas "+ ((FLayers)event.group).getName() +"============");
250

  
251
				}
252
				continue;
253
			}
254
			layerPos++;
255
			if (layerPos < firstLayer){
256
				continue;
257
			}
258

  
259
			layer = (FLayer) obj;
260
			if (cancel.isCanceled()){
261
				return;
262
			}
263

  
264
			// *** Gestion de cache ***
265
			if ((!cached) && this.isLayerCacheable(layer)){
266
				if (layerPos > 0){ //La primera capa es la activa, no cacheamos
267
					if (cachedImage==null || cachedImage.getListPosition() < layerPos-1){
268

  
269
						if (composed != null){
270
							//si tenemos una composicion de capas, necesitamos pintarlas
271
							//antes de guardarnos la imagen
272
//							System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (antes de cache)============");
273
							this.draw(composed, image, g, cancel, scale, _dpi);
274
//							composed.draw(image, g, viewPort, cancel, scale);
275
							composed = null;
276

  
277
						}
278
						CachedImage  newCached = new CachedImage();
279
						newCached.setImage(image, mapContext, viewPort, layerPos-1);
280
						this.cachedImage = newCached;
281
//						System.out.println("=======Guardando imagen de la pos "+ (layerPos-1)+" ("+ newCached.getListPosition() +")============");
282
					}
283
				}
284
				cached = true;
285
			}
286
			if (cancel.isCanceled()){
287
				return;
288
			}
289

  
290
			if (composed == null){
291
				composed = layer.newComposedLayer();
292
				if (composed != null){
293
					try {
294
//						System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName());
295
						composed.add(layer);
296
						continue;
297
					} catch (Exception e) {
298
						throw new ReadDriverException("DefaultMapContexDrawer exception",e);
299
					}
300
				}
301
			}else{
302
				if (composed.canAdd(layer)){
303
					try {
304
//						System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName());
305
						composed.add(layer);
306
						continue;
307
					} catch (Exception e) {
308
						throw new ReadDriverException("DefaultMapContexDrawer exception",e);
309
					}
310
				} else {
311
//					System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (cambio composicion)============");
312
					this.draw(composed, image, g, cancel, scale, _dpi);
313
//					composed.draw(image, g, viewPort, cancel, scale);
314
					composed = layer.newComposedLayer();
315
					if (composed != null){
316
						try {
317
//							System.out.println("=== a?adiendo a composicion de pintado "+ layerPos+ " "+layer.getName());
318
							composed.add(layer);
319
							continue;
320
						} catch (Exception e) {
321
							throw new ReadDriverException("DefaultMapContexDrawer exception",e);
322
						}					}
323
				}
324
			}
325
//			System.out.println("=== pintando "+ layerPos+ " "+layer.getName());
326
			this.draw(layer, image, g, cancel, scale, _dpi);
327
//			layer.draw(image, g, viewPort, cancel, scale);
328

  
329
		}
330
		if (composed != null){
331
			// si la composicion no se ha pintado la pintamos
332
//			System.out.println("=======Pintando composicion de pintado "+ (layerPos-1)+" (ultimo)============");
333
			this.draw(composed, image, g, cancel, scale, _dpi);
334
//			composed.draw(image, g, viewPort, cancel, scale);
335
		}
336
		if (cancel.isCanceled()){
337
			return;
338
		}
339

  
340
		this.previousDrawList = drawList;
341

  
342
	}
343

  
344 193
	private void draw(Object layerOrComposed,BufferedImage image, Graphics2D g, Cancellable cancel,
345 194
			double scale, double _dpi) throws ReadDriverException{
346 195
		ILabelable labelable= null;

Also available in: Unified diff