root / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / DwgMemoryDriver.java @ 17118
History | View | Annotate | Download (23.3 KB)
1 |
/*
|
---|---|
2 |
* Created on 14-abr-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
* DwgMemoryDriver 0.2. Driver del formato DWG para gvSIG
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
/* CVS MESSAGES:
|
46 |
*
|
47 |
* $Id: DwgMemoryDriver.java 17118 2007-12-04 12:56:38Z vcaballero $
|
48 |
* $Log$
|
49 |
* Revision 1.18 2007-09-20 07:15:33 jaume
|
50 |
* ReadExpansionFileException removed from this context
|
51 |
*
|
52 |
* Revision 1.17 2007/07/18 07:07:44 caballero
|
53 |
* id integer
|
54 |
*
|
55 |
* Revision 1.16 2007/06/27 15:20:37 azabala
|
56 |
* changes in open method to allow reusing an instance to load multiple files
|
57 |
*
|
58 |
* Revision 1.15 2007/06/22 10:50:16 caballero
|
59 |
* getFieldType
|
60 |
*
|
61 |
* Revision 1.14 2007/06/11 12:50:24 jaume
|
62 |
* refactored to use ISymbol
|
63 |
*
|
64 |
* Revision 1.13 2007/05/28 14:16:47 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.12 2007/05/17 09:43:35 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.11 2007/04/04 17:49:06 azabala
|
71 |
* Dependencies of libDwg with libFMap removed
|
72 |
*
|
73 |
* Revision 1.10 2007/03/22 19:56:12 azabala
|
74 |
* changes in exceptinos api
|
75 |
*
|
76 |
* Revision 1.9 2007/03/20 20:21:19 azabala
|
77 |
* added roi filtering, reordering of code
|
78 |
*
|
79 |
* Revision 1.7 2007/02/27 17:18:03 azabala
|
80 |
* solved bug with text orientation
|
81 |
*
|
82 |
* Revision 1.6 2007/02/14 16:17:22 azabala
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.5 2007/01/20 18:30:37 azabala
|
86 |
* refactoring of blocks
|
87 |
*
|
88 |
* Revision 1.4 2007/01/18 19:59:10 azabala
|
89 |
* refactoring to optimize and simplify the code
|
90 |
*
|
91 |
* Revision 1.3 2007/01/18 13:36:42 azabala
|
92 |
* Refactoring general para evitar dar tantas pasadas en la carga, y para incrementar
|
93 |
* la legibilidad del codigo (demasiados if-else-if en vez de usar polimorfismo)
|
94 |
*
|
95 |
* Revision 1.2 2007/01/12 19:57:44 azabala
|
96 |
* *** empty log message ***
|
97 |
*
|
98 |
* Revision 1.1 2007/01/11 20:31:05 azabala
|
99 |
* *** empty log message ***
|
100 |
*
|
101 |
*
|
102 |
*/
|
103 |
package com.iver.cit.gvsig.drivers.dwg; |
104 |
|
105 |
import java.awt.Color; |
106 |
import java.awt.geom.Rectangle2D; |
107 |
import java.io.File; |
108 |
import java.io.FileNotFoundException; |
109 |
import java.io.IOException; |
110 |
import java.sql.Types; |
111 |
import java.util.ArrayList; |
112 |
import java.util.HashMap; |
113 |
import java.util.List; |
114 |
import java.util.Map; |
115 |
|
116 |
import javax.swing.table.DefaultTableModel; |
117 |
|
118 |
import com.hardcode.gdbms.driver.exceptions.FileNotFoundDriverException; |
119 |
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
120 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
121 |
import com.hardcode.gdbms.driver.exceptions.UnsupportedVersionDriverException; |
122 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
123 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
124 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
125 |
import com.hardcode.gdbms.engine.values.IntValue; |
126 |
import com.hardcode.gdbms.engine.values.Value; |
127 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
128 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgArc2FMapConverter; |
129 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgCircle2FMapConverter; |
130 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgEllipse2FMapConverter; |
131 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgLine2FMapConverter; |
132 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgLwPline2FMapConverter; |
133 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgMText2FMapConverter; |
134 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPFacePline2FMapConverter; |
135 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPoint2FMapConverter; |
136 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPolyline2D2FMapConverter; |
137 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPolyline3D2FMapConverter; |
138 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgSolid2FMapConverter; |
139 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgText2FMapConverter; |
140 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.IDwg2FMap; |
141 |
import com.iver.cit.gvsig.fmap.core.FShape; |
142 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
143 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
144 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
145 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
146 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
147 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
148 |
import com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver; |
149 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
150 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
151 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
152 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
153 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
154 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
155 |
import com.iver.cit.gvsig.fmap.rendering.styling.AttrInTableLabeling; |
156 |
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingStrategy; |
157 |
import com.iver.cit.jdwglib.dwg.DwgFile; |
158 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
159 |
import com.iver.cit.jdwglib.dwg.DwgVersionNotSupportedException; |
160 |
import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
161 |
import com.iver.cit.jdwglib.dwg.objects.DwgArc; |
162 |
import com.iver.cit.jdwglib.dwg.objects.DwgCircle; |
163 |
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse; |
164 |
import com.iver.cit.jdwglib.dwg.objects.DwgLine; |
165 |
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline; |
166 |
import com.iver.cit.jdwglib.dwg.objects.DwgMText; |
167 |
import com.iver.cit.jdwglib.dwg.objects.DwgPFacePolyline; |
168 |
import com.iver.cit.jdwglib.dwg.objects.DwgPoint; |
169 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D; |
170 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D; |
171 |
import com.iver.cit.jdwglib.dwg.objects.DwgSolid; |
172 |
import com.iver.cit.jdwglib.dwg.objects.DwgText; |
173 |
import com.iver.cit.jdwglib.util.AcadColor; |
174 |
|
175 |
/**
|
176 |
* Driver that allows gvSIG to read files in DWG format Using this driver, a
|
177 |
* gvSIG user can manipulate part of the information contained in a DWG file
|
178 |
* This driver load the Dwg file in memory This driver uses jdwglib
|
179 |
*
|
180 |
* @author jmorell
|
181 |
* @author azabala
|
182 |
*/
|
183 |
public class DwgMemoryDriver extends AbstractCadMemoryDriver implements |
184 |
VectorialFileDriver, WithDefaultLegend { |
185 |
|
186 |
static Map convertersRegistry = new HashMap(); |
187 |
|
188 |
/*
|
189 |
* this process of registration of the 2FMapConverters could be
|
190 |
* automathic (by java reflection), but the number of dwg entities
|
191 |
* is finited, and some converters could exists but dont work well
|
192 |
* (so thats the reason we mantain a "manual" registering process.
|
193 |
* */
|
194 |
static{
|
195 |
registerFMapConverter(DwgArc.class, new DwgArc2FMapConverter());
|
196 |
registerFMapConverter(DwgCircle.class, new DwgCircle2FMapConverter());
|
197 |
registerFMapConverter(DwgEllipse.class, new DwgEllipse2FMapConverter());
|
198 |
registerFMapConverter(DwgLine.class, new DwgLine2FMapConverter());
|
199 |
registerFMapConverter(DwgLwPolyline.class, new DwgLwPline2FMapConverter());
|
200 |
registerFMapConverter(DwgMText.class, new DwgMText2FMapConverter());
|
201 |
registerFMapConverter(DwgPFacePolyline.class, new DwgPFacePline2FMapConverter());
|
202 |
registerFMapConverter(DwgPoint.class, new DwgPoint2FMapConverter());
|
203 |
registerFMapConverter(DwgPolyline2D.class, new DwgPolyline2D2FMapConverter());
|
204 |
registerFMapConverter(DwgPolyline3D.class, new DwgPolyline3D2FMapConverter());
|
205 |
registerFMapConverter(DwgSolid.class, new DwgSolid2FMapConverter());
|
206 |
registerFMapConverter(DwgText.class, new DwgText2FMapConverter());
|
207 |
try {
|
208 |
Class.forName("com.iver.cit.gvsig.drivers.dwg.fmapconverters.FMapUtil"); |
209 |
} catch (ClassNotFoundException e) { |
210 |
e.printStackTrace(); |
211 |
} |
212 |
} |
213 |
|
214 |
public static void registerFMapConverter (Class clazz, IDwg2FMap converter){ |
215 |
if(! DwgObject.class.isAssignableFrom(clazz))
|
216 |
return;
|
217 |
convertersRegistry.put(clazz, converter); |
218 |
} |
219 |
|
220 |
public static IDwg2FMap getConverter(Class clazz){ |
221 |
if(! DwgObject.class.isAssignableFrom(clazz))
|
222 |
return null; |
223 |
return (IDwg2FMap) convertersRegistry.get(clazz);
|
224 |
} |
225 |
|
226 |
VectorialUniqueValueLegend defaultLegend; |
227 |
private File m_Fich; |
228 |
private String fileVersion; |
229 |
private DriverAttributes attr = new DriverAttributes(); |
230 |
private boolean isInitialized = false; |
231 |
float heightText = 10; |
232 |
|
233 |
//new WithDefaultLegend API
|
234 |
private AttrInTableLabeling labeling;
|
235 |
|
236 |
private boolean debug = false; |
237 |
/**
|
238 |
* entities of the dwg file (once applied many transformation,
|
239 |
* including block insertion) that are IDwgToFMap.
|
240 |
* */
|
241 |
ArrayList entities = new ArrayList(); |
242 |
|
243 |
/**
|
244 |
* Saves an original DWG entity associated to a FMap entity
|
245 |
* by their index.
|
246 |
* Only available in debug mode (if debug is false, doesnt save anything)
|
247 |
* */
|
248 |
private void saveEntity(DwgObject entity) { |
249 |
if(debug)
|
250 |
entities.add(entity); |
251 |
} |
252 |
|
253 |
public DwgObject getEntity(int i){ |
254 |
if(debug)
|
255 |
return (DwgObject) entities.get(i);
|
256 |
else
|
257 |
return null; |
258 |
} |
259 |
|
260 |
/*
|
261 |
* (non-Javadoc)
|
262 |
*
|
263 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
264 |
*/
|
265 |
public void open(File f) { |
266 |
m_Fich = f; |
267 |
isInitialized = false;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* Allows recovering of the DWG Drawing entity associated to the FMap
|
272 |
* feature whose position is index.
|
273 |
* If debug mode is false, it always returns null.
|
274 |
*
|
275 |
* @param index
|
276 |
* position of the fmap feature whose dwg entity is required
|
277 |
*
|
278 |
*/
|
279 |
public Object getCadSource(int index) { |
280 |
if(debug)
|
281 |
return getEntity(index);
|
282 |
else
|
283 |
return null; |
284 |
} |
285 |
|
286 |
/**
|
287 |
* This method load the DWG file in memory. First, it will be necessary to
|
288 |
* create a DwgFile object with the DWG file path as the argument. Second,
|
289 |
* the method read of DwgFile allows to read the objects inside the DWG
|
290 |
* file. Third, it will be necessary to process some DWG objects like Layers
|
291 |
* or Polylines Fourth, applyExtrusions() can change the location of the DWG
|
292 |
* objects through the extrusion parameters. Fifth, the testDwg3D method
|
293 |
* test if this DWG has elevation informacion. Sixth, we can extract the
|
294 |
* objects contained inside the blocks through the blockManagement method.
|
295 |
* And finally, we can read the objects Vector, and convert this objects to
|
296 |
* the FMap object model.
|
297 |
*/
|
298 |
public void initialize() throws ReadDriverException { |
299 |
if (isInitialized)
|
300 |
return;
|
301 |
else
|
302 |
isInitialized = true;
|
303 |
attr.setLoadedInMemory(true);
|
304 |
DwgFile dwg = new DwgFile(m_Fich.getAbsolutePath());
|
305 |
|
306 |
try {
|
307 |
dwg.read(); |
308 |
} catch (DwgVersionNotSupportedException e1) {
|
309 |
|
310 |
String autodeskUrl = "<a href=\"http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151\">" |
311 |
+ "http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151</a>";
|
312 |
// throw new InitializeDriverException(
|
313 |
// formatString(
|
314 |
// "La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s",
|
315 |
// new String[] { e1.getDwgVersion().toString(),
|
316 |
// m_Fich.getName(),
|
317 |
// Messages.getText("Probe_to_convert"),
|
318 |
// Messages.getText("Autodesk_converter"),
|
319 |
// autodeskUrl }));
|
320 |
String description=formatString(
|
321 |
"La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s",
|
322 |
new String[] { e1.getDwgVersion().toString(), |
323 |
m_Fich.getName(), |
324 |
Messages.getText("Probe_to_convert"),
|
325 |
Messages.getText("Autodesk_converter"),
|
326 |
autodeskUrl }); |
327 |
throw new UnsupportedVersionDriverException(getName(),e1,description); |
328 |
} catch (FileNotFoundException e) { |
329 |
throw new FileNotFoundDriverException(getName(),e); |
330 |
} catch (IOException e) { |
331 |
throw new InitializeDriverException(getName(),e); |
332 |
} |
333 |
|
334 |
fileVersion = dwg.getDwgVersion(); |
335 |
dwg.calculateGisModelDwgPolylines(); |
336 |
dwg.blockManagement2(); |
337 |
List dwgObjects = dwg.getDwgObjects();
|
338 |
|
339 |
//Each dwg file has two headers vars, EXTMIN and EXTMAX
|
340 |
//that marks bounds of the file.
|
341 |
//Also, it could have spureus entities (deleted objects
|
342 |
//dont removed from the DWG database)
|
343 |
double[] extMin = (double[]) dwg.getHeader("MSPACE_EXTMIN"); |
344 |
double[] extMax = (double[]) dwg.getHeader("MSPACE_EXTMAX"); |
345 |
if(extMin != null && extMax != null){ |
346 |
if(extMin.length >= 2 && extMax.length >= 2){ |
347 |
double xmin = extMin[0]; |
348 |
double ymin = extMin[1]; |
349 |
double xmax = extMax[0]; |
350 |
double ymax = extMax[1]; |
351 |
Rectangle2D roi = new |
352 |
Rectangle2D.Double(xmin-100, ymin-100, |
353 |
(xmax-xmin)+100, (ymax-ymin)+100); |
354 |
addRegionOfInterest(roi); |
355 |
} |
356 |
} |
357 |
// Campos de las MemoryLayer:
|
358 |
Value[] auxRow = new Value[10]; |
359 |
ArrayList arrayFields = new ArrayList(); |
360 |
arrayFields.add("ID");
|
361 |
arrayFields.add("FShape");
|
362 |
arrayFields.add("Entity");
|
363 |
arrayFields.add("Layer");
|
364 |
arrayFields.add("Color");
|
365 |
arrayFields.add("Elevation");
|
366 |
arrayFields.add("Thickness");
|
367 |
arrayFields.add("Text");
|
368 |
arrayFields.add("HeightText");
|
369 |
arrayFields.add("RotationText");
|
370 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
371 |
|
372 |
labeling = new AttrInTableLabeling();
|
373 |
((AttrInTableLabeling) labeling).setTextFieldId(arrayFields.indexOf("Text"));
|
374 |
((AttrInTableLabeling) labeling).setRotationFieldId(arrayFields.indexOf("RotationText"));
|
375 |
((AttrInTableLabeling) labeling).setHeightFieldId(arrayFields.indexOf("HeightText"));
|
376 |
|
377 |
boolean is3dFile = dwg.isDwg3DFile();
|
378 |
try {
|
379 |
for (int i = 0; i < dwgObjects.size(); i++) { |
380 |
DwgObject entity = (DwgObject) dwgObjects.get(i); |
381 |
Class clazz = entity.getClass();
|
382 |
IDwg2FMap converter = getConverter(clazz); |
383 |
try {
|
384 |
if(converter != null){ |
385 |
IGeometry geometry = converter.toFMapGeometry(entity, is3dFile); |
386 |
if (geometry == null) |
387 |
continue;
|
388 |
//we check for Region of Interest of the CAD file
|
389 |
if(! checkRois(geometry))
|
390 |
continue;
|
391 |
|
392 |
String fmapStr = converter.toFMapString(is3dFile);
|
393 |
// nombre del tipo de geometria fmap
|
394 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(fmapStr); |
395 |
|
396 |
// indice del registro
|
397 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
398 |
|
399 |
// nombre de entidad dwg
|
400 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(entity.toString()); |
401 |
String layerName = dwg.getLayerName(entity);
|
402 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
403 |
.createValue(layerName); |
404 |
int colorByLayer = dwg.getColorByLayer(entity);
|
405 |
|
406 |
int color = entity.getColor();
|
407 |
if(color < 0) |
408 |
color = Math.abs(color);
|
409 |
if(color > 255) |
410 |
color = colorByLayer; |
411 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
412 |
|
413 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
|
414 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
415 |
.createValue(0.0);
|
416 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
417 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
|
418 |
|
419 |
if (entity instanceof IDwg3DTestable) { |
420 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory |
421 |
.createValue(((IDwg3DTestable) entity).getZ()); |
422 |
} |
423 |
|
424 |
if (entity instanceof DwgMText) { |
425 |
DwgMText mtext = (DwgMText) entity; |
426 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(mtext |
427 |
.getText()); |
428 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
429 |
.createValue(mtext.getHeight()); |
430 |
} else if (entity instanceof DwgText) { |
431 |
DwgText text = (DwgText) entity; |
432 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(text |
433 |
.getText()); |
434 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory |
435 |
.createValue(text.getThickness()); |
436 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
437 |
.createValue(text.getHeight()); |
438 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
439 |
.createValue(Math.toDegrees(text
|
440 |
.getRotationAngle())); |
441 |
}// if-else
|
442 |
addGeometry(geometry, auxRow); |
443 |
|
444 |
if(debug)
|
445 |
saveEntity(entity); |
446 |
|
447 |
} |
448 |
} catch (Exception e) { |
449 |
// TODO Auto-generated catch block
|
450 |
e.printStackTrace(); |
451 |
continue;
|
452 |
} |
453 |
}// for
|
454 |
|
455 |
} catch (Throwable t) { |
456 |
t.printStackTrace(); |
457 |
} |
458 |
dwgObjects = null;
|
459 |
dwg = null;
|
460 |
System.gc();
|
461 |
setSymbols(); |
462 |
} |
463 |
|
464 |
/**
|
465 |
* Sets a symbol for each dwg entity's derived feature based in
|
466 |
* the DWG symbology info.
|
467 |
* */
|
468 |
private void setSymbols() throws InitializeDriverException{ |
469 |
// JAUME REFACTORED TO ISymbol
|
470 |
// FSymbol myDefaultSymbol = new FSymbol(getShapeType());
|
471 |
// myDefaultSymbol.setShapeVisible(false);
|
472 |
// myDefaultSymbol.setFontSizeInPixels(false);
|
473 |
// myDefaultSymbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
|
474 |
// myDefaultSymbol.setFontColor(Color.BLACK);
|
475 |
// myDefaultSymbol.setFontSize(heightText);
|
476 |
// myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
|
477 |
// myDefaultSymbol.setSize(3);
|
478 |
// myDefaultSymbol.setSizeInPixels(true);
|
479 |
|
480 |
defaultLegend = LegendFactory |
481 |
.createVectorialUniqueValueLegend(getShapeType()); |
482 |
defaultLegend.setClassifyingFieldNames(new String[] {"Color"}); |
483 |
defaultLegend.setClassifyingFieldTypes(new int[]{Types.INTEGER,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.INTEGER,Types.DOUBLE,Types.DOUBLE,Types.VARCHAR,Types.DOUBLE,Types.DOUBLE}); |
484 |
|
485 |
defaultLegend.setDefaultSymbol(SymbologyFactory. |
486 |
createDefaultSymbolByShapeType(getShapeType(), Color.BLACK));
|
487 |
|
488 |
ObjectDriver rs = this;
|
489 |
IntValue clave; |
490 |
ISymbol theSymbol = null;
|
491 |
try {
|
492 |
for (long j = 0; j < rs.getRowCount(); j++) { |
493 |
clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR); |
494 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
495 |
// JAUME REFACTORED TO ISymbol
|
496 |
// theSymbol = new FSymbol(getShapeType());
|
497 |
// theSymbol.setDescription(clave.toString());
|
498 |
// theSymbol.setColor(AcadColor.getColor(clave.getValue()));
|
499 |
// // theSymbol.setFill(fillProv);
|
500 |
// // 050202, jmorell: Asigna los colores de Autocad a los
|
501 |
// // bordes
|
502 |
// // de los pol?gonos.
|
503 |
// theSymbol.setOutlineColor(AcadColor.getColor(clave
|
504 |
// .getValue()));
|
505 |
//
|
506 |
// theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
|
507 |
// theSymbol.setSize(3);
|
508 |
// theSymbol.setSizeInPixels(true);
|
509 |
// defaultLegend.addSymbol(clave, theSymbol);
|
510 |
Color c = AcadColor.getColor(clave.getValue());
|
511 |
theSymbol = SymbologyFactory. |
512 |
createDefaultSymbolByShapeType(getShapeType(), c); |
513 |
theSymbol.setDescription(clave.toString()); |
514 |
|
515 |
if (theSymbol instanceof IMarkerSymbol) { |
516 |
((IMarkerSymbol) theSymbol).setSize(1);
|
517 |
} |
518 |
|
519 |
if (theSymbol instanceof ILineSymbol) { |
520 |
((ILineSymbol) theSymbol).setLineWidth(1);
|
521 |
} |
522 |
|
523 |
if (theSymbol instanceof IFillSymbol) { |
524 |
((IFillSymbol) theSymbol).getOutline().setLineColor(c); |
525 |
((IFillSymbol) theSymbol).getOutline().setLineWidth(1);
|
526 |
((IFillSymbol) theSymbol).setFillColor(null);
|
527 |
} |
528 |
|
529 |
// theSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_TRANSPARENT);
|
530 |
defaultLegend.addSymbol(clave, theSymbol); |
531 |
}// if
|
532 |
} // for
|
533 |
} catch (ReadDriverException e) {
|
534 |
throw new InitializeDriverException(getName(),e); |
535 |
} |
536 |
} |
537 |
|
538 |
/**
|
539 |
* checks if the given geometry intersects or its
|
540 |
* contained in one of the driver regions of interest.
|
541 |
*
|
542 |
* @param geometry feature geometry we want to check
|
543 |
* against the drivers rois.
|
544 |
*
|
545 |
* @return true if feature is contained in any ROI.
|
546 |
* false if not.
|
547 |
* */
|
548 |
private boolean checkRois(IGeometry geometry){ |
549 |
Rectangle2D rect = geometry.getBounds2D();
|
550 |
int numRois = this.getNumOfRois(); |
551 |
for(int i = 0; i < numRois; i++){ |
552 |
Rectangle2D roi = getRegionOfInterest(i);
|
553 |
if( checkIntersect(rect.getMinX(), rect.getMaxX(), rect.getMinY(), rect.getMaxY(),
|
554 |
roi.getMinX(), roi.getMaxX(), roi.getMinY(),roi.getMaxY()) || |
555 |
checkContains(rect.getMinX(), rect.getMaxX(), rect.getMinY(), rect.getMaxY(), |
556 |
roi.getMinX(), roi.getMaxX(), roi.getMinY(),roi.getMaxY()) |
557 |
){ |
558 |
return true; |
559 |
} |
560 |
// if(roi.intersects(rect) || roi.contains(rect))
|
561 |
// return true;
|
562 |
} |
563 |
return false; |
564 |
} |
565 |
|
566 |
private boolean checkContains(double x1, double x2, double y1, double y2, |
567 |
double ax1, double ax2, double ay1, double ay2){ |
568 |
boolean solution = ( x1 >= ax1 &&
|
569 |
x2 <= ax2 && |
570 |
y1 >= ay1 && |
571 |
y2 <= ay2); |
572 |
return solution;
|
573 |
} |
574 |
|
575 |
private boolean checkIntersect(double x1, double x2, double y1, double y2, |
576 |
double ax1, double ax2, double ay1, double ay2){ |
577 |
|
578 |
return !(x1 > ax2 ||
|
579 |
x2 < ax1 || |
580 |
y1 > ay2 || |
581 |
y2 < ay1); |
582 |
|
583 |
} |
584 |
|
585 |
public String getFileVersion() { |
586 |
return fileVersion;
|
587 |
} |
588 |
|
589 |
private String formatString(String fmt, String[] params) { |
590 |
String ret = fmt;
|
591 |
for (int i = 0; i < params.length; i++) { |
592 |
ret = ret.replaceFirst("%s", params[i]);
|
593 |
} |
594 |
return ret;
|
595 |
} |
596 |
|
597 |
|
598 |
/*
|
599 |
* (non-Javadoc)
|
600 |
*
|
601 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
|
602 |
*/
|
603 |
public boolean accept(File f) { |
604 |
return f.getName().toUpperCase().endsWith("DWG"); |
605 |
} |
606 |
|
607 |
/*
|
608 |
* (non-Javadoc)
|
609 |
*
|
610 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
|
611 |
*/
|
612 |
public int getShapeType() { |
613 |
return FShape.MULTI;
|
614 |
} |
615 |
|
616 |
/*
|
617 |
* (non-Javadoc)
|
618 |
*
|
619 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
|
620 |
*/
|
621 |
public String getName() { |
622 |
return "gvSIG DWG Memory Driver"; |
623 |
} |
624 |
|
625 |
/*
|
626 |
* (non-Javadoc)
|
627 |
*
|
628 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
629 |
*/
|
630 |
public ILegend getDefaultLegend() {
|
631 |
return defaultLegend;
|
632 |
} |
633 |
|
634 |
/*
|
635 |
* (non-Javadoc)
|
636 |
*
|
637 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
638 |
*/
|
639 |
public DriverAttributes getDriverAttributes() {
|
640 |
return attr;
|
641 |
} |
642 |
|
643 |
/*
|
644 |
* (non-Javadoc)
|
645 |
*
|
646 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
647 |
*/
|
648 |
public int[] getPrimaryKeys() { |
649 |
// TODO Auto-generated method stub
|
650 |
return null; |
651 |
} |
652 |
|
653 |
/*
|
654 |
* (non-Javadoc)
|
655 |
*
|
656 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
657 |
*/
|
658 |
public void write(DataWare arg0) { |
659 |
// TODO Auto-generated method stub
|
660 |
|
661 |
} |
662 |
|
663 |
public void setDataSourceFactory(DataSourceFactory arg0) { |
664 |
// TODO Auto-generated method stub
|
665 |
|
666 |
} |
667 |
|
668 |
public void close() { |
669 |
entities.clear(); |
670 |
entities = null;
|
671 |
System.gc();
|
672 |
|
673 |
} |
674 |
|
675 |
public File getFile() { |
676 |
return m_Fich;
|
677 |
} |
678 |
|
679 |
public boolean isWritable() { |
680 |
return m_Fich.canWrite();
|
681 |
} |
682 |
|
683 |
|
684 |
public boolean isDebug() { |
685 |
return debug;
|
686 |
} |
687 |
|
688 |
|
689 |
public void setDebug(boolean debug) { |
690 |
this.debug = debug;
|
691 |
} |
692 |
|
693 |
public ILabelingStrategy getDefaultLabelingStrategy() {
|
694 |
return labeling;
|
695 |
} |
696 |
public int getFieldType(int i) { |
697 |
DefaultTableModel dtm=getTableModel();
|
698 |
String columnName=dtm.getColumnName(i);
|
699 |
if (columnName.equals("ID")){ |
700 |
return Types.INTEGER; |
701 |
} else if (columnName.equals("FShape")){ |
702 |
return Types.VARCHAR; |
703 |
} else if (columnName.equals("Entity")){ |
704 |
return Types.VARCHAR; |
705 |
} else if (columnName.equals("Layer")){ |
706 |
return Types.VARCHAR; |
707 |
} else if (columnName.equals("Color")){ |
708 |
return Types.INTEGER; |
709 |
} else if (columnName.equals("Elevation")){ |
710 |
return Types.DOUBLE; |
711 |
} else if (columnName.equals("Thickness")){ |
712 |
return Types.DOUBLE; |
713 |
} else if (columnName.equals("HeightText")){ |
714 |
return Types.DOUBLE; |
715 |
} else if (columnName.equals("RotationText")){ |
716 |
return Types.DOUBLE; |
717 |
} else if (columnName.equals("Text")){ |
718 |
return Types.VARCHAR; |
719 |
} else{
|
720 |
return Types.VARCHAR; |
721 |
} |
722 |
} |
723 |
} |
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|