TimeChangeOfStabilityPanel.cpp

#include "StdAfx.h"
#include "TimeChangeOfStabilityPanel.h"


#include "Motion.h"
#include "Pose.h"


using namespace Core;
using namespace Robotics;

using namespace System;


/// [ Constructor ]
TimeChangeOfStabilityPanel::TimeChangeOfStabilityPanel( void )
{
    // コンポーネントを初期化する
    InitializeComponent();


    // グラフの枠を取得する
    ZedGraph::GraphPane^ graphPane = m_zedGraph->GraphPane;

    graphPane->Title->IsVisible = false;            // タイトル
    graphPane->Legend->IsVisible = false;           // 凡例

    // 大きな格子の表示
    graphPane->XAxis->MajorGrid->IsVisible = true;
    graphPane->YAxis->MajorGrid->IsVisible = true;

    // 軸ラベル
    graphPane->XAxis->Title->Text = "時間[sec]";
    graphPane->YAxis->Title->Text = "安定余裕[m]";

    // 軸ラベルの太字
    graphPane->XAxis->Title->FontSpec->IsBold = false;
    graphPane->YAxis->Title->FontSpec->IsBold = false;


    // 軸の範囲
    graphPane->YAxis->Scale->Max = +0.100;
    graphPane->YAxis->Scale->Min = -0.010;

    /// @todo
    /// グラフの値から適切に設定されるようにする。

}

/// [ Destructor ]
TimeChangeOfStabilityPanel::~TimeChangeOfStabilityPanel()
{
    if( components != nullptr )
    {
        delete components;
    }
}


#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
void TimeChangeOfStabilityPanel::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->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(800, 400);
    this->m_zedGraph->TabIndex = 0;
    //
    // TimeChangeOfStabilityPanel
    //
    this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->Controls->Add(this->m_zedGraph);
    this->Name = L"TimeChangeOfStabilityPanel";
    this->Size = System::Drawing::Size(800, 400);
    this->ResumeLayout(false);

}
#pragma endregion


/// 初期化する
void TimeChangeOfStabilityPanel::Initialize( Motion^ motion )
{
    // モーションの変更イベントに登録する
    motion->Changed += gcnew System::EventHandler( this, &TimeChangeOfStabilityPanel::MotionChanged );

    // モーションの変更イベントを呼び出し、フィールドを初期化する
    MotionChanged( motion, nullptr );
}


/// モーションが変更された
void TimeChangeOfStabilityPanel::MotionChanged( System::Object^ sender, System::EventArgs^ )
{
    // 引数から目的とする型を取得する。
    Motion^ motion = safe_cast< Motion^ >( sender );

    // グラフの点を生成する
    ZedGraph::PointPairList^ pointList = gcnew ZedGraph::PointPairList();

    for( int i = 0; i < motion->PoseCount; i++ )
    {
        // グラフの点を設定する
        pointList->Add(
            i * Motion::UnitTime,           // 時間
            motion[ i ]->StabilityMargin    // 安定余裕
            );
    }


    // グラフの枠を取得する
    ZedGraph::GraphPane^ graphPane = m_zedGraph->GraphPane;

    // ... グラフを消去する
    graphPane->CurveList->Clear();
    graphPane->GraphObjList->Clear();

    // ... グラフの線を追加する
    graphPane->AddCurve( "label", pointList, Drawing::Color::Blue, ZedGraph::SymbolType::None );


    // 現在の時間を表すラインを生成する
    ZedGraph::LineObj^ currentTimeLine = gcnew ZedGraph::LineObj(
        Drawing::Color::Orange,         // 色
        motion->CurrentTime,
        graphPane->YAxis->Scale->Min,
        motion->CurrentTime,
        graphPane->YAxis->Scale->Max
        );

    // ... グラフのオブジェクトに追加する
    graphPane->GraphObjList->Add( currentTimeLine );


    double graphSize = ( pointList->Count - 1 ) * Motion::UnitTime;  // グラフの大きさ
    if( graphPane->XAxis->Scale->Max != graphSize )
    {
        // X軸の最大値とグラフの大きさが異なっているならば、一致させる
        graphPane->XAxis->Scale->Max = graphSize;

        // ... 軸が変化したことを通知する
        m_zedGraph->AxisChange();
    }

    // 表示を更新する
    m_zedGraph->Invalidate();
}