TorquePanel.cpp
#include "StdAfx.h"
#include "TorquePanel.h"
#include "Link.h"
#include "Motion.h"
#include "Pose.h"
using namespace Core;
using namespace System;
using namespace System::Diagnostics;
/// [ Constructor ]
TorquePanel::TorquePanel( Motion^ motion, Links^ links )
{
// コンポーネントを初期化する
InitializeComponent();
/// @todo
/// PointValue の表示フォーマットを設定する必要がある。
/// m_zedGraph->PointValueFormat ??
array< String^ >^ nameLabels = gcnew array< String^ >( links->Length );
for( int i = 0; i < links->Length; i++ )
{
// リンクの名称を格納した配列を生成する
nameLabels[ i ] = links[ i ]->Name;
}
// グラフの枠を取得する
ZedGraph::GraphPane^ graphPane = m_zedGraph->GraphPane;
graphPane->Title->IsVisible = false; // タイトル
graphPane->XAxis->MajorGrid->IsVisible = true; // 大きな格子の表示
graphPane->Legend->IsVisible = false; // 凡例
graphPane->XAxis->Title->Text = "トルク[Nm]"; // 軸ラベル
graphPane->XAxis->Title->FontSpec->IsBold = false; // 軸ラベルの太字
graphPane->YAxis->Title->IsVisible = false; // 軸ラベル
graphPane->YAxis->Type = ZedGraph::AxisType::Text; // 軸のタイプ
graphPane->YAxis->Scale->TextLabels = nameLabels; // 軸のテキスト
// 軸の範囲
graphPane->XAxis->Scale->Max = 1.0;
/// @todo
/// グラフの値から適切に設定されるようにする。
// Y軸を基準の軸とする
graphPane->BarSettings->Base = ZedGraph::BarBase::Y;
/// @note
/// デフォルトで垂直のグラフ表示となっているので、
/// 基準の軸を設定しないと水平に表示されない。
// 軸の変更を通知する
m_zedGraph->AxisChange();
// モーションの変更イベントに登録する
motion->Changed += gcnew System::EventHandler( this, &TorquePanel::MotionChanged );
// モーションの変更イベントを呼び出し、フィールドを初期化する
MotionChanged( motion, nullptr );
}
/// [ Destructor ]
TorquePanel::~TorquePanel()
{
if( components != nullptr )
{
delete components;
}
}
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
void TorquePanel::InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->m_zedGraph = (gcnew ZedGraph::ZedGraphControl());
this->SuspendLayout();
//
// m_zedGraph
//
this->m_zedGraph->Dock = System::Windows::Forms::DockStyle::Fill;
this->m_zedGraph->EditButtons = System::Windows::Forms::MouseButtons::None;
this->m_zedGraph->IsEnableHZoom = false;
this->m_zedGraph->IsEnableVZoom = false;
this->m_zedGraph->IsEnableWheelZoom = false;
this->m_zedGraph->IsShowContextMenu = false;
this->m_zedGraph->IsShowPointValues = true;
this->m_zedGraph->Location = System::Drawing::Point(0, 0);
this->m_zedGraph->Name = L"m_zedGraph";
this->m_zedGraph->ScrollGrace = 0;
this->m_zedGraph->ScrollMaxX = 0;
this->m_zedGraph->ScrollMaxY = 0;
this->m_zedGraph->ScrollMaxY2 = 0;
this->m_zedGraph->ScrollMinX = 0;
this->m_zedGraph->ScrollMinY = 0;
this->m_zedGraph->ScrollMinY2 = 0;
this->m_zedGraph->Size = System::Drawing::Size(392, 666);
this->m_zedGraph->TabIndex = 0;
//
// TorquePanel
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(392, 666);
this->CloseButton = false;
this->Controls->Add(this->m_zedGraph);
this->DockAreas = static_cast<WeifenLuo::WinFormsUI::Docking::DockAreas>(((WeifenLuo::WinFormsUI::Docking::DockAreas::Float | WeifenLuo::WinFormsUI::Docking::DockAreas::DockLeft)
| WeifenLuo::WinFormsUI::Docking::DockAreas::DockRight));
this->HideOnClose = true;
this->Name = L"TorquePanel";
this->ShowHint = WeifenLuo::WinFormsUI::Docking::DockState::DockLeftAutoHide;
this->TabText = L"Torque";
this->Text = L"Torque";
this->ResumeLayout(false);
}
#pragma endregion
/// モーションが変更された
void TorquePanel::MotionChanged( System::Object^ sender, System::EventArgs^ )
{
// 引数から目的とする型を取得する。
Motion^ motion = safe_cast< Motion^ >( sender );
// ... 現在のポーズのトルクを取得する
array< double >^ torque = motion->CurrentPose->TorqueOfJoints;
// グラフの点を生成する
array< double >^ pointList = gcnew array< double >( torque->Length );
for( int i = 0; i < torque->Length; i++ )
{
// トルクの絶対値を グラフの点に設定する
pointList[ i ] = Math::Abs( torque[ i ] );
}
// グラフの枠を取得する
ZedGraph::GraphPane^ graphPane = m_zedGraph->GraphPane;
// ... グラフを消去する
graphPane->CurveList->Clear();
// ... グラフのバーに追加する
graphPane->AddBar( nullptr, pointList, nullptr, Drawing::Color::Red );
// ラベルに数値を表示を表示する
// bar->CreateBarLabels( graphPane, false, "f0" );
/// @note
/// 消去することができないため、表示していない。
// 表示を更新する
m_zedGraph->Invalidate();
}