KernelCAD Documentation

DInsight Home
Skip Navigation Links.
Start page
Quick Start
Installation
Overview of the software
What is new
Collapse KernelCAD ModelsKernelCAD Models
Model Structure
Securing Models
Collapse Import/ExportImport/Export
Import and Export
Collapse Adanced Data ExchangeAdanced Data Exchange
Data Flow Sample
STL Tree
IDataContext Interface
ISTLDataContext Interface
Collapse Scene ItemsScene Items
Items
3D Text
Smart Labels
View Points
Collapse MeasurementsMeasurements
Measurements
Persistent Measurements
Grid
Collapse SectionsSections
Sections
Section Types
Collapse 2D2D
Overlays
2D Models
2D Items
Point Sets
Collapse Line and Curve SectionsLine and Curve Sections
Line Strips
Line Section
3DS Curves
Collapse Surface and Solid SectionsSurface and Solid Sections
Surfaces
Collapse Mesh SectionsMesh Sections
Mesh Section
Mesh
Surface Of Revolution
BRep 3D Objects
Collapse BRep BSpline objectsBRep BSpline objects
Bspline objects
BSpline Faces
BRep Section
Pipes
Collapse 3DS Sections3DS Sections
3D Section
Profiles
Surface Patches
Surfaces and Patch Strips
Collapse AttributesAttributes
Material
Clipping Planes
Symmetries (Arrays)
Textures
Collapse OperationsOperations
Boolean Operations
Surface Trim
Cut Surface
Collapse MovementsMovements
Movements
Kinematic Sections
Collision Detection
3D Grid
Collapse Mathematical ObjectsMathematical Objects
Pure Geometric Objects
Points and Vectors
Planes
Collapse CurvesCurves
Straight Lines
3D Circle
Ellipse
Free-Form Curves
Arc Spline Curves
Frames
Transfroms
Oriented Boxes
Collapse 2D Elements2D Elements
Geometric Elements
Arcs
Line Strips
Collapse Basics of 3D GraphicsBasics of 3D Graphics
Concepts
3D View
2D View
Viewing Volume
Birds Eye View
Viewing Plane
Perspective View
Background
Collapse AlgorithmsAlgorithms
Euclidean Shortest Path
Collapse User DataUser Data
Layers
Object User Data
Model User Data
Collapse KernelCAD ComponentsKernelCAD Components
KernelCAD Control
KernelCAD .NET Control
Methods and Properties
Menu
Model Explorer
Birds Eye View
Programming
Direct User Access
Direct Operations
Interface Queries
Printing Support
Data Types
Modes of KernelCAD Control
DIObjectGenerator class
Properties
FlatObjectArray Poperty
Context
64 bit development
Dual Mode
Initialisation Context
Overlay Editor
Memory Management
Input validation
Collapse Advanced functionalityAdvanced functionality
Topological Modifications
Programming commands
Dynamic model restructuring
Dynamic Object Creation
Generator of 3D Sections
Generator of SOR Objects
Model class
Selection
Selection Event
External Models
Collapse InterfacesInterfaces
Alphabetical list
I3DGrid
I3DBugger
I3Dpt
IAxiBase
IAxis
IBoolSection
IBoolSectionEx
IBoundary
IColor
IConstraint
IData
IDiffSurface_KC
IDIFont
IDraw
IDrawUtil
IDraw2
IElem
IElement
IKCLine
ILightSource
ILocation
ILocationEx
IMaterial
IMetrics
IMetrics2
IModel
IModel2
IModelEx
IPatch
IKCPathCollisionDetector
IProfiles
IPropertyArray
IPropertyArray2
IStdShape
IStrip
ISurface
IText
ITexture
ITransform
IUnknown
Collapse Open Cascade TechnologyOpen Cascade Technology
IKO_Standard_Object
IKO_Model
IKO_TopExp_Explorer
Collapse BRepExtremaBRepExtrema
IKO_BRepExtrema_DistShapeShape
Collapse Geom2dGeom2d
IKO_Geom_CylindricalSurface
IKO_Geom_ElementarySurface
IKO_Geom2d_Circle
IKO_Geom2d_Conic
IKO_Geom2d_Curve
IKO_Geom2d_Geometry
IKO_Geom2d_Line
Collapse GeomGeom
IKO_Geom_BSplineCurve
IKO_Geom_BSplineSurface
Collapse GPGP
IKO_gp_Ax1
IKO_gp_Ax2
IKO_gp_Ax22d
IKO_gp_Ax2d
IKO_gp_Ax3
IKO_gp_Circ2d
IKO_gp_GTrsf2d
IKO_gp_Lin2d
IKO_gp_Mat2d
IKO_gp_Object
IKO_gp_Sphere
IKO_gp_Cone
IKO_gp_Torus
IKO_gp_Trsf
IKO_gp_Cylinder
IKO_gp_Pln
IKO_gp_Circ
IKO_gp_Trsf2d
Collapse GeomAPIGeomAPI
IKO_GeomAPI_PointsToBSpline
IKO_GeomAPI_Interpolate
Collapse TColStdTColStd
IKO_TColStd_Array1
IKO_TColStd_Array1OfInteger
Collapse TColgpTColgp
IKO_TColgp_Array1OfPnt
IKO_TColgp_Array1OfVec
Collapse BRepBRep
IKO_BRep_Builder
Collapse BRepBuilderAPIBRepBuilderAPI
IKO_BRep_Builder
IKO_BRepBuilderAPI_MakeWire
IKO_BRepBuilderAPI_MakeEdge
Collapse BRepOffsetAPIBRepOffsetAPI
IKO_BRepOffsetAPI_ThruSections
Collapse BRepPrimAPIBRepPrimAPI
IKO_BRepPrimAPI_MakePrism
Collapse ModModelingAlgorithmsModModelingAlgorithms
IKO_BRepGProp_Face
Collapse TopoDSTopoDS
IKO_TopoDS_Shape
IKO_TopoDS_Edge
IKO_TopoDS_Face
IKO_TopoDS_Wire
Collapse DataData
Collapse Import / ExportImport / Export
IDataConvert_KC
ICADFormat_KC
IDataContext
ISTLDataContext
IFormatVersionDataContext
Collapse User Data User Data
ILayers
IDataSource
IDataTable
IRecordSet
IDataMods
IUserData
IMatrixData
Collapse MovementMovement
IKinematicSection_KC
IMove_KC
IKinematicSet_KC
ICutEffect_KC
ISpinEffect_KC
Collapse FramesFrames
I3DObject
IFrame
IFrame2
IFrame3
IFrameEx
Collapse Oriented ObjectsOriented Objects
IObjectOriented
ISphere_KC
IBox
Collapse SectionsSections
Collapse ItemsItems
IItem
ILabel3D_KC
IDynamicScreenItem_KC
IDynamicScreenItemManager_KC
ISmartLabelManager_KC
ISection
ISection2
ISectionPointSet
ISectionLineStrip
ITextSection_KC
IPipeSection
ILineSection_KC
IObjectPosition_KC
ISticky_KC
ILabelSection_KC
IModelHealer_KC
IPointCloud_KC
IProfiledElement_KC
Collapse Mesh interfacesMesh interfaces
IMesh
IMeshTopol
ISimplex
IMeshMods
IVertex
IMeshEx
IIterator
IMeshPointKC
ISurfacePointKC
ISurfaceMetric_KC
IVertexEx_KC
IEdge_KC
ISimplexEx_KC
IMeshAlgor
IMeshShading_KC
Collapse GeneralGeneral
Collapse Collections InterfacesCollections Interfaces
IArray
IArray2
IList
IListUnkn_KC
IRelation
IArrayNum
IArray3D
IRefMap_KC
IObject_KC
ITypeBasic_KC2
IModelSearch_KC
IBitmap
IBlob
IKCContext
IKCContext2
IError_KC
IKCStack
ILineStyle_KC
IMenu_KC
IMenuItem_KC
IGlobalAPI_KC
IControlInitialisationContext_KC
IRange
IRectangleAxisAligned_KC
Collapse Topological InterfacesTopological Interfaces
IStripTopol
I3DSectionGenerator
ISORSectionGenerator 
IDIObjGenerator
Collapse Viewing InterfacesViewing Interfaces
IView
IView2
IViewPoint
IViewPointArray
ILookAt
IViewModal
ILook
ILookEx
IMeasurement_KC
IPick
ISelection_KC
IRectangleColor_KC
I2DView_KC
I2DView2_KC
I2DEditor_KC
IPrint_KC
IVirtualView
IGraphicItem
Collapse Lines And CurvesLines And Curves
ILine
ILineGeom
ILineMetr
ICurve
ICurveFreeForm
ICurveFreeFormEx
IArcSpline3DCurve
IArc
IArcEx
ICircle3D_KC2
IEllipse_KC
Collapse Symmetry InterfacesSymmetry Interfaces
ISymmetries
ISymmetry
IAxialSymmetry
Collapse Clipping plane interfacesClipping plane interfaces
IClipArray
IClipPlane
Collapse AlgorithmsAlgorithms
IEuclideanShortestPath_KC
Collapse 2D Geometry2D Geometry
ILine2D
IArc
IArcEx
IStripArcLine_KC
Collapse Programming Samples and TutorialsProgramming Samples and Tutorials
Collapse OverviewOverview
Sample List
3DBugger
BoolOp
PlanarOps
Calculator
Capture
Cannon
Clip
Cloud
Collision
Collision Path
Cross View
Data Flow
Data Flow
Deploy Tutorial
DiffSurface
Direct User Access Demo
DIView
eMotion
Euclidean Shortest Path
Gear
Label
LabelEx
Layers
Light
Lines
LowDim
Make Your Move
Measure
Mesh Mods
MeshOps
Metrics
MiniCAD
Modal
Modeling Curves
Morph
Object Array
Overlay
Patch
Patchwork
Pick
Point Of View
BoolOp
Profile
Rotation
Pipes
Layers
Shape Explorer
Smart Labels
Strip Topology
Surface Metrics
Symmetry
Transform
Texture
Turbine
TwoD
User Data
View Point
WpfCAD
Zoom
Collapse DeploymentDeployment
Deploy Tutorial
DeployModule
DeployWixBasic
WixDeploy
Collapse .NET Samples.NET Samples
Collapse C# SamplesC# Samples
Patch Tutorial
MiniCAD Sample
Strip Topology Sample
DI View Sample
Modal View Sample
Modeling Curves
Label
LabelEx
Pick
Object Array
Data Flow
Profile
Cross View
Low Dim
Morph
Clip
BoolOp
Collision
Collision Path
3DBugger
Data Flow
Shape Explorer
Smart Labels
Symmetry Sample
Cannon
View Point Sample
Capture
User Data
Layers
Zoom
Collapse Visual Basic SamplesVisual Basic Samples
Patch Tutorial
DI View Sample
MiniCAD Sample
Object Array Sample
BoolOp
Data Flow
Pipes
Transform
Measure
Mesh Mods
Mesh Ops
Metrics
Morph
TwoD
eMotion
Cross View
3DBugger Tutorial
Collision
Collision Path
Light
Patchwork
Capture
Collapse WPFWPF
Clip
Mesh Ops
Measure
Lines
LowDim
WPF
Patch
Collapse Delphi SamplesDelphi Samples
3DBugger
BoolOp
Calculator
Patch Sample
Modelling Curves
MiniCAD Sample
Morph
Shape Explorer
Object Array
Metrics
Cannon
Pipes
Patchwork
Collision
Collapse C++ SamplesC++ Samples
3DBugger
BoolOp
Cannon
Capture
Cloud
Collision
Collision Path
Cross View
DI View Sample
eMotion
Gear Sample
Label
LabelEx
Light Sample
Measure
Mesh Ops
MiniCAD Sample
Modal Sample
Modeling Curves
Object Array Sample
Overlay Sample
Patch Tutorial
Pick
Point Of View
Planar Ops
Rotation Sample
Profile Sample
Shape Explorer
Smart Labels
Strip Topology Sample
Layers
Lines
LowDim
Metrics
Metrics2
Morph Sample
Patchwork
Pipes
Symmetry Sample
Texture Sample
Transform
TwoD
Turbine Sample
User Data
View Point Sample
Zoom Sample
Collapse Visual Basic SamplesVisual Basic Samples
Patch
DI View
MiniCAD
Data Flow
Cross View
Cloud
Planar Ops
Calculator
Light
Pick
Object Array
Label
Symmetry
Transform
Morph
Line Strip
Capture
Collapse Delphi SamplesDelphi Samples
KernelCAD and Delphi
3DBugger
Data Flow
BoolOp
Calculator
Cannon
Collision
Label
LabelEx
Metrics
MiniCAD
ModelingCurves
Object Array
Patch
Patchwork
Pipes
Collapse 3D Debugger3D Debugger
Creating and editing models
Editing Generic 3D Objects
Topological Commands
Model Explorer
Export / Import
Modeling Tips
3D Debugger
Collapse EditorsEditors
Form View
3D View
Collapse 2D Editors2D Editors
Crossection View
Profile View
Drum View
Collapse DialogsDialogs
3D Curve Dialog
Symmetry Collection Editor
Clip Editor
Material Editor
Surface options dialog
Collapse Modelling TutorialsModelling Tutorials
Table Tutorial
Mouse Tutorial
Collapse DeploymentDeployment
Redistribution
Registration
Deploy Module Tutorial
WixDeploy Tutorial
DeployWixBasic
Deploy Tutorial
Licensing
Model Viewer
Open C++ Source
Technical Support
Skip Navigation LinksHome Page > Programming Samples and Tutorials > .NET Samples > Visual Basic Samples > Patch Tutorial
.NET VB Patch Tutorial

