Revision 695

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/MemoryDriver.java
1
/*
2
 * Created on 27-dic-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.drivers;
8

  
9
import java.awt.geom.Rectangle2D;
10
import java.io.File;
11
import java.io.IOException;
12
import java.util.ArrayList;
13

  
14
import javax.swing.table.DefaultTableModel;
15

  
16
import com.hardcode.gdbms.engine.data.DriverException;
17
import com.hardcode.gdbms.engine.data.FileDriver;
18
import com.hardcode.gdbms.engine.values.Value;
19
import com.iver.cit.gvsig.fmap.core.FGeometry;
20
import com.iver.cit.gvsig.fmap.core.FShape;
21
import com.iver.cit.gvsig.fmap.core.IGeometry;
22
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
23
import com.iver.cit.gvsig.fmap.operations.strategies.MemoryShapeInfo;
24

  
25
/**
26
 * @author FJP
27
 *
28
 * TODO To change the template for this generated type comment go to
29
 * Window - Preferences - Java - Code Generation - Code and Comments
30
 */
31
public abstract class MemoryDriver implements VectorialFileDriver, FileDriver, BoundedShapes {
32
    private MemoryShapeInfo memShapeInfo = new MemoryShapeInfo();
33
    private ArrayList arrayGeometries = new ArrayList();
34
    private Rectangle2D fullExtent;
35
    private int m_Position;
36
    private DefaultTableModel m_TableModel = new DefaultTableModel();
37
    
38
    public DefaultTableModel getTableModel()
39
    {
40
    	return m_TableModel;
41
    }
42
    
43
    public void addShape(FShape shp, Object [] row) {
44
    	if (shp == null) return; // No a?adimos nada
45
    	Rectangle2D boundsShp = shp.getBounds(); 
46
        memShapeInfo.addShapeInfo(boundsShp, shp.getShapeType());
47
        arrayGeometries.add(ShapeFactory.createGeometry(shp));
48
        m_TableModel.addRow(row);
49
        try {
50
			fullExtent = getFullExtent();
51
		} catch (IOException e) {
52
			e.printStackTrace();
53
		}
54
        if (fullExtent == null)
55
        {
56
        	fullExtent = boundsShp;
57
        }
58
        else
59
        	fullExtent.add(boundsShp);
60
        
61
        m_Position++;
62
    }
63

  
64
    public Rectangle2D getShapeBounds(int index) throws IOException
65
	{
66
		return memShapeInfo.getBoundingBox(index);
67
	}
68
	
69
	
70
	public int getShapeType(int index) 
71
	{
72
		return memShapeInfo.getType(index);
73
	}
74
    
75
	/* (non-Javadoc)
76
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
77
	 */
78
	public abstract void open(File f) throws IOException;
79
	/* (non-Javadoc)
80
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
81
	 */
82
	public void close() throws IOException {
83
		// No hago nada, lo he abierto y cerrado en el inicialize de la clase hija
84
	}
85
	/* (non-Javadoc)
86
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShape(int)
87
	 */
88
	public IGeometry getShape(int index) throws IOException {
89
		return (IGeometry) arrayGeometries.get(index);
90
	}
91
	/* (non-Javadoc)
92
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
93
	 */
94
	public int getShapeCount() throws IOException {
95
		return arrayGeometries.size();
96
	}
97
	/* (non-Javadoc)
98
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
99
	 */
100
	public Rectangle2D getFullExtent() throws IOException {
101
		return fullExtent;
102
	}
103
	/* (non-Javadoc)
104
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
105
	 */
106
	public void initialize() throws IOException {
107
		
108
	}
109
	/* (non-Javadoc)
110
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
111
	 */
112
	public abstract boolean accept(File f);
113
	/* (non-Javadoc)
114
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
115
	 */
116
	public int getShapeType() {
117
		return 15;
118
	}
119
	/* (non-Javadoc)
120
	 * @see com.hardcode.driverManager.Driver#getName()
121
	 */
122
	public abstract String getName();
123
	/* (non-Javadoc)
124
	 * @see com.hardcode.gdbms.engine.data.FileDriver#fileAccepted(java.io.File)
125
	 */
126
	public boolean fileAccepted(File f) {
127
		return false;
128
	}
129
	/* (non-Javadoc)
130
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
131
	 */
132
	public Value getFieldValue(long rowIndex, int fieldId) throws DriverException {
133
		return (Value) m_TableModel.getValueAt((int) rowIndex, fieldId);
134
	}
135
	/* (non-Javadoc)
136
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
137
	 */
138
	public int getFieldCount() throws DriverException {
139
		return m_TableModel.getColumnCount();
140
	}
141
	/* (non-Javadoc)
142
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
143
	 */
144
	public String getFieldName(int fieldId) throws DriverException {
145
		return m_TableModel.getColumnName(fieldId);
146
	}
147
	/* (non-Javadoc)
148
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
149
	 */
150
	public long getRowCount() throws DriverException {
151
		return arrayGeometries.size();
152
	}
153

  
154
}
0 155

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dgn/DgnMemoryDriver.java
1
package com.iver.cit.gvsig.fmap.drivers.dgn;
2

  
3
import java.awt.geom.AffineTransform;
4
import java.awt.geom.Arc2D;
5
import java.io.File;
6
import java.io.IOException;
7
import java.util.ArrayList;
8
import java.util.Comparator;
9
import java.util.TreeMap;
10

  
11
import com.iver.cit.gvsig.fmap.core.FPoint2D;
12
import com.iver.cit.gvsig.fmap.core.FPoint3D;
13
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
14
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
15
import com.iver.cit.gvsig.fmap.core.FShape;
16
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
17
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
18
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
19
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver;
20
import com.iver.cit.gvsig.fmap.rendering.Legend;
21

  
22

  
23
/**
24
 * DOCUMENT ME!
25
 *
26
 * @author Vicente Caballero Navarro
27
 */
