Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / test / java / org / gvsig / symbology / fmap / mapcontext / rendering / TestCartographicSupportForSymbol.java @ 30754

History | View | Annotate | Download (21.7 KB)

1 30010 cordinyana
/* 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 junit.framework.TestCase;
49
50
import org.gvsig.compat.CompatLocator;
51
import org.gvsig.fmap.geom.GeometryLocator;
52
import org.gvsig.fmap.geom.GeometryManager;
53
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
54
import org.gvsig.fmap.geom.exception.CreateGeometryException;
55
import org.gvsig.fmap.geom.primitive.Envelope;
56
import org.gvsig.fmap.geom.primitive.Point;
57
import org.gvsig.fmap.mapcontext.MapContext;
58
import org.gvsig.fmap.mapcontext.MapContextLocator;
59
import org.gvsig.fmap.mapcontext.ViewPort;
60
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
61
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
62 30580 cordinyana
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.AbstractSymbolTestCase;
63 30010 cordinyana
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleFillSymbolTest;
64
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleLineSymbolTest;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleMarkerSymbolTest;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
67
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
68
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
69 30754 cordinyana
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
70 30010 cordinyana
import org.gvsig.utils.IPersistence;
71
import org.gvsig.utils.NotExistInXMLEntity;
72
import org.gvsig.utils.XMLEntity;
73
import org.gvsig.utils.XMLException;
74
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
76
77
78
/**
79
 *
80
 * @author jaume dominguez faus - jaume.dominguez@iver.es
81
 */