Patch Programming Tutorial

Patch Programming Tutorial demonstrates incorporation of KernelCAD ActiveX control into a simple Windows Form application using Microsoft Visual Studio .NET 7.1 or later.  Source code for Patch sample is available in Samples\Tutorials\NET\VB\Patch folder of the installation directory. It is recommended to copy the project folder to location outside of the installation folder before loading or compilation. Patch is an application which displays a DInsight model consisting of a single patch of surface using KernelCADnet ActiveX control and allows to modify geometrical parameters of the model.

See also C# Patch Tutorial    C++ Patch Tutorial,   All VB .NET Samples,   All samples

This tutorial assumes basic familiarity with Visual Studio .NET.

Running the Application

Patch application loads ArcPatch.glm located in the Models folder of the installation directory. The model represents a surface patch, which is a Generic 3D Section  with single cross-sectional element (See Elements).  To be able to compare behavior, two edges of the patch are not of the same type. The first edge (the right one) consists of arcs. The second edge consists of straight line elements. The first edit box "Cross-section position" specifies z coordinate for cross-sectional plane where all other parameter modifications will be applied. The next four edit boxes allow modification of coordinates of edge in the cross-section plane. Note that type of modifications is different depending whether the cross-section position is at the end ( z=0 or z=10 ) or anywhere in the middle of the axial range. 