28
public class DgnMemoryDriver extends MemoryDriver {
29
	private final int ID_FIELD_ID=0;
30
	private final int ID_FIELD_ENTITY=1;
31
	private final int ID_FIELD_LAYER=2;
32
	private final int ID_FIELD_COLOR=3;
33
	private final int ID_FIELD_HEIGHTTEXT=4;
34
	private final int ID_FIELD_ROTATIONTEXT=5;
35
	private final int ID_FIELD_TEXT=6;
36
	
37

  
38
	DGNReader m_DgnReader;
39
	
40
	
41
	private String path;
42
	private File m_Fich;
43

  
44

  
45
	
46
    /**
47
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
48
     */
49
    public void open(File f) throws IOException {
50
    	m_Fich = f;
51
    }
52

  
53
    /**
54
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
55
     */
56
    public void initialize() throws IOException {
57
    	
58
		float heightText = 10;
59

  
60
    	
61
    	m_DgnReader = new DGNReader(m_Fich.getAbsolutePath());
62
    	
63
    	Object [] auxRow = new Object[7];
64
    	Object [] cellRow = new Object[7];
65
    	Object [] complexRow = new Object[7];
66
		ArrayList arrayFields = new ArrayList();
67
		arrayFields.add("ID");
68
		arrayFields.add("Entity");
69
		arrayFields.add("Layer");
70
		arrayFields.add("Color");
71
		arrayFields.add("HeightText");
72
		arrayFields.add("RotationText");
73
		arrayFields.add("Text");
74
    	
75
    	
76
    	getTableModel().setColumnIdentifiers(arrayFields.toArray());
77
		
78
		
79
		// Ahora las rellenamos.
80
		FShape aux;
81
		boolean bElementoCompuesto = false, bEsPoligono = false;
82
		boolean bInsideCell = false;
83
		boolean bFirstHoleEntity = false;
84
		boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas
85
		int contadorSubElementos =0, numSubElementos = 0;
86
		int complex_index_fill_color= -1;
87
		int nClass; // Para filtrar los elementos de construcci?n, etc.
88
		GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
89
		for (int id=0; id < m_DgnReader.getNumEntities(); id++)
90
		{
91
			// System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
92
			m_DgnReader.DGNGotoElement(id);
93
	        DGNElemCore elemento = m_DgnReader.DGNReadElement();
94
	        nClass= 0;
95
	        if (elemento.properties != 0)
96
	        	nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS;
97
	        if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento
98
	         {
99
	        	aux = null;
100
	        	// if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
101
	        	// 	m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,""); 
102
	        	
103
	        	if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) || (elemento.stype == DGNFileHeader.DGNST_ARC)
104
	        			|| (elemento.stype == DGNFileHeader.DGNST_CELL_HEADER)
105
						|| (elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN)
106
						|| (elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER))
107
	        	{
108
		        	if (elemento.complex != 0)
109
		        	{
110
		        		bElementoCompuesto = true;
111
		        	}
112
		        	else
113
		        	{	        		
114
		        		if (bElementoCompuesto)
115
		        		{		        			
116
		        			if (bInsideCell)
117
		        			{
118
		        				auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY];
119
		        			}
120
		        			else
121
		        			{
122
		        				auxRow = complexRow;
123
		        			}
124
		        			// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
125
		        			addShape(new FPolyline2D(elementoCompuesto), auxRow);
126
		        			if (bEsPoligono)
127
		        			{
128
								if (complex_index_fill_color != -1)
129
									auxRow[ID_FIELD_COLOR] = new Integer(complex_index_fill_color);
130

  
131
		        				addShape(new FPolygon2D(elementoCompuesto), auxRow);
132
		        			}
133
		        			elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
134
		        		}
135
		        		// System.err.println("Entidad simple");
136
		        		bElementoCompuesto = false;
137
		        		bEsPoligono = false;
138
		        		bConnect = false;
139
		        		// elementoCompuesto = new GeneralPathX();
140
		        		bInsideCell = false;
141
		        	}
142
	        	}
143
	            switch (elemento.stype)
144
				{
145
					case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
146
						bInsideCell = true;
147
						cellRow[ID_FIELD_ID] = new Integer(elemento.element_id);
148
		                cellRow[ID_FIELD_LAYER] = new Integer(elemento.level);
149
		                cellRow[ID_FIELD_COLOR] = new Integer(elemento.color);
150
		                cellRow[ID_FIELD_ENTITY] = new String("Shared Cell");
151
						break;
152
					case DGNFileHeader.DGNST_CELL_HEADER:
153
						bInsideCell = true;
154
						DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento;
155
						cellRow[ID_FIELD_ID] = new Integer(elemento.element_id);
156
		                cellRow[ID_FIELD_LAYER] = new Integer(elemento.level);
157
		                cellRow[ID_FIELD_COLOR] = new Integer(elemento.color);
158
		                cellRow[ID_FIELD_ENTITY] = new String("Cell");
159
		                complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento);
160
		                // System.err.println("Cell Header " + complex_index_fill_color);
161
						break;
162
	
163
					case DGNFileHeader.DGNST_COMPLEX_HEADER:
164
						// bElementoCompuesto = true;
165
						// System.err.println("Complex Header");
166
						contadorSubElementos = 0;
167
						DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento;
168
						numSubElementos = psComplexHeader.numelems;
169
						complexRow[ID_FIELD_ID] = new Integer(elemento.element_id);
170
		                complexRow[ID_FIELD_LAYER] = new Integer(elemento.level);
171
		                complexRow[ID_FIELD_COLOR] = new Integer(elemento.color);
172
		                complexRow[ID_FIELD_ENTITY] = new String("Complex");
173
		                
174
						
175
						if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER)
