Through the API an application can create a custom interface. This custom interface allows you to have only the specific tools that you want in your application. When creating an interface using only the Visual CADD™ DLLs, the DLL engine should be initialized and a drawing world (window) set. The rest of the interface is under complete control of the developer. For example, an application may only need to provide viewing capabilities. In this situation, the application may simply create a drawing window and limit the tool set to the zoom and pan functions, thus limiting the user from making any changes to the drawing.
There are several steps in the process of creating a custom interface. The following code samples show the minimum steps required in order to create a custom interface.
Please note the simplicity of these fully functional samples which support several tools, accept user input, and provide user feedback. They are each only a few dozen lines of actual code, all the rest are comment lines.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using VCadd32; using VCType32; namespace API_Help_CSharp2 { public partial class Form1 : Form { // Stand-alone EXEs use the DLL engine, not the Visual // CADD EXE interface. So use AutomationEngine. AutomationEngine vcadd = new AutomationEngine(); // create an index to hold the Visual CADD world int iWorld; public Form1() { // standard C# initialization InitializeComponent(); // Initialize the DLL engine and databases. These // calls initialize internal data and load user // settings such as system and default drawing // settings. If your EXE will use any Visual CADD // dialogs, then also initialize the dialogs. vcadd.Init(); vcadd.InitDialogs(); // Set windows handles. Visual CADD uses these // Windows handles for messaging between your EXE // and the DLL engine. The hWnd Frame is the main // frame of your EXE where your main messaging loop // exists. The Dialog Frame is the window used as // the parent to Visual CADD dialogs, such as tool // ribalogs, and is usually the same frame as the // main frame. The MDI Child is the window which // will hold and display drawings. This sample uses // a picture box for the drawings. vcadd.SethWndFrame(this.Handle.ToInt32()); vcadd.SetDialogFrameHwnd(this.Handle.ToInt32()); vcadd.SethWndMdiClient(this.pictureBox1.Handle.ToInt32()); // Visual CADD has status bar messaging to give the // user various information about the current tool // operations. Visual CADD displays these in the // status bar of its own interface. This sample // uses text boxes for the messages. vcadd.SetMessageHandle(this.textBox1.Handle.ToInt32()); vcadd.SetDistanceHandle(this.textBox2.Handle.ToInt32()); vcadd.SetXYHandle(this.textBox3.Handle.ToInt32()); // Create a Visual CADD drawing, also called a world. // The drawing world is created and attached to the // picture box. Visual CADD supports multiple // drawing worlds, but only acts on one drawing at a // time, called the current world. Set the current // world to the one just created. iWorld = vcadd.NewWorld(this.pictureBox1.Handle.ToInt32()); vcadd.SetCurrWorld(iWorld); // Visual CADD can change the user interface colors. // For consistency in the sample, set the background // to white (index 15) and the cursor to black // (index 0). You may use any Visual CADD colors of // your choice. vcadd.SetBackgroundColor(15); vcadd.SetCursorColor(0); // Visual CADD places new entities in a drawing // using current properties. For consistency in the // sample, set the layer, color, line type, and line // width as below. You may use any properties of // your choice and, in fact, you will probably make // frequent changes to the properties as you add and // modify entities. vcadd.SetLayerIndex(0); vcadd.SetColorIndex(0); vcadd.SetLineTypeIndex(0); vcadd.SetLineWidthIndex(1); // Visual CADD has a default tool, a tool which runs // when Visual CADD starts and anytime any other // tool ends. Set the default tool to Single Line // (command ID 2102). This sample allows the user // to draw lines in the drawing by simply clicking // the mouse on the drawing window because the // the default Single Line tool is always running. // Set a default tool appropriate for your own // application. vcadd.SetDefaultTool(2102); // Visual CADD supports several features which can // constrain mouse movement, such as ortho mode, // running snaps, and grid snaps. This sample wants // to allow the user to draw unconstrained single // lines so these constraints are turned off. The // following illustrates 3 ways to set various // Visual CADD toggles: direct API calls for the // setting (ortho), API toggles of a command ID // (2770 is running snaps), and native command // scripts (grid snap). // direct call to VCSetOrthoMode vcadd.SetOrthoMode(0); // '0' parameter means to get the toggle state for // command ID 2770 (running snaps) if (vcadd.GetToggleState(2770, 0) == 1) { // toggle state is true (1), so use '1' parameter // to toggle the state, in this case going from // true to false vcadd.GetToggleState(2770, 1); } // SnapGrid is a native command vcadd.Macro("SnapGrid;0;"); // Besides normal Windows messages, Visual CADD is // also able to send other alerts or events to your // EXE. This sample will use the Rotate tool and // its corresponding ribalog to rotate the drawing. // When done, the sample will want to redraw the // screen so it is requesting an alert event for // dialogs closing. In this sample the Rotate // ribalog will close when the Rotate tool is done. vcadd.SetAlertEvent(VCConstants.ALERT_APP_NONE, VCConstants.ALERT_APP_EX_DIALOG_CLOSE_MESSAGE); vcadd.DialogClose += vcadd_DialogClose; // VCAbort will stop any running tool and restart // the default tool, Single Line. The status bar // normally updates after tool actions, of which // the last action was the SnapGrid above. So // force the status bar to update. And draw the // new empty drawing to clear the screen. vcadd.Abort(); vcadd.UpdateStatusBar(); vcadd.PaintWorld(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // when the app is done, disconnect the alert events // and its handlers vcadd.ClearAlertEvent(); vcadd.DialogClose -= vcadd_DialogClose; // Terminate the dialogs and DLL engine. These // calls will release the AutomationEngine object // from the app when it closes. vcadd.TerminateDialogs(); vcadd.Terminate(); } private void button1_Click(object sender, EventArgs e) { // button does Zoom All and redraws the screen vcadd.ZoomAll(); vcadd.PaintWorld(); } private void button2_Click(object sender, EventArgs e) { // button selects all entities and starts the // Rotate tool vcadd.SelectAll(); vcadd.RotateSelected(); } private void button3_Click(object sender, EventArgs e) { // button clears the existing drawing and redraws // the screen vcadd.ClearDrawingNoPrompt(iWorld); vcadd.PaintWorld(); } void vcadd_DialogClose(int wParam, int lParam) { // the alert handler that a dialog has closed, so // redraw the screen vcadd.PaintWorld(); } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { // The handler for the Windows message WM_LBUTTONDOWN // sends the mouse-click to Visual CADD using // VCLButtonDown2 and uses window coordinates. // There are alternatives for sending mouse-clicks // using real world coordinates in inches. Visual // CADD applies the mouse clicks to the running // tools for their designed operation, say drawing // lines or rotating a selection. vcadd.LButtonDown2((Int16)e.X, (Int16)e.Y); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { // The handler for the Windows message WM_MOUSEMOVE // sends the mouse-move to Visual CADD using // VCMouseMove2 and uses window coordinates. // There are alternatives for sending mouse-moves // using real world coordinates in inches. Visual // CADD applies the mouse moves to the running // tools for their designed operation, say drawing // rubber-bands. vcadd.MouseMove2((Int16)e.X, (Int16)e.Y); } } }
Public Class Form1 ' Stand-alone EXEs use the DLL engine, not the Visual ' CADD EXE interface. So use AutomationEngine. Dim vcadd As New VCadd32.AutomationEngine() ' create an index to hold the Visual CADD world Dim iWorld As Integer Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Initialize the DLL engine and databases. These ' calls initialize internal data and load user ' settings such as system and default drawing ' settings. If your EXE will use any Visual CADD ' dialogs, then also initialize the dialogs. vcadd.Init() vcadd.InitDialogs() ' Set windows handles. Visual CADD uses these ' Windows handles for messaging between your EXE ' and the DLL engine. The hWnd Frame is the main ' frame of your EXE where your main messaging loop ' exists. The Dialog Frame is the window used as ' the parent to Visual CADD dialogs, such as tool ' ribalogs, and is usually the same frame as the ' main frame. The MDI Child is the window which ' will hold and display drawings. This sample uses ' a picture box for the drawings. vcadd.SethWndFrame(Me.Handle.ToInt32()) vcadd.SetDialogFrameHwnd(Me.Handle.ToInt32()) vcadd.SethWndMdiClient(Me.PictureBox1.Handle.ToInt32()) ' Visual CADD has status bar messaging to give the ' user various information about the current tool ' operations. Visual CADD displays these in the ' status bar of its own interface. This sample ' uses text boxes for the messages. vcadd.SetMessageHandle(Me.TextBox1.Handle.ToInt32()) vcadd.SetDistanceHandle(Me.TextBox2.Handle.ToInt32()) vcadd.SetXYHandle(Me.TextBox3.Handle.ToInt32()) ' Create a Visual CADD drawing, also called a world. ' The drawing world is created and attached to the ' picture box. Visual CADD supports multiple ' drawing worlds, but only acts on one drawing at a ' time, called the current world. Set the current ' world to the one just created. iWorld = vcadd.NewWorld(Me.PictureBox1.Handle.ToInt32()) vcadd.SetCurrWorld(iWorld) ' Visual CADD can change the user interface colors. ' For consistency in the sample, set the background ' to white (index 15) and the cursor to black ' (index 0). You may use any Visual CADD colors of ' your choice. vcadd.SetBackgroundColor(15) vcadd.SetCursorColor(0) ' Visual CADD places new entities in a drawing ' using current properties. For consistency in the ' sample, set the layer, color, line type, and line ' width as below. You may use any properties of ' your choice and, in fact, you will probably make ' frequent changes to the properties as you add and ' modify entities. vcadd.SetLayerIndex(0) vcadd.SetColorIndex(0) vcadd.SetLineTypeIndex(0) vcadd.SetLineWidthIndex(1) ' Visual CADD has a default tool, a tool which runs ' when Visual CADD starts and anytime any other ' tool ends. Set the default tool to Single Line ' (command ID 2102). This sample allows the user ' to draw lines in the drawing by simply clicking ' the mouse on the drawing window because the ' the default Single Line tool is always running. ' Set a default tool appropriate for your own ' application. vcadd.SetDefaultTool(2102) ' Visual CADD supports several features which can ' constrain mouse movement, such as ortho mode, ' running snaps, and grid snaps. This sample wants ' to allow the user to draw unconstrained single ' lines so these constraints are turned off. The ' following illustrates 3 ways to set various ' Visual CADD toggles: direct API calls for the ' setting (ortho), API toggles of a command ID ' (2770 is running snaps), and native command ' scripts (grid snap). ' direct call to VCSetOrthoMode vcadd.SetOrthoMode(0) ' '0' parameter means to get the toggle state for ' command ID 2770 (running snaps) If (vcadd.GetToggleState(2770, 0) = 1) Then ' toggle state is true (1), so use '1' parameter ' to toggle the state, in this case going from ' true to false vcadd.GetToggleState(2770, 1) End If ' SnapGrid is a native command vcadd.Macro("SnapGrid;0;") ' Besides normal Windows messages, Visual CADD is ' also able to send other alerts or events to your ' EXE. This sample will use the Rotate tool and ' its corresponding ribalog to rotate the drawing. ' When done, the sample will want to redraw the ' screen so it is requesting an alert event for ' dialogs closing. In this sample the Rotate ' ribalog will close when the Rotate tool is done. vcadd.SetAlertEvent(ALERT_APP_NONE, ALERT_APP_EX_DIALOG_CLOSE_MESSAGE) AddHandler vcadd.DialogClose, AddressOf vcadd_DialogClose ' VCAbort will stop any running tool and restart ' the default tool, Single Line. The status bar ' normally updates after tool actions, of which ' the last action was the SnapGrid above. So ' force the status bar to update. And draw the ' new empty drawing to clear the screen. vcadd.Abort() vcadd.UpdateStatusBar() vcadd.PaintWorld() End Sub Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing ' when the app is done, disconnect the alert events ' and its handlers vcadd.ClearAlertEvent() RemoveHandler vcadd.DialogClose, AddressOf vcadd_DialogClose ' Terminate the dialogs and DLL engine. These ' calls will release the AutomationEngine object ' from the app when it closes. vcadd.TerminateDialogs() vcadd.Terminate() End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ' button does Zoom All and redraws the screen vcadd.ZoomAll() vcadd.PaintWorld() End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click ' button selects all entities and starts the ' Rotate tool vcadd.SelectAll() vcadd.RotateSelected() End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click ' button clears the existing drawing and redraws ' the screen vcadd.ClearDrawingNoPrompt(iWorld) vcadd.PaintWorld() End Sub Private Sub vcadd_DialogClose(wParam As Integer, lParam As Integer) ' the alert handler that a dialog has closed, so ' redraw the screen vcadd.PaintWorld() End Sub Private Sub PictureBox1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown ' The handler for the Windows message WM_LBUTTONDOWN ' sends the mouse-click to Visual CADD using ' VCLButtonDown2 and uses window coordinates. ' There are alternatives for sending mouse-clicks ' using real world coordinates in inches. Visual ' CADD applies the mouse clicks to the running ' tools for their designed operation, say drawing ' lines or rotating a selection. vcadd.LButtonDown2(e.X, e.Y) End Sub Private Sub PictureBox1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove ' The handler for the Windows message WM_MOUSEMOVE ' sends the mouse-move to Visual CADD using ' VCMouseMove2 and uses window coordinates. ' There are alternatives for sending mouse-moves ' using real world coordinates in inches. Visual ' CADD applies the mouse moves to the running ' tools for their designed operation, say drawing ' rubber-bands. vcadd.MouseMove2(e.X, e.Y) End Sub End Class
VCInit, VCInitDialogs, VCSethWndFrame, VCSetDialogFrameHwnd, VCSethWndMdiClient, VCSetMessageHandle, VCSetDistanceHandle, VCSetXYHandle, VCNewWorld, VCSetCurrWorld, VCSetBackgroundColor, VCSetCursorColor, VCSetLayerIndex, VCSetColorIndex, VCSetLineTypeIndex, VCSetLineWidthIndex, VCSetDefaultTool, VCSetOrthoMode, VCGetToggleState, VCMacro, SetAlertEvent, VCAbort, VCUpdateStatusBar, VCPaintWorld, ClearAlertEvent, VCTerminateDialogs, VCTerminate, VCZoomAll, VCSelectAll, VCRotateSelected, VCClearDrawingNoPrompt, VCLButtonDown2, VCMouseMove2