Revision 33184

View differences:

tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	InputCoordinatesPanel class.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.symbology.gui.InputCoordinatesPanel">
23
		<priority value="DEBUG" />
24
	</category>
25

  
26
	<!-- 
27
	By default, show only logging messages of INFO level or higher, 
28
	through the previously configured CONSOLE appender. 
29
	-->
30
	<root>
31
		<priority value="INFO" />
32
		<appender-ref ref="CONSOLE" />
33
	</root>
34
</log4j:configuration>
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/TestCartographicSupportForSymbol.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering;
42

  
43
import java.awt.Dimension;
44
import java.awt.geom.Rectangle2D;
45
import java.util.ArrayList;
46
import java.util.Random;
47

  
48
import org.gvsig.compat.CompatLocator;
49
import org.gvsig.fmap.geom.GeometryLocator;
50
import org.gvsig.fmap.geom.GeometryManager;
51
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
52
import org.gvsig.fmap.geom.exception.CreateGeometryException;
53
import org.gvsig.fmap.geom.primitive.Envelope;
54
import org.gvsig.fmap.geom.primitive.Point;
55
import org.gvsig.fmap.mapcontext.MapContext;
56
import org.gvsig.fmap.mapcontext.MapContextLocator;
57
import org.gvsig.fmap.mapcontext.ViewPort;
58
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
59
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
60
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.AbstractSymbolTestCase;
62
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleFillSymbolTest;
63
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleLineSymbolTest;
64
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleMarkerSymbolTest;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
67
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
68
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
69
import org.gvsig.utils.IPersistence;
70
import org.gvsig.utils.NotExistInXMLEntity;
71
import org.gvsig.utils.XMLEntity;
72
import org.gvsig.utils.XMLException;
73
import org.slf4j.Logger;
74
import org.slf4j.LoggerFactory;
75

  
76

  
77
/**
78
 *
79
 * @author jaume dominguez faus - jaume.dominguez@iver.es
80
 */
81
public class TestCartographicSupportForSymbol extends AbstractLibraryAutoInitTestCase {
82
	private static GeometryManager geomManager;	
83
	private static final Logger logger = LoggerFactory.getLogger(TestCartographicSupportForSymbol.class);
84
	
85
	/**
86
	 * Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:23030</b>
87
	 */
88
	public static Point valenciaUTM30 = null;
89

  
90
	/**
91
	 * Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:4326</b>
92
	 */
93
	public static Point valenciaGeo = null;
94

  
95
	public SymbolManager manager = MapContextLocator.getSymbolManager();
96
	/**
97
	 * Extent that covers the whole Comunitat Valenciana in  <b>EPSG:23030</b>
98
	 */
99
	public static final Rectangle2D TEST_UTM30_EXTENT = new Rectangle2D.Double();
100
	{
101
		TEST_UTM30_EXTENT.setFrameFromDiagonal(
102
				4191037.369934333,
103
				626674.7454557443,
104

  
105
				4519266.460824658,
106
				797903.2656794232
107
		);
108
	}
109
	/**
110
	 * Extent that covers the whole Comunitat Valenciana in  <b>EPSG:4326</b>
111
	 */
112

  
113
	public static final Rectangle2D TEST_GEO_EXTENT = new Rectangle2D.Double();
114
	{
115
		TEST_GEO_EXTENT.setFrameFromDiagonal(
116

  
117
				-  (1 + (31/60) + (28.09/3600)),	// Western egde
118
				37 + (50/60) + (48.05/3600),		// Southern edge
119

  
120
				0 + (31/60) + (1.85/3600),		// Eastern edge
121
				40 + (47/60) + (21.36/3600)		// Northern edge
122

  
123
		);
124
	}
125

  
126
	public static final Rectangle2D TEST_EXTENT = new Rectangle2D.Double(
127
			4191037.369934333,
128
			626674.7454557443,
129

  
130
			4519266.460824658 - 4191037.369934333,
131
			797903.2656794232 -  626674.7454557443
132
	);
133
	private static ArrayList symbolsToTest; //<AbstractSymbolTestCase>
134
	private ArrayList csSymbols; //<CartographicSupport>
135

  
136
	/**
137
	 * Acceptable pixel tolerance error. 1 pixel of error is accetable since it is probably due to
138
	 * the java.awt.Graphics
139
	 */
140
	private static final double TOL = 1;
141

  
142
	double zooms[] = new double[] {
143
			1,
144
			2,
145
			1.2,
146
			10,
147
			0.5
148
	};
149

  
150
	protected void doSetUp() throws Exception {	
151
		geomManager = GeometryLocator.getGeometryManager();
152
		try {
153
			valenciaUTM30 = geomManager.createPoint(725846.080, 4373022.720, SUBTYPES.GEOM2D);
154
			valenciaGeo = geomManager.createPoint(- (0+ 22/60 +  27.919/3600), 39 + 28/60 + 35.4276/3600, SUBTYPES.GEOM2D);
155
		} catch (CreateGeometryException e) {
156
			// TODO Auto-generated catch block
157
			e.printStackTrace();
158
		}		
159
	
160
		addSymbolTest(new SimpleFillSymbolTest());
161
		addSymbolTest(new SimpleLineSymbolTest());
162
		addSymbolTest(new SimpleMarkerSymbolTest());
163

  
164
		init();
165
	}
166

  
167
	protected void init() {
168

  
169
		// take the symbols added to the TestISymbol test
170
		ISymbol[] symbols = getNewSymbolInstances();
171

  
172
		csSymbols = new ArrayList(); //<CartographicSupport>
173
		for (int i = 0; i < symbols.length; i++) {
174
			if (symbols[i] instanceof CartographicSupport) {
175
				csSymbols.add((CartographicSupport) symbols[i]);
176
			}
177
		}
178
	}
179

  
180
	public static void addSymbolTest(AbstractSymbolTestCase symbolTestClass) {
181
		if (symbolsToTest == null) symbolsToTest = new ArrayList(); //<AbstractSymbolTestCase>
182
		symbolsToTest.add(symbolTestClass);
183
	}
184

  
185
	public static ISymbol[] getNewSymbolInstances() {
186
		ISymbol[] symbols = new ISymbol[symbolsToTest.size()];
187
		for (int i = 0; i < symbols.length; i++) {
188
			symbols[i] = (ISymbol)((AbstractSymbolTestCase)symbolsToTest.get(i)).newInstance();
189
		}
190
		return symbols;
191
	}
192

  
193

  
194
	public void testSymbolUnitDefinition() {
195
		for (int i = 0; i < csSymbols.size(); i++) {
196
			CartographicSupport symbol = (CartographicSupport)csSymbols.get(i);
197

  
198
			int aRandomUnit = new Random().nextInt(7);
199

  
200

  
201
			symbol.setUnit(aRandomUnit);
202
			XMLEntity xml=null;
203
			try {
204
				xml = ((IPersistence) symbol).getXMLEntity();
205
			} catch (XMLException e) {
206
				// TODO Auto-generated catch block
207
				e.printStackTrace();
208
			}
209
			String name = symbol.getClass().getName().substring(
210
					symbol.getClass().getName().lastIndexOf('.')+1,
211
					symbol.getClass().getName().length());
212

  
213
			try {
214
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
215
						symbol.getUnit() == xml.getIntProperty("unit"));
216
			} catch (NotExistInXMLEntity neiXMLEx) {
217
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
218
			}
219
			symbol.setUnit(5);
220
			try {
221
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getUnit()== 5);
222
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
223
						5 == ((IPersistence) symbol).getXMLEntity().getIntProperty("unit"));
224
			} catch (NotExistInXMLEntity neiXMLEx) {
225
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
226
			} catch (XMLException e) {
227
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
228
			}