176
						{
177
							bEsPoligono = true;
178
							// Si es un agujero, no conectamos con el anterior
179
							if ((psComplexHeader.properties & 0x8000) != 0)
180
								bFirstHoleEntity = true;
181
							else
182
							{
183
								// Miramos si tiene color de relleno
184
								// complex_index_fill_color = -1;
185
								// if (elemento.attr_bytes > 0) {
186
									complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento);
187
									// System.err.println("complex shape fill color = " + elemento.color);
188
								// }
189
								
190
							}
191
							bConnect = true;
192
						}
193
						else
194
						{
195
							bEsPoligono = false;
196
							bConnect = false;
197
						}
198
						break;
199
					case DGNFileHeader.DGNST_MULTIPOINT:
200
						// OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
201
						// spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
202
						// y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
203
						// TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
204
						// Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
205
						// todav?a no est? metido.
206
		               DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento;			                		                
207
		                
208
		                auxRow[ID_FIELD_LAYER] = new Integer(elemento.level);
209
		                auxRow[ID_FIELD_COLOR] = new Integer(elemento.color);
210
		                
211
		                if ((psLine.num_vertices == 2) && (psLine.vertices[0].x == psLine.vertices[1].x)
212
		                		&& (psLine.vertices[0].y == psLine.vertices[1].y))
