pelicanpic

DKDocTest - Example Application using DrawKit and DXFReader

DKDocTest is an example application that uses both the DrawKit Cocoa graphics framework created by Graham Cox and the DXFReader framework available on this site. DKDocTest is an evolution of the DKSimpleDXF example application also available on this site. DKDocTest follows a multiple-document architecture and implements a simple tool palette and layers palette for interacting with the DKDrawingDocuments.

DKDocTest has been my test-bed as I continue to learn the DrawKit framework and develop the DXFReader code. It is a simple but functional application. I am posting it here mainly as an example of code for others to see and use to allow the translation of a standard DXF file into DrawKit objects.

DKSimpleDXF is developed in Objective-C 2.0 and I am using the properties, garbage collection, and fast enumeration features of the latest version of Objective-C so it requires Mac OS X 10.5 or later. I am issuing this as opensource code under a standard BSD license. See the DrawKit site licencing information on that framework.

Features

DKDocTest Key Features are listed below.

Implements the DKDrawingDocument Multiple-Document Structure
  • allows for multiple independent documents to co-exist
  • each document tracks different layers, tool selections, etc
  • documents can be saved and opened, etc
  • saved documents use the native DKDrawingDocument format (.drawing) so can be opened by other DK-based apps
Layer Palette that implements NSOutlineView
  • allow drag and drop to reorder layers and move layers in to / out of layer groups
  • shows visible and locked status of layers and layer groups
  • correctly deals with fetching and refreshing layers when creating new documents and navigating to/from other apps in Finder
Extends (via category) DKDrawingDocument for easy DKLayerGroup creation
  • creates a new method called "newLayerGroupWithLayer:" that creates a layer group with some default layers inside
Implements a Simple Tool Palette
  • tool palette allows for selection of DK tools
  • tool palette sets "sticky" tool property when a tool is double-clicked
  • tool palette provides visual feedback of "sticky" tool status (checkbox)
  • tool palette allows user to set "sticky" status directly (checkbox)
  • implements a "pan" or "hand" tool (code provided by Graham Cox)
  • correctly deals with fetching and refreshing tool selection and "sticky" status when creating new docs and navigating to/from other apps
Provides DXF Import
  • under the "Testing" menu there is a DXF import feature
  • uses the DXFReader library
  • DXFReader library has been upgraded to provide notifications to allow a client application to track DXF parsing progress
  • uses a progress sheet with NSProgressIndicator feedback to user on DXF parsing and DK object creation status
  • provides a detailed example of how to use the DXFReader library and to convert the results to DK objects
  • creates layers in the new DK document that match the layers in the DXF file
  • creates a layer group for all the DXF layers for easy management of those layers
  • NOTE: DXF import only handles these entities at this time
    • LINE
    • POLYLINE
    • ARC
    • CIRCLE
    • TEXT
    • MTEXT
    • INSERTs and BLOCKs containing the entities listed above
Provides simple example text and shape insert code
  • under the "Testing" menu there are example commands for adding text, shapes, layers, and layer groups
  • code for these commands may be helpful to those starting out with DK (like me a year ago)
Misc
  • configures and uses a drawing grid set up for feet and inches
  • "View" menu allows enable/disable of rulers

Required Custom Changes to DrawKit

  • I deleted the test inside the DKShapeGroup that tests to see if more than one object is being assigned to a group -- this allows a single object to be placed inside of a group (allowed in DXFs and I can't see a problem with it in DK -- a bit strange, but logical)
  • Notifications added to DKToolController to signal when the "automaticallyRevertsToSelectionTool" property changes
  • both of these changes are described on the DK Additions and Changes page on this site

Source Code and Compiled Application

The DKDocTest source code is available for download from this site. This archive contains an XCode 3.1.2 project and the associated files. To run this application you will also need the download DrawKit Version 1.0 Beta 6 (July 15, 2009) from the DrawKit site.

The DKDocTest compiled application is also available to download from this site.

Example DXF files are available on this site on the DXF Resources page if you would like a sample on which to try the DXF import processing code.

Acknowledgements

Graham Cox continues to be very generous with his time and expertise and helped a great deal in the development of this application. Brad Larson and Michael Caron from SonoPlot have also provided useful input and example code (the SonoDraw application) that influenced and informed this project. Thank you Graham, Brad, and Michael.

Copyright © 2009 Allan Daly

brown-bird.net