#include "orimpexpsample_tool.h"
#define ORTOOLSAMPLE__CLASS ORTOOLSAMPLE__CLASSNAME
#define ORTOOLSAMPLE__LABEL "Sampled data"
#define ORTOOLSAMPLE__DESC "OR - Export sampled data"
ORTOOLSAMPLE__LABEL,
ORTOOLSAMPLE__DESC,
bool ORToolSample::FBCreate()
{
mExporting = false;
mFileOpen = false;
mCriticalSection.Init();
UICreate ();
UIConfigure ();
OnIdle.Add(
this, (
FBCallback) &ORToolSample::EventToolIdle );
return true;
}
void ORToolSample::FBDestroy()
{
OnIdle.Remove(
this, (
FBCallback) &ORToolSample::EventToolIdle );
}
void ORToolSample::UICreate()
{
int lW = 200;
int lS = 5;
int lH = 25;
AddRegion ("EditExportFile", "EditExportFile",
AddRegion ("EditNumberRate", "EditNumberRate",
AddRegion ("ButtonExport", "ButtonExport",
SetControl( "EditExportFile", mEditExportFile );
SetControl( "EditNumberRate", mEditNumberRate );
SetControl( "ButtonExport", mButtonExport );
}
void ORToolSample::UIConfigure()
{
mEditNumberRate.Min = 1.0;
mEditNumberRate.Max = 100.0;
mEditNumberRate.Precision = 3.2;
mEditNumberRate.SmallStep = 0.1;
mEditNumberRate.LargeStep = 1.0;
mEditNumberRate.Value = 10.0;
mButtonExport.Caption = "Export";
mEditExportFile.Text = "C:\\orimpexpsample.txt";
mButtonExport.OnClick.Add (
this,(
FBCallback)&ORToolSample::EventButtonExportClick );
}
{
if( mButtonExport.State == 0 && mExporting )
{
ExportStop();
}
if( mButtonExport.State == 1 )
{
mExportFile = fopen( mEditExportFile.Text, "wt" );
if( mExportFile )
{
mFileOpen = true;
ExportStart();
}
else
{
mButtonExport.State = 0;
}
}
}
{
if( mExporting )
{
if( (((FBTime)mSystem.LocalTime) > ((FBTimeSpan)mSystem.CurrentTake->LocalTimeSpan).GetStop() ) )
{
ExportStop();
}
else
{
ExportCurrentAndStep();
}
}
}
void ORToolSample::ExportStart()
{
mCriticalSection.Enter();
{
mExportPeriod.SetSecondDouble( 1.0 / ((double)mEditNumberRate.Value) );
mModelList.Clear();
mOriginalTime = mSystem.LocalTime;
mPlayerControl.Goto( ((FBTimeSpan)mSystem.CurrentTake->LocalTimeSpan).GetStart() );
mExporting = true;
}
mCriticalSection.Leave();
}
void ORToolSample::ExportStop()
{
mCriticalSection.Enter();
{
mExporting = false;
mButtonExport.State = 0;
mPlayerControl.Goto( mOriginalTime );
mFileOpen = false;
fclose( mExportFile );
}
mCriticalSection.Leave();
}
void ORToolSample::ExportCurrentAndStep()
{
mCriticalSection.Enter();
{
ExportCurrent();
mPlayerControl.Goto( (FBTime)mSystem.LocalTime + mExportPeriod );
}
mCriticalSection.Leave();
}
void ORToolSample::ExportCurrent()
{
if( mFileOpen )
{
fprintf( mExportFile, "[%s]", (char*)(((FBTime)mSystem.LocalTime).GetTimeString()) );
for(
int i=0;
i<mModelList.GetCount();
i++ )
{
fprintf( mExportFile, "\t" );
fprintf( mExportFile, "<%s> { T(%3.2f,%3.2f,%3.2f), R(%3.2f,%3.2f,%3.2f), S(%3.2f,%3.2f,%3.2f) }",
(
const char*)(mModelList[
i]->
Name),
lPos[0],lPos[1],lPos[2],
lRot[0],lRot[1],lRot[2],
lSca[0],lSca[1],lSca[2] );
}
fprintf( mExportFile, "\n" );
}
}