[Drawkit] DXF Import Progress / Example
Allan
allandaly at me.com
Thu Jan 22 00:47:27 PST 2009
Hello Brad and Graham,
I spent some time looking over your revised SonoPlot application,
Brad, and realized quickly that the DXF import process is pretty
complicated due to the way DXF files are formatted. You've certainly
done a good job with it, but for what I'm doing I need a more
comprehensive approach to getting all of the object types available in
the DXF files into my application.
Rather than take on the task of more-or-less writing an entire
generalized DXF importer based on the SonoPlot approach, I spent some
time looking for existing DXF import libraries and actually found a
couple written in c++ that seemed usable. There's a nice summary of
available tools at http://tomacorp.com/dxf.html where they list and
compare a number of existing libraries. Here's a quick summary of the
two I looked at.
(1) DIME (DXF Import Manipulation and Export): (http://www.coin3d.org/lib/dime/
) -- looks like this was developed starting about 9 years ago and
shows some recent activity within the past couple of years.
(2) dxflib (http://www.ribbonsoft.com/dxflib.html) -- a simple
approach for both reading and writing DXF files. Code is written in c+
+ and the concept and approach were quite clear to me. I did not
explore the writing side of the code as I do not plan to implement
that at all.
I ended up using (2) dxflib above as the basis for my test project.
The way this works you create a c++ "creation adapter" class that has
it's methods called at appropriate points in the DXF reading process.
For example, when the DXF file reads in a line, it calls the "addLine"
method and provides the info extracted from the DXF file that is
needed to create the object. I ended up wrapping this c++ file with my
own obj-c DXFImporter class. To extend the example, the "addLine"
method in the c++ class then calles an "addLine" method in my importer
class and from there I create the DrawKit objects, layers, etc.
So far I have implemented lines, polylines, circles, and arcs. It all
works pretty well and it shouldn't be that much more work to tackle
blocks and text as well as any other geometric objects that I decide I
need.
If you'd like to take a look at what I've done, I posted a zip of my
Xcode project and associated files, as well as a couple DXF file
examples at this site.
http://public.me.com/allandaly. I called the project DKSimpleDXF as
this is just a very basic extension of the simple DK demo that Graham
created and makes available as part of his downloads. If/when you run
the project, there is an "Import DXF..." command under the file menu
that you can use to try out the two sample DXF files I provided. The
shapes file is simple and small. I created it in AutoCAD 2009 and
saved it in DXF 2000 format.
The floorplan file is another example that is more like the actual
types of files I will be using. This has thousands of DXF objects in
it and works OK. Once imported things are a bit slow to drag and I'm
starting to get a number of crashes that I'll need to dig into at some
point, but for now at least it works and I've learned quite a bit
about the DXF format and the DrawKit logic/implementation. Graham --
if you happen to try this out I would appreciate it if you have any
thoughts on the crashes that happen one you try to "select all" and
"move" the large number of DK objects that I created based on the DXF
file.
Another question I have for you, Graham, is what is the correct logic
in the "simple" DK demo program to do a zoom to fit the entire extents
of the imported DXF into the area of the drawing that you can see on
the screen? In other words, how would I implement a "zoom extents"
command now that I have the DXF imported and it extends outside the
viewable area? I did play with the GCZoom methods some, but couldn't
make anything work yet -- but I haven't spent much time on that so far.
Any feedback that you have, Brad or Graham, would be helpful and
appreciated. Thank you.
-Allan
p.s. By the way, Graham, the first very simple extension I did to the
simple demo program was to create a menu command that programmatically
creates a rectangle in the drawing. This was just to get my feet wet
and I started with the logic you wrote in an email string that I found
in the DK archives. Perhaps it would make sense to include this simple
menu item call or something similar as an example to new users of how
the layers, styles, objects, etc all work together.
p.p.s. -- I realize now after writing this that the dxflib is not a
free open source product, but that the developers are asking for some
$ for its use. I'm not sure how I'll handle this with my project yet.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20090122/f6aaca87/attachment.htm>
More information about the Drawkit
mailing list