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 ViewsViews
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 C++ Tutorial

Patch Tutorial demonstrates incorporation of DG Kernel control into a simple MFC application using Microsoft Visual Studio.  Source code for Patch tutorial is available in Samples\VC\Patch folder of the installation directory.

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

See also: Sample List

Running 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 C++, Windows, Desktop are current on top. Select MFC App C++. Click Next. Enter "Patch" in the Project Name edit box on the right. Select location for the project folder and clear the "Place solution and project in the same directory". Click Create.
  • In the next step "MFC Application" select Application type "Dialog based" and click "Next". Click "Finish" to accept defaults for all other settings. The project will be created and the main dialogue will be opened in resource editor. 
  • Delete "TODO.." label in the center of the dialogue. Adjust size of the dialogue to approximately 400x250 (the size is displayed at the bottom in the right-hand pane of the status bar). Move "OK" and "Cancel" buttons to the bottom right-hand corner of the dialogue.
  • Open the Project Properties and in the Adanced tab change Character Set to "Use Multi-Byte Character Set"
  • Copy Include and Src folders from Samples\VC\ of the DG Kernel installation directory to the Patch solution folder (the top Patch folder) and add
    #include "..\Include\DIKernCAD.h"
    line at the end of pch.h just before the #endif //PCH_H line

Step 2. Inserting the DG Kernel control

  • Make sure that the current configuration is x86. Other configuration types can be added later.
  • Right-click on the dialogue and select Insert ActiveX Control. In the opened list select KernelCAD Control. Adjust size of the appeared control to approximately 300 x 240.
  • Right-click on the control and select "Add Variable". Type m_DGKern in the Variable name box. Enter CKernelCAD as the Variable type. Click Next. Change both .h and .cpp file names to kernelcad and click Finish.
  • Save All and close the resource editor.
  • Notice the new kernelcad.cpp and kernelcad.h files added to the project and CKernelCAD class appeared in the Class View. Opening the CKernelCAD node in the Class View will display available methods and properties of the control.
  • At the time of release Visual Studio 2019 was generating incorrect kernelcad.h file. If you get a compile error,  please copy the file from DGKernel_7_2\Samples\VC\Patch\ folder of the installation directory and skip the next step. Alternatively, replace LPUNKNOWN in GetModel() and GetView() with VT_UNKNOWN.
  • We need to add convenient shortcuts for smart pointers to the default declaration. Double-click GetModel() function of CKernelCAD in the class view and add the following text just below it:

    IModel_DGPtr GetModelDG()
    {
         LPUNKNOWN iUnkn = GetModel();
         IModel_DGPtr iModel(iUnkn);
         iUnkn->Release();
         return iModel;
    }

    Also add

    IView_DGPtr GetViewDG()
    {
        LPUNKNOWN iUnkn = GetView();
        IView_DGPtr iView(iUnkn);
        iUnkn->Release();
        return iView;
    }
    below the GetView()

  • For x64 application: Open Build > Configuration manager in Visual Studio menu. In the Active Solution Platform select New. Select x64 in the platform list. This is a required step, as DG Kernel is a native control. It has to be done in this sequence, after insertion of the control.

Step 3. Creating the Entity 

  • Next we will get access to IModel_DG  interface implemented by the control. Double-click OnInitDialog() node under CPatchDlg in the Class View. Replace "// TODO:" line with the next line (without the (A) annotation):

    IModel_DGPtr iModel = m_DGKern.GetModelDG();            (A)

  • Add the following declarations to the Patch class:

    IEntity_DGPtr m_iEntity = nullptr;
    double m_baseRadius = 10;
    double m_topRadius = 5;
    double m_height = 20;

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

    IStdShape_DGPtr iStdShape = iModel;
    iStdShape->Cylinder(m_baseRadius, m_topRadius, m_height, &m_iEntity);
    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 line at the end of CPatchDlg::OnInitDialog():

    m_DGKern.GetViewDG()->Reset(VARIANT_TRUE, VARIANT_TRUE);

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

Step 4. Implementing Modifications of the Object.

  • Add three text boxes for the parameters and an Apply button to the form.

    Link the text boxed to the parameters by adding
    DDX_Text(pDX, IDC_EDIT_BASE_RAD, m_baseRadius);
    DDX_Text(pDX, IDC_EDIT_TOP_RAD, m_topRadius);
    DDX_Text(pDX, IDC_EDIT_HEIGHT, m_height);
    at the end of CPatchDlg::DoDataExchange()

  • In handler of the Apply button, add: 

    UpdateData();
    IModel_DGPtr iModel = m_DGKern.GetModelDG();
    IStdShapeRef_DGPtr iStdShapeRef = iModel;
    IEntity_DG* iEntity = (IEntity_DG*)m_iEntity;
    iStdShapeRef->Cylinder(m_baseRadius, m_topRadius, m_height, &iEntity);

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