devices/deviceopticalhybrid/ordeviceopticalhybrid_layout.cxx

devices/deviceopticalhybrid/ordeviceopticalhybrid_layout.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- SDK include
#include <fbsdk/fbsdk.h>
//--- Class declarations
#include "ordeviceopticalhybrid_layout.h"
//--- Registration defines
#define ORDEVICEOPTICALHYBRIDTEMPLATE_LAYOUT ORDeviceOpticalHybrid_Template_Layout
//--- FiLMBOX implementation and registration
FBDeviceLayoutImplementation( ORDEVICEOPTICALHYBRIDTEMPLATE_LAYOUT );
FBRegisterDeviceLayout ( ORDEVICEOPTICALHYBRIDTEMPLATE_LAYOUT,
ORDEVICEOPTICALHYBRIDTEMPLATE_CLASSSTR,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORDeviceOpticalHybrid_Template_Layout::FBCreate()
{
bool lSuccess;
// important: propagate creat call to parent first.
lSuccess = FBDeviceOpticalLayout::FBCreate();
if( lSuccess )
{
mDevice = ((ORDeviceOpticalHybrid_Template *)(FBDevice *)Device);
UICreate ();
UIConfigure ();
UIReset ();
mSystem.OnUIIdle.Add ( this,(FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventUIIdle );
mDevice->OnStatusChange.Add ( this,(FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventDeviceStatusChange );
}
return lSuccess;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::FBDestroy()
{
mSystem.OnUIIdle.Remove ( this,(FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventUIIdle );
mDevice->OnStatusChange.Remove ( this,(FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventDeviceStatusChange );
}
/************************************************
* Create the UI.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UICreate()
{
int lS, lH; // space, height
lS = 5;
lH = 25;
// Create regions
AddRegion ( "TabPanel", "TabPanel", 5, kFBAttachRight, "StandardParams", 1.00,
0, kFBAttachTop, "StandardParams", 1.00,
0, kFBAttachRight, "", 1.00,
lH, kFBAttachNone, NULL, 1.00 );
AddRegion ( "MainLayout", "MainLayout", lS, kFBAttachLeft, "TabPanel", 1.00,
lS, kFBAttachBottom, "TabPanel", 1.00,
-lS, kFBAttachRight, "TabPanel", 1.00,
-lS, kFBAttachBottom, "", 1.00 );
// Assign regions
SetControl ( "Params_Border", mLayoutCommunication );
SetControl ( "TabPanel", mTabPanel );
SetControl ( "MainLayout", mLayoutMarkers );
// Create sub layouts
UICreateLayout0();
UICreateLayout1();
UICreateLayout2();
}
/************************************************
* Create the markers layout.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UICreateLayout0()
{
// Add regions
mLayoutMarkers.AddRegion( "SpreadMarkers", "SpreadMarkers",
0, kFBAttachLeft, "", 1.00,
0, kFBAttachTop, "", 1.00,
0, kFBAttachRight, "", 1.00,
0, kFBAttachBottom, "", 1.00 );
// Assign regions
mLayoutMarkers.SetControl( "SpreadMarkers", mSpreadMarkers );
}
/************************************************
* Create the setup layout.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UICreateLayout1()
{
int lS = 5;
int lSx = 15;
int lSy = 20;
int lS_y = -15;
int lW = 100;
int lH = 25;
int lHlr = 75;
int lWlr = 250;
int lWrb = 140;
int lSlbx = 30;
int lSlby = 12;
int lWlb = 80;
// Add regions (network)
mLayoutCommunication.AddRegion( "LayoutRegionNetwork", "LayoutRegionNetwork",
lSx, kFBAttachLeft, "", 1.00,
lSy, kFBAttachTop, "", 1.00,
lWlr, kFBAttachNone, NULL, 1.00,
lHlr, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "ButtonNetworkEnable", "ButtonNetworkEnable",
lS, kFBAttachLeft, "LayoutRegionNetwork", 1.00,
lS_y, kFBAttachTop, "LayoutRegionNetwork", 1.00,
lWrb, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "LabelNetworkAddress", "LabelNetworkAddress",
lSlbx, kFBAttachLeft, "LayoutRegionNetwork", 1.00,
lSlby, kFBAttachTop, "LayoutRegionNetwork", 1.00,
lWlb, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "EditNetworkAddress", "EditNetworkAddress",
lS, kFBAttachRight, "LabelNetworkAddress", 1.00,
0, kFBAttachTop, "LabelNetworkAddress", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "LabelNetworkPort", "LabelNetworkPort",
0, kFBAttachLeft, "LabelNetworkAddress", 1.00,
lS, kFBAttachBottom, "LabelNetworkAddress", 1.00,
0, kFBAttachWidth, "LabelNetworkAddress", 1.00,
0, kFBAttachHeight, "LabelNetworkAddress", 1.00 );
mLayoutCommunication.AddRegion( "EditNetworkPort", "EditNetworkPort",
lS, kFBAttachRight, "LabelNetworkPort", 1.00,
0, kFBAttachTop, "LabelNetworkPort", 1.00,
lW, kFBAttachNone, NULL, 1.00,
0, kFBAttachHeight, "LabelNetworkPort", 1.00 );
// Assign regions (network)
mLayoutCommunication.SetControl( "ButtonNetworkEnable", mButtonNetworkEnable );
mLayoutCommunication.SetControl( "LabelNetworkAddress", mLabelNetworkAddress );
mLayoutCommunication.SetControl( "EditNetworkAddress", mEditNetworkAddress );
mLayoutCommunication.SetControl( "LabelNetworkPort", mLabelNetworkPort );
mLayoutCommunication.SetControl( "EditNetworkPort", mEditNetworkPort );
}
/************************************************
* Create the information layout.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UICreateLayout2()
{
int lS, lW, lH; // space, width, height.
lS = 5;
lW = 200;
lH = 25;
// Add regions
mLayoutSetup.AddRegion ( "LabelRigidBody", "LabelRigidBody",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachTop, "", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.AddRegion ( "ButtonCreateRigidBody", "ButtonCreateRigidBody",
0, kFBAttachLeft, "LabelRigidBody", 1.00,
lS, kFBAttachBottom, "LabelRigidBody", 1.00,
0, kFBAttachWidth, "LabelRigidBody", 1.00,
0, kFBAttachHeight, "LabelRigidBody", 1.00 );
// Assign regions
mLayoutSetup.SetControl( "LabelRigidBody", mLabelRigidBody );
mLayoutSetup.SetControl( "ButtonCreateRigidBody", mButtonCreateRigidBody );
// Add regions
mLayoutSetup.AddRegion ( "LabelCharacterize", "LabelCharacterize",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "ButtonCreateRigidBody", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
// Assign regions
mLayoutSetup.SetControl( "LabelCharacterize", mLabelCharacterize );
// Add regions
mLayoutSetup.AddRegion ( "CharacterizeButton", "CharacterizeButton",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "LabelCharacterize", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
// Assign regions
mLayoutSetup.SetControl( "CharacterizeButton", mButtonCharacterize );
}
/************************************************
* Configure the main layout.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIConfigure()
{
SetBorder ("MainLayout", kFBStandardBorder, false,true, 1, 0,90,0);
mTabPanel.Items.SetString("Markers~Setup");
mTabPanel.OnChange.Add( this, (FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventTabPanelChange );
UIConfigureLayout0();
UIConfigureLayout1();
UIConfigureLayout2();
}
/************************************************
* Configure the markers layout.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIConfigureLayout0()
{
}
/************************************************
* Configure the UI elements (setup layout).
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIConfigureLayout1()
{
mLayoutCommunication.SetBorder( "LayoutRegionNetwork", kFBEmbossBorder,false,true,2,1,90.0,0);
mButtonNetworkEnable.Caption = "Use optical test server";
mButtonNetworkEnable.Style = kFBCheckbox;
mButtonNetworkEnable.State = mDevice->GetNetworkUse();
mButtonNetworkEnable.OnClick.Add( this,(FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventButtonNetworkEnableClick );
mLayoutCommunication.SetBorder( "EditNetworkAddress", kFBStandardBorder, false,true, 1, 0,90,0);
mLayoutCommunication.SetBorder( "EditNetworkPort", kFBStandardBorder, false,true, 1, 0,90,0);
mLabelNetworkAddress.Caption = "Address :";
mEditNetworkAddress.Text = mDevice->GetNetworkAddress();
mEditNetworkAddress.OnChange.Add( this, (FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventEditNetworkAddressChange );
mLabelNetworkPort.Caption = "Port :";
char lBuffer[40];
sprintf(lBuffer, "%d", mDevice->GetNetworkPort() );
mEditNetworkPort.Text = lBuffer;
mEditNetworkPort.OnChange.Add( this, (FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventEditNetworkPortChange );
}
/************************************************
* Configure the information layout.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIConfigureLayout2()
{
mLabelRigidBody.Caption = "Creation of a rigid body for markers";
mButtonCreateRigidBody.Caption = "Create RigidBody";
mButtonCreateRigidBody.OnClick.Add( this, (FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventButtonCreateRigidBodyClick );
mLabelCharacterize.Caption = "Character setup according to device template";
mButtonCharacterize.Caption = "Characterize";
mButtonCharacterize.OnClick.Add( this, (FBCallback)&ORDeviceOpticalHybrid_Template_Layout::EventSetupCharacter );
}
/************************************************
* Refresh the UI.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIRefresh()
{
UIRefreshSpreadSheet();
}
/************************************************
* Refresh the contents of the spreadsheet.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIRefreshSpreadSheet()
{
for(int i=0; i<mDevice->GetMarkerCount();i++)
{
mSpreadMarkers.SetCell( i, 0, mDevice->GetDataX(i) );
mSpreadMarkers.SetCell( i, 1, mDevice->GetDataY(i) );
mSpreadMarkers.SetCell( i, 2, mDevice->GetDataZ(i) );
mSpreadMarkers.SetCell( i, 3, mDevice->GetDataO(i) );
if(mDevice->GetDataO(i) == 1.0)
{
int a;
a=0;
}
}
}
/************************************************
* Reset all UI Components.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIReset()
{
UIResetSpreadSheet();
}
/************************************************
* Rebuild the spreadsheet.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::UIResetSpreadSheet()
{
int i;
mSpreadMarkers.Clear();
// Spreadsheet
int lColumnIndex = -1;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 200;
// column 0: X
mSpreadMarkers.ColumnAdd ("X");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 1: Y
mSpreadMarkers.ColumnAdd ("Y");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 2: Z
mSpreadMarkers.ColumnAdd ("Z");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 3: Occlusion
mSpreadMarkers.ColumnAdd ("Occlusion");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
mSpreadMarkers.GetColumn(lColumnIndex).ReadOnly = true;
for (i=0;i<mDevice->GetMarkerCount();i++)
{
mSpreadMarkers.RowAdd( (char*)mDevice->GetMarkerName(i), i );
mSpreadMarkers.GetCell(i,lColumnIndex).ReadOnly = true;
}
}
/************************************************
* Tab panel change callback.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventTabPanelChange( HISender pSender, HKEvent pEvent )
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl("MainLayout", mLayoutMarkers ); break;
case 1: SetControl("MainLayout", mLayoutSetup ); break;
}
}
/************************************************
* Server port change callback.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventButtonNetworkEnableClick( HISender pSender, HKEvent pEvent )
{
mDevice->SetNetworkUse(((int)mButtonNetworkEnable.State)==1);
}
/************************************************
* Server port change callback.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventEditNetworkPortChange( HISender pSender, HKEvent pEvent )
{
int lPort;
char lBuffer[40];
sscanf(mEditNetworkPort.Text.AsString(), "%d", &lPort);
mDevice->SetNetworkPort(lPort);
lPort = mDevice->GetNetworkPort();
sprintf(lBuffer, "%d", lPort );
mEditNetworkPort.Text = lBuffer;
}
/************************************************
* Server port address callback.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventEditNetworkAddressChange( HISender pSender, HKEvent pEvent )
{
mDevice->SetNetworkAddress(mEditNetworkAddress.Text.AsString());
mEditNetworkAddress.Text = mDevice->GetNetworkAddress();
}
/************************************************
* Device Status change callback.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventButtonCreateRigidBodyClick( HISender pSender, HKEvent pEvent )
{
mDevice->RigidBodySetup();
}
/************************************************
* Device Status change callback.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventDeviceStatusChange( HISender pSender, HKEvent pEvent )
{
UIReset();
}
/************************************************
* UI Idle callback.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventUIIdle( HISender pSender, HKEvent pEvent )
{
if(mDevice->Online)
{
UIRefresh();
}
}
//simple name mapping.
static void SetupMapping(FBCharacter* pCharacter, FBModel* pParent)
{
FBString lName = (const char*)pParent->Name; lName += "Link";
FBProperty* lLink = pCharacter->PropertyList.Find(lName,false);
if(lLink && lLink->IsList())
{
((FBPropertyListComponent*)lLink)->Add(pParent);
}
//do the same for children
for(int i = 0; i < pParent->Children.GetCount(); i++)
{
SetupMapping(pCharacter,pParent->Children[i]);
}
}
/************************************************
* Characterize binding models.
************************************************/
void ORDeviceOpticalHybrid_Template_Layout::EventSetupCharacter( HISender pSender, HKEvent pEvent )
{
if(mDevice && mDevice->ReadyForCharacterize())
{
FBCharacter* lCharacter = new FBCharacter("DeviceCharacter");
FBModel* lReference = mDevice->mRootTemplate->Model;
if(lReference)
{
SetupMapping(lCharacter,lReference);
lCharacter->SetCharacterizeOn(true);
}
}
}