Creating a Prototype

The HOOPS Visualize installation includes simple applications for a variety of GUI technologies. These applications provide a framework for the tutorials discussed later in this guide, and can also serve as containers for prototyping code. This section reviews how to start with a simple HOOPS Visualize application and insert a 'HelloWorld' text string in the scene-graph. Select the GUI technology that you wish to prototype with:

1 MFC - Microsoft Foundation Classes
2 ATL - Microsoft ActiveX Type Library
3 Windows Forms - GUI toolkit included with the Microsoft .NET Framework
4 QT - GUI toolkit for cross-platform development
5 Java/Swing - GUI toolkit for Java


1 MFC - Microsoft Foundation Classes

The MFC demonstration application can be found in the HOOPS Visualize solution, mfc_simple_vcXX project. Open the file SampleHView.cpp and find the function OnRunMyCode(). After recompiling the project, the following code will be run when you start the application and click the down arrow:

void CSampleHView::OnRunMyCode()
{
HC_Open_Segment_By_Key(m_pHView->GetModelKey());
{
HC_Insert_Text(0, 0, 0, "Hello world");
}
HC_Close_Segment();
m_pHView->Update();
}

This code does the following:

  1. Opens the model segment using the model key
  2. Inserts the text string at the origin
  3. Closes the segment, since we aren't doing anything else
  4. Updates the scene


2 ATL

This tutorial describes how to take the reference ATL control (called the HOOPS 3D Stream Control), and display the text 'Hello World' in the viewport. It assume some familiarity with ATL. Developers are encouraged to read through the HOOPS/ActiveX documentation to get an idea of what the sample ATL control is all about. The source code and project files for the HOOPS 3D Stream Control is located in <hoops>/demo/atl/Hoops3dStreamCtrl/source.

Let's modify the application to display the 'Hello World' text each time a new window is opened. This can be achieved by adding code to the CHoops3dStreamCtrl::InitModel method which does the following:

  1. Opens the segment associated with the model object. The numerical identifier of the segment (called a 'key') is accessed by calling the model object's HBaseModel::GetModelKey method, and the segment is opened using the Open_Segment_By_Key subroutine.
  2. Inserts a piece of text into the segment by calling Insert_Text.
  3. Closes the segment by calling Close_Segment.

The modified sample code for:

void class CHoops3dStreamCtrl::InitModel()
{
...
if (!m_pModel)
{
m_pModel = new HBaseModel ();
m_pModel->Init();
HC_Open_Segment_By_Key(m_pModel->GetModelKey());
HC_Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
HC_Close_Segment();
}
}

Generally, the reference control's source code should not be modified to dynamically create graphical primitives. Rather, it should be referenced on a web page to automatically stream in pre-created HSF files, and/or could could be dynamically interacted with from a web page via it's public COM interface. Again, the HOOPS/ActiveX documentation provides details.

3 Windows Forms

This tutorial describes how to take the 'simple' HOOPS/Winforms application and display the text 'Hello World' in the viewport. You may wish to first review the HOOPS/Winforms documentation to get an idea of the structure of the provided application.

There are two HOOPS/Winforms examples, one for VB.Net and one for C#.Net. Their source code and project files are located in <hoops>/demo/csharp/csharp_simple, and <hoops>/demo/visual_basic/vb_simple. Compile and run the one that you're interested in to make sure your development environment is setup correctly.

Let's modify the application to display the 'Hello World' text each time a new window is opened. This can be achieved by adding code to the custom HSimpleModel constructor which does the following:

  1. Opens the segment associated with the model object. The numerical identifier of the segment (called a 'key') is accessed by calling the model object's HBaseModel::GetModelKey method, and the segment is opened using the HCS.Open_Segment_By_Key subroutine.
  2. Inserts a piece of text into the segment by calling HCS.Insert_Text.
  3. Closes the segment by calling HCS.Close_Segment.

csharp_simple:

The sample code would be added to the HSimpleModel::Init method in SimpleHNPanel.cs:

public class HSimpleModel : HBaseModel
{
...
override public void Init()
{
base.Init();
HCS.Open_Segment_By_Key(GetModelKey());
HCS.Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
HCS.Close_Segment();
}
...
}

vb_simple:

The sample code would be added to the HSimpleModel::Init method in SimpleHNPanel.vb:

Public Class HSimpleModel
Inherits HBaseModel
...
Public Overrides Sub Init()
MyBase.Init()
HCS.Open_Segment_By_Key(GetModelKey());
HCS.Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
End Sub 'Init
...
End Class 'HSimpleModel


4 QT

This tutorial describes how to take the 'simple' HOOPS/QT application and display the text 'Hello World' in the viewport. You may wish to first review the HOOPS/QT documentation to get an idea of the structure of the provided application.

The source code to the simple HOOPS/Qt application is located in <hoops>/demo/qt/qt_simple_4. Compile and run it to make sure your development environment is set up correctly.

Let's modify the application to display the 'Hello World' text each time a new window is opened. This can be achieved by adding code to the custom HOOPS/QT widget's constructor, which does the following:

  1. Opens the HOOPS/3dGS segment associated with the model object. The numerical identifier of the segment (called a 'key') is accessed by calling the model object's HBaseModel::GetModelKey method, and the segment is opened using Open_Segment_By_Key.
  2. Inserts a piece of text into the segment by calling Insert_Text.
  3. Closes the segment by calling Close_Segment.

The modified SimpleHQWidget constructor would look like the following:

SimpleHQWidget::SimpleHQWidget(QWidget* parent, const char* name, const char * filename)
: HQWidget( parent, name )
{
CreateMenus();
// Create and initialize HOOPS/MVO Model and View objects
m_pHBaseModel = new HBaseModel();
m_pHBaseModel->Init();
HC_Open_Segment_By_Key(m_pHBaseModel->GetModelKey());
HC_Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
HC_Close_Segment();
// Initialize View object to null ; gets created in SimpleHQWidget::Init
m_pHView = 0;
// if called with a file name we load it
// otherwise open an empty view
if(filename)
m_pHBaseModel->Read(filename);
// enable MouseMoveEvents
setMouseTracking(true);
// enable key events
setEnabled(true);
setFocusPolicy(QWidget::StrongFocus);
}

Note that the sample code could have also been inserted in an overloaded method of HBaseModel::Init.

5 Java

This tutorial describes how to take the 'simple' HOOPS/Java application and display the text 'Hello World' in the viewport. You may wish to first review the HOOPS/Java documentation to get an idea of the structure of the provided application.

The source code to the simple HOOPS/Java application is located in <hoops>/demo/java/java_simple. Follow the steps in the readme.txt file to recompile and run it.

Let's modify the application to display the 'Hello World' text each time a new window is opened. This can be achieved by adding code to the HSimpleModel::Init which does the following:

  1. Opens the segment associated with the model object. The numerical identifier of the segment (called a 'key') is accessed by calling the model object's HBaseModel::GetModelKey method, and the segment is opened using Open_Segment_By_Key.
  2. Inserts a piece of text into the segment by calling Insert_Text.
  3. Closes the segment by calling Close_Segment.

The modified HSimpleModel::Init method would look like the following:

class HSimpleModel extends HBaseModel
{
...
public void Init()
{
super.Init();
HJ.Open_Segment_By_Key(GetModelKey());
HJ.Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
HJ.Close_Segment();
}
...
}

Note that the sample code could have also been inserted in an overloaded method of HBaseModel::Init.