devices/devicemocap/ordevicemocap_layout.cxx

devices/devicemocap/ordevicemocap_layout.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2013 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 <direct.h>
#include "ordevicemocap_device.h"
#include "ordevicemocap_layout.h"
#define ORDEVICEMOCAP_LAYOUT ORDeviceMocapLayout
//--- FiLMBOX implementation and registration
FBDeviceLayoutImplementation( ORDEVICEMOCAP_LAYOUT );
FBRegisterDeviceLayout ( ORDEVICEMOCAP_LAYOUT,
ORDEVICEMOCAP_CLASSSTR,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX constructor.
************************************************/
bool ORDeviceMocapLayout::FBCreate()
{
// Get a handle on the device.
mDevice = ((ORDeviceMocap *)(FBDevice *)Device);
// Create/configure UI
UICreate ();
UIConfigure ();
UIReset ();
// Add device & system callbacks
mDevice->OnStatusChange.Add ( this,(FBCallback)&ORDeviceMocapLayout::EventDeviceStatusChange );
FBSystem().OnUIIdle.Add ( this,(FBCallback)&ORDeviceMocapLayout::EventUIIdle );
return true;
}
/************************************************
* FiLMBOX destructor.
************************************************/
void ORDeviceMocapLayout::FBDestroy()
{
// Remove device & system callbacks
FBSystem().OnUIIdle.Remove ( this,(FBCallback)&ORDeviceMocapLayout::EventUIIdle );
mDevice->OnStatusChange.Remove ( this,(FBCallback)&ORDeviceMocapLayout::EventDeviceStatusChange );
// Remove the buttons callbacks
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 );
//mButtonStop.OnClick.Remove ( this, (FBCallback)&ORDeviceMocapLayout::EventFileIOStop );
}
/************************************************
* Create the UI.
************************************************/
void ORDeviceMocapLayout::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", mLayoutSetup );
// Create sub layouts
UICreateLayoutJoints();
UICreateLayoutSetup();
}
/************************************************
* Create the joints layout.
************************************************/
void ORDeviceMocapLayout::UICreateLayoutJoints()
{
// Add regions
mLayoutJoints.AddRegion( "SpreadJoints", "SpreadJoints",
0, kFBAttachLeft, "", 1.00,
0, kFBAttachTop, "", 1.00,
0, kFBAttachRight, "", 1.00,
0, kFBAttachBottom, "", 1.00 );
// Assign regions
mLayoutJoints.SetControl( "SpreadJoints", mSpreadJoints );
}
/************************************************
* Create the setup layout.
************************************************/
void ORDeviceMocapLayout::UICreateLayoutSetup()
{
int lS = 4;
int lW = 200;
int lH = 18;
// mLableTargetCharacter
mLayoutSetup.AddRegion( "LableTargetCharacter", "LableTargetCharacter",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachTop, "", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "LableTargetCharacter", mLableTargetCharacter );
// mEditTargetCharacter
mLayoutSetup.AddRegion( "EditTargetCharacter", "EditTargetCharacter",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "LableTargetCharacter", 1.00,
lW * 2, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "EditTargetCharacter", mEditTargetCharacter );
// mButtonTargetCharacter
mLayoutSetup.AddRegion( "ButtonTargetCharacter", "ButtonTargetCharacter",
lS, kFBAttachRight, "EditTargetCharacter", 1.00,
0, kFBAttachTop, "EditTargetCharacter", 1.00,
20, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "ButtonTargetCharacter", mButtonTargetCharacter );
// mLableClip
mLayoutSetup.AddRegion( "LableClip", "LableClip",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "EditTargetCharacter", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "LableClip", mLableClip );
// mEditClip
mLayoutSetup.AddRegion( "EditClip", "EditClip",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "LableClip", 1.00,
lW * 2, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "EditClip", mEditClip );
// mButtonClip
mLayoutSetup.AddRegion( "ButtonClip", "ButtonClip",
lS, kFBAttachRight, "EditClip", 1.00,
0, kFBAttachTop, "EditClip", 1.00,
20, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "ButtonClip", mButtonClip );
// mLabelRecording
mLayoutSetup.AddRegion ( "LabelRecording", "LabelRecording",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "EditClip", 1.00,
lW*2, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "LabelRecording", mLabelRecording );
// mButtonRecording
mLayoutSetup.AddRegion ( "ButtonRecording", "ButtonRecording",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "LabelRecording", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "ButtonRecording", mButtonRecording );
// mLabelCalibration
mLayoutSetup.AddRegion ( "LabelCalibration", "LabelCalibration",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "ButtonRecording", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "LabelCalibration", mLabelCalibration );
// mButtonCalibration
mLayoutSetup.AddRegion ( "ButtonCalibration", "ButtonCalibration",
lS, kFBAttachLeft, "", 1.00,
lS, kFBAttachBottom, "LabelCalibration", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "ButtonCalibration", mButtonCalibration );
if( IsMocapDataFileExisting() )
{
// mButtonExport
mLayoutSetup.AddRegion ( "ButtonExport", "ButtonExport",
300, kFBAttachRight, "LableTargetCharacter", 1.00,
0, kFBAttachTop, "LableTargetCharacter", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "ButtonExport", mButtonExport );
// mButtonImport
mLayoutSetup.AddRegion ( "ButtonImport", "ButtonImport",
0, kFBAttachLeft, "ButtonExport", 1.00,
lS, kFBAttachBottom, "ButtonExport", 1.00,
lW, kFBAttachNone, NULL, 1.00,
lH, kFBAttachNone, NULL, 1.00 );
mLayoutSetup.SetControl( "ButtonImport", mButtonImport );
//mLayoutSetup.AddRegion ( "ButtonStop", "ButtonStop",
// 0, kFBAttachLeft, "ButtonImport", 1.00,
// lS, kFBAttachBottom, "ButtonImport", 1.00,
// lW, kFBAttachNone, NULL, 1.00,
// lH, kFBAttachNone, NULL, 1.00 );
//mLayoutSetup.SetControl( "ButtonStop", mButtonStop );
}
}
/************************************************
* Configure the UI elements (main layout).
************************************************/
void ORDeviceMocapLayout::UIConfigure()
{
SetBorder ("MainLayout", kFBStandardBorder, false,true, 1, 0,90,0);
mTabPanel.Items.SetString("Setup~Joints");
mTabPanel.OnChange.Add( this, (FBCallback)&ORDeviceMocapLayout::EventTabPanelChange );
UIConfigureLayoutJoints();
UIConfigureLayoutSetup();
}
/************************************************
* Configure the UI elements (joint layout).
************************************************/
void ORDeviceMocapLayout::UIConfigureLayoutJoints()
{
}
/************************************************
* Configure the UI elements (setup layout).
************************************************/
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 );
//mButtonStop.Caption = "Stop";
//mButtonStop.OnClick.Add( this, (FBCallback)&ORDeviceMocapLayout::EventFileIOStop );
EnableDisableButtons();
}
/************************************************
* Refresh the UI.
************************************************/
void ORDeviceMocapLayout::UIRefresh()
{
UIRefreshSpreadSheet();
}
/************************************************
* Refresh the spreadsheet content.
************************************************/
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) );
}
}
/************************************************
* Reset the UI values from device.
************************************************/
void ORDeviceMocapLayout::UIReset()
{
UIResetSpreadSheet();
}
/************************************************
* Re-build the spreadsheet.
************************************************/
void ORDeviceMocapLayout::UIResetSpreadSheet()
{
int i;
mSpreadJoints.Clear();
// Spreadsheet
int lColumnIndex = -1;
mSpreadJoints.GetColumn(lColumnIndex).Width = 200;
// column 0: Translation X
mSpreadJoints.ColumnAdd ("PosX");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 1: Translation Y
mSpreadJoints.ColumnAdd ("PosY");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 2: Translation Z
mSpreadJoints.ColumnAdd ("PosZ");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 3: Rotation X
mSpreadJoints.ColumnAdd ("RotX");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 4: Rotation Y
mSpreadJoints.ColumnAdd ("RotY");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
// column 5: Rotation Z
mSpreadJoints.ColumnAdd ("RotZ");
lColumnIndex++;
mSpreadJoints.GetColumn(lColumnIndex).Width = 60;
mSpreadJoints.GetColumn(lColumnIndex).Style = kFBCellStyleDouble;
{
mSpreadJoints.RowAdd( mDevice->GetChannelName(i), i );
mSpreadJoints.GetCell(i,lColumnIndex).ReadOnly = true;
}
}
/************************************************
* Events
************************************************/
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();
}
void ORDeviceMocapLayout::EventUIIdle( HISender pSender, HKEvent pEvent )
{
if( mDevice->Online )
{
UIRefresh();
EnableDisableButtons();
}
}
void ORDeviceMocapLayout::EventTargetCharacterPath( HISender pSender, HKEvent pEvent )
{
FBFilePopup lPopup;
lPopup.Caption = "FBX file to load";
lPopup.Style = kFBFilePopupOpen;
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;
}
// Note: Must move the file merging step into UI Idle time as file merging causes layout destroy,
// which causes the UI assert when it still invoking this destroyed button event callback.
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() )
{
// Do calibration
static bool gMuteCalibrationPopDialog = false;
if( !gMuteCalibrationPopDialog )
{
FBMessageBoxWithCheck("Mocap Device Info:",
"Stand in front of the camera for calibration",
"OK", NULL, NULL,
"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 )
FBMessageBoxWithCheck("Mocap Device Info:",
"Cannot export now as importing is in progress",
"OK", NULL, NULL,
"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 )
FBMessageBoxWithCheck("Mocap Device Info:",
"Cannot import now as exporting is in progress",
"OK", NULL, NULL,
"Don't show this dialog", gCannotImportNowDialog
);
return;
}
mDevice->SetFileIOStatus(eFileIOImport_Loading);
}
//void ORDeviceMocapLayout::EventFileIOStop( HISender pSender, HKEvent pEvent )
//{
// mDevice->SetFileIOStatus(eStop);
//}
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;
}
}