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