229

  
230
//			xml.putProperty("unit", 3);
231
//			ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
232
//			assertTrue("The application of the UNIT value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getUnit() == 3);
233
		}
234

  
235
	}
236

  
237

  
238
	public void testSymbolReferenceSystemDefinition() {
239
		for (int i = 0; i < csSymbols.size(); i++) {
240
			CartographicSupport symbol = (CartographicSupport)csSymbols.get(i);
241
			XMLEntity xml=null;
242
			try {
243
				xml = ((IPersistence) symbol).getXMLEntity();
244
			} catch (XMLException e) {
245
				// TODO Auto-generated catch block
246
				e.printStackTrace();
247
			}
248
			String name = symbol.getClass().getName().substring(
249
					symbol.getClass().getName().lastIndexOf('.')+1,
250
					symbol.getClass().getName().length());
251
			try {
252
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
253
						symbol.getReferenceSystem() == xml.getIntProperty("referenceSystem"));
254
			} catch (NotExistInXMLEntity neiXMLEx) {
255
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
256
			}
257
			symbol.setReferenceSystem(CartographicSupport.PAPER);
258
			try {
259
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.PAPER);
260
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly",
261
						CartographicSupport.PAPER == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
262
			} catch (NotExistInXMLEntity neiXMLEx) {
263
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")");
264
			} catch (XMLException e) {
265
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")");
266
			}
267

  
268
			symbol.setReferenceSystem(CartographicSupport.WORLD);
269
			try {
270
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.WORLD);
271
				assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly",
272
						CartographicSupport.WORLD == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
273
			} catch (NotExistInXMLEntity neiXMLEx) {
274
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
275
			} catch (XMLException e) {
276
				fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
277
			}
278

  
279
//			xml.putProperty("referenceSystem", CartographicSupport.PAPER);
280
//			ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
281
//			assertTrue("The application of the REFERENCE SYSTEM value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getReferenceSystem() == CartographicSupport.PAPER);
282
		}
283
	}
