Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / test / java / org / gvsig / symbology / fmap / mapcontext / rendering / TestCartographicSupportForSymbol.java @ 40560

History | View | Annotate | Download (21.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.symbology.fmap.mapcontext.rendering;
25

    
26
import java.awt.Dimension;
27
import java.awt.geom.Rectangle2D;
28
import java.util.ArrayList;
29
import java.util.Random;
30

    
31
import org.gvsig.compat.CompatLocator;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.exception.CreateGeometryException;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.fmap.mapcontext.MapContextLocator;
40
import org.gvsig.fmap.mapcontext.ViewPort;
41
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
43
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.AbstractSymbolTestCase;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleFillSymbolTest;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleLineSymbolTest;
47
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.SimpleMarkerSymbolTest;
48
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
49
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
50
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
51
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
52
import org.gvsig.utils.IPersistence;
53
import org.gvsig.utils.NotExistInXMLEntity;
54
import org.gvsig.utils.XMLEntity;
55
import org.gvsig.utils.XMLException;
56
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
58

    
59

    
60
/**
61
 *
62
 * @author jaume dominguez faus - jaume.dominguez@iver.es
63
 */
64
public class TestCartographicSupportForSymbol extends AbstractLibraryAutoInitTestCase {
65
        private static GeometryManager geomManager;        
66
        private static final Logger logger = LoggerFactory.getLogger(TestCartographicSupportForSymbol.class);
67
        
68
        /**
69
         * Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:23030</b>
70
         */
71
        public static Point valenciaUTM30 = null;
72

    
73
        /**
74
         * Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:4326</b>
75
         */
76
        public static Point valenciaGeo = null;
77

    
78
        public SymbolManager manager = MapContextLocator.getSymbolManager();
79
        /**
80
         * Extent that covers the whole Comunitat Valenciana in  <b>EPSG:23030</b>
81
         */
82
        public static final Rectangle2D TEST_UTM30_EXTENT = new Rectangle2D.Double();
83
        {
84
                TEST_UTM30_EXTENT.setFrameFromDiagonal(
85
                                4191037.369934333,
86
                                626674.7454557443,
87

    
88
                                4519266.460824658,
89
                                797903.2656794232
90
                );
91
        }
92
        /**
93
         * Extent that covers the whole Comunitat Valenciana in  <b>EPSG:4326</b>
94
         */
95

    
96
        public static final Rectangle2D TEST_GEO_EXTENT = new Rectangle2D.Double();
97
        {
98
                TEST_GEO_EXTENT.setFrameFromDiagonal(
99

    
100
                                -  (1 + (31/60) + (28.09/3600)),        // Western egde
101
                                37 + (50/60) + (48.05/3600),                // Southern edge
102

    
103
                                0 + (31/60) + (1.85/3600),                // Eastern edge
104
                                40 + (47/60) + (21.36/3600)                // Northern edge
105

    
106
                );
107
        }
108

    
109
        public static final Rectangle2D TEST_EXTENT = new Rectangle2D.Double(
110
                        4191037.369934333,
111
                        626674.7454557443,
112

    
113
                        4519266.460824658 - 4191037.369934333,
114
                        797903.2656794232 -  626674.7454557443
115
        );
116
        private static ArrayList symbolsToTest; //<AbstractSymbolTestCase>
117
        private ArrayList csSymbols; //<CartographicSupport>
118

    
119
        /**
120
         * Acceptable pixel tolerance error. 1 pixel of error is accetable since it is probably due to
121
         * the java.awt.Graphics
122
         */
123
        private static final double TOL = 1;
124

    
125
        double zooms[] = new double[] {
126
                        1,
127
                        2,
128
                        1.2,
129
                        10,
130
                        0.5
131
        };
132

    
133
        protected void doSetUp() throws Exception {        
134
                geomManager = GeometryLocator.getGeometryManager();
135
                try {
136
                        valenciaUTM30 = geomManager.createPoint(725846.080, 4373022.720, SUBTYPES.GEOM2D);
137
                        valenciaGeo = geomManager.createPoint(- (0+ 22/60 +  27.919/3600), 39 + 28/60 + 35.4276/3600, SUBTYPES.GEOM2D);
138
                } catch (CreateGeometryException e) {
139
                        // TODO Auto-generated catch block
140
                        e.printStackTrace();
141
                }                
142
        
143
                addSymbolTest(new SimpleFillSymbolTest());
144
                addSymbolTest(new SimpleLineSymbolTest());
145
                addSymbolTest(new SimpleMarkerSymbolTest());
146

    
147
                init();
148
        }
149

    
150
        protected void init() {
151

    
152
                // take the symbols added to the TestISymbol test
153
                ISymbol[] symbols = getNewSymbolInstances();
154

    
155
                csSymbols = new ArrayList(); //<CartographicSupport>
156
                for (int i = 0; i < symbols.length; i++) {
157
                        if (symbols[i] instanceof CartographicSupport) {
158
                                csSymbols.add((CartographicSupport) symbols[i]);
159
                        }
160
                }
161
        }
162

    
163
        public static void addSymbolTest(AbstractSymbolTestCase symbolTestClass) {
164
                if (symbolsToTest == null) symbolsToTest = new ArrayList(); //<AbstractSymbolTestCase>
165
                symbolsToTest.add(symbolTestClass);
166
        }
167

    
168
        public static ISymbol[] getNewSymbolInstances() {
169
                ISymbol[] symbols = new ISymbol[symbolsToTest.size()];
170
                for (int i = 0; i < symbols.length; i++) {
171
                        symbols[i] = (ISymbol)((AbstractSymbolTestCase)symbolsToTest.get(i)).newInstance();
172
                }
173
                return symbols;
174
        }
175

    
176

    
177
        public void testSymbolUnitDefinition() {
178
                for (int i = 0; i < csSymbols.size(); i++) {
179
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(i);
180

    
181
                        int aRandomUnit = new Random().nextInt(7);
182

    
183

    
184
                        symbol.setUnit(aRandomUnit);
185
                        XMLEntity xml=null;
186
                        try {
187
                                xml = ((IPersistence) symbol).getXMLEntity();
188
                        } catch (XMLException e) {
189
                                // TODO Auto-generated catch block
190
                                e.printStackTrace();
191
                        }
192
                        String name = symbol.getClass().getName().substring(
193
                                        symbol.getClass().getName().lastIndexOf('.')+1,
194
                                        symbol.getClass().getName().length());
195

    
196
                        try {
197
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
198
                                                symbol.getUnit() == xml.getIntProperty("unit"));
199
                        } catch (NotExistInXMLEntity neiXMLEx) {
200
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
201
                        }
202
                        symbol.setUnit(5);
203
                        try {
204
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getUnit()== 5);
205
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
206
                                                5 == ((IPersistence) symbol).getXMLEntity().getIntProperty("unit"));
207
                        } catch (NotExistInXMLEntity neiXMLEx) {
208
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
209
                        } catch (XMLException e) {
210
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare field attribute in its XMLEntity");
211
                        }
212

    
213
//                        xml.putProperty("unit", 3);
214
//                        ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
215
//                        assertTrue("The application of the UNIT value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getUnit() == 3);
216
                }
217

    
218
        }
219

    
220

    
221
        public void testSymbolReferenceSystemDefinition() {
222
                for (int i = 0; i < csSymbols.size(); i++) {
223
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(i);
224
                        XMLEntity xml=null;
225
                        try {
226
                                xml = ((IPersistence) symbol).getXMLEntity();
227
                        } catch (XMLException e) {
228
                                // TODO Auto-generated catch block
229
                                e.printStackTrace();
230
                        }
231
                        String name = symbol.getClass().getName().substring(
232
                                        symbol.getClass().getName().lastIndexOf('.')+1,
233
                                        symbol.getClass().getName().length());
234
                        try {
235
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare units correctly",
236
                                                symbol.getReferenceSystem() == xml.getIntProperty("referenceSystem"));
237
                        } catch (NotExistInXMLEntity neiXMLEx) {
238
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
239
                        }
240
                        symbol.setReferenceSystem(CartographicSupport.PAPER);
241
                        try {
242
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.PAPER);
243
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly",
244
                                                CartographicSupport.PAPER == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
245
                        } catch (NotExistInXMLEntity neiXMLEx) {
246
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")");
247
                        } catch (XMLException e) {
248
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")");
249
                        }
250

    
251
                        symbol.setReferenceSystem(CartographicSupport.WORLD);
