tools/toolstory/ortoolstory_tool.cxx

tools/toolstory/ortoolstory_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 "ortoolstory_tool.h"
//--- Registration defines
#define ORTOOLSTORY__CLASS ORTOOLSTORY__CLASSNAME
#define ORTOOLSTORY__LABEL "Story Example"
#define ORTOOLSTORY__DESC "FBSDK - Tool Story Description"
//--- FiLMBOX implementation and registration
FBToolImplementation( ORTOOLSTORY__CLASS );
FBRegisterTool ( ORTOOLSTORY__CLASS,
ORTOOLSTORY__LABEL,
ORTOOLSTORY__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORToolStory::FBCreate()
{
StartSize[0] = 200;
StartSize[1] = 68;
// Configure layout
AddRegion( "ButtonTest", "ButtonTest", 10, kFBAttachLeft, "", 1.0,
10, kFBAttachTop, "", 1.0,
-10, kFBAttachRight, "", 1.0,
-10, kFBAttachBottom, "", 1.0);
SetControl( "ButtonTest", mButtonTest );
// Configure button
mButtonTest.OnClick.Add( this, (FBCallback) &ORToolStory::EventButtonTestClick );
mButtonTest.Caption = "Save to 'C:\\ortooltory.txt'";
// Add tool callbacks
OnShow.Add ( this, (FBCallback) &ORToolStory::EventToolShow );
OnIdle.Add ( this, (FBCallback) &ORToolStory::EventToolIdle );
OnResize.Add( this, (FBCallback) &ORToolStory::EventToolResize );
OnPaint.Add ( this, (FBCallback) &ORToolStory::EventToolPaint );
OnInput.Add ( this, (FBCallback) &ORToolStory::EventToolInput );
return true;
}
/************************************************
* FiLMBOX Destruction function.
************************************************/
void ORToolStory::FBDestroy()
{
// Remove tool callbacks
OnShow.Remove ( this, (FBCallback) &ORToolStory::EventToolShow );
OnIdle.Remove ( this, (FBCallback) &ORToolStory::EventToolIdle );
OnPaint.Remove ( this, (FBCallback) &ORToolStory::EventToolPaint );
OnInput.Remove ( this, (FBCallback) &ORToolStory::EventToolInput );
OnResize.Remove ( this, (FBCallback) &ORToolStory::EventToolResize);
// Free user allocated memory
}
/************************************************
* Button click callback.
************************************************/
void ORToolStory::EventButtonTestClick( HISender pSender, HKEvent pEvent )
{
FBStory& lStory = FBStory::TheOne();
FBStoryFolder* lEditFolder = lStory.RootEditFolder;
FBStoryFolder* lActionFolder = lStory.RootFolder;
mFile = fopen( "C:\\ortoolstory.txt", "w");
if( !mFile ) return;
WriteRecursiveFolder(0, lEditFolder);
if( mFile ) fwrite("\n", strlen("\n"), 1, mFile);
WriteRecursiveFolder(0, lActionFolder);
if( mFile )
{
fclose(mFile);
mFile = NULL;
}
}
/************************************************
* UI Idle callback.
************************************************/
void ORToolStory::EventToolIdle( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Handle tool activation (selection/unselection).
************************************************/
void ORToolStory::EventToolShow( HISender pSender, HKEvent pEvent )
{
FBEventShow lEvent( pEvent );
if( lEvent.Shown )
{
// Reset the UI here.
}
else
{
}
}
/************************************************
* Paint callback for tool (on expose).
************************************************/
void ORToolStory::EventToolPaint( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Tool resize callback.
************************************************/
void ORToolStory::EventToolResize( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* Handle input into the tool.
************************************************/
void ORToolStory::EventToolInput( HISender pSender, HKEvent pEvent )
{
}
/************************************************
* FBX Storage.
************************************************/
bool ORToolStory::FbxStore ( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
return true;
}
/************************************************
* FBX Retrieval.
************************************************/
bool ORToolStory::FbxRetrieve( FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat )
{
return true;
}
/************************************************
* FBX Retrieval.
************************************************/
static const char* GetTrackTypeName(FBStoryTrackType pTrackType)
{
switch( pTrackType )
{
case kFBStoryTrackAnimation: return "Animation";
case kFBStoryTrackCamera: return "Camera";
case kFBStoryTrackCharacter: return "Character";
case kFBStoryTrackConstraint: return "Constraint";
case kFBStoryTrackCommand: return "Command";
case kFBStoryTrackShot: return "Shot";
case kFBStoryTrackAudio: return "Audio";
case kFBStoryTrackVideo: return "Video";
default: return "";
}
}
bool ORToolStory::WriteRecursiveFolder(int pCount, FBStoryFolder* pFolder)
{
if( !mFile ) return false;
//Write folder content
WriteFolderContent(pCount, pFolder);
//Do the recursion for every children
int i, c = pFolder->Childs.GetCount();
for( i = 0; i < c; i++ )
{
if( !WriteRecursiveFolder(pCount + 1, pFolder->Childs[i]) ) return false;
}
return true;
}
bool ORToolStory::WriteFolderContent(int pCount, FBStoryFolder* pFolder)
{
if( !mFile ) return false;
FBString lText;
for( int k = 0; k < pCount; k++ ) lText += " ";
lText += " - Folder (Name: ";
lText += pFolder->Name;
lText += ")\n";
fwrite((char*)lText, strlen(lText), 1, mFile);
//Write track content
int i, c = pFolder->Tracks.GetCount();
for( i = 0; i < c; i++ )
{
if( !WriteTrackContent(pCount + 1, pFolder->Tracks[i]) ) return false;
}
return true;
}
bool ORToolStory::WriteTrackContent(int pCount, FBStoryTrack* pTrack)
{
if( !mFile ) return false;
int i, c;
FBString lText;
for( int k = 0; k < pCount; k++ ) lText += " ";
lText += " - ";
lText += GetTrackTypeName(pTrack->Type);
lText += " Track (Name: ";
lText += pTrack->Name;
c = pTrack->Details.GetCount();
if( c > 0 )
{
lText += ", Details:";
for( i = 0; i < c; i++ )
{
lText += " ";
lText += pTrack->Details[i]->Name;
if( i == 2 ) //Limit details print to 3 max (or it will take too much space. only for clarity)
{
lText += " etc...";
break;
}
}
}
lText += ")\n";
fwrite((char*)lText, strlen(lText), 1, mFile);
//Write clip content
c = pTrack->Clips.GetCount();
for( i = 0; i < c; i++ )
{
if( !WriteClipContent(pCount + 1, pTrack->Clips[i], pTrack->Type) ) return false;
}
return true;
}
bool ORToolStory::WriteClipContent(int pCount, FBStoryClip* pClip, FBStoryTrackType pTrackType)
{
if( !mFile ) return false;
FBTime lInTime = pClip->Start;
FBTime lOutTime = pClip->Stop;
char lSpeed[32];
sprintf(lSpeed, "%0.2f", double(pClip->Speed));
FBString lText;
for( int k = 0; k < pCount; k++ ) lText += " ";
lText += " - Clip (Name: ";
lText += pClip->Name;
lText += ", Speed: ";
lText += lSpeed;
if( pTrackType == kFBStoryTrackShot )
{
lText += ", Camera: ";
FBCamera* lCamera = pClip->ShotCamera; //lCamera can be NULL
if( lCamera ) lText += lCamera->Name;
else lText += "<None>";
FBTime lStart = pClip->ShotActionStart;
FBTime lStop = pClip->ShotActionStop;
lText += ", ActionStart: ";
lText += lStart.GetTimeString();
lText += ", ActionStop: ";
lText += lStop.GetTimeString();
}
else if( pTrackType == kFBStoryTrackAudio )
{
lText += ", AudioFile: ";
FBAudioClip* lAudio = pClip->AudioClip; //lAudio can be NULL
if( lAudio ) lText += lAudio->Filename;
else lText += "<None>";
}
else if( pTrackType == kFBStoryTrackVideo )
{
/* lText += ", VideoFile: ";
FBVideoClip* lVideo = pClip->VideoClip; //lVideo can be NULL
if( lVideo ) lText += lVideo->Name;
else lText += "<None>"; */
}
lText += ", InTime: ";
lText += lInTime.GetTimeString();
lText += ", OutTime: ";
lText += lOutTime.GetTimeString();
lText += ")\n";
fwrite((char*)lText, strlen(lText), 1, mFile);
return true;
}