root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dgn / DgnMemoryDriver.java @ 10627
History | View | Annotate | Download (21.9 KB)
1 |
/* ALL THIS WORK ABOUT DGN IS BASED IN DGNLib, from Frank Warmerdam
|
---|---|
2 |
* It is a java port, and is incompleted, just to let gvSIG
|
3 |
* display DGN's. His DGNLib is more advanced, and must be
|
4 |
* used as reference.
|
5 |
* DGNLib: http://dgnlib.maptools.org/
|
6 |
*
|
7 |
* (Thanks, Frank :). For this, and for your very good job with
|
8 |
* shapefiles. And also for GDAL!!!!
|
9 |
*/
|
10 |
|
11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
12 |
*
|
13 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
14 |
*
|
15 |
* This program is free software; you can redistribute it and/or
|
16 |
* modify it under the terms of the GNU General Public License
|
17 |
* as published by the Free Software Foundation; either version 2
|
18 |
* of the License, or (at your option) any later version.
|
19 |
*
|
20 |
* This program is distributed in the hope that it will be useful,
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
* GNU General Public License for more details.
|
24 |
*
|
25 |
* You should have received a copy of the GNU General Public License
|
26 |
* along with this program; if not, write to the Free Software
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
28 |
*
|
29 |
* For more information, contact:
|
30 |
*
|
31 |
* Generalitat Valenciana
|
32 |
* Conselleria d'Infraestructures i Transport
|
33 |
* Av. Blasco Ib??ez, 50
|
34 |
* 46010 VALENCIA
|
35 |
* SPAIN
|
36 |
*
|
37 |
* +34 963862235
|
38 |
* gvsig@gva.es
|
39 |
* www.gvsig.gva.es
|
40 |
*
|
41 |
* or
|
42 |
*
|
43 |
* IVER T.I. S.A
|
44 |
* Salamanca 50
|
45 |
* 46005 Valencia
|
46 |
* Spain
|
47 |
*
|
48 |
* +34 963163400
|
49 |
* dac@iver.es
|
50 |
*/
|
51 |
package com.iver.cit.gvsig.fmap.drivers.dgn; |
52 |
|
53 |
import java.awt.Color; |
54 |
import java.awt.Font; |
55 |
import java.awt.geom.AffineTransform; |
56 |
import java.awt.geom.Arc2D; |
57 |
import java.io.File; |
58 |
import java.util.ArrayList; |
59 |
|
60 |
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
61 |
import com.hardcode.gdbms.driver.exceptions.OpenDriverException; |
62 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
63 |
import com.hardcode.gdbms.driver.exceptions.WriteDriverException; |
64 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
65 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
66 |
import com.hardcode.gdbms.engine.values.IntValue; |
67 |
import com.hardcode.gdbms.engine.values.Value; |
68 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
69 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
70 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
71 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
72 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
73 |
import com.iver.cit.gvsig.fmap.core.FShape; |
74 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
75 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
76 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
77 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
78 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
79 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
80 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
81 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
82 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
83 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
84 |
|
85 |
|
86 |
/**
|
87 |
* Driver DGN que trabaja directamente cargando el fichero en memoria.
|
88 |
*
|
89 |
* @author Vicente Caballero Navarro
|
90 |
*/
|
91 |
public class DgnMemoryDriver extends MemoryDriver implements VectorialFileDriver, WithDefaultLegend { |
92 |
private final int ID_FIELD_ID = 0; |
93 |
private final int ID_FIELD_ENTITY = 1; |
94 |
private final int ID_FIELD_LAYER = 2; |
95 |
private final int ID_FIELD_COLOR = 3; |
96 |
private final int ID_FIELD_HEIGHTTEXT = 4; |
97 |
private final int ID_FIELD_ROTATIONTEXT = 5; |
98 |
private final int ID_FIELD_TEXT = 6; |
99 |
DGNReader m_DgnReader; |
100 |
VectorialUniqueValueLegend defaultLegend; |
101 |
private String path; |
102 |
private File m_Fich; |
103 |
private DriverAttributes attr = new DriverAttributes(); |
104 |
|
105 |
/**
|
106 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
107 |
*/
|
108 |
public void open(File f) throws OpenDriverException { |
109 |
m_Fich = f; |
110 |
} |
111 |
|
112 |
/**
|
113 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
114 |
*/
|
115 |
public void initialize() throws InitializeDriverException { |
116 |
float heightText = 10; |
117 |
|
118 |
attr.setLoadedInMemory(true);
|
119 |
|
120 |
m_DgnReader = new DGNReader(m_Fich.getAbsolutePath());
|
121 |
|
122 |
Value[] auxRow = new Value[7]; |
123 |
Value[] cellRow = new Value[7]; |
124 |
Value[] complexRow = new Value[7]; |
125 |
ArrayList arrayFields = new ArrayList(); |
126 |
arrayFields.add("ID");
|
127 |
arrayFields.add("Entity");
|
128 |
arrayFields.add("Layer");
|
129 |
arrayFields.add("Color");
|
130 |
arrayFields.add("HeightText");
|
131 |
arrayFields.add("RotationText");
|
132 |
arrayFields.add("Text");
|
133 |
|
134 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
135 |
|
136 |
// Ahora las rellenamos.
|
137 |
FShape aux; |
138 |
boolean bElementoCompuesto = false; |
139 |
boolean bEsPoligono = false; |
140 |
boolean bInsideCell = false; |
141 |
boolean bFirstHoleEntity = false; |
142 |
boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas |
143 |
int contadorSubElementos = 0; |
144 |
int numSubElementos = 0; |
145 |
int complex_index_fill_color = -1; |
146 |
int nClass; // Para filtrar los elementos de construcci?n, etc. |
147 |
GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
148 |
|
149 |
for (int id = 0; id < m_DgnReader.getNumEntities(); id++) { |
150 |
// System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
|
151 |
m_DgnReader.DGNGotoElement(id); |
152 |
|
153 |
DGNElemCore elemento = m_DgnReader.DGNReadElement(); |
154 |
nClass = 0;
|
155 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
|
156 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
|
157 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
158 |
|
159 |
if (elemento.properties != 0) { |
160 |
nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS; |
161 |
} |
162 |
|
163 |
if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento |
164 |
{ |
165 |
aux = null;
|
166 |
|
167 |
// if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
|
168 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
|
169 |
if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) ||
|
170 |
(elemento.stype == DGNFileHeader.DGNST_ARC) || |
171 |
(elemento.stype == DGNFileHeader.DGNST_CELL_HEADER) || |
172 |
(elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN) || |
173 |
(elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER)) { |
174 |
if (elemento.complex != 0) { |
175 |
bElementoCompuesto = true;
|
176 |
} else {
|
177 |
if (bElementoCompuesto) {
|
178 |
if (bInsideCell) {
|
179 |
auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY]; |
180 |
} else {
|
181 |
auxRow = complexRow; |
182 |
} |
183 |
|
184 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
185 |
addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
186 |
|
187 |
if (bEsPoligono) {
|
188 |
if (complex_index_fill_color != -1) { |
189 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color); |
190 |
} |
191 |
|
192 |
addShape(new FPolygon2D(elementoCompuesto),
|
193 |
auxRow); |
194 |
} |
195 |
|
196 |
elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
197 |
} |
198 |
|
199 |
// System.err.println("Entidad simple");
|
200 |
bElementoCompuesto = false;
|
201 |
bEsPoligono = false;
|
202 |
bConnect = false;
|
203 |
|
204 |
// elementoCompuesto = new GeneralPathX();
|
205 |
bInsideCell = false;
|
206 |
} |
207 |
} |
208 |
|
209 |
switch (elemento.stype) {
|
210 |
case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
|
211 |
bInsideCell = true;
|
212 |
cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
213 |
cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
214 |
cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
215 |
cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
216 |
"Shared Cell");
|
217 |
|
218 |
break;
|
219 |
|
220 |
case DGNFileHeader.DGNST_CELL_HEADER:
|
221 |
bInsideCell = true;
|
222 |
|
223 |
DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento; |
224 |
cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
225 |
cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
226 |
cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
227 |
cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
228 |
"Cell");
|
229 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
230 |
|
231 |
// System.err.println("Cell Header " + complex_index_fill_color);
|
232 |
break;
|
233 |
|
234 |
case DGNFileHeader.DGNST_COMPLEX_HEADER:
|
235 |
|
236 |
// bElementoCompuesto = true;
|
237 |
// System.err.println("Complex Header");
|
238 |
contadorSubElementos = 0;
|
239 |
|
240 |
DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento; |
241 |
numSubElementos = psComplexHeader.numelems; |
242 |
complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
243 |
complexRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
244 |
complexRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
245 |
complexRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
246 |
"Complex");
|
247 |
|
248 |
if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
|
249 |
bEsPoligono = true;
|
250 |
|
251 |
// Si es un agujero, no conectamos con el anterior
|
252 |
if ((psComplexHeader.properties & 0x8000) != 0) { |
253 |
bFirstHoleEntity = true;
|
254 |
} else {
|
255 |
// Miramos si tiene color de relleno
|
256 |
// complex_index_fill_color = -1;
|
257 |
// if (elemento.attr_bytes > 0) {
|
258 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
259 |
|
260 |
// System.err.println("complex shape fill color = " + elemento.color);
|
261 |
// }
|
262 |
} |
263 |
|
264 |
bConnect = true;
|
265 |
} else {
|
266 |
bEsPoligono = false;
|
267 |
bConnect = false;
|
268 |
} |
269 |
|
270 |
break;
|
271 |
|
272 |
case DGNFileHeader.DGNST_MULTIPOINT:
|
273 |
|
274 |
// OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
|
275 |
// spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
|
276 |
// y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
|
277 |
// TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
|
278 |
// Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
|
279 |
// todav?a no est? metido.
|
280 |
DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento; |
281 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
282 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
283 |
|
284 |
if ((psLine.num_vertices == 2) && |
285 |
(psLine.vertices[0].x == psLine.vertices[1].x) && |
286 |
(psLine.vertices[0].y == psLine.vertices[1].y)) { |
287 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
288 |
"Point");
|
289 |
addShape(new FPoint3D(psLine.vertices[0].x, |
290 |
psLine.vertices[0].y, psLine.vertices[0].z), |
291 |
auxRow); |
292 |
} else {
|
293 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
294 |
|
295 |
if (psLine.type == DGNFileHeader.DGNT_CURVE) {
|
296 |
psLine.num_vertices = psLine.num_vertices - 4;
|
297 |
|
298 |
for (int aux_n = 0; |
299 |
aux_n < psLine.num_vertices; aux_n++) { |
300 |
psLine.vertices[aux_n] = psLine.vertices[aux_n + |
301 |
2];
|
302 |
} |
303 |
} |
304 |
|
305 |
if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
|
306 |
((psLine.properties & 0x8000) != 0)) { |
307 |
// Invertimos el orden porque es un agujero
|
308 |
elShape.moveTo(psLine.vertices[psLine.num_vertices - |
309 |
1].x,
|
310 |
psLine.vertices[psLine.num_vertices - 1].y);
|
311 |
|
312 |
for (int i = psLine.num_vertices - 2; i >= 0; |
313 |
i--) |
314 |
elShape.lineTo(psLine.vertices[i].x, |
315 |
psLine.vertices[i].y); |
316 |
} else {
|
317 |
elShape.moveTo(psLine.vertices[0].x,
|
318 |
psLine.vertices[0].y);
|
319 |
|
320 |
for (int i = 1; i < psLine.num_vertices; i++) |
321 |
elShape.lineTo(psLine.vertices[i].x, |
322 |
psLine.vertices[i].y); |
323 |
} |
324 |
|
325 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
326 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
327 |
"Multipoint");
|
328 |
|
329 |
if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices - |
330 |
1].x) &&
|
331 |
(psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
|
332 |
1].y)) {
|
333 |
// Lo a?adimos tambi?n como pol?gono
|
334 |
bEsPoligono = true;
|
335 |
|
336 |
// Miramos si tiene color de relleno
|
337 |
if (elemento.attr_bytes > 0) { |
338 |
elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
339 |
|
340 |
// System.err.println("fill color = " + elemento.color);
|
341 |
if (elemento.color != -1) { |
342 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
343 |
} |
344 |
} |
345 |
|
346 |
if (elemento.complex == 0) { |
347 |
addShape(new FPolygon2D(elShape), auxRow);
|
348 |
} |
349 |
} |
350 |
|
351 |
if (elemento.complex != 0) { |
352 |
// Si es un agujero o
|
353 |
// es la primera entidad del agujero, lo a?adimos sin unir al anterior
|
354 |
if (bFirstHoleEntity ||
|
355 |
((psLine.type == DGNFileHeader.DGNT_SHAPE) && |
356 |
((psLine.properties & 0x8000) != 0))) { |
357 |
elementoCompuesto.append(elShape, false);
|
358 |
bFirstHoleEntity = false;
|
359 |
} else {
|
360 |
elementoCompuesto.append(elShape, bConnect); |
361 |
} |
362 |
} else {
|
363 |
addShape(new FPolyline2D(elShape), auxRow);
|
364 |
} |
365 |
} |
366 |
|
367 |
break;
|
368 |
|
369 |
case DGNFileHeader.DGNST_ARC:
|
370 |
|
371 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
|
372 |
DGNElemArc psArc = (DGNElemArc) elemento; |
373 |
|
374 |
// La definici?n de arco de MicroStation es distinta a la de Java.
|
375 |
// En el dgn el origin se entiende que es el centro del arco,
|
376 |
// y a la hora de crear un Arc2D las 2 primeras coordenadas son
|
377 |
// la esquina inferior izquierda del rect?ngulo que rodea al arco.
|
378 |
// 1.- Creamos la elipse sin rotaci?n.
|
379 |
// 2.- Creamos el arco
|
380 |
// 3.- Rotamos el resultado
|
381 |
|
382 |
/* System.out.println("Arco con primari axis: " + psArc.primary_axis +
|
383 |
" start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
|
384 |
System.out.println("secondaria axis: " + psArc.secondary_axis +
|
385 |
" rotation = " + psArc.rotation); */
|
386 |
AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians( |
387 |
psArc.rotation), psArc.origin.x, |
388 |
psArc.origin.y); |
389 |
|
390 |
// mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
|
391 |
Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x - |
392 |
psArc.primary_axis, |
393 |
psArc.origin.y - psArc.secondary_axis, |
394 |
2.0 * psArc.primary_axis,
|
395 |
2.0 * psArc.secondary_axis, -psArc.startang,
|
396 |
-psArc.sweepang, Arc2D.OPEN);
|
397 |
|
398 |
// Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
|
399 |
// psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
|
400 |
GeneralPathX elShapeArc = new GeneralPathX(elArco);
|
401 |
|
402 |
// Transformamos el GeneralPahtX porque si transformamos elArco nos lo convierte
|
403 |
// a GeneralPath y nos guarda las coordenadas en float, con la correspondiente p?rdida de precisi?n
|
404 |
elShapeArc.transform(mT); |
405 |
|
406 |
if (m_DgnReader.getInfo().dimension == 3) { |
407 |
//Aqu? podr?amos hacer cosas con la coordenada Z
|
408 |
} |
409 |
|
410 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
411 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
412 |
"Arc");
|
413 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
414 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
415 |
|
416 |
/* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
|
417 |
psArc.origin.x + psArc.primary_axis, psArc.origin.y);
|
418 |
|
419 |
lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, new GeneralPathX(ejeMayor)), auxRow); */
|
420 |
|
421 |
// lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
|
422 |
if (elemento.complex != 0) { |
423 |
// Esto es una posible fuente de fallos si detr?s de una
|
424 |
// elipse vienen m?s cosas pegadas. Deber?amos volver
|
425 |
// a conectar una vez pasada la elipse.
|
426 |
if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
|
427 |
bConnect = false;
|
428 |
} |
429 |
|
430 |
// SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
|
431 |
// Y EL ELEMENTO ES UN POLIGONO
|
432 |
if (bFirstHoleEntity ||
|
433 |
((elemento.type == DGNFileHeader.DGNT_SHAPE) && |
434 |
((elemento.properties & 0x8000) != 0))) { |
435 |
elementoCompuesto.append(elShapeArc, false);
|
436 |
bFirstHoleEntity = false;
|
437 |
} else {
|
438 |
elementoCompuesto.append(elShapeArc, bConnect); |
439 |
} |
440 |
} else {
|
441 |
addShape(new FPolyline2D(elShapeArc), auxRow);
|
442 |
|
443 |
if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
|
444 |
addShape(new FPolygon2D(elShapeArc), auxRow);
|
445 |
} |
446 |
} |
447 |
|
448 |
// System.err.println("Entra un Arco");
|
449 |
break;
|
450 |
|
451 |
case DGNFileHeader.DGNST_TEXT:
|
452 |
|
453 |
DGNElemText psText = (DGNElemText) elemento; |
454 |
FPoint2D elShapeTxt = new FPoint3D(psText.origin.x,
|
455 |
psText.origin.y, psText.origin.z); |
456 |
|
457 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
458 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
459 |
"Text");
|
460 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
461 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
462 |
heightText = (float) psText.height_mult;
|
463 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText); |
464 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation); |
465 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
|
466 |
addShape(elShapeTxt, auxRow); |
467 |
|
468 |
// System.out.println("Rotaci?n texto: " + psText.rotation + "Altura Texto = " + heightText);
|
469 |
|
470 |
/* System.out.println(" origin=(" + psText.origin.x +
|
471 |
", " + psText.origin.y + ") rotation=" +
|
472 |
psText.rotation + "\n" + " font=" +
|
473 |
psText.font_id + " just=" +
|
474 |
psText.justification + "length_mult=" +
|
475 |
psText.length_mult + " height_mult=" +
|
476 |
psText.height_mult + "\n" + " string =" +
|
477 |
new String(psText.string).toString().trim() +
|
478 |
"\n"); */
|
479 |
break;
|
480 |
|
481 |
/* default:
|
482 |
m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
|
483 |
*/
|
484 |
} // switch
|
485 |
} // if
|
486 |
} // for
|
487 |
|
488 |
if (bElementoCompuesto) {
|
489 |
if (bInsideCell) {
|
490 |
auxRow = cellRow; |
491 |
} else {
|
492 |
auxRow = complexRow; |
493 |
} |
494 |
|
495 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
496 |
addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
497 |
|
498 |
if (bEsPoligono) {
|
499 |
if (complex_index_fill_color != -1) { |
500 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color); |
501 |
} |
502 |
|
503 |
addShape(new FPolygon2D(elementoCompuesto), auxRow);
|
504 |
} |
505 |
} |
506 |
|
507 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
508 |
defaultLegend.setFieldName("Color");
|
509 |
defaultLegend.setLabelField("Text");
|
510 |
FSymbol myDefaultSymbol = new FSymbol(getShapeType());
|
511 |
myDefaultSymbol.setShapeVisible(false);
|
512 |
myDefaultSymbol.setFontSizeInPixels(false);
|
513 |
myDefaultSymbol.setFont(new Font("SansSerif",Font.PLAIN, 9)); |
514 |
myDefaultSymbol.setFontColor(Color.BLACK);
|
515 |
myDefaultSymbol.setFontSize(heightText); |
516 |
myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
517 |
myDefaultSymbol.setSize(3);
|
518 |
myDefaultSymbol.setSizeInPixels(true);
|
519 |
|
520 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
521 |
|
522 |
defaultLegend.setLabelHeightField("HeightText");
|
523 |
defaultLegend.setLabelRotationField("RotationText");
|
524 |
|
525 |
ObjectDriver rs = this;
|
526 |
IntValue clave; |
527 |
FSymbol theSymbol = null;
|
528 |
|
529 |
try {
|
530 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
531 |
/* BufferedImage bi= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
532 |
Graphics2D big = bi.createGraphics();
|
533 |
Color color=new Color(0,0,0,0);
|
534 |
big.setBackground(color);
|
535 |
big.clearRect(0, 0, 1, 1);
|
536 |
Paint fillProv = null;
|
537 |
Rectangle2D rProv = new Rectangle();
|
538 |
rProv.setFrame(0, 0,1,1);
|
539 |
fillProv = new TexturePaint(bi,rProv); */
|
540 |
for (long j = 0; j < rs.getRowCount(); j++) { |
541 |
clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR); |
542 |
|
543 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
544 |
theSymbol = new FSymbol(getShapeType());
|
545 |
theSymbol.setDescription(clave.toString()); |
546 |
Color c = m_DgnReader.DGNLookupColor(
|
547 |
clave.getValue()); |
548 |
// Le ponemos transparencia para que los pol?gonos no
|
549 |
// tapen del todo. (Est? dentro del DGNLookupColor
|
550 |
// c.
|
551 |
theSymbol.setColor(c); |
552 |
// theSymbol.setFill(fillProv);
|
553 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
554 |
theSymbol.setSize(3);
|
555 |
theSymbol.setSizeInPixels(true);
|
556 |
|
557 |
// theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
|
558 |
defaultLegend.addSymbol(clave, theSymbol); |
559 |
} |
560 |
} // for
|
561 |
} catch (ReadDriverException e) {
|
562 |
throw new InitializeDriverException(getName(),e); |
563 |
} |
564 |
} |
565 |
|
566 |
/**
|
567 |
* Devuelve el tipo de shape que contiene el formato DGN.
|
568 |
*
|
569 |
* @return Entero que representa el tipo de shape.
|
570 |
*/
|
571 |
public int getShapeType() { |
572 |
return FShape.MULTI;
|
573 |
} |
574 |
|
575 |
/**
|
576 |
* @see com.hardcode.driverManager.Driver#getType()
|
577 |
*/
|
578 |
public String getName() { |
579 |
return "gvSIG DGN Memory Driver"; |
580 |
} |
581 |
|
582 |
/**
|
583 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
584 |
*/
|
585 |
public boolean accept(File f) { |
586 |
return f.getName().toUpperCase().endsWith("DGN"); |
587 |
} |
588 |
|
589 |
/* (non-Javadoc)
|
590 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
591 |
*/
|
592 |
public Legend getDefaultLegend() {
|
593 |
return defaultLegend;
|
594 |
} |
595 |
|
596 |
/* (non-Javadoc)
|
597 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
598 |
*/
|
599 |
public DriverAttributes getDriverAttributes() {
|
600 |
return attr;
|
601 |
} |
602 |
|
603 |
/**
|
604 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
605 |
*/
|
606 |
public int[] getPrimaryKeys() throws ReadDriverException { |
607 |
return null; |
608 |
} |
609 |
|
610 |
/**
|
611 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
612 |
*/
|
613 |
public void write(DataWare arg0) throws WriteDriverException { |
614 |
// TODO Auto-generated method stub
|
615 |
|
616 |
} |
617 |
|
618 |
/* (non-Javadoc)
|
619 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
620 |
*/
|
621 |
public void close() { |
622 |
// TODO Auto-generated method stub
|
623 |
|
624 |
} |
625 |
|
626 |
public File getFile() { |
627 |
return m_Fich;
|
628 |
} |
629 |
|
630 |
public boolean isWritable() { |
631 |
return m_Fich.canWrite();
|
632 |
} |
633 |
|
634 |
} |