svn-gvsig-desktop / trunk / extensions / extDwg / src / com / iver / cit / gvsig / drivers / dwg / DwgMemoryDriver.java @ 19318
History | View | Annotate | Download (23.4 KB)
1 | 9686 | azabala | /*
|
---|---|---|---|
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 | 10823 | azabala | *
|
47 | * $Id$
|
||
48 | * $Log$
|
||
49 | 13893 | jaume | * 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 | 12658 | caballero | * id integer
|
54 | *
|
||
55 | * Revision 1.16 2007/06/27 15:20:37 azabala
|
||
56 | 12372 | azabala | * 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 | 12299 | caballero | * getFieldType
|
60 | *
|
||
61 | * Revision 1.14 2007/06/11 12:50:24 jaume
|
||
62 | 12115 | jaume | * refactored to use ISymbol
|
63 | *
|
||
64 | * Revision 1.13 2007/05/28 14:16:47 jaume
|
||
65 | 11704 | jaume | * *** empty log message ***
|
66 | *
|
||
67 | 11851 | jaume | * Revision 1.12 2007/05/17 09:43:35 jaume
|
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | 11704 | jaume | * Revision 1.11 2007/04/04 17:49:06 azabala
|
71 | 11061 | azabala | * Dependencies of libDwg with libFMap removed
|
72 | *
|
||
73 | * Revision 1.10 2007/03/22 19:56:12 azabala
|
||
74 | 10860 | azabala | * changes in exceptinos api
|
75 | *
|
||
76 | * Revision 1.9 2007/03/20 20:21:19 azabala
|
||
77 | 10823 | azabala | * 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 | 9686 | azabala | package com.iver.cit.gvsig.drivers.dwg; |
104 | |||
105 | import java.awt.Color; |
||
106 | 10823 | azabala | import java.awt.geom.Rectangle2D; |
107 | 9686 | azabala | import java.io.File; |
108 | 17118 | vcaballero | import java.io.FileNotFoundException; |
109 | 9686 | azabala | import java.io.IOException; |
110 | 12299 | caballero | import java.sql.Types; |
111 | 9686 | azabala | import java.util.ArrayList; |
112 | 11061 | azabala | import java.util.HashMap; |
113 | 9843 | azabala | import java.util.List; |
114 | 11061 | azabala | import java.util.Map; |
115 | 9686 | azabala | |
116 | 12299 | caballero | import javax.swing.table.DefaultTableModel; |
117 | |||
118 | 17118 | vcaballero | import com.hardcode.gdbms.driver.exceptions.FileNotFoundDriverException; |
119 | 10628 | caballero | import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
120 | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
||
121 | import com.hardcode.gdbms.driver.exceptions.UnsupportedVersionDriverException; |
||
122 | 10860 | azabala | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
123 | 9686 | azabala | 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 | 11061 | azabala | 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 | 9686 | azabala | import com.iver.cit.gvsig.fmap.core.FShape; |
142 | 10823 | azabala | import com.iver.cit.gvsig.fmap.core.IGeometry; |
143 | 12115 | jaume | 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 | 9686 | azabala | 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 | 11704 | jaume | import com.iver.cit.gvsig.fmap.rendering.ILegend; |
153 | 9686 | azabala | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
154 | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
||
155 | 19318 | jmvivo | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy; |
156 | import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy; |
||
157 | 9686 | azabala | import com.iver.cit.jdwglib.dwg.DwgFile; |
158 | import com.iver.cit.jdwglib.dwg.DwgObject; |
||
159 | import com.iver.cit.jdwglib.dwg.DwgVersionNotSupportedException; |
||
160 | 9825 | azabala | import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
161 | 11061 | azabala | 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 | 9686 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgMText; |
167 | 11061 | azabala | 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 | 9686 | azabala | 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 | 11704 | jaume | *
|
180 | 9686 | azabala | * @author jmorell
|
181 | 11061 | azabala | * @author azabala
|
182 | 9686 | azabala | */
|
183 | public class DwgMemoryDriver extends AbstractCadMemoryDriver implements |
||
184 | VectorialFileDriver, WithDefaultLegend { |
||
185 | 11704 | jaume | |
186 | 11061 | azabala | static Map convertersRegistry = new HashMap(); |
187 | 9686 | azabala | |
188 | 11061 | azabala | /*
|
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 | 11704 | jaume | |
226 | 9686 | azabala | VectorialUniqueValueLegend defaultLegend; |
227 | private File m_Fich; |
||
228 | 10823 | azabala | private String fileVersion; |
229 | 9686 | azabala | private DriverAttributes attr = new DriverAttributes(); |
230 | private boolean isInitialized = false; |
||
231 | 11704 | jaume | float heightText = 10; |
232 | |||
233 | 10860 | azabala | //new WithDefaultLegend API
|
234 | 19318 | jmvivo | private AttrInTableLabelingStrategy labeling;
|
235 | 10860 | azabala | |
236 | 10823 | azabala | 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 | 11704 | jaume | |
243 | 10823 | azabala | /**
|
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 | 11704 | jaume | |
253 | 10823 | azabala | public DwgObject getEntity(int i){ |
254 | if(debug)
|
||
255 | return (DwgObject) entities.get(i);
|
||
256 | else
|
||
257 | return null; |
||
258 | } |
||
259 | 9686 | azabala | |
260 | /*
|
||
261 | * (non-Javadoc)
|
||
262 | 11704 | jaume | *
|
263 | 9686 | azabala | * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
|
264 | */
|
||
265 | 10860 | azabala | public void open(File f) { |
266 | 9686 | azabala | m_Fich = f; |
267 | 12372 | azabala | isInitialized = false;
|
268 | 9686 | azabala | } |
269 | 10628 | caballero | |
270 | 9686 | azabala | /**
|
271 | 10823 | azabala | * 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 | 11704 | jaume | *
|
275 | 10823 | azabala | * @param index
|
276 | * position of the fmap feature whose dwg entity is required
|
||
277 | 11704 | jaume | *
|
278 | 10823 | azabala | */
|
279 | public Object getCadSource(int index) { |
||
280 | if(debug)
|
||
281 | return getEntity(index);
|
||
282 | else
|
||
283 | return null; |
||
284 | 9686 | azabala | } |
285 | 10823 | azabala | |
286 | 9686 | azabala | /**
|
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 | 17118 | vcaballero | public void initialize() throws ReadDriverException { |
299 | 9686 | azabala | if (isInitialized)
|
300 | return;
|
||
301 | else
|
||
302 | isInitialized = true;
|
||
303 | attr.setLoadedInMemory(true);
|
||
304 | 10823 | azabala | DwgFile dwg = new DwgFile(m_Fich.getAbsolutePath());
|
305 | 9686 | azabala | |
306 | try {
|
||
307 | dwg.read(); |
||
308 | } catch (DwgVersionNotSupportedException e1) {
|
||
309 | 10628 | caballero | |
310 | 9686 | azabala | 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 | 10628 | caballero | // 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 | 17118 | vcaballero | } catch (FileNotFoundException e) { |
329 | throw new FileNotFoundDriverException(getName(),e); |
||
330 | 10628 | caballero | } catch (IOException e) { |
331 | throw new InitializeDriverException(getName(),e); |
||
332 | } |
||
333 | 9686 | azabala | |
334 | 10823 | azabala | fileVersion = dwg.getDwgVersion(); |
335 | 9686 | azabala | dwg.calculateGisModelDwgPolylines(); |
336 | 10325 | azabala | dwg.blockManagement2(); |
337 | 10823 | azabala | List dwgObjects = dwg.getDwgObjects();
|
338 | 11704 | jaume | |
339 | 10823 | azabala | //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 | 11704 | jaume | Rectangle2D roi = new |
352 | Rectangle2D.Double(xmin-100, ymin-100, |
||
353 | 10823 | azabala | (xmax-xmin)+100, (ymax-ymin)+100); |
354 | addRegionOfInterest(roi); |
||
355 | } |
||
356 | } |
||
357 | 9686 | azabala | // 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 | 11704 | jaume | |
372 | 19318 | jmvivo | labeling = new AttrInTableLabelingStrategy();
|
373 | ((AttrInTableLabelingStrategy) labeling).setTextFieldId(arrayFields.indexOf("Text"));
|
||
374 | ((AttrInTableLabelingStrategy) labeling).setRotationFieldId(arrayFields.indexOf("RotationText"));
|
||
375 | ((AttrInTableLabelingStrategy) labeling).setHeightFieldId(arrayFields.indexOf("HeightText"));
|
||
376 | 9686 | azabala | |
377 | 9825 | azabala | boolean is3dFile = dwg.isDwg3DFile();
|
378 | 10823 | azabala | try {
|
379 | for (int i = 0; i < dwgObjects.size(); i++) { |
||
380 | DwgObject entity = (DwgObject) dwgObjects.get(i); |
||
381 | 11061 | azabala | 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 | 11704 | jaume | |
392 | 11061 | azabala | String fmapStr = converter.toFMapString(is3dFile);
|
393 | // nombre del tipo de geometria fmap
|
||
394 | auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(fmapStr); |
||
395 | 11704 | jaume | |
396 | 11061 | azabala | // indice del registro
|
397 | auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
||
398 | 11704 | jaume | |
399 | 11061 | azabala | // 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 | 11704 | jaume | |
406 | 11061 | azabala | int color = entity.getColor();
|
407 | if(color < 0) |
||
408 | color = Math.abs(color);
|
||
409 | if(color > 255) |
||
410 | 11704 | jaume | color = colorByLayer; |
411 | 11061 | azabala | auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
412 | 10628 | caballero | |
413 | 11061 | azabala | 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 | 10628 | caballero | |
419 | 11061 | azabala | if (entity instanceof IDwg3DTestable) { |
420 | auxRow[ID_FIELD_ELEVATION] = ValueFactory |
||
421 | .createValue(((IDwg3DTestable) entity).getZ()); |
||
422 | } |
||
423 | 10628 | caballero | |
424 | 11061 | azabala | 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 | 11704 | jaume | |
444 | 11061 | azabala | if(debug)
|
445 | saveEntity(entity); |
||
446 | |||
447 | 10823 | azabala | } |
448 | 11061 | azabala | } catch (Exception e) { |
449 | // TODO Auto-generated catch block
|
||
450 | e.printStackTrace(); |
||
451 | continue;
|
||
452 | 9686 | azabala | } |
453 | 10823 | azabala | }// for
|
454 | 10628 | caballero | |
455 | 10823 | azabala | } catch (Throwable t) { |
456 | t.printStackTrace(); |
||
457 | } |
||
458 | dwgObjects = null;
|
||
459 | dwg = null;
|
||
460 | System.gc();
|
||
461 | setSymbols(); |
||
462 | } |
||
463 | 11704 | jaume | |
464 | 10823 | azabala | /**
|
465 | * Sets a symbol for each dwg entity's derived feature based in
|
||
466 | * the DWG symbology info.
|
||
467 | * */
|
||
468 | 10860 | azabala | private void setSymbols() throws InitializeDriverException{ |
469 | 12115 | jaume | // 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 | 10628 | caballero | |
480 | 9830 | azabala | defaultLegend = LegendFactory |
481 | .createVectorialUniqueValueLegend(getShapeType()); |
||
482 | 13893 | jaume | defaultLegend.setClassifyingFieldNames(new String[] {"Color"}); |
483 | 17118 | vcaballero | 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 | 12115 | jaume | defaultLegend.setDefaultSymbol(SymbologyFactory. |
486 | createDefaultSymbolByShapeType(getShapeType(), Color.BLACK));
|
||
487 | 9686 | azabala | |
488 | ObjectDriver rs = this;
|
||
489 | IntValue clave; |
||
490 | 12115 | jaume | ISymbol theSymbol = null;
|
491 | 9686 | azabala | 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 | 12115 | jaume | // 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 | 9686 | azabala | |
515 | 12115 | jaume | 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 | 10823 | azabala | }// if
|
532 | 9686 | azabala | } // for
|
533 | 10628 | caballero | } catch (ReadDriverException e) {
|
534 | throw new InitializeDriverException(getName(),e); |
||
535 | 9686 | azabala | } |
536 | } |
||
537 | 11704 | jaume | |
538 | 10823 | azabala | /**
|
539 | * checks if the given geometry intersects or its
|
||
540 | * contained in one of the driver regions of interest.
|
||
541 | 11704 | jaume | *
|
542 | 10823 | azabala | * @param geometry feature geometry we want to check
|
543 | * against the drivers rois.
|
||
544 | 11704 | jaume | *
|
545 | 10823 | azabala | * @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 | 11704 | jaume | |
566 | private boolean checkContains(double x1, double x2, double y1, double y2, |
||
567 | 10823 | azabala | 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 | 11704 | jaume | |
575 | private boolean checkIntersect(double x1, double x2, double y1, double y2, |
||
576 | 10823 | azabala | double ax1, double ax2, double ay1, double ay2){ |
577 | 11704 | jaume | |
578 | 10823 | azabala | return !(x1 > ax2 ||
|
579 | x2 < ax1 || |
||
580 | y1 > ay2 || |
||
581 | y2 < ay1); |
||
582 | 11704 | jaume | |
583 | 10823 | azabala | } |
584 | 9686 | azabala | |
585 | public String getFileVersion() { |
||
586 | 10823 | azabala | return fileVersion;
|
587 | 9686 | azabala | } |
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 | 11704 | jaume | |
598 | 9686 | azabala | /*
|
599 | * (non-Javadoc)
|
||
600 | 11704 | jaume | *
|
601 | 9686 | azabala | * @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 | 11704 | jaume | *
|
610 | 9686 | azabala | * @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 | 11704 | jaume | *
|
619 | 9686 | azabala | * @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 | 11704 | jaume | *
|
628 | 9686 | azabala | * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
|
629 | */
|
||
630 | 11704 | jaume | public ILegend getDefaultLegend() {
|
631 | 9686 | azabala | return defaultLegend;
|
632 | } |
||
633 | |||
634 | /*
|
||
635 | * (non-Javadoc)
|
||
636 | 11704 | jaume | *
|
637 | 9686 | azabala | * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
638 | */
|
||
639 | public DriverAttributes getDriverAttributes() {
|
||
640 | return attr;
|
||
641 | } |
||
642 | |||
643 | /*
|
||
644 | * (non-Javadoc)
|
||
645 | 11704 | jaume | *
|
646 | 9686 | azabala | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
647 | */
|
||
648 | 10860 | azabala | public int[] getPrimaryKeys() { |
649 | 9686 | azabala | // TODO Auto-generated method stub
|
650 | return null; |
||
651 | } |
||
652 | |||
653 | /*
|
||
654 | * (non-Javadoc)
|
||
655 | 11704 | jaume | *
|
656 | 9686 | azabala | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
657 | */
|
||
658 | 10860 | azabala | public void write(DataWare arg0) { |
659 | 9686 | azabala | // TODO Auto-generated method stub
|
660 | |||
661 | } |
||
662 | |||
663 | public void setDataSourceFactory(DataSourceFactory arg0) { |
||
664 | // TODO Auto-generated method stub
|
||
665 | |||
666 | } |
||
667 | |||
668 | 10860 | azabala | public void close() { |
669 | 12372 | azabala | entities.clear(); |
670 | entities = null;
|
||
671 | System.gc();
|
||
672 | 9686 | azabala | |
673 | } |
||
674 | |||
675 | public File getFile() { |
||
676 | return m_Fich;
|
||
677 | } |
||
678 | |||
679 | public boolean isWritable() { |
||
680 | return m_Fich.canWrite();
|
||
681 | } |
||
682 | 10823 | azabala | |
683 | |||
684 | public boolean isDebug() { |
||
685 | return debug;
|
||
686 | } |
||
687 | |||
688 | |||
689 | public void setDebug(boolean debug) { |
||
690 | this.debug = debug;
|
||
691 | } |
||
692 | 11704 | jaume | |
693 | 10860 | azabala | public ILabelingStrategy getDefaultLabelingStrategy() {
|
694 | return labeling;
|
||
695 | } |
||
696 | 12299 | caballero | public int getFieldType(int i) { |
697 | DefaultTableModel dtm=getTableModel();
|
||
698 | String columnName=dtm.getColumnName(i);
|
||
699 | if (columnName.equals("ID")){ |
||
700 | 12658 | caballero | return Types.INTEGER; |
701 | 12299 | caballero | } 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 | 9686 | azabala | } |
724 | 11061 | azabala | |
725 | |||
726 | |||
727 | |||
728 |