82 30754 cordinyana
public class TestCartographicSupportForSymbol extends AbstractLibraryAutoInitTestCase {
83
        private static GeometryManager geomManager;
84 30010 cordinyana
        private static final Logger logger = LoggerFactory.getLogger(TestCartographicSupportForSymbol.class);
85
86
        /**
87
         * Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:23030</b>
88
         */
89
        public static Point valenciaUTM30 = null;
90
91
        /**
92
         * Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:4326</b>
93
         */
94
        public static Point valenciaGeo = null;
95
        /**
96
         * Extent that covers the whole Comunitat Valenciana in  <b>EPSG:23030</b>
97
         */
98
        public static final Rectangle2D TEST_UTM30_EXTENT = new Rectangle2D.Double();
99
        {
100
                TEST_UTM30_EXTENT.setFrameFromDiagonal(
101
                                4191037.369934333,
102
                                626674.7454557443,
103
104
                                4519266.460824658,
105
                                797903.2656794232
106
                );
107
        }
108
        /**
109
         * Extent that covers the whole Comunitat Valenciana in  <b>EPSG:4326</b>
110
         */
111
112
        public static final Rectangle2D TEST_GEO_EXTENT = new Rectangle2D.Double();
113
        {
114
                TEST_GEO_EXTENT.setFrameFromDiagonal(
115
116
                                -  (1 + (31/60) + (28.09/3600)),        // Western egde
117
                                37 + (50/60) + (48.05/3600),                // Southern edge
118
119
                                0 + (31/60) + (1.85/3600),                // Eastern edge
120
                                40 + (47/60) + (21.36/3600)                // Northern edge
121
122
                );
123
        }
124
125
        public static final Rectangle2D TEST_EXTENT = new Rectangle2D.Double(
126
                        4191037.369934333,
127
                        626674.7454557443,
128
129
                        4519266.460824658 - 4191037.369934333,
130
                        797903.2656794232 -  626674.7454557443
131
        );
132
        private static ArrayList symbolsToTest; //<AbstractSymbolTestCase>
133
        private ArrayList csSymbols; //<CartographicSupport>
134
135
        /**
136
         * Acceptable pixel tolerance error. 1 pixel of error is accetable since it is probably due to
137
         * the java.awt.Graphics
138
         */
139
        private static final double TOL = 1;
140
141
        double zooms[] = new double[] {
142
                        1,
143
                        2,
144
                        1.2,
145
                        10,
146
                        0.5
147
        };
148
149 30754 cordinyana
        protected void doSetUp() throws Exception {
150
                geomManager = GeometryLocator.getGeometryManager();
151 30010 cordinyana
                try {
152
                        valenciaUTM30 = geomManager.createPoint(725846.080, 4373022.720, SUBTYPES.GEOM2D);
153
                        valenciaGeo = geomManager.createPoint(- (0+ 22/60 +  27.919/3600), 39 + 28/60 + 35.4276/3600, SUBTYPES.GEOM2D);
154
                } catch (CreateGeometryException e) {
155
                        // TODO Auto-generated catch block
156
                        e.printStackTrace();
157
                }
158
159
                addSymbolTest(new SimpleFillSymbolTest());
160
                addSymbolTest(new SimpleLineSymbolTest());
161
                addSymbolTest(new SimpleMarkerSymbolTest());
162
163
                init();
164
        }
165
166
        protected void init() {
167
168
                // take the symbols added to the TestISymbol test
169
                ISymbol[] symbols = getNewSymbolInstances();
170
171
                csSymbols = new ArrayList(); //<CartographicSupport>
172
                for (int i = 0; i < symbols.length; i++) {
173
                        if (symbols[i] instanceof CartographicSupport) {
174
                                csSymbols.add((CartographicSupport) symbols[i]);
175
                        }
176
                }
177
        }
178
179
        public static void addSymbolTest(AbstractSymbolTestCase symbolTestClass) {
180
                if (symbolsToTest == null) symbolsToTest = new ArrayList(); //<AbstractSymbolTestCase>
181
                symbolsToTest.add(symbolTestClass);
182
        }
183
184
        public static ISymbol[] getNewSymbolInstances() {
185
                ISymbol[] symbols = new ISymbol[symbolsToTest.size()];
186
                for (int i = 0; i < symbols.length; i++) {
187
                        symbols[i] = (ISymbol)((AbstractSymbolTestCase)symbolsToTest.get(i)).newInstance();
188
                }
189
                return symbols;
190
        }
191
192
193
        public void testSymbolUnitDefinition() {
194
                for (int i = 0; i < csSymbols.size(); i++) {
195
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(i);
196
197
                        int aRandomUnit = new Random().nextInt(7);
198
199
200
                        symbol.setUnit(aRandomUnit);
201
                        XMLEntity xml=null;
202
                        try {
203
                                xml = ((IPersistence) symbol).getXMLEntity();
204
                        } catch (XMLException e) {
205
                                // TODO Auto-generated catch block
206
                                e.printStackTrace();
207
                        }
208
                        String name = symbol.getClass().getName().substring(
209
                                        symbol.getClass().getName().lastIndexOf('.')+1,
210
                                        symbol.getClass().getName().length());
211
212
                        try {
213 30287 jpiera
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
214 30010 cordinyana
                                                symbol.getUnit() == xml.getIntProperty("unit"));
215
                        } catch (NotExistInXMLEntity neiXMLEx) {
216 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
217 30010 cordinyana
                        }
218
                        symbol.setUnit(5);
219
                        try {
220 30287 jpiera
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getUnit()== 5);
221
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
222 30010 cordinyana
                                                5 == ((IPersistence) symbol).getXMLEntity().getIntProperty("unit"));
223
                        } catch (NotExistInXMLEntity neiXMLEx) {
224 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
225 30010 cordinyana
                        } catch (XMLException e) {
226 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
227 30010 cordinyana
                        }
228
229
//                        xml.putProperty("unit", 3);
230
//                        ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
231
//                        assertTrue("The application of the UNIT value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getUnit() == 3);
232
                }
233
234
        }
235
236
237
        public void testSymbolReferenceSystemDefinition() {
238
                for (int i = 0; i < csSymbols.size(); i++) {
239
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(i);
240
                        XMLEntity xml=null;
241
                        try {
242
                                xml = ((IPersistence) symbol).getXMLEntity();
243
                        } catch (XMLException e) {
244
                                // TODO Auto-generated catch block
245
                                e.printStackTrace();
246
                        }
247
                        String name = symbol.getClass().getName().substring(
248
                                        symbol.getClass().getName().lastIndexOf('.')+1,
249
                                        symbol.getClass().getName().length());
250
                        try {
251 30287 jpiera
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
252 30010 cordinyana
                                                symbol.getReferenceSystem() == xml.getIntProperty("referenceSystem"));
253
                        } catch (NotExistInXMLEntity neiXMLEx) {
254 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
255 30010 cordinyana
                        }
256
                        symbol.setReferenceSystem(CartographicSupport.PAPER);
257
                        try {
258 30287 jpiera
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.PAPER);
259
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly",
260 30010 cordinyana
                                                CartographicSupport.PAPER == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
261
                        } catch (NotExistInXMLEntity neiXMLEx) {
262 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")");
263 30010 cordinyana
                        } catch (XMLException e) {
264 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")");
265 30010 cordinyana
                        }
