#include "ordeviceopticalhybrid_layout.h"
#define ORDEVICEOPTICALHYBRIDTEMPLATE_LAYOUT ORDeviceOpticalHybrid_Template_Layout
ORDEVICEOPTICALHYBRIDTEMPLATE_CLASSSTR,
bool ORDeviceOpticalHybrid_Template_Layout::FBCreate()
{
bool lSuccess;
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;
}
void ORDeviceOpticalHybrid_Template_Layout::FBDestroy()
{
mSystem.OnUIIdle.Remove (
this,(
FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventUIIdle );
mDevice->OnStatusChange.Remove (
this,(
FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventDeviceStatusChange );
}
void ORDeviceOpticalHybrid_Template_Layout::UICreate()
{
int lS, lH;
lS = 5;
lH = 25;
AddRegion (
"TabPanel",
"TabPanel", 5,
kFBAttachRight,
"StandardParams", 1.00,
AddRegion (
"MainLayout",
"MainLayout", lS,
kFBAttachLeft,
"TabPanel", 1.00,
SetControl ( "Params_Border", mLayoutCommunication );
SetControl ( "TabPanel", mTabPanel );
SetControl ( "MainLayout", mLayoutMarkers );
UICreateLayout0();
UICreateLayout1();
UICreateLayout2();
}
void ORDeviceOpticalHybrid_Template_Layout::UICreateLayout0()
{
mLayoutMarkers.AddRegion( "SpreadMarkers", "SpreadMarkers",
mLayoutMarkers.SetControl( "SpreadMarkers", mSpreadMarkers );
}
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;
mLayoutCommunication.AddRegion( "LayoutRegionNetwork", "LayoutRegionNetwork",
mLayoutCommunication.AddRegion( "ButtonNetworkEnable", "ButtonNetworkEnable",
mLayoutCommunication.AddRegion( "LabelNetworkAddress", "LabelNetworkAddress",
mLayoutCommunication.AddRegion( "EditNetworkAddress", "EditNetworkAddress",
mLayoutCommunication.AddRegion( "LabelNetworkPort", "LabelNetworkPort",
mLayoutCommunication.AddRegion( "EditNetworkPort", "EditNetworkPort",
mLayoutCommunication.SetControl( "ButtonNetworkEnable", mButtonNetworkEnable );
mLayoutCommunication.SetControl( "LabelNetworkAddress", mLabelNetworkAddress );
mLayoutCommunication.SetControl( "EditNetworkAddress", mEditNetworkAddress );
mLayoutCommunication.SetControl( "LabelNetworkPort", mLabelNetworkPort );
mLayoutCommunication.SetControl( "EditNetworkPort", mEditNetworkPort );
}
void ORDeviceOpticalHybrid_Template_Layout::UICreateLayout2()
{
int lS, lW, lH;
lS = 5;
lW = 200;
lH = 25;
mLayoutSetup.AddRegion ( "LabelRigidBody", "LabelRigidBody",
mLayoutSetup.AddRegion ( "ButtonCreateRigidBody", "ButtonCreateRigidBody",
mLayoutSetup.SetControl( "LabelRigidBody", mLabelRigidBody );
mLayoutSetup.SetControl( "ButtonCreateRigidBody", mButtonCreateRigidBody );
mLayoutSetup.AddRegion ( "LabelCharacterize", "LabelCharacterize",
mLayoutSetup.SetControl( "LabelCharacterize", mLabelCharacterize );
mLayoutSetup.AddRegion ( "CharacterizeButton", "CharacterizeButton",
mLayoutSetup.SetControl( "CharacterizeButton", mButtonCharacterize );
}
void ORDeviceOpticalHybrid_Template_Layout::UIConfigure()
{
mTabPanel.Items.SetString("Markers~Setup");
mTabPanel.OnChange.Add(
this, (
FBCallback) &ORDeviceOpticalHybrid_Template_Layout::EventTabPanelChange );
UIConfigureLayout0();
UIConfigureLayout1();
UIConfigureLayout2();
}
void ORDeviceOpticalHybrid_Template_Layout::UIConfigureLayout0()
{
}
void ORDeviceOpticalHybrid_Template_Layout::UIConfigureLayout1()
{
mLayoutCommunication.SetBorder(
"LayoutRegionNetwork",
kFBEmbossBorder,
false,
true,2,1,90.0,0);
mButtonNetworkEnable.Caption = "Use optical test server";
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 );
}
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 );
}
void ORDeviceOpticalHybrid_Template_Layout::UIRefresh()
{
UIRefreshSpreadSheet();
}
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;
}
}
}
void ORDeviceOpticalHybrid_Template_Layout::UIReset()
{
UIResetSpreadSheet();
}
void ORDeviceOpticalHybrid_Template_Layout::UIResetSpreadSheet()
{
mSpreadMarkers.Clear();
int lColumnIndex = -1;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 200;
mSpreadMarkers.ColumnAdd ("X");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.ColumnAdd ("Y");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.ColumnAdd ("Z");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
mSpreadMarkers.ColumnAdd ("Occlusion");
lColumnIndex++;
mSpreadMarkers.GetColumn(lColumnIndex).Width = 60;
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;
}
}
void ORDeviceOpticalHybrid_Template_Layout::EventTabPanelChange(
HISender pSender,
HKEvent pEvent )
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl("MainLayout", mLayoutMarkers ); break;
case 1: SetControl("MainLayout", mLayoutSetup ); break;
}
}
void ORDeviceOpticalHybrid_Template_Layout::EventButtonNetworkEnableClick(
HISender pSender,
HKEvent pEvent )
{
mDevice->SetNetworkUse(((int)mButtonNetworkEnable.State)==1);
}
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;
}
void ORDeviceOpticalHybrid_Template_Layout::EventEditNetworkAddressChange(
HISender pSender,
HKEvent pEvent )
{
mDevice->SetNetworkAddress(mEditNetworkAddress.Text.AsString());
mEditNetworkAddress.Text = mDevice->GetNetworkAddress();
}
void ORDeviceOpticalHybrid_Template_Layout::EventButtonCreateRigidBodyClick(
HISender pSender,
HKEvent pEvent )
{
mDevice->RigidBodySetup();
}
void ORDeviceOpticalHybrid_Template_Layout::EventDeviceStatusChange(
HISender pSender,
HKEvent pEvent )
{
UIReset();
}
void ORDeviceOpticalHybrid_Template_Layout::EventUIIdle(
HISender pSender,
HKEvent pEvent )
{
if(mDevice->Online)
{
UIRefresh();
}
}
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);
}
for(int i = 0; i < pParent->Children.GetCount(); i++)
{
SetupMapping(pCharacter,pParent->Children[i]);
}
}
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);
}
}
}