void CameraTrackSettingDialog::RefreshCodeText(void)
{
    if (mCameraTrack)
    {
        mCodeText.Clear();
        mCameraInfoListBox->Clear();
        
        mModifySpinCtrl->SetValue("1");

        mPointIndexTextCtrl->Clear();
        mPositionTextCtrl->Clear();
        mOrientationTextCtrl->Clear();
        mTimeTextCtrl->Clear();

        mCodeText += "Ogre::TransformKeyFrame* ";

        for (unsigned short index = 0; index < mCameraTrack->getNumKeyFrames(); ++index)
        {
            Ogre::TransformKeyFrame* keyFrame = static_cast<Ogre::TransformKeyFrame*>( mCameraTrack->getKeyFrame(index) );

            const Ogre::Vector3& pos = keyFrame->getTranslate();
            const Ogre::Quaternion& ori = keyFrame->getRotation();
            float time = keyFrame->getTime();

            mCodeText += "key = mCameraTrack->createNodeKeyFrame(" + Ogre::StringConverter::toString(time) + ");\n";

            mCodeText += "key->setTranslate(Ogre::Vector3(" + Ogre::StringConverter::toString(pos.x) + "," + 
                Ogre::StringConverter::toString(pos.y) + "," + Ogre::StringConverter::toString(pos.z) + "));\n";
            mCodeText += "key->setRotation(Ogre::Quaternion(" + Ogre::StringConverter::toString(ori.w) + "," + 
                Ogre::StringConverter::toString(ori.x) + "," + Ogre::StringConverter::toString(ori.y) + "," +
                Ogre::StringConverter::toString(ori.z) +"));\n";

            // 刷新listbox
            mCameraInfoListBox->Append(Ogre::StringConverter::toString(pos) + "," + 
                Ogre::StringConverter::toString(ori) + "," + Ogre::StringConverter::toString(time));
        }

        mCodeTextCtrl->SetValue(mCodeText);

        mModifySpinCtrl->SetRange(1, mCameraTrack->getNumKeyFrames());
    }
}
void CameraTrackSettingDialog::OnSaveTrack(wxCommandEvent& event)
{
    assert (mCameraTrack);
    assert (mCameraAnimState);

    wxFileDialog fileDialog(this,
        _("Save track file"),
        "",
        "",
        "Track files (*.track)|*.track",
        wxSAVE | wxOVERWRITE_PROMPT);

    if (fileDialog.ShowModal() != wxID_OK)
        return;

    wxString fullFileName = fileDialog.GetPath();

    std::ofstream stream(fullFileName.c_str());
    
    Ogre::String trackStr;

    trackStr += Ogre::StringConverter::toString( mCameraAnimState->getLength() ) + ","
           + Ogre::StringConverter::toString( mCameraTrack->getNumKeyFrames() ) + ",";

    for (unsigned short index = 0; index < mCameraTrack->getNumKeyFrames(); ++index)
    {
        Ogre::TransformKeyFrame* keyFrame = static_cast<Ogre::TransformKeyFrame*>( mCameraTrack->getKeyFrame(index) );

        const Ogre::Vector3& pos = keyFrame->getTranslate();
        const Ogre::Quaternion& ori = keyFrame->getRotation();
        float time = keyFrame->getTime();

        trackStr += Ogre::StringConverter::toString(pos) + ","
            + Ogre::StringConverter::toString(ori) + ","
            + Ogre::StringConverter::toString(time) + ",";
    }

    stream << trackStr.c_str();

    stream.close();
}