DG Kernel Documentation


Skip Navigation Links.
Start page
Quick Start
Search Page
Installation
Overview of the software
What is new
Licensing
Collapse ModelsModels
Models
Persistence
Collapse EntitiesEntities
Collapse GeometryGeometry
Geometry
Collapse BSpline BRepBSpline BRep
BSpline BRep Overview
BSpline Geometry
Curves
Faces
Wires
Edges
Collapse MeshMesh
Mesh Geometry
Mesh
Line Strips
Point Sets
Collapse Entity AttributesEntity Attributes
Local Frame
Material
Texture
Clipping Planes
Properties of an Entity
3D Grid
Collapse Model ItemsModel Items
Items
View Points
Collapse MeasurementsMeasurements
Measurements
Persistent Measurements
Grid
Collapse Operations and AlgorithmsOperations and Algorithms
Boolean Operations
Euclidean Shortest Path
Collapse MovementMovement
Movements
Kinematic Sections
Collision Detection
Collapse Import/ExportImport/Export
Import/Export Overview
Data Flow Sample
STL Tree
Collapse DG Kernel ComponentsDG Kernel Components
Components
DG Kernel Control
Collapse Properies, Methods, EventsProperies, Methods, Events
Properies
Methods
Events
Collapse Interactive FunctionalityInteractive Functionality
Context Menu
Direct User Access
Modes of DG Kernel
Current Entities
Collapse View of DGK ControlView of DGK Control
Global Axes
Background
3D Background
Collapse Selection OverviewSelection Overview
Selection
Selection Event
Collapse Auxiliary ViewsAuxiliary Views
Model Explorer
Birds Eye View
Full Screen window
Collapse Programmatic FunctionalityProgrammatic Functionality
Programming
Porting V5 Apps to DGK
Queries
Data Types
Object Construction
Generator
Component Context
Model Properties
Initialisation Context
Collapse AdvancedAdvanced
64 Bit Development
Memory Management
Third Party Technologies
Collapse API ReferenceAPI Reference
Interface List
Vector Space
Collapse General GeometryGeneral Geometry
IPointArray_DG
IPointMatrix_DG
Collapse CurvesCurves
ICurve2d_DG
ICircle2d_DG
ICurve_DG
ICircle_DG
IKCLine
IBSplineCurve_DG
IBSplineCurveInterpolator_DG
ICurveFreeForm
ICurveFreeFormEx
IArcSpline3DCurve
Collapse 2D2D
ILine2D
IArc
IArcEx
IEllipse_KC
IStripArcLine_KC
Collapse Oriented ObjectsOriented Objects
IObjectOriented
ISphere_DG
ICone_DG
ITorus_DG
IBox_DG
IPolygon3D_DG
IPrizmInfinite_KC
ICylindricalSurface_DG
IUVSurface_DG
IPartialSplineProps_DG
IBSplineSurface_DG
ISurface
IRectangleAxisAligned_KC
Collapse GeneralGeneral
IStrip
IStripTopol
IElem
IElement
ILocation
ILocationEx
Collapse ModelModel
IModel_DG
Collapse EntitiesEntities
IEntity_DG
IEntityArray_DG
IStdShape_DG
IStdShapeRef_DG
IDraw_DG
IConstraint
Collapse GeometryGeometry
IGeometry_DG
ISurfacePoint_DG
ISurfaceMetric_KC
Collapse BSpline BRep GeometryBSpline BRep Geometry
Collapse Advanced AlgorithmsAdvanced Algorithms
IBRepChamfer_DG
IBRepDraftAngle_DG
IBRepFillet_DG
IFeaturePrism_DG
IBRepShape_DG
IBRepVertex_DG
IBRepEdge_DG
IBRepWire_DG
IBRepFace_DG
IBRepShell_DG
IBRepSolid_DG
IBRepCompositeSolid_DG
IBRepCompound_DG
IShapeArray_DG
IBRepBuilderEx_DG
IWireArrayToSurfaceBuilder_DG
IBRepGeometry_DG
IBRepBuilder_DG
Collapse Native OCCTNative OCCT
IIKO_Standard_Object
IKO_Model
IKO_TopExp_Explorer
BRep
BRepBuilderAPI
BRepExtrema
BRepOffsetAPI
BRepPrimAPI
Geom2d
GeomAPI
GP
ModModeling Algorithms
TColgp
TColStd
TopoDS
TopTools
Collapse Mesh GeometryMesh Geometry
IMesh
IMeshTopol
ISimplex
IMeshMods
IVertex
IMeshEx
IMeshPointKC
IVertexEx_KC
IEdge_KC
ISimplexEx_KC
IMeshAlgor
IMeshBuilder_KC
IMeshShading_KC
Collapse AppearenceAppearence
IAppearance_DG
IColor
IMaterial
ITexture
ILineStyle_KC
Collapse MovementMovement
Collapse Collision DetectionCollision Detection
IMetrics
IMetrics2
IKCPathCollisionDetector
IKinematicSection_KC
IMove_KC
IKinematicSet_KC
ICutEffect_KC
ISpinEffect_KC
Collapse ItemsItems
IModelItem_DG
IItemArray_DG
Collapse Import / ExportImport / Export
ICADFormat_KC
IDataContext
IFormatVersionDataContext
ISTLDataContext
IDataConvert_KC
Collapse Operations and AgorithmsOperations and Agorithms
IBooleanEntity_DG
IBoolSectionEx
ITransform
IDiffSurface_KC
IEuclideanShortestPath_KC
Collapse User DataUser Data
ILayers
IUserData_DG
IMatrixData
Collapse ViewView
IView_DG
ISelection_DG
IViewPoint
IViewPointArray
IScene_DG
IRectangleColor_KC
I2DView_KC
I2DView2_KC
I2DEditor_KC
IPrint_KC
IVirtualView
ILightSource
I3DGrid
Collapse General ComputingGeneral Computing
IObjectGenerator_DG
IControlInitialisationContext_KC
Collections
IUnknown
IObject_DG
ITypeBasic_KC
IBitmap
IBlob
IKCContext
IKCContext2
IError_KC
IKCStack
IMenu_KC
IMenuItem_KC
IGlobalAPI_KC
IRange
ITechnology_DG
IText
IDIFont
I3DBugger
Collapse Embedded User DBEmbedded User DB
IData
Collapse Samples and TutorialsSamples and Tutorials
Sample List
.NET Samples
Delphi and C++ Samples
Collapse GraphicsGraphics
Concepts
3D View
Viewing Volume
Eye Frame
Perspective View
Collapse Math ObjectsMath Objects
Mathematical Objects
Points and Vectors
Planes
Frames
Transforms
Oriented Objects
Boxes
Collapse CurvesCurves
Curve Technologies
Native Curves
Collapse 2D Elements2D Elements
Geometric Elements
Arcs
Line Strips
Collapse DeprecatedDeprecated
Collapse Deprecated GeometryDeprecated Geometry
Collapse 3DS3DS
3DS Generator
Profiles
Surface Patches
Surfaces and Patch Strips
Input Validation
Collapse Lines and CurvesLines and Curves
Line Section
3DS Curves
Surface Of Revolution
Pipes
Collapse Deprecated API ReferenceDeprecated API Reference
Vector Space
General Geometry
Collapse ModelModel
IModel
IModel2
IModelEx
IModelSearch_KC
Collapse SectionSection
IBoundary
IStdShape
ISurfacePointKC
ISurfacePointArrayKC
IBoolSection
ISection
ISection2
ISectionPointSet
ISectionLineStrip
IPipeSection
ILineSection_KC
IObjectPosition_KC
IModelHealer_KC
IPointCloud_KC
Collapse 3DS3DS
I3DSectionGenerator
IAxiBase
IProfiles
IProfiledElement_KC
Collapse SORSOR
ISORSectionGenerator
Clipping Planes
IDraw
IDrawUtil
IDraw2
View
Collapse General ComputingGeneral Computing
IDIObjGenerator
IObject_KC
Collapse CollectionsCollections
IArray
IArray2
IList
IListUnkn_KC
IRelation
IArrayNum
IArray3D
IRefMap_KC
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 Windows Form application using Microsoft Visual Studio.  Source code for Patch sample is available in Samples\NET\CS\Patch\ folder of the installation directory.