213
		                {
214
		                	auxRow[ID_FIELD_ENTITY] = new String("Point");
215
		                	addShape(new FPoint3D(psLine.vertices[0].x,
216
		                			psLine.vertices[0].y,psLine.vertices[0].z), auxRow);
217
		                }
218
		                else
219
		                {
220
			               GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
221
			               if (psLine.type == DGNFileHeader.DGNT_CURVE)
222
			               {
223
			               		psLine.num_vertices = psLine.num_vertices - 4;
224
			               		for (int aux_n = 0; aux_n < psLine.num_vertices; aux_n++)
225
			               		{
226
			               			psLine.vertices[aux_n] = psLine.vertices[aux_n+2];
227
			               		}
228
			               }
229
			               if ((psLine.type == DGNFileHeader.DGNT_SHAPE)
230
			               		&& ((psLine.properties & 0x8000) != 0))
231
			               {
232
			               		// Invertimos el orden porque es un agujero
233
				               elShape.moveTo(psLine.vertices[psLine.num_vertices-1].x,
234
				               		psLine.vertices[psLine.num_vertices-1].y);
235
				               for (int i = psLine.num_vertices-2; i >= 0; i--)
236
				               		elShape.lineTo( psLine.vertices[i].x,
237
				               				psLine.vertices[i].y);
238
			               }
239
			               else
240
			               {
241
				               elShape.moveTo(psLine.vertices[0].x, psLine.vertices[0].y);
242
				               for (int i = 1; i < psLine.num_vertices; i++)
243
				               		elShape.lineTo( psLine.vertices[i].x,
244
				               				psLine.vertices[i].y);
245
			               }
246
				               	
247
			               auxRow[ID_FIELD_ID] = new Integer(elemento.element_id);
248
		                	auxRow[ID_FIELD_ENTITY] = new String("Multipoint");
249
		                	
250
		                	
251
		                	if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices-1].x)
252
		                			&& (psLine.vertices[0].y == psLine.vertices[psLine.num_vertices-1].y))
253
		                	{
254
		                		// Lo a?adimos tambi?n como pol?gono
255
		                		bEsPoligono = true;
256
								// Miramos si tiene color de relleno
257
								if (elemento.attr_bytes > 0) {
258
									elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento);
259
									// System.err.println("fill color = " + elemento.color);
260
									if (elemento.color != -1)
261
										auxRow[ID_FIELD_COLOR] = new Integer(elemento.color);
262
								}
263
		                		
264
		                		if (elemento.complex == 0)
265
		                			addShape(new FPolygon2D(elShape), auxRow);
266
		                	}
267
	                		if (elemento.complex != 0)
268
	                			// Si es un agujero o 
269
	                			// es la primera entidad del agujero, lo a?adimos sin unir al anterior
270
	 			               if (bFirstHoleEntity || ((psLine.type == DGNFileHeader.DGNT_SHAPE) && ((psLine.properties & 0x8000) != 0)))
271
				               {
272
	 			               			elementoCompuesto.append(elShape, false);
273
	 			               			bFirstHoleEntity = false;
274
	 			               }
