tools/toolimportexport/ortoolimportexport_tool.cxx

tools/toolimportexport/ortoolimportexport_tool.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 declaration
#include "ortoolimportexport_tool.h"
//--- Registration defines
#define ORTOOLIMPORTEXPORT__CLASS ORTOOLIMPORTEXPORT__CLASSNAME
#define ORTOOLIMPORTEXPORT__LABEL "Import Export"
#define ORTOOLIMPORTEXPORT__DESC "OR - ImportExport Tool Description"
//--- FiLMBOX Registration & Implementation.
FBToolImplementation( ORTOOLIMPORTEXPORT__CLASS );
FBRegisterTool ( ORTOOLIMPORTEXPORT__CLASS,
ORTOOLIMPORTEXPORT__LABEL,
ORTOOLIMPORTEXPORT__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
#define IMPORT_EXPORT_FILTERS "*.bvh;*.htr;*.trc;*.c3d;*.fbx;*.3ds;*.dxf;*.obj"
/************************************************
* FiLMBOX Constructor.
************************************************/
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;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORToolImportExport::FBDestroy()
{
OnShow.Remove( this, (FBCallback) &ORToolImportExport::EventToolShow );
OnIdle.Remove( this, (FBCallback) &ORToolImportExport::EventToolIdle );
}
/************************************************
* Create the UI.
************************************************/
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;
//
// Create regions
//
AddRegion( "TabPanel", "TabPanel",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
-lS, kFBAttachRight, "", 1.0,
25, kFBAttachNone, NULL, 1.0 );
AddRegion( "Layout", "Layout",
0, kFBAttachLeft, "TabPanel", 1.0,
lS, kFBAttachBottom, "TabPanel", 1.0,
0, kFBAttachRight, "TabPanel", 1.0,
-lS, kFBAttachBottom, "", 1.0 );
// Import
mLayout[0].AddRegion( "LabelImportFile", "LabelImportFile",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
-lS, kFBAttachRight, "", 1.0,
20, kFBAttachNone, NULL, 1.0 );
mLayout[0].AddRegion( "EditImportFile", "EditImportFile",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachBottom, "LabelImportFile", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
mLayout[0].AddRegion( "ButtonBrowseImportFile", "ButtonBrowseImportFile",
lS, kFBAttachRight, "EditImportFile", 1.0,
lS, kFBAttachBottom, "LabelImportFile", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
mLayout[0].AddRegion( "ButtonMatchModelsCheckbox", "ButtonMatchModelsCheckbox",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachBottom, "EditImportFile", 1.0,
100, kFBAttachNone, NULL, 1.0,
lListH, kFBAttachNone, NULL, 1.0 );
mLayout[0].AddRegion( "ButtonImport", "ButtonImport",
lS, kFBAttachLeft, "", 1.0,
lS * 4, kFBAttachBottom, "ButtonMatchModelsCheckbox", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
// Export
mLayout[1].AddRegion( "LabelExportFile", "LabelExportFile",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachTop, "", 1.0,
-lS, kFBAttachRight, "", 1.0,
20, kFBAttachNone, NULL, 1.0 );
mLayout[1].AddRegion( "EditExportFile", "EditExportFile",
lS, kFBAttachLeft, "", 1.0,
lS, kFBAttachBottom, "LabelExportFile", 1.0,
lEditW, kFBAttachNone, NULL, 1.0,
lEditH, kFBAttachNone, NULL, 1.0 );
mLayout[1].AddRegion( "ButtonBrowseExportFile", "ButtonBrowseExportFile",
lS, kFBAttachRight, "EditExportFile", 1.0,
lS, kFBAttachBottom, "LabelExportFile", 1.0,
lBrowseW, kFBAttachNone, NULL, 1.0,
lBrowseH, kFBAttachNone, NULL, 1.0 );
mLayout[1].AddRegion( "ButtonExport", "ButtonExport",
lS, kFBAttachLeft, "", 1.0,
lS * 4, kFBAttachBottom, "EditExportFile", 1.0,
lButtonW, kFBAttachNone, NULL, 1.0,
lButtonH, kFBAttachNone, NULL, 1.0 );
//
// Assign regions
//
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()
{
//
// Configuration
//
mLabelImportFile.Caption = "File to import :";
mLabelExportFile.Caption = "File to create :";
mButtonBrowseImportFile.Caption = "...";
mButtonBrowseExportFile.Caption = "...";
mButtonImport.Caption = "Import";
mButtonExport.Caption = "Export";
mButtonMatchModelsCheckbox.Style = kFB2States;
mButtonMatchModelsCheckbox.Caption = "Match models";
mTabPanel.Items.SetString( "Import~Export" );
//
// Callbacks
//
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()
{
}
/************************************************
* TabPanelChange event.
************************************************/
void ORToolImportExport::EventTabPanelChange( HISender pSender, HKEvent pEvent )
{
//
// Change the current layout
//
switch( mTabPanel.ItemIndex )
{
case 0: SetControl( "Layout", mLayout[0] ); break;
case 1: SetControl( "Layout", mLayout[1] ); break;
}
}
/************************************************
* ButtonBrowseImportFileClick event.
************************************************/
void ORToolImportExport::EventButtonBrowseImportFileClick( HISender pSender, HKEvent pEvent )
{
//
// Show the file popup to select the file
//
FBFilePopup lFilePopup;
lFilePopup.Caption = "Open";
lFilePopup.Filter = IMPORT_EXPORT_FILTERS;
lFilePopup.Path = "";
lFilePopup.Style = kFBFilePopupOpen;
lFilePopup.Execute();
//
// Set the path in the edit box
//
mEditImportFile.Text = (const char*)lFilePopup.FullFilename;
}
/************************************************
* ButtonBrowseExportFileClick event.
************************************************/
void ORToolImportExport::EventButtonBrowseExportFileClick( HISender pSender, HKEvent pEvent )
{
//
// Show the file popup to select the file
//
FBFilePopup lFilePopup;
lFilePopup.Caption = "Save";
lFilePopup.Filter = IMPORT_EXPORT_FILTERS;
lFilePopup.Path = "";
lFilePopup.Style = kFBFilePopupSave;
lFilePopup.Execute();
//
// Set the path in the edit box
//
mEditExportFile.Text = (const char*)lFilePopup.FullFilename;
}
/************************************************
* ButtonImportClick event.
************************************************/
void ORToolImportExport::EventButtonImportClick( HISender pSender, HKEvent pEvent )
{
bool lResult = false;
//
// Import the file into the specified take.
//
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 );
}
}
/************************************************
* ButtonExportClick event.
************************************************/
void ORToolImportExport::EventButtonExportClick( HISender pSender, HKEvent pEvent )
{
bool lResult = false;
//
// Export the selected take into a file
//
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 );
}
}
/************************************************
* Show event.
************************************************/
void ORToolImportExport::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
UIReset();
}
else
{
}
}
/************************************************
* UI Idle event.
************************************************/
void ORToolImportExport::EventToolIdle( HISender pSender, HKEvent pEvent )
{
UIRefresh();
}