Chapter 27. OpenDCL

The DCL language has extremely interesting features. The procedure used to control dialog structure using the column and row containers is comparable to the containers and Layout Managers in Java, which undoubtedly is far better than the way Visual BASIC forms are programmed. For many applications, its performance is more than enough. This can be verified just by checking the many DCL files in a typical AutoCAD installation. But DCL is limited to modal dialog boxes and can only use a few of the wide range of widgets available in the Windows graphic user interface. Having a truly “visual” environment for their design that allows on-screen placement is also missed. This second aspect, given the extreme simplicity of the DCL language, is not so problematic. 
 This chapter will be devoted to examining OpenDCL, an alternative that even if it does not meet all the requirements we would wish to find in a tool like this, is currently the most practical solution for the Visual LISP programmer wishing to enrich the graphical user interface beyond that which DCL offers. OpenDCL is justified in those cases in which: 
  • A Non-Modal Dialog is required, i.e., a dialog that allows working in AutoCAD despite the dialog box being open. 
  • The use of controls (widgets) not available in DCL. 
This chapter will discuss the operation of OpenDCL developing an application with these characteristics.
OpenDCL not part of AutoCAD. It is based on ObjectDCL, a commercial application by 3rd day Software that was released as open source under the GNU General Public License in 2006 by owner Chad Wanless. OpenDCL has been enriched with the contribution of a large group of developers led by Owen Wengerd and David Robison in an open source project hosted on SourceForge, from where the application’s latest version can be downloaded. The URL for OpenDCL is  http://www.sourceforge.net/projects/opendcl. This chapter has been prepared using the ENU.7.0.0.4 version. The OpenDCL help is available online at http://www.opendcl.com/HelpFiles/index.php.
The downloaded package includes an installer that creates the application’s folders and installs the necessary files. The OpenDCL runtime module is automatically registered for all versions of AutoCAD installed in the host computer. Once installed, the OpenDCL development environment may be started as a stand-alone program by double-clicking the icon created on the desktop or the Start menu.
We can include the user interface created with OpenDCL in our LSP source code file. But for this application to work on a computer that does not have OpenDCL installed we must include with our application its runtime module. Ensuring proper installation of the necessary files automatically requires the creation of an installer, for which there are widely used applications, but this subject is beyond this book's scope. An excellent free application that can be used to create our application's installer, including the runtime module, is Jordan Russell's InnoSetup. The OpenDCL website includes a step by step tutorial written by Lance Gordon that shows how to create an application installer using InnoSetup. In the case of an application using modeless dialogs like the one created in this chapter we must take into account the need to include in an acaddoc.lsp file the expression needed to load the application for each drawing.
An OpenDCL application consists of AutoLISP code and OpenDCL project data. The OpenDCL project is created and edited in OpenDCL Studio and may be stored in an ODCL file or embedded into the AutoLISP source code file.  OpenDCL follows the event-driven programming paradigm, so what happens in the user interface triggers the action specified by that particular event's callback function. A typical OpenDCL application includes in an associated LSP file:
  • The code required to load and display a form.
  • The event handlers, i.e., functions that react to events such as selecting a button or list item.
To simplify the project's structure a LSP file should be created for each form, with the code organized in such a way that the main function is placed first, followed by the auxiliary functions and finally the event callback functions.

This Chapter's Tutorial: An application developed with OpenDCL.

To show how to create and use an OpenDCL dialog linked to a Visual LISP application, we will discuss the application we have named XREF Explorer.  This application displays the Layers in a hierarchical tree view related to the drawing they belong to, whether it is the main drawing or an attached external reference. All the drawings, both the active one and its attached external references appear as branches dependent on a root node identified as All.
Next to the each drawing’s name an icon is displayed to distinguish between the current drawing and the attached external references. This icon changes color to indicate whether the corresponding node is selected or not. From the drawing nodes new branches originate representing their Layers. These branches are identified as Layers by a different icon, that also changes color to indicate it the Layer it represents is selected.
The application can be used to perform some Layer operations such as turning them on and off, isolating selected Layers by turning off the others and changing the Layer colors. More operations were not included to keep the code as simple as possible, but by creating more buttons and their callback actions the functionality of AutoCAD’s native Layer command can be reproduced.
For this project a non-modal Palette form will be used. This form can be docked to one side of the AutoCAD window and can also be shown or hidden automatically according to the cursor location. Being a non-modal form is will be necessary:
  • To load the AutoLISP code for each open drawing, which could be done with an expression included in the acaddoc.lsp file.
  • To foresee possible environment changes such as opening new files or changing the focus between different open drawings in order to update the Drawings and Layers Tree view.
  • To consider the possibility that all drawings are closed, entering a no-document state. In this case, the form should be closed.
In addition to this, resizing will be enabled showing how to keep a consistent arrangement of the controls in the resized form.
Figure 27.7. XREF Explorer palette in use.

 This Chapter includes the following sections:

27.1. The OpenDCL project.
27.2. The OpenDCL development environment.
27.3. Form Types.
27.4. Control Property Wizard.
27.5. Tutorial: An application developed with OpenDCL.
27.6. Adding the necessary controls.
27.7. Distributing the Application.
27.8. Summary.

Chapter 27 Source code.


Your questions or comments about this Chapter's contents are welcome!


Buy this book from Amazon

No comments:

Post a Comment