#include "ortoolimportexport_tool.h"
#define ORTOOLIMPORTEXPORT__CLASS ORTOOLIMPORTEXPORT__CLASSNAME
#define ORTOOLIMPORTEXPORT__LABEL "Import Export"
#define ORTOOLIMPORTEXPORT__DESC "OR - ImportExport Tool Description"
ORTOOLIMPORTEXPORT__LABEL,
ORTOOLIMPORTEXPORT__DESC,
#define IMPORT_EXPORT_FILTERS "*.bvh;*.htr;*.trc;*.c3d;*.fbx;*.3ds;*.dxf;*.obj"
bool ORToolImportExport::FBCreate()
{
StartSize[0] = 350;
StartSize[1] = 200;
UICreate ();
UIConfigure ();
UIReset ();
OnShow.Add(
this, (
FBCallback) &ORToolImportExport::EventToolShow );
OnIdle.Add(
this, (
FBCallback) &ORToolImportExport::EventToolIdle );
return true;
}
void ORToolImportExport::FBDestroy()
{
OnShow.Remove(
this, (
FBCallback) &ORToolImportExport::EventToolShow );
OnIdle.Remove(
this, (
FBCallback) &ORToolImportExport::EventToolIdle );
}
void ORToolImportExport::UICreate()
{
int lS = 4;
int lEditW = 300;
int lEditH = 18;
int lListH = 18;
int lButtonW = 100;
int lButtonH = 18;
int lBrowseW = 20;
int lBrowseH = 18;
AddRegion( "TabPanel", "TabPanel",
AddRegion( "Layout", "Layout",
mLayout[0].AddRegion( "LabelImportFile", "LabelImportFile",
mLayout[0].AddRegion( "EditImportFile", "EditImportFile",
mLayout[0].AddRegion( "ButtonBrowseImportFile", "ButtonBrowseImportFile",
mLayout[0].AddRegion( "ButtonMatchModelsCheckbox", "ButtonMatchModelsCheckbox",
mLayout[0].AddRegion( "ButtonImport", "ButtonImport",
mLayout[1].AddRegion( "LabelExportFile", "LabelExportFile",
mLayout[1].AddRegion( "EditExportFile", "EditExportFile",
mLayout[1].AddRegion( "ButtonBrowseExportFile", "ButtonBrowseExportFile",
mLayout[1].AddRegion( "ButtonExport", "ButtonExport",
SetControl( "TabPanel", mTabPanel );
SetControl( "Layout", mLayout[0] );
mLayout[0].SetControl( "LabelImportFile", mLabelImportFile );
mLayout[0].SetControl( "EditImportFile", mEditImportFile );
mLayout[0].SetControl( "ButtonMatchModelsCheckbox", mButtonMatchModelsCheckbox );
mLayout[0].SetControl( "ButtonBrowseImportFile", mButtonBrowseImportFile );
mLayout[0].SetControl( "ButtonImport", mButtonImport );
mLayout[1].SetControl( "LabelExportFile", mLabelExportFile );
mLayout[1].SetControl( "EditExportFile", mEditExportFile );
mLayout[1].SetControl( "ButtonBrowseExportFile", mButtonBrowseExportFile );
mLayout[1].SetControl( "ButtonExport", mButtonExport );
}
void ORToolImportExport::UIConfigure()
{
mLabelImportFile.Caption = "File to import :";
mLabelExportFile.Caption = "File to create :";
mButtonBrowseImportFile.Caption = "...";
mButtonBrowseExportFile.Caption = "...";
mButtonImport.Caption = "Import";
mButtonExport.Caption = "Export";
mButtonMatchModelsCheckbox.Caption = "Match models";
mTabPanel.Items.SetString( "Import~Export" );
mTabPanel.OnChange.Add (
this, (
FBCallback) &ORToolImportExport::EventTabPanelChange );
mButtonBrowseImportFile.OnClick.Add (
this, (
FBCallback) &ORToolImportExport::EventButtonBrowseImportFileClick );
mButtonBrowseExportFile.OnClick.Add (
this, (
FBCallback) &ORToolImportExport::EventButtonBrowseExportFileClick );
mButtonImport.OnClick.Add (
this, (
FBCallback) &ORToolImportExport::EventButtonImportClick );
mButtonExport.OnClick.Add (
this, (
FBCallback) &ORToolImportExport::EventButtonExportClick );
}
void ORToolImportExport::UIReset()
{
}
void ORToolImportExport::UIRefresh()
{
}
void ORToolImportExport::EventTabPanelChange(
HISender pSender,
HKEvent pEvent )
{
switch( mTabPanel.ItemIndex )
{
case 0: SetControl( "Layout", mLayout[0] ); break;
case 1: SetControl( "Layout", mLayout[1] ); break;
}
}
void ORToolImportExport::EventButtonBrowseImportFileClick(
HISender pSender,
HKEvent pEvent )
{
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = IMPORT_EXPORT_FILTERS;
lFilePopup.Path = "";
lFilePopup.Execute();
mEditImportFile.Text = (const char*)lFilePopup.FullFilename;
}
void ORToolImportExport::EventButtonBrowseExportFileClick(
HISender pSender,
HKEvent pEvent )
{
FBFilePopup lFilePopup;
lFilePopup.Caption = "Save";
lFilePopup.Filter = IMPORT_EXPORT_FILTERS;
lFilePopup.Path = "";
lFilePopup.Execute();
mEditExportFile.Text = (const char*)lFilePopup.FullFilename;
}
void ORToolImportExport::EventButtonImportClick(
HISender pSender,
HKEvent pEvent )
{
bool lResult = false;
FBString lFileName( mEditImportFile.Text );
bool lMatchModels = mButtonMatchModelsCheckbox.State != 0;
if( !lFileName.IsEmpty() )
{
lResult = mApplication.FileImport( lFileName, lMatchModels );
}
if( lResult == false )
{
FBMessageBox(
"Import error",
"Could not import the file!",
"OK",
NULL,
NULL, 1 );
}
}
void ORToolImportExport::EventButtonExportClick(
HISender pSender,
HKEvent pEvent )
{
bool lResult = false;
FBString lFileName( mEditExportFile.Text );
if( !lFileName.IsEmpty() )
{
lResult = mApplication.FileExport( lFileName );
}
if( lResult == false )
{
FBMessageBox(
"Export error",
"Could not export the file!",
"OK",
NULL,
NULL, 1 );
}
}
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
{
UIRefresh();
}