DG Kernel Documentation


Skip Navigation Links.
Start page
Quick Start
Search Page
Installation
Overview of the software
What is new
Licensing
Collapse ModelsModels
Collapse DG Kernel ComponentsDG Kernel Components
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 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 2013.

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 Projects tab select MFC AppWizard(exe). Enter "Patch" in the Project Name edit box on the right. Select location for the project folder. Turn on "Create directory for solution" and click OK.
  • In Step 1 of the application wizard select "Dialog based" and click "Next". In the step 2 clear "About box" and press "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.
  • 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 stdafx.h

Step 2. Inserting the DG Kernel component

  • Right-click on the dialogue and select Insert ActiveX Control. In the opened list select DG Kernel Control. Adjust size of the appeared control to approximately 300 x 240.
  • Right-click on the control and select Properties. Set ShowGlobalAxes property to true.
  • Right-click on the control and select "Add Variable". Type m_kernCAD in the Variable name box and click Finish.
    Notice the new kernelcad1.cpp and kernelcad1.h files added to the project and CKernelCAD1 class appeared in the Class View. Opening the CKernelCAD1 node in the Class View will display available methods and properties of the control.
  • Close the resource editor.
  • We need to add convenient shortcuts for smart pointers to the default declaration. Double-click GetModel() function of CKernelCAD1 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_kernCAD.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_kernCAD.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_kernCAD.GetModelDG();
    IStdShapeRef_DGPtr iStdShapeRef = iModel;
    IEntity_DG* iEntity = (IEntity_DG*)m_iEntity;
    iStdShapeRef->Cylinder(m_baseRadius, m_topRadius, m_height, &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.