284

  
285

  
286
	public void testDegreesUnits_MapReferenceSystem() throws Exception {
287
		for (int j = 0; j < csSymbols.size(); j++) {
288
			CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
289

  
290
			MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_PROJECTION);
291
			ViewPort viewPort = mc.getViewPort();
292

  
293
			int unit = 8;
294
			Dimension dim = new Dimension(600, 600);
295
			viewPort.setImageSize(dim);
296

  
297

  
298
			/*
299
			 * will test with several extents but in the same map image size, so
300
			 * the scale issue is exercised as well.
301
			 */
302
			for (int i = 0; i < zooms.length; i++) {
303
				Envelope extent = geomManager.createEnvelope(-30, -30,dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
304

  
305
				viewPort.setMapUnits(unit);
306
				viewPort.setEnvelope(extent);
307

  
308

  
309
				String name = ((IPersistence) symbol).getClassName().substring(
310
						((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
311
						((IPersistence) symbol).getClassName().length());
312

  
313
				CartographicSupport csSym = (CartographicSupport) symbol;
314
				csSym.setReferenceSystem(CartographicSupport.WORLD);
315
				double size = 30;
316

  
317
				csSym.setUnit(unit);
318

  
319

  
320

  
321
				if (symbol instanceof IMarkerSymbol) {
322

  
323
					IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
324
					markerSym.setSize(size);
325
					csSym.toCartographicSize(
326
							viewPort,
327
							CompatLocator.getGraphicsUtils().getScreenDPI(),
328
							geomManager.createPoint(
329
									viewPort.getAdjustedExtent().getCenter(0),
330
									viewPort.getAdjustedExtent().getCenter(1),
331
									SUBTYPES.GEOM2D
332
							)
333
					);
334
					double mySize = markerSym.getSize();
335
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
336
							"It returned "+markerSym.getSize()+" when expecting "+
337
							size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
338
				}
339

  
340
				if (symbol instanceof ILineSymbol) {
341

  
342
					ILineSymbol lineSym = (ILineSymbol) symbol;
343
					lineSym.setLineWidth(size);
344
					csSym.toCartographicSize(
345
							viewPort,
346
							CompatLocator.getGraphicsUtils().getScreenDPI(),
347
							geomManager.createPoint(
348
									viewPort.getAdjustedExtent().getCenter(0),
349
									viewPort.getAdjustedExtent().getCenter(1),
350
									SUBTYPES.GEOM2D
351
							)
352
					);
353
					double mySize = lineSym.getLineStyle().getLineWidth();
354
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
355
							"It returned "+mySize+" when expecting "+
356
							size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
357
				}
358

  
359
				if (symbol instanceof IFillSymbol) {
360
					// this tests if symbol applies the cartographic support to its
361
					// outline, since is the only thing that may be resized
362
					IFillSymbol fillSym = (IFillSymbol) symbol;
363
					if (fillSym.getOutline() == null) {
364
						fillSym.setOutline((ILineSymbol) manager.createSymbol(ILineSymbol.SYMBOL_NAME));
365
					}
366

  
367
					fillSym.getOutline().setLineWidth(size);
368

  
369
					csSym.toCartographicSize(
370
							viewPort,
371
							CompatLocator.getGraphicsUtils().getScreenDPI(),
372
							geomManager.createPoint(
373
									viewPort.getAdjustedExtent().getCenter(0),
374
									viewPort.getAdjustedExtent().getCenter(1),
375
									SUBTYPES.GEOM2D
376
							)
377
					);
378
					double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
379
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
380
							"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
381
							size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
382
				}
383

  
384
			}
385
		}
386
	}
387

  
388

  
389
	public void testKilometersUnits_MapReferenceSystem() throws Exception {
390
		for (int j = 0; j < csSymbols.size(); j++) {
391
			CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
392
			MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
393
			ViewPort viewPort = mc.getViewPort();
394

  
395
			int unit = 0;
396
			Dimension dim = new Dimension(60, 60);
397
			viewPort.setImageSize(dim);
398

  
399

  
400
			/*
401
			 * will test with several extents but in the same map image size, so
402
			 * the scale issue is exercised as well.
403
			 */
404
			for (int i = 0; i < zooms.length; i++) {
405
				Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
406

  
407
				viewPort.setMapUnits(unit);
408
				viewPort.setEnvelope(extent);
409

  
410

  
411
				String name = ((IPersistence) symbol).getClassName().substring(
412
						((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
413
						((IPersistence) symbol).getClassName().length());
414

  
415
				CartographicSupport csSym = (CartographicSupport) symbol;
416
				csSym.setReferenceSystem(CartographicSupport.WORLD);
417
				double size = 30;
418

  
419
				csSym.setUnit(unit);
420

  
421

  
422

  
423

  
424
				if (symbol instanceof IMarkerSymbol) {
425

  
426
					IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
427
					markerSym.setSize(size);
428
					csSym.toCartographicSize(
429
							viewPort,
430
							CompatLocator.getGraphicsUtils().getScreenDPI(),
431
							geomManager.createPoint(
432
									viewPort.getAdjustedExtent().getCenter(0),
433
									viewPort.getAdjustedExtent().getCenter(1),
434
									SUBTYPES.GEOM2D
435
							)
436
					);
437
					double mySize = markerSym.getSize();
438
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
439
							"It returned "+markerSym.getSize()+" when expecting "+
440
							size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
441
				}
442

  
443
				if (symbol instanceof ILineSymbol) {
444

  
445
					ILineSymbol lineSym = (ILineSymbol) symbol;
446
					lineSym.setLineWidth(size);
447
					csSym.toCartographicSize(
448
							viewPort,
449
							CompatLocator.getGraphicsUtils().getScreenDPI(),
450
							geomManager.createPoint(
451
									viewPort.getAdjustedExtent().getCenter(0),
452
									viewPort.getAdjustedExtent().getCenter(1),
453
									SUBTYPES.GEOM2D								
454
							)
455
					);
456
					double mySize = lineSym.getLineStyle().getLineWidth();
457
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
458
							"It returned "+lineSym.getLineWidth()+" when expecting "+
459
							size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
460
				}
461

  
462
				if (symbol instanceof IFillSymbol) {
463
					// this tests if symbol applies the cartographic support to its
464
					// outline, since is the only thing that may be resized
465
					IFillSymbol fillSym = (IFillSymbol) symbol;
466
					if (fillSym.getOutline() == null) {
467
						fillSym.setOutline((ILineSymbol) manager.createSymbol(
468
										ILineSymbol.SYMBOL_NAME));
469
					}
470

  
471
					fillSym.getOutline().setLineWidth(size);
472

  
473
					csSym.toCartographicSize(
474
							viewPort,
475
							CompatLocator.getGraphicsUtils().getScreenDPI(),
476
							geomManager.createPoint(
477
									viewPort.getAdjustedExtent().getCenter(0),
478
									viewPort.getAdjustedExtent().getCenter(1),
479
									SUBTYPES.GEOM2D
480
							)
481
					);
482
					double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
483
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
484
							"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
485
							size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
486
				}
487

  
488
			}
489
		}
490

  
491
	}
492

  
493
	public void testMapInKilometersSymbolInMeters_MapReferenceSystem() throws Exception {
494
		for (int j = 0; j < csSymbols.size(); j++) {
495
			CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
496

  
497
			MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
498
			ViewPort viewPort = mc.getViewPort();
499

  
500
			int mapUnit = 0;
501
			int symbolUnit = 1;
502
			Dimension dim = new Dimension(60, 60);
503
			viewPort.setImageSize(dim);
504

  
505

  
506
			/*
507
			 * will test with several extents but in the same map image size, so
508
			 * the scale issue is exercised as well.
509
			 */
510
			for (int i = 0; i < zooms.length; i++) {
511
				Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
512
				viewPort.setMapUnits(mapUnit);
513
				viewPort.setEnvelope(extent);
514
				double size = 30;
515

  
516

  
517
				String name = ((IPersistence) symbol).getClassName().substring(
518
						((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
519
						((IPersistence) symbol).getClassName().length());
520

  
521

  
522
				CartographicSupport csSym = (CartographicSupport) symbol;
523
				csSym.setReferenceSystem(CartographicSupport.WORLD);
524

  
525
				csSym.setUnit(symbolUnit);
526

  
527
				if (symbol instanceof IMarkerSymbol) {
528

  
529
					IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
530
					markerSym.setSize(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km
531
					csSym.toCartographicSize(
532
							viewPort,
533
							CompatLocator.getGraphicsUtils().getScreenDPI(),
534
							geomManager.createPoint(
535
									viewPort.getAdjustedExtent().getCenter(0),
536
									viewPort.getAdjustedExtent().getCenter(1),
537
									SUBTYPES.GEOM2D
538
							)
539
					);
540
					double mySize = markerSym.getSize();
541
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
542
							"It returned "+markerSym.getSize()+" when expecting "+
543
							size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
544
				}
545

  
546
				if (symbol instanceof ILineSymbol) {
547

  
548
					ILineSymbol lineSym = (ILineSymbol) symbol;
549
					lineSym.setLineWidth(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km
550
					csSym.toCartographicSize(
551
							viewPort,
552
							CompatLocator.getGraphicsUtils().getScreenDPI(),
553
							geomManager.createPoint(
554
									viewPort.getAdjustedExtent().getCenter(0),
555
									viewPort.getAdjustedExtent().getCenter(1),
556
									SUBTYPES.GEOM2D
557
							)
558
					);
559
					double mySize = lineSym.getLineStyle().getLineWidth();
560
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
561
							"It returned "+lineSym.getLineWidth()+" when expecting "+
562
							size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
563
				}
564

  
565
				if (symbol instanceof IFillSymbol) {
566
					// this tests if symbol applies the cartographic support to its
567
					// outline, since is the only thing that may be resized
568
					IFillSymbol fillSym = (IFillSymbol) symbol;
569
					if (fillSym.getOutline() == null) {
570
						fillSym.setOutline((ILineSymbol) manager.createSymbol(
571
										ILineSymbol.SYMBOL_NAME));
572
					}
573

  
574
					fillSym.getOutline().setLineWidth(size*MapContext.CHANGEM[mapUnit]);
575

  
576
					csSym.toCartographicSize(
577
							viewPort,
578
							CompatLocator.getGraphicsUtils().getScreenDPI(),
579
							geomManager.createPoint(
580
									viewPort.getAdjustedExtent().getCenter(0),
581
									viewPort.getAdjustedExtent().getCenter(1),
582
									SUBTYPES.GEOM2D
583
							)
584
					);
585
					double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
586
					assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
587
							"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
588
							size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
589
				}
590

  
591
			}
592
		}
593
	}
594

  
595
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleMarkerSymbolTest.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
42

  
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
44

  
45
public class SimpleMarkerSymbolTest extends AbstractSymbolTestCase{
46
	public SimpleMarkerSymbolTest() {
47
		super(SimpleMarkerSymbol.class);
48
	}
49
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawMarkers.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
42

  
43
import java.awt.Color;
44
import java.awt.Dimension;
45
import java.awt.Graphics2D;
46
import java.awt.Rectangle;
47
import java.awt.geom.AffineTransform;
48
import java.awt.geom.Point2D;
49
import java.awt.image.BufferedImage;
50
import java.util.ArrayList;
51
import java.util.Random;
52

  
53
import org.gvsig.compat.CompatLocator;
54
import org.gvsig.fmap.geom.GeometryLocator;
55
import org.gvsig.fmap.geom.GeometryManager;
56
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
57
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
59
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
60
import org.slf4j.Logger;
61
import org.slf4j.LoggerFactory;
62

  
63
/**
64
 * Integration test to test that Marker symbols always draw in the same
65
 * place respecting size constraints.
66
 *
67
 * @author jaume dominguez faus - jaume.dominguez@iver.es
68
 */
69
public class TestDrawMarkers extends AbstractLibraryAutoInitTestCase {
70
	private GeometryManager geomManager;
71
	private static final Logger logger = LoggerFactory.getLogger(TestDrawMarkers.class);
72
	private IMarkerSymbol[] symbols;
73
	private final Dimension sz = new Dimension(400, 400);
74
	private org.gvsig.fmap.geom.primitive.Point centerP = null;
75
	private static final int OUTTER_TOLERANCE = 1;
76
	private static final int INNER_TOLERANCE = 1;
77

  
78
	private static final double sizes[] = new double[] {
79
		200,
80
		100,
81
		50,
82
		30,
83
		16,
84
		5,
85
		3,
86
		2,
87
		// smaller sizes don't make any sense
88

  
89
	};
90

  
91
	protected void doSetUp() throws Exception {
92
		geomManager = GeometryLocator.getGeometryManager();
93

  
94
		centerP = geomManager.createPoint(sz.width/2, sz.height/2, SUBTYPES.GEOM2D);
95
		
96
		ISymbol[] allSymbols = TestISymbol.getNewSymbolInstances();
97
		// Filter the marker ones
98
		ArrayList symbols = new ArrayList();
99

  
100
		for (int i = 0; i < allSymbols.length; i++) {
101
			if (allSymbols[i] instanceof IMarkerSymbol) {
102
				IMarkerSymbol sym = (IMarkerSymbol) allSymbols[i];
103
				symbols.add(sym);
104

  
105
			}
106
		}
107
		this.symbols = (IMarkerSymbol[]) symbols.toArray(new IMarkerSymbol[symbols.size()]);
108
	}
109

  
110
	public void testDrawingSize() {
111
		for (int i = 0; i < symbols.length; i++) {
112
			for (int j = 0; j < sizes.length; j++) {
113
				// new blank buffered image
114
				BufferedImage bi = CompatLocator.getGraphicsUtils().createBufferedImage(sz.width, sz.height, BufferedImage.TYPE_INT_ARGB);
115

  
116
				// the graphics for the image, so we can draw onto the buffered image
117
				Graphics2D g = bi.createGraphics();
118

  
119
				IMarkerSymbol testSymbol = symbols[i];
120
				testSymbol.setColor(Color.YELLOW);
121
				testSymbol.setSize(sizes[j]);
122
				String name = testSymbol.getClass().getName().substring(
123
						testSymbol.getClass().getName().lastIndexOf('.')+1,
124
						testSymbol.getClass().getName().length());
125

  
126
				testSymbol.draw(g, new AffineTransform(), centerP, null, null);
127

  
128
				Rectangle wrappingRect = new Rectangle(
129
						(int) (centerP.getX()-sizes[j]/2),
130
						(int) (centerP.getY()-sizes[j]/2),
131
						(int) (sizes[j]),
132
						(int) (sizes[j]));
133

  
134
//				if (testSymbol instanceof CharacterMarkerSymbol)
135
//					continue;
136

  
137

  
138

  
139

  
140
				assertFalse("fails sizing marker, too big ("+name+", "+sizes[j]+"px)", isOutsideRect(bi, wrappingRect, OUTTER_TOLERANCE ));
141
				assertTrue("fails sizing marker, too small ("+name+", "+sizes[j]+"px) \n" +
142
						"\t - forgot to enable ANTIALIASING?", fitsInsideRect(bi, wrappingRect, INNER_TOLERANCE));
143

  
144

  
145
			}
146
		}
147
	}
148

  
149
	public void testDrawingOffset() {
150
		// TODO: uncomment this test and make it run successfully
151
//		Random random = new Random(System.currentTimeMillis());
152
//		for (int i = 0; i < symbols.length; i++) {
153
//			for (int j = 0; j < sizes.length; j++) {
154
//				// new blank buffered image
155
//				BufferedImage bi = CompatLocator.getGraphicsUtils().createBufferedImage(sz.width, sz.height, BufferedImage.TYPE_INT_ARGB);
156
//
157
//
158
//				// the graphics for the image, so we can draw onto the buffered image
159
//				Graphics2D g = bi.createGraphics();
160
//
161
//				IMarkerSymbol testSymbol = symbols[i];
162
//				testSymbol.setColor(Color.YELLOW);
163
//				testSymbol.setSize(sizes[j]);
164
//
165
//				String name = testSymbol.getClass().getName().substring(
166
//						testSymbol.getClass().getName().lastIndexOf('.')+1,
167
//						testSymbol.getClass().getName().length());
168
//
169
//				double xOffset = (random.nextDouble()-0.5)*sz.width;
170
//				double yOffset = (random.nextDouble()-0.5)*sz.height;
171
//
172
//				testSymbol.setOffset(new Point2D.Double(xOffset, yOffset));
173
//
174
//				Rectangle wrappingRect = new Rectangle(
175
//						(int) ((centerP.getX()-sizes[j]/2) + xOffset),
176
//						(int) ((centerP.getY()-sizes[j]/2) + yOffset),
177
//						(int) (sizes[j]),
178
//						(int) (sizes[j]));
179
//
180
////				if (testSymbol instanceof CharacterMarkerSymbol)
181
////					continue;
182
//
183
//
184
//
185
//				testSymbol.draw(g, new AffineTransform(), centerP, null, null);
186
//				assertFalse("fails sizing marker, too big ("+name+", "+sizes[j]+"px)", isOutsideRect(bi, wrappingRect, OUTTER_TOLERANCE ));
187
//				assertTrue("fails sizing marker, too small ("+name+", "+sizes[j]+"px) \n" +
188
//						"\t - forgot to enable ANTIALIASING?", fitsInsideRect(bi, wrappingRect, INNER_TOLERANCE));
189
//
190
//			}
191
//		}
192
	}
193

  
194
	public void testDrawingRotation() {
195
		// TODO implement it
196

  
197
	}
198

  
199
	private boolean fitsInsideRect(BufferedImage bi, Rectangle wrappingRect, int tolerance) {
200
		int myTolerance = Math.min(tolerance, wrappingRect.width);
201
		Rectangle myRect;
202
		if (myTolerance >= INNER_TOLERANCE) {
203
			myRect = new Rectangle(
204
					wrappingRect.x+myTolerance,
205
					wrappingRect.y+myTolerance,
206
					wrappingRect.width-myTolerance-myTolerance,
207
					wrappingRect.height-myTolerance-myTolerance);
208
		} else {
209
			myRect = new Rectangle(-1, -1, 0, 0); // just ensure it does not disturb the check
210
		}
211

  
212
		for (int i = 0; i < bi.getWidth(); i++) {
213
			for (int j = 0; j < bi.getHeight(); j++) {
214
				if (wrappingRect.contains(i,j)
215
						&& !myRect.contains(i,j)) {
216

  
217
					if (bi.getRGB(i,j) != 0)
218
						return true;
219
				}
220
			}
221
		}
222
		return false;
223
	}
224

  
225
	private boolean isOutsideRect(BufferedImage bi, Rectangle wrappingRect, int tolerance) {
226
		Rectangle myRect = new Rectangle(
227
				wrappingRect.x-tolerance,
228
				wrappingRect.y-tolerance,
229
				wrappingRect.width+tolerance+tolerance,
230
				wrappingRect.height+tolerance+tolerance);
231
		for (int i = 0; i < bi.getWidth(); i++) {
232
			for (int j = 0; j < bi.getHeight(); j++) {
233
				if (!myRect.contains(i,j))
234
					continue;
235

  
236
				if (bi.getRGB(i,j) != 0) return false;
237
			}
238
		}
239
		return true;
240
	}
241
}
242

  
243
/// paste this piece of code to produce some png files to check visually what is happening
244
//g.setColor(Color.BLUE);
245
//Rectangle myRect = new Rectangle(
246
//		wrappingRect.x+INNER_TOLERANCE,
247
//		wrappingRect.y+INNER_TOLERANCE,
248
//		wrappingRect.width-INNER_TOLERANCE-INNER_TOLERANCE,
249
//		wrappingRect.height-INNER_TOLERANCE-INNER_TOLERANCE);
250
//
251
//g.draw(myRect);
252
//g.setColor(Color.RED);
253
//g.draw(wrappingRect);
254
//try {
255
//
256
//	File dstDir = new File (System.getProperty("java.io.tmpdir")+"/prova-imatges/");
257
//	if (!dstDir.exists()) dstDir.mkdir();
258
//	ImageIO.write(bi, "png",
259
//			new File(dstDir.getAbsoluteFile()+File.separator+
260
//					name+"_size_"+sizes[j]
261
//					                    +".png"));
262
//} catch (IOException e) {
263
//	e.printStackTrace();
264
//	fail();
265
//}
266
///
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/IDrawFillSymbol.java
1
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
2

  
3
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
4

  
5
public interface IDrawFillSymbol {
6

  
7
	IFillSymbol makeSymbolTransparent(IFillSymbol newSymbol);
8

  
9
	boolean isSuitableFor(IFillSymbol newSymbol);
10

  
11
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleTextSymbolTest.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
42

  
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
44

  
45
public class SimpleTextSymbolTest extends AbstractSymbolTestCase{
46
	public SimpleTextSymbolTest() {
47
		super(SimpleTextSymbol.class);
48
	}
49
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/AbstractSymbolTestCase.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
42

  
43
import junit.framework.TestCase;
44

  
45
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
46

  
47

  
48
public abstract class AbstractSymbolTestCase extends TestCase {
49
	protected Class symClazz;
50

  
51
	public AbstractSymbolTestCase(Class symClazz) {
52
		this.symClazz = symClazz;
53
	}
54

  
55
	public ISymbol newInstance() {
56
		try {
57
			return (ISymbol) symClazz.newInstance();
58
		} catch (Exception e) {
59
			fail("Failed installing symbol to test "+symClazz.getName());
60
			return null;
61
		}
62
	}
63
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleFillSymbolTest.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
42

  
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
44

  
45
public class SimpleFillSymbolTest extends AbstractSymbolTestCase{
46
	public SimpleFillSymbolTest() {
47
		super(SimpleFillSymbol.class);
48
	}
49
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleLineSymbolTest.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
42

  
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
44

  
45
public class SimpleLineSymbolTest extends AbstractSymbolTestCase{
46
	public SimpleLineSymbolTest() {
47
		super(SimpleLineSymbol.class);
48
	}
49
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawFills.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol;
42

  
43
import java.awt.Dimension;
44
import java.awt.Graphics2D;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Point2D;
47
import java.awt.image.BufferedImage;
48
import java.io.File;
49
import java.io.IOException;
50
import java.util.ArrayList;
51

  
52
import javax.imageio.ImageIO;
53

  
54
import junit.framework.TestCase;
55

  
56
import org.gvsig.compat.CompatLocator;
57
import org.gvsig.fmap.geom.Geometry;
58
import org.gvsig.fmap.geom.GeometryLocator;
59
import org.gvsig.fmap.geom.GeometryManager;
60
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
61
import org.gvsig.fmap.geom.exception.CreateGeometryException;
62
import org.gvsig.fmap.geom.primitive.GeneralPathX;
63
import org.gvsig.fmap.mapcontext.MapContext;
64
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.AllTests;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
67
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
68
import org.slf4j.Logger;
69
import org.slf4j.LoggerFactory;
70

  
71

  
72
/**
73
 * Integration test to test that Fill symbols always draw in the same
74
 * place respecting size constraints.
75
 *
76
 * @author jaume dominguez faus - jaume.dominguez@iver.es
77
 */
78
public class TestDrawFills extends AbstractLibraryAutoInitTestCase {
79
	private GeometryManager geomManager;
80
	private static final Logger logger = LoggerFactory.getLogger(TestDrawFills.class);
81
	private final Dimension sz = new Dimension(400, 400);
82
	private org.gvsig.fmap.geom.primitive.Point centerP = null;
83
	private static final int OUTTER_TOLERANCE = 1;
84
	private static final int INNER_TOLERANCE = 1;
85
	private IFillSymbol[] symbols;
86
	private IDrawFillSymbol[] drawFillSymbols;
87
	private static ArrayList classesToTest;
88

  
89
	private static final double sizes[] = new double[] {
90
		200,
91
		100,
92
		50,
93
		30,
94
		16,
95
		5,
96
		3,
97
		2,
98
		// smaller sizes don't make any sense
99

  
100
	};
101

  
102

  
103
	private static ArrayList getClassesToTest() {
104
		if (classesToTest == null) {
105
			classesToTest = new ArrayList();
106
//			TestDrawFills.addSymbolToTest(DrawLineFillSymbol.class);
107
//			TestDrawFills.addSymbolToTest(DrawPictureFillSymbol.class);
108
		}
109

  
110
		return classesToTest;
111
	}
112

  
113
	public static void addSymbolToTest(Class symbolClass) {
114
        try {
115
            IDrawFillSymbol sym = (IDrawFillSymbol) symbolClass.newInstance();
116
        } catch (InstantiationException e) {
117
            // TODO Auto-generated catch block
118
            fail("Instantiating class, cannot test a non-instantiable symbol");
119
        } catch (IllegalAccessException e) {
120
            // TODO Auto-generated catch block
121
            fail("Class not instantiable");
122
        } catch (ClassCastException ccEx) {
123
            fail("Cannot test a non symbol class");
124
        }
125
        getClassesToTest().add(symbolClass);
126
    }
127

  
128
	protected void doSetUp() throws Exception {
129
		geomManager = GeometryLocator.getGeometryManager();
130
		centerP = geomManager.createPoint(sz.width/2, sz.height/2, SUBTYPES.GEOM2D);
131
		
132
		this.drawFillSymbols = new IDrawFillSymbol[getClassesToTest().size()];
133

  
134
		for (int i = 0; i < drawFillSymbols.length; i++) {
135
			drawFillSymbols[i] = (IDrawFillSymbol) ((Class) getClassesToTest().get(i)).newInstance();
136
		}
137

  
138
		TestISymbol.addSymbols();
139
		ISymbol[] allSymbols = TestISymbol.getNewSymbolInstances();
140
		// Filter the marker ones
141
		ArrayList symbols = new ArrayList();
142

  
143
		for (int i = 0; i < allSymbols.length; i++) {
144
			if (allSymbols[i] instanceof IFillSymbol) {
145
				IFillSymbol sym = (IFillSymbol) allSymbols[i];
146
				symbols.add(sym);
147

  
148
			}
149
		}
150
		this.symbols = (IFillSymbol[]) symbols.toArray(new IFillSymbol[symbols.size()]);
151

  
152

  
153

  
154
	}
155

  
156
	public void testDraw() {
157
		MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
158

  
159
	}
160

  
161

  
162
	public final void testNullColorAvoidsFilling() throws CreateGeometryException {
163

  
164
		for (int i = 0; i < symbols.length; i++) {
165

  
166
			for (int s = 0; s < sizes.length; s++) {
167

  
168
				BufferedImage bi = CompatLocator.getGraphicsUtils().createBufferedImage(sz.width,sz.height, BufferedImage.TYPE_INT_ARGB);
169
				// the graphics for the image, so we can draw onto the buffered image
170
				Graphics2D g = bi.createGraphics();
171

  
172
				IFillSymbol newSymbol = symbols[i];
173
				newSymbol.setFillColor(null);
174
				newSymbol.setOutline(null);
175

  
176

  
177

  
178

  
179
				String name = newSymbol.getClass().getName().substring(
180
						newSymbol.getClass().getName().lastIndexOf('.')+1,
181
						newSymbol.getClass().getName().length());
182

  
183

  
184
				Point2D firstPoint = new Point2D.Float((float)(centerP.getX()-sizes[s]/2-3),(float)(centerP.getY()-sizes[s]/2-3));
185
				Point2D lastPoint = new Point2D.Float((float)(centerP.getX()+sizes[s]/2+3),(float)(centerP.getY()+sizes[s]/2+3));
186

  
187

  
188

  
189
				GeneralPathX gpx = new GeneralPathX();
190

  
191
				gpx.moveTo((float)firstPoint.getX(),(float) firstPoint.getY());
192
				gpx.lineTo((float)lastPoint.getX(),(float) firstPoint.getY());
193
				gpx.lineTo((float)lastPoint.getX(),(float) lastPoint.getY());
194
				gpx.lineTo((float)firstPoint.getX(),(float) lastPoint.getY());
195
				gpx.lineTo((float)firstPoint.getX(), (float)firstPoint.getY());
196
				gpx.closePath();
197

  
198

  
199
				for (int j = 0; j < drawFillSymbols.length; j++) {
200
					if (drawFillSymbols[j].isSuitableFor(newSymbol)) {
201
						newSymbol = drawFillSymbols[j].makeSymbolTransparent(newSymbol);
202
						break;
203
					}
204
				}
205

  
206

  
207
				newSymbol.draw(g, new AffineTransform(), geomManager.createSurface(gpx, SUBTYPES.GEOM2D), null, null);
208

  
209
				try {
210

  
211
					File dstDir = new File (System.getProperty("java.io.tmpdir")+"/prova-imatges/");
212
					if (!dstDir.exists()) dstDir.mkdir();
213
					ImageIO.write(bi, "png",
214
							new File(dstDir.getAbsoluteFile()+File.separator+
215
									name+"_size_"+sizes[s]
216
									                    +".png"));
217
				} catch (IOException e) {
218
					e.printStackTrace();
219
					fail();
220
				}
221

  
222
				for (int j = 0; j < bi.getWidth(); j++) {
223
					for (int k = 0; k < bi.getHeight(); k++) {
224
						if (isInsideShape(geomManager.createSurface(gpx, SUBTYPES.GEOM2D), j, k)) {
225
							assertEquals("Failed, the fill is being painted when the color is null",bi.getRGB(j, k),0);
226

  
227
						}
228
					}
229

  
230
				}
231
			}
232
		}
233
	}
234

  
235

  
236
	private boolean isInsideShape(Geometry geom, int x, int y) {
237
		Point2D p = new Point2D.Float(x,y);
238
		if(geom.contains(p))return true;
239
		return false;
240
	}
241

  
242

  
243
}
tags/v2_0_0_Build_2010/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawLines.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff