Revision 452

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FConstant.java
1
/*
2
 * Created on 02-mar-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
package com.iver.cit.gvsig.fmap.core.v02;
8

  
9

  
10
/**
11
 * DOCUMENT ME!
12
 *
13
 * @author vcn To change the template for this generated type comment go to
14
 *         Window>Preferences>Java>Code Generation>Code and
15
 *         Comments
16
 */
17
public class FConstant {
18
	
19
	/**
20
     * Nombre de las unidades de medida, utilizadas.
21
     */
22
    public static String[] NAMES = null;
23
	public final static int SHAPE_TYPE_NULL = 0;
24
	public final static int SHAPE_TYPE_POINT = 1;
25
	public final static int SHAPE_TYPE_POLYLINE = 3;
26
	public final static int SHAPE_TYPE_POLYGON = 5;
27
	public final static int SHAPE_TYPE_MULTIPOINT = 8;
28
	
29
	
30
	public final static int SHAPE_TYPE_POINTZ = 11;
31
	public final static int SHAPE_TYPE_POLYLINEZ = 13;
32
	public final static int SHAPE_TYPE_POLYGONZ = 15;
33
	public final static int SHAPE_TYPE_MULTIPOINTZ = 18;
34
	
35
	public final static int SHAPE_TYPE_POINTM = 21;
36
	public final static int SHAPE_TYPE_POLYLINEM = 23;
37
	public final static int SHAPE_TYPE_POLYGONM = 25;
38
	public final static int SHAPE_TYPE_MULTIPOINTM = 28;
39
	
40
	public final static int LAYER_TYPE_DGN = 1;
41
	public final static int LAYER_TYPE_DWG = 2;
42
	public final static int LAYER_TYPE_DXF = 3;
43
	public final static int LAYER_TYPE_JPEG2000 = 4;
44
	public final static int LAYER_TYPE_SHP = 5;
45
	public final static int LAYER_TYPE_WMS = 6;
46
	public final static int LEGEND_TYPE_BREAK = 3;
47
	public final static int LEGEND_TYPE_DEFAULT = 1;
48
	public final static int LEGEND_TYPE_VALUE = 2;
49
	public final static int SYMBOL_TYPE_DEFAULT = 5;
50

  
51
    
52
	public final static int SYMBOL_TYPE_POINT = 1;
53
	public final static int SYMBOL_TYPE_LINE = 3;
54
	public final static int SYMBOL_TYPE_FILL = 5;
55
	public final static int SYMBOL_TYPE_TEXT = 7;
56
	public final static int SYMBOL_TYPE_ICON = 9;
57
		
58
	public final static int SYMBOL_TYPE_POINTZ = 11;
59
	public final static int SYMBOL_TYPE_MULTIPOINT = 8;
60
	public final static int SYMBOL_STYLE_POINTZ = 0;
61
	public final static int SYMBOL_TYPE_POLYLINEZ = 13;
62
	public final static int SYMBOL_TYPE_POLYGONZ = 15;
63
	// Para s?mbolos de tipo pol?gono.
64
	public final static int SYMBOL_STYLE_FILL_SOLID = 1;
65
	public final static int SYMBOL_STYLE_FILL_TRANSPARENT = 2;
66
	public final static int SYMBOL_STYLE_FILL_HORIZONTAL = 3;
67
	public final static int SYMBOL_STYLE_FILL_VERTICAL = 4;
68
	public final static int SYMBOL_STYLE_FILL_CROSS = 5;
69
	public final static int SYMBOL_STYLE_FILL_UPWARD_DIAGONAL = 6;
70
	public final static int SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL = 7;
71
	public final static int SYMBOL_STYLE_FILL_CROSS_DIAGONAL = 8;
72
	public final static int SYMBOL_STYLE_FILL_GRAYFILL = 9;
73
	public final static int SYMBOL_STYLE_FILL_LIGHTGRAYFILL = 10;
74
	public final static int SYMBOL_STYLE_FILL_DARKGRAYFILL = 11;
75

  
76
	//	Para s?mbolos de tipo Punto
77
	public final static int SYMBOL_STYLE_MARKER_CIRCLE = 30;
78
	public final static int SYMBOL_STYLE_MARKER_SQUARE = 31;
79
	public final static int SYMBOL_STYLE_MARKER_TRIANGLE = 32;
80
	public final static int SYMBOL_STYLE_MARKER_CROSS = 33;
81
	public final static int SYMBOL_STYLE_MARKER_TRUETYPE = 34;
82
	public final static int SYMBOL_STYLE_MARKER_IMAGEN = 35;		      
83

  
84
	// Para s?mbolos de l?neas
85
	public final static int SYMBOL_STYLE_LINE_SOLID = 60;
86
	public final static int SYMBOL_STYLE_LINE_DASH = 61;
87
	public final static int SYMBOL_STYLE_LINE_DOT = 62;
88
	public final static int SYMBOL_STYLE_LINE_DASHDOT = 63;
89
	public final static int SYMBOL_STYLE_LINE_DASHDOTDOT = 64;
90
	public final static int SYMBOL_STYLE_LINE_RAIL = 65;
91
	public final static int SYMBOL_STYLE_LINE_ARROW = 66;
92
    
93
	// Para s?mbolos de tipo texto
94
	public final static int SYMBOL_STYLE_TEXT_NORMAL = 90;
95
	public final static int SYMBOL_STYLE_TEXT_CURSIVE = 91;
96
	public final static int SYMBOL_STYLE_TEXT_BOLD = 92;
97
	public final static int SYMBOL_STYLE_TEXT_BOLDCURSIVE = 93;
98
	static{
99
	new FConstant();	
100
	}
101
	public FConstant(){
102
		if (NAMES == null) {
103
    		int i=0;
104
    		NAMES = new String[8];
105
    		NAMES[i++] = "Kilometros";
106
    		NAMES[i++] = "Metros";
107
    		NAMES[i++] = "Centimetros";
108
    		NAMES[i++] = "Milimetros";
109
    		NAMES[i++] = "Millas";
110
    		NAMES[i++] = "Yardas";
111
    		NAMES[i++] = "Pies";
112
    		NAMES[i++] = "Pulgadas";
113
    	}
114
	}
115

  
116
}
0 117

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FGraphicUtilities.java
1
/*
2
 * Created on 28-abr-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
package com.iver.cit.gvsig.fmap.core.v02;
8

  
9
import java.awt.Font;
10
import java.awt.FontMetrics;
11
import java.awt.Graphics2D;
12
import java.awt.Rectangle;
13
import java.awt.geom.AffineTransform;
14
import java.awt.geom.Point2D;
15

  
16
import org.apache.batik.ext.awt.geom.PathLength;
17

  
18
import com.iver.cit.gvsig.fmap.core.FPoint2D;
19
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
20
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
21
import com.iver.cit.gvsig.fmap.core.FShape;
22
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
23
import com.vividsolutions.jts.geom.Geometry;
24
import com.vividsolutions.jts.geom.Point;
25

  
26

  
27
/**
28
 * DOCUMENT ME!
29
 *
30
 * @author fjp To change the template for this generated type comment go to
31
 *         Window>Preferences>Java>Code Generation>Code and
32
 *         Comments
33
 */
34
public class FGraphicUtilities {
35
    /**
36
     * DOCUMENT ME!
37
     *
38
     * @param g2 DOCUMENT ME!
39
     * @param mT2 DOCUMENT ME!
40
     * @param r DOCUMENT ME!
41
     * @param symbol DOCUMENT ME!
42
     */
43
    public static void DrawSymbol(Graphics2D g2, AffineTransform mT2,
44
        Rectangle r, FSymbol symbol) {
45
        FShape shp;
46

  
47
        AffineTransform mT = new AffineTransform();
48
        mT.setToIdentity();
49

  
50
        // g2.clearRect(r.x, r.y, r.width, r.height);
51
        // System.out.println("r = " + r.toString() + " Color preview:" + m_FSymbol.m_Color.toString());
52
        // System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
53
        switch (symbol.m_symbolType) {
54
            case FConstant.SYMBOL_TYPE_MULTIPOINT:
55

  
56
                shp = new FPoint2D(r.x + (r.width / 2),
57
                        r.y + (r.height / 2));
58
                
59

  
60
                //  Para no tener que clonarlo si viene en unidades de mapa
61
                boolean bAux22 = symbol.m_bUseSize;
62
                int alturaMetros2 = symbol.m_Size; // Nota: Cambiar m_Size a float
63

  
64
                if (symbol.m_bUseSize) {
65
                    symbol.m_Size = 8; // tama?o fijo
66
                    symbol.m_bUseSize = false;
67
                }
68
				//FShape auxshp=new FShape(shp.multipoint.getPoint(0));
69
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
70

  
71
                if (bAux22) {
72
                    symbol.m_Size = alturaMetros2;
73
                    symbol.m_bUseSize = bAux22;
74
                }
75

  
76
                if (symbol.m_Font != null) {
77
                    // Para no tener que clonarlo si viene en unidades de mapa
78
                    boolean bAux = symbol.m_bUseFontSize;
79
                    symbol.m_bUseFontSize = false;
80
                    FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
81
                        new FLabel("Abcd"));
82
                    symbol.m_bUseFontSize = bAux;
83
                }
84

  
85
                break;
86

  
87
            case FConstant.SYMBOL_TYPE_POINT:
88
            case FConstant.SYMBOL_TYPE_POINTZ:
89

  
90
                shp = new FPoint2D(r.x + (r.width / 2),
91
                        r.y + (r.height / 2));
92

  
93
                //  Para no tener que clonarlo si viene en unidades de mapa
94
                boolean bAux2 = symbol.m_bUseSize;
95
                int alturaMetros = symbol.m_Size; // Nota: Cambiar m_Size a float
96

  
97
                if (symbol.m_bUseSize) {
98
                    symbol.m_Size = 8; // tama?o fijo
99
                    symbol.m_bUseSize = false;
100
                }
101

  
102
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
103

  
104
                if (bAux2) {
105
                    symbol.m_Size = alturaMetros;
106
                    symbol.m_bUseSize = bAux2;
107
                }
108

  
109
                if (symbol.m_Font != null) {
110
                    // Para no tener que clonarlo si viene en unidades de mapa
111
                    boolean bAux = symbol.m_bUseFontSize;
112
                    symbol.m_bUseFontSize = false;
113
                    FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
114
                        new FLabel("Abcd"));
115
                    symbol.m_bUseFontSize = bAux;
116
                }
117

  
118
                break;
119

  
120
            case FConstant.SYMBOL_TYPE_LINE:
121
            case FConstant.SHAPE_TYPE_POLYLINEZ:
122

  
123
                Rectangle rect = mT2.createTransformedShape(r).getBounds();
124
                GeneralPathX line = new GeneralPathX();
125
                line.moveTo(rect.x, rect.y + (rect.height / 2));
126

  
127
                // line.lineTo(rect.x + rect.width/3, rect.y + rect.height);								
128
                // line.lineTo(rect.x + 2*rect.width/3, rect.y);				
129
                // line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
130
                line.curveTo(rect.x + (rect.width / 3),
131
                    rect.y + (2 * rect.height),
132
                    rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
133
                    rect.x + rect.width, rect.y + (rect.height / 2));
134

  
135
                shp = new FPolyline2D(line);
136
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
137

  
138
                break;
139

  
140
            case FConstant.SYMBOL_TYPE_FILL:
141
            case FConstant.SHAPE_TYPE_POLYGONZ:
142

  
143
                GeneralPathX rectAux = new GeneralPathX(r);
144
                rectAux.transform(mT2);
145
                shp = new FPolygon2D( rectAux);
146

  
147
                // System.out.println("rect = "+rectAux.getBounds());
148
                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
149

  
150
                break;
151
        }
152
    }
153

  
154
    /**
155
     * DOCUMENT ME!
156
     *
157
     * @param g2 DOCUMENT ME!
158
     * @param mT DOCUMENT ME!
159
     * @param shp DOCUMENT ME!
160
     * @param theSymbol DOCUMENT ME!
161
     */
162
    public static void DrawShape(Graphics2D g2, AffineTransform mT, FShape shp,
163
        FSymbol theSymbol) {
164
        // Hacemos la transformaci?n del shape aqu? dentro... por ahora.
165
        if (shp == null) {
166
            return;
167
        }
168

  
169
        g2.setColor(theSymbol.m_Color);
170

  
171
        switch (shp.getShapeType()) {
172
            case FShape.POINT: //Tipo punto
173
                drawSymbolPoint(g2, mT, (FPoint2D) shp, theSymbol);
174

  
175
                break;
176
            case FShape.LINE:
177

  
178
                // Shape theShp = mT.createTransformedShape(shp.m_Polyline);
179
                // g2.setColor(theSymbol.m_Color);
180
                if (theSymbol.m_Stroke != null) {
181
                    g2.setStroke(theSymbol.m_Stroke);
182
                }
183

  
184
                g2.draw(shp);
185

  
186
                break;
187
                
188

  
189
            case FShape.POLYGON:
190
                g2.setPaint(theSymbol.m_Fill);
191

  
192
                if (theSymbol.m_Color != null) {
193
                    g2.fill(shp);
194
                }
195

  
196
                if (theSymbol.m_useOutline) {
197
                    g2.setColor(theSymbol.m_outlineColor);
198

  
199
                    if (theSymbol.m_Stroke != null) {
200
                        g2.setStroke(theSymbol.m_Stroke);
201
                    }
202

  
203
                    g2.draw(shp);
204
                }
205

  
206
                break;
207
        }
208
    }
209

  
210
    public static void DrawLabel(Graphics2D g2, AffineTransform mT, FShape shp,
211
        FSymbol theSymbol, FLabel theLabel) {
212
        float angle;
213
        float x;
214
        float y;
215
        Point2D pAux = null;
216

  
217
        // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
218
        // Y/O EDITARLO "IN SITU"
219

  
220
        /* if (m_labelValues[numReg].length() > 0)
221
           {
222
                   TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
223
                   layout.draw(g2, x, y);
224
           } */
225
        if (shp == null) {
226
            return;
227
        }
228

  
229
        // Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
230
        // ?til para cuando queramos eliminar duplicados.
231
        if (theLabel.getString() == null) {
232
            return;
233
        }
234

  
235
        FontMetrics metrics = g2.getFontMetrics();
236
        int width = metrics.stringWidth(theLabel.getString());
237
        int height = metrics.getMaxAscent();
238

  
239
        // int height = metrics.getHeight();
240
        g2.setFont(theSymbol.m_Font);
241
        g2.setColor(theSymbol.m_FontColor);
242

  
243
        // Aqu? hay que mirar m_Size y m_useSize...
244
        if (theSymbol.m_bUseFontSize) {
245
            // Suponemos que m_Size viene en coordenadas de mundo real
246
            // Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
247
            // de FSymbol.
248
            // CAMBIO: La altura del texto la miramos en FLabel
249
            // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
250
            float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX());
251

  
252
            /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
253
               " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
254
            if (alturaPixels < 3) {
255
                return; // No leemos nada
256
            }
257

  
258
            Font nuevaFuente = theSymbol.m_Font.deriveFont(alturaPixels);
259
            g2.setFont(nuevaFuente);
260
            width = g2.getFontMetrics().stringWidth(theLabel.getString());
261
        }
262

  
263
        switch (shp.getShapeType()) {
264
            case FShape.POINT: //Tipo punto
265
            	
266
            	pAux = new Point2D.Double(((FPoint2D)shp).getX(), ((FPoint2D)shp).getY());
267
                pAux = mT.transform(pAux, null);
268

  
269
                break;
270

  
271
            case FShape.LINE:
272

  
273
                // 
274
                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez
275
                 {
276
                    PathLength pathLen = new PathLength(shp);
277

  
278
                    // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
279
                    float midDistance = pathLen.lengthOfPath() / 2;
280
                    pAux = pathLen.pointAtLength(midDistance);
281
                    angle = pathLen.angleAtLength(midDistance);
282

  
283
                    if (angle < 0) {
284
                        angle = angle + (float) (2 * Math.PI);
285
                    }
286

  
287
                    if ((angle > (Math.PI / 2)) &&
288
                            (angle < ((3 * Math.PI) / 2))) {
289
                        angle = angle - (float) Math.PI;
290
                    }
291

  
292
                    theLabel.setRotation(Math.toDegrees(angle));
293
                    theLabel.setOrig(pAux);
294
                }
295

  
296
                pAux = mT.transform(theLabel.getOrig(), null);
297

  
298
                // pAux = theLabel.getOrig();
299
                // GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
300
                // Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);				
301
                // g2.draw(txtShp);
302
                // System.out.println("Pintando etiqueta " + theLabel );
303
                break;
304

  
305
            case FShape.POLYGON:
306
                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
307
                 {
308
                    Geometry geo = FConverter.java2d_to_jts(shp);
309

  
310
                    // System.out.println("Area de " + m_labelValues[numReg] + " = "
311
                    //   + geo.getArea());
312
                    //   System.out.println(geo.toText()); 
313
                    Point pJTS = geo.getInteriorPoint();
314
                    FShape pLabel = FConverter.jts_to_java2d(pJTS);
315
                    theLabel.setRotation(0);
316
                    theLabel.setOrig(new Point2D.Double(((FPoint2D)pLabel).getX(), ((FPoint2D)pLabel).getX()));
317
                }
318

  
319
                pAux = mT.transform(theLabel.getOrig(), null);
320

  
321
                break;
322
        }
323

  
324
        AffineTransform ant = g2.getTransform();
325

  
326
        x = (float) pAux.getX();
327
        y = (float) pAux.getY();
328

  
329
        AffineTransform Tx = (AffineTransform) ant.clone();
330
        Tx.translate(x, y); // S3: final translation
331
        Tx.rotate(Math.toRadians(-theLabel.getRotation())); // S2: rotate around anchor
332
        g2.setTransform(Tx);
333

  
334
        switch (theLabel.getJustification()) {
335
            case FLabel.LEFT_BOTTOM:
336
                g2.drawString(theLabel.getString(), 0, 0 - 3);
337

  
338
                break;
339

  
340
            case FLabel.LEFT_CENTER:
341
                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
342

  
343
                break;
344

  
345
            case FLabel.LEFT_TOP:
346
                g2.drawString(theLabel.getString(), 0, 0 - height);
347

  
348
                break;
349

  
350
            case FLabel.CENTER_BOTTOM:
351
                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
352

  
353
                break;
354

  
355
            case FLabel.CENTER_CENTER:
356
                g2.drawString(theLabel.getString(), 0 - (width / 2),
357
                    0 - (height / 2));
358

  
359
                break;
360

  
361
            case FLabel.CENTER_TOP:
362
                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
363
                    height);
364

  
365
                break;
366

  
367
            case FLabel.RIGHT_BOTTOM:
368
                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
369

  
370
                break;
371

  
372
            case FLabel.RIGHT_CENTER:
373
                g2.drawString(theLabel.getString(), 0 - width, 0 -
374
                    (height / 2));
375

  
376
                break;
377

  
378
            case FLabel.RIGHT_TOP:
379
                g2.drawString(theLabel.getString(), 0 - width, 0 - height);
380

  
381
                break;
382
        }
383

  
384
        // Restauramos
385
        g2.setTransform(ant);
386
    }
387

  
388
    /**
389
     * DOCUMENT ME!
390
     *
391
     * @param g2 DOCUMENT ME!
392
     * @param mT DOCUMENT ME!
393
     * @param shp DOCUMENT ME!
394
     * @param theSymbol DOCUMENT ME!
395
     */
396
    private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT, FPoint2D pAux, FSymbol theSymbol) {
397
        int x;
398
        int y;
399
        x = (int) pAux.getX();
400
        y = (int) pAux.getY();
401
		/*if (x==0){
402
			x=100;
403
		}
404
		if (y==0){
405
			y=100;
406
		}
407
		*/
408
        Rectangle rectAux = new Rectangle();
409

  
410
        // Aqu? hay que mirar m_Size y m_useSize...
411
        float radio_simbolo;
412
        radio_simbolo = theSymbol.m_Size / 2;
413

  
414
        if (theSymbol.m_bUseSize) {
415
            // Suponemos que m_Size viene en coordenadas de mundo real
416
            radio_simbolo = (float) (theSymbol.m_Size * mT.getScaleX());
417

  
418
            /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
419
               " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
420
            // if (radio_simbolo < 1) return; // No dibujamos nada
421
            rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
422
                radio_simbolo * 2, radio_simbolo * 2);
423
        } else {
424
            // m_Size viene en pixels
425
            rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
426
                theSymbol.m_Size, theSymbol.m_Size);
427
        }
428

  
429
        // 	continue; //radioSimbolo_en_pixels = 3;
430
        if (theSymbol.m_Fill != null) {
431
            g2.setPaint(theSymbol.m_Fill);
432
        }
433

  
434
        if (theSymbol.m_Stroke != null) {
435
            g2.setStroke(theSymbol.m_Stroke);
436
        }
437

  
438
        if (radio_simbolo < 2) {
439
            g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
440

  
441
            return;
442
        }
443

  
444
        switch (theSymbol.m_Style) {
445
            case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
446

  
447
                if (theSymbol.m_Color != null) {
448
                    g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
449
                        rectAux.height);
450
                }
451

  
452
                if (theSymbol.m_useOutline) {
453
                    g2.setColor(theSymbol.m_outlineColor);
454
                    g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
455
                        rectAux.height);
456
                }
457

  
458
                break;
459

  
460
            case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
461
                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
462

  
463
                if (theSymbol.m_useOutline) {
464
                    g2.setColor(theSymbol.m_outlineColor);
465
                    g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
466
                        rectAux.height);
467
                }
468

  
469
                break;
470

  
471
            case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
472

  
473
                // y = r*sin30, x = r*cos30
474
                GeneralPathX genPath = new GeneralPathX();
475
                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
476
                    y + (int) (radio_simbolo * 0.5));
477
                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
478
                    y + (int) (radio_simbolo * 0.5));
479
                genPath.lineTo(x, y - (float) radio_simbolo);
480
                genPath.closePath();
481

  
482
                g2.fill(genPath);
483

  
484
                break;
485

  
486
            case FConstant.SYMBOL_STYLE_MARKER_CROSS: // Cruz
487

  
488
                GeneralPathX genPathCruz = new GeneralPathX();
489
                genPathCruz.moveTo(x, y - radio_simbolo);
490
                genPathCruz.lineTo(x, y + radio_simbolo);
491
                genPathCruz.moveTo(x - radio_simbolo, y);
492
                genPathCruz.lineTo(x + radio_simbolo, y);
493
                g2.draw(genPathCruz);
494

  
495
                break;
496

  
497
            case 34: // TrueType marker
498

  
499
            /* lf.lfHeight = -radioSimbolo_en_pixels;
500
               angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
501
               angulo = -180.0 * angulo / PI;
502
            
503
               lf.lfEscapement = (long) angulo*10;
504
               lf.lfOrientation = (long) angulo*10;
505
            
506
               fuente.CreateFontIndirect(&lf);
507
               pOldFont = pDC->SelectObject(&fuente);
508
            
509
               pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1);
510
            
511
               pDC->SelectObject(pOldFont);
512
               fuente.DeleteObject();
513
            
514
               break; */
515
            case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
516
            {
517
            	if (theSymbol.m_Icon != null)
518
            	{
519
            		float w, h;
520
                    if (theSymbol.m_bUseSize) {
521
                        // Suponemos que m_Size viene en coordenadas de mundo real
522
                    	// Por ejemplo, nos valemos del ancho para fijar la escala
523
                        w = (float) (theSymbol.m_Size * mT.getScaleX());
524
                        h = theSymbol.m_Icon.getHeight(null) * w / theSymbol.m_Icon.getWidth(null);  
525

  
526
                        rectAux.setRect(x - w, y - h,
527
                            w * 2, h * 2);
528
                    } else {
529
                        // m_Size viene en pixels
530
                    	w = theSymbol.m_Size;
531
                        h = theSymbol.m_Icon.getHeight(null) * w / theSymbol.m_Icon.getWidth(null);                    	
532
                        rectAux.setRect(x - w, y - h, w, h);
533
                    }
534
            		
535
            		g2.drawImage(theSymbol.m_Icon, rectAux.x, rectAux.y, rectAux.width, rectAux.height, null);
536
            	}
537
            	else
538
            	{
539
            		String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen"); 
540
                    FontMetrics metrics = g2.getFontMetrics();
541
                    int width = metrics.stringWidth(strImg);
542
                    int height = metrics.getMaxAscent();
543

  
544
            		g2.drawString(strImg, x - width/2, y -2 + height/2);
545
            	}
546
            	break;
547
            }
548

  
549
            /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
550
               pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
551
               break; */
552
            case FConstant.SYMBOL_STYLE_POINTZ: // Circulito
553

  
554
                if (theSymbol.m_Color != null) {
555
                    g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
556
                        rectAux.height);
557
                }
558

  
559
                if (theSymbol.m_useOutline) {
560
                    g2.setColor(theSymbol.m_outlineColor);
561
                    g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
562
                        rectAux.height);
563
                }
564

  
565
                break;
566
        } // del switch estilo
567
    }
568
}
0 569

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FLabel.java
1
/*
2
 * Created on 13-jul-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
package com.iver.cit.gvsig.fmap.core.v02;
8

  
9
import java.awt.geom.Point2D;
10

  
11
import com.iver.cit.gvsig.fmap.core.FPoint2D;
12
import com.iver.utiles.XMLEntity;
13

  
14
/**
15
 * @author FJP
16
 *
17
 * Se utiliza para etiquetar. Las capas vectoriales tienen un arrayList (m_labels) de FLabel, un
18
 * FLabel por cada registro.
19
 */
20
public class FLabel implements Cloneable {
21
	public final static byte LEFT_TOP = 0;
22
	public final static byte LEFT_CENTER = 1;
23
	public final static byte LEFT_BOTTOM = 2;
24
	
25
	public final static byte CENTER_TOP = 6;
26
	public final static byte CENTER_CENTER = 7;
27
	public final static byte CENTER_BOTTOM = 8;
28
	
29
	public final static byte RIGHT_TOP = 12;
30
	public final static byte RIGHT_CENTER = 13;
31
	public final static byte RIGHT_BOTTOM = 14;
32
	
33
	private String m_Str = null;
34
	private Point2D m_Orig = null;
35
	private double m_Height;
36
	/**
37
	 * <code>m_rotation</code> en grados, NO en radianes. Se convierte en radianes al dibujar.
38
	 */
39
	private double m_rotation;
40
	/**
41
	 * Valores posibles para <code>m_Justification</code>:
42
	 * Left/Top = 0				Center/Top = 6				Right/Top = 12
43
	 * Left/Center = 1			Center/Center = 7			Right/Center = 13
44
	 * Left/Bottom = 2			Center/Bottom = 8			Right/Bottom = 14
45
	 */
46
	private byte m_Justification = LEFT_BOTTOM; // Por defecto 
47
	
48
	
49
	FLabel()
50
	{
51
	}
52
	public FLabel(String str)
53
	{
54
		m_Str  = str;
55
	}
56
	
57
	public FLabel(String str, Point2D pOrig, double heightText, double rotation)
58
	{
59
		m_Str = str;
60
		m_Orig = pOrig;
61
		m_Height = heightText;
62
		m_rotation = rotation;
63
	}
64
	public void setFLabel(FLabel label)
65
	{
66
		m_Str = label.m_Str;
67
		m_Orig = label.m_Orig;
68
		m_Height = label.m_Height;
69
		m_rotation = label.m_rotation;
70
	}
71
	
72
	public Object clone()
73
	{
74
		return new FLabel(m_Str,m_Orig, m_Height, m_rotation);
75
	}
76

  
77
	/**
78
	 * @return Returns the m_Height.
79
	 */
80
	public double getHeight() {
81
		return m_Height;
82
	}
83
	/**
84
	 * @return Returns the m_Orig.
85
	 */
86
	public Point2D getOrig() {
87
		return m_Orig;
88
	}
89
	/**
90
	 * @return Returns the m_rotation.
91
	 */
92
	public double getRotation() {
93
		return m_rotation;
94
	}
95
	/**
96
	 * @return Returns the m_Str.
97
	 */
98
	public String getString() {
99
		return m_Str;
100
	}
101
	/**
102
	 * @param height The m_Height to set.
103
	 */
104
	public void setHeight(double height) {
105
		m_Height = height;
106
	}
107
	/**
108
	 * @param orig The m_Orig to set.
109
	 */
110
	public void setOrig(Point2D orig) {
111
		m_Orig = orig;
112
	}
113
	/**
114
	 * @param m_rotation The m_rotation to set.
115
	 */
116
	public void setRotation(double m_rotation) {
117
		this.m_rotation = m_rotation;
118
	}
119
	/**
120
	 * @param str The m_Str to set.
121
	 */
122
	public void setString(String str) {
123
		m_Str = str;
124
	}
125
	/**
126
	 * Valores posibles para <code>m_Justification</code>:
127
	 * Left/Top = 0				Center/Top = 6				Right/Top = 12
128
	 * Left/Center = 1			Center/Center = 7			Right/Center = 13
129
	 * Left/Bottom = 2			Center/Bottom = 8			Right/Bottom = 14
130
	 */
131
	public byte getJustification() {
132
		return m_Justification;
133
	}
134
	/**
135
	 * Valores posibles para <code>m_Justification</code>:
136
	 * Left/Top = 0				Center/Top = 6				Right/Top = 12
137
	 * Left/Center = 1			Center/Center = 7			Right/Center = 13
138
	 * Left/Bottom = 2			Center/Bottom = 8			Right/Bottom = 14
139
	 */
140
	public void setJustification(byte justification) {
141
		m_Justification = justification;
142
	}
143
	/**
144
		 * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
145
		 * para poder despu?s volver a crear el objeto original.
146
		 *
147
		 * @return XMLEntity.
148
		 */
149
		public XMLEntity getXMLEntity() {
150
			XMLEntity xml = new XMLEntity();
151
			xml.setName("flabel");
152
			xml.putProperty("m_Height", m_Height);
153
			xml.putProperty("m_Justification", (int)m_Justification);
154
			xml.putProperty("m_OrigX", m_Orig.getX());
155
			xml.putProperty("m_OrigY", m_Orig.getY());
156
			xml.putProperty("m_rotation", m_rotation);
157
			xml.putProperty("m_Str", m_Str);
158
			return xml;
159
		}
160

  
161
		/**
162
		 * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
163
		 *
164
		 * @param xml XMLEntity
165
		 *
166
		 * @return Objeto de esta clase.
167
		 */
168
		public static FLabel createFLabel(XMLEntity xml) {
169
			FLabel label = new FLabel();
170
			label.setHeight(xml.getDoubleProperty("m_Height"));
171
			label.setJustification((byte)xml.getIntProperty("m_Justification"));
172
			label.setOrig(new Point2D.Double(xml.getDoubleProperty("m_OrigX"),xml.getDoubleProperty("m_OrigY")));
173
			label.setString("m_Str");
174
			return label;
175
		}
176

  
177
}
0 178

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FSymbol.java
1
/*
2
 * Created on 19-feb-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
6
 */
7
package com.iver.cit.gvsig.fmap.core.v02;
8

  
9
import java.awt.BasicStroke;
10
import java.awt.Color;
11
import java.awt.Font;
12
import java.awt.Image;
13
import java.awt.Paint;
14
import java.awt.Stroke;
15

  
16
import com.iver.utiles.StringUtilities;
17
import com.iver.utiles.XMLEntity;
18

  
19

  
20
/**
21
 * DOCUMENT ME!
22
 *
23
 * @author vcn To change the template for this generated type comment go to
24
 *         Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
25
 *         Comments
26
 */
27
public class FSymbol {
28
    public int m_symbolType;
29
    public int m_Style;
30
    public boolean m_useOutline;
31
    public Color m_Color;
32
    public Color m_outlineColor;
33
    public Font m_Font;
34
    public Color m_FontColor;
35
    public float m_FontSize;
36
    /**
37
     * Si <code>m_bUseFontSize</code> viene a true entonces m_FontSize viene en unidades de mapa (metros)
38
     */
39
    public boolean m_bUseFontSize; 
40
    /**
41
     * <code>m_bDrawShape</code> indica si queremos dibujar el shape de fondo. Es ?til
42
     * cuando est?s etiquetando y no quieres que se dibuje el s?mbolo que te sirve de
43
     * base para etiquetar.
44
     */
45
    public boolean m_bDrawShape = true;
46
    public int m_Size;
47
    public Image m_Icon;
48
    public int m_Rotation;
49
    public Paint m_Fill;
50
    public String m_LinePattern = "0"; // Solo para poder mostrarlo cuando vamos a seleccionar un s?mbolo
51
    									// En realidad lo podemos ver de BasicStroke, pero....
52
    									// ya veremos si luego lo quitamos.
53
    public Stroke m_Stroke;
54
    //private float m_stroke=0;
55
    // public int m_Transparency; // Ya la lleva dentro del Color
56
    public boolean m_bUseSize;	// Si est? a true, m_Size viene en coordenadas de mundo real.
57
    public int m_AlingVert;
58
    public int m_AlingHoriz;
59
    public String m_Descrip;
60
    public Color m_BackColor;
61
    public Paint m_BackFill;
62

  
63
	public FSymbol cloneSymbol()
64
	{
65
		FSymbol nS = new FSymbol();
66

  
67
		
68
		nS.m_symbolType = m_symbolType; 
69
		nS.m_Style = m_Style;
70
		nS.m_useOutline = m_useOutline;
71
		nS.m_Color = m_Color;
72
		nS.m_outlineColor = m_outlineColor;
73
		nS.m_Font = m_Font;
74
		nS.m_FontColor = m_FontColor;
75
		nS.m_FontSize = m_FontSize;
76
		nS.m_bUseFontSize = m_bUseFontSize;
77
		nS.m_bDrawShape = m_bDrawShape;
78
		nS.m_Size = m_Size;
79
		nS.m_Icon = m_Icon;
80
		nS.m_Rotation = m_Rotation;
81
		nS.m_Fill = m_Fill;
82
		nS.m_Stroke = m_Stroke;
83
		// nS.m_Transparency =m_Transparency ;
84
		nS.m_bUseSize = m_bUseSize;
85
		nS.m_AlingVert = m_AlingVert;
86
		nS.m_AlingHoriz = m_AlingHoriz;
87
		nS.m_Descrip = m_Descrip;
88
		nS.m_BackColor = m_BackColor;
89
		nS.m_BackFill = m_BackFill;
90
		
91
		nS.m_LinePattern = m_LinePattern;
92
		
93
		return nS;
94
	}
95
	
96
	public FSymbol()
97
	{
98
	}
99

  
100
	private void createSymbol(int tipoSymbol, Color c)
101
	{
102
		// Tipo de simbolo
103
		m_symbolType = tipoSymbol;
104
        
105
		// Ponemos un estilo por defecto
106
		m_useOutline = true;
107
		m_Color = c;
108
		m_Stroke = null;
109
		m_Fill = null;
110
		
111
		m_FontColor = Color.BLACK;
112
            
113
		m_Size = 0;
114
		
115
		switch (m_symbolType)
116
		{        
117
			case FConstant.SYMBOL_TYPE_POINT:
118
			case FConstant.SYMBOL_TYPE_POINTZ:
119
			case FConstant.SYMBOL_TYPE_MULTIPOINT:
120
				m_useOutline = false;
121
				m_Style = FConstant.SYMBOL_STYLE_MARKER_SQUARE;
122
				m_Size = 5; //pixels
123
				break;
124
			case FConstant.SYMBOL_TYPE_LINE:
125
			case FConstant.SYMBOL_TYPE_POLYLINEZ:
126
			case FConstant.SYMBOL_TYPE_POLYGONZ:
127
				m_Stroke = new BasicStroke();
128
				m_Style = FConstant.SYMBOL_STYLE_LINE_SOLID;
129
				break;
130
			case FConstant.SYMBOL_TYPE_FILL:
131
				m_Style = FConstant.SYMBOL_STYLE_FILL_SOLID;
132
				break;		
133
		}
134
		m_outlineColor = c.darker();
135
	}
136

  
137
    /**
138
     * Creates a new FSymbol object.
139
     *
140
     * @param tipoSymbol DOCUMENT ME!
141
     */
142
	public FSymbol(int tipoSymbol, Color c) {
143
		createSymbol(tipoSymbol,c);
144
	}
145
	public FSymbol(int tipoSymbol) {
146
			int numreg = (int) (Math.random() * 100);
147
			Color colorAleatorio = new Color(((numreg * numreg) + 100) % 255,
148
					(numreg + ((3 * numreg) + 100)) % 255, numreg % 255);
149
				
150
			createSymbol(tipoSymbol, colorAleatorio);
151
        
152
                
153
			// }
154
	}
155
        
156
                
157

  
158
    /**
159
     * DOCUMENT ME!
160
     */
161
    public void onChangeSymbol() {
162
    }
163
	/**
164
		 * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
165
		 */
166
		public XMLEntity getXMLEntity(){
167
			XMLEntity xml=new XMLEntity();
168
			xml.putProperty("m_symbolType",m_symbolType);
169
			xml.putProperty("m_Style",m_Style);
170
			xml.putProperty("m_useOutline",m_useOutline);
171
			if (m_Color!=null){
172
			xml.putProperty("m_Color",StringUtilities.color2String(m_Color));
173
			}
174
			if (m_outlineColor!=null){
175
			xml.putProperty("m_outlineColor",StringUtilities.color2String(m_outlineColor));
176
			}
177
			if (m_Font!=null){
178
			xml.putProperty("fontname",m_Font.getName());
179
			xml.putProperty("fontstyle",m_Font.getStyle());
180
			xml.putProperty("m_FontSize",m_FontSize);
181
			xml.putProperty("m_FontColor",StringUtilities.color2String(m_FontColor));
182
			}
183
			
184
			xml.putProperty("m_bUseFontSize",m_bUseFontSize);
185
			xml.putProperty("m_bDrawShape",m_bDrawShape);
186
			xml.putProperty("m_Size",m_Size);
187
			//xml.putProperty("m_Icon",m_Icon.);
188
			xml.putProperty("m_Rotation",m_Rotation);
189
			if (m_Fill instanceof Color){
190
				xml.putProperty("m_Fill",StringUtilities.color2String((Color)m_Fill));	
191
			}
192
			xml.putProperty("m_LinePattern",m_LinePattern);
193
			//Ancho del stroke en float
194
			if (m_Stroke!=null){
195
			xml.putProperty("m_stroke",((BasicStroke)m_Stroke).getLineWidth());
196
			}else{
197
				
198
				xml.putProperty("m_stroke",0f);
199
			}
200
			xml.putProperty("m_bUseSize",m_bUseSize);
201
			xml.putProperty("m_AlingVert",m_AlingVert);
202
			xml.putProperty("m_AlingHoriz",m_AlingHoriz);
203
			xml.putProperty("m_Descrip",m_Descrip);
204
			if (m_BackColor!=null){
205
			xml.putProperty("m_BackColor",StringUtilities.color2String(m_BackColor));
206
			}
207
			if (m_BackFill instanceof Color){
208
				xml.putProperty("m_BackFill",StringUtilities.color2String((Color)m_BackFill));	
209
			}
210
			
211
			
212
			
213
			return xml;
214
		}
215
	public static FSymbol createFSymbol(XMLEntity xml) {
216
			FSymbol symbol = new FSymbol();
217
		symbol.m_symbolType=xml.getIntProperty("m_symbolType");
218
		symbol.m_Style=	xml.getIntProperty("m_Style");
219
		symbol.m_useOutline=xml.getBooleanProperty("m_useOutline");
220
		if (xml.getStringProperty("m_Color")!=null){
221
		symbol.m_Color=StringUtilities.string2Color(xml.getStringProperty("m_Color"));
222
		}
223
		if (xml.getStringProperty("m_outlineColor")!=null){
224
		symbol.m_outlineColor=StringUtilities.string2Color(xml.getStringProperty("m_outlineColor"));
225
		}
226
		if (xml.getStringProperty("m_FontColor")!=null){
227
		symbol.m_Font=new Font(xml.getStringProperty("fontname"),xml.getIntProperty("fontstyle"),(int)xml.getFloatProperty("m_FontSize"));
228
		symbol.m_FontColor=StringUtilities.string2Color(xml.getStringProperty("m_FontColor"));
229
		symbol.m_FontSize=xml.getFloatProperty("m_FontSize");
230
		}
231
		symbol.m_bUseFontSize=xml.getBooleanProperty("m_bUseFontSize");
232
		symbol.m_bDrawShape=xml.getBooleanProperty("m_bDrawShape");
233
		symbol.m_Size=xml.getIntProperty("m_Size");
234
		//xml.putProperty("m_Icon",m_Icon.);
235
		symbol.m_Rotation=xml.getIntProperty("m_Rotation");
236
		if (xml.getStringProperty("m_Fill")!=null){
237
			symbol.m_Fill=StringUtilities.string2Color(xml.getStringProperty("m_Fill"));	
238
		}
239
		symbol.m_LinePattern=xml.getStringProperty("m_LinePattern");
240
		//Ancho del stroke en float
241
		symbol.m_Stroke=new BasicStroke(xml.getFloatProperty("m_stroke"));
242
		symbol.m_bUseSize=xml.getBooleanProperty("m_bUseSize");
243
		symbol.m_AlingVert=xml.getIntProperty("m_AlingVert");
244
		symbol.m_AlingHoriz=xml.getIntProperty("m_AlingHoriz");
245
		symbol.m_Descrip=xml.getStringProperty("m_Descrip");
246
		if (xml.getStringProperty("m_BackColor")!=null){
247
		symbol.m_BackColor=StringUtilities.string2Color(xml.getStringProperty("m_BackColor"));
248
		}
249
		if (xml.getStringProperty("m_BackFill")!=null){
250
			symbol.m_BackFill=StringUtilities.string2Color(xml.getStringProperty("m_BackFill"));	
251
		}
252
			return symbol;
253
		}
254
}
0 255

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FConverter.java
1
/*
2
 * Created on 08-jun-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
package com.iver.cit.gvsig.fmap.core.v02;
8

  
9

  
10
import java.awt.geom.NoninvertibleTransformException;
11
import java.awt.geom.PathIterator;
12
import java.awt.geom.Point2D;
13
import java.lang.reflect.Array;
14
import java.util.ArrayList;
15

  
16
import com.iver.cit.gvsig.fmap.core.FPoint2D;
17
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
18
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
19
import com.iver.cit.gvsig.fmap.core.FShape;
20
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
21
import com.vividsolutions.jts.algorithm.CGAlgorithms;
22
import com.vividsolutions.jts.algorithm.RobustCGAlgorithms;
23
import com.vividsolutions.jts.geom.Coordinate;
24
import com.vividsolutions.jts.geom.CoordinateArrays;
25
import com.vividsolutions.jts.geom.Envelope;
26
import com.vividsolutions.jts.geom.Geometry;
27
import com.vividsolutions.jts.geom.GeometryCollection;
28
import com.vividsolutions.jts.geom.GeometryFactory;
29
import com.vividsolutions.jts.geom.LineString;
30
import com.vividsolutions.jts.geom.LinearRing;
31
import com.vividsolutions.jts.geom.MultiLineString;
32
import com.vividsolutions.jts.geom.MultiPolygon;
33
import com.vividsolutions.jts.geom.Point;
34
import com.vividsolutions.jts.geom.Polygon;
35

  
36

  
37
/**
38
 * @author fjp
39
 *
40
 * TODO To change the template for this generated type comment go to
41
 * Window - Preferences - Java - Code Generation - Code and Comments
42
 */
43
public class FConverter {
44
	
45
	/**
46
	 * ?QU? PODEMOS HACER CON LOS MULTIPOINT??? => DEBER?AMOS TRABAJAR CON UN ARRAY
47
	 * DE PUNTOS EN FShape.....Pensarlo bien.
48
	 * 
49
	 * 
50
	 */
51
	private final static GeometryFactory geomFactory = new GeometryFactory();
52
	protected static CGAlgorithms cga = new RobustCGAlgorithms();
53
	
54
    //returns true if testPoint is a point in the pointList list.
55
    static boolean pointInList(Coordinate testPoint, Coordinate[] pointList)
56
    {
57
        int t, numpoints;
58
        Coordinate  p;
59
        
60
        numpoints = Array.getLength( pointList) ;
61
        for (t=0;t<numpoints; t++)
62
        {
63
            p = pointList[t];
64
            if ( (testPoint.x == p.x) && (testPoint.y == p.y) &&
65
                    ((testPoint.z == p.z) || (!(testPoint.z == testPoint.z))  )  //nan test; x!=x iff x is nan
66
                    )
67
            {
68
                return true;
69
            }
70
        }
71
        return false;
72
    }
73
	
74
	
75
	/**
76
	 * Convierte un FShape a una Geometry del JTS. Para ello, utilizamos un 
77
	 * "flattened PathIterator". El flattened indica que las curvas las pasa a segmentos
78
	 * de l?nea recta AUTOMATICAMENTE!!!.
79
	 */
80
	 public static Geometry java2d_to_jts(FShape shp)
81
	 {
82
	 	double flatness = 0.8; // Por ejemplo. Cuanto m?s peque?o, m?s segmentos necesitar? la curva
83
	 							// Es la m?xima distancia que permitimos que el trazo aproximado
84
	 							// difiera del trazo real.
85
	 	Geometry geoJTS = null;
86
	 	Coordinate coord;
87
	 	Coordinate[] coords;
88
	 	ArrayList arrayCoords = null;
89
	 	ArrayList arrayLines;
90
	 	LineString lin;
91
	 	LinearRing linRing, linRingExt = null;
92
	 	int theType; 
93
	 	int numParts = 0;
94
//	 	Use this array to store segment coordinate data
95
	    double[] theData = new double[6]; 
96
	    PathIterator theIterator;
97
	 	
98
	 	switch (shp.getShapeType())
99
		{
100
	 		case FShape.POINT:
101
	 			FPoint2D p = (FPoint2D) shp;
102
	 			coord = new Coordinate(p.getX(), p.getY());
103
	 			geoJTS = new GeometryFactory().createPoint(coord);
104
	 			break;
105
	 		case FShape.LINE:	 				 			
106
	 			arrayLines = new ArrayList();
107
	 			theIterator = shp.getPathIterator(null); //, flatness);
108
		 		while(!theIterator.isDone()){
109
		 		    //while not done
110
		 		      theType = theIterator.currentSegment(theData);
111
		 		       
112
		 		      //Populate a segment of the new
113
		 		      // GeneralPathX object.
114
		 		     //Process the current segment to populate a new
115
		 		      // segment of the new GeneralPathX object.
116
		 		      switch(theType){
117
		 		        case PathIterator.SEG_MOVETO :
118
		 		          // System.out.println("SEG_MOVETO");
119
		 		          if (arrayCoords == null)
120
		 		          {
121
		 		          		arrayCoords = new ArrayList();		
122
		 		          		
123
		 		          }
124
		 		          else
125
		 		          {
126
		 		          		lin = new GeometryFactory().createLineString(
127
		 		          				CoordinateArrays.toCoordinateArray(arrayCoords));
128
		 		          		arrayLines.add(lin);
129
		 		          		arrayCoords = new ArrayList();
130
		 		          }
131
		 		          numParts++;
132
		 		          arrayCoords.add(new Coordinate(theData[0], theData[1]));
133
		 		          break;
134
		 		        case PathIterator.SEG_LINETO :
135
		 		        	// System.out.println("SEG_LINETO");
136
		 		        	arrayCoords.add(new Coordinate(theData[0], theData[1]));
137
		 		                                       
138
		 		          break;
139
		 		        case PathIterator.SEG_QUADTO :
140
		 		          System.out.println("Not supported here");     
141
		 		          break;
142
		 		        case PathIterator.SEG_CUBICTO :
143
		 		          System.out.println("Not supported here");
144
		 		          break;
145
		 		        case PathIterator.SEG_CLOSE :
146
		 		          System.out.println("SEG_CLOSE");
147
		 		          // A?adimos el primer punto para cerrar.
148
		 		          Coordinate firstCoord = (Coordinate) arrayCoords.get(0);
149
		 		          arrayCoords.add(new Coordinate(firstCoord.x, firstCoord.y));
150
		 		          break;
151
		 		      }//end switch
152
	 		       
153
		 		      theIterator.next();
154
		 		    }//end while loop
155
	          		lin = new GeometryFactory().createLineString(
156
		          				CoordinateArrays.toCoordinateArray(arrayCoords));
157

  
158
		 			if (numParts > 1) // Generamos una MultiLineString
159
		 			{
160
		          		arrayLines.add(lin);
161
		 				geoJTS = new GeometryFactory().createMultiLineString(
162
		 							GeometryFactory.toLineStringArray(arrayLines));
163
		 			}
164
		 			else
165
		 			{
166
		 				geoJTS = lin;
167
		 			}
168
		 			break;
169
	 		case FShape.POLYGON:
170
	 			arrayLines = new ArrayList();
171
		        ArrayList shells = new ArrayList();
172
		        ArrayList holes = new ArrayList();
173
		        Coordinate[] points = null;
174
	 		
175
 				theIterator = shp.getPathIterator(null);//, flatness);
176
		 		while(!theIterator.isDone()){
177
		 		    //while not done
178
		 		      theType = theIterator.currentSegment(theData);
179
		 		       
180
		 		      //Populate a segment of the new
181
		 		      // GeneralPathX object.
182
		 		     //Process the current segment to populate a new
183
		 		      // segment of the new GeneralPathX object.
184
		 		      switch(theType){
185
		 		        case PathIterator.SEG_MOVETO :
186
		 		          // System.out.println("SEG_MOVETO");
187
		 		          if (arrayCoords == null)
188
		 		          {
189
		 		          		arrayCoords = new ArrayList();		
190
		 		          		
191
		 		          }
192
		 		          else
193
		 		          {
194
		 		          		points = CoordinateArrays.toCoordinateArray(arrayCoords);
195
			 		            LinearRing ring = geomFactory.createLinearRing(points);
196
			 		            if(cga.isCCW(points)){
197
			 		                holes.add(ring);
198
			 		            }
199
			 		            else{
200
			 		                shells.add(ring);
201
			 		            }
202
		 		          	
203
		 		          	
204
		 		          	 	/* if (numParts == 1)
205
		 		          	 	{
206
		 		          	 		linRingExt = new GeometryFactory().createLinearRing(
207
		 		          				CoordinateArrays.toCoordinateArray(arrayCoords));
208
		 		          	 	}
209
		 		          	 	else
210
		 		          	 	{
211
		 		          	 		linRing = new GeometryFactory().createLinearRing(
212
			 		          				CoordinateArrays.toCoordinateArray(arrayCoords));		 		          	 		
213
		 		          	 		arrayLines.add(linRing);
214
		 		          	 	} */
215
		 		          		arrayCoords = new ArrayList();
216
		 		          }
217
		 		          numParts++;
218
		 		          arrayCoords.add(new Coordinate(theData[0], theData[1]));
219
		 		          break;
220
		 		        case PathIterator.SEG_LINETO :
221
		 		        	// System.out.println("SEG_LINETO");
222
		 		        	arrayCoords.add(new Coordinate(theData[0], theData[1]));
223
		 		                                       
224
		 		          break;
225
		 		        case PathIterator.SEG_QUADTO :
226
		 		          System.out.println("SEG_QUADTO Not supported here");     
227
		 		          break;
228
		 		        case PathIterator.SEG_CUBICTO :
229
		 		          System.out.println("SEG_CUBICTO Not supported here");
230
		 		          break;
231
		 		        case PathIterator.SEG_CLOSE :
232
			 		          // A?adimos el primer punto para cerrar.
233
			 		          Coordinate firstCoord = (Coordinate) arrayCoords.get(0);
234
			 		          arrayCoords.add(new Coordinate(firstCoord.x, firstCoord.y));
235
		 		          break;
236
		 		      }//end switch
237
	 		          // System.out.println("theData[0] = " + theData[0] + " theData[1]=" + theData[1]);
238
		 		      theIterator.next();
239
	 		    }//end while loop
240
		 		// arrayCoords.add(arrayCoords.get(0));
241
          		points = CoordinateArrays.toCoordinateArray(arrayCoords);
242
	            LinearRing ring = geomFactory.createLinearRing(points);
243
	            if(cga.isCCW(points)){
244
	                holes.add(ring);
245
	            }
246
	            else{
247
	                shells.add(ring);
248
	            }
249
		 		
250
          		/* linRing = new GeometryFactory().createLinearRing(
251
	          				CoordinateArrays.toCoordinateArray(arrayCoords)); */
252
          		// System.out.println("NumParts = " + numParts);
253
                //now we have a list of all shells and all holes
254
                ArrayList holesForShells = new ArrayList(shells.size());
255
                for(int i=0;i<shells.size();i++){
256
                    holesForShells.add(new ArrayList());
257
                }
258
                
259
                //find homes
260
                for(int i=0;i<holes.size();i++){
261
                    LinearRing testRing = (LinearRing)holes.get(i);
262
                    LinearRing minShell = null;
263
                    Envelope minEnv = null;
264
                    Envelope testEnv = testRing.getEnvelopeInternal();
265
                    Coordinate testPt = testRing.getCoordinateN(0);
266
                    LinearRing tryRing;
267
                    for(int j=0;j<shells.size();j++){
268
                        tryRing = (LinearRing) shells.get(j);
269
                        Envelope tryEnv = tryRing.getEnvelopeInternal();
270
                        if (minShell != null) minEnv = minShell.getEnvelopeInternal();
271
                        boolean isContained = false;
272
                        Coordinate[] coordList = tryRing.getCoordinates() ;
273
                        
274
                        if (tryEnv.contains(testEnv)
275
                                && (cga.isPointInRing(testPt,coordList ) || (pointInList(testPt, coordList)))
276
                           )
277
                            isContained = true;
278
                        // check if this new containing ring is smaller than the current minimum ring
279
                        if (isContained) {
280
                            if (minShell == null
281
                            || minEnv.contains(tryEnv)) {
282
                                minShell = tryRing;
283
                            }
284
                        }
285
                    }
286
                    
287
                    if (minShell == null)
288
                    {
289
                        System.out.println("polygon found with a hole thats not inside a shell");
290
                    }
291
                    else
292
                    {
293
                      ((ArrayList)holesForShells.get(shells.indexOf(minShell))).add(testRing);
294
                    }
295
                }
296
                
297
                Polygon[] polygons = new Polygon[shells.size()];
298
                for(int i=0;i<shells.size();i++){
299
                    polygons[i]=geomFactory.createPolygon((LinearRing)shells.get(i),(LinearRing[])((ArrayList)holesForShells.get(i)).toArray(new LinearRing[0]));
300
                }
301
                
302
                if(polygons.length==1){
303
                    return polygons[0];
304
                }
305
                
306
                holesForShells = null;
307
                shells = null;
308
                holes = null;
309
                //its a multi part
310
                
311

  
312
                geoJTS =  geomFactory.createMultiPolygon(polygons);
313

  
314
	 			/* if (numParts > 1) // Generamos un Polygon con agujeros
315
	 			{
316
	          		arrayLines.add(linRing);
317
	 				// geoJTS = new GeometryFactory().createPolygon(linRingExt, 
318
	 						// GeometryFactory.toLinearRingArray(arrayLines));
319
	          		geoJTS = new GeometryFactory().buildGeometry(arrayLines);
320
	          		
321
	          		// geoJTS = Polygonizer.class.
322
	 			}
323
	 			else
324
	 			{
325
	 				geoJTS = new GeometryFactory().createPolygon(linRing,null);
326
	 			} */
327
	 			break;
328
	 			
329
		}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff