Revision 11061
trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/DwgMemoryDriver.java | ||
---|---|---|
46 | 46 |
* |
47 | 47 |
* $Id$ |
48 | 48 |
* $Log$ |
49 |
* Revision 1.10 2007-03-22 19:56:12 azabala |
|
49 |
* Revision 1.11 2007-04-04 17:49:06 azabala |
|
50 |
* Dependencies of libDwg with libFMap removed |
|
51 |
* |
|
52 |
* Revision 1.10 2007/03/22 19:56:12 azabala |
|
50 | 53 |
* changes in exceptinos api |
51 | 54 |
* |
52 | 55 |
* Revision 1.9 2007/03/20 20:21:19 azabala |
... | ... | |
84 | 87 |
import java.io.File; |
85 | 88 |
import java.io.IOException; |
86 | 89 |
import java.util.ArrayList; |
90 |
import java.util.HashMap; |
|
87 | 91 |
import java.util.List; |
92 |
import java.util.Map; |
|
88 | 93 |
|
89 | 94 |
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
90 | 95 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
... | ... | |
95 | 100 |
import com.hardcode.gdbms.engine.values.IntValue; |
96 | 101 |
import com.hardcode.gdbms.engine.values.Value; |
97 | 102 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
103 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgArc2FMapConverter; |
|
104 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgCircle2FMapConverter; |
|
105 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgEllipse2FMapConverter; |
|
106 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgLine2FMapConverter; |
|
107 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgLwPline2FMapConverter; |
|
108 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgMText2FMapConverter; |
|
109 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPFacePline2FMapConverter; |
|
110 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPoint2FMapConverter; |
|
111 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPolyline2D2FMapConverter; |
|
112 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgPolyline3D2FMapConverter; |
|
113 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgSolid2FMapConverter; |
|
114 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.DwgText2FMapConverter; |
|
115 |
import com.iver.cit.gvsig.drivers.dwg.fmapconverters.IDwg2FMap; |
|
98 | 116 |
import com.iver.cit.gvsig.fmap.core.FShape; |
99 | 117 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
100 | 118 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
... | ... | |
111 | 129 |
import com.iver.cit.jdwglib.dwg.DwgFile; |
112 | 130 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
113 | 131 |
import com.iver.cit.jdwglib.dwg.DwgVersionNotSupportedException; |
114 |
import com.iver.cit.jdwglib.dwg.IDwg2FMap; |
|
115 | 132 |
import com.iver.cit.jdwglib.dwg.IDwg3DTestable; |
133 |
import com.iver.cit.jdwglib.dwg.objects.DwgArc; |
|
134 |
import com.iver.cit.jdwglib.dwg.objects.DwgCircle; |
|
135 |
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse; |
|
136 |
import com.iver.cit.jdwglib.dwg.objects.DwgLine; |
|
137 |
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline; |
|
116 | 138 |
import com.iver.cit.jdwglib.dwg.objects.DwgMText; |
139 |
import com.iver.cit.jdwglib.dwg.objects.DwgPFacePolyline; |
|
140 |
import com.iver.cit.jdwglib.dwg.objects.DwgPoint; |
|
141 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D; |
|
142 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D; |
|
143 |
import com.iver.cit.jdwglib.dwg.objects.DwgSolid; |
|
117 | 144 |
import com.iver.cit.jdwglib.dwg.objects.DwgText; |
118 | 145 |
import com.iver.cit.jdwglib.util.AcadColor; |
119 | 146 |
|
... | ... | |
123 | 150 |
* This driver load the Dwg file in memory This driver uses jdwglib |
124 | 151 |
* |
125 | 152 |
* @author jmorell |
153 |
* @author azabala |
|
126 | 154 |
*/ |
127 | 155 |
public class DwgMemoryDriver extends AbstractCadMemoryDriver implements |
128 | 156 |
VectorialFileDriver, WithDefaultLegend { |
157 |
|
|
158 |
static Map convertersRegistry = new HashMap(); |
|
129 | 159 |
|
160 |
/* |
|
161 |
* this process of registration of the 2FMapConverters could be |
|
162 |
* automathic (by java reflection), but the number of dwg entities |
|
163 |
* is finited, and some converters could exists but dont work well |
|
164 |
* (so thats the reason we mantain a "manual" registering process. |
|
165 |
* */ |
|
166 |
static{ |
|
167 |
registerFMapConverter(DwgArc.class, new DwgArc2FMapConverter()); |
|
168 |
registerFMapConverter(DwgCircle.class, new DwgCircle2FMapConverter()); |
|
169 |
registerFMapConverter(DwgEllipse.class, new DwgEllipse2FMapConverter()); |
|
170 |
registerFMapConverter(DwgLine.class, new DwgLine2FMapConverter()); |
|
171 |
registerFMapConverter(DwgLwPolyline.class, new DwgLwPline2FMapConverter()); |
|
172 |
registerFMapConverter(DwgMText.class, new DwgMText2FMapConverter()); |
|
173 |
registerFMapConverter(DwgPFacePolyline.class, new DwgPFacePline2FMapConverter()); |
|
174 |
registerFMapConverter(DwgPoint.class, new DwgPoint2FMapConverter()); |
|
175 |
registerFMapConverter(DwgPolyline2D.class, new DwgPolyline2D2FMapConverter()); |
|
176 |
registerFMapConverter(DwgPolyline3D.class, new DwgPolyline3D2FMapConverter()); |
|
177 |
registerFMapConverter(DwgSolid.class, new DwgSolid2FMapConverter()); |
|
178 |
registerFMapConverter(DwgText.class, new DwgText2FMapConverter()); |
|
179 |
try { |
|
180 |
Class.forName("com.iver.cit.gvsig.drivers.dwg.fmapconverters.FMapUtil"); |
|
181 |
} catch (ClassNotFoundException e) { |
|
182 |
e.printStackTrace(); |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
public static void registerFMapConverter (Class clazz, IDwg2FMap converter){ |
|
187 |
if(! DwgObject.class.isAssignableFrom(clazz)) |
|
188 |
return; |
|
189 |
convertersRegistry.put(clazz, converter); |
|
190 |
} |
|
191 |
|
|
192 |
public static IDwg2FMap getConverter(Class clazz){ |
|
193 |
if(! DwgObject.class.isAssignableFrom(clazz)) |
|
194 |
return null; |
|
195 |
return (IDwg2FMap) convertersRegistry.get(clazz); |
|
196 |
} |
|
197 |
|
|
130 | 198 |
VectorialUniqueValueLegend defaultLegend; |
131 | 199 |
private File m_Fich; |
132 | 200 |
private String fileVersion; |
... | ... | |
137 | 205 |
//new WithDefaultLegend API |
138 | 206 |
private AttrInTableLabeling labeling; |
139 | 207 |
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 | 208 |
private boolean debug = false; |
145 | 209 |
/** |
146 | 210 |
* entities of the dwg file (once applied many transformation, |
... | ... | |
279 | 343 |
((AttrInTableLabeling) labeling).setRotationFieldId(arrayFields.indexOf("RotationText")); |
280 | 344 |
((AttrInTableLabeling) labeling).setHeightFieldId(arrayFields.indexOf("HeightText")); |
281 | 345 |
|
282 |
|
|
283 | 346 |
boolean is3dFile = dwg.isDwg3DFile(); |
284 | 347 |
try { |
285 | 348 |
for (int i = 0; i < dwgObjects.size(); i++) { |
286 | 349 |
DwgObject entity = (DwgObject) dwgObjects.get(i); |
350 |
Class clazz = entity.getClass(); |
|
351 |
IDwg2FMap converter = getConverter(clazz); |
|
352 |
try { |
|
353 |
if(converter != null){ |
|
354 |
IGeometry geometry = converter.toFMapGeometry(entity, is3dFile); |
|
355 |
if (geometry == null) |
|
356 |
continue; |
|
357 |
//we check for Region of Interest of the CAD file |
|
358 |
if(! checkRois(geometry)) |
|
359 |
continue; |
|
360 |
|
|
361 |
String fmapStr = converter.toFMapString(is3dFile); |
|
362 |
// nombre del tipo de geometria fmap |
|
363 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(fmapStr); |
|
364 |
|
|
365 |
// indice del registro |
|
366 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
367 |
|
|
368 |
// nombre de entidad dwg |
|
369 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(entity.toString()); |
|
370 |
String layerName = dwg.getLayerName(entity); |
|
371 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
|
372 |
.createValue(layerName); |
|
373 |
int colorByLayer = dwg.getColorByLayer(entity); |
|
374 |
|
|
375 |
int color = entity.getColor(); |
|
376 |
if(color < 0) |
|
377 |
color = Math.abs(color); |
|
378 |
if(color > 255) |
|
379 |
color = colorByLayer; |
|
380 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
|
287 | 381 |
|
288 |
if (entity instanceof IDwg2FMap) { |
|
289 |
IDwg2FMap dwgEnt = (IDwg2FMap) entity; |
|
290 |
IGeometry geometry = dwgEnt.toFMapGeometry(is3dFile); |
|
291 |
if (geometry == null) |
|
292 |
continue; |
|
293 |
//we check for Region of Interest of the CAD file |
|
294 |
if(! checkRois(geometry)) |
|
295 |
continue; |
|
296 |
|
|
297 |
String fmapStr = dwgEnt.toFMapString(is3dFile); |
|
298 |
// nombre del tipo de geometria fmap |
|
299 |
auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(fmapStr); |
|
300 |
|
|
301 |
// indice del registro |
|
302 |
auxRow[ID_FIELD_ID] = ValueFactory.createValue(i); |
|
303 |
|
|
304 |
// nombre de entidad dwg |
|
305 |
auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(dwgEnt |
|
306 |
.toString()); |
|
307 |
String layerName = dwg.getLayerName(entity); |
|
308 |
auxRow[ID_FIELD_LAYER] = ValueFactory |
|
309 |
.createValue(layerName); |
|
310 |
int colorByLayer = dwg.getColorByLayer(entity); |
|
311 |
|
|
312 |
int color = entity.getColor(); |
|
313 |
if(color < 0) |
|
314 |
color = Math.abs(color); |
|
315 |
if(color > 255) |
|
316 |
color = colorByLayer; |
|
317 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
|
382 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0); |
|
383 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
|
384 |
.createValue(0.0); |
|
385 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
|
386 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
318 | 387 |
|
319 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0); |
|
320 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
|
321 |
.createValue(0.0); |
|
322 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
|
323 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
|
388 |
if (entity instanceof IDwg3DTestable) { |
|
389 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory |
|
390 |
.createValue(((IDwg3DTestable) entity).getZ()); |
|
391 |
} |
|
324 | 392 |
|
325 |
if (entity instanceof IDwg3DTestable) { |
|
326 |
auxRow[ID_FIELD_ELEVATION] = ValueFactory |
|
327 |
.createValue(((IDwg3DTestable) entity).getZ()); |
|
393 |
if (entity instanceof DwgMText) { |
|
394 |
DwgMText mtext = (DwgMText) entity; |
|
395 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(mtext |
|
396 |
.getText()); |
|
397 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
|
398 |
.createValue(mtext.getHeight()); |
|
399 |
} else if (entity instanceof DwgText) { |
|
400 |
DwgText text = (DwgText) entity; |
|
401 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(text |
|
402 |
.getText()); |
|
403 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory |
|
404 |
.createValue(text.getThickness()); |
|
405 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
|
406 |
.createValue(text.getHeight()); |
|
407 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
|
408 |
.createValue(Math.toDegrees(text |
|
409 |
.getRotationAngle())); |
|
410 |
}// if-else |
|
411 |
addGeometry(geometry, auxRow); |
|
412 |
|
|
413 |
if(debug) |
|
414 |
saveEntity(entity); |
|
415 |
|
|
328 | 416 |
} |
329 |
|
|
330 |
if (entity instanceof DwgMText) { |
|
331 |
DwgMText mtext = (DwgMText) entity; |
|
332 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(mtext |
|
333 |
.getText()); |
|
334 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
|
335 |
.createValue(mtext.getHeight()); |
|
336 |
} else if (entity instanceof DwgText) { |
|
337 |
DwgText text = (DwgText) entity; |
|
338 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(text |
|
339 |
.getText()); |
|
340 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory |
|
341 |
.createValue(text.getThickness()); |
|
342 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory |
|
343 |
.createValue(text.getHeight()); |
|
344 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory |
|
345 |
.createValue(Math.toDegrees(text |
|
346 |
.getRotationAngle())); |
|
347 |
}// if-else |
|
348 |
addGeometry(geometry, auxRow); |
|
349 |
|
|
350 |
if(debug) |
|
351 |
saveEntity(entity); |
|
352 |
|
|
417 |
} catch (Exception e) { |
|
418 |
// TODO Auto-generated catch block |
|
419 |
e.printStackTrace(); |
|
420 |
continue; |
|
353 | 421 |
} |
354 | 422 |
}// for |
355 | 423 |
|
... | ... | |
572 | 640 |
return labeling; |
573 | 641 |
} |
574 | 642 |
} |
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
Also available in: Unified diff