DG Kernel (ActiveX) Documentation


Skip Navigation Links.
Start page
Quick Start
Search Page
Installation
What is new
Upgrading Native Apps
Licensing
Collapse ModelsModels
Collapse DG Kernel ControlsDG Kernel Controls
Collapse API ReferenceAPI Reference
Interface List
Vector Space
Collapse General GeometryGeneral Geometry
Collapse ModelModel
Collapse ViewView
Collapse General ComputingGeneral Computing
Collapse Samples and TutorialsSamples and Tutorials
Collapse GraphicsGraphics
Collapse Math ObjectsMath Objects
Collapse DeprecatedDeprecated
Redistribution
Model Viewer
Open Source
Support
Skip Navigation Links Go to DGKC docs Search Documentation


Patch Delphi Sample

Patch Tutorial demonstrates incorporation of DG Kernel control into a simple Windows Form application using Embarcadero Delphi/RAD Studio.  Source code for Patch sample is available in Samples\Delphi\Patch\ folder of the installation directory.

See also: Sample List

This tutorial assumes basic familiarity with Delphi. It is based on Delphi 10.3.

The Application

Patch application creates a new truncated cone and allows modification of its parameters.

Step 1. Creating the project

  • Open Delphi. Select File > New > Windows VCL Application in the menu.
  • Select File > Save All, select folder for project, save Unit1.pas as PatchUnit.pas.
    Save Project1.dproj as Patch.dproj
  • In the form editor select Form1 and set name to PatchForm. Save all.

Step 2. Inserting the DG Kernel control

  • In the IDE find Pallete, expand ActiveX branch and find TKernelCAD.
  • Drag TKernelCAD to the main form
  • Change component's size if needed
  • Rename component form KernelCAD1 to m_kernCAD
  • Save all
  • Right-click on the control and select Properties. The form shows properties of the control. The properties can also be accessed via the Object Inspector of Delphi IDE. The main one, ModelPath, can point to an .mdg model file or a file in any other supported format. We will leave it empty as our entity will be created at runtime.

Step 3. Creating the Entity 

  • To create handler for the OnShow event of the form, in design mode, click on the form outside the control. Click Events tab on the top of Object Inspector pane. Select OnShow row in the list and double-click the row on the right. A new FormShow() procedure will be added to the TPatchForm class.
  • Next we will get access to IModel_DG  interface implemented by the control. Add to FormShow() the next line (without the (A) annotation):

    iMdl := m_kernCAD.GetModel() as IModel_DG;            (A)

  • Add the following private declarations to the TPatchForm class:

    m_iEntity: IEntity_DG;
    m_baseRadius: double;
    m_topRadius: double;
    m_height: double;

  • Initialise the parameters in TPatchForm constructor as:

    m_baseRadius := 10;
    m_topRadius := 5;
    m_height := 20;

  • Add the following three lines just below the line (A):

    iStdShp := iMdl as IStdShape_DG;
    iStdShp.Cylinder(m_baseRadius, m_topRadius, m_height, m_iEntity);
    iMdl.AddEntity(m_iEntity);

    The first line obtains an interface for creation of basic shapes. The second line creates a cylindrical object and stores its reference in m_iEntity. The third line adds the entity to the model to be displayed in the 3D view.

  • Add the following two lines at the end of FormShow():

    iVw := m_kernCAD.GetView() as IView_DG;
    iVw.Reset(true, true);

    The first line accesses IView_DG, which is the root of the view-related functionality and the second line refits the view to include the new object.

Step 4. Implementing Modifications of the Object.

  • Add three edit boxes for the parameters and an Apply button to the form. Please make sure the text in edit boxes coincides with the initial values.
  • In OnClick handler of the Apply button, add: 

    m_baseRadius := double.Parse(Edit1.Text);
    m_topRadius := double.Parse(Edit2.Text);
    m_height := double.Parse(Edit3.Text);

    iMdl := m_kernCAD.GetModel() as IModel_DG;
    iStdShapeRef := iMdl as IStdShapeRef_DG;
    iStdShapeRef.Cylinder(m_baseRadius, m_topRadius, m_height, m_iEntity);

    m_kernCAD.UpdateView();

    Notice the different version of interface used. IStdShapeRef_DG is designed for modification (and creation) rather than creation only. The last line redraws the window.

  • Run the application and test modifications of the entity.