Note that curvature can be negative. Valid range for the curvature is [-cMax, cMax], where cMax is 1/ (half distance between the edges at the current cross-section)

To enter new value of the parameters press "Apply" button. If entered values are valid, the model will change in 3D.

Step 1. Creating the project

  • Open Visual Studio. Select File > New > Project in the menu. In Projects types window select "Visual Basic Projects". Make sure that "Windows 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 the menu select Project > "Add Reference...".
  • In the dialog open COM tab and select "KernelCADnet ActiveX Control Module". 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 600, 460 by 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" and place the control on the left in the form..
  • Right-click on the control and select "Properties". In the opened Properties dialog open Control tab. Click "Browse" button and select ArcPatch.glm in the Models folder of the installation directory, which is "C:\Program Files\DInsight" by default.
  • On the Render page of the dialog turn "Show global axes" check box on and select background color you like using the "Modify" button. 
  • Press F5 key to run the application. Check that the model can be rotated (left mouse button). Pan (shift + left mouse button) and zoom (right mouse button) should work too.
  • Open the Object Browser (View > Object Browser menu option). Expand interop.kerncadnet and KernCADnet nodes. This node displays all necessary information about types, interfaces and their methods available in the KernelCADnet component.

Step 2. Programming access to the model 

  • To create handler for the Load event of the form, select Form1 in the Solution Explorer, and select "View Code" from the context menu (Right mouse click). With the Form1.vb opened select From1 events from the left hand drop down list at the top of the editor. Select Load from the right hand drop down list  A new Form1_Load() method will be added to the form class.
  • Next we will get access to IModel  interface implemented by the control. Add to Form1_Load() the next two lines (without the (A) annotation):

                    Dim iModel As KernCADnet.IModel

                    iModel = axKernCADnet1.GetModel()            (A)

  • Now we have access to the root interface, from which all other interfaces can be queried. The next step is to obtain access to ISection interface of the first (and only) object in the model. Add line

                       Dim m_iSection As KernCADnet.ISection 

          above declaration of Form1_Load() sub.

  • Open KernelCADnet node in the Object Browser again and select IModel. The right hand pane will display methods available in the interface. Select GetSection() item. Bottom pane of the Object Browser will show that the method returns objects of KernCADnet.ISection type. It will allow us to make the next modification:
  • In the handler Form1_Load() for the Load event enter the next line just below the line (A):

               m_iSection  =  iModel.GetSection(0)                                    (B)

         Note that in a real life application prior to the previous call it is necessary to verify that the model contains at least one object with the help of       GetSectionCount() of IModel (Se the Object Browser). 

