root / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / fmap / data / feature / file / dgn / DGNResource.java @ 23303
History | View | Annotate | Download (26.1 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.fmap.data.feature.file.dgn; |
32 |
|
33 |
import java.awt.geom.AffineTransform; |
34 |
import java.awt.geom.Arc2D; |
35 |
import java.util.HashMap; |
36 |
import java.util.Map; |
37 |
|
38 |
import org.gvsig.fmap.data.DataException; |
39 |
import org.gvsig.fmap.data.OpenException; |
40 |
import org.gvsig.fmap.data.ReadException; |
41 |
import org.gvsig.fmap.data.feature.Feature; |
42 |
import org.gvsig.fmap.data.feature.FeatureType; |
43 |
import org.gvsig.fmap.data.feature.IsNotFeatureSettingException; |
44 |
import org.gvsig.fmap.data.feature.file.FileMemoryResource; |
45 |
import org.gvsig.fmap.data.feature.file.FileStoreParameters; |
46 |
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemArc; |
47 |
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemComplexHeader; |
48 |
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemCore; |
49 |
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemMultiPoint; |
50 |
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemText; |
51 |
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNFileHeader; |
52 |
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNReader; |
53 |
import org.gvsig.fmap.data.feature.operation.LegendLabelingManager; |
54 |
import org.gvsig.fmap.data.feature.operation.LegendLabelingManagerFactory; |
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.geom.GeometryFactory; |
57 |
import org.gvsig.fmap.geom.GeometryManager; |
58 |
import org.gvsig.fmap.geom.primitive.Envelope; |
59 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
60 |
|
61 |
/**
|
62 |
* @author jmvivo
|
63 |
*
|
64 |
*/
|
65 |
public class DGNResource extends FileMemoryResource { |
66 |
private static LegendLabelingManagerFactory legendLabelingManagerFactory = null; |
67 |
|
68 |
public static final int ID_FIELD_ID = 0; |
69 |
public static final int ID_FIELD_ENTITY = 1; |
70 |
public static final int ID_FIELD_LAYER = 2; |
71 |
public static final int ID_FIELD_COLOR = 3; |
72 |
public static final int ID_FIELD_HEIGHTTEXT = 4; |
73 |
public static final int ID_FIELD_ROTATIONTEXT = 5; |
74 |
public static final int ID_FIELD_TEXT = 6; |
75 |
public static final int ID_FIELD_GEOMETRY = 7; |
76 |
|
77 |
|
78 |
private FeatureType featureType;
|
79 |
|
80 |
private LegendLabelingManager legendlabelingManager;
|
81 |
|
82 |
/**
|
83 |
* @param params
|
84 |
*/
|
85 |
DGNResource(FileStoreParameters params) { |
86 |
super(params);
|
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see org.gvsig.fmap.data.Resource#getName()
|
91 |
*/
|
92 |
public String getName() { |
93 |
return "DGN"; |
94 |
} |
95 |
|
96 |
private void initializeFeatureType() throws DataException { |
97 |
this.featureType= DGNStore.newFeatureType();
|
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#load()
|
102 |
*/
|
103 |
protected void load() throws DataException { |
104 |
float heightText = 10; |
105 |
// attr.setLoadedInMemory(true);
|
106 |
initializeFeatureType(); |
107 |
DGNReader m_DgnReader; |
108 |
GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory(); |
109 |
try {
|
110 |
m_DgnReader = new DGNReader(this.getFile().getAbsolutePath()); |
111 |
} catch (ReadException e) {
|
112 |
throw new OpenException(this.description(),e); |
113 |
} |
114 |
if (legendLabelingManagerFactory != null) { |
115 |
legendlabelingManager = legendLabelingManagerFactory.newManager(); |
116 |
Map params = new HashMap(); |
117 |
params.put("reader", m_DgnReader);
|
118 |
legendlabelingManager.startLoading(params); |
119 |
} else {
|
120 |
legendlabelingManager = null;
|
121 |
} |
122 |
|
123 |
try{
|
124 |
// Value[] auxRow = new Value[7];
|
125 |
// Value[] cellRow = new Value[7];
|
126 |
// Value[] complexRow = new Value[7];
|
127 |
DGNFeature auxFeature=new DGNFeature(featureType,true); |
128 |
auxFeature.loading(); |
129 |
DGNFeature cellFeature=new DGNFeature(featureType,false); |
130 |
cellFeature.loading(); |
131 |
DGNFeature complexFeature=new DGNFeature(featureType,false); |
132 |
complexFeature.loading(); |
133 |
initializeFeatureType(); |
134 |
// ArrayList arrayFields = new ArrayList();
|
135 |
// arrayFields.add("ID");
|
136 |
// arrayFields.add("Entity");
|
137 |
// arrayFields.add("Layer");
|
138 |
// arrayFields.add("Color");
|
139 |
// arrayFields.add("HeightText");
|
140 |
// arrayFields.add("RotationText");
|
141 |
// arrayFields.add("Text");
|
142 |
|
143 |
// getTableModel().setColumnIdentifiers(arrayFields.toArray());
|
144 |
|
145 |
|
146 |
// Ahora las rellenamos.
|
147 |
// FShape aux;
|
148 |
boolean bElementoCompuesto = false; |
149 |
boolean bEsPoligono = false; |
150 |
boolean bInsideCell = false; |
151 |
boolean bFirstHoleEntity = false; |
152 |
boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas |
153 |
// int contadorSubElementos = 0;
|
154 |
// int numSubElementos = 0;
|
155 |
int complex_index_fill_color = -1; |
156 |
int nClass; // Para filtrar los elementos de construcci?n, etc. |
157 |
GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
158 |
|
159 |
for (int id = 0; id < m_DgnReader.getNumEntities(); id++) { |
160 |
|
161 |
// System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
|
162 |
m_DgnReader.DGNGotoElement(id); |
163 |
|
164 |
DGNElemCore elemento = m_DgnReader.DGNReadElement(); |
165 |
nClass = 0;
|
166 |
// auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
|
167 |
auxFeature.set(ID_FIELD_HEIGHTTEXT, 0);
|
168 |
// auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
|
169 |
auxFeature.set(ID_FIELD_ROTATIONTEXT, 0);
|
170 |
// auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
|
171 |
auxFeature.set(ID_FIELD_TEXT, null);
|
172 |
|
173 |
if (elemento.properties != 0) { |
174 |
nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS; |
175 |
} |
176 |
|
177 |
if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento |
178 |
{ |
179 |
// aux = null;
|
180 |
|
181 |
// if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
|
182 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
|
183 |
if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) ||
|
184 |
(elemento.stype == DGNFileHeader.DGNST_ARC) || |
185 |
(elemento.stype == DGNFileHeader.DGNST_CELL_HEADER) || |
186 |
(elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN) || |
187 |
(elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER)) { |
188 |
if (elemento.complex != 0) { |
189 |
bElementoCompuesto = true;
|
190 |
} else {
|
191 |
if (bElementoCompuesto) {
|
192 |
if (bInsideCell) {
|
193 |
auxFeature.set(ID_FIELD_ENTITY,cellFeature.get(ID_FIELD_ENTITY)); |
194 |
// auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY];
|
195 |
} else {
|
196 |
auxFeature=complexFeature; |
197 |
// auxRow = complexRow;
|
198 |
} |
199 |
|
200 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
201 |
Geometry geom=gFactory.createPolyline2D(elementoCompuesto); |
202 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
203 |
// auxFeature.setDefaultGeometry(geom);
|
204 |
addDGNFeature(auxFeature); |
205 |
// addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
206 |
|
207 |
if (bEsPoligono) {
|
208 |
if (complex_index_fill_color != -1) { |
209 |
auxFeature.set(ID_FIELD_COLOR,complex_index_fill_color); |
210 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
|
211 |
} |
212 |
geom=gFactory.createPolygon2D(elementoCompuesto); |
213 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
214 |
// auxFeature.setDefaultGeometry(geom);
|
215 |
addDGNFeature(auxFeature); |
216 |
// addShape(new FPolygon2D(elementoCompuesto), auxRow);
|
217 |
} |
218 |
|
219 |
elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
220 |
} |
221 |
|
222 |
// System.err.println("Entidad simple");
|
223 |
bElementoCompuesto = false;
|
224 |
bEsPoligono = false;
|
225 |
bConnect = false;
|
226 |
|
227 |
// elementoCompuesto = new GeneralPathX();
|
228 |
bInsideCell = false;
|
229 |
} |
230 |
} |
231 |
|
232 |
switch (elemento.stype) {
|
233 |
case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
|
234 |
bInsideCell = true;
|
235 |
cellFeature.set(ID_FIELD_ID,elemento.element_id); |
236 |
// cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
237 |
cellFeature.set(ID_FIELD_LAYER,elemento.level); |
238 |
// cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
239 |
cellFeature.set(ID_FIELD_COLOR,elemento.color); |
240 |
// cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
241 |
cellFeature.set(ID_FIELD_ENTITY,"Shared Cell");
|
242 |
// cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
243 |
// "Shared Cell");
|
244 |
|
245 |
break;
|
246 |
|
247 |
case DGNFileHeader.DGNST_CELL_HEADER:
|
248 |
bInsideCell = true;
|
249 |
|
250 |
// DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento;
|
251 |
cellFeature.set(ID_FIELD_ID,elemento.element_id); |
252 |
// cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
253 |
cellFeature.set(ID_FIELD_LAYER,elemento.level); |
254 |
// cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
255 |
cellFeature.set(ID_FIELD_COLOR,elemento.color); |
256 |
// cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
257 |
cellFeature.set(ID_FIELD_ENTITY,"Cell");
|
258 |
// cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
259 |
// "Cell");
|
260 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
261 |
|
262 |
// System.err.println("Cell Header " + complex_index_fill_color);
|
263 |
break;
|
264 |
|
265 |
case DGNFileHeader.DGNST_COMPLEX_HEADER:
|
266 |
|
267 |
// bElementoCompuesto = true;
|
268 |
// System.err.println("Complex Header");
|
269 |
// contadorSubElementos = 0;
|
270 |
|
271 |
DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento; |
272 |
// numSubElementos = psComplexHeader.numelems;
|
273 |
complexFeature.set(ID_FIELD_ID,elemento.element_id); |
274 |
// complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
275 |
complexFeature.set(ID_FIELD_LAYER,elemento.level); |
276 |
// complexRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
277 |
complexFeature.set(ID_FIELD_COLOR,elemento.color); |
278 |
// complexRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
279 |
complexFeature.set(ID_FIELD_ENTITY,"Complex");
|
280 |
// complexRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
281 |
// "Complex");
|
282 |
|
283 |
if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
|
284 |
bEsPoligono = true;
|
285 |
|
286 |
// Si es un agujero, no conectamos con el anterior
|
287 |
if ((psComplexHeader.properties & 0x8000) != 0) { |
288 |
bFirstHoleEntity = true;
|
289 |
} else {
|
290 |
// Miramos si tiene color de relleno
|
291 |
// complex_index_fill_color = -1;
|
292 |
// if (elemento.attr_bytes > 0) {
|
293 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
294 |
|
295 |
// System.err.println("complex shape fill color = " + elemento.color);
|
296 |
// }
|
297 |
} |
298 |
|
299 |
bConnect = true;
|
300 |
} else {
|
301 |
bEsPoligono = false;
|
302 |
bConnect = false;
|
303 |
} |
304 |
|
305 |
break;
|
306 |
|
307 |
case DGNFileHeader.DGNST_MULTIPOINT:
|
308 |
|
309 |
// OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
|
310 |
// spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
|
311 |
// y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
|
312 |
// TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
|
313 |
// Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
|
314 |
// todav?a no est? metido.
|
315 |
DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento; |
316 |
auxFeature.set(ID_FIELD_ID,elemento.element_id); |
317 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
318 |
auxFeature.set(ID_FIELD_ENTITY,"Multipoint");
|
319 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
320 |
// "Multipoint");
|
321 |
auxFeature.set(ID_FIELD_LAYER,elemento.level); |
322 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
323 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
324 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
325 |
|
326 |
if ((psLine.num_vertices == 2) && |
327 |
(psLine.vertices[0].x == psLine.vertices[1].x) && |
328 |
(psLine.vertices[0].y == psLine.vertices[1].y)) { |
329 |
auxFeature.set(ID_FIELD_ENTITY,"Point");
|
330 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
331 |
// "Point");
|
332 |
|
333 |
Geometry geom=gFactory.createPoint3D(psLine.vertices[0].x,
|
334 |
psLine.vertices[0].y, psLine.vertices[0].z); |
335 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
336 |
// auxFeature.setDefaultGeometry(geom);
|
337 |
addDGNFeature(auxFeature); |
338 |
|
339 |
// addShape(new FPoint3D(psLine.vertices[0].x,
|
340 |
// psLine.vertices[0].y, psLine.vertices[0].z),
|
341 |
// auxRow);
|
342 |
} else {
|
343 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
344 |
|
345 |
if (psLine.type == DGNFileHeader.DGNT_CURVE) {
|
346 |
psLine.num_vertices = psLine.num_vertices - 4;
|
347 |
|
348 |
for (int aux_n = 0; |
349 |
aux_n < psLine.num_vertices; aux_n++) { |
350 |
psLine.vertices[aux_n] = psLine.vertices[aux_n + |
351 |
2];
|
352 |
} |
353 |
} |
354 |
|
355 |
if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
|
356 |
((psLine.properties & 0x8000) != 0)) { |
357 |
// Invertimos el orden porque es un agujero
|
358 |
elShape.moveTo(psLine.vertices[psLine.num_vertices - |
359 |
1].x,
|
360 |
psLine.vertices[psLine.num_vertices - 1].y);
|
361 |
|
362 |
for (int i = psLine.num_vertices - 2; i >= 0; |
363 |
i--) { |
364 |
elShape.lineTo(psLine.vertices[i].x, |
365 |
psLine.vertices[i].y); |
366 |
} |
367 |
} else {
|
368 |
elShape.moveTo(psLine.vertices[0].x,
|
369 |
psLine.vertices[0].y);
|
370 |
|
371 |
for (int i = 1; i < psLine.num_vertices; i++) { |
372 |
elShape.lineTo(psLine.vertices[i].x, |
373 |
psLine.vertices[i].y); |
374 |
} |
375 |
} |
376 |
|
377 |
if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices - |
378 |
1].x) &&
|
379 |
(psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
|
380 |
1].y)) {
|
381 |
// Lo a?adimos tambi?n como pol?gono
|
382 |
bEsPoligono = true;
|
383 |
|
384 |
// Miramos si tiene color de relleno
|
385 |
if (elemento.attr_bytes > 0) { |
386 |
elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
387 |
|
388 |
// System.err.println("fill color = " + elemento.color);
|
389 |
if (elemento.color != -1) { |
390 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
391 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
392 |
} |
393 |
} |
394 |
|
395 |
if (elemento.complex == 0) { |
396 |
Geometry geom=gFactory.createPolygon2D(elShape); |
397 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
398 |
// auxFeature.setDefaultGeometry(geom);
|
399 |
addDGNFeature(auxFeature); |
400 |
// addShape(new FPolygon2D(elShape), auxRow);
|
401 |
} |
402 |
} |
403 |
|
404 |
if (elemento.complex != 0) { |
405 |
// Si es un agujero o
|
406 |
// es la primera entidad del agujero, lo a?adimos sin unir al anterior
|
407 |
if (bFirstHoleEntity ||
|
408 |
((psLine.type == DGNFileHeader.DGNT_SHAPE) && |
409 |
((psLine.properties & 0x8000) != 0))) { |
410 |
elementoCompuesto.append(elShape, false);
|
411 |
bFirstHoleEntity = false;
|
412 |
} else {
|
413 |
elementoCompuesto.append(elShape, bConnect); |
414 |
} |
415 |
} else {
|
416 |
Geometry geom=gFactory.createPolyline2D(elShape); |
417 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
418 |
// auxFeature.setDefaultGeometry(geom);
|
419 |
addDGNFeature(auxFeature); |
420 |
// addShape(new FPolyline2D(elShape), auxRow);
|
421 |
} |
422 |
} |
423 |
|
424 |
break;
|
425 |
|
426 |
case DGNFileHeader.DGNST_ARC:
|
427 |
|
428 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
|
429 |
DGNElemArc psArc = (DGNElemArc) elemento; |
430 |
|
431 |
// La definici?n de arco de MicroStation es distinta a la de Java.
|
432 |
// En el dgn el origin se entiende que es el centro del arco,
|
433 |
// y a la hora de crear un Arc2D las 2 primeras coordenadas son
|
434 |
// la esquina inferior izquierda del rect?ngulo que rodea al arco.
|
435 |
// 1.- Creamos la elipse sin rotaci?n.
|
436 |
// 2.- Creamos el arco
|
437 |
// 3.- Rotamos el resultado
|
438 |
|
439 |
/* System.out.println("Arco con primari axis: " + psArc.primary_axis +
|
440 |
" start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
|
441 |
System.out.println("secondaria axis: " + psArc.secondary_axis +
|
442 |
" rotation = " + psArc.rotation); */
|
443 |
AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians( |
444 |
psArc.rotation), psArc.origin.x, |
445 |
psArc.origin.y); |
446 |
|
447 |
// mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
|
448 |
Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x - |
449 |
psArc.primary_axis, |
450 |
psArc.origin.y - psArc.secondary_axis, |
451 |
2.0 * psArc.primary_axis,
|
452 |
2.0 * psArc.secondary_axis, -psArc.startang,
|
453 |
-psArc.sweepang, Arc2D.OPEN);
|
454 |
|
455 |
// Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
|
456 |
// psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
|
457 |
GeneralPathX elShapeArc = new GeneralPathX(elArco);
|
458 |
|
459 |
// Transformamos el GeneralPahtX porque si transformamos elArco nos lo convierte
|
460 |
// a GeneralPath y nos guarda las coordenadas en float, con la correspondiente p?rdida de precisi?n
|
461 |
elShapeArc.transform(mT); |
462 |
|
463 |
if (m_DgnReader.getInfo().dimension == 3) { |
464 |
//Aqu? podr?amos hacer cosas con la coordenada Z
|
465 |
} |
466 |
|
467 |
auxFeature.set(ID_FIELD_ID,elemento.element_id); |
468 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
469 |
auxFeature.set(ID_FIELD_ENTITY,"Arc");
|
470 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
471 |
// "Arc");
|
472 |
auxFeature.set(ID_FIELD_LAYER,elemento.level); |
473 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
474 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
475 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
476 |
|
477 |
/* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
|
478 |
psArc.origin.x + psArc.primary_axis, psArc.origin.y);
|
479 |
|
480 |
lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, new GeneralPathX(ejeMayor)), auxRow); */
|
481 |
|
482 |
// lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
|
483 |
if (elemento.complex != 0) { |
484 |
// Esto es una posible fuente de fallos si detr?s de una
|
485 |
// elipse vienen m?s cosas pegadas. Deber?amos volver
|
486 |
// a conectar una vez pasada la elipse.
|
487 |
if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
|
488 |
bConnect = false;
|
489 |
} |
490 |
|
491 |
// SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
|
492 |
// Y EL ELEMENTO ES UN POLIGONO
|
493 |
if (bFirstHoleEntity ||
|
494 |
((elemento.type == DGNFileHeader.DGNT_SHAPE) && |
495 |
((elemento.properties & 0x8000) != 0))) { |
496 |
elementoCompuesto.append(elShapeArc, false);
|
497 |
bFirstHoleEntity = false;
|
498 |
} else {
|
499 |
elementoCompuesto.append(elShapeArc, bConnect); |
500 |
} |
501 |
} else {
|
502 |
Geometry geom=gFactory.createPolyline2D(elShapeArc); |
503 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
504 |
// auxFeature.setDefaultGeometry(geom);
|
505 |
addDGNFeature(auxFeature); |
506 |
|
507 |
// addShape(new FPolyline2D(elShapeArc), auxRow);
|
508 |
|
509 |
if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
|
510 |
geom=gFactory.createPolygon2D(elShapeArc); |
511 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
512 |
// auxFeature.setDefaultGeometry(geom);
|
513 |
addDGNFeature(auxFeature); |
514 |
// addShape(new FPolygon2D(elShapeArc), auxRow);
|
515 |
} |
516 |
} |
517 |
|
518 |
// System.err.println("Entra un Arco");
|
519 |
break;
|
520 |
|
521 |
case DGNFileHeader.DGNST_TEXT:
|
522 |
|
523 |
DGNElemText psText = (DGNElemText) elemento; |
524 |
|
525 |
|
526 |
auxFeature.set(ID_FIELD_ID,elemento.element_id); |
527 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
528 |
auxFeature.set(ID_FIELD_ENTITY,"Text");
|
529 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
530 |
// "Text");
|
531 |
auxFeature.set(ID_FIELD_LAYER,elemento.level); |
532 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
533 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
534 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
535 |
heightText = (float) psText.height_mult;
|
536 |
auxFeature.set(ID_FIELD_HEIGHTTEXT,heightText); |
537 |
// auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
|
538 |
auxFeature.set(ID_FIELD_ROTATIONTEXT,psText.rotation); |
539 |
// auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation);
|
540 |
auxFeature.set(ID_FIELD_TEXT,psText.string); |
541 |
// auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
|
542 |
|
543 |
Geometry geom=gFactory.createPoint3D(psText.origin.x, |
544 |
psText.origin.y, psText.origin.z); |
545 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
546 |
// auxFeature.setDefaultGeometry(geom);
|
547 |
addDGNFeature(auxFeature); |
548 |
|
549 |
// addShape(elShapeTxt, auxRow);
|
550 |
|
551 |
// System.out.println("Rotaci?n texto: " + psText.rotation + "Altura Texto = " + heightText);
|
552 |
|
553 |
/* System.out.println(" origin=(" + psText.origin.x +
|
554 |
", " + psText.origin.y + ") rotation=" +
|
555 |
psText.rotation + "\n" + " font=" +
|
556 |
psText.font_id + " just=" +
|
557 |
psText.justification + "length_mult=" +
|
558 |
psText.length_mult + " height_mult=" +
|
559 |
psText.height_mult + "\n" + " string =" +
|
560 |
new String(psText.string).toString().trim() +
|
561 |
"\n"); */
|
562 |
break;
|
563 |
|
564 |
/* default:
|
565 |
m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
|
566 |
*/
|
567 |
} // switch
|
568 |
} // if
|
569 |
} // for
|
570 |
|
571 |
if (bElementoCompuesto) {
|
572 |
if (bInsideCell) {
|
573 |
auxFeature=cellFeature; |
574 |
// auxRow = cellRow;
|
575 |
} else {
|
576 |
auxFeature=complexFeature; |
577 |
// auxRow = complexRow;
|
578 |
} |
579 |
|
580 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
581 |
Geometry geom=gFactory.createPolyline2D(elementoCompuesto); |
582 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
583 |
// auxFeature.setDefaultGeometry(geom);
|
584 |
addDGNFeature(auxFeature); |
585 |
|
586 |
// addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
587 |
|
588 |
if (bEsPoligono) {
|
589 |
if (complex_index_fill_color != -1) { |
590 |
auxFeature.set(ID_FIELD_COLOR,complex_index_fill_color); |
591 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
|
592 |
} |
593 |
geom=gFactory.createPolygon2D(elementoCompuesto); |
594 |
auxFeature.setGeometry(ID_FIELD_GEOMETRY,geom); |
595 |
// auxFeature.setDefaultGeometry(geom);
|
596 |
addDGNFeature(auxFeature); |
597 |
// addShape(new FPolygon2D(elementoCompuesto), auxRow);
|
598 |
} |
599 |
|
600 |
} |
601 |
cellFeature.stopLoading(); |
602 |
auxFeature.stopLoading(); |
603 |
complexFeature.stopLoading(); |
604 |
|
605 |
}catch (IsNotFeatureSettingException e) {
|
606 |
throw new OpenException(this.description(),e); |
607 |
} catch (ReadException e) {
|
608 |
throw new OpenException(this.description(),e); |
609 |
} |
610 |
|
611 |
if (legendlabelingManager != null) { |
612 |
legendlabelingManager.endLoading(); |
613 |
} |
614 |
// ISymbol theSymbol = null;
|
615 |
|
616 |
// try {
|
617 |
// for (long j = 0; j < getFeatureCount(); j++) {
|
618 |
// Feature feat=(Feature)getFeature((int)j);
|
619 |
// int clave=feat.getInt(ID_FIELD_COLOR);
|
620 |
// if (defaultLegend.getSymbolByValue(clave) == null) {
|
621 |
|
622 |
// Color c = m_DgnReader.DGNLookupColor(
|
623 |
// clave.getValue());
|
624 |
// theSymbol = SymbologyFactory.
|
625 |
// createDefaultSymbolByShapeType(featureType.getGeometryTypes()[0], c);
|
626 |
// theSymbol.setDescription(clave.toString());
|
627 |
|
628 |
// if (theSymbol instanceof IMarkerSymbol) {
|
629 |
// ((IMarkerSymbol) theSymbol).setSize(1);
|
630 |
// }
|
631 |
|
632 |
// if (theSymbol instanceof ILineSymbol) {
|
633 |
// ((ILineSymbol) theSymbol).setLineWidth(1);
|
634 |
// }
|
635 |
|
636 |
// if (theSymbol instanceof IFillSymbol) {
|
637 |
// ((IFillSymbol) theSymbol).getOutline().setLineColor(c);
|
638 |
// ((IFillSymbol) theSymbol).getOutline().setLineWidth(1);
|
639 |
// ((IFillSymbol) theSymbol).setFillColor(null);
|
640 |
// }
|
641 |
|
642 |
// // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
|
643 |
// defaultLegend.addSymbol(clave, theSymbol);
|
644 |
// }
|
645 |
|
646 |
// if ("Text".equalsIgnoreCase(((StringValue) rs.getFieldValue(j, ID_FIELD_ENTITY)).toString())) {
|
647 |
|
648 |
// }
|
649 |
|
650 |
|
651 |
// } // for
|
652 |
// } catch (ReadException e) {
|
653 |
// throw new OpenException(getName(),e);
|
654 |
// }
|
655 |
|
656 |
|
657 |
} |
658 |
|
659 |
private void addDGNFeature(Feature feature) throws DataException{ |
660 |
DGNFeature newFeature = new DGNFeature(feature);
|
661 |
this.addFeature(newFeature);
|
662 |
if (this.legendlabelingManager != null) { |
663 |
this.legendlabelingManager.add(newFeature, null); |
664 |
} |
665 |
} |
666 |
|
667 |
|
668 |
/* (non-Javadoc)
|
669 |
* @see org.gvsig.fmap.data.feature.file.IFileResource#getTotalFiles()
|
670 |
*/
|
671 |
public int getTotalFiles() { |
672 |
return 1; |
673 |
} |
674 |
|
675 |
protected FeatureType getFeatureType() throws ReadException{ |
676 |
this.checkOpen();
|
677 |
return this.featureType; |
678 |
} |
679 |
|
680 |
/**
|
681 |
* @return
|
682 |
* @throws ReadException
|
683 |
*/
|
684 |
protected Object getDefaultLegend() throws ReadException { |
685 |
this.checkOpen();
|
686 |
if (this.legendlabelingManager == null) { |
687 |
return null; |
688 |
} |
689 |
return this.legendlabelingManager.getDefaultLegend(); |
690 |
} |
691 |
|
692 |
/* (non-Javadoc)
|
693 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#getFeatureCount()
|
694 |
*/
|
695 |
protected int getFeatureCount() throws ReadException { |
696 |
return super.getFeatureCount(); |
697 |
} |
698 |
|
699 |
/* (non-Javadoc)
|
700 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#getFullExtent()
|
701 |
*/
|
702 |
protected Envelope getFullExtent() throws ReadException { |
703 |
return super.getFullExtent(); |
704 |
} |
705 |
|
706 |
/* (non-Javadoc)
|
707 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#getFeature(int)
|
708 |
*/
|
709 |
protected Feature getFeature(int index) throws ReadException { |
710 |
return super.getFeature(index); |
711 |
} |
712 |
|
713 |
protected Object getDefaultLabelingStrategy() throws ReadException { |
714 |
this.checkOpen();
|
715 |
|
716 |
if (this.legendlabelingManager == null) { |
717 |
return null; |
718 |
} |
719 |
return this.legendlabelingManager.getLabeling(); |
720 |
} |
721 |
|
722 |
public static void setLegendLabelingManagerFactory( |
723 |
LegendLabelingManagerFactory factory) { |
724 |
legendLabelingManagerFactory = factory; |
725 |
} |
726 |
|
727 |
public static LegendLabelingManagerFactory getLegendLabelingManagerFactory() { |
728 |
return legendLabelingManagerFactory;
|
729 |
} |
730 |
|
731 |
} |
732 |
|