root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / DXFMemoryDriver.java @ 31807
History | View | Annotate | Download (36.4 KB)
1 |
/*
|
---|---|
2 |
* @(#)DXFMemoryDriver 29-dic-2004
|
3 |
*
|
4 |
* @author jmorell (jose.morell@gmail.com)
|
5 |
*/
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
7 |
*
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
9 |
*
|
10 |
* This program is free software; you can redistribute it and/or
|
11 |
* modify it under the terms of the GNU General Public License
|
12 |
* as published by the Free Software Foundation; either version 2
|
13 |
* of the License, or (at your option) any later version.
|
14 |
*
|
15 |
* This program is distributed in the hope that it will be useful,
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
* GNU General Public License for more details.
|
19 |
*
|
20 |
* You should have received a copy of the GNU General Public License
|
21 |
* along with this program; if not, write to the Free Software
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
23 |
*
|
24 |
* For more information, contact:
|
25 |
*
|
26 |
* Generalitat Valenciana
|
27 |
* Conselleria d'Infraestructures i Transport
|
28 |
* Av. Blasco Ib??ez, 50
|
29 |
* 46010 VALENCIA
|
30 |
* SPAIN
|
31 |
*
|
32 |
* +34 963862235
|
33 |
* gvsig@gva.es
|
34 |
* www.gvsig.gva.es
|
35 |
*
|
36 |
* or
|
37 |
*
|
38 |
* IVER T.I. S.A
|
39 |
* Salamanca 50
|
40 |
* 46005 Valencia
|
41 |
* Spain
|
42 |
*
|
43 |
* +34 963163400
|
44 |
* dac@iver.es
|
45 |
*/
|
46 |
package com.iver.cit.gvsig.fmap.drivers.dxf; |
47 |
|
48 |
import java.awt.Color; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.io.File; |
51 |
import java.io.FileInputStream; |
52 |
import java.io.FileNotFoundException; |
53 |
import java.io.FileOutputStream; |
54 |
import java.io.IOException; |
55 |
import java.nio.channels.FileChannel; |
56 |
import java.sql.Types; |
57 |
import java.util.ArrayList; |
58 |
import java.util.Properties; |
59 |
import java.util.logging.Logger; |
60 |
import java.util.regex.Matcher; |
61 |
import java.util.regex.Pattern; |
62 |
|
63 |
import javax.swing.table.DefaultTableModel; |
64 |
|
65 |
import org.cresques.cts.IProjection; |
66 |
import org.cresques.geo.Point3D; |
67 |
import org.cresques.io.DxfFile; |
68 |
import org.cresques.px.IObjList; |
69 |
import org.cresques.px.dxf.AcadColor; |
70 |
import org.cresques.px.dxf.DxfFeatureMaker; |
71 |
import org.cresques.px.dxf.DxfHeaderManager; |
72 |
import org.cresques.px.gml.Feature; |
73 |
import org.cresques.px.gml.LineString; |
74 |
import org.cresques.px.gml.LineString3D; |
75 |
import org.cresques.px.gml.Point; |
76 |
import org.cresques.px.gml.Polygon; |
77 |
import org.cresques.px.gml.Polygon3D; |
78 |
|
79 |
import com.hardcode.gdbms.driver.DriverUtilities; |
80 |
import com.hardcode.gdbms.driver.exceptions.FileNotFoundDriverException; |
81 |
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
82 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
83 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
84 |
import com.hardcode.gdbms.driver.exceptions.ReloadDriverException; |
85 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
86 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
87 |
import com.hardcode.gdbms.engine.values.IntValue; |
88 |
import com.hardcode.gdbms.engine.values.Value; |
89 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
90 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException; |
91 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
92 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
93 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
94 |
import com.iver.cit.gvsig.fmap.core.FPoint3D; |
95 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
96 |
import com.iver.cit.gvsig.fmap.core.FPolygon3D; |
97 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
98 |
import com.iver.cit.gvsig.fmap.core.FPolyline3D; |
99 |
import com.iver.cit.gvsig.fmap.core.FShape; |
100 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
101 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
102 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
103 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
104 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
105 |
import com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver; |
106 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
107 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
108 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
109 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
110 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
111 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
112 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
113 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
114 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
115 |
import com.iver.cit.gvsig.fmap.edition.writers.dxf.DxfFieldsMapping; |
116 |
import com.iver.cit.gvsig.fmap.edition.writers.dxf.DxfWriter; |
117 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
118 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
119 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
120 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy; |
121 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy; |
122 |
|
123 |
/**
|
124 |
* @author jmorell (jose.morell@gmail.com)
|
125 |
* @author azabala
|
126 |
* @version 29-dic-2004
|
127 |
*/
|
128 |
public class DXFMemoryDriver extends AbstractCadMemoryDriver implements |
129 |
VectorialFileDriver, WithDefaultLegend, ISpatialWriter, IWriteable { |
130 |
|
131 |
private static String tempDirectoryPath = System |
132 |
.getProperty("java.io.tmpdir");
|
133 |
|
134 |
|
135 |
private DxfWriter dxfWriter = new DxfWriter(); |
136 |
private File fTemp; |
137 |
VectorialUniqueValueLegend defaultLegend; |
138 |
private File m_Fich; |
139 |
private DxfFile.EntityFactory featureMaker;
|
140 |
private DxfFile dxfFeatureFile;
|
141 |
private IObjList.vector features;
|
142 |
private DriverAttributes attr = new DriverAttributes(); |
143 |
|
144 |
/**
|
145 |
* Habilita la utilizaci?n del lector del HEADER del DXF.
|
146 |
*/
|
147 |
private DxfFile.VarSettings headerManager;
|
148 |
private AttrInTableLabelingStrategy labeling;
|
149 |
|
150 |
/*
|
151 |
* (non-Javadoc)
|
152 |
*
|
153 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
154 |
*/
|
155 |
public void open(File f) { |
156 |
m_Fich = f; |
157 |
} |
158 |
|
159 |
public void initialize() throws ReadDriverException { |
160 |
float heightText = 10; |
161 |
|
162 |
attr.setLoadedInMemory(true);
|
163 |
|
164 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
165 |
featureMaker = new DxfFeatureMaker(proj);
|
166 |
headerManager = new DxfHeaderManager();
|
167 |
dxfFeatureFile = new DxfFile(proj, m_Fich.getAbsolutePath(),
|
168 |
featureMaker, headerManager); |
169 |
try {
|
170 |
dxfFeatureFile.load(); |
171 |
} catch (Exception e1) { |
172 |
// throw new FileNotFoundDriverException(getName(),e1);
|
173 |
} |
174 |
features = (IObjList.vector) ((DxfFeatureMaker) featureMaker) |
175 |
.getObjects(); |
176 |
String acadVersion = (String) ((DxfHeaderManager) headerManager) |
177 |
.getAcadVersion(); |
178 |
System.out.println("initialize(): acadVersion = " + acadVersion); |
179 |
if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) { // y no |
180 |
// est?n
|
181 |
// todos
|
182 |
// a
|
183 |
// 9999
|
184 |
Feature[] features2D = new Feature[features.size()]; |
185 |
for (int i = 0; i < features.size(); i++) { |
186 |
Feature fea = (Feature) features.get(i); |
187 |
if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
188 |
Point point = (Point) fea.getGeometry(); |
189 |
Point point2 = new Point(); |
190 |
for (int j = 0; j < point.pointNr(); j++) { |
191 |
point2.add(point.get(j)); |
192 |
} |
193 |
point2.setTextPoint(point.isTextPoint()); |
194 |
fea.setGeometry(point2); |
195 |
features2D[i] = fea; |
196 |
// } else if (fea.getGeometry() instanceof InsPoint3D) {
|
197 |
// InsPoint insPoint = (InsPoint)fea.getGeometry();
|
198 |
// InsPoint insPoint2 = new InsPoint();
|
199 |
// for (int j=0;j<insPoint.pointNr();j++) {
|
200 |
// insPoint2.add(insPoint.get(j));
|
201 |
// }
|
202 |
// fea.setGeometry(insPoint2);
|
203 |
// features2D[i] = fea;
|
204 |
} else if (fea.getGeometry() instanceof LineString3D) { |
205 |
LineString lineString = (LineString) fea.getGeometry(); |
206 |
LineString lineString2 = new LineString();
|
207 |
for (int j = 0; j < lineString.pointNr(); j++) { |
208 |
lineString2.add(lineString.get(j)); |
209 |
} |
210 |
fea.setGeometry(lineString2); |
211 |
features2D[i] = fea; |
212 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
213 |
Polygon polygon = (Polygon) fea.getGeometry(); |
214 |
Polygon polygon2 = new Polygon(); |
215 |
for (int j = 0; j < polygon.pointNr(); j++) { |
216 |
polygon2.add(polygon.get(j)); |
217 |
} |
218 |
fea.setGeometry(polygon2); |
219 |
features2D[i] = fea; |
220 |
} |
221 |
} |
222 |
features.clear(); |
223 |
for (int i = 0; i < features2D.length; i++) { |
224 |
features.add(features2D[i]); |
225 |
} |
226 |
} |
227 |
// String acadVersion =
|
228 |
// (String)((DxfHeaderManager)headerManager).getAcadVersion();
|
229 |
// System.out.println("initialize(): acadVersion = " + acadVersion);
|
230 |
|
231 |
int nAtt = featureMaker.getAttributes().size();
|
232 |
|
233 |
// Campos de las MemoryLayer:
|
234 |
Value[] auxRow = new Value[10 + nAtt]; |
235 |
ArrayList arrayFields = new ArrayList(); |
236 |
arrayFields.add("ID");
|
237 |
arrayFields.add("FShape");
|
238 |
arrayFields.add("Entity");
|
239 |
arrayFields.add("Layer");
|
240 |
arrayFields.add("Color");
|
241 |
arrayFields.add("Elevation");
|
242 |
arrayFields.add("Thickness");
|
243 |
arrayFields.add("Text");
|
244 |
arrayFields.add("HeightText");
|
245 |
arrayFields.add("RotationText");
|
246 |
for (int i = 0; i < nAtt; i++) { |
247 |
String att[] = new String[2]; |
248 |
att = (String[]) featureMaker.getAttributes().get(i); |
249 |
arrayFields.add(att[0]);
|
250 |
} |
251 |
|
252 |
labeling = new AttrInTableLabelingStrategy();
|
253 |
((AttrInTableLabelingStrategy) labeling).setTextFieldId(arrayFields.indexOf("Text"));
|
254 |
((AttrInTableLabelingStrategy) labeling).setRotationFieldId(arrayFields.indexOf("RotationText"));
|
255 |
((AttrInTableLabelingStrategy) labeling).setHeightFieldId(arrayFields.indexOf("HeightText"));
|
256 |
((AttrInTableLabelingStrategy) labeling).setUnit(1); //MapContext.NAMES[1] (meters) |
257 |
|
258 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
259 |
|
260 |
for (int i = 0; i < features.size(); i++) { |
261 |
|
262 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
|
263 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
|
264 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
265 |
|
266 |
Feature fea = (Feature) features.get(i); |
267 |
if (fea.getGeometry() instanceof Point |
268 |
&& !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
|
269 |
Point point = (Point) fea.getGeometry(); |
270 |
Point2D pto = new Point2D.Double(); |
271 |
pto = point.get(0);
|
272 |
FShape nuevoShp; |
273 |
if (point.isTextPoint()) {
|
274 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
275 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
276 |
.createValue(new String("FPoint2D")); |
277 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
278 |
.createValue(new String(fea.getProp("dxfEntity"))); |
279 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
280 |
.createValue(new String(fea.getProp("layer"))); |
281 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
282 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
283 |
auxRow[ID_FIELD_TEXT] = ValueFactory |
284 |
.createValue(getTextFromMtext(fixUnicode(new String(fea.getProp("text"))))); |
285 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
286 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
287 |
.createValue(heightText); |
288 |
double auxR = Double.parseDouble(fea |
289 |
.getProp("textRotation"));
|
290 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
291 |
.createValue(auxR); |
292 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
293 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
294 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
295 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
296 |
// Attributes
|
297 |
for (int j = 0; j < nAtt; j++) { |
298 |
String[] attributes = new String[2]; |
299 |
attributes = (String[]) featureMaker.getAttributes() |
300 |
.get(j); |
301 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
302 |
attributes[1]));
|
303 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
304 |
auxRow[10 + j] = ValueFactory
|
305 |
.createValue(new String(fea |
306 |
.getProp(attributes[0])));
|
307 |
} |
308 |
} |
309 |
nuevoShp = new FPoint2D(pto.getX(), pto.getY());
|
310 |
addShape(nuevoShp, auxRow); |
311 |
} else {
|
312 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
313 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
314 |
.createValue(new String("FPoint2D")); |
315 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
316 |
.createValue(new String(fea.getProp("dxfEntity"))); |
317 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
318 |
.createValue(new String(fea.getProp("layer"))); |
319 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
320 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
321 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
322 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
323 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
324 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
325 |
// Attributes
|
326 |
for (int j = 0; j < nAtt; j++) { |
327 |
String[] attributes = new String[2]; |
328 |
attributes = (String[]) featureMaker.getAttributes() |
329 |
.get(j); |
330 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
331 |
attributes[1]));
|
332 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
333 |
auxRow[10 + j] = ValueFactory
|
334 |
.createValue(new String(fea |
335 |
.getProp(attributes[0])));
|
336 |
} |
337 |
} |
338 |
nuevoShp = new FPoint2D(pto.getX(), pto.getY());
|
339 |
addShape(nuevoShp, auxRow); |
340 |
} |
341 |
} else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
342 |
org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D) fea |
343 |
.getGeometry(); |
344 |
Point3D pto = new Point3D();
|
345 |
pto = point.getPoint3D(0);
|
346 |
FShape nuevoShp; |
347 |
if (point.isTextPoint()) {
|
348 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
349 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
350 |
.createValue(new String("FPoint3D")); |
351 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
352 |
.createValue(new String(fea.getProp("dxfEntity"))); |
353 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
354 |
.createValue(new String(fea.getProp("layer"))); |
355 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
356 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
357 |
auxRow[ID_FIELD_TEXT] = ValueFactory |
358 |
.createValue(getTextFromMtext(fixUnicode(new String(fea.getProp("text"))))); |
359 |
heightText = Float.parseFloat(fea.getProp("textHeight")); |
360 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
361 |
.createValue(heightText); |
362 |
double auxR = Double.parseDouble(fea |
363 |
.getProp("textRotation"));
|
364 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
365 |
.createValue(auxR); |
366 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
367 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
368 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
369 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
370 |
// Attributes
|
371 |
for (int j = 0; j < nAtt; j++) { |
372 |
String[] attributes = new String[2]; |
373 |
attributes = (String[]) featureMaker.getAttributes() |
374 |
.get(j); |
375 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
376 |
attributes[1]));
|
377 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
378 |
auxRow[10 + j] = ValueFactory
|
379 |
.createValue(new String(fea |
380 |
.getProp(attributes[0])));
|
381 |
} |
382 |
} |
383 |
nuevoShp = new FPoint3D(pto.getX(), pto.getY(), pto.getZ());
|
384 |
addShape(nuevoShp, auxRow); |
385 |
} else {
|
386 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
387 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory |
388 |
.createValue(new String("FPoint3D")); |
389 |
auxRow[ID_FIELD_ENTITY] = ValueFactory |
390 |
.createValue(new String(fea.getProp("dxfEntity"))); |
391 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
392 |
.createValue(new String(fea.getProp("layer"))); |
393 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
394 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
395 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
396 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
397 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
398 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
399 |
// Attributes
|
400 |
for (int j = 0; j < nAtt; j++) { |
401 |
String[] attributes = new String[2]; |
402 |
attributes = (String[]) featureMaker.getAttributes() |
403 |
.get(j); |
404 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
405 |
attributes[1]));
|
406 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
407 |
auxRow[10 + j] = ValueFactory
|
408 |
.createValue(new String(fea |
409 |
.getProp(attributes[0])));
|
410 |
} |
411 |
} |
412 |
nuevoShp = new FPoint3D(pto.getX(), pto.getY(), pto.getZ());
|
413 |
addShape(nuevoShp, auxRow); |
414 |
} |
415 |
/*
|
416 |
* } else if (fea.getGeometry() instanceof InsPoint &&
|
417 |
* !(fea.getGeometry() instanceof InsPoint3D)) { InsPoint
|
418 |
* insPoint = (InsPoint)fea.getGeometry(); Point2D pto = new
|
419 |
* Point2D.Double(); pto = (Point2D)insPoint.get(0);
|
420 |
* auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
421 |
* auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new
|
422 |
* String("PointZ")); auxRow[ID_FIELD_ENTITY] =
|
423 |
* ValueFactory.createValue(new
|
424 |
* String(fea.getProp("dxfEntity"))); auxRow[ID_FIELD_LAYER] =
|
425 |
* ValueFactory.createValue(new String(fea.getProp("layer")));
|
426 |
* int auxInt = Integer.parseInt(fea.getProp("color"));
|
427 |
* auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
428 |
* double auxE = Double.parseDouble(fea.getProp("elevation"));
|
429 |
* auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); //
|
430 |
* Attributes for (int j=0;j<nAtt;j++) { String[] attributes =
|
431 |
* new String[2]; attributes =
|
432 |
* (String[])featureMaker.getAttributes().get(j); auxRow[9+j] =
|
433 |
* ValueFactory.createValue(new String((String)attributes[1]));
|
434 |
* if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
435 |
* auxRow[9+j] = ValueFactory.createValue(new
|
436 |
* String(fea.getProp(attributes[0]))); } } FShape nuevoShp =
|
437 |
* new FPoint2D(pto.getX(),pto.getY()); addShape(nuevoShp,
|
438 |
* auxRow); } else if (fea.getGeometry() instanceof InsPoint3D) {
|
439 |
* InsPoint3D insPoint = (InsPoint3D)fea.getGeometry(); Point3D
|
440 |
* pto = new Point3D(); pto = (Point3D)insPoint.getPoint3D(0);
|
441 |
* auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
|
442 |
* auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new
|
443 |
* String("PointZ")); auxRow[ID_FIELD_ENTITY] =
|
444 |
* ValueFactory.createValue(new
|
445 |
* String(fea.getProp("dxfEntity"))); auxRow[ID_FIELD_LAYER] =
|
446 |
* ValueFactory.createValue(new String(fea.getProp("layer")));
|
447 |
* int auxInt = Integer.parseInt(fea.getProp("color"));
|
448 |
* auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
|
449 |
* double auxE = Double.parseDouble(fea.getProp("elevation"));
|
450 |
* auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); //
|
451 |
* Attributes for (int j=0;j<nAtt;j++) { String[] attributes =
|
452 |
* new String[2]; attributes =
|
453 |
* (String[])featureMaker.getAttributes().get(j); auxRow[9+j] =
|
454 |
* ValueFactory.createValue(new String((String)attributes[1]));
|
455 |
* if (!fea.getProp(attributes[0]).equals(attributes[1])) {
|
456 |
* auxRow[9+j] = ValueFactory.createValue(new
|
457 |
* String(fea.getProp(attributes[0]))); } } FShape nuevoShp =
|
458 |
* new FPoint3D(pto.getX(),pto.getY(),pto.getZ());
|
459 |
* addShape(nuevoShp, auxRow);
|
460 |
*/
|
461 |
} else if (fea.getGeometry() instanceof LineString |
462 |
&& !(fea.getGeometry() instanceof LineString3D)) {
|
463 |
GeneralPathX genPathX = new GeneralPathX();
|
464 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr()]; |
465 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
466 |
pts[j] = fea.getGeometry().get(j); |
467 |
} |
468 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
469 |
for (int j = 1; j < pts.length; j++) { |
470 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
471 |
} |
472 |
// double[] elevations = new double[pts.length];
|
473 |
// for (int j=0;j<pts.length;j++) {
|
474 |
// elevations[j]=pts[j].getZ();
|
475 |
// }
|
476 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
477 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
478 |
"FPolyline2D"));
|
479 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
480 |
fea.getProp("dxfEntity")));
|
481 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
482 |
fea.getProp("layer")));
|
483 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
484 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
485 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
486 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
487 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
488 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
489 |
// Attributes
|
490 |
for (int j = 0; j < nAtt; j++) { |
491 |
String[] attributes = new String[2]; |
492 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
493 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
494 |
attributes[1]));
|
495 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
496 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
497 |
fea.getProp(attributes[0])));
|
498 |
} |
499 |
} |
500 |
FShape nuevoShp = new FPolyline2D(genPathX);
|
501 |
addShape(nuevoShp, auxRow); |
502 |
} else if (fea.getGeometry() instanceof LineString3D) { |
503 |
GeneralPathX genPathX = new GeneralPathX();
|
504 |
Point3D[] pts = new Point3D[fea.getGeometry().pointNr()]; |
505 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
506 |
pts[j] = ((LineString3D) fea.getGeometry()).getPoint3D(j); |
507 |
} |
508 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
509 |
for (int j = 1; j < pts.length; j++) { |
510 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
511 |
} |
512 |
double[] elevations = new double[pts.length]; |
513 |
for (int j = 0; j < pts.length; j++) { |
514 |
elevations[j] = pts[j].getZ(); |
515 |
} |
516 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
517 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
518 |
"FPolyline3D"));
|
519 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
520 |
fea.getProp("dxfEntity")));
|
521 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
522 |
fea.getProp("layer")));
|
523 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
524 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
525 |
if (fea.getProp("elevation") != null) { |
526 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
527 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
528 |
} |
529 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
530 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
531 |
// Attributes
|
532 |
for (int j = 0; j < nAtt; j++) { |
533 |
String[] attributes = new String[2]; |
534 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
535 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
536 |
attributes[1]));
|
537 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
538 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
539 |
fea.getProp(attributes[0])));
|
540 |
} |
541 |
} |
542 |
FShape nuevoShp = new FPolyline3D(genPathX, elevations);
|
543 |
addShape(nuevoShp, auxRow); |
544 |
} else if (fea.getGeometry() instanceof Polygon |
545 |
&& !(fea.getGeometry() instanceof Polygon3D)) {
|
546 |
GeneralPathX genPathX = new GeneralPathX();
|
547 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
548 |
// creo el objeto firstPt.
|
549 |
Point2D firstPt = new Point2D.Double(); |
550 |
firstPt = fea.getGeometry().get(0);
|
551 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr() + 1]; |
552 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
553 |
pts[j] = fea.getGeometry().get(j); |
554 |
} |
555 |
// 050112: A?ado el primer punto al final para cerrar los
|
556 |
// pol?gonos.
|
557 |
pts[fea.getGeometry().pointNr()] = firstPt; |
558 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
559 |
for (int j = 1; j < pts.length; j++) { |
560 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
561 |
} |
562 |
// double[] elevations = new double[pts.length];
|
563 |
// for (int j=0;j<pts.length;j++) {
|
564 |
// elevations[j]=pts[j].getZ();
|
565 |
// }
|
566 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
567 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
568 |
"FPolygon2D"));
|
569 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
570 |
fea.getProp("dxfEntity")));
|
571 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
572 |
fea.getProp("layer")));
|
573 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
574 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
575 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
576 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
577 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
578 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
579 |
// Attributes
|
580 |
for (int j = 0; j < nAtt; j++) { |
581 |
String[] attributes = new String[2]; |
582 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
583 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
584 |
attributes[1]));
|
585 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
586 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
587 |
fea.getProp(attributes[0])));
|
588 |
} |
589 |
} |
590 |
FShape nuevoShp = new FPolygon2D(genPathX);
|
591 |
addShape(nuevoShp, auxRow); |
592 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
593 |
GeneralPathX genPathX = new GeneralPathX();
|
594 |
// 050112: A?ado una posici?n m?s para el punto que cierra y
|
595 |
// creo el objeto firstPt.
|
596 |
Point2D firstPt = new Point3D(); |
597 |
Point2D p=((Polygon3D) fea.getGeometry())
|
598 |
.get(0);
|
599 |
if (p instanceof Point2D.Float){ |
600 |
firstPt=new Point3D(p);
|
601 |
}else
|
602 |
firstPt = p; |
603 |
Point2D[] pts = new Point3D[fea.getGeometry().pointNr() + 1]; |
604 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
605 |
p=((Polygon3D) fea.getGeometry()) |
606 |
.get(j); |
607 |
if (p instanceof Point2D.Float){ |
608 |
pts[j]=new Point3D(p);
|
609 |
}else
|
610 |
pts[j] = p; |
611 |
} |
612 |
// 050112: A?ado el primer punto al final para cerrar los
|
613 |
// pol?gonos.
|
614 |
pts[fea.getGeometry().pointNr()] = firstPt; |
615 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
616 |
for (int j = 1; j < pts.length; j++) { |
617 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
618 |
} |
619 |
double[] elevations = new double[pts.length]; |
620 |
for (int j = 0; j < pts.length; j++) { |
621 |
if (pts[j] instanceof Point3D) |
622 |
elevations[j] = ((Point3D)pts[j]).getZ(); |
623 |
} |
624 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
625 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String( |
626 |
"FPolygon3D"));
|
627 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String( |
628 |
fea.getProp("dxfEntity")));
|
629 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String( |
630 |
fea.getProp("layer")));
|
631 |
int auxInt = Integer.parseInt(fea.getProp("color")); |
632 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt); |
633 |
if (fea.getProp("elevation") != null) { |
634 |
double auxE = Double.parseDouble(fea.getProp("elevation")); |
635 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE); |
636 |
} |
637 |
double auxT = Double.parseDouble(fea.getProp("thickness")); |
638 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT); |
639 |
// Attributes
|
640 |
for (int j = 0; j < nAtt; j++) { |
641 |
String[] attributes = new String[2]; |
642 |
attributes = (String[]) featureMaker.getAttributes().get(j); |
643 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
644 |
attributes[1]));
|
645 |
if (!fea.getProp(attributes[0]).equals(attributes[1])) { |
646 |
auxRow[10 + j] = ValueFactory.createValue(new String( |
647 |
fea.getProp(attributes[0])));
|
648 |
} |
649 |
} |
650 |
FShape nuevoShp = new FPolygon3D(genPathX, elevations);
|
651 |
addShape(nuevoShp, auxRow); |
652 |
} else {
|
653 |
// System.out.println("Detectado feature desconocido");
|
654 |
} |
655 |
} |
656 |
|
657 |
defaultLegend = LegendFactory |
658 |
.createVectorialUniqueValueLegend(getShapeType()); |
659 |
defaultLegend.setClassifyingFieldNames(new String[] {"Color"}); |
660 |
defaultLegend.setClassifyingFieldTypes(new int[]{Types.INTEGER,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.INTEGER,Types.DOUBLE,Types.DOUBLE}); |
661 |
|
662 |
Logger.getAnonymousLogger().info("DXFMemoryDriver: should check if this is a text symbol"); |
663 |
ISymbol myDefaultSymbol = SymbologyFactory. |
664 |
createDefaultSymbolByShapeType(getShapeType(), Color.BLACK);
|
665 |
|
666 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
667 |
|
668 |
ObjectDriver rs = this;
|
669 |
IntValue clave; |
670 |
ISymbol theSymbol = null;
|
671 |
|
672 |
try {
|
673 |
// TODO: Provisional hasta que cambiemos los s?mbolos.
|
674 |
/*
|
675 |
* BufferedImage bi= new BufferedImage(5, 5,
|
676 |
* BufferedImage.TYPE_INT_ARGB); Graphics2D big =
|
677 |
* bi.createGraphics(); Color color=new Color(0,0,0,0);
|
678 |
* big.setBackground(color); big.clearRect(0, 0, 5, 5); Paint
|
679 |
* fillProv = null; Rectangle2D rProv = new Rectangle();
|
680 |
* rProv.setFrame(0, 0,5,5); fillProv = new TexturePaint(bi,rProv);
|
681 |
*/
|
682 |
|
683 |
for (long j = 0; j < rs.getRowCount(); j++) { |
684 |
clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR); |
685 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
686 |
/*
|
687 |
theSymbol = new FSymbol(getShapeType());
|
688 |
theSymbol.setDescription(clave.toString());
|
689 |
theSymbol.setColor(AcadColor.getColor(clave.getValue()));
|
690 |
// theSymbol.setFill(fillProv);
|
691 |
// 050202, jmorell: Asigna los colores de Autocad a los
|
692 |
// bordes
|
693 |
// de los pol?gonos.
|
694 |
theSymbol.setOutlineColor(AcadColor.getColor(clave
|
695 |
.getValue()));
|
696 |
|
697 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
|
698 |
theSymbol.setSize(3);
|
699 |
theSymbol.setSizeInPixels(true);
|
700 |
*/
|
701 |
Color color=null; |
702 |
try{
|
703 |
color=AcadColor.getColor(clave.getValue()); |
704 |
}catch (ArrayIndexOutOfBoundsException e) { |
705 |
color=AcadColor.getColor(255);
|
706 |
} |
707 |
// jaume, moved to ISymbol
|
708 |
theSymbol = SymbologyFactory. |
709 |
createDefaultSymbolByShapeType( |
710 |
getShapeType(), |
711 |
color); |
712 |
theSymbol.setDescription(clave.toString()); |
713 |
// Asigna los colores de Autocad a los
|
714 |
// bordes
|
715 |
// de los pol?gonos.
|
716 |
if (theSymbol instanceof IFillSymbol) { |
717 |
((IFillSymbol) theSymbol).getOutline().setLineColor(color); |
718 |
|
719 |
} |
720 |
defaultLegend.addSymbol(clave, theSymbol); |
721 |
} |
722 |
} // for
|
723 |
} catch (ReadDriverException e) {
|
724 |
throw new InitializeDriverException(getName(),e); |
725 |
} |
726 |
} |
727 |
|
728 |
/*
|
729 |
* (non-Javadoc)
|
730 |
*
|
731 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
732 |
*/
|
733 |
public boolean accept(File f) { |
734 |
return f.getName().toUpperCase().endsWith("DXF"); |
735 |
} |
736 |
|
737 |
/*
|
738 |
* (non-Javadoc)
|
739 |
*
|
740 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
741 |
*/
|
742 |
public int getShapeType() { |
743 |
return FShape.MULTI;
|
744 |
} |
745 |
|
746 |
/*
|
747 |
* (non-Javadoc)
|
748 |
*
|
749 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
750 |
*/
|
751 |
public String getName() { |
752 |
return "gvSIG DXF Memory Driver"; |
753 |
} |
754 |
|
755 |
/*
|
756 |
* (non-Javadoc)
|
757 |
*
|
758 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
759 |
*/
|
760 |
public ILegend getDefaultLegend() {
|
761 |
return defaultLegend;
|
762 |
} |
763 |
|
764 |
/*
|
765 |
* (non-Javadoc)
|
766 |
*
|
767 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
768 |
*/
|
769 |
public DriverAttributes getDriverAttributes() {
|
770 |
return attr;
|
771 |
} |
772 |
|
773 |
/**
|
774 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
775 |
*/
|
776 |
public int[] getPrimaryKeys() { |
777 |
return null; |
778 |
} |
779 |
|
780 |
/**
|
781 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
782 |
*/
|
783 |
public void write(DataWare arg0) { |
784 |
// TODO Auto-generated method stub
|
785 |
|
786 |
} |
787 |
|
788 |
/*
|
789 |
* (non-Javadoc)
|
790 |
*
|
791 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
792 |
*/
|
793 |
public void close() { |
794 |
// TODO Auto-generated method stub
|
795 |
|
796 |
} |
797 |
|
798 |
public File getFile() { |
799 |
return m_Fich;
|
800 |
} |
801 |
|
802 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
803 |
return dxfWriter.canWriteGeometry(gvSIGgeometryType);
|
804 |
} |
805 |
|
806 |
public void initialize(ITableDefinition layerDef) throws InitializeWriterException { |
807 |
int aux = (int) (Math.random() * 1000); |
808 |
fTemp = new File(tempDirectoryPath + "/tmpDxf" + aux + ".dxf"); |
809 |
dxfWriter.setFile(fTemp); |
810 |
|
811 |
dxfWriter.initialize(layerDef); |
812 |
/*
|
813 |
* arrayFields.add("ID"); arrayFields.add("FShape");
|
814 |
* arrayFields.add("Entity"); arrayFields.add("Layer");
|
815 |
* arrayFields.add("Color"); arrayFields.add("Elevation");
|
816 |
* arrayFields.add("Thickness"); arrayFields.add("Text");
|
817 |
* arrayFields.add("HeightText"); arrayFields.add("RotationText");
|
818 |
*/
|
819 |
|
820 |
DxfFieldsMapping fieldsMapping = new DxfFieldsMapping();
|
821 |
fieldsMapping.setLayerField("Layer");
|
822 |
fieldsMapping.setColorField("Color");
|
823 |
fieldsMapping.setElevationField("Elevation");
|
824 |
fieldsMapping.setThicknessField("Thickness");
|
825 |
fieldsMapping.setTextField("Text");
|
826 |
fieldsMapping.setHeightText("HeightText");
|
827 |
fieldsMapping.setRotationText("Layer");
|
828 |
dxfWriter.setFieldMapping(fieldsMapping); |
829 |
dxfWriter.setProjection(((ILayerDefinition)layerDef).getProjection()); |
830 |
} |
831 |
|
832 |
public void preProcess() throws StartWriterVisitorException { |
833 |
dxfWriter.preProcess(); |
834 |
} |
835 |
|
836 |
public void process(IRowEdited row) throws ProcessWriterVisitorException { |
837 |
dxfWriter.process(row); |
838 |
} |
839 |
|
840 |
public void postProcess() throws StopWriterVisitorException { |
841 |
dxfWriter.postProcess(); |
842 |
try {
|
843 |
|
844 |
// close();
|
845 |
|
846 |
// Dxf
|
847 |
FileChannel fcinDxf = new FileInputStream(fTemp).getChannel(); |
848 |
FileChannel fcoutDxf = new FileOutputStream(m_Fich).getChannel(); |
849 |
DriverUtilities.copy(fcinDxf, fcoutDxf); |
850 |
|
851 |
// Borramos los temporales
|
852 |
fTemp.delete(); |
853 |
// reload();
|
854 |
|
855 |
} catch (FileNotFoundException e) { |
856 |
throw new StopWriterVisitorException(getName(),e); |
857 |
} catch (IOException e) { |
858 |
throw new StopWriterVisitorException(getName(),e); |
859 |
} |
860 |
|
861 |
} |
862 |
|
863 |
public String getCapability(String capability) { |
864 |
return dxfWriter.getCapability(capability);
|
865 |
} |
866 |
|
867 |
public void setCapabilities(Properties capabilities) { |
868 |
dxfWriter.setCapabilities(capabilities); |
869 |
|
870 |
} |
871 |
|
872 |
public boolean canWriteAttribute(int sqlType) { |
873 |
return dxfWriter.canWriteAttribute(sqlType);
|
874 |
} |
875 |
|
876 |
|
877 |
public void reload() throws ReloadDriverException { |
878 |
super.reload();
|
879 |
try {
|
880 |
initialize(); |
881 |
} catch (InitializeDriverException e) {
|
882 |
throw new ReloadDriverException(getName(),e); |
883 |
} catch (ReadDriverException e) {
|
884 |
throw new ReloadDriverException(getName(),e); |
885 |
} |
886 |
} |
887 |
|
888 |
public boolean isWritable() { |
889 |
return m_Fich.canWrite();
|
890 |
} |
891 |
|
892 |
public IWriter getWriter() {
|
893 |
return this; |
894 |
} |
895 |
|
896 |
public ITableDefinition getTableDefinition() {
|
897 |
return dxfWriter.getTableDefinition();
|
898 |
} |
899 |
|
900 |
public boolean canAlterTable() { |
901 |
return false; |
902 |
} |
903 |
|
904 |
public boolean canSaveEdits() { |
905 |
return dxfWriter.canSaveEdits();
|
906 |
} |
907 |
|
908 |
/**
|
909 |
* Returns the drawing entity associated to an FMap feature
|
910 |
* */
|
911 |
public Object getCadSource(int index) { |
912 |
IObjList.vector vector = (IObjList.vector) ((DxfFeatureMaker) featureMaker) |
913 |
.getObjects(); |
914 |
return vector.get(index);
|
915 |
} |
916 |
|
917 |
public boolean isWriteAll() { |
918 |
return true; |
919 |
} |
920 |
|
921 |
public ILabelingStrategy getDefaultLabelingStrategy() {
|
922 |
return labeling;
|
923 |
} |
924 |
public int getFieldType(int i) { |
925 |
DefaultTableModel dtm=getTableModel();
|
926 |
String columnName=dtm.getColumnName(i);
|
927 |
if (columnName.equals("ID")){ |
928 |
return Types.INTEGER; |
929 |
} else if (columnName.equals("FShape")){ |
930 |
return Types.VARCHAR; |
931 |
} else if (columnName.equals("Entity")){ |
932 |
return Types.VARCHAR; |
933 |
} else if (columnName.equals("Layer")){ |
934 |
return Types.VARCHAR; |
935 |
} else if (columnName.equals("Color")){ |
936 |
return Types.INTEGER; |
937 |
} else if (columnName.equals("Elevation")){ |
938 |
return Types.DOUBLE; |
939 |
} else if (columnName.equals("Thickness")){ |
940 |
return Types.DOUBLE; |
941 |
} else if (columnName.equals("HeightText")){ |
942 |
return Types.DOUBLE; |
943 |
} else if (columnName.equals("RotationText")){ |
944 |
return Types.DOUBLE; |
945 |
} else if (columnName.equals("Text")){ |
946 |
return Types.VARCHAR; |
947 |
} else{
|
948 |
return Types.VARCHAR; |
949 |
} |
950 |
} |
951 |
|
952 |
/**
|
953 |
* Replace the Unicode characters formatted for AutoCAD
|
954 |
* by the Unicode character corresponding
|
955 |
*
|
956 |
* @param s
|
957 |
* Multiline text formatted with Autocad.
|
958 |
*
|
959 |
* @return Text fixed
|
960 |
*/
|
961 |
private String fixUnicode(String s){ |
962 |
// Viene una cadena tal que as? CA\U+00D1O1
|
963 |
// (una especie de formato Unicode de Autocad)
|
964 |
// y hay que devolver CA?O1
|
965 |
|
966 |
String s2 = ""; |
967 |
String patron = "(\\\\[U][+])([0-9A-Fa-f]{4})"; |
968 |
Pattern compiledPatron = Pattern.compile(patron); |
969 |
Matcher matcher = compiledPatron.matcher(s);
|
970 |
|
971 |
int lastEnd = 0; |
972 |
while(matcher.find()){
|
973 |
int start = matcher.start();
|
974 |
int end = matcher.end();
|
975 |
|
976 |
String code = matcher.group(2); |
977 |
String hexa = "0x"+code; |
978 |
int caracter = Integer.decode(hexa).intValue(); |
979 |
|
980 |
s2 = s2 + s.substring(lastEnd, start) + (char)caracter;
|
981 |
lastEnd = end; |
982 |
} |
983 |
s2 = s2 + s.substring(lastEnd); |
984 |
return s2;
|
985 |
} |
986 |
|
987 |
|
988 |
/**
|
989 |
* Extracts the text of a multiline text formatted with Autocad
|
990 |
*
|
991 |
* @param mtext
|
992 |
* Multiline text formatted with Autocad.
|
993 |
* ACAD seems to add braces ({ }) and backslash-P's
|
994 |
* to indicate paragraphs, as well as fonts and / or sizes.
|
995 |
*
|
996 |
* @return Text extracted
|
997 |
*/
|
998 |
private String getTextFromMtext(String mtext){ |
999 |
String text = ""; |
1000 |
String patron = "([^{]*)([{][^;]*[;])([^}]*)([}])"; |
1001 |
Pattern compiledPatron = Pattern.compile(patron); |
1002 |
Matcher matcher = compiledPatron.matcher(mtext);
|
1003 |
int lastEnd = 0; |
1004 |
while(matcher.find()){
|
1005 |
for (int i=1; i<=matcher.groupCount(); i++){ |
1006 |
if (i==1){ |
1007 |
text = text + matcher.group(i); |
1008 |
} |
1009 |
if (i%4 == 3){ |
1010 |
String grupo = matcher.group(i).replace("\\P", " \n"); |
1011 |
if(grupo.contains(";")){ |
1012 |
String[] ss = grupo.split(";"); |
1013 |
text = text + ss[ss.length-1];
|
1014 |
} else {
|
1015 |
text = text + grupo; |
1016 |
} |
1017 |
} |
1018 |
} |
1019 |
lastEnd = matcher.end(); |
1020 |
} |
1021 |
text = text + mtext.substring(lastEnd); |
1022 |
return text;
|
1023 |
} |
1024 |
} |