275
	 			               else
276
	 			               			elementoCompuesto.append(elShape, bConnect);	 			               	
277
	                		else		                	
278
	                			addShape(new FPolyline2D(elShape), auxRow);
279
		                }		                	
280
		                
281
		                break;
282
	                case DGNFileHeader.DGNST_ARC: 
283
	                   // m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
284
	                   DGNElemArc psArc = (DGNElemArc) elemento;
285
	                   // La definici?n de arco de MicroStation es distinta a la de Java.
286
	                   // En el dgn el origin se entiende que es el centro del arco,
287
	                   // y a la hora de crear un Arc2D las 2 primeras coordenadas son
288
	                   // la esquina inferior izquierda del rect?ngulo que rodea al arco.
289
	                
290
	                   // 1.- Creamos la elipse sin rotaci?n.
291
	                   // 2.- Creamos el arco
292
	                   // 3.- Rotamos el resultado
293
	                	/* System.out.println("Arco con primari axis: " + psArc.primary_axis +
294
	                			" start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
295
	                	System.out.println("secondaria axis: " + psArc.secondary_axis +
296
								 " rotation = " + psArc.rotation); */ 
297
	                
298
	                   AffineTransform mT = AffineTransform.getRotateInstance(
299
	                   		Math.toRadians(psArc.rotation), psArc.origin.x, psArc.origin.y);
300
	                   // mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
301
     	               Arc2D.Double elArco = new Arc2D.Double(
302
     	               		psArc.origin.x - psArc.primary_axis, psArc.origin.y - psArc.secondary_axis,                    	
303
                            2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis,
304
                            -psArc.startang, -psArc.sweepang, Arc2D.OPEN);
305
	                   // Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
306
	                   // 		psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
307
     	               GeneralPathX elShapeArc = new GeneralPathX(elArco);
308
     	               // Transformamos el GeneralPahtX porque si transformamos elArco nos lo convierte
309
     	               // a GeneralPath y nos guarda las coordenadas en float, con la correspondiente p?rdida de precisi?n
310
     	               elShapeArc.transform(mT);
311
     	              if (m_DgnReader.getInfo().dimension == 3) {
312
     	              	//Aqu? podr?amos hacer cosas con la coordenada Z
313
     	              }
314
     	              
315
     	              auxRow[ID_FIELD_ID] = new Integer(elemento.element_id);
316
		               auxRow[ID_FIELD_ENTITY] = new String("Arc");
317
		               auxRow[ID_FIELD_LAYER] = new Integer(elemento.level);
318
		               auxRow[ID_FIELD_COLOR] = new Integer(elemento.color);
319
		               
320
		               /* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y, 
321
		               		psArc.origin.x + psArc.primary_axis, psArc.origin.y);
322
     	               
323
		               lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, new GeneralPathX(ejeMayor)), auxRow); */
324
     	               // lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
325
		               if (elemento.complex != 0)
326
		               {
327
		               		// Esto es una posible fuente de fallos si detr?s de una
328
		               	    // elipse vienen m?s cosas pegadas. Deber?amos volver
329
		               		// a conectar una vez pasada la elipse.
330
		               	   if (elemento.type == DGNFileHeader.DGNT_ELLIPSE)
331
		               	   		bConnect = false;
332

  
333
		               	   // SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
334
		               	   // Y EL ELEMENTO ES UN POLIGONO		               	   
335
			               if (bFirstHoleEntity || ((elemento.type == DGNFileHeader.DGNT_SHAPE)
336
			               		&& ((elemento.properties & 0x8000) != 0)))
337
			               {
338
 			               			elementoCompuesto.append(elShapeArc, false);
339
 			               			bFirstHoleEntity = false;
340
			               }
341
 			               else
342
 			               			elementoCompuesto.append(elShapeArc, bConnect);	 			               	
343
		               }
344
		            	else	