266
267
                        symbol.setReferenceSystem(CartographicSupport.WORLD);
268
                        try {
269 30287 jpiera
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.WORLD);
270
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly",
271 30010 cordinyana
                                                CartographicSupport.WORLD == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
272
                        } catch (NotExistInXMLEntity neiXMLEx) {
273 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
274 30010 cordinyana
                        } catch (XMLException e) {
275 30287 jpiera
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
276 30010 cordinyana
                        }
277
278
//                        xml.putProperty("referenceSystem", CartographicSupport.PAPER);
279
//                        ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
280
//                        assertTrue("The application of the REFERENCE SYSTEM value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getReferenceSystem() == CartographicSupport.PAPER);
281
                }
282
        }
283
284
285
        public void testDegreesUnits_MapReferenceSystem() throws Exception {
286
                for (int j = 0; j < csSymbols.size(); j++) {
287
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
288
289
                        MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_PROJECTION);
290
                        ViewPort viewPort = mc.getViewPort();
291
292
                        int unit = 8;
293
                        Dimension dim = new Dimension(600, 600);
294
                        viewPort.setImageSize(dim);
295
296
297
                        /*
298
                         * will test with several extents but in the same map image size, so
299
                         * the scale issue is exercised as well.
300
                         */
301
                        for (int i = 0; i < zooms.length; i++) {
302
                                Envelope extent = geomManager.createEnvelope(-30, -30,dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
303
304
                                viewPort.setMapUnits(unit);
305
                                viewPort.setEnvelope(extent);
306
307
308
                                String name = ((IPersistence) symbol).getClassName().substring(
309
                                                ((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
310
                                                ((IPersistence) symbol).getClassName().length());
311
312
                                CartographicSupport csSym = (CartographicSupport) symbol;
313
                                csSym.setReferenceSystem(CartographicSupport.WORLD);
314
                                double size = 30;
315
316
                                csSym.setUnit(unit);
317
318
319
320
                                if (symbol instanceof IMarkerSymbol) {
321
322
                                        IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
323
                                        markerSym.setSize(size);
324
                                        csSym.toCartographicSize(
325
                                                        viewPort,
326
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
327
                                                        geomManager.createPoint(
328
                                                                        viewPort.getAdjustedExtent().getCenter(0),
329
                                                                        viewPort.getAdjustedExtent().getCenter(1),
330
                                                                        SUBTYPES.GEOM2D
331
                                                        )
332
                                        );
333
                                        double mySize = markerSym.getSize();
334
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
335
                                                        "It returned "+markerSym.getSize()+" when expecting "+
336
                                                        size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
337
                                }
338
339
                                if (symbol instanceof ILineSymbol) {
340
341
                                        ILineSymbol lineSym = (ILineSymbol) symbol;
342
                                        lineSym.setLineWidth(size);
343
                                        csSym.toCartographicSize(
344
                                                        viewPort,
345
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
346
                                                        geomManager.createPoint(
347
                                                                        viewPort.getAdjustedExtent().getCenter(0),
348
                                                                        viewPort.getAdjustedExtent().getCenter(1),
349
                                                                        SUBTYPES.GEOM2D
350
                                                        )
351
                                        );
352
                                        double mySize = lineSym.getLineStyle().getLineWidth();
353
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
354
                                                        "It returned "+mySize+" when expecting "+
355
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
356
                                }
357
358
                                if (symbol instanceof IFillSymbol) {
359
                                        // this tests if symbol applies the cartographic support to its
360
                                        // outline, since is the only thing that may be resized
361
                                        IFillSymbol fillSym = (IFillSymbol) symbol;
362
                                        if (fillSym.getOutline() == null) {
363
                                                fillSym.setOutline((ILineSymbol) MapContextLocator
364
                                                                .getMapContextManager().createSymbol(
365
                                                                                ILineSymbol.SYMBOL_NAME));
366
                                        }
367
368
                                        fillSym.getOutline().setLineWidth(size);
369
370
                                        csSym.toCartographicSize(
371
                                                        viewPort,
372
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
373
                                                        geomManager.createPoint(
374
                                                                        viewPort.getAdjustedExtent().getCenter(0),
375
                                                                        viewPort.getAdjustedExtent().getCenter(1),
376
                                                                        SUBTYPES.GEOM2D
377
                                                        )
378
                                        );
379
                                        double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
380
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
381
                                                        "It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
382
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
383
                                }
384
385
                        }
386
                }
387
        }
388
389
390
        public void testKilometersUnits_MapReferenceSystem() throws Exception {
391
                for (int j = 0; j < csSymbols.size(); j++) {
392
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
393
                        MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
394
                        ViewPort viewPort = mc.getViewPort();
395
396
                        int unit = 0;
397
                        Dimension dim = new Dimension(60, 60);
398
                        viewPort.setImageSize(dim);
399
400
401
                        /*
402
                         * will test with several extents but in the same map image size, so
403
                         * the scale issue is exercised as well.
404
                         */
405
                        for (int i = 0; i < zooms.length; i++) {
406
                                Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
407
408
                                viewPort.setMapUnits(unit);
409
                                viewPort.setEnvelope(extent);
410
411
412
                                String name = ((IPersistence) symbol).getClassName().substring(
413
                                                ((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
414
                                                ((IPersistence) symbol).getClassName().length());
415
416
                                CartographicSupport csSym = (CartographicSupport) symbol;
417
                                csSym.setReferenceSystem(CartographicSupport.WORLD);
418
                                double size = 30;
419
420
                                csSym.setUnit(unit);
421
422
423
424
425
                                if (symbol instanceof IMarkerSymbol) {
426
427
                                        IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
428
                                        markerSym.setSize(size);
429
                                        csSym.toCartographicSize(
430
                                                        viewPort,
431
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
432
                                                        geomManager.createPoint(
433
                                                                        viewPort.getAdjustedExtent().getCenter(0),
434
                                                                        viewPort.getAdjustedExtent().getCenter(1),
435
                                                                        SUBTYPES.GEOM2D
436
                                                        )
437
                                        );
438
                                        double mySize = markerSym.getSize();
439
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
440
                                                        "It returned "+markerSym.getSize()+" when expecting "+
441
                                                        size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
442
                                }
443
444
                                if (symbol instanceof ILineSymbol) {
445
446
                                        ILineSymbol lineSym = (ILineSymbol) symbol;
447
                                        lineSym.setLineWidth(size);
448
                                        csSym.toCartographicSize(
449
                                                        viewPort,
450
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
451
                                                        geomManager.createPoint(
452
                                                                        viewPort.getAdjustedExtent().getCenter(0),
453
                                                                        viewPort.getAdjustedExtent().getCenter(1),
454
                                                                        SUBTYPES.GEOM2D
455
                                                        )
456
                                        );
457
                                        double mySize = lineSym.getLineStyle().getLineWidth();
458
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
459
                                                        "It returned "+lineSym.getLineWidth()+" when expecting "+
460
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
461
                                }
462
463
                                if (symbol instanceof IFillSymbol) {
464
                                        // this tests if symbol applies the cartographic support to its
465
                                        // outline, since is the only thing that may be resized
466
                                        IFillSymbol fillSym = (IFillSymbol) symbol;
467
                                        if (fillSym.getOutline() == null) {
468
                                                fillSym.setOutline((ILineSymbol) MapContextLocator
469
                                                                .getMapContextManager().createSymbol(
470
                                                                                ILineSymbol.SYMBOL_NAME));
471
                                        }
472
473
                                        fillSym.getOutline().setLineWidth(size);
474
475
                                        csSym.toCartographicSize(
476
                                                        viewPort,
477
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
478
                                                        geomManager.createPoint(
479
                                                                        viewPort.getAdjustedExtent().getCenter(0),
480
                                                                        viewPort.getAdjustedExtent().getCenter(1),
481
                                                                        SUBTYPES.GEOM2D
482
                                                        )
483
                                        );
484
                                        double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
485
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
486
                                                        "It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
487
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
488
                                }
489
490
                        }
491
                }
492
493
        }
494
495
        public void testMapInKilometersSymbolInMeters_MapReferenceSystem() throws Exception {
496
                for (int j = 0; j < csSymbols.size(); j++) {
497
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
498
499
                        MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
500
                        ViewPort viewPort = mc.getViewPort();
501
502
                        int mapUnit = 0;
503
                        int symbolUnit = 1;
504
                        Dimension dim = new Dimension(60, 60);
505
                        viewPort.setImageSize(dim);
506
507
508
                        /*
509
                         * will test with several extents but in the same map image size, so
510
                         * the scale issue is exercised as well.
511
                         */
512
                        for (int i = 0; i < zooms.length; i++) {
513
                                Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
514
                                viewPort.setMapUnits(mapUnit);
515
                                viewPort.setEnvelope(extent);
516
                                double size = 30;
517
518
519
                                String name = ((IPersistence) symbol).getClassName().substring(
520
                                                ((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
521
                                                ((IPersistence) symbol).getClassName().length());
522
523
524
                                CartographicSupport csSym = (CartographicSupport) symbol;
525
                                csSym.setReferenceSystem(CartographicSupport.WORLD);
526
527
                                csSym.setUnit(symbolUnit);
528
529
                                if (symbol instanceof IMarkerSymbol) {
530
531
                                        IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
532
                                        markerSym.setSize(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km
533
                                        csSym.toCartographicSize(
534
                                                        viewPort,
535
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
536
                                                        geomManager.createPoint(
537
                                                                        viewPort.getAdjustedExtent().getCenter(0),
538
                                                                        viewPort.getAdjustedExtent().getCenter(1),
539
                                                                        SUBTYPES.GEOM2D
540
                                                        )
541
                                        );
542
                                        double mySize = markerSym.getSize();
543
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
544
                                                        "It returned "+markerSym.getSize()+" when expecting "+
545
                                                        size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
546
                                }
547
548
                                if (symbol instanceof ILineSymbol) {
549
550
                                        ILineSymbol lineSym = (ILineSymbol) symbol;
551
                                        lineSym.setLineWidth(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km
552
                                        csSym.toCartographicSize(
553
                                                        viewPort,
554
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
555
                                                        geomManager.createPoint(
556
                                                                        viewPort.getAdjustedExtent().getCenter(0),
557
                                                                        viewPort.getAdjustedExtent().getCenter(1),
558
                                                                        SUBTYPES.GEOM2D
559
                                                        )
560
                                        );
561
                                        double mySize = lineSym.getLineStyle().getLineWidth();
562
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
563
                                                        "It returned "+lineSym.getLineWidth()+" when expecting "+
564
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
565
                                }
566
567
                                if (symbol instanceof IFillSymbol) {
568
                                        // this tests if symbol applies the cartographic support to its
569
                                        // outline, since is the only thing that may be resized
570
                                        IFillSymbol fillSym = (IFillSymbol) symbol;
571
                                        if (fillSym.getOutline() == null) {
572
                                                fillSym.setOutline((ILineSymbol) MapContextLocator
573
                                                                .getMapContextManager().createSymbol(
574
                                                                                ILineSymbol.SYMBOL_NAME));
575
                                        }
576
577
                                        fillSym.getOutline().setLineWidth(size*MapContext.CHANGEM[mapUnit]);
578
579
                                        csSym.toCartographicSize(
580
                                                        viewPort,
581
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
582
                                                        geomManager.createPoint(
583
                                                                        viewPort.getAdjustedExtent().getCenter(0),
584
                                                                        viewPort.getAdjustedExtent().getCenter(1),
585
                                                                        SUBTYPES.GEOM2D
586
                                                        )
587
                                        );
588
                                        double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
589
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
590
                                                        "It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
591
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
592
                                }
593
594
                        }
595
                }
596
        }
597
598
}