252
                        try {
253
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.WORLD);
254
                                assertTrue( ((ISymbol) symbol).getClass().getName()+" does not declare referenceSystem correctly",
255
                                                CartographicSupport.WORLD == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
256
                        } catch (NotExistInXMLEntity neiXMLEx) {
257
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
258
                        } catch (XMLException e) {
259
                                fail(((ISymbol) symbol).getClass().getName()+ " does not declare referenceSystem field attribute in its XMLEntity");
260
                        }
261

    
262
//                        xml.putProperty("referenceSystem", CartographicSupport.PAPER);
263
//                        ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
264
//                        assertTrue("The application of the REFERENCE SYSTEM value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getReferenceSystem() == CartographicSupport.PAPER);
265
                }
266
        }
267

    
268

    
269
        public void testDegreesUnits_MapReferenceSystem() throws Exception {
270
                for (int j = 0; j < csSymbols.size(); j++) {
271
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
272

    
273
                        MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_PROJECTION);
274
                        ViewPort viewPort = mc.getViewPort();
275

    
276
                        int unit = 8;
277
                        Dimension dim = new Dimension(600, 600);
278
                        viewPort.setImageSize(dim);
279

    
280

    
281
                        /*
282
                         * will test with several extents but in the same map image size, so
283
                         * the scale issue is exercised as well.
284
                         */
285
                        for (int i = 0; i < zooms.length; i++) {
286
                                Envelope extent = geomManager.createEnvelope(-30, -30,dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
287

    
288
                                viewPort.setMapUnits(unit);
289
                                viewPort.setEnvelope(extent);
290

    
291

    
292
                                String name = ((IPersistence) symbol).getClassName().substring(
293
                                                ((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
294
                                                ((IPersistence) symbol).getClassName().length());
295

    
296
                                CartographicSupport csSym = (CartographicSupport) symbol;
297
                                csSym.setReferenceSystem(CartographicSupport.WORLD);
298
                                double size = 30;
299

    
300
                                csSym.setUnit(unit);
301

    
302

    
303

    
304
                                if (symbol instanceof IMarkerSymbol) {
305

    
306
                                        IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
307
                                        markerSym.setSize(size);
308
                                        csSym.toCartographicSize(
309
                                                        viewPort,
310
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
311
                                                        geomManager.createPoint(
312
                                                                        viewPort.getAdjustedExtent().getCenter(0),
313
                                                                        viewPort.getAdjustedExtent().getCenter(1),
314
                                                                        SUBTYPES.GEOM2D
315
                                                        )
316
                                        );
317
                                        double mySize = markerSym.getSize();
318
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
319
                                                        "It returned "+markerSym.getSize()+" when expecting "+
320
                                                        size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
321
                                }
322

    
323
                                if (symbol instanceof ILineSymbol) {
324

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

    
342
                                if (symbol instanceof IFillSymbol) {
343
                                        // this tests if symbol applies the cartographic support to its
344
                                        // outline, since is the only thing that may be resized
345
                                        IFillSymbol fillSym = (IFillSymbol) symbol;
346
                                        if (fillSym.getOutline() == null) {
347
                                                fillSym.setOutline((ILineSymbol) manager.createSymbol(ILineSymbol.SYMBOL_NAME));
348
                                        }
349

    
350
                                        fillSym.getOutline().setLineWidth(size);
351

    
352
                                        csSym.toCartographicSize(
353
                                                        viewPort,
354
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
355
                                                        geomManager.createPoint(
356
                                                                        viewPort.getAdjustedExtent().getCenter(0),
357
                                                                        viewPort.getAdjustedExtent().getCenter(1),
358
                                                                        SUBTYPES.GEOM2D
359
                                                        )
360
                                        );
361
                                        double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
362
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
363
                                                        "It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
364
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
365
                                }
366

    
367
                        }
368
                }
369
        }
370

    
371

    
372
        public void testKilometersUnits_MapReferenceSystem() throws Exception {
373
                for (int j = 0; j < csSymbols.size(); j++) {
374
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
375
                        MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
376
                        ViewPort viewPort = mc.getViewPort();
377

    
378
                        int unit = 0;
379
                        Dimension dim = new Dimension(60, 60);
380
                        viewPort.setImageSize(dim);
381

    
382

    
383
                        /*
384
                         * will test with several extents but in the same map image size, so
385
                         * the scale issue is exercised as well.
386
                         */
387
                        for (int i = 0; i < zooms.length; i++) {
388
                                Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
389

    
390
                                viewPort.setMapUnits(unit);
391
                                viewPort.setEnvelope(extent);
392

    
393

    
394
                                String name = ((IPersistence) symbol).getClassName().substring(
395
                                                ((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
396
                                                ((IPersistence) symbol).getClassName().length());
397

    
398
                                CartographicSupport csSym = (CartographicSupport) symbol;
399
                                csSym.setReferenceSystem(CartographicSupport.WORLD);
400
                                double size = 30;
401

    
402
                                csSym.setUnit(unit);
403

    
404

    
405

    
406

    
407
                                if (symbol instanceof IMarkerSymbol) {
408

    
409
                                        IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
410
                                        markerSym.setSize(size);
411
                                        csSym.toCartographicSize(
412
                                                        viewPort,
413
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
414
                                                        geomManager.createPoint(
415
                                                                        viewPort.getAdjustedExtent().getCenter(0),
416
                                                                        viewPort.getAdjustedExtent().getCenter(1),
417
                                                                        SUBTYPES.GEOM2D
418
                                                        )
419
                                        );
420
                                        double mySize = markerSym.getSize();
421
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
422
                                                        "It returned "+markerSym.getSize()+" when expecting "+
423
                                                        size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
424
                                }
425

    
426
                                if (symbol instanceof ILineSymbol) {
427

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

    
445
                                if (symbol instanceof IFillSymbol) {
446
                                        // this tests if symbol applies the cartographic support to its
447
                                        // outline, since is the only thing that may be resized
448
                                        IFillSymbol fillSym = (IFillSymbol) symbol;
449
                                        if (fillSym.getOutline() == null) {
450
                                                fillSym.setOutline((ILineSymbol) manager.createSymbol(
451
                                                                                ILineSymbol.SYMBOL_NAME));
452
                                        }
453

    
454
                                        fillSym.getOutline().setLineWidth(size);
455

    
456
                                        csSym.toCartographicSize(
457
                                                        viewPort,
458
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
459
                                                        geomManager.createPoint(
460
                                                                        viewPort.getAdjustedExtent().getCenter(0),
461
                                                                        viewPort.getAdjustedExtent().getCenter(1),
462
                                                                        SUBTYPES.GEOM2D
463
                                                        )
464
                                        );
465
                                        double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
466
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
467
                                                        "It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
468
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
469
                                }
470

    
471
                        }
472
                }
473

    
474
        }
475

    
476
        public void testMapInKilometersSymbolInMeters_MapReferenceSystem() throws Exception {
477
                for (int j = 0; j < csSymbols.size(); j++) {
478
                        CartographicSupport symbol = (CartographicSupport)csSymbols.get(j);
479

    
480
                        MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION);
481
                        ViewPort viewPort = mc.getViewPort();
482

    
483
                        int mapUnit = 0;
484
                        int symbolUnit = 1;
485
                        Dimension dim = new Dimension(60, 60);
486
                        viewPort.setImageSize(dim);
487

    
488

    
489
                        /*
490
                         * will test with several extents but in the same map image size, so
491
                         * the scale issue is exercised as well.
492
                         */
493
                        for (int i = 0; i < zooms.length; i++) {
494
                                Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D);
495
                                viewPort.setMapUnits(mapUnit);
496
                                viewPort.setEnvelope(extent);
497
                                double size = 30;
498

    
499

    
500
                                String name = ((IPersistence) symbol).getClassName().substring(
501
                                                ((IPersistence) symbol).getClassName().lastIndexOf('.')+1,
502
                                                ((IPersistence) symbol).getClassName().length());
503

    
504

    
505
                                CartographicSupport csSym = (CartographicSupport) symbol;
506
                                csSym.setReferenceSystem(CartographicSupport.WORLD);
507

    
508
                                csSym.setUnit(symbolUnit);
509

    
510
                                if (symbol instanceof IMarkerSymbol) {
511

    
512
                                        IMarkerSymbol markerSym = (IMarkerSymbol) symbol;
513
                                        markerSym.setSize(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km
514
                                        csSym.toCartographicSize(
515
                                                        viewPort,
516
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
517
                                                        geomManager.createPoint(
518
                                                                        viewPort.getAdjustedExtent().getCenter(0),
519
                                                                        viewPort.getAdjustedExtent().getCenter(1),
520
                                                                        SUBTYPES.GEOM2D
521
                                                        )
522
                                        );
523
                                        double mySize = markerSym.getSize();
524
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
525
                                                        "It returned "+markerSym.getSize()+" when expecting "+
526
                                                        size+"*"+zooms[i]+"="+size*zooms[i],  Math.abs(mySize-size*zooms[i]) <= TOL );
527
                                }
528

    
529
                                if (symbol instanceof ILineSymbol) {
530

    
531
                                        ILineSymbol lineSym = (ILineSymbol) symbol;
532
                                        lineSym.setLineWidth(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 = lineSym.getLineStyle().getLineWidth();
543
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
544
                                                        "It returned "+lineSym.getLineWidth()+" when expecting "+
545
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
546
                                }
547

    
548
                                if (symbol instanceof IFillSymbol) {
549
                                        // this tests if symbol applies the cartographic support to its
550
                                        // outline, since is the only thing that may be resized
551
                                        IFillSymbol fillSym = (IFillSymbol) symbol;
552
                                        if (fillSym.getOutline() == null) {
553
                                                fillSym.setOutline((ILineSymbol) manager.createSymbol(
554
                                                                                ILineSymbol.SYMBOL_NAME));
555
                                        }
556

    
557
                                        fillSym.getOutline().setLineWidth(size*MapContext.CHANGEM[mapUnit]);
558

    
559
                                        csSym.toCartographicSize(
560
                                                        viewPort,
561
                                                        CompatLocator.getGraphicsUtils().getScreenDPI(),
562
                                                        geomManager.createPoint(
563
                                                                        viewPort.getAdjustedExtent().getCenter(0),
564
                                                                        viewPort.getAdjustedExtent().getCenter(1),
565
                                                                        SUBTYPES.GEOM2D
566
                                                        )
567
                                        );
568
                                        double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
569
                                        assertTrue("The Symbol '"+name+"' failed computing cartographic size. " +
570
                                                        "It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+
571
                                                        size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL );
572
                                }
573

    
574
                        }
575
                }
576
        }
577

    
578
}