345
		            	{
346
		            		addShape(new FPolyline2D(elShapeArc), auxRow);
347
		            		if (psArc.type == DGNFileHeader.DGNT_ELLIPSE)
348
		            			addShape(new FPolygon2D(elShapeArc), auxRow);
349
		            	}
350
		               	     	        
351
	     	               // System.err.println("Entra un Arco");
352
	                    break;
353

  
354
	                case DGNFileHeader.DGNST_TEXT: 
355
	                    DGNElemText psText = (DGNElemText) elemento;
356
		                FPoint2D elShapeTxt = new FPoint3D(
357
		                		psText.origin.x, psText.origin.y,psText.origin.z);
358
		                		                
359
		                auxRow[ID_FIELD_ID] = new Integer(elemento.element_id);
360
		                auxRow[ID_FIELD_ENTITY] = new String("Text");
361
		                auxRow[ID_FIELD_LAYER] = new Integer(elemento.level);
362
		                auxRow[ID_FIELD_COLOR] = new Integer(elemento.color);
363
		                heightText = (float) psText.height_mult;
364
		                auxRow[ID_FIELD_HEIGHTTEXT] = new Double(heightText);
365
		                auxRow[ID_FIELD_ROTATIONTEXT] = new Double(psText.rotation);
366
		                auxRow[ID_FIELD_TEXT] = psText.string; // .trim();
367
		                addShape(elShapeTxt, 
368
		                		auxRow);
369
		                
370
		                // System.out.println("Rotaci?n texto: " + psText.rotation + "Altura Texto = " + heightText);
371

  
372

  
373
	                        /* System.out.println("  origin=(" + psText.origin.x +
374
	                            ", " + psText.origin.y + ") rotation=" +
375
	                            psText.rotation + "\n" + "  font=" +
376
	                            psText.font_id + " just=" +
377
	                            psText.justification + "length_mult=" +
378
	                            psText.length_mult + " height_mult=" +
379
	                            psText.height_mult + "\n" + "  string =" +
380
	                            new String(psText.string).toString().trim() +
381
	                            "\n"); */ 
382
	                	break;
383
	                	/* default:
384
	                		m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
385
	                		*/
386
		                
387
		            } // switch
388
		
389
		            
390
				} // if
391
			
392
		} // for
393

  
394
		if (bElementoCompuesto)
395
		{
396
			if (bInsideCell)
397
			{
398
				auxRow = cellRow;
399
			}
400
			else
401
			{
402
				auxRow = complexRow;
403
			}
404
			// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);			
405
			addShape(new FPolyline2D(elementoCompuesto), auxRow);
406
			if (bEsPoligono)
407
			{
408
				if (complex_index_fill_color != -1)
409
					auxRow[ID_FIELD_COLOR] = new Integer(complex_index_fill_color);
410

  
411
				addShape(new FPolygon2D(elementoCompuesto), auxRow);
412
			}
413
		}
414
		