See also: Sample List

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

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 types window select "Visual C# Projects". Make sure that "Windows Forms Application" is selected in the right-hand pane. Enter "Patch" in the Name edit box. Select location for the project folder and click OK.
  • In Solution Explorer select the Form1.cs created by default and rename it (using context menu on right-mouse click) to Patch.cs. Accept the suggestion to rename related elements when asked.

Step 2. Inserting the DG Kernel control

  • In the menu select Project > "Add Reference...".
  • In the dialog open COM tab and select "KernelCAD .NET Pro ActiveX Control". Press OK. If the control was already used in Visual Studio this step is not required and the OK button will be disabled.
  • 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 also Text property to "Patch".
  • In Toolbox panel (View > Toolbox) open Components tab, select "KernCADnet Control", press Esc key to hide the toolbox and place the control on the left in the form. Save All. A new member of type AxKernCADnet.AxKernCADnet called axKernCADnet1 will be added to the Patch class. Close the from designer
  • Open Build > Configuration manager in Visual Studio menu. In the Active Solution Platform select New. Select either x64 or x86 depending on bitness of the installed DG Kernel. 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.
  • Open Class View and rename (context menu) ext menu) axKernCADnet1 field of the Patch class to m_kernCAD.
  • Open the form. Select the control and change its size to 698, 482 using Properties Window. On rare occasions control may throw an exception at this point. Please save all then, close the solution and restart Visual Studio. Generally, it is recommended to close the form designer as soon as possible.
  • 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 Interop.KernCADnet 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 handler for the Load event of the form, in design mode, click on the form outside the control. Click Events icon on the top of Properties Window. Select 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:

    using KernCADnet;

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

    IModel_DG iModel = m_kernCAD.GetModel() as IModel_DG;            (A)

  • Add the folliwing declarations to the Patch class:

    public IEntity_DG m_iEntity;
    public double m_baseRadius;
    public double m_topRadius;
    public double m_height;

  • Initialise the parameters in Patch constructor as:

    m_baseRadius = 10;
    m_topRadius = 5;
    m_height = 10;

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

    IStdShape_DG iStdShape = iModel as 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():

    IView_DG iView = m_kernCAD.GetView() as IView_DG;
    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. Please make sure the text in edit boxes coincides with the initial values. The controls can be copied in design mode from the installed completed version of the sample
  • In handler of the Apply button, add: 

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

    IModel_DG iModel = m_kernCAD.GetModel() as IModel_DG;
    IStdShapeRef_DG iStdShapeRef = iModel as IStdShapeRef_DG;
    iStdShapeRef.Cylinder(m_baseRadius, m_topRadius, m_height, ref 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.