root / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / file / dgn / DGNStore.java @ 20049
History | View | Annotate | Download (31.7 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.dgn; |
---|---|
2 |
|
3 |
import java.awt.geom.AffineTransform; |
4 |
import java.awt.geom.Arc2D; |
5 |
import java.io.File; |
6 |
import java.sql.Types; |
7 |
import java.util.ArrayList; |
8 |
import java.util.Collection; |
9 |
import java.util.Iterator; |
10 |
import java.util.List; |
11 |
|
12 |
import org.gvsig.data.IDataCollection; |
13 |
import org.gvsig.data.IDataExplorer; |
14 |
import org.gvsig.data.IDataStoreParameters; |
15 |
import org.gvsig.data.datastores.vectorial.IFeaturesReader; |
16 |
import org.gvsig.data.datastores.vectorial.IFeaturesWriter; |
17 |
import org.gvsig.data.datastores.vectorial.base.MemoryStore; |
18 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemArc; |
19 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemCellHeader; |
20 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemComplexHeader; |
21 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemCore; |
22 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemMultiPoint; |
23 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNElemText; |
24 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNFileHeader; |
25 |
import org.gvsig.data.datastores.vectorial.file.dgn.utils.DGNReader; |
26 |
import org.gvsig.data.exception.CloseException; |
27 |
import org.gvsig.data.exception.InitializeException; |
28 |
import org.gvsig.data.exception.OpenException; |
29 |
import org.gvsig.data.exception.ReadException; |
30 |
import org.gvsig.data.exception.WriteException; |
31 |
import org.gvsig.data.spatialprovisional.IExtent; |
32 |
import org.gvsig.data.vectorial.DefaultAttributeDescriptor; |
33 |
import org.gvsig.data.vectorial.DefaultFeatureType; |
34 |
import org.gvsig.data.vectorial.FeatureStoreNotification; |
35 |
import org.gvsig.data.vectorial.IFeature; |
36 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
37 |
import org.gvsig.data.vectorial.IFeatureCollection; |
38 |
import org.gvsig.data.vectorial.IFeatureID; |
39 |
import org.gvsig.data.vectorial.IFeatureType; |
40 |
import org.gvsig.exceptions.BaseException; |
41 |
import org.gvsig.metadata.IMetadata; |
42 |
import org.gvsig.metadata.IMetadataManager; |
43 |
import org.gvsig.metadata.MetadataManager; |
44 |
|
45 |
import com.iver.cit.gvsig.fmap.core.FShape; |
46 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
47 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
48 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
49 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
50 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
51 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
52 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
53 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy; |
54 |
|
55 |
public class DGNStore extends MemoryStore{ |
56 |
public static String DATASTORE_NAME = "DGNStore"; |
57 |
private final int ID_FIELD_ID = 0; |
58 |
private final int ID_FIELD_ENTITY = 1; |
59 |
private final int ID_FIELD_LAYER = 2; |
60 |
private final int ID_FIELD_COLOR = 3; |
61 |
private final int ID_FIELD_HEIGHTTEXT = 4; |
62 |
private final int ID_FIELD_ROTATIONTEXT = 5; |
63 |
private final int ID_FIELD_TEXT = 6; |
64 |
private final int ID_FIELD_GEOMETRY = 7; |
65 |
|
66 |
private List featureTypes = new ArrayList();//<IFeatureType> |
67 |
private IFeatureType featureType;
|
68 |
protected IMetadata metadata;
|
69 |
private DGNStoreParameters dgnParameters=null; |
70 |
private File dgnFile; |
71 |
private DGNReader m_DgnReader;
|
72 |
private AttrInTableLabelingStrategy labeling;
|
73 |
private VectorialUniqueValueLegend defaultLegend;
|
74 |
|
75 |
public void init(IDataStoreParameters parameters) throws InitializeException { |
76 |
super.init(parameters);
|
77 |
dgnParameters=(DGNStoreParameters)parameters; |
78 |
dgnFile=dgnParameters.getDGNFile(); |
79 |
} |
80 |
|
81 |
static IFeatureType newFeatureType(){
|
82 |
DefaultFeatureType fType= new DefaultFeatureType();
|
83 |
|
84 |
DefaultAttributeDescriptor descriptorID = new DefaultAttributeDescriptor();
|
85 |
descriptorID.setType(IFeatureAttributeDescriptor.TYPE_INT); |
86 |
descriptorID.setName("ID");
|
87 |
descriptorID.setDefaultValue(new Integer(0)); |
88 |
fType.add(descriptorID); |
89 |
fType.setFieldId("ID");
|
90 |
|
91 |
DefaultAttributeDescriptor descriptorEntity = new DefaultAttributeDescriptor();
|
92 |
descriptorEntity.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
93 |
descriptorEntity.setName("Entity");
|
94 |
descriptorEntity.setDefaultValue("Entity");
|
95 |
fType.add(descriptorEntity); |
96 |
|
97 |
DefaultAttributeDescriptor descriptorLayer = new DefaultAttributeDescriptor();
|
98 |
descriptorLayer.setType(IFeatureAttributeDescriptor.TYPE_INT); |
99 |
descriptorLayer.setName("Layer");
|
100 |
descriptorLayer.setDefaultValue(new Integer(0)); |
101 |
fType.add(descriptorLayer); |
102 |
|
103 |
DefaultAttributeDescriptor descriptorColor = new DefaultAttributeDescriptor();
|
104 |
descriptorColor.setType(IFeatureAttributeDescriptor.TYPE_INT); |
105 |
descriptorColor.setName("Color");
|
106 |
descriptorColor.setDefaultValue(new Integer(0)); |
107 |
fType.add(descriptorColor); |
108 |
|
109 |
// DefaultAttributeDescriptor descriptorElevation = new DefaultAttributeDescriptor();
|
110 |
// descriptorElevation.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE);
|
111 |
// descriptorElevation.setName("Elevation");
|
112 |
// descriptorElevation.setDefaultValue(new Double(0));
|
113 |
// featureType.add(descriptorElevation);
|
114 |
//
|
115 |
// DefaultAttributeDescriptor descriptorThickness = new DefaultAttributeDescriptor();
|
116 |
// descriptorThickness.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE);
|
117 |
// descriptorThickness.setName("Thickness");
|
118 |
// descriptorThickness.setDefaultValue(new Double(0));
|
119 |
// featureType.add(descriptorThickness);
|
120 |
|
121 |
DefaultAttributeDescriptor descriptorHeightText = new DefaultAttributeDescriptor();
|
122 |
descriptorHeightText.setType(IFeatureAttributeDescriptor.TYPE_FLOAT); |
123 |
descriptorHeightText.setName("HeightText");
|
124 |
descriptorHeightText.setDefaultValue(new Float(0)); |
125 |
fType.add(descriptorHeightText); |
126 |
|
127 |
DefaultAttributeDescriptor descriptorRotationText = new DefaultAttributeDescriptor();
|
128 |
descriptorRotationText.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE); |
129 |
descriptorRotationText.setName("RotationText");
|
130 |
descriptorRotationText.setDefaultValue(new Double(0)); |
131 |
fType.add(descriptorRotationText); |
132 |
|
133 |
DefaultAttributeDescriptor descriptorText = new DefaultAttributeDescriptor();
|
134 |
descriptorText.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
135 |
descriptorText.setName("Text");
|
136 |
descriptorText.setDefaultValue("");
|
137 |
fType.add(descriptorText); |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
DefaultAttributeDescriptor descriptorShape = new DefaultAttributeDescriptor();
|
144 |
descriptorShape.setType(IFeatureAttributeDescriptor.TYPE_GEOMETRY); |
145 |
descriptorShape.setName("GEOMETRY");
|
146 |
descriptorShape.setDefaultValue(null);
|
147 |
fType.add(descriptorShape); |
148 |
fType.setDefaultGeometry("GEOMETRY");
|
149 |
return fType;
|
150 |
|
151 |
|
152 |
} |
153 |
|
154 |
private void initializeFeatureType() { |
155 |
featureType = newFeatureType(); |
156 |
} |
157 |
|
158 |
protected void doFinishEdition() throws WriteException, ReadException { |
159 |
IFeaturesWriter writer = getFeaturesWriter(); |
160 |
writer.init(this);
|
161 |
writer.updateFeatureType(featureType); |
162 |
writer.preProcess(); |
163 |
Collection collection=getDataCollection();
|
164 |
Iterator iterator=collection.iterator();
|
165 |
IFeature feature; |
166 |
while (iterator.hasNext()) {
|
167 |
feature= (IFeature) iterator.next(); |
168 |
writer.insertFeature(feature); |
169 |
} |
170 |
writer.postProcess(); |
171 |
|
172 |
} |
173 |
|
174 |
public IDataCollection getDataCollection(IFeatureType type, String filter, String order) throws ReadException { |
175 |
if (type==null){ |
176 |
type=getDefaultFeatureType(); |
177 |
} |
178 |
IDataCollection dataCollection= getFeatutesReader().getFeatures(featureManager,type,filter,order); |
179 |
this.addObserver(dataCollection);
|
180 |
return dataCollection;
|
181 |
} |
182 |
|
183 |
public IFeature getFeatureByID(IFeatureID id) throws ReadException { |
184 |
if (this.alterMode){ |
185 |
if (featureManager.contains(id)) {
|
186 |
return featureManager.getFeature(id);
|
187 |
} |
188 |
} |
189 |
return id.getFeature(featureType);
|
190 |
} |
191 |
|
192 |
public List getFeatureTypes() { |
193 |
featureTypes.set(0,getDefaultFeatureType());
|
194 |
return featureTypes;
|
195 |
} |
196 |
|
197 |
public IFeatureType getDefaultFeatureType() {
|
198 |
IFeatureType ft = featureType; |
199 |
if (isEditing()){
|
200 |
// Aqu? hay que construir un FeatureType con los cambios que se hayan hecho en la edici?n.
|
201 |
return attributeManager.getFeatureType(ft);
|
202 |
} |
203 |
return ft;
|
204 |
} |
205 |
|
206 |
public boolean isWithDefaultLegend() { |
207 |
return false; |
208 |
} |
209 |
|
210 |
public Object getDefaultLegend() { |
211 |
return null; |
212 |
} |
213 |
|
214 |
public Object getDefaultLabelingStrategy() { |
215 |
return null; |
216 |
} |
217 |
|
218 |
public boolean canAlterFeatureType() { |
219 |
return true; |
220 |
} |
221 |
|
222 |
public String getName() { |
223 |
return DATASTORE_NAME;
|
224 |
} |
225 |
|
226 |
public void open() throws OpenException { |
227 |
this.observable.notifyObservers(
|
228 |
new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_OPEN) |
229 |
); |
230 |
float heightText = 10; |
231 |
// attr.setLoadedInMemory(true);
|
232 |
initializeFeatureType(); |
233 |
try {
|
234 |
m_DgnReader = new DGNReader(dgnFile.getAbsolutePath());
|
235 |
} catch (ReadException e) {
|
236 |
throw new OpenException(getName(),e); |
237 |
} |
238 |
|
239 |
|
240 |
// Value[] auxRow = new Value[7];
|
241 |
// Value[] cellRow = new Value[7];
|
242 |
// Value[] complexRow = new Value[7];
|
243 |
IFeature auxFeature=new DGNFeature(featureType,true); |
244 |
IFeature cellFeature=new DGNFeature(featureType,false); |
245 |
IFeature complexFeature=new DGNFeature(featureType,false); |
246 |
initializeFeatureType(); |
247 |
// ArrayList arrayFields = new ArrayList();
|
248 |
// arrayFields.add("ID");
|
249 |
// arrayFields.add("Entity");
|
250 |
// arrayFields.add("Layer");
|
251 |
// arrayFields.add("Color");
|
252 |
// arrayFields.add("HeightText");
|
253 |
// arrayFields.add("RotationText");
|
254 |
// arrayFields.add("Text");
|
255 |
|
256 |
// getTableModel().setColumnIdentifiers(arrayFields.toArray());
|
257 |
|
258 |
// jaume
|
259 |
labeling = new AttrInTableLabelingStrategy();
|
260 |
((AttrInTableLabelingStrategy) labeling).setTextFieldId(featureType.getFieldIndex("Text"));
|
261 |
((AttrInTableLabelingStrategy) labeling).setRotationFieldId(featureType.getFieldIndex("RotationText"));
|
262 |
((AttrInTableLabelingStrategy) labeling).setHeightFieldId(featureType.getFieldIndex("HeightText"));
|
263 |
((AttrInTableLabelingStrategy) labeling).setUnit(1); //MapContext.NAMES[1] (meters) |
264 |
|
265 |
|
266 |
// Ahora las rellenamos.
|
267 |
// FShape aux;
|
268 |
boolean bElementoCompuesto = false; |
269 |
boolean bEsPoligono = false; |
270 |
boolean bInsideCell = false; |
271 |
boolean bFirstHoleEntity = false; |
272 |
boolean bConnect = false; // Se usa para que los pol?gonos cierren bien cuando son formas compuestas |
273 |
// int contadorSubElementos = 0;
|
274 |
// int numSubElementos = 0;
|
275 |
int complex_index_fill_color = -1; |
276 |
int nClass; // Para filtrar los elementos de construcci?n, etc. |
277 |
GeneralPathX elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
278 |
|
279 |
for (int id = 0; id < m_DgnReader.getNumEntities(); id++) { |
280 |
|
281 |
// System.out.println("Elemento " + id + " de " + m_DgnReader.getNumEntities());
|
282 |
m_DgnReader.DGNGotoElement(id); |
283 |
|
284 |
DGNElemCore elemento = m_DgnReader.DGNReadElement(); |
285 |
nClass = 0;
|
286 |
// auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
|
287 |
// auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
|
288 |
// auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
|
289 |
|
290 |
if (elemento.properties != 0) { |
291 |
nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS; |
292 |
} |
293 |
|
294 |
if ((elemento != null) && (elemento.deleted == 0) && (nClass == 0)) //Leer un elemento |
295 |
{ |
296 |
// aux = null;
|
297 |
|
298 |
// if ((elemento.element_id > 3800) && (elemento.element_id < 3850))
|
299 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(),elemento,"");
|
300 |
if ((elemento.stype == DGNFileHeader.DGNST_MULTIPOINT) ||
|
301 |
(elemento.stype == DGNFileHeader.DGNST_ARC) || |
302 |
(elemento.stype == DGNFileHeader.DGNST_CELL_HEADER) || |
303 |
(elemento.stype == DGNFileHeader.DGNST_SHARED_CELL_DEFN) || |
304 |
(elemento.stype == DGNFileHeader.DGNST_COMPLEX_HEADER)) { |
305 |
if (elemento.complex != 0) { |
306 |
bElementoCompuesto = true;
|
307 |
} else {
|
308 |
if (bElementoCompuesto) {
|
309 |
if (bInsideCell) {
|
310 |
auxFeature.set(ID_FIELD_ENTITY,cellFeature.get(ID_FIELD_ENTITY)); |
311 |
// auxRow[ID_FIELD_ENTITY] = cellRow[ID_FIELD_ENTITY];
|
312 |
} else {
|
313 |
auxFeature=complexFeature; |
314 |
// auxRow = complexRow;
|
315 |
} |
316 |
|
317 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
318 |
IGeometry geom=ShapeFactory.createPolyline2D(elementoCompuesto); |
319 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
320 |
// auxFeature.setDefaultGeometry(geom);
|
321 |
addFeature(auxFeature); |
322 |
// addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
323 |
|
324 |
if (bEsPoligono) {
|
325 |
if (complex_index_fill_color != -1) { |
326 |
auxFeature.set(ID_FIELD_COLOR,complex_index_fill_color); |
327 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
|
328 |
} |
329 |
geom=ShapeFactory.createPolygon2D(elementoCompuesto); |
330 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
331 |
// auxFeature.setDefaultGeometry(geom);
|
332 |
addFeature(auxFeature); |
333 |
// addShape(new FPolygon2D(elementoCompuesto), auxRow);
|
334 |
} |
335 |
|
336 |
elementoCompuesto = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
337 |
} |
338 |
|
339 |
// System.err.println("Entidad simple");
|
340 |
bElementoCompuesto = false;
|
341 |
bEsPoligono = false;
|
342 |
bConnect = false;
|
343 |
|
344 |
// elementoCompuesto = new GeneralPathX();
|
345 |
bInsideCell = false;
|
346 |
} |
347 |
} |
348 |
|
349 |
switch (elemento.stype) {
|
350 |
case DGNFileHeader.DGNST_SHARED_CELL_DEFN:
|
351 |
bInsideCell = true;
|
352 |
cellFeature.set(ID_FIELD_ID,elemento.element_id); |
353 |
// cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
354 |
cellFeature.set(ID_FIELD_LAYER,elemento.level); |
355 |
// cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
356 |
cellFeature.set(ID_FIELD_COLOR,elemento.color); |
357 |
// cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
358 |
cellFeature.set(ID_FIELD_ENTITY,"Shared Cell");
|
359 |
// cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
360 |
// "Shared Cell");
|
361 |
|
362 |
break;
|
363 |
|
364 |
case DGNFileHeader.DGNST_CELL_HEADER:
|
365 |
bInsideCell = true;
|
366 |
|
367 |
DGNElemCellHeader psCellHeader = (DGNElemCellHeader) elemento; |
368 |
cellFeature.set(ID_FIELD_ID,elemento.element_id); |
369 |
// cellRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
370 |
cellFeature.set(ID_FIELD_LAYER,elemento.level); |
371 |
// cellRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
372 |
cellFeature.set(ID_FIELD_COLOR,elemento.color); |
373 |
// cellRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
374 |
cellFeature.set(ID_FIELD_ENTITY,"Cell");
|
375 |
// cellRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
376 |
// "Cell");
|
377 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
378 |
|
379 |
// System.err.println("Cell Header " + complex_index_fill_color);
|
380 |
break;
|
381 |
|
382 |
case DGNFileHeader.DGNST_COMPLEX_HEADER:
|
383 |
|
384 |
// bElementoCompuesto = true;
|
385 |
// System.err.println("Complex Header");
|
386 |
// contadorSubElementos = 0;
|
387 |
|
388 |
DGNElemComplexHeader psComplexHeader = (DGNElemComplexHeader) elemento; |
389 |
// numSubElementos = psComplexHeader.numelems;
|
390 |
complexFeature.set(ID_FIELD_ID,elemento.element_id); |
391 |
// complexRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
392 |
complexFeature.set(ID_FIELD_LAYER,elemento.level); |
393 |
// complexRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
394 |
complexFeature.set(ID_FIELD_COLOR,elemento.color); |
395 |
// complexRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
396 |
complexFeature.set(ID_FIELD_ENTITY,"Complex");
|
397 |
// complexRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
398 |
// "Complex");
|
399 |
|
400 |
if (psComplexHeader.type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER) {
|
401 |
bEsPoligono = true;
|
402 |
|
403 |
// Si es un agujero, no conectamos con el anterior
|
404 |
if ((psComplexHeader.properties & 0x8000) != 0) { |
405 |
bFirstHoleEntity = true;
|
406 |
} else {
|
407 |
// Miramos si tiene color de relleno
|
408 |
// complex_index_fill_color = -1;
|
409 |
// if (elemento.attr_bytes > 0) {
|
410 |
complex_index_fill_color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
411 |
|
412 |
// System.err.println("complex shape fill color = " + elemento.color);
|
413 |
// }
|
414 |
} |
415 |
|
416 |
bConnect = true;
|
417 |
} else {
|
418 |
bEsPoligono = false;
|
419 |
bConnect = false;
|
420 |
} |
421 |
|
422 |
break;
|
423 |
|
424 |
case DGNFileHeader.DGNST_MULTIPOINT:
|
425 |
|
426 |
// OJO: Si lo que viene en este multipoint es un elemento con type=11 (curve), se trata de una "parametric
|
427 |
// spline curve". La vamos a tratar como si no fuera curva, pero seg?n la documentaci?n, los 2 primeros puntos
|
428 |
// y los 2 ?ltimos puntos definen "endpoint derivatives" y NO se muestran.
|
429 |
// TODAV?A HAY UN PEQUE?O FALLO CON EL FICHERO dgn-sample.dgn, pero lo dejo por ahora.
|
430 |
// Es posible que tenga que ver con lo de los arcos (arco distorsionado), que
|
431 |
// todav?a no est? metido.
|
432 |
DGNElemMultiPoint psLine = (DGNElemMultiPoint) elemento; |
433 |
auxFeature.set(ID_FIELD_ID,elemento.element_id); |
434 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
435 |
auxFeature.set(ID_FIELD_ENTITY,"Multipoint");
|
436 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
437 |
// "Multipoint");
|
438 |
auxFeature.set(ID_FIELD_LAYER,elemento.level); |
439 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
440 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
441 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
442 |
|
443 |
if ((psLine.num_vertices == 2) && |
444 |
(psLine.vertices[0].x == psLine.vertices[1].x) && |
445 |
(psLine.vertices[0].y == psLine.vertices[1].y)) { |
446 |
auxFeature.set(ID_FIELD_ENTITY,"Point");
|
447 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
448 |
// "Point");
|
449 |
|
450 |
IGeometry geom=ShapeFactory.createPoint3D(psLine.vertices[0].x,
|
451 |
psLine.vertices[0].y, psLine.vertices[0].z); |
452 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
453 |
// auxFeature.setDefaultGeometry(geom);
|
454 |
addFeature(auxFeature); |
455 |
|
456 |
// addShape(new FPoint3D(psLine.vertices[0].x,
|
457 |
// psLine.vertices[0].y, psLine.vertices[0].z),
|
458 |
// auxRow);
|
459 |
} else {
|
460 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
461 |
|
462 |
if (psLine.type == DGNFileHeader.DGNT_CURVE) {
|
463 |
psLine.num_vertices = psLine.num_vertices - 4;
|
464 |
|
465 |
for (int aux_n = 0; |
466 |
aux_n < psLine.num_vertices; aux_n++) { |
467 |
psLine.vertices[aux_n] = psLine.vertices[aux_n + |
468 |
2];
|
469 |
} |
470 |
} |
471 |
|
472 |
if ((psLine.type == DGNFileHeader.DGNT_SHAPE) &&
|
473 |
((psLine.properties & 0x8000) != 0)) { |
474 |
// Invertimos el orden porque es un agujero
|
475 |
elShape.moveTo(psLine.vertices[psLine.num_vertices - |
476 |
1].x,
|
477 |
psLine.vertices[psLine.num_vertices - 1].y);
|
478 |
|
479 |
for (int i = psLine.num_vertices - 2; i >= 0; |
480 |
i--) |
481 |
elShape.lineTo(psLine.vertices[i].x, |
482 |
psLine.vertices[i].y); |
483 |
} else {
|
484 |
elShape.moveTo(psLine.vertices[0].x,
|
485 |
psLine.vertices[0].y);
|
486 |
|
487 |
for (int i = 1; i < psLine.num_vertices; i++) |
488 |
elShape.lineTo(psLine.vertices[i].x, |
489 |
psLine.vertices[i].y); |
490 |
} |
491 |
|
492 |
if ((psLine.vertices[0].x == psLine.vertices[psLine.num_vertices - |
493 |
1].x) &&
|
494 |
(psLine.vertices[0].y == psLine.vertices[psLine.num_vertices -
|
495 |
1].y)) {
|
496 |
// Lo a?adimos tambi?n como pol?gono
|
497 |
bEsPoligono = true;
|
498 |
|
499 |
// Miramos si tiene color de relleno
|
500 |
if (elemento.attr_bytes > 0) { |
501 |
elemento.color = m_DgnReader.DGNGetShapeFillInfo(elemento); |
502 |
|
503 |
// System.err.println("fill color = " + elemento.color);
|
504 |
if (elemento.color != -1) { |
505 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
506 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
507 |
} |
508 |
} |
509 |
|
510 |
if (elemento.complex == 0) { |
511 |
IGeometry geom=ShapeFactory.createPolygon2D(elShape); |
512 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
513 |
// auxFeature.setDefaultGeometry(geom);
|
514 |
addFeature(auxFeature); |
515 |
// addShape(new FPolygon2D(elShape), auxRow);
|
516 |
} |
517 |
} |
518 |
|
519 |
if (elemento.complex != 0) { |
520 |
// Si es un agujero o
|
521 |
// es la primera entidad del agujero, lo a?adimos sin unir al anterior
|
522 |
if (bFirstHoleEntity ||
|
523 |
((psLine.type == DGNFileHeader.DGNT_SHAPE) && |
524 |
((psLine.properties & 0x8000) != 0))) { |
525 |
elementoCompuesto.append(elShape, false);
|
526 |
bFirstHoleEntity = false;
|
527 |
} else {
|
528 |
elementoCompuesto.append(elShape, bConnect); |
529 |
} |
530 |
} else {
|
531 |
IGeometry geom=ShapeFactory.createPolyline2D(elShape); |
532 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
533 |
// auxFeature.setDefaultGeometry(geom);
|
534 |
addFeature(auxFeature); |
535 |
// addShape(new FPolyline2D(elShape), auxRow);
|
536 |
} |
537 |
} |
538 |
|
539 |
break;
|
540 |
|
541 |
case DGNFileHeader.DGNST_ARC:
|
542 |
|
543 |
// m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento,"");
|
544 |
DGNElemArc psArc = (DGNElemArc) elemento; |
545 |
|
546 |
// La definici?n de arco de MicroStation es distinta a la de Java.
|
547 |
// En el dgn el origin se entiende que es el centro del arco,
|
548 |
// y a la hora de crear un Arc2D las 2 primeras coordenadas son
|
549 |
// la esquina inferior izquierda del rect?ngulo que rodea al arco.
|
550 |
// 1.- Creamos la elipse sin rotaci?n.
|
551 |
// 2.- Creamos el arco
|
552 |
// 3.- Rotamos el resultado
|
553 |
|
554 |
/* System.out.println("Arco con primari axis: " + psArc.primary_axis +
|
555 |
" start angle: " + psArc.startang + " sweepang = " + psArc.sweepang);
|
556 |
System.out.println("secondaria axis: " + psArc.secondary_axis +
|
557 |
" rotation = " + psArc.rotation); */
|
558 |
AffineTransform mT = AffineTransform.getRotateInstance(Math.toRadians( |
559 |
psArc.rotation), psArc.origin.x, |
560 |
psArc.origin.y); |
561 |
|
562 |
// mT.preConcatenate(AffineTransform.getScaleInstance(100.0,100.0));
|
563 |
Arc2D.Double elArco = new Arc2D.Double(psArc.origin.x - |
564 |
psArc.primary_axis, |
565 |
psArc.origin.y - psArc.secondary_axis, |
566 |
2.0 * psArc.primary_axis,
|
567 |
2.0 * psArc.secondary_axis, -psArc.startang,
|
568 |
-psArc.sweepang, Arc2D.OPEN);
|
569 |
|
570 |
// Ellipse2D.Double elArco = new Ellipse2D.Double(psArc.origin.x - psArc.primary_axis,
|
571 |
// psArc.origin.y - psArc.secondary_axis,2.0 * psArc.primary_axis, 2.0 * psArc.secondary_axis);
|
572 |
GeneralPathX elShapeArc = new GeneralPathX(elArco);
|
573 |
|
574 |
// Transformamos el GeneralPahtX porque si transformamos elArco nos lo convierte
|
575 |
// a GeneralPath y nos guarda las coordenadas en float, con la correspondiente p?rdida de precisi?n
|
576 |
elShapeArc.transform(mT); |
577 |
|
578 |
if (m_DgnReader.getInfo().dimension == 3) { |
579 |
//Aqu? podr?amos hacer cosas con la coordenada Z
|
580 |
} |
581 |
|
582 |
auxFeature.set(ID_FIELD_ID,elemento.element_id); |
583 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
584 |
auxFeature.set(ID_FIELD_ENTITY,"Arc");
|
585 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
586 |
// "Arc");
|
587 |
auxFeature.set(ID_FIELD_LAYER,elemento.level); |
588 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
589 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
590 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
591 |
|
592 |
/* Line2D.Double ejeMayor = new Line2D.Double(psArc.origin.x - psArc.primary_axis, psArc.origin.y,
|
593 |
psArc.origin.x + psArc.primary_axis, psArc.origin.y);
|
594 |
|
595 |
lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, new GeneralPathX(ejeMayor)), auxRow); */
|
596 |
|
597 |
// lyrLines.addShape(new FShape(FConstant.SHAPE_TYPE_POLYLINE, elShapeArc), auxRow);
|
598 |
if (elemento.complex != 0) { |
599 |
// Esto es una posible fuente de fallos si detr?s de una
|
600 |
// elipse vienen m?s cosas pegadas. Deber?amos volver
|
601 |
// a conectar una vez pasada la elipse.
|
602 |
if (elemento.type == DGNFileHeader.DGNT_ELLIPSE) {
|
603 |
bConnect = false;
|
604 |
} |
605 |
|
606 |
// SI LA ELIPSE ES UN AGUJERO, SE A?ADE SIN PEGAR
|
607 |
// Y EL ELEMENTO ES UN POLIGONO
|
608 |
if (bFirstHoleEntity ||
|
609 |
((elemento.type == DGNFileHeader.DGNT_SHAPE) && |
610 |
((elemento.properties & 0x8000) != 0))) { |
611 |
elementoCompuesto.append(elShapeArc, false);
|
612 |
bFirstHoleEntity = false;
|
613 |
} else {
|
614 |
elementoCompuesto.append(elShapeArc, bConnect); |
615 |
} |
616 |
} else {
|
617 |
IGeometry geom=ShapeFactory.createPolyline2D(elShapeArc); |
618 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
619 |
// auxFeature.setDefaultGeometry(geom);
|
620 |
addFeature(auxFeature); |
621 |
|
622 |
// addShape(new FPolyline2D(elShapeArc), auxRow);
|
623 |
|
624 |
if (psArc.type == DGNFileHeader.DGNT_ELLIPSE) {
|
625 |
geom=ShapeFactory.createPolygon2D(elShapeArc); |
626 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
627 |
// auxFeature.setDefaultGeometry(geom);
|
628 |
addFeature(auxFeature); |
629 |
// addShape(new FPolygon2D(elShapeArc), auxRow);
|
630 |
} |
631 |
} |
632 |
|
633 |
// System.err.println("Entra un Arco");
|
634 |
break;
|
635 |
|
636 |
case DGNFileHeader.DGNST_TEXT:
|
637 |
|
638 |
DGNElemText psText = (DGNElemText) elemento; |
639 |
|
640 |
|
641 |
auxFeature.set(ID_FIELD_ID,elemento.element_id); |
642 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(elemento.element_id);
|
643 |
auxFeature.set(ID_FIELD_ENTITY,"Text");
|
644 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(
|
645 |
// "Text");
|
646 |
auxFeature.set(ID_FIELD_LAYER,elemento.level); |
647 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(elemento.level);
|
648 |
auxFeature.set(ID_FIELD_COLOR,elemento.color); |
649 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(elemento.color);
|
650 |
heightText = (float) psText.height_mult;
|
651 |
auxFeature.set(ID_FIELD_HEIGHTTEXT,heightText); |
652 |
// auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
|
653 |
auxFeature.set(ID_FIELD_ROTATIONTEXT,psText.rotation); |
654 |
// auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(psText.rotation);
|
655 |
auxFeature.set(ID_FIELD_TEXT,psText.string); |
656 |
// auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(psText.string); // .trim();
|
657 |
|
658 |
IGeometry geom=ShapeFactory.createPoint3D(psText.origin.x, |
659 |
psText.origin.y, psText.origin.z); |
660 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
661 |
// auxFeature.setDefaultGeometry(geom);
|
662 |
addFeature(auxFeature); |
663 |
|
664 |
// addShape(elShapeTxt, auxRow);
|
665 |
|
666 |
// System.out.println("Rotaci?n texto: " + psText.rotation + "Altura Texto = " + heightText);
|
667 |
|
668 |
/* System.out.println(" origin=(" + psText.origin.x +
|
669 |
", " + psText.origin.y + ") rotation=" +
|
670 |
psText.rotation + "\n" + " font=" +
|
671 |
psText.font_id + " just=" +
|
672 |
psText.justification + "length_mult=" +
|
673 |
psText.length_mult + " height_mult=" +
|
674 |
psText.height_mult + "\n" + " string =" +
|
675 |
new String(psText.string).toString().trim() +
|
676 |
"\n"); */
|
677 |
break;
|
678 |
|
679 |
/* default:
|
680 |
m_DgnReader.DGNDumpElement(m_DgnReader.getInfo(), elemento, "");
|
681 |
*/
|
682 |
} // switch
|
683 |
} // if
|
684 |
} // for
|
685 |
|
686 |
if (bElementoCompuesto) {
|
687 |
if (bInsideCell) {
|
688 |
auxFeature=cellFeature; |
689 |
// auxRow = cellRow;
|
690 |
} else {
|
691 |
auxFeature=complexFeature; |
692 |
// auxRow = complexRow;
|
693 |
} |
694 |
|
695 |
// System.err.println("Entidad compuesta. bInsideCell = " + bInsideCell + " auxRow = " + auxRow[ID_FIELD_ENTITY]);
|
696 |
IGeometry geom=ShapeFactory.createPolyline2D(elementoCompuesto); |
697 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
698 |
// auxFeature.setDefaultGeometry(geom);
|
699 |
addFeature(auxFeature); |
700 |
|
701 |
// addShape(new FPolyline2D(elementoCompuesto), auxRow);
|
702 |
|
703 |
if (bEsPoligono) {
|
704 |
if (complex_index_fill_color != -1) { |
705 |
auxFeature.set(ID_FIELD_COLOR,complex_index_fill_color); |
706 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(complex_index_fill_color);
|
707 |
} |
708 |
geom=ShapeFactory.createPolygon2D(elementoCompuesto); |
709 |
auxFeature.set(ID_FIELD_GEOMETRY,geom); |
710 |
// auxFeature.setDefaultGeometry(geom);
|
711 |
addFeature(auxFeature); |
712 |
// addShape(new FPolygon2D(elementoCompuesto), auxRow);
|
713 |
} |
714 |
} |
715 |
|
716 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(FShape.MULTI); |
717 |
defaultLegend.setClassifyingFieldNames(new String[] {"Color"} ); |
718 |
defaultLegend.setClassifyingFieldTypes(new int[]{Types.INTEGER,Types.VARCHAR,Types.INTEGER,Types.INTEGER,Types.FLOAT,Types.DOUBLE,Types.VARCHAR}); |
719 |
|
720 |
|
721 |
ISymbol myDefaultSymbol = SymbologyFactory. |
722 |
createDefaultSymbolByShapeType(FShape.MULTI); |
723 |
|
724 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
725 |
|
726 |
|
727 |
// ISymbol theSymbol = null;
|
728 |
|
729 |
// try {
|
730 |
// for (long j = 0; j < getFeatureCount(); j++) {
|
731 |
// IFeature feat=(IFeature)getFeature((int)j);
|
732 |
// int clave=feat.getInt(ID_FIELD_COLOR);
|
733 |
// if (defaultLegend.getSymbolByValue(clave) == null) {
|
734 |
|
735 |
// Color c = m_DgnReader.DGNLookupColor(
|
736 |
// clave.getValue());
|
737 |
// theSymbol = SymbologyFactory.
|
738 |
// createDefaultSymbolByShapeType(featureType.getGeometryTypes()[0], c);
|
739 |
// theSymbol.setDescription(clave.toString());
|
740 |
|
741 |
// if (theSymbol instanceof IMarkerSymbol) {
|
742 |
// ((IMarkerSymbol) theSymbol).setSize(1);
|
743 |
// }
|
744 |
|
745 |
// if (theSymbol instanceof ILineSymbol) {
|
746 |
// ((ILineSymbol) theSymbol).setLineWidth(1);
|
747 |
// }
|
748 |
|
749 |
// if (theSymbol instanceof IFillSymbol) {
|
750 |
// ((IFillSymbol) theSymbol).getOutline().setLineColor(c);
|
751 |
// ((IFillSymbol) theSymbol).getOutline().setLineWidth(1);
|
752 |
// ((IFillSymbol) theSymbol).setFillColor(null);
|
753 |
// }
|
754 |
|
755 |
// // theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
|
756 |
// defaultLegend.addSymbol(clave, theSymbol);
|
757 |
// }
|
758 |
|
759 |
// if ("Text".equalsIgnoreCase(((StringValue) rs.getFieldValue(j, ID_FIELD_ENTITY)).toString())) {
|
760 |
|
761 |
// }
|
762 |
|
763 |
|
764 |
// } // for
|
765 |
// } catch (ReadException e) {
|
766 |
// throw new OpenException(getName(),e);
|
767 |
// }
|
768 |
|
769 |
|
770 |
this.observable.notifyObservers(
|
771 |
new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_OPEN) |
772 |
); |
773 |
|
774 |
} |
775 |
|
776 |
public void close() throws CloseException { |
777 |
this.observable.notifyObservers(
|
778 |
new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_CLOSE) |
779 |
); |
780 |
super.close();
|
781 |
this.observable.notifyObservers(
|
782 |
new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_CLOSE) |
783 |
); |
784 |
|
785 |
} |
786 |
|
787 |
public void dispose() throws CloseException { |
788 |
this.observable.notifyObservers(
|
789 |
new FeatureStoreNotification(this,FeatureStoreNotification.BEFORE_DISPOSE) |
790 |
); |
791 |
close(); |
792 |
this.observable.notifyObservers(
|
793 |
new FeatureStoreNotification(this,FeatureStoreNotification.AFTER_DISPOSE) |
794 |
); |
795 |
} |
796 |
|
797 |
public boolean isEditable() { |
798 |
return false; |
799 |
} |
800 |
|
801 |
public IMetadata getMetadata() throws BaseException { |
802 |
if (metadata==null){ |
803 |
IMetadataManager manager=MetadataManager.getManager(); |
804 |
metadata=manager.create(DATASTORE_NAME); |
805 |
IExtent extent=getFullExtent(); |
806 |
metadata.set("extent",extent);
|
807 |
String srs=getSRS();
|
808 |
metadata.set("srs",srs);
|
809 |
} |
810 |
if (this.alterMode){ |
811 |
IExtent extent=(IExtent)metadata.get("extent");
|
812 |
IFeatureCollection featureCollection=(IFeatureCollection)getDataCollection(); |
813 |
if (spatialManager.isFullExtentDirty()){
|
814 |
if (!featureCollection.isEmpty()){
|
815 |
Iterator featureIterator=featureCollection.iterator();
|
816 |
extent = ((IFeature)featureIterator.next()).getExtent(); |
817 |
while(featureIterator.hasNext()){
|
818 |
IFeature feature=(IFeature)featureIterator.next(); |
819 |
IExtent boundExtent=feature.getExtent(); |
820 |
if (boundExtent!=null) |
821 |
extent.add(boundExtent); |
822 |
} |
823 |
} |
824 |
} |
825 |
metadata.set("extent",extent);
|
826 |
} |
827 |
return metadata;
|
828 |
} |
829 |
private String getSRS() { |
830 |
// TODO Auto-generated method stub
|
831 |
return null; |
832 |
} |
833 |
|
834 |
|
835 |
public IFeaturesReader getFeatutesReader() {
|
836 |
IFeaturesReader reader = new DGNFeaturesReader();
|
837 |
reader.init(this);
|
838 |
return reader;
|
839 |
} |
840 |
public IFeaturesWriter getFeaturesWriter() {
|
841 |
return null; |
842 |
} |
843 |
public IDataStoreParameters getParameters() {
|
844 |
return parameters;
|
845 |
} |
846 |
public void addFeature(IFeature feature){ |
847 |
DGNFeature f=new DGNFeature(feature);
|
848 |
super.addFeature(f);
|
849 |
} |
850 |
|
851 |
public IDataExplorer getExplorer() {
|
852 |
// TODO Auto-generated method stub
|
853 |
return null; |
854 |
} |
855 |
} |