415
		/* Legend rendererLines = lyrLines.getLegend();
416
		rendererLines.setField("Color");
417
		rendererLines.setLegendType(FConstant.LEGEND_TYPE_VALUE);
418
        FRecordset rs = lyrLines.getRecordset();
419
		rendererLines.m_symbolList = new TreeMap(
420
				new Comparator() {
421
					public int compare(Object o1, Object o2)
422
					{
423
						int resul = -1;
424
						if ((o1 != null) && (o2 != null))
425
						{
426
							double d2 = Double.parseDouble((String)o2);
427
							double d1 = Double.parseDouble((String)o1);
428
							resul = (int) (d1-d2);
429
						}
430
						return resul;
431
					}
432
				}		
433
			); 
434
	
435
		String clave;
436
		FSymbol theSymbol = null;
437
		
438
		for (int j = 0; j < lyrLines.m_NumShapes; j++)
439
		{
440
			rs.moveTo(j);
441

  
442
			clave =rs.getFieldValueAsString(ID_FIELD_COLOR);
443

  
444
			////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
445
			if (!rendererLines.m_symbolList.containsKey(clave)) {
446
				//si no esta creado el simbolo se crea
447
				theSymbol = new FSymbol(lyrLines.m_shapeType);				
448
				theSymbol.m_Descrip = clave.toString();
449
				theSymbol.m_Color = m_DgnReader.DGNLookupColor(rs.getFieldValueAsNumber(ID_FIELD_COLOR).intValue());
450
				rendererLines.addSymbol(clave, theSymbol);								
451
			}
452
			
453
			lyrLines.m_legendValues[j] = rs.getFieldValueAsString(ID_FIELD_COLOR);
454
		} // for
455

  
456
		Legend rendererPoly = lyrPolygons.getLegend();
457
		rendererPoly.setField("Color");
458
		rendererPoly.setLegendType(FConstant.LEGEND_TYPE_VALUE);
459
        rs = lyrPolygons.getRecordset();
460
        
461
        rendererPoly.m_symbolList = new TreeMap(
462
				new Comparator() {
463
					public int compare(Object o1, Object o2)
464
					{
465
						int resul = -1;
466
						if ((o1 != null) && (o2 != null))
467
						{
468
							double d2 = Double.parseDouble((String)o2);
469
							double d1 = Double.parseDouble((String)o1);
470
							resul = (int) (d1-d2);
471
						}
472
						return resul;
473
					}
474
				}		
475
			);  
476
        		
477
		
478
		for (int j = 0; j < lyrPolygons.m_NumShapes; j++)
479
		{
480
			rs.moveTo(j);
481

  
482
			clave =rs.getFieldValueAsString(ID_FIELD_COLOR);
483

  
484
			////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
485
			if (!rendererPoly.m_symbolList.containsKey(clave)) {
486
				//si no esta creado el simbolo se crea
487
				theSymbol = new FSymbol(lyrPolygons.m_shapeType);				
488
				theSymbol.m_Descrip = clave.toString();
489
				theSymbol.m_Color = m_DgnReader.DGNLookupColor(rs.getFieldValueAsNumber(ID_FIELD_COLOR).intValue());
490
				rendererPoly.addSymbol(clave, theSymbol);								
491
			}
492
			
493
			lyrPolygons.m_legendValues[j] = rs.getFieldValueAsString(ID_FIELD_COLOR);
494
		} // for
495
    	*/
496
    }
497

  
498

  
499
    /**
500
	 * @see com.hardcode.driverManager.Driver#getType()
501
	 */
502
	public String getName() {
503
		return "gvSIG DGN Memory Driver";
504
	}
505

  
506
	/**
507
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
508
	 */
509
	public boolean accept(File f) {
510
		return f.getName().toUpperCase().endsWith("DGN");
511
	}
512

  
513
}
0 514

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dgn/DGNDriver.java
36 36
	private String path;
37 37
	private File m_Fich;
38 38

  
39
	// Campos del registro en cache:
40
	Object [] auxRow = new Object[7];
41
	Object [] cellRow = new Object[7];
42
	Object [] complexRow = new Object[7];
43
	
44
	/**
45
	 * Traduce las posiciones de comienzo de las entidades del DGN
46
	 * a nuestras entidades FShape. (Una FShape puede corresponder
47
	 * a varias entidades de un DGN).
48
	 */
49
	private int[] m_posShapes;
50

  
51
	
39 52
    /**
40 53
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
41 54
     */
......
62 75
		int nClass; // Para filtrar los elementos de construcci?n, etc.
63 76
		
64 77
		
65
		// Campos de las MemoryLayer:
66
		Object [] auxRow = new Object[4];
67
		Object [] cellRow = new Object[4];
68
		Object [] complexRow = new Object[4];
69 78
		ArrayList arrayFields = new ArrayList();
70 79
		arrayFields.add("ID");
71 80
		arrayFields.add("Entity");
72 81
		arrayFields.add("Layer");
73 82
		arrayFields.add("Color");
83
		arrayFields.add("HeightText");
84
		arrayFields.add("RotationText");
85
		arrayFields.add("Text");
74 86
		
75 87
		IGeometry aux;
76 88
		GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);

Also available in: Unified diff