KernelCAD Documentation

DInsight Home
Skip Navigation Links.
Start page
Quick Start
Installation
Overview of the software
What is new
Collapse KernelCAD ModelsKernelCAD Models
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
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
Collapse DataData
Collapse MovementMovement
Collapse FramesFrames
Collapse Oriented ObjectsOriented Objects
Collapse SectionsSections
Collapse GeneralGeneral
Collapse Topological InterfacesTopological Interfaces
Collapse Viewing InterfacesViewing Interfaces
Collapse Lines And CurvesLines And Curves
Collapse Symmetry InterfacesSymmetry Interfaces
Collapse Clipping plane interfacesClipping plane interfaces
Collapse AlgorithmsAlgorithms
Collapse 2D Geometry2D Geometry
Collapse Programming Samples and TutorialsProgramming Samples and Tutorials
Collapse OverviewOverview
Collapse DeploymentDeployment
Collapse .NET Samples.NET Samples
Collapse C++ SamplesC++ Samples
Collapse Visual Basic SamplesVisual Basic Samples
Collapse Delphi SamplesDelphi Samples
Collapse 3D Debugger3D Debugger
Collapse DeploymentDeployment
Licensing
Model Viewer
Open C++ Source
Technical Support
Skip Navigation LinksHome Page > Programming Samples and Tutorials > C++ Samples > 3DBugger
3DBugger VC Sample

3DBugger C++ Tutorial

See Overview for general description and initial steps of the tutorial.

Overview of implementation

Initial tasks for starting the application are performed in DBuggerDlg::Init() called from DBuggerDlg::OnInitDialog(). GetVertices() function sets coordinates of the pyramid object stored in m_vert array of the dialog.

After that CreateGenerator() function loads KernelCAD component and obtains IDIObjGenerator interface using generic COM API. The interface is stored in m_iDIObjGenerator variable. The main debugging related interface I3DBugger is queried from and stored as m_i3DBugger.

Notice also Plane and Segment classes in the project. They are responsible for managing and dumping relevant geometric objects. Segment object will be used to represent a single shared edge of a flat face of the pyramid.

The calculation: The algorithm will calculate intersection of all six segments of the pyramid object with the plane The intersection points will be stored in m_intersection array. These points are corners of the intersection polygon, which can also become a segment, a point or an empty set depending on position and orientation of the plane.

It is convenient to position Visual Studio and 3DBugger windows side by side as shown on picture below

Debugging the application

  • Put break point on the DumpModel(); line of DBuggerDlg::Calculate() function. Start the application and press Calculate button
  • Step into the DumpModel() call. This function uses IModel and IModelEx to load 3Dbugger.glm model file, which contains model of the pyramid
  • Step Over the m_i3DBugger->DumpObject(iModel, (int)iModel, VARIANT_TRUE, VARIANT_FALSE); line and notice the pyramid object, which appeared in 3DBugger window. Notice the name of the object displayed in explorer window. You can view the object is 3D with all functionality of 3D Debugger available.
  • Step out of the DumpModel() function, step into m_plane.Dump(m_i3DBugger) call. and have a look at implementation of the Dump method of the Plane object. The method uses indirect dump technique. The dump is performed via IDrawUtil.Disk, at the line iDrawUtil->Disk(0, 3); Most of the code in the function is devoted to positioning and orienting the current rendering frame for IDraw because IDrawUtil.Disk renders a disk at a standard location (0,0) of the x and y axes of the current frame.
  • Notice how name of the dumped object is set at Util::SetCurrentName(strName, iDraw); line. The Util::SetCurrentName uses IKCContext to set the current Name property of the debugger to "Plane.." string. The actual dump will be performed at the i3DBugger->Dump(); line of the Plane::Dump()
  • Step out of the Plane::Dump() and notice the disk representing the plane to appear in the debugger window. Name of the object containing pointer of the Plane object is displayed in the Explorer
  • In DBuggerDlg::Calculate() function step through several lines and step into the first call of the AddSegmentIntersection(); line
  • This function calculates intersection of  a segment with the plane. Step over two lines and stop at the segment.Dump();
  • Try very useful technique, which sometimes allows debugging without adding any extra code to the application: Open Debug > Quick Watch window in Visual Studio and paste segment.Dump() into the expression line. Press Recalculate button. The segment will appear in the 3D view. Close the quick watch window
  • Step into the segment.Dump(); line of DBuggerDlg::AddSegmentIntersection(). The function demonstrates indirect dump using IDraw interface. Notice the iKCContext->SetBoolParam(0, VARIANT_TRUE); line, which indicates the the segment must be dumped as a transient object. Notice also usage of IKCStack to save the state before the above change and restore it after the dump.
  • Step out up the call stack two times to reach the DBuggerDlg::Calculate() function. Step thought the repetitive loops while watching the dumped segments. Notice how previous segments are removed by the m_i3DBugger->BeginDump(); in the start of each loop. It is important that the segment was dumped as a transient object.
  • Notice that when the segment intersects the plane the intersection point appears in debugger window. This is accomplished in DBuggerDlg::DumpPoint function.
  • Let the application to continue (Debug > Continue in Visual Studio). The final scene displayed in debugger window should look like:
  • :
  • The Intersection face is dumped by DBuggerDlg::DumpIntersection() using IDraw