Revision 10628 trunk/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/DwgMemoryDriver.java
DwgMemoryDriver.java | ||
---|---|---|
46 | 46 |
* |
47 | 47 |
* $Id$ |
48 | 48 |
* $Log$ |
49 |
* Revision 1.7 2007-02-27 17:18:03 azabala |
|
49 |
* Revision 1.8 2007-03-06 17:27:31 caballero |
|
50 |
* Exceptions |
|
51 |
* |
|
52 |
* Revision 1.7 2007/02/27 17:18:03 azabala |
|
50 | 53 |
* solved bug with text orientation |
51 | 54 |
* |
52 | 55 |
* Revision 1.6 2007/02/14 16:17:22 azabala |
... | ... | |
80 | 83 |
import java.util.ArrayList; |
81 | 84 |
import java.util.List; |
82 | 85 |
|
86 |
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
|
87 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
88 |
import com.hardcode.gdbms.driver.exceptions.UnsupportedVersionDriverException; |
|
83 | 89 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
84 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
85 | 90 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
86 | 91 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
87 | 92 |
import com.hardcode.gdbms.engine.values.IntValue; |
... | ... | |
112 | 117 |
* Driver that allows gvSIG to read files in DWG format Using this driver, a |
113 | 118 |
* gvSIG user can manipulate part of the information contained in a DWG file |
114 | 119 |
* This driver load the Dwg file in memory This driver uses jdwglib |
115 |
*
|
|
120 |
* |
|
116 | 121 |
* @author jmorell |
117 | 122 |
*/ |
118 | 123 |
public class DwgMemoryDriver extends AbstractCadMemoryDriver implements |
... | ... | |
132 | 137 |
|
133 | 138 |
/* |
134 | 139 |
* (non-Javadoc) |
135 |
*
|
|
140 |
* |
|
136 | 141 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File) |
137 | 142 |
*/ |
138 |
public void open(File f) throws IOException {
|
|
143 |
public void open(File f) { |
|
139 | 144 |
m_Fich = f; |
140 | 145 |
} |
141 |
|
|
146 |
|
|
142 | 147 |
/** |
143 | 148 |
* Allows recovering of the DWG Drawing entity |
144 |
* associated to the FMap feature whose position
|
|
149 |
* associated to the FMap feature whose position |
|
145 | 150 |
* is index |
146 | 151 |
* @param index position of the fmap feature whose |
147 | 152 |
* dwg entity is required |
148 |
*
|
|
153 |
* |
|
149 | 154 |
* */ |
150 | 155 |
public Object getCadSource(int index){ |
151 | 156 |
return dwg.getDwgObject(index); |
... | ... | |
161 | 166 |
* objects contained inside the blocks through the blockManagement method. |
162 | 167 |
* And finally, we can read the objects Vector, and convert this objects to |
163 | 168 |
* the FMap object model. |
169 |
* @throws InitializeDriverException |
|
164 | 170 |
*/ |
165 |
public void initialize() throws IOException {
|
|
171 |
public void initialize() throws InitializeDriverException {
|
|
166 | 172 |
if (isInitialized) |
167 | 173 |
return; |
168 | 174 |
else |
... | ... | |
175 | 181 |
try { |
176 | 182 |
dwg.read(); |
177 | 183 |
} catch (DwgVersionNotSupportedException e1) { |
184 |
|
|
178 | 185 |
String autodeskUrl = "<a href=\"http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151\">" |
179 | 186 |
+ "http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151</a>"; |
180 |
throw new IOException( |
|
181 |
formatString( |
|
182 |
"La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s", |
|
183 |
new String[] { e1.getDwgVersion().toString(), |
|
184 |
m_Fich.getName(), |
|
185 |
Messages.getText("Probe_to_convert"), |
|
186 |
Messages.getText("Autodesk_converter"), |
|
187 |
autodeskUrl })); |
|
188 |
}// catch |
|
187 |
// throw new InitializeDriverException( |
|
188 |
// formatString( |
|
189 |
// "La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s", |
|
190 |
// new String[] { e1.getDwgVersion().toString(), |
|
191 |
// m_Fich.getName(), |
|
192 |
// Messages.getText("Probe_to_convert"), |
|
193 |
// Messages.getText("Autodesk_converter"), |
|
194 |
// autodeskUrl })); |
|
195 |
String description=formatString( |
|
196 |
"La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s", |
|
197 |
new String[] { e1.getDwgVersion().toString(), |
|
198 |
m_Fich.getName(), |
|
199 |
Messages.getText("Probe_to_convert"), |
|
200 |
Messages.getText("Autodesk_converter"), |
|
201 |
autodeskUrl }); |
|
202 |
throw new UnsupportedVersionDriverException(getName(),e1,description); |
|
203 |
} catch (IOException e) { |
|
204 |
throw new InitializeDriverException(getName(),e); |
|
205 |
} |
|
189 | 206 |
|
190 | 207 |
// dwg.initializeLayerTable(); |
191 | 208 |
dwg.calculateGisModelDwgPolylines(); |
... | ... | |
211 | 228 |
|
212 | 229 |
for (int i = 0; i < dwgObjects.size(); i++) { |
213 | 230 |
DwgObject entity = (DwgObject) dwgObjects.get(i); |
214 |
|
|
231 |
|
|
215 | 232 |
if(entity instanceof IDwg2FMap){ |
216 |
|
|
233 |
|
|
217 | 234 |
IDwg2FMap dwgEnt = (IDwg2FMap)entity; |
218 | 235 |
//TODO Ojo, revisar las fshape a null |
219 | 236 |
FShape fshape = dwgEnt.toFMapGeometry(is3dFile); |
... | ... | |
229 | 246 |
auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName); |
230 | 247 |
int color = entity.getColor(); |
231 | 248 |
int colorByLayer = dwg.getColorByLayer(entity); |
232 |
|
|
249 |
|
|
233 | 250 |
// TODO: if (color==0) color ByBlock |
234 | 251 |
if (color == 256) |
235 | 252 |
color = colorByLayer; |
236 | 253 |
auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color); |
237 |
|
|
254 |
|
|
238 | 255 |
auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0); |
239 | 256 |
auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0); |
240 | 257 |
auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
241 | 258 |
auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0); |
242 |
|
|
259 |
|
|
243 | 260 |
if(entity instanceof IDwg3DTestable){ |
244 |
auxRow[ID_FIELD_ELEVATION] =
|
|
245 |
ValueFactory.createValue(((IDwg3DTestable)entity).getZ());
|
|
261 |
auxRow[ID_FIELD_ELEVATION] = |
|
262 |
ValueFactory.createValue(((IDwg3DTestable)entity).getZ()); |
|
246 | 263 |
} |
247 |
|
|
264 |
|
|
248 | 265 |
if(entity instanceof DwgMText){ |
249 | 266 |
DwgMText mtext = (DwgMText) entity; |
250 | 267 |
auxRow[ID_FIELD_TEXT] = ValueFactory. |
... | ... | |
263 | 280 |
createValue(Math.toDegrees(text.getRotationAngle())); |
264 | 281 |
}//if-else |
265 | 282 |
addShape(fshape, auxRow); |
266 |
|
|
283 |
|
|
267 | 284 |
}//if instanceof |
268 | 285 |
else{ |
269 | 286 |
|
270 | 287 |
} |
271 | 288 |
}//for |
272 |
|
|
289 |
|
|
273 | 290 |
FSymbol myDefaultSymbol = new FSymbol(getShapeType()); |
274 | 291 |
myDefaultSymbol.setShapeVisible(false); |
275 | 292 |
myDefaultSymbol.setFontSizeInPixels(false); |
... | ... | |
279 | 296 |
myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
280 | 297 |
myDefaultSymbol.setSize(3); |
281 | 298 |
myDefaultSymbol.setSizeInPixels(true); |
282 |
|
|
299 |
|
|
283 | 300 |
defaultLegend = LegendFactory |
284 | 301 |
.createVectorialUniqueValueLegend(getShapeType()); |
285 | 302 |
defaultLegend.setFieldName("Color"); |
... | ... | |
311 | 328 |
defaultLegend.addSymbol(clave, theSymbol); |
312 | 329 |
}//if |
313 | 330 |
} // for |
314 |
} catch (DriverException e) { |
|
315 |
e.printStackTrace(); |
|
316 |
throw new IOException( |
|
317 |
"Error al poner la leyenda por defecto en el Dwg"); |
|
331 |
} catch (ReadDriverException e) { |
|
332 |
throw new InitializeDriverException(getName(),e); |
|
318 | 333 |
} |
319 | 334 |
} |
320 | 335 |
|
... | ... | |
330 | 345 |
return ret; |
331 | 346 |
} |
332 | 347 |
|
333 |
|
|
334 |
|
|
335 | 348 |
|
336 |
|
|
337 | 349 |
|
350 |
|
|
351 |
|
|
352 |
|
|
338 | 353 |
/** |
339 | 354 |
* Method that changes a Point2D array to a FPolygon2D. Is useful to convert |
340 | 355 |
* a polygon given by it points to a FPolygon2D, a polygon in the FMap model |
341 | 356 |
* object |
342 |
*
|
|
357 |
* |
|
343 | 358 |
* @param pts |
344 | 359 |
* Array of Point2D that defines the polygon that will be |
345 | 360 |
* converted in a FPolygon2D |
... | ... | |
358 | 373 |
|
359 | 374 |
/* |
360 | 375 |
* (non-Javadoc) |
361 |
*
|
|
376 |
* |
|
362 | 377 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File) |
363 | 378 |
*/ |
364 | 379 |
public boolean accept(File f) { |
... | ... | |
367 | 382 |
|
368 | 383 |
/* |
369 | 384 |
* (non-Javadoc) |
370 |
*
|
|
385 |
* |
|
371 | 386 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType() |
372 | 387 |
*/ |
373 | 388 |
public int getShapeType() { |
... | ... | |
376 | 391 |
|
377 | 392 |
/* |
378 | 393 |
* (non-Javadoc) |
379 |
*
|
|
394 |
* |
|
380 | 395 |
* @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName() |
381 | 396 |
*/ |
382 | 397 |
public String getName() { |
... | ... | |
385 | 400 |
|
386 | 401 |
/* |
387 | 402 |
* (non-Javadoc) |
388 |
*
|
|
403 |
* |
|
389 | 404 |
* @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend() |
390 | 405 |
*/ |
391 | 406 |
public Legend getDefaultLegend() { |
... | ... | |
394 | 409 |
|
395 | 410 |
/* |
396 | 411 |
* (non-Javadoc) |
397 |
*
|
|
412 |
* |
|
398 | 413 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes() |
399 | 414 |
*/ |
400 | 415 |
public DriverAttributes getDriverAttributes() { |
... | ... | |
403 | 418 |
|
404 | 419 |
/* |
405 | 420 |
* (non-Javadoc) |
406 |
*
|
|
421 |
* |
|
407 | 422 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys() |
408 | 423 |
*/ |
409 |
public int[] getPrimaryKeys() throws DriverException {
|
|
424 |
public int[] getPrimaryKeys() { |
|
410 | 425 |
// TODO Auto-generated method stub |
411 | 426 |
return null; |
412 | 427 |
} |
413 | 428 |
|
414 | 429 |
/* |
415 | 430 |
* (non-Javadoc) |
416 |
*
|
|
431 |
* |
|
417 | 432 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare) |
418 | 433 |
*/ |
419 |
public void write(DataWare arg0) throws DriverException {
|
|
434 |
public void write(DataWare arg0) { |
|
420 | 435 |
// TODO Auto-generated method stub |
421 | 436 |
|
422 | 437 |
} |
... | ... | |
426 | 441 |
|
427 | 442 |
} |
428 | 443 |
|
429 |
public void close() throws IOException {
|
|
444 |
public void close() { |
|
430 | 445 |
// TODO Auto-generated method stub |
431 | 446 |
|
432 | 447 |
} |
Also available in: Unified diff