ParameterPanel.cpp
#include "StdAfx.h"
#include "ParameterPanel.h"
#include "Link.h"
#include "joint.h"
#include "ExtendedNumericUpDown.h"
using namespace Core;
using namespace Robotics;
using namespace System;
using namespace System::Diagnostics;
/// [ Constructor ]
ParameterPanel::ParameterPanel( void )
{
// コンポーネントを初期化する
InitializeComponent();
// 位置か姿勢のイベントハンドラを生成する
System::EventHandler^ positionOrPostureChangedEventHandler = gcnew System::EventHandler( this, &ParameterPanel::PositionOrPostureChanged );
// ... それを設定する
m_yawSpinBox->ValueChangedEventHandler = positionOrPostureChangedEventHandler;
m_pitchSpinBox->ValueChangedEventHandler = positionOrPostureChangedEventHandler;
m_rollSpinBox->ValueChangedEventHandler = positionOrPostureChangedEventHandler;
m_zSpinBox->ValueChangedEventHandler = positionOrPostureChangedEventHandler;
m_ySpinBox->ValueChangedEventHandler = positionOrPostureChangedEventHandler;
m_xSpinBox->ValueChangedEventHandler = positionOrPostureChangedEventHandler;
// 角度の変更イベントハンドラを設定する
m_angleSpinBox->ValueChangedEventHandler = gcnew System::EventHandler( this, &ParameterPanel::AngleChanged );
}
/// < Destructor >
ParameterPanel::~ParameterPanel()
{
if( components != nullptr )
{
delete components;
}
}
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
void ParameterPanel::InitializeComponent(void)
{
this->m_postureGroupBox = (gcnew System::Windows::Forms::GroupBox());
this->m_yawUnitLabel = (gcnew System::Windows::Forms::Label());
this->m_pitchUnitLabel = (gcnew System::Windows::Forms::Label());
this->m_rollUnitLabel = (gcnew System::Windows::Forms::Label());
this->m_yawSpinBox = (gcnew ExtendedNumericUpDown());
this->m_pitchSpinBox = (gcnew ExtendedNumericUpDown());
this->m_rollSpinBox = (gcnew ExtendedNumericUpDown());
this->m_yawLabel = (gcnew System::Windows::Forms::Label());
this->m_pitchLabel = (gcnew System::Windows::Forms::Label());
this->m_rollLabel = (gcnew System::Windows::Forms::Label());
this->m_positionGroupBox = (gcnew System::Windows::Forms::GroupBox());
this->m_zUnitLabel = (gcnew System::Windows::Forms::Label());
this->m_yUnitLabel = (gcnew System::Windows::Forms::Label());
this->m_xUnitLabel = (gcnew System::Windows::Forms::Label());
this->m_zSpinBox = (gcnew ExtendedNumericUpDown());
this->m_ySpinBox = (gcnew ExtendedNumericUpDown());
this->m_xSpinBox = (gcnew ExtendedNumericUpDown());
this->m_zLabel = (gcnew System::Windows::Forms::Label());
this->m_yLabel = (gcnew System::Windows::Forms::Label());
this->m_xLabel = (gcnew System::Windows::Forms::Label());
this->m_unitLabel = (gcnew System::Windows::Forms::Label());
this->m_nameLabel = (gcnew System::Windows::Forms::Label());
this->m_angleSpinBox = (gcnew ExtendedNumericUpDown());
this->m_angleLabel = (gcnew System::Windows::Forms::Label());
this->m_postureGroupBox->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_yawSpinBox))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_pitchSpinBox))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_rollSpinBox))->BeginInit();
this->m_positionGroupBox->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_zSpinBox))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_ySpinBox))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_xSpinBox))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_angleSpinBox))->BeginInit();
this->SuspendLayout();
//
// m_postureGroupBox
//
this->m_postureGroupBox->Controls->Add(this->m_yawUnitLabel);
this->m_postureGroupBox->Controls->Add(this->m_pitchUnitLabel);
this->m_postureGroupBox->Controls->Add(this->m_rollUnitLabel);
this->m_postureGroupBox->Controls->Add(this->m_yawSpinBox);
this->m_postureGroupBox->Controls->Add(this->m_pitchSpinBox);
this->m_postureGroupBox->Controls->Add(this->m_rollSpinBox);
this->m_postureGroupBox->Controls->Add(this->m_yawLabel);
this->m_postureGroupBox->Controls->Add(this->m_pitchLabel);
this->m_postureGroupBox->Controls->Add(this->m_rollLabel);
this->m_postureGroupBox->Location = System::Drawing::Point(133, 36);
this->m_postureGroupBox->Name = L"m_postureGroupBox";
this->m_postureGroupBox->Size = System::Drawing::Size(149, 97);
this->m_postureGroupBox->TabIndex = 3;
this->m_postureGroupBox->TabStop = false;
this->m_postureGroupBox->Text = L"姿勢";
//
// m_yawUnitLabel
//
this->m_yawUnitLabel->AutoSize = true;
this->m_yawUnitLabel->Location = System::Drawing::Point(102, 69);
this->m_yawUnitLabel->Margin = System::Windows::Forms::Padding(0, 0, 3, 0);
this->m_yawUnitLabel->Name = L"m_yawUnitLabel";
this->m_yawUnitLabel->Size = System::Drawing::Size(39, 12);
this->m_yawUnitLabel->TabIndex = 15;
this->m_yawUnitLabel->Text = L"( deg )";
//
// m_pitchUnitLabel
//
this->m_pitchUnitLabel->AutoSize = true;
this->m_pitchUnitLabel->Location = System::Drawing::Point(102, 44);
this->m_pitchUnitLabel->Margin = System::Windows::Forms::Padding(0, 0, 3, 0);
this->m_pitchUnitLabel->Name = L"m_pitchUnitLabel";
this->m_pitchUnitLabel->Size = System::Drawing::Size(39, 12);
this->m_pitchUnitLabel->TabIndex = 14;
this->m_pitchUnitLabel->Text = L"( deg )";
//
// m_rollUnitLabel
//
this->m_rollUnitLabel->AutoSize = true;
this->m_rollUnitLabel->Location = System::Drawing::Point(102, 19);
this->m_rollUnitLabel->Margin = System::Windows::Forms::Padding(0, 0, 3, 0);
this->m_rollUnitLabel->Name = L"m_rollUnitLabel";
this->m_rollUnitLabel->Size = System::Drawing::Size(39, 12);
this->m_rollUnitLabel->TabIndex = 13;
this->m_rollUnitLabel->Text = L"( deg )";
//
// m_yawSpinBox
//
this->m_yawSpinBox->DecimalPlaces = 1;
this->m_yawSpinBox->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {5, 0, 0, 0});
this->m_yawSpinBox->Location = System::Drawing::Point(43, 67);
this->m_yawSpinBox->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, 0});
this->m_yawSpinBox->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, System::Int32::MinValue});
this->m_yawSpinBox->Name = L"m_yawSpinBox";
this->m_yawSpinBox->Size = System::Drawing::Size(56, 19);
this->m_yawSpinBox->TabIndex = 10;
this->m_yawSpinBox->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// m_pitchSpinBox
//
this->m_pitchSpinBox->DecimalPlaces = 1;
this->m_pitchSpinBox->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {5, 0, 0, 0});
this->m_pitchSpinBox->Location = System::Drawing::Point(43, 42);
this->m_pitchSpinBox->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, 0});
this->m_pitchSpinBox->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, System::Int32::MinValue});
this->m_pitchSpinBox->Name = L"m_pitchSpinBox";
this->m_pitchSpinBox->Size = System::Drawing::Size(56, 19);
this->m_pitchSpinBox->TabIndex = 11;
this->m_pitchSpinBox->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// m_rollSpinBox
//
this->m_rollSpinBox->DecimalPlaces = 1;
this->m_rollSpinBox->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {5, 0, 0, 0});
this->m_rollSpinBox->Location = System::Drawing::Point(43, 17);
this->m_rollSpinBox->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, 0});
this->m_rollSpinBox->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, System::Int32::MinValue});
this->m_rollSpinBox->Name = L"m_rollSpinBox";
this->m_rollSpinBox->Size = System::Drawing::Size(56, 19);
this->m_rollSpinBox->TabIndex = 12;
this->m_rollSpinBox->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// m_yawLabel
//
this->m_yawLabel->AutoSize = true;
this->m_yawLabel->Location = System::Drawing::Point(6, 70);
this->m_yawLabel->Name = L"m_yawLabel";
this->m_yawLabel->Size = System::Drawing::Size(26, 12);
this->m_yawLabel->TabIndex = 7;
this->m_yawLabel->Text = L"Yaw";
//
// m_pitchLabel
//
this->m_pitchLabel->AutoSize = true;
this->m_pitchLabel->Location = System::Drawing::Point(6, 45);
this->m_pitchLabel->Name = L"m_pitchLabel";
this->m_pitchLabel->Size = System::Drawing::Size(31, 12);
this->m_pitchLabel->TabIndex = 8;
this->m_pitchLabel->Text = L"Pitch";
//
// m_rollLabel
//
this->m_rollLabel->AutoSize = true;
this->m_rollLabel->Location = System::Drawing::Point(6, 20);
this->m_rollLabel->Name = L"m_rollLabel";
this->m_rollLabel->Size = System::Drawing::Size(25, 12);
this->m_rollLabel->TabIndex = 9;
this->m_rollLabel->Text = L"Roll";
//
// m_positionGroupBox
//
this->m_positionGroupBox->Controls->Add(this->m_zUnitLabel);
this->m_positionGroupBox->Controls->Add(this->m_yUnitLabel);
this->m_positionGroupBox->Controls->Add(this->m_xUnitLabel);
this->m_positionGroupBox->Controls->Add(this->m_zSpinBox);
this->m_positionGroupBox->Controls->Add(this->m_ySpinBox);
this->m_positionGroupBox->Controls->Add(this->m_xSpinBox);
this->m_positionGroupBox->Controls->Add(this->m_zLabel);
this->m_positionGroupBox->Controls->Add(this->m_yLabel);
this->m_positionGroupBox->Controls->Add(this->m_xLabel);
this->m_positionGroupBox->Location = System::Drawing::Point(3, 36);
this->m_positionGroupBox->Name = L"m_positionGroupBox";
this->m_positionGroupBox->Size = System::Drawing::Size(124, 97);
this->m_positionGroupBox->TabIndex = 2;
this->m_positionGroupBox->TabStop = false;
this->m_positionGroupBox->Text = L"位置";
//
// m_zUnitLabel
//
this->m_zUnitLabel->AutoSize = true;
this->m_zUnitLabel->Location = System::Drawing::Point(91, 69);
this->m_zUnitLabel->Margin = System::Windows::Forms::Padding(0, 0, 3, 0);
this->m_zUnitLabel->Name = L"m_zUnitLabel";
this->m_zUnitLabel->Size = System::Drawing::Size(30, 12);
this->m_zUnitLabel->TabIndex = 9;
this->m_zUnitLabel->Text = L"( m )";
//
// m_yUnitLabel
//
this->m_yUnitLabel->AutoSize = true;
this->m_yUnitLabel->Location = System::Drawing::Point(91, 44);
this->m_yUnitLabel->Margin = System::Windows::Forms::Padding(0, 0, 3, 0);
this->m_yUnitLabel->Name = L"m_yUnitLabel";
this->m_yUnitLabel->Size = System::Drawing::Size(30, 12);
this->m_yUnitLabel->TabIndex = 8;
this->m_yUnitLabel->Text = L"( m )";
//
// m_xUnitLabel
//
this->m_xUnitLabel->AutoSize = true;
this->m_xUnitLabel->Location = System::Drawing::Point(91, 20);
this->m_xUnitLabel->Margin = System::Windows::Forms::Padding(0, 0, 3, 0);
this->m_xUnitLabel->Name = L"m_xUnitLabel";
this->m_xUnitLabel->Size = System::Drawing::Size(30, 12);
this->m_xUnitLabel->TabIndex = 7;
this->m_xUnitLabel->Text = L"( m )";
//
// m_zSpinBox
//
this->m_zSpinBox->DecimalPlaces = 3;
this->m_zSpinBox->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {5, 0, 0, 196608});
this->m_zSpinBox->Location = System::Drawing::Point(24, 67);
this->m_zSpinBox->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
this->m_zSpinBox->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, System::Int32::MinValue});
this->m_zSpinBox->Name = L"m_zSpinBox";
this->m_zSpinBox->Size = System::Drawing::Size(64, 19);
this->m_zSpinBox->TabIndex = 6;
this->m_zSpinBox->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// m_ySpinBox
//
this->m_ySpinBox->DecimalPlaces = 3;
this->m_ySpinBox->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {5, 0, 0, 196608});
this->m_ySpinBox->Location = System::Drawing::Point(24, 42);
this->m_ySpinBox->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
this->m_ySpinBox->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, System::Int32::MinValue});
this->m_ySpinBox->Name = L"m_ySpinBox";
this->m_ySpinBox->Size = System::Drawing::Size(64, 19);
this->m_ySpinBox->TabIndex = 5;
this->m_ySpinBox->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// m_xSpinBox
//
this->m_xSpinBox->DecimalPlaces = 3;
this->m_xSpinBox->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {5, 0, 0, 196608});
this->m_xSpinBox->Location = System::Drawing::Point(24, 18);
this->m_xSpinBox->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
this->m_xSpinBox->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, System::Int32::MinValue});
this->m_xSpinBox->Name = L"m_xSpinBox";
this->m_xSpinBox->Size = System::Drawing::Size(64, 19);
this->m_xSpinBox->TabIndex = 4;
this->m_xSpinBox->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// m_zLabel
//
this->m_zLabel->AutoSize = true;
this->m_zLabel->Location = System::Drawing::Point(6, 69);
this->m_zLabel->Name = L"m_zLabel";
this->m_zLabel->Size = System::Drawing::Size(12, 12);
this->m_zLabel->TabIndex = 3;
this->m_zLabel->Text = L"Z";
//
// m_yLabel
//
this->m_yLabel->AutoSize = true;
this->m_yLabel->Location = System::Drawing::Point(6, 44);
this->m_yLabel->Name = L"m_yLabel";
this->m_yLabel->Size = System::Drawing::Size(12, 12);
this->m_yLabel->TabIndex = 2;
this->m_yLabel->Text = L"Y";
//
// m_xLabel
//
this->m_xLabel->AutoSize = true;
this->m_xLabel->Location = System::Drawing::Point(6, 20);
this->m_xLabel->Name = L"m_xLabel";
this->m_xLabel->Size = System::Drawing::Size(12, 12);
this->m_xLabel->TabIndex = 1;
this->m_xLabel->Text = L"X";
//
// m_unitLabel
//
this->m_unitLabel->AutoSize = true;
this->m_unitLabel->Location = System::Drawing::Point(235, 9);
this->m_unitLabel->Margin = System::Windows::Forms::Padding(0, 0, 3, 0);
this->m_unitLabel->Name = L"m_unitLabel";
this->m_unitLabel->Size = System::Drawing::Size(39, 12);
this->m_unitLabel->TabIndex = 9;
this->m_unitLabel->Text = L"( deg )";
//
// m_nameLabel
//
this->m_nameLabel->AutoSize = true;
this->m_nameLabel->Font = (gcnew System::Drawing::Font(L"MS UI Gothic", 9, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(128)));
this->m_nameLabel->Location = System::Drawing::Point(12, 9);
this->m_nameLabel->Name = L"m_nameLabel";
this->m_nameLabel->Size = System::Drawing::Size(34, 12);
this->m_nameLabel->TabIndex = 8;
this->m_nameLabel->Text = L"Name";
//
// m_angleSpinBox
//
this->m_angleSpinBox->DecimalPlaces = 1;
this->m_angleSpinBox->Increment = System::Decimal(gcnew cli::array< System::Int32 >(4) {10, 0, 0, 0});
this->m_angleSpinBox->Location = System::Drawing::Point(168, 7);
this->m_angleSpinBox->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, 0});
this->m_angleSpinBox->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {180, 0, 0, System::Int32::MinValue});
this->m_angleSpinBox->Name = L"m_angleSpinBox";
this->m_angleSpinBox->Size = System::Drawing::Size(64, 19);
this->m_angleSpinBox->TabIndex = 7;
this->m_angleSpinBox->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
//
// m_angleLabel
//
this->m_angleLabel->AutoSize = true;
this->m_angleLabel->Location = System::Drawing::Point(133, 9);
this->m_angleLabel->Name = L"m_angleLabel";
this->m_angleLabel->Size = System::Drawing::Size(29, 12);
this->m_angleLabel->TabIndex = 6;
this->m_angleLabel->Text = L"角度";
//
// ParameterPanel
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 146);
this->CloseButton = false;
this->Controls->Add(this->m_unitLabel);
this->Controls->Add(this->m_nameLabel);
this->Controls->Add(this->m_angleSpinBox);
this->Controls->Add(this->m_angleLabel);
this->Controls->Add(this->m_postureGroupBox);
this->Controls->Add(this->m_positionGroupBox);
this->DockAreas = static_cast<WeifenLuo::WinFormsUI::Docking::DockAreas>(((((WeifenLuo::WinFormsUI::Docking::DockAreas::Float | WeifenLuo::WinFormsUI::Docking::DockAreas::DockLeft)
| WeifenLuo::WinFormsUI::Docking::DockAreas::DockRight)
| WeifenLuo::WinFormsUI::Docking::DockAreas::DockTop)
| WeifenLuo::WinFormsUI::Docking::DockAreas::DockBottom));
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->HideOnClose = true;
this->Name = L"ParameterPanel";
this->ShowHint = WeifenLuo::WinFormsUI::Docking::DockState::DockRightAutoHide;
this->TabText = L"Parameter";
this->Text = L"Parameter";
this->m_postureGroupBox->ResumeLayout(false);
this->m_postureGroupBox->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_yawSpinBox))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_pitchSpinBox))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_rollSpinBox))->EndInit();
this->m_positionGroupBox->ResumeLayout(false);
this->m_positionGroupBox->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_zSpinBox))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_ySpinBox))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_xSpinBox))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->m_angleSpinBox))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
/// コントロールが初めて表示される
void ParameterPanel::OnLoad( System::EventArgs^ e )
{
// 基本クラスの同一関数を呼び出す
Windows::Forms::Form::OnLoad( e );
// リンクのイベントに登録する
Link::StandardChanged += gcnew System::EventHandler( this, &ParameterPanel::SetInputEnable );
Link::AbsolutePositionChanged += gcnew System::EventHandler( this, &ParameterPanel::SetPosition );
Link::PostureChanged += gcnew System::EventHandler( this, &ParameterPanel::SetPosture );
// 関節のイベントに登録する
Joint::AngleChanged += gcnew System::EventHandler( this, &ParameterPanel::SetAngle );
// 対象を初期化する
SetTarget( nullptr );
}
/// 対象を設定する
void ParameterPanel::SetTarget( Link^ link )
{
// リンクを設定する
SetLink( link );
// 関節を設定する
SetJoint( ( link != nullptr )? link->Joint : nullptr );
}
/// リンクを設定する
void ParameterPanel::SetLink( Link^ link )
{
m_link = link; // リンク
if( link != nullptr )
{
m_nameLabel->Text = link->Name; // 名称のテキスト
// 位置を設定する
SetPosition( link, nullptr );
// 姿勢を設定する
SetPosture( link, nullptr );
}
// 入力の有効・無効を設定する
SetInputEnable( link, nullptr );
}
/// 位置を設定する
void ParameterPanel::SetPosition( System::Object^ sender, System::EventArgs^ )
{
// 引数から目的とする型を取得する
Link^ link = safe_cast< Link^ >( sender );
// 管理しているリンクのイベントにしか応じない
if( m_link == link )
{
PositionVector^ position = link->AbsolutePosition; // リンクの絶対位置
// スピンボックスに設定する
m_xSpinBox->Number = position->X;
m_ySpinBox->Number = position->Y;
m_zSpinBox->Number = position->Z;
}
}
/// 姿勢を設定する
void ParameterPanel::SetPosture( System::Object^ sender, System::EventArgs^ )
{
// 引数から目的とする型を取得する
Link^ link = safe_cast< Link^ >( sender );
// 管理しているリンクのイベントにしか応じない
if( m_link == link )
{
RotationMatrix^ posture = link->Posture; // リンクの姿勢
// 現在の値を基準として ロール・ピッチ・ヨー角を取得する
Angle roll = posture->GetRoll( Angle( GetRadian( m_rollSpinBox ) ) );
Angle pitch = posture->GetPitch( Angle( GetRadian( m_pitchSpinBox ) ) );
Angle yaw = posture->GetYaw( Angle( GetRadian( m_yawSpinBox ) ) );
// ... それをスピンボックスに設定する
m_rollSpinBox->Number = roll.Degree;
m_pitchSpinBox->Number = pitch.Degree;
m_yawSpinBox->Number = yaw.Degree;
}
}
/// 位置か角度が変更された
System::Void ParameterPanel::PositionOrPostureChanged( System::Object^ sender, System::EventArgs^ )
{
Debug::Assert( m_link != nullptr, "リンクは設定されている" );
// 引数から目的とする型を取得する
Windows::Forms::Control^ control = safe_cast< Windows::Forms::Control^ >( sender );
// ... ユーザーからの入力に対してしか応じない
if( control->Focused )
{
// スピンボックスから 位置を取得する
PositionVector^ position = gcnew PositionVector(
m_xSpinBox->Value,
m_ySpinBox->Value,
m_zSpinBox->Value
);
// スピンボックスから 姿勢を取得する
RotationMatrix^ posture = gcnew RotationMatrix(
GetRadian( m_rollSpinBox ),
GetRadian( m_pitchSpinBox ),
GetRadian( m_yawSpinBox )
);
// ... リンクの位置と姿勢を設定する
m_link->SetPositionAndPosture( position, posture );
}
}
/// 入力の有効・無効を設定する
void ParameterPanel::SetInputEnable( System::Object^ sender, System::EventArgs^ )
{
// 引数から目的とする型を取得する
Link^ link = safe_cast< Link^ >( sender );
// 管理しているリンクのイベントにしか応じない
if( m_link == link )
{
// スピンボックスの有効・無効を、無効なリンク及び基準リンクかによって設定する
bool enable = ( link != nullptr ) && ( !link->IsStandard() );
m_xSpinBox->Enabled = enable;
m_ySpinBox->Enabled = enable;
m_zSpinBox->Enabled = enable;
m_rollSpinBox->Enabled = enable;
m_pitchSpinBox->Enabled = enable;
m_yawSpinBox->Enabled = enable;
}
}
/// 関節を設定する
void ParameterPanel::SetJoint( Joint^ joint )
{
// スピンボックスのタグに格納する
m_angleSpinBox->Tag = joint;
if( joint != nullptr )
{
m_angleSpinBox->Maximum = Decimal( joint->AngleRange.Maximum.Degree ); // スピンボックスの最大値
m_angleSpinBox->Minimum = Decimal( joint->AngleRange.Minimum.Degree ); // スピンボックスの最小値
// 角度を設定する
SetAngle( joint, nullptr );
// スピンボックスにフォーカスを合わせる
m_angleSpinBox->Focus();
// ... 全ての文字を選択する
m_angleSpinBox->Select( 0, m_angleSpinBox->Text->Length );
}
// スピンボックスの有効・無効を、無効なタグかによって設定する
m_angleSpinBox->Enabled = ( m_angleSpinBox->Tag != nullptr );
}
/// 角度を設定する
void ParameterPanel::SetAngle( System::Object^ sender, System::EventArgs^ )
{
// タグから関節を取得する
Joint^ joint = safe_cast< Joint^ >( m_angleSpinBox->Tag );
// 管理している関節のイベントにしか応じない
if( joint == sender )
{
// 関節から degreeで角度を取得して、スピンボックスに設定する
m_angleSpinBox->Number = joint->Angle.Degree;
}
}
/// 角度が変更された
System::Void ParameterPanel::AngleChanged( System::Object^ sender, System::EventArgs^ )
{
// タグから関節を取得する
Joint^ joint = safe_cast< Joint^ >( m_angleSpinBox->Tag );
Debug::Assert( joint != nullptr, "関節は設定されている" );
// 引数から目的とする型を取得する
Windows::Forms::Control^ control = safe_cast< Windows::Forms::Control^ >( sender );
// ... ユーザーからの入力に対してしか応じない
if( control->Focused )
{
// イベントハンドラを生成する
System::EventHandler^ eventHandler = gcnew System::EventHandler( this, &ParameterPanel::SetAngle );
// ... 角度の設定時にイベントから呼び出されないように、それを削除する
Joint::AngleChanged -= eventHandler;
// スピンボックスから Radianで角度を取得して、関節の角度に設定する
joint->Angle = Angle( GetRadian( m_angleSpinBox ) );
// 関節角度の変更イベントを発生する
JointAngleChanged( joint, nullptr );
// ... 削除したイベントに登録する
Joint::AngleChanged += eventHandler;
}
}
/// Radianで取得する
double ParameterPanel::GetRadian( System::Windows::Forms::NumericUpDown^ control )
{
// コントロールから値を取得し、それの Radianを求めて返す
return Angle::CalculateRadian( control->Value );
}