Step 3. Accessing Surface of the Object.

We need to retrieve another interface, which will be stored in a field of the form. It is IStrip interface. For objects of this type (Generic 3D Section) IStrip acts as a container of joined surface patches, of which  the object's surface consists. In this case the model consists of a single patch.

  • Add a variable m_iStrip of KernCADnet.IStrip type to the form class
  • To retrieve the interface add line 

            m_iStrip = m_iSection            (C)

           below the line (B) in the Form1_Load() method.

  • Build the project to make sure that no compilation errors where introduced so far.

Step 4. Accessing the base.

To be able to retrieve z-extents of the object and modify the current cross-section position it is needed to obtain IAxiBase interface.

  • Add field m_iAxiBase of type KernCADnet.IAxiBase to the form class.
  • Add line

            m_iAxiBase = m_iSection

        to the Form1_Load() below the line (C).

Step 5. Obtaining parameters of the object

Here we will get access to geometrical parameters of the only object in the model and display them in controls of the dialog.

  • Open the form in design mode and place an edit box with name editCrossPosn in the top right hand corner. Add label "Cross-section position:" next to it.
  • Add field m_dZCrossPosn of double type to the form.

        Let us separate obtaining access to edges of the patch into a different function. 

  • Add new Sub UpdateSurfaceInfo() to the form class. This Sub will be obtaining information from the KernelCADnet component and storing it into fields of the form.
  • At  the beginning of the Sub add line

                    m_iAxiBase.SetCrossPosition( m_dZCrossPosn )            (D)

           which sets the current cross-section position in the KernelCAD component at position currently entered in the dialog.

  • Add declarations 

