DG Kernel (ActiveX) Documentation


Skip Navigation Links.
Start page
Quick Start
Search Page
Installation
What is new
Upgrading Native Apps
Licensing
Collapse ModelsModels
Collapse DG Kernel ControlsDG Kernel Controls
Collapse API ReferenceAPI Reference
Interface List
Vector Space
Collapse General GeometryGeneral Geometry
Collapse ModelModel
Collapse ViewView
Collapse General ComputingGeneral Computing
Collapse ViewsViews
Collapse Samples and TutorialsSamples and Tutorials
Collapse GraphicsGraphics
Collapse Math ObjectsMath Objects
Collapse DeprecatedDeprecated
Redistribution
Model Viewer
Open Source
Support
Skip Navigation Links Go to DGKC docs Search Documentation


Object Array Sample

Source code for Object Array sample is available in Samples\VC folder of the installation directory. It is recommended to copy whole VC directory to location outside of the installation folder before loading or compilation. ObjArray is an MFC application, which demonstrates dynamic creation of objects.

See also C# Object Array sample  Visual Basic .NET Object Array sample  Visual C++ Samples, All samples

Running the application  

Controls on the right allow navigation between objects in the currently loaded model. (see Structure of DInsight models). They represent a simplified version of Model Explorer of 3D Debugger. Children group displays number of children in the current object and allows to make current one of them. The current object is highlighted in 3D with blue color and its name is displayed at the top of the dialogue. On load "Children" group displays information about objects in the model, meaning that the whole model is considered as the top object in the hierarchy. 

"Switch to parent" button on the top of the dialogue makes parent the current object.

"Position" edit boxes allow modification of location of the current object.

"New Child" group allows adding new objects to the model or new children to the current object. 

File submenu allows saving and loading models.

"Current Object" submenu contains operations with the model structure:

Operations

"Delete" command deletes the child selected in the "Child" edit box.

"Detach" command makes the current object independent top level object of the model. On this command nothing will change in the 3D view. To make sure that the command was carried out try to modify position of the current object using "Position" edit boxes. The object should move independently of its previous parent.

"Join" command makes the first top level object (different from the current) child of the current object. This command is invalid when a top object is being attached to its child. As the result the object will move together with its parent.

Implementation

The most important work, specific to this sample, is done using IArray interface. IArray is a topological interface, which means it changes structure of the model rather than modifying its parameters. Actions performed by IArray depend on context. In this sample IArray adds or deletes child objects from/to the entity or model it was queried from. It is done in CObjArrayDlg::OnButtAdd() and CObjArrayDlg::OnButtDelete() handlers. 

New objects are added in CObjArrayDlg::OnButtAdd() handler. Depending on selection in Type radio button group either NewStandardObjectDlg or NewGenericObjectDlg is displayed. NewStandardObjectDlg uses IStdShape interface to create new objects. NewGenericObjectDlg uses Object Generators to demonstrate more flexible but more complex object creation.

NewGenericObjectDlg::Create3DS() uses call to  CoGetClassObject() COM API to get access to class factory of Sect3DGenerator objects using its class id CLSID_Sect3DGenerator. CLSID_Sect3DGenerator is declared in DIInterface.h common header file. 

Sect3DGenerator is a generic constructor of new 3D entity objects. It has a single interface I3DSectionGenerator, which is obtained during the object creation with the help of call to CreateInstance() method of the class factory. Creation of the actual 3D Entity is done by using Create() method of I3DSectionGenerator. Create() returns an ISection interface, implemented by the new entity, which is used later to add to the array of objects of the model or parent entity. Prior to that, default parameters for the required entity are collected into a DI3DSectInfo structure by Set3DSDefaults() function.

Function  NewGenericObjectDlg::CreateSOR() does the same job for Surface Of Revolution type of objects. All other generic objects are constructed with the help of  DIObjGenerator

Suggested exercise

Add operation to change order of top level object in the model.