MainForm.cpp
#include "StdAfx.h"
#include "MainForm.h"
// Panel
#include "ModelPanel.h"
#include "MotionPanel.h"
#include "ParameterPanel.h"
#include "LinkPropertyPanel.h"
#include "StabilityPanel.h"
#include "TorquePanel.h"
#include "EnergyEfficiencyPanel.h"
#include "VelocityPanel.h"
#include "FileExplorerPanel.h"
// ----------------------------
#include "AnalysisDialog.h"
#include "Model.h"
#include "Distinction.h"
#include "XmlFile.h"
#include "Settings.h"
using namespace Core;
using namespace System;
using namespace System::Diagnostics;
/// [ Constructor ]
MainForm::MainForm( void )
{
// 作業フォルダを設定する
FileExplorerPanel::SetWorkingFolder();
Debug::WriteLine( "メイン ウィンドウを生成する" );
// コンポーネントを初期化する
InitializeComponent();
// 実行ファイルのパスを取得する
String^ excutablePath = IO::Path::GetDirectoryName( Windows::Forms::Application::ExecutablePath );
// ... アプリケーションの設定ファイル名を 実行ファイルのパスと結合して設定する
m_applicationConfigFileName = IO::Path::Combine( excutablePath, "Application.config" );
// ... パネル レイアウトの設定ファイル名を 実行ファイルのパスと結合して設定する
m_panelLayoutConfigFileName = IO::Path::Combine( excutablePath, "PanelLayout.config" );
}
/// [ Destructor ]
MainForm::~MainForm()
{
if( components != nullptr )
{
delete components;
}
}
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドである。このメソッドの内容を
/// コード エディタで変更してはならない。
/// </summary>
void MainForm::InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid));
this->m_statusBar = (gcnew System::Windows::Forms::StatusStrip());
this->m_menuBar = (gcnew System::Windows::Forms::MenuStrip());
this->m_fileMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_newMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_separatorMenuItem = (gcnew System::Windows::Forms::ToolStripSeparator());
this->m_saveMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_saveAsMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_viewMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_expressionModeMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_mechanismModelMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_analysisMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_dockPanel = (gcnew WeifenLuo::WinFormsUI::Docking::DockPanel());
this->m_motionPanel = (gcnew Core::MotionPanel());
this->m_toolBar = (gcnew System::Windows::Forms::ToolStrip());
this->m_newToolButton = (gcnew System::Windows::Forms::ToolStripButton());
this->m_saveToolButton = (gcnew System::Windows::Forms::ToolStripButton());
this->m_separatorButton = (gcnew System::Windows::Forms::ToolStripSeparator());
this->m_mechanismModelButton = (gcnew System::Windows::Forms::ToolStripButton());
this->m_toolStripContainer = (gcnew System::Windows::Forms::ToolStripContainer());
this->m_menuBar->SuspendLayout();
this->m_toolBar->SuspendLayout();
this->m_toolStripContainer->BottomToolStripPanel->SuspendLayout();
this->m_toolStripContainer->ContentPanel->SuspendLayout();
this->m_toolStripContainer->TopToolStripPanel->SuspendLayout();
this->m_toolStripContainer->SuspendLayout();
this->SuspendLayout();
//
// m_statusBar
//
this->m_statusBar->Dock = System::Windows::Forms::DockStyle::None;
this->m_statusBar->Location = System::Drawing::Point(0, 0);
this->m_statusBar->Name = L"m_statusBar";
this->m_statusBar->Size = System::Drawing::Size(792, 22);
this->m_statusBar->TabIndex = 0;
//
// m_menuBar
//
this->m_menuBar->Dock = System::Windows::Forms::DockStyle::None;
this->m_menuBar->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->m_fileMenuItem, this->m_viewMenuItem,
this->m_analysisMenuItem});
this->m_menuBar->Location = System::Drawing::Point(0, 0);
this->m_menuBar->Name = L"m_menuBar";
this->m_menuBar->Size = System::Drawing::Size(792, 24);
this->m_menuBar->TabIndex = 0;
this->m_menuBar->Text = L"m_menuBar";
//
// m_fileMenuItem
//
this->m_fileMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->m_newMenuItem,
this->m_separatorMenuItem, this->m_saveMenuItem, this->m_saveAsMenuItem});
this->m_fileMenuItem->Name = L"m_fileMenuItem";
this->m_fileMenuItem->Size = System::Drawing::Size(66, 20);
this->m_fileMenuItem->Text = L"ファイル(&F)";
//
// m_newMenuItem
//
this->m_newMenuItem->Name = L"m_newMenuItem";
this->m_newMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::N));
this->m_newMenuItem->Size = System::Drawing::Size(180, 22);
this->m_newMenuItem->Text = L"新規作成(&N)";
this->m_newMenuItem->Click += gcnew System::EventHandler(this, &MainForm::CreateNewMotion);
//
// m_separatorMenuItem
//
this->m_separatorMenuItem->Name = L"m_separatorMenuItem";
this->m_separatorMenuItem->Size = System::Drawing::Size(177, 6);
//
// m_saveMenuItem
//
this->m_saveMenuItem->Name = L"m_saveMenuItem";
this->m_saveMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::S));
this->m_saveMenuItem->Size = System::Drawing::Size(180, 22);
this->m_saveMenuItem->Text = L"上書き保存(&S)";
this->m_saveMenuItem->Click += gcnew System::EventHandler(this, &MainForm::SaveMotionToFile);
//
// m_saveAsMenuItem
//
this->m_saveAsMenuItem->Name = L"m_saveAsMenuItem";
this->m_saveAsMenuItem->Size = System::Drawing::Size(180, 22);
this->m_saveAsMenuItem->Text = L"名前を付けて保存(&A)...";
this->m_saveAsMenuItem->Click += gcnew System::EventHandler(this, &MainForm::SaveMotionToFileGivingName);
//
// m_viewMenuItem
//
this->m_viewMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->m_expressionModeMenuItem});
this->m_viewMenuItem->Name = L"m_viewMenuItem";
this->m_viewMenuItem->Size = System::Drawing::Size(57, 20);
this->m_viewMenuItem->Text = L"表示(&V)";
//
// m_expressionModeMenuItem
//
this->m_expressionModeMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->m_mechanismModelMenuItem});
this->m_expressionModeMenuItem->Name = L"m_expressionModeMenuItem";
this->m_expressionModeMenuItem->Size = System::Drawing::Size(137, 22);
this->m_expressionModeMenuItem->Text = L"表示モード(&E)";
this->m_expressionModeMenuItem->DropDownOpening += gcnew System::EventHandler(this, &MainForm::ExpressionModeMenuItemPopup);
//
// m_mechanismModelMenuItem
//
this->m_mechanismModelMenuItem->Name = L"m_mechanismModelMenuItem";
this->m_mechanismModelMenuItem->Size = System::Drawing::Size(123, 22);
this->m_mechanismModelMenuItem->Text = L"機構モデル";
this->m_mechanismModelMenuItem->Click += gcnew System::EventHandler(this, &MainForm::ChangeExpressionMode);
//
// m_analysisMenuItem
//
this->m_analysisMenuItem->Name = L"m_analysisMenuItem";
this->m_analysisMenuItem->Size = System::Drawing::Size(63, 20);
this->m_analysisMenuItem->Text = L"分析(&N)...";
this->m_analysisMenuItem->Click += gcnew System::EventHandler(this, &MainForm::AnalysisMenuItemClick);
//
// m_dockPanel
//
this->m_dockPanel->ActiveAutoHideContent = nullptr;
this->m_dockPanel->Dock = System::Windows::Forms::DockStyle::Fill;
this->m_dockPanel->DocumentStyle = WeifenLuo::WinFormsUI::Docking::DocumentStyle::DockingSdi;
this->m_dockPanel->Location = System::Drawing::Point(0, 0);
this->m_dockPanel->Name = L"m_dockPanel";
this->m_dockPanel->Size = System::Drawing::Size(792, 426);
this->m_dockPanel->TabIndex = 2;
//
// m_motionPanel
//
this->m_motionPanel->Dock = System::Windows::Forms::DockStyle::Bottom;
this->m_motionPanel->Location = System::Drawing::Point(0, 426);
this->m_motionPanel->Name = L"m_motionPanel";
this->m_motionPanel->Size = System::Drawing::Size(792, 69);
this->m_motionPanel->TabIndex = 1;
//
// m_toolBar
//
this->m_toolBar->Dock = System::Windows::Forms::DockStyle::None;
this->m_toolBar->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->m_newToolButton, this->m_saveToolButton,
this->m_separatorButton, this->m_mechanismModelButton});
this->m_toolBar->Location = System::Drawing::Point(3, 24);
this->m_toolBar->Name = L"m_toolBar";
this->m_toolBar->Size = System::Drawing::Size(126, 25);
this->m_toolBar->TabIndex = 3;
this->m_toolBar->Text = L"toolBar";
//
// m_newToolButton
//
this->m_newToolButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->m_newToolButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"m_newToolButton.Image")));
this->m_newToolButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->m_newToolButton->Name = L"m_newToolButton";
this->m_newToolButton->Size = System::Drawing::Size(23, 22);
this->m_newToolButton->Text = L"新規作成";
this->m_newToolButton->Click += gcnew System::EventHandler(this, &MainForm::CreateNewMotion);
//
// m_saveToolButton
//
this->m_saveToolButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->m_saveToolButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"m_saveToolButton.Image")));
this->m_saveToolButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->m_saveToolButton->Name = L"m_saveToolButton";
this->m_saveToolButton->Size = System::Drawing::Size(23, 22);
this->m_saveToolButton->Text = L"上書き保存";
this->m_saveToolButton->ToolTipText = L"上書き保存";
this->m_saveToolButton->Click += gcnew System::EventHandler(this, &MainForm::SaveMotionToFile);
//
// m_separatorButton
//
this->m_separatorButton->Name = L"m_separatorButton";
this->m_separatorButton->Size = System::Drawing::Size(6, 25);
//
// m_mechanismModelButton
//
this->m_mechanismModelButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text;
this->m_mechanismModelButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"m_mechanismModelButton.Image")));
this->m_mechanismModelButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->m_mechanismModelButton->Name = L"m_mechanismModelButton";
this->m_mechanismModelButton->Size = System::Drawing::Size(62, 22);
this->m_mechanismModelButton->Text = L"機構モデル";
this->m_mechanismModelButton->ToolTipText = L"表示モード切替";
this->m_mechanismModelButton->Click += gcnew System::EventHandler(this, &MainForm::ChangeExpressionMode);
//
// m_toolStripContainer
//
//
// m_toolStripContainer.BottomToolStripPanel
//
this->m_toolStripContainer->BottomToolStripPanel->Controls->Add(this->m_statusBar);
//
// m_toolStripContainer.ContentPanel
//
this->m_toolStripContainer->ContentPanel->Controls->Add(this->m_dockPanel);
this->m_toolStripContainer->ContentPanel->Controls->Add(this->m_motionPanel);
this->m_toolStripContainer->ContentPanel->Size = System::Drawing::Size(792, 495);
this->m_toolStripContainer->Dock = System::Windows::Forms::DockStyle::Fill;
this->m_toolStripContainer->LeftToolStripPanelVisible = false;
this->m_toolStripContainer->Location = System::Drawing::Point(0, 0);
this->m_toolStripContainer->Name = L"m_toolStripContainer";
this->m_toolStripContainer->RightToolStripPanelVisible = false;
this->m_toolStripContainer->Size = System::Drawing::Size(792, 566);
this->m_toolStripContainer->TabIndex = 4;
this->m_toolStripContainer->Text = L"toolStripContainer";
//
// m_toolStripContainer.TopToolStripPanel
//
this->m_toolStripContainer->TopToolStripPanel->Controls->Add(this->m_menuBar);
this->m_toolStripContainer->TopToolStripPanel->Controls->Add(this->m_toolBar);
//
// MainForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(792, 566);
this->Controls->Add(this->m_toolStripContainer);
this->MainMenuStrip = this->m_menuBar;
this->MinimumSize = System::Drawing::Size(600, 500);
this->Name = L"MainForm";
this->Text = L"MainForm";
this->m_menuBar->ResumeLayout(false);
this->m_menuBar->PerformLayout();
this->m_toolBar->ResumeLayout(false);
this->m_toolBar->PerformLayout();
this->m_toolStripContainer->BottomToolStripPanel->ResumeLayout(false);
this->m_toolStripContainer->BottomToolStripPanel->PerformLayout();
this->m_toolStripContainer->ContentPanel->ResumeLayout(false);
this->m_toolStripContainer->TopToolStripPanel->ResumeLayout(false);
this->m_toolStripContainer->TopToolStripPanel->PerformLayout();
this->m_toolStripContainer->ResumeLayout(false);
this->m_toolStripContainer->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
/// コントロールが初めて表示される
void MainForm::OnLoad( System::EventArgs^ e )
{
// 基本クラスの同一関数を呼び出す
Windows::Forms::Form::OnLoad( e );
// アプリケーション設定を読み込む
LoadApplicationSettings();
// パネルを初期化する
InitializePanel();
// ... パネルのレイアウトを読み込む
LoadPanelLayout();
}
/// コントロールが閉じられる
void MainForm::OnFormClosing( System::Windows::Forms::FormClosingEventArgs^ e )
{
// 基本クラスの同一関数を呼び出す
Windows::Forms::Form::OnFormClosing( e );
// アプリケーション設定を保存する
SaveApplicationSettings();
// ドッキングパネルのレイアウト情報を保存する
m_dockPanel->SaveAsXml( m_panelLayoutConfigFileName );
}
// アプリケーション設定を読み込む
void MainForm::LoadApplicationSettings()
{
Debug::WriteLine( "アプリケーション設定を読み込む" );
XmlFile^ document = gcnew XmlFile();
// XMLドキュメントを読み込む
if( document->LoadFile( m_applicationConfigFileName ) )
{
// ルート要素から クラスの要素を取得する
Xml::XmlElement^ element = document->DocumentElement[ "MainForm" ];
if( element != nullptr )
{
// ウィンドウの情報を読み込む
document->LoadWindowStatus( this, element );
}
}
}
// アプリケーション設定を保存する
void MainForm::SaveApplicationSettings()
{
XmlFile^ document = gcnew XmlFile();
// ルートを生成する
Xml::XmlElement^ root = document->CreateRoot( "root" );
// クラスの要素を生成する
Xml::XmlElement^ element = document->CreateElement( "MainForm" );
// ... それをルートに追加する
root->AppendChild( element );
// ウィンドウの情報を保存する
document->SaveWindowStatus( this, element );
// XML ドキュメントを保存する
document->Save( m_applicationConfigFileName );
Debug::WriteLine( "アプリケーション設定を保存した" );
}
/// パネルを初期化する
void MainForm::InitializePanel()
{
Debug::WriteLine( "パネルの初期化を開始する" );
// モデルパネルを生成する
m_modelPanel = gcnew ModelPanel();
// ... モーションを新規作成する
CreateNewMotion( this, nullptr );
Model^ model = m_modelPanel->Model; // モデル
Motion^ motion = m_motionPanel->Motion; // モーション
ParameterPanel^ parameterPanel = gcnew ParameterPanel(); // 属性
FileExplorerPanel^ fileExplorerPanel = gcnew FileExplorerPanel(); // ファイル エクスプローラー
// ドッキングパネルを生成する
m_dockingPanels = gcnew Collections::Generic::List< WeifenLuo::WinFormsUI::Docking::DockContent^ >();
// ... ドッキングパネルに追加する
m_dockingPanels->Add( m_modelPanel );
m_dockingPanels->Add( parameterPanel );
m_dockingPanels->Add( fileExplorerPanel );
m_dockingPanels->Add( gcnew TorquePanel( motion, model->Links ) ); // トルク パネル
m_dockingPanels->Add( gcnew EnergyEfficiencyPanel( motion ) ); // エネルギー効率
m_dockingPanels->Add( gcnew VelocityPanel( motion ) ); // 速度
m_dockingPanels->Add( gcnew StabilityPanel( motion) ); // 安定性
m_dockingPanels->Add( gcnew LinkPropertyPanel( model ) ); // リンク プロパティ
/// @note
/// 汎用性を高めるために、クラスフィールドであるモデルパネルも
/// ドッキングパネルのリストに追加している。
// イベントに登録する
m_modelPanel->Selected += gcnew SelectEventHandler( this, &MainForm::ModelSelected );
fileExplorerPanel->FileSelected += gcnew FileEventHandler( this, &MainForm::LoadMotionFromFile );
parameterPanel->JointAngleChanged += gcnew System::EventHandler( model, &Model::Recompute );
}
/// パネルのレイアウトを読み込む
void MainForm::LoadPanelLayout()
{
// ドッキングパネルのレイアウト情報の存在を確認する
if( IO::File::Exists( m_panelLayoutConfigFileName ) )
{
// デシリアライズのためのインスタンスを生成する
WeifenLuo::WinFormsUI::Docking::DeserializeDockContent^ deserializeDockContent
= gcnew WeifenLuo::WinFormsUI::Docking::DeserializeDockContent( this, &MainForm::GetDockingPanel );
try
{
// ファイルから読み込む
m_dockPanel->LoadFromXml( m_panelLayoutConfigFileName, deserializeDockContent);
}
catch( InvalidOperationException^ e )
{
Debug::WriteLine( "ドッキングパネルのレイアウト情報の読み込みエラー : " + e->Message );
}
}
if( m_dockPanel->Contents->Count == 0 )
{
// コンテンツが存在しないならば、全てのパネルを デフォルトの設定で表示する
for each( WeifenLuo::WinFormsUI::Docking::DockContent^ panel in m_dockingPanels )
{
panel->Show( m_dockPanel );
}
/// @note
/// レイアウト情報が破損している場合、情報が読み取れないことがある。
/// ファイル読み取り後にもこのように確認をするのは、それへの対処である。
}
/// @note
/// 明示的にパネルを表示できるようになっていないと、
/// ここで表示に失敗した場合、表示する手段がない。
/// エラーチェックをより厳密に行う必要があると思われる。
}
/// ドッキングパネルを取得する
WeifenLuo::WinFormsUI::Docking::IDockContent^ MainForm::GetDockingPanel( System::String^ persistString )
{
// 全てのドッキングパネルと比較する
for each( WeifenLuo::WinFormsUI::Docking::DockContent^ panel in m_dockingPanels )
{
if( persistString == panel->GetType()->ToString() )
{
// 型の文字列と一致するインスタンスを返す
return panel;
}
}
Debug::Fail( "登録されていないドッキングパネルがある" );
return nullptr;
}
/// モデルが選択された
void MainForm::ModelSelected( System::Object^, SelectEventArgs^ e )
{
// モデルパネルから モデルを取得する
Model^ model = m_modelPanel->Model;
// パネルを取得する
ParameterPanel^ parameterPanel = safe_cast< ParameterPanel^ >( GetDockingPanel( ParameterPanel::typeid->ToString() ) );
VelocityPanel^ velocityPanel = safe_cast< VelocityPanel^ >( GetDockingPanel( VelocityPanel::typeid->ToString() ) );
LinkPropertyPanel^ linkPropertyPanel = safe_cast< LinkPropertyPanel^ >( GetDockingPanel( LinkPropertyPanel::typeid->ToString() ) );
/// @todo
/// モデル選択のイベントに登録することで、メソッドの呼び出しはしないようにする。
///
/// イベント登録は、パネルの初期化時に行う。
/// 必要なパラメータは、SelectEventArgsから取得できるようにする。
/// 必要ならば、Motionをクラスに保持させる。
// 選択されているか?
if( e->Selection != nullptr )
{
// モデルからリンクを取得する
Link^ selectedLink = model->Link[ e->Selection->Name ];
// 属性パネルの対象に設定する
parameterPanel->SetTarget( selectedLink );
// 速度パネルの対象に設定する
velocityPanel->SetTarget( model->GetLinkIndex( selectedLink ), m_motionPanel->Motion );
linkPropertyPanel->SelectedObject = selectedLink; // リンク プロパティの表示項目
}
else
{
// 属性パネルの対象に設定する
parameterPanel->SetTarget( nullptr );
// 速度パネルの対象に設定する
const int bodyIndex = 0;
velocityPanel->SetTarget( bodyIndex, m_motionPanel->Motion );
/// @todo
/// 胴体を指定するのに、マジックナンバーであるゼロを指定しないようにする。
linkPropertyPanel->SelectedObject = model; // リンク プロパティの表示項目
}
}
/// 分析メニューが選択された
System::Void MainForm::AnalysisMenuItemClick( System::Object^, System::EventArgs^ )
{
// 分析ダイアログを生成する
AnalysisDialog^ dialog = gcnew AnalysisDialog();
// ... それを表示する
dialog->Show( m_motionPanel->Motion, m_modelPanel->Model );
}
/// 表示モード メニューが表示される
System::Void MainForm::ExpressionModeMenuItemPopup( System::Object^, System::EventArgs^ )
{
m_mechanismModelMenuItem->Checked = ( m_modelPanel->ExpressionMode == ExpressionModel::MechanismModel );
}
/// 表示モードを切り替える
System::Void MainForm::ChangeExpressionMode( System::Object^, System::EventArgs^ )
{
m_modelPanel->ChangeExpressionMode();
// 機構モデルに設定されているならば、機構モデルボタンを選択状態にする
m_mechanismModelButton->Checked = ( m_modelPanel->ExpressionMode == ExpressionModel::MechanismModel );
}
/// モーションを新規作成する
System::Void MainForm::CreateNewMotion( System::Object^, System::EventArgs^ )
{
/// @todo
/// モーションのデータが更新されているならば、保存の確認をする。
// モーションパネルを初期化する
m_motionPanel->Initialize( m_modelPanel->Model );
// フォームのタイトルを設定する
SetFormTitle();
}
/// 名前を付けて、モーションをファイルに保存する
System::Void MainForm::SaveMotionToFileGivingName( System::Object^ sender, System::EventArgs^ e )
{
// モーション名を設定する
if( m_motionPanel->SetMotionName() )
{
// 設定されたならば、モーションをファイルに保存する
SaveMotionToFile( sender, e );
}
}
/// モーションをファイルに保存する
System::Void MainForm::SaveMotionToFile( System::Object^, System::EventArgs^ )
{
Xml::XmlDocument^ document = gcnew Xml::XmlDocument();
// XML 宣言ノードを追記する
document->AppendChild( document->CreateXmlDeclaration( "1.0", "UTF-8", nullptr ) );
// モーションの設定を書き込む
Xml::XmlElement^ motionElement = m_motionPanel->SaveSettings( document );
if( motionElement != nullptr )
{
// 書き込まれたならば、ドキュメントに追記する
document->AppendChild( motionElement );
// ファイルエクスプローラ パネルを取得する
WeifenLuo::WinFormsUI::Docking::IDockContent^ panel
= GetDockingPanel( FileExplorerPanel::typeid->ToString() );
FileExplorerPanel^ fileExplorer = safe_cast< FileExplorerPanel^ >( panel );
// ... ファイルを保存する
fileExplorer->SaveFile( m_motionPanel->MotionName, document );
// フォームのタイトルを設定する
SetFormTitle();
}
}
/// モーションをファイルから読み込む
void MainForm::LoadMotionFromFile( System::Object^, FileEventArgs^ e )
{
/// @todo
/// 編集中のファイルの保存の確認をする。
// ファイルエクスプローラ パネルを取得する
WeifenLuo::WinFormsUI::Docking::IDockContent^ panel
= GetDockingPanel( FileExplorerPanel::typeid->ToString() );
FileExplorerPanel^ fileExplorer = safe_cast< FileExplorerPanel^ >( panel );
String^ absolutePath = e->Name; // 絶対パス
// ... ファイルから読み込む
Xml::XmlDocument^ document = fileExplorer->LoadFile( absolutePath );
if( document != nullptr )
{
// モーションの設定を読み込む
m_motionPanel->LoadSettings( document );
// ディレクトリを 開いたファイルのあるフォルダに設定する
fileExplorer->SelectSpecifiedDirectory( absolutePath );
// フォームのタイトルを設定する
SetFormTitle();
}
}
/// フォームのタイトルを設定する
void MainForm::SetFormTitle()
{
String^ motionName = m_motionPanel->MotionName; // モーション名
if( motionName != String::Empty )
{
// 名称が指定されているならば、ハイフンを追加する
motionName += " - ";
}
// アプリケーションタイトルを結合して タイトルに設定する
this->Text = motionName + Settings::ApplicationTitle;
}