Dim m_iElemEdge1 As KernCADnet.IElement
Dim m_iElemEdge2 As KernCADnet.IElement
Dim m_iElemPatch As  KernCADnet.IElement

            next to declarations of m_iAxiBase in the Patch class. IElement interface manages parameters of basic geometric primitives. In this case elements are lines of two (right and left, see Surface Patches topic) edges and the  adjoined surface patch.

  • Enter another two lines

m_iElemEdge1 = m_iStrip.GetElement(0, false)
m_iElemEdge2 = m_iStrip.GetElement(1, false)

        just below the line (D) in UpdateSurfaceInfo(). They will obtain IElement interfaces of the edges.

  • The last line in the method will be:

                    m_iElemPatch = m_iStrip.GetElement(0, true)

            which will retrieve IElement interface of the surface patch. 

  • Add call to the implemented function UpdateSurfaceInfo() in the end of  Form1_Load().
  • Add remaining controls so that the form looks like:

  • Select the top X edit box in the form designer and set its name in the properties window to editX1. Rename all other edit boxes to editY1, editX2, editY2 and editCurvature respectively.
  • Create variables m_dX1, m_dY1, m_dX2, m_dY2 and m_dCurvature of double type
  • Create another Sub UpdatePage() in the dialog. Whenever necessary, this Sub will update controls on the form.
  • Copy the code below and paste into the body of the Sub:

