#include <direct.h>
#include "ordevicemocap_device.h"
#include "ordevicemocap_layout.h"
#define ORDEVICEMOCAP_LAYOUT ORDeviceMocapLayout
ORDEVICEMOCAP_CLASSSTR,
bool ORDeviceMocapLayout::FBCreate()
{
mDevice = ((ORDeviceMocap *)(FBDevice *)Device);
UICreate ();
UIConfigure ();
UIReset ();
mDevice->OnStatusChange.Add (
this,(
FBCallback)&ORDeviceMocapLayout::EventDeviceStatusChange );
FBSystem().OnUIIdle.Add (
this,(
FBCallback)&ORDeviceMocapLayout::EventUIIdle );
return true;
}
void ORDeviceMocapLayout::FBDestroy()
{
FBSystem().OnUIIdle.Remove (
this,(
FBCallback)&ORDeviceMocapLayout::EventUIIdle );
mDevice->OnStatusChange.Remove (
this,(
FBCallback)&ORDeviceMocapLayout::EventDeviceStatusChange );
mTabPanel.OnChange.Remove (
this, (
FBCallback)&ORDeviceMocapLayout::EventTabPanelChange );
mButtonTargetCharacter.OnClick.Remove(
this, (
FBCallback)&ORDeviceMocapLayout::EventTargetCharacterPath );
mButtonClip.OnClick.Remove (
this, (
FBCallback)&ORDeviceMocapLayout::EventClipPath );
mButtonRecording.OnClick.Remove (
this, (
FBCallback)&ORDeviceMocapLayout::EventSetupRecording );
mButtonCalibration.OnClick.Remove (
this, (
FBCallback)&ORDeviceMocapLayout::EventCalibration );
mButtonExport.OnClick.Remove (
this, (
FBCallback)&ORDeviceMocapLayout::EventFileIOExport );
mButtonImport.OnClick.Remove (
this, (
FBCallback)&ORDeviceMocapLayout::EventFileIOImport );
}
void ORDeviceMocapLayout::UICreate()
{
int lS, lH;
lS = 4;
lH = 25;
AddRegion (
"MainLayout",
"MainLayout", lS,
kFBAttachLeft,
"TabPanel", 1.00,
SetControl ( "TabPanel", mTabPanel );
SetControl ( "MainLayout", mLayoutSetup );
UICreateLayoutJoints();
UICreateLayoutSetup();
}
void ORDeviceMocapLayout::UICreateLayoutJoints()
{
mLayoutJoints.AddRegion( "SpreadJoints", "SpreadJoints",
mLayoutJoints.SetControl( "SpreadJoints", mSpreadJoints );
}
void ORDeviceMocapLayout::UICreateLayoutSetup()
{
int lS = 4;
int lW = 200;
int lH = 18;
mLayoutSetup.AddRegion( "LableTargetCharacter", "LableTargetCharacter",
mLayoutSetup.SetControl( "LableTargetCharacter", mLableTargetCharacter );
mLayoutSetup.AddRegion( "EditTargetCharacter", "EditTargetCharacter",
mLayoutSetup.SetControl( "EditTargetCharacter", mEditTargetCharacter );
mLayoutSetup.AddRegion( "ButtonTargetCharacter", "ButtonTargetCharacter",
mLayoutSetup.SetControl( "ButtonTargetCharacter", mButtonTargetCharacter );
mLayoutSetup.AddRegion( "LableClip", "LableClip",
mLayoutSetup.SetControl( "LableClip", mLableClip );
mLayoutSetup.AddRegion( "EditClip", "EditClip",
mLayoutSetup.SetControl( "EditClip", mEditClip );
mLayoutSetup.AddRegion( "ButtonClip", "ButtonClip",
mLayoutSetup.SetControl( "ButtonClip", mButtonClip );
mLayoutSetup.AddRegion ( "LabelRecording", "LabelRecording",
mLayoutSetup.SetControl( "LabelRecording", mLabelRecording );
mLayoutSetup.AddRegion ( "ButtonRecording", "ButtonRecording",
mLayoutSetup.SetControl( "ButtonRecording", mButtonRecording );
mLayoutSetup.AddRegion ( "LabelCalibration", "LabelCalibration",
mLayoutSetup.SetControl( "LabelCalibration", mLabelCalibration );
mLayoutSetup.AddRegion ( "ButtonCalibration", "ButtonCalibration",
mLayoutSetup.SetControl( "ButtonCalibration", mButtonCalibration );
if( IsMocapDataFileExisting() )
{
mLayoutSetup.AddRegion ( "ButtonExport", "ButtonExport",
mLayoutSetup.SetControl( "ButtonExport", mButtonExport );
mLayoutSetup.AddRegion ( "ButtonImport", "ButtonImport",
mLayoutSetup.SetControl( "ButtonImport", mButtonImport );
}
}
void ORDeviceMocapLayout::UIConfigure()
{
mTabPanel.Items.SetString("Setup~Joints");
mTabPanel.OnChange.Add(
this, (
FBCallback)&ORDeviceMocapLayout::EventTabPanelChange );
UIConfigureLayoutJoints();
UIConfigureLayoutSetup();
}
void ORDeviceMocapLayout::UIConfigureLayoutJoints()
{
}
void ORDeviceMocapLayout::UIConfigureLayoutSetup()
{
mLableTargetCharacter.Caption = "Character Path";
mButtonTargetCharacter.Caption = "...";
mButtonTargetCharacter.OnClick.Add(
this, (
FBCallback)&ORDeviceMocapLayout::EventTargetCharacterPath );
FBString lBinPath( FBSystem().ApplicationPath );
mEditTargetCharacter.Text = lBinPath + "//..//..//OpenRealitySDK//Scenes//Male_01.fbx";
mEditClip.Text = FBString(FBSystem().UserConfigPath) + "//..//recording";
if( !FileExist( mEditClip.Text ) )
{
_mkdir(mEditClip.Text.AsString());
}
mLableClip.Caption = "Recording Path";
mButtonClip.Caption = "...";
mButtonClip.OnClick.Add(
this, (
FBCallback)&ORDeviceMocapLayout::EventClipPath );
mLabelRecording.Caption = "";
mButtonRecording.Caption = "Setup Recording";
mButtonRecording.OnClick.Add(
this, (
FBCallback)&ORDeviceMocapLayout::EventSetupRecording );
mLabelCalibration.Caption = "";
mButtonCalibration.Caption = "Calibration";
mButtonCalibration.OnClick.Add(
this, (
FBCallback)&ORDeviceMocapLayout::EventCalibration );
if( mDevice->GetFileIOStatus() == eFileIOExport_WaitForCalibration )
mButtonExport.Caption = "Stop Exporting";
else
mButtonExport.Caption = "Start Exporting";
mButtonExport.OnClick.Add(
this, (
FBCallback)&ORDeviceMocapLayout::EventFileIOExport );
mButtonImport.Caption = "Import";
mButtonImport.OnClick.Add(
this, (
FBCallback)&ORDeviceMocapLayout::EventFileIOImport );
EnableDisableButtons();
}
void ORDeviceMocapLayout::UIRefresh()
{
UIRefreshSpreadSheet();
}
void ORDeviceMocapLayout::UIRefreshSpreadSheet()
{
{
mSpreadJoints.SetCell(
i, 0, mDevice->GetDataTX(
i) );
mSpreadJoints.SetCell(
i, 1, mDevice->GetDataTY(
i) );
mSpreadJoints.SetCell(
i, 2, mDevice->GetDataTZ(
i) );
mSpreadJoints.SetCell(
i, 3, mDevice->GetDataRX(
i) );
mSpreadJoints.SetCell(
i, 4, mDevice->GetDataRY(
i) );
mSpreadJoints.SetCell(
i, 5, mDevice->GetDataRZ(
i) );
}
}
void ORDeviceMocapLayout::UIReset()
{
UIResetSpreadSheet();
}
void ORDeviceMocapLayout::UIResetSpreadSheet()
{
mSpreadJoints.Clear();
int lColumnIndex = -1;
mSpreadJoints.GetColumn(lColumnIndex).Width = 200;
mSpreadJoints.ColumnAdd ("PosX");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.ColumnAdd ("PosY");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.ColumnAdd ("PosZ");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.ColumnAdd ("RotX");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.ColumnAdd ("RotY");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.ColumnAdd ("RotZ");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
{
mSpreadJoints.RowAdd( mDevice->GetChannelName(i),
i );
mSpreadJoints.GetCell(i,lColumnIndex).ReadOnly = true;
}
}
void ORDeviceMocapLayout::EventTabPanelChange(
HISender pSender,
HKEvent pEvent )
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl("MainLayout", mLayoutSetup ); break;
case 1: SetControl("MainLayout", mLayoutJoints ); break;
}
}
void ORDeviceMocapLayout::EventDeviceStatusChange(
HISender pSender,
HKEvent pEvent )
{
UIReset();
}
{
if( mDevice->Online )
{
UIRefresh();
EnableDisableButtons();
}
}
void ORDeviceMocapLayout::EventTargetCharacterPath(
HISender pSender,
HKEvent pEvent )
{
FBFilePopup lPopup;
lPopup.Caption = "FBX file to load";
lPopup.Filter = "*.fbx";
if( lPopup.Execute() )
{
mEditTargetCharacter.Text = lPopup.FullFilename;
}
}
void ORDeviceMocapLayout::EventClipPath(
HISender pSender,
HKEvent pEvent )
{
FBFolderPopup lPopup;
lPopup.Caption = "Clip directory to save";
if( lPopup.Execute() )
{
mEditClip.Text = lPopup.Path;
}
}
void ORDeviceMocapLayout::EventSetupRecording(
HISender pSender,
HKEvent pEvent )
{
if( mDevice->GetOperationState() < eAskForPressSetupRecording )
{
EnableDisableButtons();
return;
}
FBString lCharacterPath = mEditTargetCharacter.Text;
FBString lClipDirectory = mEditClip.Text;
mDevice->PrepareSetupRecording(lCharacterPath, lClipDirectory);
}
void ORDeviceMocapLayout::EventCalibration(
HISender pSender,
HKEvent pEvent )
{
if( mDevice->GetOperationState() < eAskForPressCalibration )
{
EnableDisableButtons();
return;
}
if( mDevice->TriggerMocapCalibration() )
{
static bool gMuteCalibrationPopDialog = false;
if( !gMuteCalibrationPopDialog )
{
"Stand in front of the camera for calibration",
"Don't show this dialog", gMuteCalibrationPopDialog
);
}
}
return;
}
void ORDeviceMocapLayout::EventFileIOExport(
HISender pSender,
HKEvent pEvent )
{
if( mDevice->GetFileIOStatus() == eFileIOImport_Loading ||
mDevice->GetFileIOStatus() == eFileIOImport_WaitForCalibration ||
mDevice->GetFileIOStatus() == eFileIOImport_Pause ||
mDevice->GetFileIOStatus() == eFileIOImport_Start )
{
static bool gCannotExportNowDialog = false;
if( !gCannotExportNowDialog )
"Cannot export now as importing is in progress",
"Don't show this dialog", gCannotExportNowDialog
);
return;
}
if( mDevice->GetFileIOStatus() == eFileIOExport_WaitForCalibration ||
mDevice->GetFileIOStatus() == eFileIOExport_Start )
{
mDevice->SetFileIOStatus(eFileIOExport_Stop);
mButtonExport.Caption = "Start Exporting";
}
else
{
mDevice->SetFileIOStatus(eFileIOExport_WaitForCalibration);
mButtonExport.Caption = "Stop Exporting";
}
}
void ORDeviceMocapLayout::EventFileIOImport(
HISender pSender,
HKEvent pEvent )
{
if( mDevice->GetFileIOStatus() == eFileIOExport_WaitForCalibration ||
mDevice->GetFileIOStatus() == eFileIOExport_Start )
{
static bool gCannotImportNowDialog = false;
if( !gCannotImportNowDialog )
"Cannot import now as exporting is in progress",
"Don't show this dialog", gCannotImportNowDialog
);
return;
}
mDevice->SetFileIOStatus(eFileIOImport_Loading);
}
bool ORDeviceMocapLayout::IsMocapDataFileExisting()
{
FBString lFile = FBString( FBSystem().TheOne().UserConfigPath ) + "//..//recording//mocap.txt";
if( FileExist( lFile ) )
return true;
return false;
}
void ORDeviceMocapLayout::EnableDisableButtons()
{
if( mDevice->GetOperationState() >= eAskForPressSetupRecording )
{
if( !mButtonRecording.Enabled )
mButtonRecording.Enabled = true;
}
else
{
if( mButtonRecording.Enabled )
mButtonRecording.Enabled = false;
}
if( mDevice->GetOperationState() >= eAskForPressCalibration )
{
if( !mButtonCalibration.Enabled )
mButtonCalibration.Enabled = true;
}
else
{
if( mButtonCalibration.Enabled )
mButtonCalibration.Enabled = false;
}
}