devices/deviceoutput/ordeviceoutput_layout.cxx

devices/deviceoutput/ordeviceoutput_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 "ordeviceoutput_layout.h"
//--- Registration define
#define ORDEVICEOUTPUT__LAYOUT ORDeviceOutputLayout
//--- FiLMBOX implementation and registration
FBDeviceLayoutImplementation( ORDEVICEOUTPUT__LAYOUT );
FBRegisterDeviceLayout ( ORDEVICEOUTPUT__LAYOUT,
ORDEVICEOUTPUT__CLASSSTR,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX constructor.
************************************************/
bool ORDeviceOutputLayout::FBCreate()
{
// Get a handle on the device.
mDevice = ((ORDeviceOutput *)(FBDevice *)Device);
UICreate ();
UIConfigure ();
UIReset ();
mDevice->OnStatusChange.Add ( this,(FBCallback)&ORDeviceOutputLayout::EventDeviceStatusChange );
mSystem.OnUIIdle.Add ( this,(FBCallback)&ORDeviceOutputLayout::EventUIIdle );
return true;
}
/************************************************
* FiLMBOX destructor.
************************************************/
void ORDeviceOutputLayout::FBDestroy()
{
mDevice->OnStatusChange.Remove ( this,(FBCallback)&ORDeviceOutputLayout::EventDeviceStatusChange );
mSystem.OnUIIdle.Remove ( this,(FBCallback)&ORDeviceOutputLayout::EventUIIdle );
}
/************************************************
* UI Creation.
************************************************/
void ORDeviceOutputLayout::UICreate()
{
int lS, lH; // space, height
lS = 5;
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", mLayoutLightParameters );
// Create sub layouts
UICreateLayout0();
UICreateLayout1();
UICreateLayout2();
}
/************************************************
* Create the sub-layout 0.
************************************************/
void ORDeviceOutputLayout::UICreateLayout0()
{
int lS, lW, lH; // space, width, height.
lS = 4;
lW = 100;
lH = 18;
// Add regions
mLayoutLightParameters.AddRegion("LabelExportFilename", "LabelExportFilename",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
lW, kFBAttachNone, NULL, 1.0,
lH, kFBAttachNone, NULL, 1.0 );
mLayoutLightParameters.AddRegion("EditExportFilename", "EditExportFilename",
lS, kFBAttachRight, "LabelExportFilename", 1.0,
0, kFBAttachTop, "LabelExportFilename", 1.0,
(3*lW)/2, kFBAttachNone, NULL, 1.0,
0, kFBAttachHeight, "LabelExportFilename", 1.0 );
mLayoutLightParameters.AddRegion("LabelExportRate", "LabelExportRate",
0, kFBAttachLeft, "LabelExportFilename", 1.0,
lS, kFBAttachBottom, "LabelExportFilename", 1.0,
0, kFBAttachWidth, "LabelExportFilename", 1.0,
0, kFBAttachHeight, "LabelExportFilename", 1.0 );
mLayoutLightParameters.AddRegion("EditNumberExportRate", "EditNumberExportRate",
lS, kFBAttachRight, "LabelExportRate", 1.0,
0, kFBAttachTop, "LabelExportRate", 1.0,
0, kFBAttachWidth, "EditExportFilename", 1.0,
0, kFBAttachHeight, "LabelExportRate", 1.0 );
// Assign regions
mLayoutLightParameters.SetControl("LabelExportFilename", mLabelExportFilename );
mLayoutLightParameters.SetControl("EditExportFilename", mEditExportFilename );
mLayoutLightParameters.SetControl("LabelExportRate", mLabelExportRate );
mLayoutLightParameters.SetControl("EditNumberExportRate", mEditNumberExportRate );
}
/************************************************
* Create the communications layout.
************************************************/
void ORDeviceOutputLayout::UICreateLayout1()
{
int lS = 5;
int lSx = 15;
int lSy = 20;
int lS_y = -15;
int lW = 100;
int lH = 18;
int lHlr = 75;
int lWlr = 200;
int lWrb = 80;
int lSlbx = 15;
int lSlby = 10;
int lWlb = 80;
// Add regions (serial)
mLayoutCommunication.AddRegion( "LayoutRegionSerial", "LayoutRegionSerial",
lSx, kFBAttachLeft, "", 1.00,
lSy, kFBAttachTop, "", 1.00,
lWlr, kFBAttachNone, NULL, 1.00,
lHlr, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "ButtonSerialEnable", "ButtonSerialEnable",
lS, kFBAttachLeft, "LayoutRegionSerial", 1.00,
lS_y, kFBAttachTop, "LayoutRegionSerial", 1.00,
lWrb, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "LabelSerialPort", "LabelSerialPort",
lSlbx, kFBAttachLeft, "LayoutRegionSerial", 1.00,
lSlby, kFBAttachTop, "LayoutRegionSerial", 1.00,
lWlb, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "ListSerialPort", "ListSerialPort",
lS, kFBAttachRight, "LabelSerialPort", 1.00,
0, kFBAttachTop, "LabelSerialPort", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutCommunication.AddRegion( "LabelSerialBaudRate", "LabelSerialBaudRate",
0, kFBAttachLeft, "LabelSerialPort", 1.00,
lS, kFBAttachBottom, "LabelSerialPort", 1.00,
0, kFBAttachWidth, "LabelSerialPort", 1.00,
0, kFBAttachHeight, "LabelSerialPort", 1.00 );
mLayoutCommunication.AddRegion( "ListSerialBaudRate", "ListSerialBaudRate",
lS, kFBAttachRight, "LabelSerialBaudRate", 1.00,
0, kFBAttachTop, "LabelSerialBaudRate", 1.00,
0, kFBAttachWidth, "ListSerialPort", 1.00,
0, kFBAttachHeight, "LabelSerialBaudRate", 1.00 );
// Assign regions (serial)
mLayoutCommunication.SetControl( "ButtonSerialEnable", mButtonSerialEnable );
mLayoutCommunication.SetControl( "LabelSerialPort", mLabelSerialPort );
mLayoutCommunication.SetControl( "ListSerialPort", mListSerialPort );
mLayoutCommunication.SetControl( "LabelSerialBaudRate", mLabelSerialBaudRate );
mLayoutCommunication.SetControl( "ListSerialBaudRate", mListSerialBaudRate );
}
/************************************************
* Create the information layout.
************************************************/
void ORDeviceOutputLayout::UICreateLayout2()
{
int lS, lW, lH; // space, width, height.
lS = 5;
lW = 200;
lH = 25;
// 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.
************************************************/
void ORDeviceOutputLayout::UIConfigure()
{
SetBorder ("MainLayout", kFBStandardBorder, false,true, 1, 0,90,0);
mTabPanel.Items.SetString("Light Parameters~Communication~Information");
mTabPanel.OnChange.Add( this, (FBCallback)&ORDeviceOutputLayout::EventTabPanelChange );
UIConfigureLayout0();
UIConfigureLayout1();
UIConfigureLayout2();
}
/************************************************
* Configure the test button layout.
************************************************/
void ORDeviceOutputLayout::UIConfigureLayout0()
{
// Configure elements
mLabelExportFilename.Caption = "Export File :";
mLabelExportRate.Caption = "Export Rate :";
mEditNumberExportRate.Min = 1.0;
mEditNumberExportRate.Max = 100.0;
// Add callbacks
mEditExportFilename.OnChange.Add ( this, (FBCallback)&ORDeviceOutputLayout::EventEditExportFilenameChange );
mEditNumberExportRate.OnChange.Add ( this, (FBCallback)&ORDeviceOutputLayout::EventEditNumberExportRateChange );
}
/************************************************
* Configure the communiciations layout.
************************************************/
void ORDeviceOutputLayout::UIConfigureLayout1()
{
mLayoutCommunication.SetBorder( "LayoutRegionSerial", kFBEmbossBorder,false,true,2,1,90.0,0 );
mButtonSerialEnable.Caption = "Serial";
mButtonSerialEnable.Style = kFBRadioButton;
mButtonSerialEnable.State = 1;
mLabelSerialPort.Caption = "Port :";
int i;
int lPortNumber;
char lBuffer[40];
for( i=0; i<mSystem.CommPorts.GetCount(); i++ )
{
lPortNumber = mSystem.CommPorts[i];
sprintf(lBuffer, "Comm %d", lPortNumber );
mListSerialPort.Items.Add( lBuffer, lPortNumber );
}
mListSerialPort.OnChange.Add( this, (FBCallback)&ORDeviceOutputLayout::EventListSerialPortChange );
mLabelSerialBaudRate.Caption = "Speed :";
mListSerialBaudRate.Items.Add( "9600", 9600 );
mListSerialBaudRate.Items.Add( "19200", 19200 );
mListSerialBaudRate.Items.Add( "38400", 38400 );
mListSerialBaudRate.Items.Add( "57600", 57600 );
mListSerialBaudRate.Items.Add( "115200", 115200 );
mListSerialBaudRate.Items.Add( "230400", 230400 );
mListSerialBaudRate.OnChange.Add( this, (FBCallback)&ORDeviceOutputLayout::EventListSerialBaudRateChange );
}
/************************************************
* Configure the information layout.
************************************************/
void ORDeviceOutputLayout::UIConfigureLayout2()
{
mLabelInformation.Caption = "Information...";
}
/************************************************
* Refresh the UI.
************************************************/
void ORDeviceOutputLayout::UIRefresh()
{
}
/************************************************
* Reset the UI components from the device.
************************************************/
void ORDeviceOutputLayout::UIReset()
{
mEditNumberExportRate.Value = mDevice->GetExportRate();
mEditExportFilename.Text = mDevice->GetExportFilename();
mListSerialPort.ItemIndex = mListSerialPort.Items.Find ( mDevice->GetSerialPort() );
mListSerialBaudRate.ItemIndex = mListSerialBaudRate.Items.Find( mDevice->GetSerialBaudRate() );
}
/************************************************
* Filename change callback.
************************************************/
void ORDeviceOutputLayout::EventEditExportFilenameChange( HISender pSender, HKEvent pEvent )
{
if( mDevice->Online )
{
mDevice->DeviceSendCommand( FBDevice::kOpStop );
}
mDevice->SetExportFilename( mEditExportFilename.Text );
mEditExportFilename.Text = mDevice->GetExportFilename();
}
/************************************************
* Export rate change callback.
************************************************/
void ORDeviceOutputLayout::EventEditNumberExportRateChange( HISender pSender, HKEvent pEvent )
{
if( mDevice->Online )
{
mDevice->DeviceSendCommand( FBDevice::kOpStop );
}
mDevice->SetExportRate( mEditNumberExportRate.Value );
mEditNumberExportRate.Value = mDevice->GetExportRate();
}
/************************************************
* Tab panel change callback.
************************************************/
void ORDeviceOutputLayout::EventTabPanelChange( HISender pSender, HKEvent pEvent )
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl("MainLayout", mLayoutLightParameters ); break;
case 1: SetControl("MainLayout", mLayoutCommunication ); break;
case 2: SetControl("MainLayout", mLayoutInformation ); break;
}
}
/************************************************
* Device status change callback.
************************************************/
void ORDeviceOutputLayout::EventDeviceStatusChange( HISender pSender, HKEvent pEvent )
{
UIReset();
}
/************************************************
* UI Idle callback.
************************************************/
void ORDeviceOutputLayout::EventUIIdle( HISender pSender, HKEvent pEvent )
{
if( mDevice->Online )
{
UIRefresh();
}
}
/************************************************
* When the serial port list changes.
************************************************/
void ORDeviceOutputLayout::EventListSerialPortChange( HISender pSender, HKEvent pEvent )
{
if( mDevice->Online )
{
mDevice->DeviceSendCommand( FBDevice::kOpStop );
}
mDevice->SetSerialPort(mListSerialPort.Items.GetReferenceAt(mListSerialPort.ItemIndex));
mListSerialPort.ItemIndex = mListSerialPort.Items.Find(mDevice->GetSerialPort());
}
/************************************************
* Server port change callback.
************************************************/
void ORDeviceOutputLayout::EventListSerialBaudRateChange( HISender pSender, HKEvent pEvent )
{
if( mDevice->Online )
{
mDevice->DeviceSendCommand( FBDevice::kOpStop );
}
mDevice->SetSerialBaudRate( mListSerialBaudRate.Items.GetReferenceAt(mListSerialBaudRate.ItemIndex) );
mListSerialBaudRate.ItemIndex = mListSerialBaudRate.Items.Find( mDevice->GetSerialBaudRate() );
}