devices/deviceinput/ordeviceinput_layout.cxx

devices/deviceinput/ordeviceinput_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.
***************************************************************************************/
//--- Class declarations
#include "ordeviceinput_device.h"
#include "ordeviceinput_layout.h"
#define ORDEVICEINPUT__LAYOUT ORDeviceInputLayout
//--- FiLMBOX implementation and registration
FBDeviceLayoutImplementation( ORDEVICEINPUT__LAYOUT );
FBRegisterDeviceLayout ( ORDEVICEINPUT__LAYOUT,
ORDEVICEINPUT__CLASSSTR,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX constructor.
************************************************/
bool ORDeviceInputLayout::FBCreate()
{
// Get a handle on the device.
mDevice = ((ORDeviceInput *)(FBDevice *)Device);
// Create/configure UI
UICreate ();
UIConfigure ();
UIReset ();
// Add device & system callbacks
mDevice->OnStatusChange.Add ( this,(FBCallback)&ORDeviceInputLayout::EventDeviceStatusChange );
mSystem.OnUIIdle.Add ( this,(FBCallback)&ORDeviceInputLayout::EventUIIdle );
return true;
}
/************************************************
* FiLMBOX destructor.
************************************************/
void ORDeviceInputLayout::FBDestroy()
{
// Remove device & system callbacks
mSystem.OnUIIdle.Remove ( this,(FBCallback)&ORDeviceInputLayout::EventUIIdle );
mDevice->OnStatusChange.Remove ( this,(FBCallback)&ORDeviceInputLayout::EventDeviceStatusChange );
}
/************************************************
* Create the UI.
************************************************/
void ORDeviceInputLayout::UICreate()
{
int lS, lH; // space, height
lS = 4;
lH = 25;
// Create regions
AddRegion ( "TabPanel", "TabPanel", 0, kFBAttachLeft, "", 1.00,
0, kFBAttachTop, "", 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 ( "TabPanel", mTabPanel );
SetControl ( "MainLayout", mLayoutMarkers );
// Create sub layouts
UICreateLayout0();
UICreateLayout1();
}
/************************************************
* Create the markers layout.
************************************************/
void ORDeviceInputLayout::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 information layout.
************************************************/
void ORDeviceInputLayout::UICreateLayout1()
{
int lS, lW, lH; // space, width, height.
lS = 4;
lW = 200;
lH = 18;
// Add regions
mLayoutInformation.AddRegion ( "LabelInformation", "LabelInformation",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachTop, "", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
// Assign regions
mLayoutInformation.SetControl( "LabelInformation", mLabelInformation );
}
/************************************************
* Configure the UI elements (main layout).
************************************************/
void ORDeviceInputLayout::UIConfigure()
{
SetBorder ("MainLayout", kFBStandardBorder, false,true, 1, 0,90,0);
mTabPanel.Items.SetString("Markers~Information");
mTabPanel.OnChange.Add( this, (FBCallback)&ORDeviceInputLayout::EventTabPanelChange );
UIConfigureLayout0();
UIConfigureLayout1();
}
/************************************************
* Configure the UI elements (marker layout).
************************************************/
void ORDeviceInputLayout::UIConfigureLayout0()
{
}
/************************************************
* Configure the UI elements (information layout).
************************************************/
void ORDeviceInputLayout::UIConfigureLayout1()
{
mLabelInformation.Caption = "Information...";
}
/************************************************
* Refresh the UI.
************************************************/
void ORDeviceInputLayout::UIRefresh()
{
UIRefreshSpreadSheet();
}
/************************************************
* Refresh the spreadsheet content.
************************************************/
void ORDeviceInputLayout::UIRefreshSpreadSheet()
{
for(int i=0; i<mDevice->GetChannelCount();i++)
{
mSpreadMarkers.SetCell( i, 0, mDevice->GetDataTX(i) );
mSpreadMarkers.SetCell( i, 1, mDevice->GetDataTY(i) );
mSpreadMarkers.SetCell( i, 2, mDevice->GetDataTZ(i) );
mSpreadMarkers.SetCell( i, 3, mDevice->GetDataRX(i) );
mSpreadMarkers.SetCell( i, 4, mDevice->GetDataRY(i) );
mSpreadMarkers.SetCell( i, 5, mDevice->GetDataRZ(i) );
}
}
/************************************************
* Reset the UI values from device.
************************************************/
void ORDeviceInputLayout::UIReset()
{
UIResetSpreadSheet();
}
/************************************************
* Re-build the spreadsheet.
************************************************/
void ORDeviceInputLayout::UIResetSpreadSheet()
{
int i;
mSpreadMarkers.Clear();
// Spreadsheet
int lColumnIndex = -1;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 200;
// column 0: Translation X
mSpreadMarkers.ColumnAdd ("PosX");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 1: Translation Y
mSpreadMarkers.ColumnAdd ("PosY");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 2: Translation Z
mSpreadMarkers.ColumnAdd ("PosZ");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 3: Rotation X
mSpreadMarkers.ColumnAdd ("RotX");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 4: Rotation Y
mSpreadMarkers.ColumnAdd ("RotY");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 5: Rotation Z
mSpreadMarkers.ColumnAdd ("RotZ");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
for (i=0;i<mDevice->GetChannelCount();i++)
{
mSpreadMarkers.RowAdd( mDevice->GetChannelName(i), i );
mSpreadMarkers.GetCell(i,lColumnIndex).ReadOnly = true;
}
}
/************************************************
* Tab panel change callback.
************************************************/
void ORDeviceInputLayout::EventTabPanelChange( HISender pSender, HKEvent pEvent )
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl("MainLayout", mLayoutMarkers ); break;
case 1: SetControl("MainLayout", mLayoutInformation ); break;
}
}
/************************************************
* Device status change callback.
************************************************/
void ORDeviceInputLayout::EventDeviceStatusChange( HISender pSender, HKEvent pEvent )
{
UIReset();
}
/************************************************
* UI Idle callback.
************************************************/
void ORDeviceInputLayout::EventUIIdle( HISender pSender, HKEvent pEvent )
{
if( mDevice->Online )
{
UIRefresh();
}
}