m_dX1 = m_iElemEdge1.GetParam(0)

m_dY1 = m_iElemEdge1.GetParam(1)

m_dX2 = m_iElemEdge2.GetParam(0)

m_dY2 = m_iElemEdge2.GetParam(1)

m_dCurvature  = m_iElemPatch.GetParam(0)

            Edge1 is a line, which at the current z cross-section position gives a point, x and y coordinates of which are retrieved by the first two calls to GetParam() methods of IElement interface.

The last call to GetParam() retrieves the only parameter of the surface patch, namely radius of cross-sectional arc. 

  • Append the next five lines to the end of UpdatePage(): 

editX1.Text = m_dX1.ToString()

editY1.Text = m_dY1.ToString()

editX2.Text = m_dX2.ToString()

editY2.Text = m_dY2.ToString()

editCurvature.Text = m_dCurvature.ToString()

This code will transfer data from the class fields into correspondent edit boxes.

  • Add call to UpdatePage() to the end of UpdateSurfaceInfo().
  • Run the application. The Edge1 edit boxes should display numbers 10 and 0. Edge2 edit boxes should both display 0. Curvature should be equal to 0.1.

Step 6. Programming modifications of the model

Here we will add code to update the model with new values of entered parameters.

  • Crete new Sub UpdateData(), which will perform transfer of data from the form controls into fields of the form. Fill its body with code below:

m_dZCrossPosn = Double.Parse(editCrossPosn.Text)

m_dX1 = Double.Parse(editX1.Text)

m_dY1 = Double.Parse(editY1.Text)

m_dX2 = Double.Parse(editX2.Text)

m_dY2 = Double.Parse(editY2.Text)

m_dCurvature = Double.Parse(editCurvature.Text)

  • Add a handler of Apply button by double-clicking the button in the form designer.
  • Fill the body of the handler with the code below:

UpdateData();

if(m_dZCrossPosn<0.0) Then
    m_dZCrossPosn = 0.0
if(m_dZCrossPosn>10.0)
    m_dZCrossPosn = 10.0

m_iAxiBase.SetCrossPosition( m_dZCrossPosn )

m_iElemEdge1.SetParam(0, m_dX1) 

m_iElemEdge1.SetParam(1, m_dY1)

m_iElemEdge2.SetParam(0, m_dX2)

m_iElemEdge2.SetParam(1, m_dY2)

m_iElemPatch.SetParam(0, m_dCurvature);

axKernCADnet1.UpdateSurface()

UpdatePage()

axKernCADnet1.Invalidate()
axKernCADnet1.Update()

           For simplicity we have hard coded here actual minimal and maximal z coordinates in the model. SetParam() calls make actual changes in the model. 

UpdateSurface() call is needed to recalculate the surface after changes in the geometry.

The last two calls is the standard way to make the control to redraw itself.

  • Add a handler for the OK button clicks and call Close() base class method from inside to close the form.

Step 7. Testing the application

Try to enter different values in the edit boxes and observe how the geometry of the model changes. Note that the result depends dramatically on whether the cross position is at the end of z (base ) range, namely 0.0 and 10.0 or anywhere in the middle.

Note also that when the cross-section position is inside the range, left and right hand edges behave differently because the right hand edge is a curve and the left hand one is a straight line. This can be verified using 3D Debugger.

Note also that some parameter values are rejected by the software because it would make impossible the geometry, like an attempt to make ends of an arc too far for the given radius or attempt to make curvature too high for the given distance between the ends.