Home Page > 3D Debugger > 3D Debugger
Debugger
KernelCAD 3D Debugger
KernelCAD 3D Debugger (3DBugger) is a useful tool for 3D development. It
can be used for any kind of development, not necessarily development with
KernelCAD.
3DBugger works concurrently in collaboration with KernelCAD component, loaded on by the
application, which is being debugged (debugee application or simply
application). In this situation KernelCAD component is called
Client Debugger Component
3DBugger allows display and analysis of intermediate steps and state of the
application while the application is being debugged by stepping through in a
conventional debugger like Microsoft Visual Studio.
This is similar to Console.WriteLine() in .NET, printf
in C, TRACE in MFC, etc with exception that the output
window is three-dimensional and instead of text lines there are 3D objects.
See also
3DBugger Sample
Quick Start
To debug an application query I3DBugger
from IDIObjGenerator
and call I3DBugger.DumpObject with
representation parameter set to ISection
of the object to be displayed or to IModel. to
display a model.
Use also IDraw, and IDrawUtil,
queried form I3DBugger to add simple
primitives or standard parametric objects to the debugger display.
To start debugging Start 3D Debugger from the computer's Start menu. Select Debug >
Start in the menu. Step through your code and watch how
I3DBugger.DumpObject
and other 3DBugger calls display the progress in 3D.
It is strongly recommended to keep the Model Explorer open as it shows
sequence of added objects, other useful information and provides shortcuts
for the most frequent operations.
Concepts
Debugging stream should be thought of as a virtual model file, which is
displayed in the 3D output debugger window. On
I3DBugger.DumpObject or
I3DBugger.Dump the object is
written into the stream from the debugee application. 3DBugger application
is notified about the stream change and adds the last dumped objects to the
scene.
If the object has the same hash supplied in
I3DBugger.DumpObject call or via debugging context as an existing object the
object is updated with the dumped version. Visibility and some other properties
set from 3Dbugger remain unchanged.
An application can dump into several streams. This is useful, for example, in
situation when some of calculations are two dimensional and should be
isolated from 3D objects. Several applications can dump into the same stream
simultaneously. 3D debugger can display a single stream only, but several
instances of debugger can run simultaneously.
Streams are distinguished by its names. If an application uses only one
stream there is no need to worry about streams as a default stream named "Dump"
is used
To open and/or activate a stream for dumping from a debugee call
I3DBugger.AttachStream. To
attach 3DBugger to a non-default stream select
Debug > Options in 3D Debugger menu.
Only one stream can be active at a time in an application. When there are
several streams I3DBugger.AttachStream
is used to switch between the streams.
Representation
The dumped objects do not have to be the exact geometric object of the
debugee application. Quite often it is useful to simplify the object to show
only its location and orientation and may be some key features of its shape.
This simplified version of the object is called representation.
Normally any geometry aware class would have a Dump() method, which knows
about structure of the object and can either construct representation
dynamically, dump an existing KernelCAD object or use
IDraw, and IDrawUtil
interfaces. See Plane and Segment classes of
3DBugger Sample for an example.
Output Management
It is recommended to add meaningful names to the dumped object. It can be
done either by modifying name of the representation with
ISection.SetName or use
Name property of the debugger state (see below) in case of
IDraw or IDrawUtil.
It is also recommended to set valid hash parameter while using
I3DBugger.DumpObject. The
pointer of the original object in C++ is a good candidate for hash value.
Use Object.GetHashCode Method in .NET.
Some objects are very volatile and should be displayed for short time only.
For this purpose a dumped representation can be marked as
Transient Object
by setting the relevant parameter of
I3DBugger.DumpObject.
Transient objects are removed from the debugging 3D stream during the next call
to I3DBugger.BeginDump. Objects can also be marked as
transient by using Hash property of the Debugger state (see below).
The 3D Debug stream can be cleared with
I3DBugger.BeginSession, which also resets all parameters of the debugger
state. Relatively complex programs can make several calls to
I3DBugger.BeginSession when executions passes
from one major part of the algorithm to another. To clear the stream from
3DBugger application use Action > "Delete All Objects" menu option of Model
Explorer. Be aware that the change is saved without warning.
The Client Debugger Component
implements IDraw and IDrawUtil,
which can be used to dump some primitives indirectly, i.e. bypassing
I3DBugger.DumpObject. Using IDraw
and IDrawUtil
is identical to their use inside the ClientDraw
event. The difference is that the rendering is persistent. The result is
an object in 3D debug stream instead of image on the screen.
Dump of a primitive happens on call to End or
on call to any method of IDrawUtil. For
performance the object is not displayed immediately assuming that there can be
some more objects added to the stream before flashing it to the debugger window.
Call I3DBugger.Dump to force the 3DBugger update.
Use 3D Debugger State (below) for setting name, hash and other properties of
the object, which is about to be dumped.
Properties of dumped object like name and transient property for indirectly
dumped objects can be set using 3D Debugger State. 3D Debugger State is a
collection of several parameters, which are used when the next indirect dump
occurs.
To access the state use IKCContext
queried from I3DBugger.
Use IKCStack to save and restore
the state.
See also 3DBugger Sample
|