The Drawing Exchange Format (DXF) is the exchange format of
AutoCAD. This format supports vector graphics (such as polygons,
arcs, lines, and points) and layers. The different editions of the
specifications of the DXF format corresponding to the various
AutoCAD releases can be accessed from the following URL: http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=5129239.
Using the DXF reader
Reading a DXF File into IlvManager shows
how to read the content of a DXF file into an IlvManager object.
Reading a DXF File into IlvManager
IlvManager manager = new IlvManager(0); //with no layer IlvDXFReader reader = new IlvDXFReader(); try { reader.read("myDXFFile.dxf", manager); } catch (IOException e) { e.printStackTrace(); }
You can also read a DXF file directly with the
read
method of the manager. First, you must create the manager and the
stream factory as shown in Preparing to Read a DXF File with the
Manager.
Preparing to Read a DXF File with the
Manager
IlvManager manager = new IlvManager(0); // with no layer IlvDXFStreamFactory factory = new IlvDXFStreamFactory(); manager.setStreamFactory(factory);
When the stream factory is set, calling read loads a DXF file instead of an Rogue
Wave JViews IVL file. See Loading a DXF File.
Loading a DXF File
try { manager.read("myDXFFile.dxf"); } catch (IOException ex) { ex.printStackTrace(); }
The content of the DXF file can be read into an IlvManager object or into any
implementation of the IlvGraphicBag interface, such as IlvGraphicSet. The layer information of the
DXF file is ignored when the file is read into anything other
than an
IlvManager
object.
The IlvDXFReader reads the DXF file and adds
the graphic objects defined in the DXF file to the manager. If an
error occurs during this process, an exception of the type IOException can occur and must be caught.
An example of the use of the reader is available as part of the
demonstration software. For details, see <installdir> /jviews-framework89/samples/dxfreader/index.html.
Customizing the DXF reader
Configuration options can be set on IlvDXFReaderConfigurator. A default
configurator is created when the default constructor of IlvDXFReader is used. You can also pass
your own instance of a configurator to the constructor
IlvDXFReader(IlvDXFReaderConfigurator)
. You can retrieve the current instance of the configurator by
using
IlvDXFReader.getConfigurator()
.
The reader delegates the conversion of DXF entities into Rogue
Wave JViews graphic objects to a factory, IlvDXFGraphicFactory.
A default implementation is provided:
ilog.views.dxf.IlvDefaultDXFGraphicFactory
You can provide your own implementation or
specialize the default implementation.
To set a new factory, use the method:
IlvDXFReaderConfigurator.setGraphicFactory(IlvDXFGraphicFactory)
The following DXF entities are read:
3DFACE
- ARC
- CIRCLE
- DIMENSION
- LINE
- POLYLINE
- LWPOLYLINE
- TEXT
- MTEXT
- POINT
- SOLID
- TRACE
Limitations
Only the 2D information of the DXF file is
read; 3D information is ignored.
The reader recognizes the most popular
attributes, but does not process all the attributes of the
entities. Some attributes are not rendered in the same way as
Autodesk® AutoCAD.