root / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / fmap / data / feature / file / dxf / DXFResource.java @ 24250
History | View | Annotate | Download (31 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.dxf; |
32 |
|
33 |
import java.awt.geom.Point2D; |
34 |
|
35 |
import org.cresques.cts.IProjection; |
36 |
import org.cresques.geo.Point3D; |
37 |
import org.cresques.io.DxfFile; |
38 |
import org.cresques.px.IObjList; |
39 |
import org.cresques.px.dxf.DxfFeatureMaker; |
40 |
import org.cresques.px.dxf.DxfHeaderManager; |
41 |
import org.cresques.px.gml.Feature; |
42 |
import org.cresques.px.gml.LineString; |
43 |
import org.cresques.px.gml.LineString3D; |
44 |
import org.cresques.px.gml.Point; |
45 |
import org.cresques.px.gml.Polygon; |
46 |
import org.cresques.px.gml.Polygon3D; |
47 |
import org.gvsig.fmap.crs.CRSFactory; |
48 |
import org.gvsig.fmap.data.exceptions.DataException; |
49 |
import org.gvsig.fmap.data.exceptions.OpenException; |
50 |
import org.gvsig.fmap.data.exceptions.ReadException; |
51 |
import org.gvsig.fmap.data.feature.AttributeDescriptor; |
52 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
53 |
import org.gvsig.fmap.data.feature.FeatureType; |
54 |
import org.gvsig.fmap.data.feature.MemoryFeature; |
55 |
import org.gvsig.fmap.data.feature.exceptions.IsNotAttributeSettingException; |
56 |
import org.gvsig.fmap.data.feature.exceptions.IsNotFeatureSettingException; |
57 |
import org.gvsig.fmap.data.feature.file.FileMemoryResource; |
58 |
import org.gvsig.fmap.data.feature.impl.DefaultFeatureType; |
59 |
import org.gvsig.fmap.data.feature.operation.LegendLabelingManager; |
60 |
import org.gvsig.fmap.data.feature.operation.LegendLabelingManagerFactory; |
61 |
import org.gvsig.fmap.geom.Geometry; |
62 |
import org.gvsig.fmap.geom.GeometryFactory; |
63 |
import org.gvsig.fmap.geom.GeometryManager; |
64 |
import org.gvsig.fmap.geom.primitive.Envelope; |
65 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
66 |
|
67 |
/**
|
68 |
* @author jmvivo
|
69 |
*
|
70 |
*/
|
71 |
public class DXFResource extends FileMemoryResource { |
72 |
|
73 |
private static LegendLabelingManagerFactory legendLabelingManagerFactory = null; |
74 |
|
75 |
public final static int ID_FIELD_ID = 0; |
76 |
|
77 |
public final static int ID_FIELD_GEOMETRY = 1; |
78 |
|
79 |
public final static int ID_FIELD_ENTITY = 2; |
80 |
|
81 |
public final static int ID_FIELD_LAYER = 3; |
82 |
|
83 |
public final static int ID_FIELD_COLOR = 4; |
84 |
|
85 |
public final static int ID_FIELD_ELEVATION = 5; |
86 |
|
87 |
public final static int ID_FIELD_THICKNESS = 6; |
88 |
|
89 |
public final static int ID_FIELD_TEXT = 7; |
90 |
|
91 |
public final static int ID_FIELD_HEIGHTTEXT = 8; |
92 |
|
93 |
public final static int ID_FIELD_ROTATIONTEXT = 9; |
94 |
|
95 |
private LegendLabelingManager legendlabelingManager;
|
96 |
|
97 |
private FeatureType featureType;
|
98 |
|
99 |
|
100 |
|
101 |
DXFResource(DXFStoreParameters params) { |
102 |
super(params);
|
103 |
} |
104 |
|
105 |
/* (non-Javadoc)
|
106 |
* @see org.gvsig.fmap.data.Resource#getName()
|
107 |
*/
|
108 |
public String getName() { |
109 |
return "DXF"; |
110 |
} |
111 |
|
112 |
private void initializeFeatureType() { |
113 |
this.featureType= DXFStore.newFeatureType();
|
114 |
} |
115 |
|
116 |
protected FeatureType getFeatureType() throws ReadException{ |
117 |
this.checkOpen();
|
118 |
return this.featureType; |
119 |
} |
120 |
|
121 |
|
122 |
/* (non-Javadoc)
|
123 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#getFeature(int)
|
124 |
*/
|
125 |
protected org.gvsig.fmap.data.feature.Feature getFeature(int index) throws ReadException { |
126 |
return super.getFeature(index); |
127 |
} |
128 |
|
129 |
/* (non-Javadoc)
|
130 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#getFeatureCount()
|
131 |
*/
|
132 |
protected int getFeatureCount() throws ReadException { |
133 |
return super.getFeatureCount(); |
134 |
} |
135 |
|
136 |
/* (non-Javadoc)
|
137 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#getFullExtent()
|
138 |
*/
|
139 |
protected Envelope getFullExtent() throws ReadException { |
140 |
return super.getFullExtent(); |
141 |
} |
142 |
|
143 |
/* (non-Javadoc)
|
144 |
* @see org.gvsig.fmap.data.feature.file.FileMemoryResource#load()
|
145 |
*/
|
146 |
protected void load() throws DataException { |
147 |
float heightText = 10; |
148 |
DxfFile dxfFeatureFile; |
149 |
IProjection projection = CRSFactory |
150 |
.getCRS(((DXFStoreParameters) this.params).getSRSID());
|
151 |
DxfFile.EntityFactory featureMaker = new DxfFeatureMaker(projection);
|
152 |
DxfFile.VarSettings headerManager = new DxfHeaderManager();
|
153 |
dxfFeatureFile = new DxfFile(projection, this.getFile() |
154 |
.getAbsolutePath(), |
155 |
featureMaker, headerManager); |
156 |
|
157 |
if (legendLabelingManagerFactory != null) { |
158 |
legendlabelingManager = legendLabelingManagerFactory.newManager(); |
159 |
legendlabelingManager.startLoading(null);
|
160 |
} else {
|
161 |
legendlabelingManager = null;
|
162 |
} |
163 |
|
164 |
try {
|
165 |
dxfFeatureFile.load(); |
166 |
} catch (Exception e1) { |
167 |
throw new OpenException(getDescription(),e1); |
168 |
} |
169 |
IObjList.vector features = (IObjList.vector) ((DxfFeatureMaker) featureMaker) |
170 |
.getObjects(); |
171 |
String acadVersion = ((DxfHeaderManager) headerManager)
|
172 |
.getAcadVersion(); |
173 |
System.out.println("initialize(): acadVersion = " + acadVersion); |
174 |
|
175 |
GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory(); |
176 |
|
177 |
if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) { // y no |
178 |
// est?n
|
179 |
// todos
|
180 |
// a
|
181 |
// 9999
|
182 |
Feature[] features2D = new Feature[features.size()]; |
183 |
for (int i = 0; i < features.size(); i++) { |
184 |
Feature fea = (Feature) features.get(i); |
185 |
if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
186 |
Point point = (Point) fea.getGeometry(); |
187 |
Point point2 = new Point(); |
188 |
for (int j = 0; j < point.pointNr(); j++) { |
189 |
point2.add(point.get(j)); |
190 |
} |
191 |
point2.setTextPoint(point.isTextPoint()); |
192 |
fea.setGeometry(point2); |
193 |
features2D[i] = fea; |
194 |
// } else if (fea.getGeometry() instanceof InsPoint3D) {
|
195 |
// InsPoint insPoint = (InsPoint)fea.getGeometry();
|
196 |
// InsPoint insPoint2 = new InsPoint();
|
197 |
// for (int j=0;j<insPoint.pointNr();j++) {
|
198 |
// insPoint2.add(insPoint.get(j));
|
199 |
// }
|
200 |
// fea.setGeometry(insPoint2);
|
201 |
// features2D[i] = fea;
|
202 |
} else if (fea.getGeometry() instanceof LineString3D) { |
203 |
LineString lineString = (LineString) fea.getGeometry(); |
204 |
LineString lineString2 = new LineString();
|
205 |
for (int j = 0; j < lineString.pointNr(); j++) { |
206 |
lineString2.add(lineString.get(j)); |
207 |
} |
208 |
fea.setGeometry(lineString2); |
209 |
features2D[i] = fea; |
210 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
211 |
Polygon polygon = (Polygon) fea.getGeometry(); |
212 |
Polygon polygon2 = new Polygon(); |
213 |
for (int j = 0; j < polygon.pointNr(); j++) { |
214 |
polygon2.add(polygon.get(j)); |
215 |
} |
216 |
fea.setGeometry(polygon2); |
217 |
features2D[i] = fea; |
218 |
} |
219 |
} |
220 |
features.clear(); |
221 |
for (int i = 0; i < features2D.length; i++) { |
222 |
features.add(features2D[i]); |
223 |
} |
224 |
} |
225 |
// String acadVersion =
|
226 |
// (String)((DxfHeaderManager)headerManager).getAcadVersion();
|
227 |
// System.out.println("initialize(): acadVersion = " + acadVersion);
|
228 |
|
229 |
int nAtt = featureMaker.getAttributes().size();
|
230 |
|
231 |
// Campos de las MemoryLayer:
|
232 |
|
233 |
// Object[] auxRow = new Object[10 + nAtt];
|
234 |
// ArrayList arrayFields = new ArrayList();
|
235 |
// arrayFields.add("ID");
|
236 |
// arrayFields.add("FShape");
|
237 |
// arrayFields.add("Entity");
|
238 |
// arrayFields.add("Layer");
|
239 |
// arrayFields.add("Color");
|
240 |
// arrayFields.add("Elevation");
|
241 |
// arrayFields.add("Thickness");
|
242 |
// arrayFields.add("Text");
|
243 |
// arrayFields.add("HeightText");
|
244 |
// arrayFields.add("RotationText");
|
245 |
initializeFeatureType(); |
246 |
|
247 |
|
248 |
|
249 |
|
250 |
for (int i = 0; i < nAtt; i++) { |
251 |
String att[] = new String[2]; |
252 |
att = (String[]) featureMaker.getAttributes().get(i); |
253 |
|
254 |
AttributeDescriptor descriptorAux = (AttributeDescriptor) ((DefaultFeatureType)featureType).createAttributeDescriptor(); |
255 |
try {
|
256 |
descriptorAux.loading(); |
257 |
descriptorAux.setType(FeatureAttributeDescriptor.STRING); |
258 |
descriptorAux.setName(att[0]);
|
259 |
descriptorAux.setDefaultValue("");
|
260 |
descriptorAux.stopLoading(); |
261 |
} catch (IsNotAttributeSettingException e) {
|
262 |
e.printStackTrace(); |
263 |
} |
264 |
featureType.add(descriptorAux); |
265 |
|
266 |
|
267 |
// arrayFields.add(att[0]);
|
268 |
} |
269 |
|
270 |
// getTableModel().setColumnIdentifiers(arrayFields.toArray());
|
271 |
|
272 |
for (int i = 0; i < features.size(); i++) { |
273 |
|
274 |
MemoryFeature feature; |
275 |
try {
|
276 |
feature = new DXFFeature(featureType,true); |
277 |
} catch (ReadException e1) {
|
278 |
throw new OpenException(this.getDescription(),e1); |
279 |
} |
280 |
// auxRow[ID_FIELD_HEIGHTTEXT] = new Double(0.0);
|
281 |
// auxRow[ID_FIELD_ROTATIONTEXT] = new Double(0.0);
|
282 |
// auxRow[ID_FIELD_TEXT] = null;
|
283 |
try{
|
284 |
feature.loading(); |
285 |
Feature fea = (Feature) features.get(i); |
286 |
if (fea.getGeometry() instanceof Point |
287 |
&& !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
|
288 |
Point point = (Point) fea.getGeometry(); |
289 |
Point2D pto = new Point2D.Double(); |
290 |
pto = point.get(0);
|
291 |
// FShape nuevoShp;
|
292 |
if (point.isTextPoint()) {
|
293 |
feature.setAttribute(ID_FIELD_ID,i); |
294 |
// auxRow[ID_FIELD_ID] = new Integer(i);
|
295 |
// feature.set(ID_FIELD_FSHAPE,"Point2D");
|
296 |
// auxRow[ID_FIELD_FSHAPE] = new String("FPoint2D");
|
297 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
298 |
// auxRow[ID_FIELD_ENTITY] = new String(fea.getProp("dxfEntity"));
|
299 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
300 |
// auxRow[ID_FIELD_LAYER] = new String(fea.getProp("layer"));
|
301 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
302 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
303 |
// auxRow[ID_FIELD_COLOR] = new Integer(auxInt);
|
304 |
feature.setAttribute(ID_FIELD_TEXT,fea.getProp("text"));
|
305 |
// auxRow[ID_FIELD_TEXT] = ValueFactory
|
306 |
// .createValue(new String(fea.getProp("text")));
|
307 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
308 |
feature.setAttribute(ID_FIELD_HEIGHTTEXT,heightText); |
309 |
// auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
|
310 |
// .createValue(heightText);
|
311 |
double auxR = Double.parseDouble(fea |
312 |
.getProp("textRotation"));
|
313 |
feature.setAttribute(ID_FIELD_ROTATIONTEXT,auxR); |
314 |
// auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
|
315 |
// .createValue(auxR);
|
316 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
317 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
318 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
319 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
320 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
321 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
322 |
// Attributes
|
323 |
for (int j = 0; j < nAtt; j++) { |
324 |
String[] attributes = new String[2]; |
325 |
attributes = (String[]) featureMaker.getAttributes() |
326 |
.get(j); |
327 |
feature.setAttribute(10+j,attributes[1]); |
328 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
329 |
// attributes[1]));
|
330 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
331 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
332 |
// auxRow[10 + j] = ValueFactory
|
333 |
// .createValue(new String(fea
|
334 |
// .getProp(attributes[0])));
|
335 |
} |
336 |
} |
337 |
Geometry geom=gFactory.createPoint2D(new org.gvsig.fmap.geom.primitive.Point2D(pto.getX(), pto.getY()));
|
338 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
339 |
// feature.setDefaultGeometry(geom);
|
340 |
addDXFFeature(feature); |
341 |
|
342 |
// addShape(nuevoShp, auxRow);
|
343 |
} else {
|
344 |
feature.setAttribute(ID_FIELD_ID,i); |
345 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
346 |
// feature.set(ID_FIELD_FSHAPE,"Point2D");
|
347 |
// auxRow[ID_FIELD_FSHAPE] = ValueFactory
|
348 |
// .createValue(new String("FPoint2D"));
|
349 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
350 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory
|
351 |
// .createValue(new String(fea.getProp("dxfEntity")));
|
352 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
353 |
// auxRow[ID_FIELD_LAYER] = ValueFactory
|
354 |
// .createValue(new String(fea.getProp("layer")));
|
355 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
356 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
357 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
358 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
359 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
360 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
361 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
362 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
363 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
364 |
// Attributes
|
365 |
for (int j = 0; j < nAtt; j++) { |
366 |
String[] attributes = new String[2]; |
367 |
attributes = (String[]) featureMaker.getAttributes() |
368 |
.get(j); |
369 |
feature.setAttribute(10+j,attributes[1]); |
370 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
371 |
// attributes[1]));
|
372 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
373 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
374 |
// auxRow[10 + j] = ValueFactory
|
375 |
// .createValue(new String(fea
|
376 |
// .getProp(attributes[0])));
|
377 |
} |
378 |
} |
379 |
Geometry geom=gFactory.createPoint2D(new org.gvsig.fmap.geom.primitive.Point2D(pto.getX(), pto.getY()));
|
380 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
381 |
// feature.setDefaultGeometry(geom);
|
382 |
addDXFFeature(feature); |
383 |
// addShape(nuevoShp, auxRow);
|
384 |
} |
385 |
} else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
386 |
org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D) fea |
387 |
.getGeometry(); |
388 |
Point3D pto = new Point3D();
|
389 |
pto = point.getPoint3D(0);
|
390 |
// FShape nuevoShp;
|
391 |
if (point.isTextPoint()) {
|
392 |
feature.setAttribute(ID_FIELD_ID,i); |
393 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
394 |
feature.setGeometry(ID_FIELD_GEOMETRY,"Point3D");
|
395 |
// auxRow[ID_FIELD_FSHAPE] = ValueFactory
|
396 |
// .createValue(new String("FPoint3D"));
|
397 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
398 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory
|
399 |
// .createValue(new String(fea.getProp("dxfEntity")));
|
400 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
401 |
// auxRow[ID_FIELD_LAYER] = ValueFactory
|
402 |
// .createValue(new String(fea.getProp("layer")));
|
403 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
404 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
405 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
406 |
feature.setAttribute(ID_FIELD_TEXT,fea.getProp("text"));
|
407 |
// auxRow[ID_FIELD_TEXT] = ValueFactory
|
408 |
// .createValue(new String(fea.getProp("text")));
|
409 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
410 |
feature.setAttribute(ID_FIELD_HEIGHTTEXT,heightText); |
411 |
// auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
|
412 |
// .createValue(heightText);
|
413 |
double auxR = Double.parseDouble(fea |
414 |
.getProp("textRotation"));
|
415 |
feature.setAttribute(ID_FIELD_ROTATIONTEXT,auxR); |
416 |
// auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
|
417 |
// .createValue(auxR);
|
418 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
419 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
420 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
421 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
422 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
423 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
424 |
// Attributes
|
425 |
for (int j = 0; j < nAtt; j++) { |
426 |
String[] attributes = new String[2]; |
427 |
attributes = (String[]) featureMaker.getAttributes() |
428 |
.get(j); |
429 |
feature.setAttribute(10+j,attributes[1]); |
430 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
431 |
// attributes[1]));
|
432 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
433 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
434 |
// auxRow[10 + j] = ValueFactory
|
435 |
// .createValue(new String(fea
|
436 |
// .getProp(attributes[0])));
|
437 |
} |
438 |
} |
439 |
Geometry geom=gFactory.createPoint3D(pto.getX(), pto.getY(), pto.getZ()); |
440 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
441 |
// feature.setDefaultGeometry(geom);
|
442 |
addDXFFeature(feature); |
443 |
// addShape(nuevoShp, auxRow);
|
444 |
} else {
|
445 |
feature.setAttribute(ID_FIELD_ID,i); |
446 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
447 |
feature.setGeometry(ID_FIELD_GEOMETRY,"Point3D");
|
448 |
// auxRow[ID_FIELD_FSHAPE] = ValueFactory
|
449 |
// .createValue(new String("FPoint3D"));
|
450 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
451 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory
|
452 |
// .createValue(new String(fea.getProp("dxfEntity")));
|
453 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
454 |
// auxRow[ID_FIELD_LAYER] = ValueFactory
|
455 |
// .createValue(new String(fea.getProp("layer")));
|
456 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
457 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
458 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
459 |
|
460 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
461 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
462 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
463 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
464 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
465 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
466 |
// Attributes
|
467 |
for (int j = 0; j < nAtt; j++) { |
468 |
String[] attributes = new String[2]; |
469 |
attributes = (String[]) featureMaker.getAttributes() |
470 |
.get(j); |
471 |
feature.setAttribute(10+j,attributes[1]); |
472 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
473 |
// attributes[1]));
|
474 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
475 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
476 |
// auxRow[10 + j] = ValueFactory
|
477 |
// .createValue(new String(fea
|
478 |
// .getProp(attributes[0])));
|
479 |
} |
480 |
} |
481 |
Geometry geom=gFactory.createPoint3D(pto.getX(), pto.getY(), pto.getZ()); |
482 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
483 |
// feature.setDefaultGeometry(geom);
|
484 |
addDXFFeature(feature); |
485 |
// addShape(nuevoShp, auxRow);
|
486 |
} |
487 |
} else if (fea.getGeometry() instanceof LineString |
488 |
&& !(fea.getGeometry() instanceof LineString3D)) {
|
489 |
GeneralPathX genPathX = new GeneralPathX();
|
490 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr()]; |
491 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
492 |
pts[j] = fea.getGeometry().get(j); |
493 |
} |
494 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
495 |
for (int j = 1; j < pts.length; j++) { |
496 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
497 |
} |
498 |
feature.setAttribute(ID_FIELD_ID,i); |
499 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
500 |
feature.setGeometry(ID_FIELD_GEOMETRY,"Polyline2D");
|
501 |
// auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
|
502 |
// "FPolyline2D"));
|
503 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
504 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
|
505 |
// fea.getProp("dxfEntity")));
|
506 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
507 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
|
508 |
// fea.getProp("layer")));
|
509 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
510 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
511 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
512 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
513 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
514 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
515 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
516 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
517 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
518 |
// Attributes
|
519 |
for (int j = 0; j < nAtt; j++) { |
520 |
String[] attributes = new String[2]; |
521 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
522 |
feature.setAttribute(10+j,attributes[1]); |
523 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
524 |
// attributes[1]));
|
525 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
526 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
527 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
528 |
// fea.getProp(attributes[0])));
|
529 |
} |
530 |
} |
531 |
Geometry geom=gFactory.createPolyline2D(genPathX); |
532 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
533 |
// feature.setDefaultGeometry(geom);
|
534 |
addDXFFeature(feature); |
535 |
// addShape(nuevoShp, auxRow);
|
536 |
} else if (fea.getGeometry() instanceof LineString3D) { |
537 |
GeneralPathX genPathX = new GeneralPathX();
|
538 |
Point3D[] pts = new Point3D[fea.getGeometry().pointNr()]; |
539 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
540 |
pts[j] = ((LineString3D) fea.getGeometry()).getPoint3D(j); |
541 |
} |
542 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
543 |
for (int j = 1; j < pts.length; j++) { |
544 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
545 |
} |
546 |
double[] elevations = new double[pts.length]; |
547 |
for (int j = 0; j < pts.length; j++) { |
548 |
elevations[j] = pts[j].getZ(); |
549 |
} |
550 |
feature.setAttribute(ID_FIELD_ID,i); |
551 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
552 |
feature.setGeometry(ID_FIELD_GEOMETRY,"Polyline3D");
|
553 |
// auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
|
554 |
// "FPolyline3D"));
|
555 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
556 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
|
557 |
// fea.getProp("dxfEntity")));
|
558 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
559 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
|
560 |
// fea.getProp("layer")));
|
561 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
562 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
563 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
564 |
if (fea.getProp("elevation") != null) { |
565 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
566 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
567 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
568 |
} |
569 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
570 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
571 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
572 |
// Attributes
|
573 |
for (int j = 0; j < nAtt; j++) { |
574 |
String[] attributes = new String[2]; |
575 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
576 |
feature.setAttribute(10+j,attributes[1]); |
577 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
578 |
// attributes[1]));
|
579 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
580 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
581 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
582 |
// fea.getProp(attributes[0])));
|
583 |
} |
584 |
} |
585 |
Geometry geom=gFactory.createPolyline3D(genPathX,elevations); |
586 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
587 |
// feature.setDefaultGeometry(geom);
|
588 |
addDXFFeature(feature); |
589 |
// addShape(nuevoShp, auxRow);
|
590 |
} else if (fea.getGeometry() instanceof Polygon |
591 |
&& !(fea.getGeometry() instanceof Polygon3D)) {
|
592 |
GeneralPathX genPathX = new GeneralPathX();
|
593 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
594 |
// creo el objeto firstPt.
|
595 |
Point2D firstPt = new Point2D.Double(); |
596 |
firstPt = fea.getGeometry().get(0);
|
597 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr() + 1]; |
598 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
599 |
pts[j] = fea.getGeometry().get(j); |
600 |
} |
601 |
// 050112: A?ado el primer punto al final para cerrar los
|
602 |
// pol?gonos.
|
603 |
pts[fea.getGeometry().pointNr()] = firstPt; |
604 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
605 |
for (int j = 1; j < pts.length; j++) { |
606 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
607 |
} |
608 |
feature.setAttribute(ID_FIELD_ID,i); |
609 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
610 |
feature.setGeometry(ID_FIELD_GEOMETRY,"Polygon2D");
|
611 |
// auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
|
612 |
// "FPolygon2D"));
|
613 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
614 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
|
615 |
// fea.getProp("dxfEntity")));
|
616 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
617 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
|
618 |
// fea.getProp("layer")));
|
619 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
620 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
621 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
622 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
623 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
624 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
625 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
626 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
627 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
628 |
// Attributes
|
629 |
for (int j = 0; j < nAtt; j++) { |
630 |
String[] attributes = new String[2]; |
631 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
632 |
feature.setAttribute(10+j,attributes[1]); |
633 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
634 |
// attributes[1]));
|
635 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
636 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
637 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
638 |
// fea.getProp(attributes[0])));
|
639 |
} |
640 |
} |
641 |
Geometry geom=gFactory.createPolygon2D(genPathX); |
642 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
643 |
// feature.setDefaultGeometry(geom);
|
644 |
addDXFFeature(feature); |
645 |
// addShape(nuevoShp, auxRow);
|
646 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
647 |
GeneralPathX genPathX = new GeneralPathX();
|
648 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
649 |
// creo el objeto firstPt.
|
650 |
Point3D firstPt = new Point3D();
|
651 |
firstPt = ((Polygon3D) fea.getGeometry()) |
652 |
.getPoint3D(0);
|
653 |
Point3D[] pts = new Point3D[fea.getGeometry().pointNr() + 1]; |
654 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
655 |
pts[j] = ((Polygon3D) fea.getGeometry()) |
656 |
.getPoint3D(j); |
657 |
} |
658 |
// 050112: A?ado el primer punto al final para cerrar los
|
659 |
// pol?gonos.
|
660 |
pts[fea.getGeometry().pointNr()] = firstPt; |
661 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
662 |
for (int j = 1; j < pts.length; j++) { |
663 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
664 |
} |
665 |
double[] elevations = new double[pts.length]; |
666 |
for (int j = 0; j < pts.length; j++) { |
667 |
elevations[j] = pts[j].getZ(); |
668 |
} |
669 |
feature.setAttribute(ID_FIELD_ID,i); |
670 |
// auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
671 |
feature.setGeometry(ID_FIELD_GEOMETRY,"Polygon3D");
|
672 |
// auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
|
673 |
// "FPolygon3D"));
|
674 |
feature.setAttribute(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
|
675 |
// auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
|
676 |
// fea.getProp("dxfEntity")));
|
677 |
feature.setAttribute(ID_FIELD_LAYER,fea.getProp("layer"));
|
678 |
// auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
|
679 |
// fea.getProp("layer")));
|
680 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
681 |
feature.setAttribute(ID_FIELD_COLOR,auxInt); |
682 |
// auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
683 |
if (fea.getProp("elevation") != null) { |
684 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
685 |
feature.setAttribute(ID_FIELD_ELEVATION,auxE); |
686 |
// auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
|
687 |
} |
688 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
689 |
feature.setAttribute(ID_FIELD_THICKNESS,auxT); |
690 |
// auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
|
691 |
// Attributes
|
692 |
for (int j = 0; j < nAtt; j++) { |
693 |
String[] attributes = new String[2]; |
694 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
695 |
feature.setAttribute(10+j,attributes[1]); |
696 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
697 |
// attributes[1]));
|
698 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
699 |
feature.setAttribute(10+j,fea.getProp(attributes[0])); |
700 |
// auxRow[10 + j] = ValueFactory.createValue(new String(
|
701 |
// fea.getProp(attributes[0])));
|
702 |
} |
703 |
} |
704 |
Geometry geom=gFactory.createPolygon3D(genPathX,elevations); |
705 |
feature.setGeometry(ID_FIELD_GEOMETRY,geom); |
706 |
// feature.setDefaultGeometry(geom);
|
707 |
addDXFFeature(feature); |
708 |
// addShape(nuevoShp, auxRow);
|
709 |
} else {
|
710 |
// System.out.println("Detectado feature desconocido");
|
711 |
} |
712 |
feature.stopLoading(); |
713 |
}catch (IsNotFeatureSettingException e) {
|
714 |
e.printStackTrace(); |
715 |
} |
716 |
} |
717 |
|
718 |
if (legendlabelingManager != null) { |
719 |
legendlabelingManager.endLoading(); |
720 |
} |
721 |
|
722 |
|
723 |
// ISymbol theSymbol = null;
|
724 |
//
|
725 |
// for (long j = 0; j < featuresAux.size(); j++) {
|
726 |
// Feature feat=(Feature)featuresAux.get((int)j);
|
727 |
// int clave=feat.getInt(ID_FIELD_COLOR);
|
728 |
//// clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR);
|
729 |
// if (defaultLegend.getSymbolByValue(clave) == null) {
|
730 |
// theSymbol = SymbologyFactory.
|
731 |
// createDefaultSymbolByShapeType(
|
732 |
// FShape.MULTI,
|
733 |
// AcadColor.getColor(clave.getValue()));
|
734 |
// theSymbol.setDescription(clave.toString());
|
735 |
// // Asigna los colores de Autocad a los
|
736 |
// // bordes
|
737 |
// // de los pol?gonos.
|
738 |
// if (theSymbol instanceof IFillSymbol) {
|
739 |
// ((IFillSymbol) theSymbol).getOutline().setLineColor(AcadColor.getColor(clave
|
740 |
// .getValue()));
|
741 |
//
|
742 |
// }
|
743 |
// defaultLegend.addSymbol(clave, theSymbol);
|
744 |
// }
|
745 |
// } // for
|
746 |
|
747 |
} |
748 |
|
749 |
private void addDXFFeature(org.gvsig.fmap.data.feature.Feature feature) throws DataException{ |
750 |
DXFFeature newFeature = new DXFFeature(feature);
|
751 |
this.add(newFeature);
|
752 |
if (this.legendlabelingManager != null) { |
753 |
this.legendlabelingManager.add(newFeature, null); |
754 |
} |
755 |
|
756 |
} |
757 |
|
758 |
/* (non-Javadoc)
|
759 |
* @see org.gvsig.fmap.data.feature.file.IFileResource#getTotalFiles()
|
760 |
*/
|
761 |
public int getTotalFiles() { |
762 |
return 1; |
763 |
} |
764 |
|
765 |
/* (non-Javadoc)
|
766 |
* @see org.gvsig.fmap.data.feature.file.FileResource#editing()
|
767 |
*/
|
768 |
protected void editing() { |
769 |
super.editing();
|
770 |
} |
771 |
|
772 |
/* (non-Javadoc)
|
773 |
* @see org.gvsig.fmap.data.feature.file.FileResource#isEditing()
|
774 |
*/
|
775 |
protected boolean isEditing() { |
776 |
return super.isEditing(); |
777 |
} |
778 |
|
779 |
/* (non-Javadoc)
|
780 |
* @see org.gvsig.fmap.data.feature.file.FileResource#stopEditing()
|
781 |
*/
|
782 |
protected void stopEditing() { |
783 |
super.stopEditing();
|
784 |
} |
785 |
|
786 |
protected Object getDefaultLegend() throws ReadException { |
787 |
this.checkOpen();
|
788 |
if (legendlabelingManager == null) { |
789 |
return null; |
790 |
} |
791 |
return legendlabelingManager.getDefaultLegend();
|
792 |
} |
793 |
|
794 |
protected Object getDefaultLabelingStrategy() throws ReadException { |
795 |
this.checkOpen();
|
796 |
if (legendlabelingManager == null) { |
797 |
return null; |
798 |
} |
799 |
return legendlabelingManager.getLabeling();
|
800 |
} |
801 |
|
802 |
public static void setLegendLabelingManagerFactory( |
803 |
LegendLabelingManagerFactory factory) { |
804 |
legendLabelingManagerFactory = factory; |
805 |
} |
806 |
|
807 |
public static LegendLabelingManagerFactory getLegendLabelingManagerFactory() { |
808 |
return legendLabelingManagerFactory;
|
809 |
} |
810 |
|
811 |
} |
812 |
|