DGKC Control Documentation


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


Patch Visual Basic Tutorial

Patch Tutorial demonstrates incorporation of DGKCn6 DG Kernel Control into a simple Windows Form application using Microsoft Visual Studio.  Source code for Patch sample is available in Samples\NET\VB\Patch\ folder of the installation directory.

See also: Sample List

This tutorial assumes basic familiarity with Visual Studio. It is based on Visual Studio 2022.

The Application

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

Step 1. Creating the project

  • Open Visual Studio. Select File > New > Project in the menu. In the "Create a new project" make sure Visual Basic, Windows and Desktop are current at the top. Select "Windows Forms App" project type. Click Next. Enter "Patch" for the project name. Select location and make sure .NET framework 6.0 is selected. Click Create.
  • In Solution Explorer select the Form1.vb created by default and rename it (using context menu on right-mouse click) to Patch.vb. Accept the suggestion to rename related elements when asked.

Step 2. Inserting the DG Kernel control

  • In the Project menu of Visual Studio select "Manage NuGet Packages".
  • In the package source combo at the top right corner select nuget.org
  • Open Browse tab and in the search box type DGKCn6. This should display a single item.
  • Select the item and click Install in the right-hand panel.
  • Click Apply in the displayed dialogue. Close the NuGet manager.
  • Double-click the Patch.vb node in the Solution Explorer to open the form in Designer.
  • Open Patch form in design mode and adjust size of the form to 890, 532 by pasting or typing the pair in Size property of the Properties Window (View > "Properties Window"). Change the Text property to "Patch".
  • Expand Toolbox. It should have DGKCn6 group with DGKCn6 (DGKC) item under it. Close and reopen toolbox few times if you do not see it.
  • Click the item and place it on the form. Save All. Close the form designer.
  • Open Class View. A new member of type DGKCn6 called dgkCn61 will be added to the Patch class.
  • Open the form. Select the control and change its size to 698, 482 using Properties Window.
  • Right-click on the control and select Properties. The form shows properties of the control. The properties can also be accessed via the Properties Window of Visual Studio. 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 in the code.
  • Open the Object Browser (View > Object Browser menu option). Expand DGKCn6 and its child node. This node displays all necessary information about types, interfaces and their methods available in the component.

Step 3. Creating the Entity 

  • To create a handler for the Load event of the form, in design mode, click on the form outside the control. Click the Events icon on the top of Properties Window. Select the Load row in the list and double-click the row on the right. A new Patch_Load() method will be added to the Patch class.
  • Add line:

    Imports DGKC

    at the top of the Patch.vb
  • Next we will get access to the IModel_DG  interface implemented by the control. Add to Patch_Load() the next line (without the (A) annotation):

    Dim iModel As IModel_DG = dgkCn61.GetModel()           (A)

  • Add the following declarations to the Patch class:

    Dim m_iEntity As IEntity_DG
    Dim m_baseRadius As Double
    Dim m_topRadius As Double
    Dim m_height As Double

  • Initialise the parameters in New() Patch constructor or on start of  Patch_Load() as:

    m_baseRadius = 10
    m_topRadius = 5
    m_height = 10

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

    Dim iStdShape As IStdShape_DG = iModel.Query(Of IStdShape_DG)()
    m_iEntity = iStdShape.Cylinder(m_baseRadius, m_topRadius, m_height)
    iModel.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 Patch_Load():

    Dim iView As IView_DG = dgkCn61.GetView()
    iView.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. The controls can be copied in design mode from the installed completed version of the sample
  • Rename the edit boxes to: editBaseRad, editTopRad, editHeight.
  • At the end of Patch constructor add the following to populate the edit boxes with default values:
  • editBaseRad.Text = m_baseRadius.ToString()
    editTopRad.Text = m_topRadius.ToString()
    editHeight.Text = m_height.ToString()
  • In the handler of the Apply button, add: 

    m_baseRadius = Double.Parse(editBaseRad.Text)
    m_topRadius = Double.Parse(editTopRad.Text)
    m_height = Double.Parse(editHeight.Text)

    Dim iModel As IModel_DG = Dgkc1.GetModel()
    Dim iStdShapeRef As IStdShapeRef_DG = iModel.Query(Of IStdShapeRef_DG)()
    iStdShapeRef.Cylinder(m_baseRadius, m_topRadius, m_height, m_iEntity)

    Dgkc1.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.