root / tags / v1_0_2_Build_895 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dgn / DgnMemoryDriver.java @ 10328
History | View | Annotate | Download (21.8 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.io.IOException; |
59 |
import java.util.ArrayList; |
60 |
|
61 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
62 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
63 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
64 |
import com.hardcode.gdbms.engine.values.IntValue; |
65 |
import com.hardcode.gdbms.engine.values.Value; |
66 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
67 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
68 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
69 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
70 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
71 |
import com.iver.cit.gvsig.fmap.core.FShape; |
72 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
73 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
74 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
75 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
76 |
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver; |
77 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
78 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
79 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
80 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
81 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
82 |
|
83 |
|
84 |
/**
|
85 |
* Driver DGN que trabaja directamente cargando el fichero en memoria.
|
86 |
*
|
87 |
* @author Vicente Caballero Navarro
|
88 |
*/
|
89 |
public class DgnMemoryDriver extends MemoryDriver implements VectorialFileDriver, WithDefaultLegend { |
90 |
private final int ID_FIELD_ID = 0; |
91 |
private final int ID_FIELD_ENTITY = 1; |
92 |
private final int ID_FIELD_LAYER = 2; |
93 |
private final int ID_FIELD_COLOR = 3; |
94 |
private final int ID_FIELD_HEIGHTTEXT = 4; |
95 |
private final int ID_FIELD_ROTATIONTEXT = 5; |
96 |
private final int ID_FIELD_TEXT = 6; |
97 |
DGNReader m_DgnReader; |
98 |
VectorialUniqueValueLegend defaultLegend; |
99 |
private String path; |
100 |
private File m_Fich; |
101 |
private DriverAttributes attr = new DriverAttributes(); |
102 |
|
103 |
/**
|
104 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
105 |
*/
|
106 |
public void open(File f) throws IOException { |
107 |
m_Fich = f; |
108 |
} |
109 |
|
110 |
/**
|
111 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
112 |
*/
|
113 |
public void initialize() throws IOException { |
114 |
float heightText = 10; |
115 |
|
116 |
attr.setLoadedInMemory(true);
|
117 |
|
118 |
m_DgnReader = new DGNReader(m_Fich.getAbsolutePath());
|
119 |
|
120 |
Value[] auxRow = new Value[7]; |
121 |
Value[] cellRow = new Value[7]; |
122 |
Value[] complexRow = new Value[7]; |
123 |
ArrayList arrayFields = new ArrayList(); |
124 |
arrayFields.add("ID");
|
125 |
arrayFields.add("Entity");
|
126 |
arrayFields.add("Layer");
|
127 |
arrayFields.add("Color");
|
128 |
arrayFields.add("HeightText");
|
129 |
arrayFields.add("RotationText");
|
130 |
arrayFields.add("Text");
|
131 |
|
132 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
133 |
|
134 |
// Ahora las rellenamos.
|
135 |
FShape aux; |
136 |
boolean bElementoCompuesto = false; |
137 |
boolean bEsPoligono = false; |
138 |
boolean bInsideCell = false; |
139 |
boolean bFirstHoleEntity = false; |
140 |
boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas |
141 |
int contadorSubElementos = 0; |
142 |
int numSubElementos = 0; |
143 |
int complex_index_fill_color = -1; |
144 |
int nClass; // Para filtrar los elementos de construcci?n, etc. |
145 |
GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
146 |
|
147 |
for (int id = 0; id < m_DgnReader.getNumEntities(); id++) { |
148 |
// System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
|
149 |
m_DgnReader.DGNGotoElement(id); |
150 |
|
151 |
DGNElemCore elemento = m_DgnReader.DGNReadElement(); |
152 |
nClass = 0;
|
153 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
|
154 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
|
155 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
156 |
|
157 |
if (elemento.properties != 0) { |
158 |
nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS; |
159 |
} |
160 |
|
161 |
if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento |
162 |
{ |
163 |
aux = null;
|
164 |
|
165 |
// if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
|
166 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
|
167 |
if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) ||
|
168 |
(elemento.stype == DGNFileHeader.DGNST_ARC) || |
169 |
(elemento.stype == DGNFileHeader.DGNST_CELL_HEADER) || |
170 |
(elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN) || |
171 |
(elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER)) { |
172 |
if (elemento.complex != 0) { |
173 |
bElementoCompuesto = true;
|
174 |
} else {
|
175 |
if (bElementoCompuesto) {
|
176 |
if (bInsideCell) {
|
177 |
auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY]; |
178 |
} else {
|
179 |
auxRow = complexRow; |
180 |
} |
181 |
|
182 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
183 |
addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
184 |
|
185 |
if (bEsPoligono) {
|
186 |
if (complex_index_fill_color != -1) { |
187 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color); |
188 |
} |
189 |
|
190 |
addShape(new FPolygon2D(elementoCompuesto),
|
191 |
auxRow); |
192 |
} |
193 |
|
194 |
elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
195 |
} |
196 |
|
197 |
// System.err.println("Entidad simple");
|
198 |
bElementoCompuesto = false;
|
199 |
bEsPoligono = false;
|
200 |
bConnect = false;
|
201 |
|
202 |
// elementoCompuesto = new GeneralPathX();
|
203 |
bInsideCell = false;
|
204 |
} |
205 |
} |
206 |
|
207 |
switch (elemento.stype) {
|
208 |
case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
|
209 |
bInsideCell = true;
|
210 |
cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
211 |
cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
212 |
cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
213 |
cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
214 |
"Shared Cell");
|
215 |
|
216 |
break;
|
217 |
|
218 |
case DGNFileHeader.DGNST_CELL_HEADER:
|
219 |
bInsideCell = true;
|
220 |
|
221 |
DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento; |
222 |
cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
223 |
cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
224 |
cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
225 |
cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
226 |
"Cell");
|
227 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
228 |
|
229 |
// System.err.println("Cell Header " + complex_index_fill_color);
|
230 |
break;
|
231 |
|
232 |
case DGNFileHeader.DGNST_COMPLEX_HEADER:
|
233 |
|
234 |
// bElementoCompuesto = true;
|
235 |
// System.err.println("Complex Header");
|
236 |
contadorSubElementos = 0;
|
237 |
|
238 |
DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento; |
239 |
numSubElementos = psComplexHeader.numelems; |
240 |
complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
241 |
complexRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
242 |
complexRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
243 |
complexRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
244 |
"Complex");
|
245 |
|
246 |
if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
|
247 |
bEsPoligono = true;
|
248 |
|
249 |
// Si es un agujero, no conectamos con el anterior
|
250 |
if ((psComplexHeader.properties & 0x8000) != 0) { |
251 |
bFirstHoleEntity = true;
|
252 |
} else {
|
253 |
// Miramos si tiene color de relleno
|
254 |
// complex_index_fill_color = -1;
|
255 |
// if (elemento.attr_bytes > 0) {
|
256 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
257 |
|
258 |
// System.err.println("complex shape fill color = " + elemento.color);
|
259 |
// }
|
260 |
} |
261 |
|
262 |
bConnect = true;
|
263 |
} else {
|
264 |
bEsPoligono = false;
|
265 |
bConnect = false;
|
266 |
} |
267 |
|
268 |
break;
|
269 |
|
270 |
case DGNFileHeader.DGNST_MULTIPOINT:
|
271 |
|
272 |
// OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
|
273 |
// spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
|
274 |
// y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
|
275 |
// TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
|
276 |
// Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
|
277 |
// todav?a no est? metido.
|
278 |
DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento; |
279 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
280 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
281 |
|
282 |
if ((psLine.num_vertices == 2) && |
283 |
(psLine.vertices[0].x == psLine.vertices[1].x) && |
284 |
(psLine.vertices[0].y == psLine.vertices[1].y)) { |
285 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
286 |
"Point");
|
287 |
addShape(new FPoint3D(psLine.vertices[0].x, |
288 |
psLine.vertices[0].y, psLine.vertices[0].z), |
289 |
auxRow); |
290 |
} else {
|
291 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
292 |
|
293 |
if (psLine.type == DGNFileHeader.DGNT_CURVE) {
|
294 |
psLine.num_vertices = psLine.num_vertices - 4;
|
295 |
|
296 |
for (int aux_n = 0; |
297 |
aux_n < psLine.num_vertices; aux_n++) { |
298 |
psLine.vertices[aux_n] = psLine.vertices[aux_n + |
299 |
2];
|
300 |
} |
301 |
} |
302 |
|
303 |
if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
|
304 |
((psLine.properties & 0x8000) != 0)) { |
305 |
// Invertimos el orden porque es un agujero
|
306 |
elShape.moveTo(psLine.vertices[psLine.num_vertices - |
307 |
1].x,
|
308 |
psLine.vertices[psLine.num_vertices - 1].y);
|
309 |
|
310 |
for (int i = psLine.num_vertices - 2; i >= 0; |
311 |
i--) |
312 |
elShape.lineTo(psLine.vertices[i].x, |
313 |
psLine.vertices[i].y); |
314 |
} else {
|
315 |
elShape.moveTo(psLine.vertices[0].x,
|
316 |
psLine.vertices[0].y);
|
317 |
|
318 |
for (int i = 1; i < psLine.num_vertices; i++) |
319 |
elShape.lineTo(psLine.vertices[i].x, |
320 |
psLine.vertices[i].y); |
321 |
} |
322 |
|
323 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
324 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
325 |
"Multipoint");
|
326 |
|
327 |
if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices - |
328 |
1].x) &&
|
329 |
(psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
|
330 |
1].y)) {
|
331 |
// Lo a?adimos tambi?n como pol?gono
|
332 |
bEsPoligono = true;
|
333 |
|
334 |
// Miramos si tiene color de relleno
|
335 |
if (elemento.attr_bytes > 0) { |
336 |
elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
337 |
|
338 |
// System.err.println("fill color = " + elemento.color);
|
339 |
if (elemento.color != -1) { |
340 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
341 |
} |
342 |
} |
343 |
|
344 |
if (elemento.complex == 0) { |
345 |
addShape(new FPolygon2D(elShape), auxRow);
|
346 |
} |
347 |
} |
348 |
|
349 |
if (elemento.complex != 0) { |
350 |
// Si es un agujero o
|
351 |
// es la primera entidad del agujero, lo a?adimos sin unir al anterior
|
352 |
if (bFirstHoleEntity ||
|
353 |
((psLine.type == DGNFileHeader.DGNT_SHAPE) && |
354 |
((psLine.properties & 0x8000) != 0))) { |
355 |
elementoCompuesto.append(elShape, false);
|
356 |
bFirstHoleEntity = false;
|
357 |
} else {
|
358 |
elementoCompuesto.append(elShape, bConnect); |
359 |
} |
360 |
} else {
|
361 |
addShape(new FPolyline2D(elShape), auxRow);
|
362 |
} |
363 |
} |
364 |
|
365 |
break;
|
366 |
|
367 |
case DGNFileHeader.DGNST_ARC:
|
368 |
|
369 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
|
370 |
DGNElemArc psArc = (DGNElemArc) elemento; |
371 |
|
372 |
// La definici?n de arco de MicroStation es distinta a la de Java.
|
373 |
// En el dgn el origin se entiende que es el centro del arco,
|
374 |
// y a la hora de crear un Arc2D las 2 primeras coordenadas son
|
375 |
// la esquina inferior izquierda del rect?ngulo que rodea al arco.
|
376 |
// 1.- Creamos la elipse sin rotaci?n.
|
377 |
// 2.- Creamos el arco
|
378 |
// 3.- Rotamos el resultado
|
379 |
|
380 |
/* System.out.println("Arco con primari axis: " + psArc.primary_axis +
|
381 |
" start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
|
382 |
System.out.println("secondaria axis: " + psArc.secondary_axis +
|
383 |
" rotation = " + psArc.rotation); */
|
384 |
AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians( |
385 |
psArc.rotation), psArc.origin.x, |
386 |
psArc.origin.y); |
387 |
|
388 |
// mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
|
389 |
Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x - |
390 |
psArc.primary_axis, |
391 |
psArc.origin.y - psArc.secondary_axis, |
392 |
2.0 * psArc.primary_axis,
|
393 |
2.0 * psArc.secondary_axis, -psArc.startang,
|
394 |
-psArc.sweepang, Arc2D.OPEN);
|
395 |
|
396 |
// Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
|
397 |
// psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
|
398 |
GeneralPathX elShapeArc = new GeneralPathX(elArco);
|
399 |
|
400 |
// Transformamos el GeneralPahtX porque si transformamos elArco nos lo convierte
|
401 |
// a GeneralPath y nos guarda las coordenadas en float, con la correspondiente p?rdida de precisi?n
|
402 |
elShapeArc.transform(mT); |
403 |
|
404 |
if (m_DgnReader.getInfo().dimension == 3) { |
405 |
//Aqu? podr?amos hacer cosas con la coordenada Z
|
406 |
} |
407 |
|
408 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
409 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
410 |
"Arc");
|
411 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
412 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
413 |
|
414 |
/* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
|
415 |
psArc.origin.x + psArc.primary_axis, psArc.origin.y);
|
416 |
|
417 |
lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, new GeneralPathX(ejeMayor)), auxRow); */
|
418 |
|
419 |
// lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
|
420 |
if (elemento.complex != 0) { |
421 |
// Esto es una posible fuente de fallos si detr?s de una
|
422 |
// elipse vienen m?s cosas pegadas. Deber?amos volver
|
423 |
// a conectar una vez pasada la elipse.
|
424 |
if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
|
425 |
bConnect = false;
|
426 |
} |
427 |
|
428 |
// SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
|
429 |
// Y EL ELEMENTO ES UN POLIGONO
|
430 |
if (bFirstHoleEntity ||
|
431 |
((elemento.type == DGNFileHeader.DGNT_SHAPE) && |
432 |
((elemento.properties & 0x8000) != 0))) { |
433 |
elementoCompuesto.append(elShapeArc, false);
|
434 |
bFirstHoleEntity = false;
|
435 |
} else {
|
436 |
elementoCompuesto.append(elShapeArc, bConnect); |
437 |
} |
438 |
} else {
|
439 |
addShape(new FPolyline2D(elShapeArc), auxRow);
|
440 |
|
441 |
if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
|
442 |
addShape(new FPolygon2D(elShapeArc), auxRow);
|
443 |
} |
444 |
} |
445 |
|
446 |
// System.err.println("Entra un Arco");
|
447 |
break;
|
448 |
|
449 |
case DGNFileHeader.DGNST_TEXT:
|
450 |
|
451 |
DGNElemText psText = (DGNElemText) elemento; |
452 |
FPoint2D elShapeTxt = new FPoint3D(psText.origin.x,
|
453 |
psText.origin.y, psText.origin.z); |
454 |
|
455 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id); |
456 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue( |
457 |
"Text");
|
458 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level); |
459 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color); |
460 |
heightText = (float) psText.height_mult;
|
461 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText); |
462 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation); |
463 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
|
464 |
addShape(elShapeTxt, auxRow); |
465 |
|
466 |
// System.out.println("Rotaci?n texto: " + psText.rotation + "Altura Texto = " + heightText);
|
467 |
|
468 |
/* System.out.println(" origin=(" + psText.origin.x +
|
469 |
", " + psText.origin.y + ") rotation=" +
|
470 |
psText.rotation + "\n" + " font=" +
|
471 |
psText.font_id + " just=" +
|
472 |
psText.justification + "length_mult=" +
|
473 |
psText.length_mult + " height_mult=" +
|
474 |
psText.height_mult + "\n" + " string =" +
|
475 |
new String(psText.string).toString().trim() +
|
476 |
"\n"); */
|
477 |
break;
|
478 |
|
479 |
/* default:
|
480 |
m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
|
481 |
*/
|
482 |
} // switch
|
483 |
} // if
|
484 |
} // for
|
485 |
|
486 |
if (bElementoCompuesto) {
|
487 |
if (bInsideCell) {
|
488 |
auxRow = cellRow; |
489 |
} else {
|
490 |
auxRow = complexRow; |
491 |
} |
492 |
|
493 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
494 |
addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
495 |
|
496 |
if (bEsPoligono) {
|
497 |
if (complex_index_fill_color != -1) { |
498 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color); |
499 |
} |
500 |
|
501 |
addShape(new FPolygon2D(elementoCompuesto), auxRow);
|
502 |
} |
503 |
} |
504 |
|
505 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
506 |
defaultLegend.setFieldName("Color");
|
507 |
defaultLegend.setLabelField("Text");
|
508 |
FSymbol myDefaultSymbol = new FSymbol(getShapeType());
|
509 |
myDefaultSymbol.setShapeVisible(false);
|
510 |
myDefaultSymbol.setFontSizeInPixels(false);
|
511 |
myDefaultSymbol.setFont(new Font("SansSerif",Font.PLAIN, 9)); |
512 |
myDefaultSymbol.setFontColor(Color.BLACK);
|
513 |
myDefaultSymbol.setFontSize(heightText); |
514 |
myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
515 |
myDefaultSymbol.setSize(3);
|
516 |
myDefaultSymbol.setSizeInPixels(true);
|
517 |
|
518 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
519 |
|
520 |
defaultLegend.setLabelHeightField("HeightText");
|
521 |
defaultLegend.setLabelRotationField("RotationText");
|
522 |
|
523 |
ObjectDriver rs = this;
|
524 |
IntValue clave; |
525 |
FSymbol theSymbol = null;
|
526 |
|
527 |
try {
|
528 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
529 |
/* BufferedImage bi= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
530 |
Graphics2D big = bi.createGraphics();
|
531 |
Color color=new Color(0,0,0,0);
|
532 |
big.setBackground(color);
|
533 |
big.clearRect(0, 0, 1, 1);
|
534 |
Paint fillProv = null;
|
535 |
Rectangle2D rProv = new Rectangle();
|
536 |
rProv.setFrame(0, 0,1,1);
|
537 |
fillProv = new TexturePaint(bi,rProv); */
|
538 |
for (long j = 0; j < rs.getRowCount(); j++) { |
539 |
clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR); |
540 |
|
541 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
542 |
theSymbol = new FSymbol(getShapeType());
|
543 |
theSymbol.setDescription(clave.toString()); |
544 |
Color c = m_DgnReader.DGNLookupColor(
|
545 |
clave.getValue()); |
546 |
// Le ponemos transparencia para que los pol?gonos no
|
547 |
// tapen del todo. (Est? dentro del DGNLookupColor
|
548 |
// c.
|
549 |
theSymbol.setColor(c); |
550 |
// theSymbol.setFill(fillProv);
|
551 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
552 |
theSymbol.setSize(3);
|
553 |
theSymbol.setSizeInPixels(true);
|
554 |
|
555 |
// theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
|
556 |
defaultLegend.addSymbol(clave, theSymbol); |
557 |
} |
558 |
} // for
|
559 |
} catch (DriverException e) {
|
560 |
e.printStackTrace(); |
561 |
throw new IOException( |
562 |
"Error al poner la leyenda por defecto en el DGN");
|
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 DriverException { |
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 DriverException { |
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() throws IOException { |
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 |
} |