#pragma once
#include "armadillo"
#include "stdafx.h"
#include "discrete.h"
#include "NIDAQmx.h"
#include "NI_DAQ.h"
#include <math.h>
#include "Chart.h"
#include "Timer1.h"
#include "MicroStopwatch.h"
#include "PreciseTimer.h"
#include "PreciseTimerEventArgs.h"


using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
using namespace System::Threading;
using namespace System::Timers;
using namespace System::Diagnostics;
using namespace System::Runtime::InteropServices; 

namespace Sianaso {


	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Main_form : public System::Windows::Forms::Form
	{
	public:
		Main_form(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
			i = 1;
			plant_over = this->over->CreateGraphics();
			this->chart_layout->Invalidate();
			this->groupBox1->Invalidate();
			this->over->Invalidate();
			change_grid = true;
			array<Label^>^ xs = gcnew array<Label^>{x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,xmax};
			array<Label^>^ ys = gcnew array<Label^>{y0,y1,y2,y3,y4,y5,y6,y7,ymax};
			t = 0;
			v = 0;
			n = 0;
			Chart1 = gcnew Chart(xs,ys,this->chart_layout);
			Delegate_Sample = gcnew CallBack_Sample(this, &Sianaso::Main_form::Sample); //vytvori delagat pro funkci Sample (neco jako ukazatel na tu fci v cistym c++ pro pouziti s call back fcemi)
			Time_verify_sample = gcnew Stopwatch();
			milisec = gcnew array<Int64>(10000);
			microsec = gcnew array<Int64>(10000);
			Stopky = gcnew MicroStopwatch();

			Time_verify_sample->Start();
			
			tim = gcnew PreciseTimer(200000);
			this->tim->PreciseTimerElapsed += gcnew PreciseTimerElapsedEventHandler(this,&Sianaso::Main_form::OnTimeEvent);

			myrand = gcnew Random;

			Stop_button->Enabled = false;
			pause_button->Enabled = false;
			_pause = false;
			//tim->Start();
			/*ThreadStart ^ThrStart1 = gcnew ThreadStart(this,&Sianaso::Main_form::Sample);
			Thread ^firstThread = gcnew Thread(ThrStart1);
			firstThread->Priority = ThreadPriority::Highest;
			firstThread->Start();*/
		}
		
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Main_form()
		{
			if (components)
			{
				delete components;
			}
			delete output;
			delete input;
		}
	private: System::Windows::Forms::Button^  Start_button;
	protected: 

	private: System::Windows::Forms::PictureBox^  chart_layout;
	private: System::Windows::Forms::TextBox^  soustava_num;

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		discrete^ F;
		static Pen ^line = gcnew Pen(Color::Yellow);
		static Pen ^line2 = gcnew Pen(Color::Black);
		static Graphics^ plant_over;
		static bool change_grid = false;
		int i;
		float Tvz;
		NI_DAQ* output;
		NI_DAQ* input;
		Chart^ Chart1;
		float Y;
		float t;
		double v; //porucha na vstupu sosutavy
		double n; //porucha na vystupu soustavy
		double v_t; //cas, ve kterem zacne porucha v pusobit
		double n_t; //cas, ve kterem zacne porucha n pusobit
		double v_mean; //stredni hodnota sumu na vstupu do soustavy
		double v_variance; //rozptyl sumu na vstupu do soustavy
		double n_mean;
		double n_variance;
		Timer1^ timere;
		CallBack_Sample^ Delegate_Sample;
		Stopwatch^ Time_verify_sample;
		array<Int64>^ milisec;
		Random^ myrand;
	
		array<Int64>^ microsec;
		MicroStopwatch^ Stopky;
		PreciseTimer^ tim;
		bool _pause;

/****************************************************************************************************************/
	private: System::Windows::Forms::TextBox^  soustava_den;
	private: System::Windows::Forms::Timer^  timer1;
	private: System::Windows::Forms::Button^  Stop_button;

	private: System::Windows::Forms::TextBox^  TvzTEXTbox;

	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Button^  Autoscale_butt;





	private: System::Windows::Forms::Label^  xmax;
	private: System::Windows::Forms::Label^  x0;
	private: System::Windows::Forms::Label^  ymax;
	private: System::Windows::Forms::Label^  y0;
	private: System::Windows::Forms::Label^  x1;
	private: System::Windows::Forms::Label^  x2;
	private: System::Windows::Forms::Label^  x3;
	private: System::Windows::Forms::Label^  x4;
	private: System::Windows::Forms::Label^  x5;
	private: System::Windows::Forms::Label^  x7;
	private: System::Windows::Forms::Label^  x8;
	private: System::Windows::Forms::Label^  x6;
	private: System::Windows::Forms::Label^  y5;
	private: System::Windows::Forms::Label^  y4;
	private: System::Windows::Forms::Label^  y3;
	private: System::Windows::Forms::Label^  y2;
	private: System::Windows::Forms::Label^  y1;
	private: System::Windows::Forms::Label^  y6;
	private: System::Windows::Forms::Label^  x9;
	private: System::Windows::Forms::Label^  y7;


private: System::Windows::Forms::TabControl^  tabControl_transfer_fce;

private: System::Windows::Forms::TabPage^  tabPage1;
private: System::Windows::Forms::TabPage^  tabPage2;
private: System::Windows::Forms::Button^  pause_button;

private: System::Windows::Forms::Label^  label_jmen;

private: System::Windows::Forms::Label^  label_cit;
private: System::Windows::Forms::Label^  poznm;
private: System::Windows::Forms::GroupBox^  groupBox1;
private: System::Windows::Forms::GroupBox^  groupBox2;
private: System::Windows::Forms::Label^  label_gain;
private: System::Windows::Forms::TextBox^  text_gain;
private: System::Windows::Forms::Label^  label_poles;
private: System::Windows::Forms::TextBox^  text_poles;
private: System::Windows::Forms::Label^  label_zeros;
private: System::Windows::Forms::TextBox^  text_zeros;
private: System::Windows::Forms::TextBox^  textBox_X_min;
private: System::Windows::Forms::TextBox^  textBox_Y_max;


private: System::Windows::Forms::TextBox^  textBox_Y_min;

private: System::Windows::Forms::TextBox^  textBox_X_max;


private: System::Windows::Forms::Label^  label5;
private: System::Windows::Forms::GroupBox^  groupBox3;
private: System::Windows::Forms::Label^  label8;
private: System::Windows::Forms::Label^  label7;
private: System::Windows::Forms::Label^  label6;

private: System::Windows::Forms::ComboBox^  combo_ai;
private: System::Windows::Forms::ComboBox^  combo_ao;

private: System::Windows::Forms::GroupBox^  groupBox4;
private: System::Windows::Forms::Label^  label11;
private: System::Windows::Forms::Label^  label10;
private: System::Windows::Forms::Label^  label9;
private: System::Windows::Forms::TextBox^  DevName;
private: System::Windows::Forms::ToolTip^  toolTip1;
private: System::Windows::Forms::Label^  dev_stat;
private: System::Windows::Forms::Label^  label12;
private: System::Windows::Forms::Button^  dev_actul_button;
private: System::Windows::Forms::GroupBox^  groupBox5;
private: System::Windows::Forms::Label^  label14;
private: System::Windows::Forms::Label^  label13;
private: System::Windows::Forms::Label^  label16;
private: System::Windows::Forms::Label^  label15;
private: System::Windows::Forms::Label^  label22;
private: System::Windows::Forms::Label^  label21;
private: System::Windows::Forms::TextBox^  n_time;

private: System::Windows::Forms::TextBox^  v_time;

private: System::Windows::Forms::TextBox^  n_amp;

private: System::Windows::Forms::TextBox^  v_amp;

private: System::Windows::Forms::Label^  label20;
private: System::Windows::Forms::Label^  label19;
private: System::Windows::Forms::Label^  label18;
private: System::Windows::Forms::Label^  label17;
private: System::Windows::Forms::TextBox^  variance_n;

private: System::Windows::Forms::TextBox^  variance_v;
private: System::Windows::Forms::TextBox^  mean_n;


private: System::Windows::Forms::Label^  label26;
private: System::Windows::Forms::Label^  label25;
private: System::Windows::Forms::Label^  label24;
private: System::Windows::Forms::Label^  label23;
private: System::Windows::Forms::TextBox^  mean_v;
private: System::Windows::Forms::RichTextBox^  trans_num_text;



private: System::Windows::Forms::Button^  step_butt;
private: System::Windows::Forms::RichTextBox^  trans_den_text;
private: System::Windows::Forms::Label^  label27;
private: System::Windows::Forms::PictureBox^  over;
private: System::Windows::Forms::Button^  trans_fct_actual_butt;
private: System::Windows::Forms::PictureBox^  pictureBox1;
private: System::Windows::Forms::Label^  label4;
private: System::Windows::Forms::Label^  label3;
private: System::Windows::Forms::Label^  label29;
private: System::Windows::Forms::Label^  label28;
private: System::Windows::Forms::TextBox^  U_text;
private: System::Windows::Forms::TextBox^  Y_text;
private: System::Windows::Forms::CheckBox^  test_checkBox;
private: System::Windows::Forms::CheckBox^  precise_tim_on;










	private: System::ComponentModel::IContainer^  components;



#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Main_form::typeid));
			this->Start_button = (gcnew System::Windows::Forms::Button());
			this->chart_layout = (gcnew System::Windows::Forms::PictureBox());
			this->soustava_num = (gcnew System::Windows::Forms::TextBox());
			this->soustava_den = (gcnew System::Windows::Forms::TextBox());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->Stop_button = (gcnew System::Windows::Forms::Button());
			this->TvzTEXTbox = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->xmax = (gcnew System::Windows::Forms::Label());
			this->x0 = (gcnew System::Windows::Forms::Label());
			this->Autoscale_butt = (gcnew System::Windows::Forms::Button());
			this->ymax = (gcnew System::Windows::Forms::Label());
			this->y0 = (gcnew System::Windows::Forms::Label());
			this->x1 = (gcnew System::Windows::Forms::Label());
			this->x2 = (gcnew System::Windows::Forms::Label());
			this->x3 = (gcnew System::Windows::Forms::Label());
			this->x4 = (gcnew System::Windows::Forms::Label());
			this->x5 = (gcnew System::Windows::Forms::Label());
			this->x7 = (gcnew System::Windows::Forms::Label());
			this->x8 = (gcnew System::Windows::Forms::Label());
			this->x6 = (gcnew System::Windows::Forms::Label());
			this->y5 = (gcnew System::Windows::Forms::Label());
			this->y4 = (gcnew System::Windows::Forms::Label());
			this->y3 = (gcnew System::Windows::Forms::Label());
			this->y2 = (gcnew System::Windows::Forms::Label());
			this->y1 = (gcnew System::Windows::Forms::Label());
			this->y6 = (gcnew System::Windows::Forms::Label());
			this->x9 = (gcnew System::Windows::Forms::Label());
			this->y7 = (gcnew System::Windows::Forms::Label());
			this->tabControl_transfer_fce = (gcnew System::Windows::Forms::TabControl());
			this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
			this->poznm = (gcnew System::Windows::Forms::Label());
			this->label_jmen = (gcnew System::Windows::Forms::Label());
			this->label_cit = (gcnew System::Windows::Forms::Label());
			this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
			this->label_gain = (gcnew System::Windows::Forms::Label());
			this->text_gain = (gcnew System::Windows::Forms::TextBox());
			this->label_poles = (gcnew System::Windows::Forms::Label());
			this->text_poles = (gcnew System::Windows::Forms::TextBox());
			this->label_zeros = (gcnew System::Windows::Forms::Label());
			this->text_zeros = (gcnew System::Windows::Forms::TextBox());
			this->pause_button = (gcnew System::Windows::Forms::Button());
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->trans_fct_actual_butt = (gcnew System::Windows::Forms::Button());
			this->step_butt = (gcnew System::Windows::Forms::Button());
			this->label27 = (gcnew System::Windows::Forms::Label());
			this->trans_num_text = (gcnew System::Windows::Forms::RichTextBox());
			this->trans_den_text = (gcnew System::Windows::Forms::RichTextBox());
			this->over = (gcnew System::Windows::Forms::PictureBox());
			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
			this->label29 = (gcnew System::Windows::Forms::Label());
			this->label28 = (gcnew System::Windows::Forms::Label());
			this->U_text = (gcnew System::Windows::Forms::TextBox());
			this->Y_text = (gcnew System::Windows::Forms::TextBox());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->textBox_X_min = (gcnew System::Windows::Forms::TextBox());
			this->textBox_Y_max = (gcnew System::Windows::Forms::TextBox());
			this->textBox_Y_min = (gcnew System::Windows::Forms::TextBox());
			this->textBox_X_max = (gcnew System::Windows::Forms::TextBox());
			this->combo_ai = (gcnew System::Windows::Forms::ComboBox());
			this->combo_ao = (gcnew System::Windows::Forms::ComboBox());
			this->groupBox4 = (gcnew System::Windows::Forms::GroupBox());
			this->dev_stat = (gcnew System::Windows::Forms::Label());
			this->label12 = (gcnew System::Windows::Forms::Label());
			this->dev_actul_button = (gcnew System::Windows::Forms::Button());
			this->label11 = (gcnew System::Windows::Forms::Label());
			this->label10 = (gcnew System::Windows::Forms::Label());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->DevName = (gcnew System::Windows::Forms::TextBox());
			this->toolTip1 = (gcnew System::Windows::Forms::ToolTip(this->components));
			this->label13 = (gcnew System::Windows::Forms::Label());
			this->label14 = (gcnew System::Windows::Forms::Label());
			this->groupBox5 = (gcnew System::Windows::Forms::GroupBox());
			this->variance_n = (gcnew System::Windows::Forms::TextBox());
			this->variance_v = (gcnew System::Windows::Forms::TextBox());
			this->mean_n = (gcnew System::Windows::Forms::TextBox());
			this->label26 = (gcnew System::Windows::Forms::Label());
			this->label25 = (gcnew System::Windows::Forms::Label());
			this->label24 = (gcnew System::Windows::Forms::Label());
			this->label23 = (gcnew System::Windows::Forms::Label());
			this->mean_v = (gcnew System::Windows::Forms::TextBox());
			this->label22 = (gcnew System::Windows::Forms::Label());
			this->label21 = (gcnew System::Windows::Forms::Label());
			this->n_time = (gcnew System::Windows::Forms::TextBox());
			this->v_time = (gcnew System::Windows::Forms::TextBox());
			this->n_amp = (gcnew System::Windows::Forms::TextBox());
			this->v_amp = (gcnew System::Windows::Forms::TextBox());
			this->label20 = (gcnew System::Windows::Forms::Label());
			this->label19 = (gcnew System::Windows::Forms::Label());
			this->label18 = (gcnew System::Windows::Forms::Label());
			this->label17 = (gcnew System::Windows::Forms::Label());
			this->label16 = (gcnew System::Windows::Forms::Label());
			this->label15 = (gcnew System::Windows::Forms::Label());
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			this->test_checkBox = (gcnew System::Windows::Forms::CheckBox());
			this->precise_tim_on = (gcnew System::Windows::Forms::CheckBox());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->chart_layout))->BeginInit();
			this->tabControl_transfer_fce->SuspendLayout();
			this->tabPage1->SuspendLayout();
			this->tabPage2->SuspendLayout();
			this->groupBox1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->over))->BeginInit();
			this->groupBox2->SuspendLayout();
			this->groupBox3->SuspendLayout();
			this->groupBox4->SuspendLayout();
			this->groupBox5->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			this->SuspendLayout();
			// 
			// Start_button
			// 
			this->Start_button->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Zoom;
			this->Start_button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"Start_button.Image")));
			this->Start_button->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->Start_button->Location = System::Drawing::Point(348, 529);
			this->Start_button->Name = L"Start_button";
			this->Start_button->Size = System::Drawing::Size(71, 35);
			this->Start_button->TabIndex = 0;
			this->Start_button->Text = L"Start";
			this->Start_button->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			this->Start_button->UseVisualStyleBackColor = true;
			this->Start_button->Click += gcnew System::EventHandler(this, &Main_form::Start_button_Click);
			// 
			// chart_layout
			// 
			this->chart_layout->BackColor = System::Drawing::Color::Black;
			this->chart_layout->InitialImage = nullptr;
			this->chart_layout->Location = System::Drawing::Point(63, 21);
			this->chart_layout->Name = L"chart_layout";
			this->chart_layout->Size = System::Drawing::Size(600, 360);
			this->chart_layout->TabIndex = 2;
			this->chart_layout->TabStop = false;
			this->chart_layout->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Main_form::chart_layout_Paint);
			this->chart_layout->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Main_form::chart_layout_MouseDown);
			this->chart_layout->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Main_form::chart_layout_MouseMove);
			this->chart_layout->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Main_form::chart_layout_MouseUp);
			// 
			// soustava_num
			// 
			this->soustava_num->Location = System::Drawing::Point(13, 23);
			this->soustava_num->Name = L"soustava_num";
			this->soustava_num->Size = System::Drawing::Size(249, 20);
			this->soustava_num->TabIndex = 3;
			this->soustava_num->Text = L"2";
			// 
			// soustava_den
			// 
			this->soustava_den->Location = System::Drawing::Point(13, 66);
			this->soustava_den->Name = L"soustava_den";
			this->soustava_den->Size = System::Drawing::Size(249, 20);
			this->soustava_den->TabIndex = 4;
			this->soustava_den->Text = L"10 21 12 1";
			// 
			// timer1
			// 
			this->timer1->Tick += gcnew System::EventHandler(this, &Main_form::timer1_Tick);
			// 
			// Stop_button
			// 
			this->Stop_button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"Stop_button.Image")));
			this->Stop_button->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->Stop_button->Location = System::Drawing::Point(502, 529);
			this->Stop_button->Name = L"Stop_button";
			this->Stop_button->Size = System::Drawing::Size(71, 35);
			this->Stop_button->TabIndex = 5;
			this->Stop_button->Text = L"Stop";
			this->Stop_button->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			this->Stop_button->UseVisualStyleBackColor = true;
			this->Stop_button->Click += gcnew System::EventHandler(this, &Main_form::Stop_button_Click);
			// 
			// TvzTEXTbox
			// 
			this->TvzTEXTbox->Location = System::Drawing::Point(516, 495);
			this->TvzTEXTbox->Name = L"TvzTEXTbox";
			this->TvzTEXTbox->Size = System::Drawing::Size(48, 20);
			this->TvzTEXTbox->TabIndex = 6;
			this->TvzTEXTbox->Text = L"0,2";
			this->TvzTEXTbox->Leave += gcnew System::EventHandler(this, &Main_form::TvzTEXTbox_Leave);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(350, 498);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(161, 13);
			this->label1->TabIndex = 7;
			this->label1->Text = L"Tvz [s] (velikost kroku simulace):";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(343, 398);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(24, 13);
			this->label2->TabIndex = 8;
			this->label2->Text = L"t [s]";
			// 
			// xmax
			// 
			this->xmax->AutoSize = true;
			this->xmax->Location = System::Drawing::Point(650, 384);
			this->xmax->Name = L"xmax";
			this->xmax->Size = System::Drawing::Size(19, 13);
			this->xmax->TabIndex = 9;
			this->xmax->Text = L"20";
			// 
			// x0
			// 
			this->x0->AutoSize = true;
			this->x0->Location = System::Drawing::Point(58, 384);
			this->x0->Name = L"x0";
			this->x0->Size = System::Drawing::Size(13, 13);
			this->x0->TabIndex = 10;
			this->x0->Text = L"0";
			// 
			// Autoscale_butt
			// 
			this->Autoscale_butt->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"Autoscale_butt.Image")));
			this->Autoscale_butt->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->Autoscale_butt->Location = System::Drawing::Point(63, 415);
			this->Autoscale_butt->Name = L"Autoscale_butt";
			this->Autoscale_butt->Size = System::Drawing::Size(75, 23);
			this->Autoscale_butt->TabIndex = 11;
			this->Autoscale_butt->Text = L"Autoscale";
			this->Autoscale_butt->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			this->Autoscale_butt->UseVisualStyleBackColor = true;
			this->Autoscale_butt->Click += gcnew System::EventHandler(this, &Main_form::Autoscale_butt_Click);
			// 
			// ymax
			// 
			this->ymax->AutoSize = true;
			this->ymax->Location = System::Drawing::Point(37, 16);
			this->ymax->Name = L"ymax";
			this->ymax->Size = System::Drawing::Size(19, 13);
			this->ymax->TabIndex = 27;
			this->ymax->Text = L"20";
			// 
			// y0
			// 
			this->y0->AutoSize = true;
			this->y0->Location = System::Drawing::Point(21, 368);
			this->y0->Name = L"y0";
			this->y0->Size = System::Drawing::Size(19, 13);
			this->y0->TabIndex = 28;
			this->y0->Text = L"20";
			// 
			// x1
			// 
			this->x1->AutoSize = true;
			this->x1->Location = System::Drawing::Point(102, 384);
			this->x1->Name = L"x1";
			this->x1->Size = System::Drawing::Size(13, 13);
			this->x1->TabIndex = 29;
			this->x1->Text = L"0";
			// 
			// x2
			// 
			this->x2->AutoSize = true;
			this->x2->Location = System::Drawing::Point(157, 384);
			this->x2->Name = L"x2";
			this->x2->Size = System::Drawing::Size(13, 13);
			this->x2->TabIndex = 30;
			this->x2->Text = L"0";
			// 
			// x3
			// 
			this->x3->AutoSize = true;
			this->x3->Location = System::Drawing::Point(202, 384);
			this->x3->Name = L"x3";
			this->x3->Size = System::Drawing::Size(13, 13);
			this->x3->TabIndex = 31;
			this->x3->Text = L"0";
			// 
			// x4
			// 
			this->x4->AutoSize = true;
			this->x4->Location = System::Drawing::Point(245, 384);
			this->x4->Name = L"x4";
			this->x4->Size = System::Drawing::Size(13, 13);
			this->x4->TabIndex = 32;
			this->x4->Text = L"0";
			// 
			// x5
			// 
			this->x5->AutoSize = true;
			this->x5->Location = System::Drawing::Point(279, 384);
			this->x5->Name = L"x5";
			this->x5->Size = System::Drawing::Size(13, 13);
			this->x5->TabIndex = 33;
			this->x5->Text = L"0";
			// 
			// x7
			// 
			this->x7->AutoSize = true;
			this->x7->Location = System::Drawing::Point(354, 384);
			this->x7->Name = L"x7";
			this->x7->Size = System::Drawing::Size(13, 13);
			this->x7->TabIndex = 34;
			this->x7->Text = L"0";
			// 
			// x8
			// 
			this->x8->AutoSize = true;
			this->x8->Location = System::Drawing::Point(402, 384);
			this->x8->Name = L"x8";
			this->x8->Size = System::Drawing::Size(13, 13);
			this->x8->TabIndex = 35;
			this->x8->Text = L"0";
			// 
			// x6
			// 
			this->x6->AutoSize = true;
			this->x6->Location = System::Drawing::Point(321, 384);
			this->x6->Name = L"x6";
			this->x6->Size = System::Drawing::Size(13, 13);
			this->x6->TabIndex = 36;
			this->x6->Text = L"0";
			// 
			// y5
			// 
			this->y5->AutoSize = true;
			this->y5->Location = System::Drawing::Point(37, 125);
			this->y5->Name = L"y5";
			this->y5->Size = System::Drawing::Size(13, 13);
			this->y5->TabIndex = 37;
			this->y5->Text = L"0";
			// 
			// y4
			// 
			this->y4->AutoSize = true;
			this->y4->Location = System::Drawing::Point(37, 176);
			this->y4->Name = L"y4";
			this->y4->Size = System::Drawing::Size(13, 13);
			this->y4->TabIndex = 38;
			this->y4->Text = L"0";
			// 
			// y3
			// 
			this->y3->AutoSize = true;
			this->y3->Location = System::Drawing::Point(37, 222);
			this->y3->Name = L"y3";
			this->y3->Size = System::Drawing::Size(13, 13);
			this->y3->TabIndex = 39;
			this->y3->Text = L"0";
			// 
			// y2
			// 
			this->y2->AutoSize = true;
			this->y2->Location = System::Drawing::Point(37, 269);
			this->y2->Name = L"y2";
			this->y2->Size = System::Drawing::Size(13, 13);
			this->y2->TabIndex = 40;
			this->y2->Text = L"0";
			// 
			// y1
			// 
			this->y1->AutoSize = true;
			this->y1->Location = System::Drawing::Point(37, 322);
			this->y1->Name = L"y1";
			this->y1->Size = System::Drawing::Size(13, 13);
			this->y1->TabIndex = 41;
			this->y1->Text = L"0";
			// 
			// y6
			// 
			this->y6->AutoSize = true;
			this->y6->Location = System::Drawing::Point(37, 90);
			this->y6->Name = L"y6";
			this->y6->Size = System::Drawing::Size(13, 13);
			this->y6->TabIndex = 42;
			this->y6->Text = L"0";
			// 
			// x9
			// 
			this->x9->AutoSize = true;
			this->x9->Location = System::Drawing::Point(444, 384);
			this->x9->Name = L"x9";
			this->x9->Size = System::Drawing::Size(13, 13);
			this->x9->TabIndex = 43;
			this->x9->Text = L"0";
			// 
			// y7
			// 
			this->y7->AutoSize = true;
			this->y7->Location = System::Drawing::Point(37, 51);
			this->y7->Name = L"y7";
			this->y7->Size = System::Drawing::Size(13, 13);
			this->y7->TabIndex = 44;
			this->y7->Text = L"0";
			// 
			// tabControl_transfer_fce
			// 
			this->tabControl_transfer_fce->Controls->Add(this->tabPage1);
			this->tabControl_transfer_fce->Controls->Add(this->tabPage2);
			this->tabControl_transfer_fce->Location = System::Drawing::Point(9, 26);
			this->tabControl_transfer_fce->Name = L"tabControl_transfer_fce";
			this->tabControl_transfer_fce->SelectedIndex = 0;
			this->tabControl_transfer_fce->ShowToolTips = true;
			this->tabControl_transfer_fce->Size = System::Drawing::Size(301, 174);
			this->tabControl_transfer_fce->TabIndex = 47;
			// 
			// tabPage1
			// 
			this->tabPage1->BackColor = System::Drawing::SystemColors::Control;
			this->tabPage1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::None;
			this->tabPage1->Controls->Add(this->poznm);
			this->tabPage1->Controls->Add(this->label_jmen);
			this->tabPage1->Controls->Add(this->label_cit);
			this->tabPage1->Controls->Add(this->soustava_num);
			this->tabPage1->Controls->Add(this->soustava_den);
			this->tabPage1->Location = System::Drawing::Point(4, 22);
			this->tabPage1->Name = L"tabPage1";
			this->tabPage1->Padding = System::Windows::Forms::Padding(3);
			this->tabPage1->Size = System::Drawing::Size(293, 148);
			this->tabPage1->TabIndex = 0;
			this->tabPage1->Text = L"Koef. čit. a jmen.";
			this->tabPage1->ToolTipText = L"Nastavení parametrů přenosu soustavy pomocí definování vektoru koeficientů čitate" 
				L"le a jmenovatele přenosu.\\n Koeficienty čitatele musí být vektor. Počtem koefici" 
				L"entů v daném vektoru je určen řád p.";
			// 
			// poznm
			// 
			this->poznm->AutoSize = true;
			this->poznm->Location = System::Drawing::Point(10, 97);
			this->poznm->Name = L"poznm";
			this->poznm->Size = System::Drawing::Size(274, 13);
			this->poznm->TabIndex = 7;
			this->poznm->Text = L"Poznm.: Řád jmenovatele musí být větší než řád čitatele";
			// 
			// label_jmen
			// 
			this->label_jmen->AutoSize = true;
			this->label_jmen->Location = System::Drawing::Point(10, 50);
			this->label_jmen->Name = L"label_jmen";
			this->label_jmen->Size = System::Drawing::Size(122, 13);
			this->label_jmen->TabIndex = 6;
			this->label_jmen->Text = L"Koeficienty jmenovatele:";
			// 
			// label_cit
			// 
			this->label_cit->AutoSize = true;
			this->label_cit->Location = System::Drawing::Point(10, 7);
			this->label_cit->Name = L"label_cit";
			this->label_cit->Size = System::Drawing::Size(99, 13);
			this->label_cit->TabIndex = 5;
			this->label_cit->Text = L"Koeficienty čitatele:";
			// 
			// tabPage2
			// 
			this->tabPage2->BackColor = System::Drawing::SystemColors::Control;
			this->tabPage2->Controls->Add(this->label_gain);
			this->tabPage2->Controls->Add(this->text_gain);
			this->tabPage2->Controls->Add(this->label_poles);
			this->tabPage2->Controls->Add(this->text_poles);
			this->tabPage2->Controls->Add(this->label_zeros);
			this->tabPage2->Controls->Add(this->text_zeros);
			this->tabPage2->Location = System::Drawing::Point(4, 22);
			this->tabPage2->Name = L"tabPage2";
			this->tabPage2->Padding = System::Windows::Forms::Padding(3);
			this->tabPage2->Size = System::Drawing::Size(293, 148);
			this->tabPage2->TabIndex = 1;
			this->tabPage2->Text = L"Póly a nuly";
			// 
			// label_gain
			// 
			this->label_gain->AutoSize = true;
			this->label_gain->Location = System::Drawing::Point(10, 93);
			this->label_gain->Name = L"label_gain";
			this->label_gain->Size = System::Drawing::Size(47, 13);
			this->label_gain->TabIndex = 55;
			this->label_gain->Text = L"Zesílení";
			// 
			// text_gain
			// 
			this->text_gain->Location = System::Drawing::Point(13, 109);
			this->text_gain->Name = L"text_gain";
			this->text_gain->Size = System::Drawing::Size(249, 20);
			this->text_gain->TabIndex = 54;
			this->text_gain->Text = L"0,2";
			// 
			// label_poles
			// 
			this->label_poles->AutoSize = true;
			this->label_poles->Location = System::Drawing::Point(10, 50);
			this->label_poles->Name = L"label_poles";
			this->label_poles->Size = System::Drawing::Size(30, 13);
			this->label_poles->TabIndex = 53;
			this->label_poles->Text = L"Póly:";
			// 
			// text_poles
			// 
			this->text_poles->Location = System::Drawing::Point(13, 66);
			this->text_poles->Name = L"text_poles";
			this->text_poles->Size = System::Drawing::Size(249, 20);
			this->text_poles->TabIndex = 52;
			this->text_poles->Text = L"-1 -1 -0,1";
			// 
			// label_zeros
			// 
			this->label_zeros->AutoSize = true;
			this->label_zeros->Location = System::Drawing::Point(10, 7);
			this->label_zeros->Name = L"label_zeros";
			this->label_zeros->Size = System::Drawing::Size(31, 13);
			this->label_zeros->TabIndex = 51;
			this->label_zeros->Text = L"Nuly:";
			// 
			// text_zeros
			// 
			this->text_zeros->Location = System::Drawing::Point(13, 23);
			this->text_zeros->Name = L"text_zeros";
			this->text_zeros->Size = System::Drawing::Size(249, 20);
			this->text_zeros->TabIndex = 51;
			// 
			// pause_button
			// 
			this->pause_button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pause_button.Image")));
			this->pause_button->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->pause_button->Location = System::Drawing::Point(425, 529);
			this->pause_button->Name = L"pause_button";
			this->pause_button->Size = System::Drawing::Size(71, 35);
			this->pause_button->TabIndex = 48;
			this->pause_button->Text = L"Pause";
			this->pause_button->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			this->pause_button->UseVisualStyleBackColor = true;
			this->pause_button->Click += gcnew System::EventHandler(this, &Main_form::pause_button_Click);
			// 
			// groupBox1
			// 
			this->groupBox1->BackColor = System::Drawing::SystemColors::Control;
			this->groupBox1->Controls->Add(this->trans_fct_actual_butt);
			this->groupBox1->Controls->Add(this->step_butt);
			this->groupBox1->Controls->Add(this->tabControl_transfer_fce);
			this->groupBox1->Controls->Add(this->label27);
			this->groupBox1->Controls->Add(this->trans_num_text);
			this->groupBox1->Controls->Add(this->trans_den_text);
			this->groupBox1->Controls->Add(this->over);
			this->groupBox1->Location = System::Drawing::Point(10, 12);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(321, 270);
			this->groupBox1->TabIndex = 49;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"Nastavení parametrů přenosu soustavy";
			// 
			// trans_fct_actual_butt
			// 
			this->trans_fct_actual_butt->BackColor = System::Drawing::SystemColors::Control;
			this->trans_fct_actual_butt->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, 
				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(238)));
			this->trans_fct_actual_butt->Location = System::Drawing::Point(263, 210);
			this->trans_fct_actual_butt->Name = L"trans_fct_actual_butt";
			this->trans_fct_actual_butt->Size = System::Drawing::Size(52, 23);
			this->trans_fct_actual_butt->TabIndex = 55;
			this->trans_fct_actual_butt->Text = L"Aktualizovat";
			this->trans_fct_actual_butt->UseVisualStyleBackColor = true;
			this->trans_fct_actual_butt->Click += gcnew System::EventHandler(this, &Main_form::trans_fct_actual_butt_Click);
			// 
			// step_butt
			// 
			this->step_butt->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(238)));
			this->step_butt->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"step_butt.Image")));
			this->step_butt->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->step_butt->Location = System::Drawing::Point(263, 237);
			this->step_butt->Name = L"step_butt";
			this->step_butt->Size = System::Drawing::Size(52, 23);
			this->step_butt->TabIndex = 51;
			this->step_butt->Text = L"1(t)";
			this->step_butt->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			this->step_butt->UseVisualStyleBackColor = true;
			this->step_butt->Click += gcnew System::EventHandler(this, &Main_form::step_butt_Click);
			// 
			// label27
			// 
			this->label27->AutoSize = true;
			this->label27->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(238)));
			this->label27->Location = System::Drawing::Point(2, 227);
			this->label27->Name = L"label27";
			this->label27->Size = System::Drawing::Size(41, 13);
			this->label27->TabIndex = 53;
			this->label27->Text = L"S(p) =";
			// 
			// trans_num_text
			// 
			this->trans_num_text->BackColor = System::Drawing::SystemColors::Control;
			this->trans_num_text->BorderStyle = System::Windows::Forms::BorderStyle::None;
			this->trans_num_text->Location = System::Drawing::Point(42, 210);
			this->trans_num_text->Name = L"trans_num_text";
			this->trans_num_text->ReadOnly = true;
			this->trans_num_text->Size = System::Drawing::Size(216, 24);
			this->trans_num_text->TabIndex = 50;
			this->trans_num_text->Text = L"";
			// 
			// trans_den_text
			// 
			this->trans_den_text->BackColor = System::Drawing::SystemColors::Control;
			this->trans_den_text->BorderStyle = System::Windows::Forms::BorderStyle::None;
			this->trans_den_text->Location = System::Drawing::Point(42, 235);
			this->trans_den_text->Name = L"trans_den_text";
			this->trans_den_text->ReadOnly = true;
			this->trans_den_text->Size = System::Drawing::Size(216, 24);
			this->trans_den_text->TabIndex = 52;
			this->trans_den_text->Text = L"";
			// 
			// over
			// 
			this->over->BackColor = System::Drawing::SystemColors::Control;
			this->over->Location = System::Drawing::Point(41, 234);
			this->over->Name = L"over";
			this->over->Size = System::Drawing::Size(217, 10);
			this->over->TabIndex = 54;
			this->over->TabStop = false;
			this->over->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Main_form::over_Paint);
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->label29);
			this->groupBox2->Controls->Add(this->label28);
			this->groupBox2->Controls->Add(this->U_text);
			this->groupBox2->Controls->Add(this->Y_text);
			this->groupBox2->Controls->Add(this->label4);
			this->groupBox2->Controls->Add(this->label3);
			this->groupBox2->Controls->Add(this->groupBox3);
			this->groupBox2->Controls->Add(this->y7);
			this->groupBox2->Controls->Add(this->x9);
			this->groupBox2->Controls->Add(this->y6);
			this->groupBox2->Controls->Add(this->Autoscale_butt);
			this->groupBox2->Controls->Add(this->y1);
			this->groupBox2->Controls->Add(this->y2);
			this->groupBox2->Controls->Add(this->y3);
			this->groupBox2->Controls->Add(this->y4);
			this->groupBox2->Controls->Add(this->y5);
			this->groupBox2->Controls->Add(this->x6);
			this->groupBox2->Controls->Add(this->x8);
			this->groupBox2->Controls->Add(this->x7);
			this->groupBox2->Controls->Add(this->x5);
			this->groupBox2->Controls->Add(this->x4);
			this->groupBox2->Controls->Add(this->x3);
			this->groupBox2->Controls->Add(this->x2);
			this->groupBox2->Controls->Add(this->x1);
			this->groupBox2->Controls->Add(this->y0);
			this->groupBox2->Controls->Add(this->ymax);
			this->groupBox2->Controls->Add(this->x0);
			this->groupBox2->Controls->Add(this->xmax);
			this->groupBox2->Controls->Add(this->label2);
			this->groupBox2->Controls->Add(this->chart_layout);
			this->groupBox2->Location = System::Drawing::Point(337, 12);
			this->groupBox2->Name = L"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(694, 473);
			this->groupBox2->TabIndex = 50;
			this->groupBox2->TabStop = false;
			this->groupBox2->Text = L"Průběh odezvy soustavy na řízení a akčního zásahu v závislosti na čase";
			this->groupBox2->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Main_form::groupBox2_Paint);
			// 
			// label29
			// 
			this->label29->AutoSize = true;
			this->label29->Location = System::Drawing::Point(324, 424);
			this->label29->Name = L"label29";
			this->label29->Size = System::Drawing::Size(14, 13);
			this->label29->TabIndex = 59;
			this->label29->Text = L"V";
			// 
			// label28
			// 
			this->label28->AutoSize = true;
			this->label28->Location = System::Drawing::Point(324, 444);
			this->label28->Name = L"label28";
			this->label28->Size = System::Drawing::Size(14, 13);
			this->label28->TabIndex = 58;
			this->label28->Text = L"V";
			// 
			// U_text
			// 
			this->U_text->Location = System::Drawing::Point(283, 441);
			this->U_text->Name = L"U_text";
			this->U_text->ReadOnly = true;
			this->U_text->Size = System::Drawing::Size(39, 20);
			this->U_text->TabIndex = 57;
			this->U_text->Text = L"0";
			// 
			// Y_text
			// 
			this->Y_text->Location = System::Drawing::Point(283, 421);
			this->Y_text->Name = L"Y_text";
			this->Y_text->ReadOnly = true;
			this->Y_text->Size = System::Drawing::Size(39, 20);
			this->Y_text->TabIndex = 54;
			this->Y_text->Text = L"0";
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(177, 444);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(84, 13);
			this->label4->TabIndex = 56;
			this->label4->Text = L"akční zásah (u):";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(177, 424);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(100, 13);
			this->label3->TabIndex = 55;
			this->label3->Text = L"výstup soustavy (y):";
			// 
			// groupBox3
			// 
			this->groupBox3->Controls->Add(this->label8);
			this->groupBox3->Controls->Add(this->label7);
			this->groupBox3->Controls->Add(this->label6);
			this->groupBox3->Controls->Add(this->label5);
			this->groupBox3->Controls->Add(this->textBox_X_min);
			this->groupBox3->Controls->Add(this->textBox_Y_max);
			this->groupBox3->Controls->Add(this->textBox_Y_min);
			this->groupBox3->Controls->Add(this->textBox_X_max);
			this->groupBox3->Location = System::Drawing::Point(400, 400);
			this->groupBox3->Name = L"groupBox3";
			this->groupBox3->Size = System::Drawing::Size(263, 71);
			this->groupBox3->TabIndex = 54;
			this->groupBox3->TabStop = false;
			this->groupBox3->Text = L"Nastavení os grafu";
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(134, 47);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(61, 13);
			this->label8->TabIndex = 53;
			this->label8->Text = L"Osa Y max:";
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(134, 21);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(58, 13);
			this->label7->TabIndex = 52;
			this->label7->Text = L"Osa Y min:";
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(7, 47);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(61, 13);
			this->label6->TabIndex = 51;
			this->label6->Text = L"Osa X max:";
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(7, 21);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(58, 13);
			this->label5->TabIndex = 50;
			this->label5->Text = L"Osa X min:";
			// 
			// textBox_X_min
			// 
			this->textBox_X_min->Location = System::Drawing::Point(68, 18);
			this->textBox_X_min->Name = L"textBox_X_min";
			this->textBox_X_min->Size = System::Drawing::Size(39, 20);
			this->textBox_X_min->TabIndex = 49;
			this->textBox_X_min->Text = L"0";
			this->textBox_X_min->Leave += gcnew System::EventHandler(this, &Main_form::textBox_X_min_Leave);
			// 
			// textBox_Y_max
			// 
			this->textBox_Y_max->Location = System::Drawing::Point(198, 44);
			this->textBox_Y_max->Name = L"textBox_Y_max";
			this->textBox_Y_max->Size = System::Drawing::Size(39, 20);
			this->textBox_Y_max->TabIndex = 48;
			this->textBox_Y_max->Text = L"5";
			this->textBox_Y_max->Leave += gcnew System::EventHandler(this, &Main_form::textBox_Y_max_Leave);
			// 
			// textBox_Y_min
			// 
			this->textBox_Y_min->Location = System::Drawing::Point(198, 18);
			this->textBox_Y_min->Name = L"textBox_Y_min";
			this->textBox_Y_min->Size = System::Drawing::Size(39, 20);
			this->textBox_Y_min->TabIndex = 47;
			this->textBox_Y_min->Text = L"0";
			this->textBox_Y_min->Leave += gcnew System::EventHandler(this, &Main_form::textBox_Y_min_Leave);
			// 
			// textBox_X_max
			// 
			this->textBox_X_max->Location = System::Drawing::Point(68, 44);
			this->textBox_X_max->Name = L"textBox_X_max";
			this->textBox_X_max->Size = System::Drawing::Size(39, 20);
			this->textBox_X_max->TabIndex = 46;
			this->textBox_X_max->Text = L"10";
			this->textBox_X_max->Leave += gcnew System::EventHandler(this, &Main_form::textBox_X_max_Leave);
			// 
			// combo_ai
			// 
			this->combo_ai->FormattingEnabled = true;
			this->combo_ai->Items->AddRange(gcnew cli::array< System::Object^  >(8) {L"ai0", L"ai1", L"ai2", L"ai3", L"ai4", L"ai5", 
				L"ai6", L"ai7"});
			this->combo_ai->Location = System::Drawing::Point(11, 65);
			this->combo_ai->Name = L"combo_ai";
			this->combo_ai->Size = System::Drawing::Size(121, 21);
			this->combo_ai->TabIndex = 51;
			this->combo_ai->Text = L"ai0";
			// 
			// combo_ao
			// 
			this->combo_ao->FormattingEnabled = true;
			this->combo_ao->Items->AddRange(gcnew cli::array< System::Object^  >(2) {L"ao0", L"ao1"});
			this->combo_ao->Location = System::Drawing::Point(160, 65);
			this->combo_ao->Name = L"combo_ao";
			this->combo_ao->Size = System::Drawing::Size(121, 21);
			this->combo_ao->TabIndex = 52;
			this->combo_ao->Text = L"ao0";
			// 
			// groupBox4
			// 
			this->groupBox4->Controls->Add(this->dev_stat);
			this->groupBox4->Controls->Add(this->label12);
			this->groupBox4->Controls->Add(this->dev_actul_button);
			this->groupBox4->Controls->Add(this->label11);
			this->groupBox4->Controls->Add(this->label10);
			this->groupBox4->Controls->Add(this->label9);
			this->groupBox4->Controls->Add(this->DevName);
			this->groupBox4->Controls->Add(this->combo_ao);
			this->groupBox4->Controls->Add(this->combo_ai);
			this->groupBox4->Location = System::Drawing::Point(12, 488);
			this->groupBox4->Name = L"groupBox4";
			this->groupBox4->Size = System::Drawing::Size(320, 135);
			this->groupBox4->TabIndex = 53;
			this->groupBox4->TabStop = false;
			this->groupBox4->Text = L"Nastavení NI USB-6008";
			// 
			// dev_stat
			// 
			this->dev_stat->AutoSize = true;
			this->dev_stat->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(238)));
			this->dev_stat->ForeColor = System::Drawing::Color::Red;
			this->dev_stat->Location = System::Drawing::Point(168, 100);
			this->dev_stat->Name = L"dev_stat";
			this->dev_stat->Size = System::Drawing::Size(133, 20);
			this->dev_stat->TabIndex = 59;
			this->dev_stat->Text = L"NEPŘIPOJENO";
			this->toolTip1->SetToolTip(this->dev_stat, resources->GetString(L"dev_stat.ToolTip"));
			// 
			// label12
			// 
			this->label12->AutoSize = true;
			this->label12->Location = System::Drawing::Point(133, 103);
			this->label12->Name = L"label12";
			this->label12->Size = System::Drawing::Size(40, 13);
			this->label12->TabIndex = 58;
			this->label12->Text = L"Status:";
			this->toolTip1->SetToolTip(this->label12, resources->GetString(L"label12.ToolTip"));
			// 
			// dev_actul_button
			// 
			this->dev_actul_button->Location = System::Drawing::Point(9, 98);
			this->dev_actul_button->Name = L"dev_actul_button";
			this->dev_actul_button->Size = System::Drawing::Size(118, 23);
			this->dev_actul_button->TabIndex = 57;
			this->dev_actul_button->Text = L"Aktualizovat/připojit";
			this->dev_actul_button->UseVisualStyleBackColor = true;
			this->dev_actul_button->Click += gcnew System::EventHandler(this, &Main_form::dev_actul_button_Click);
			// 
			// label11
			// 
			this->label11->AutoSize = true;
			this->label11->Location = System::Drawing::Point(160, 46);
			this->label11->Name = L"label11";
			this->label11->Size = System::Drawing::Size(125, 13);
			this->label11->TabIndex = 56;
			this->label11->Text = L"Výběr výstupního kanálu";
			// 
			// label10
			// 
			this->label10->AutoSize = true;
			this->label10->Location = System::Drawing::Point(11, 46);
			this->label10->Name = L"label10";
			this->label10->Size = System::Drawing::Size(120, 13);
			this->label10->TabIndex = 55;
			this->label10->Text = L"Výběr vstupního kanálu";
			// 
			// label9
			// 
			this->label9->AutoSize = true;
			this->label9->Location = System::Drawing::Point(11, 25);
			this->label9->Name = L"label9";
			this->label9->Size = System::Drawing::Size(84, 13);
			this->label9->TabIndex = 54;
			this->label9->Text = L"Název zařízení:";
			this->toolTip1->SetToolTip(this->label9, resources->GetString(L"label9.ToolTip"));
			// 
			// DevName
			// 
			this->DevName->Location = System::Drawing::Point(101, 22);
			this->DevName->Name = L"DevName";
			this->DevName->Size = System::Drawing::Size(183, 20);
			this->DevName->TabIndex = 53;
			this->DevName->Text = L"Dev1";
			// 
			// toolTip1
			// 
			this->toolTip1->AutoPopDelay = 10000;
			this->toolTip1->InitialDelay = 500;
			this->toolTip1->IsBalloon = true;
			this->toolTip1->ReshowDelay = 100;
			this->toolTip1->ToolTipTitle = L"Tip:";
			// 
			// label13
			// 
			this->label13->AutoSize = true;
			this->label13->Location = System::Drawing::Point(10, 107);
			this->label13->Name = L"label13";
			this->label13->Size = System::Drawing::Size(254, 13);
			this->label13->TabIndex = 0;
			this->label13->Text = L"Konst. porucha (v) působící na vstupu soustavy [V]:";
			this->toolTip1->SetToolTip(this->label13, L"Běží-li již simulace a nastavený čas, kdy má chyba nastat je menší než právě aktu" 
				L"ální čas simulace, projeví se vliv poruchy ihned po opuštění políčka amplituda.");
			// 
			// label14
			// 
			this->label14->AutoSize = true;
			this->label14->Location = System::Drawing::Point(10, 152);
			this->label14->Name = L"label14";
			this->label14->Size = System::Drawing::Size(259, 13);
			this->label14->TabIndex = 1;
			this->label14->Text = L"Konst. porucha (n) působící na výstupu soustavy [V]:";
			this->toolTip1->SetToolTip(this->label14, L"Běží-li již simulace a nastavený čas, kdy má chyba nastat je menší než právě aktu" 
				L"ální čas simulace, projeví se vliv poruchy ihned po opuštění políčka amplituda.");
			// 
			// groupBox5
			// 
			this->groupBox5->Controls->Add(this->variance_n);
			this->groupBox5->Controls->Add(this->variance_v);
			this->groupBox5->Controls->Add(this->mean_n);
			this->groupBox5->Controls->Add(this->label26);
			this->groupBox5->Controls->Add(this->label25);
			this->groupBox5->Controls->Add(this->label24);
			this->groupBox5->Controls->Add(this->label23);
			this->groupBox5->Controls->Add(this->mean_v);
			this->groupBox5->Controls->Add(this->label22);
			this->groupBox5->Controls->Add(this->label21);
			this->groupBox5->Controls->Add(this->n_time);
			this->groupBox5->Controls->Add(this->v_time);
			this->groupBox5->Controls->Add(this->n_amp);
			this->groupBox5->Controls->Add(this->v_amp);
			this->groupBox5->Controls->Add(this->label20);
			this->groupBox5->Controls->Add(this->label19);
			this->groupBox5->Controls->Add(this->label18);
			this->groupBox5->Controls->Add(this->label17);
			this->groupBox5->Controls->Add(this->label16);
			this->groupBox5->Controls->Add(this->label15);
			this->groupBox5->Controls->Add(this->label14);
			this->groupBox5->Controls->Add(this->label13);
			this->groupBox5->Location = System::Drawing::Point(12, 284);
			this->groupBox5->Name = L"groupBox5";
			this->groupBox5->Size = System::Drawing::Size(319, 201);
			this->groupBox5->TabIndex = 54;
			this->groupBox5->TabStop = false;
			this->groupBox5->Text = L"Nastavení rušení/kostatní poruchy";
			// 
			// variance_n
			// 
			this->variance_n->Location = System::Drawing::Point(218, 81);
			this->variance_n->Name = L"variance_n";
			this->variance_n->Size = System::Drawing::Size(44, 20);
			this->variance_n->TabIndex = 21;
			this->variance_n->Text = L"0";
			this->variance_n->Leave += gcnew System::EventHandler(this, &Main_form::variance_n_Leave);
			// 
			// variance_v
			// 
			this->variance_v->Location = System::Drawing::Point(218, 36);
			this->variance_v->Name = L"variance_v";
			this->variance_v->Size = System::Drawing::Size(44, 20);
			this->variance_v->TabIndex = 20;
			this->variance_v->Text = L"0";
			this->variance_v->Leave += gcnew System::EventHandler(this, &Main_form::variance_v_Leave);
			// 
			// mean_n
			// 
			this->mean_n->Location = System::Drawing::Point(116, 81);
			this->mean_n->Name = L"mean_n";
			this->mean_n->Size = System::Drawing::Size(44, 20);
			this->mean_n->TabIndex = 19;
			this->mean_n->Text = L"0";
			this->mean_n->Leave += gcnew System::EventHandler(this, &Main_form::mean_n_Leave);
			// 
			// label26
			// 
			this->label26->AutoSize = true;
			this->label26->Location = System::Drawing::Point(171, 84);
			this->label26->Name = L"label26";
			this->label26->Size = System::Drawing::Size(45, 13);
			this->label26->TabIndex = 18;
			this->label26->Text = L"Rozptyl:";
			// 
			// label25
			// 
			this->label25->AutoSize = true;
			this->label25->Location = System::Drawing::Point(21, 84);
			this->label25->Name = L"label25";
			this->label25->Size = System::Drawing::Size(88, 13);
			this->label25->TabIndex = 17;
			this->label25->Text = L"Střední hodnota:";
			// 
			// label24
			// 
			this->label24->AutoSize = true;
			this->label24->Location = System::Drawing::Point(171, 39);
			this->label24->Name = L"label24";
			this->label24->Size = System::Drawing::Size(45, 13);
			this->label24->TabIndex = 16;
			this->label24->Text = L"Rozptyl:";
			// 
			// label23
			// 
			this->label23->AutoSize = true;
			this->label23->Location = System::Drawing::Point(21, 39);
			this->label23->Name = L"label23";
			this->label23->Size = System::Drawing::Size(88, 13);
			this->label23->TabIndex = 15;
			this->label23->Text = L"Střední hodnota:";
			// 
			// mean_v
			// 
			this->mean_v->Location = System::Drawing::Point(116, 36);
			this->mean_v->Name = L"mean_v";
			this->mean_v->Size = System::Drawing::Size(44, 20);
			this->mean_v->TabIndex = 14;
			this->mean_v->Text = L"0";
			this->mean_v->Leave += gcnew System::EventHandler(this, &Main_form::mean_v_Leave);
			// 
			// label22
			// 
			this->label22->AutoSize = true;
			this->label22->Location = System::Drawing::Point(250, 172);
			this->label22->Name = L"label22";
			this->label22->Size = System::Drawing::Size(12, 13);
			this->label22->TabIndex = 13;
			this->label22->Text = L"s";
			// 
			// label21
			// 
			this->label21->AutoSize = true;
			this->label21->Location = System::Drawing::Point(250, 126);
			this->label21->Name = L"label21";
			this->label21->Size = System::Drawing::Size(12, 13);
			this->label21->TabIndex = 12;
			this->label21->Text = L"s";
			// 
			// n_time
			// 
			this->n_time->Location = System::Drawing::Point(204, 169);
			this->n_time->Name = L"n_time";
			this->n_time->Size = System::Drawing::Size(44, 20);
			this->n_time->TabIndex = 11;
			this->n_time->Text = L"0";
			this->n_time->Leave += gcnew System::EventHandler(this, &Main_form::n_time_Leave);
			// 
			// v_time
			// 
			this->v_time->Location = System::Drawing::Point(204, 124);
			this->v_time->Name = L"v_time";
			this->v_time->Size = System::Drawing::Size(44, 20);
			this->v_time->TabIndex = 10;
			this->v_time->Text = L"0";
			this->v_time->Leave += gcnew System::EventHandler(this, &Main_form::v_time_Leave);
			// 
			// n_amp
			// 
			this->n_amp->Location = System::Drawing::Point(96, 169);
			this->n_amp->Name = L"n_amp";
			this->n_amp->Size = System::Drawing::Size(44, 20);
			this->n_amp->TabIndex = 9;
			this->n_amp->Text = L"0";
			this->n_amp->Leave += gcnew System::EventHandler(this, &Main_form::n_amp_Leave);
			// 
			// v_amp
			// 
			this->v_amp->Location = System::Drawing::Point(96, 124);
			this->v_amp->Name = L"v_amp";
			this->v_amp->Size = System::Drawing::Size(44, 20);
			this->v_amp->TabIndex = 8;
			this->v_amp->Text = L"0";
			this->v_amp->Leave += gcnew System::EventHandler(this, &Main_form::v_amp_Leave);
			// 
			// label20
			// 
			this->label20->AutoSize = true;
			this->label20->Location = System::Drawing::Point(157, 172);
			this->label20->Name = L"label20";
			this->label20->Size = System::Drawing::Size(43, 13);
			this->label20->TabIndex = 7;
			this->label20->Text = L"V čase:";
			// 
			// label19
			// 
			this->label19->AutoSize = true;
			this->label19->Location = System::Drawing::Point(21, 172);
			this->label19->Name = L"label19";
			this->label19->Size = System::Drawing::Size(71, 13);
			this->label19->TabIndex = 6;
			this->label19->Text = L"S amplitudou:";
			// 
			// label18
			// 
			this->label18->AutoSize = true;
			this->label18->Location = System::Drawing::Point(157, 126);
			this->label18->Name = L"label18";
			this->label18->Size = System::Drawing::Size(43, 13);
			this->label18->TabIndex = 5;
			this->label18->Text = L"V čase:";
			// 
			// label17
			// 
			this->label17->AutoSize = true;
			this->label17->Location = System::Drawing::Point(21, 126);
			this->label17->Name = L"label17";
			this->label17->Size = System::Drawing::Size(71, 13);
			this->label17->TabIndex = 4;
			this->label17->Text = L"S amplitudou:";
			// 
			// label16
			// 
			this->label16->AutoSize = true;
			this->label16->Location = System::Drawing::Point(10, 62);
			this->label16->Name = L"label16";
			this->label16->Size = System::Drawing::Size(222, 13);
			this->label16->TabIndex = 3;
			this->label16->Text = L"Rušení (n) působící na výstupu soustavy [V]:";
			// 
			// label15
			// 
			this->label15->AutoSize = true;
			this->label15->Location = System::Drawing::Point(10, 17);
			this->label15->Name = L"label15";
			this->label15->Size = System::Drawing::Size(217, 13);
			this->label15->TabIndex = 2;
			this->label15->Text = L"Rušení (v) působící na vstupu soustavy [V]:";
			// 
			// pictureBox1
			// 
			this->pictureBox1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.BackgroundImage")));
			this->pictureBox1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
			this->pictureBox1->Location = System::Drawing::Point(589, 490);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(439, 134);
			this->pictureBox1->TabIndex = 55;
			this->pictureBox1->TabStop = false;
			// 
			// test_checkBox
			// 
			this->test_checkBox->AutoSize = true;
			this->test_checkBox->Location = System::Drawing::Point(348, 592);
			this->test_checkBox->Name = L"test_checkBox";
			this->test_checkBox->Size = System::Drawing::Size(189, 17);
			this->test_checkBox->TabIndex = 56;
			this->test_checkBox->Text = L"TEST - Akční zásah bude roven 1";
			this->test_checkBox->UseVisualStyleBackColor = true;
			// 
			// precise_tim_on
			// 
			this->precise_tim_on->AutoSize = true;
			this->precise_tim_on->Location = System::Drawing::Point(348, 571);
			this->precise_tim_on->Name = L"precise_tim_on";
			this->precise_tim_on->Size = System::Drawing::Size(150, 17);
			this->precise_tim_on->TabIndex = 57;
			this->precise_tim_on->Text = L"Aktivovat přesný časovač";
			this->precise_tim_on->UseVisualStyleBackColor = true;
			// 
			// Main_form
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(1036, 631);
			this->Controls->Add(this->precise_tim_on);
			this->Controls->Add(this->test_checkBox);
			this->Controls->Add(this->pictureBox1);
			this->Controls->Add(this->groupBox5);
			this->Controls->Add(this->groupBox4);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->pause_button);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->TvzTEXTbox);
			this->Controls->Add(this->Stop_button);
			this->Controls->Add(this->Start_button);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
			this->Name = L"Main_form";
			this->Text = L"Sianaso";
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->chart_layout))->EndInit();
			this->tabControl_transfer_fce->ResumeLayout(false);
			this->tabPage1->ResumeLayout(false);
			this->tabPage1->PerformLayout();
			this->tabPage2->ResumeLayout(false);
			this->tabPage2->PerformLayout();
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->over))->EndInit();
			this->groupBox2->ResumeLayout(false);
			this->groupBox2->PerformLayout();
			this->groupBox3->ResumeLayout(false);
			this->groupBox3->PerformLayout();
			this->groupBox4->ResumeLayout(false);
			this->groupBox4->PerformLayout();
			this->groupBox5->ResumeLayout(false);
			this->groupBox5->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

private: 
	System::Void Start_button_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		bool _continue = true;
		
		if (dev_stat->Text->ToString() != "OK")
			if (System::Windows::Forms::DialogResult::No == System::Windows::Forms::MessageBox::Show( L"Měřicí karta je buď v chybovém stavu nebo není připojena.\n Přejete si přesto pokračovat?", L"Upozornění", MessageBoxButtons::YesNo, MessageBoxIcon::Exclamation))
				_continue = false;

		if (_continue)
		{
			if (!_pause)
			{
				Chart1->Chart_Clear();
				chart_layout->Refresh();
				t = 0;
			}
			else
				pause_button->Enabled = true;
			
			Tvz = Double::Parse(this->TvzTEXTbox->Text->ToString());
			
			if (precise_tim_on->Checked == true)
			{
				tim->Interval = Tvz * 1000 * 1000;
				tim->Start();
			}
			else
			{
				timere = gcnew Timer1(Delegate_Sample, Tvz*1000);
			}

			//this->timer1->Interval = Tvz*1000;	//neni potreba protoze timer1 nebude pouzit, protoze je nepresny		 				 

			Start_button->Enabled = false;
			TvzTEXTbox->Enabled = false;
			step_butt->Enabled = false;
			trans_fct_actual_butt->Enabled = false;

			Stop_button->Enabled = true;
			pause_button->Enabled = true;
			precise_tim_on->Enabled = false;
		}

		//tim->Start();
/*
		Time_verify_sample->Start();
		Stopky->Start();

		//plant_over->d
		/* Int64 freq = Stopwatch::Frequency;
		Int64 nanosecPerTick = (1000L * 1000L * 1000L) / freq;
*/
	}

	System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) 
	{ // to necham jen na porovnani presnosti timeru
		double fu;
		milisec[i] = Time_verify_sample->ElapsedMilliseconds;
		Time_verify_sample->Restart();

		Y = (float)F->output(1);
		//Chart1->Chart_AutoScale();
		Chart1->Chart_Draw(t, Y, 0);
		t += Tvz;
		output->write(Y);
		input->read(&fu);
		i++;
	}

	delegate void SetTextDelegate(System:: String ^ s); //aby slo nastavovat stav zarizeni i z vlaken, ktery nejsou spusteny tim hlavnim
	void SetText(System:: String ^ s)
	{
		dev_stat->Text = s;
		dev_stat->ForeColor = Color::Red;
	}
	void SetText_Y_U(System:: String ^ s)
	{
		array<String^>^ _text = s->Split(';');
		Y_text->Text = _text[0];
		U_text->Text = _text[1];
	}

	void Sample(void) //callback fce volana timerem
	{	
		milisec[i] = Time_verify_sample->ElapsedMilliseconds;
		Time_verify_sample->Restart();
		microsec[i] = Stopky->ElapsedMicroseconds;
		Stopky->Restart(); 

		double u = 0; //akcni zasah
/*--------------------------pro test---------------------------*/
/*		float f = 1;
		Y = System::Math::Sin(2 * System::Math::PI * f *t) + 2;*/
		/*if (Y == 0)
			Y = 1;
		else
			Y = 0;*/
/*------------------------------------------------------------*/

		if (input != nullptr) //je-li definovanej vstup, tak precte akci zasah
			input->read(&u);
		if (u < 0.009 && u > -0.009) //protoze to samozrejme nikdy nenameri uplne 0
			u = 0;

		if (test_checkBox->Checked == true)
			u = 1;

		Y = (float)F_output(u); //jednicku pak zmenit na u

		if (output != nullptr)
			output->write(Y);
		Chart1->Chart_Draw(t, Y, 0);
		Chart1->Chart_Draw(t, (float)u, 1);
		t += Tvz;
		i++;
		if (input != nullptr && output != nullptr)
		{
			if (input->error || output->error)
			{
				Control::Invoke(gcnew SetTextDelegate(this, &Main_form::SetText), String::Concat((input->error).ToString(),"; " ,(output->error).ToString()));
			}
		}
		Control::Invoke(gcnew SetTextDelegate(this, &Main_form::SetText_Y_U), String::Concat(Y.ToString("0.000"),";" , u.ToString("0.000")));
	}

	/*-----------------------------------------------------------------------------*/
	System::Void OnTimeEvent(System::Object^ sender, PreciseTimerEventArgs^ e)
	{
		microsec[i] = Stopky->ElapsedMicroseconds;
		Stopky->Restart();
		Sample();
	}
	/*-----------------------------------------------------------------------------*/

	double F_output (double _u)
	{
		double v_aux = 0, n_aux = 0, v_noise = 0, n_noise = 0;

		myrand->Next(0,200);

		if (t >= v_t) //kdyz se cas rovna nebo je vetsi dobe, kdy ma nastat konst. porucha, tak nastane
			v_aux = v;
		if (t >= n_t)
			n_aux = n;
		if (v_variance > 0)
			v_noise = v_mean - v_variance + (2*v_variance)*myrand->NextDouble();
		if (n_variance > 0)
			n_noise = n_mean - n_variance + (2*n_variance)*myrand->NextDouble();

		return F->output(_u+v_aux+v_noise) + n_aux + n_noise;
	}

	System::Void Stop_button_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		this->timer1->Enabled = false;
		Time_verify_sample->Stop();
		if (precise_tim_on->Checked == true)
		{
			tim->Stop();
		}
		else
		{
			delete timere;
		}

		Start_button->Enabled = true;
		TvzTEXTbox->Enabled = true;
		step_butt->Enabled = true;
		Stop_button->Enabled = false;
		pause_button->Enabled = false;
		trans_fct_actual_butt->Enabled = true;
		precise_tim_on->Enabled = true;
		F->clear_states();
		_pause = false;
		if (output != nullptr)
			output->write(0);
		i = 1;
	}

	System::Void pause_button_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		if (precise_tim_on->Checked == true)
		{
			tim->Stop();
		}
		else
		{
			delete timere;
		}
		Start_button->Enabled = true;
		pause_button->Enabled = false;
		precise_tim_on->Enabled = true;
		_pause = true;
	}

	static bool graph_change_scale = false;
	System::Void Autoscale_butt_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		Chart1->Chart_AutoScale();
		this->chart_layout->Refresh();
		//Chart1->Chart_Refresh();

		textBox_X_min->Text = (Chart1->xmin).ToString("0.000");
		textBox_X_max->Text = (Chart1->xmax).ToString("0.000");
		textBox_Y_min->Text = (Chart1->ymin).ToString("0.000");
		textBox_Y_max->Text = (Chart1->ymax).ToString("0.000");
	}

	Rectangle RcDraw;
	System::Void chart_layout_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
	{
		RcDraw.X = e->X;
		RcDraw.Y = e->Y;

		graph_change_scale = true;
		//selection->TranslateTransform( 100, 0 );//DrawRectangle(gcnew Pen( Color::Blue,1 ),0,0, 25,25);//Clear(Color::BurlyWood);
	}

	System::Void chart_layout_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
	{
		graph_change_scale = false;
		Chart1->Chart_Change_Scale(RcDraw);
		chart_layout->Refresh(); //vymaze plochu
		//Chart1->Chart_Refresh(); //obnovi data, co jsou ulozeny v poli chartu
		
		textBox_X_min->Text = (Chart1->xmin).ToString("0.000");
		textBox_X_max->Text = (Chart1->xmax).ToString("0.000");
		textBox_Y_min->Text = (Chart1->ymin).ToString("0.000");
		textBox_Y_max->Text = (Chart1->ymax).ToString("0.000");
		// Force a repaint of the region occupied by the rectangle...
		//this->chart_layout->Invalidate( RcDraw );
	}

	System::Void chart_layout_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
	{
		if (change_grid) //tady to zmenit spis na INIT
		{
			Chart1->Chart_change_grid(e,0,0,10,5, true);
			change_grid = false;
		}

		if (graph_change_scale)
		{
			//graph_ref = false;
			e->Graphics->DrawRectangle(gcnew Pen(Color::Red,1), RcDraw);
			//Chart1->Chart_Refresh(e);
		}
		Chart1->Chart_Refresh(e);
		Chart1->Chart_Refresh_grid(e);
	}

	System::Void chart_layout_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
	{
		RcDraw.Width = e->X - RcDraw.X;
		RcDraw.Height = e->Y - RcDraw.Y;
		//selection->ExcludeClip(RcDraw);//DrawRectangle(gcnew Pen( Color::Red,1 ), RcDraw );
		if (graph_change_scale)
		{					
			this->chart_layout->Invalidate();
		}				 
	}

	array<double>^ Read_from_textBox(TextBox^ textBox)
	{
		array<double>^ returnArr = gcnew array<double>(0);		
		array<String^>^ readString = textBox->Text->ToString()->Split(' '); 

		for (int j=0;j<readString->Length;j++)
		{
			Array::Resize(returnArr,returnArr->Length+1);
			try
			{
				returnArr[j] = Convert::ToDouble(readString[j]);
			}
			catch (...)
			{
				System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
				j = readString->Length;
				returnArr = nullptr;
			}				
		}
		return returnArr;
	}

	bool Read_from_textBox(TextBox^ textBox, double* readNumber)
	{		
		try
		{
			*readNumber = Convert::ToDouble(textBox->Text->ToString());
		}
		catch (...)
		{
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
			return false;
		}				
		return true;
	}

	System::Void textBox_X_min_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		double aux;
		if (Read_from_textBox(this->textBox_X_min, &aux))
		{
			Chart1->Chart_change_grid((float)aux, Chart1->ymin, Chart1->xmax, Chart1->ymax);
			chart_layout->Refresh();
			//Chart1->Chart_Refresh();
		}
	}

	System::Void textBox_X_max_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		double aux;
		if (Read_from_textBox(this->textBox_X_max, &aux))
		{
			Chart1->Chart_change_grid(Chart1->xmin, Chart1->ymin, (float)aux, Chart1->ymax);
			chart_layout->Refresh();
			//Chart1->Chart_Refresh();
		}
	}

	System::Void textBox_Y_min_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		double aux;
		if(Read_from_textBox(this->textBox_Y_min, &aux))
		{
			Chart1->Chart_change_grid(Chart1->xmin, (float)aux, Chart1->xmax, Chart1->ymax);
			chart_layout->Refresh();
			//Chart1->Chart_Refresh();
		}
	}

	System::Void textBox_Y_max_Leave(System::Object^  sender, System::EventArgs^  e)
	{
		double aux;
		if(Read_from_textBox(this->textBox_Y_max, &aux))
		{
			Chart1->Chart_change_grid(Chart1->xmin, Chart1->ymin, Chart1->xmax, (float)aux);
			chart_layout->Refresh();
			//Chart1->Chart_Refresh();
		}
	}

	System::Void dev_actul_button_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		array<int>^ err = gcnew array<int>(2);
		
		err = create_change_NI();
		if ((err[0] == 0) && (err[1] == 0))
		{
			dev_stat->Text = "OK";
			dev_stat->ForeColor = Color::Green;
		}
		else
		{
			dev_stat->Text = String::Concat(err[0].ToString(),"; " ,err[1].ToString());
			dev_stat->ForeColor = Color::Red;
		}
	}
	
	array<int>^ create_change_NI(void)
	{
		char* Dev; 
		char* chann;
		array<int>^err = gcnew array<int>(2);

		Dev = (char*)(void*)Marshal::StringToHGlobalAnsi(DevName->Text->ToString());
		chann = (char*)(void*)Marshal::StringToHGlobalAnsi(combo_ao->Text->ToString());
		if (output == nullptr)
		{
			output = new NI_DAQ('O', Dev, chann);
			output->write(0);
		}
		else
		{
			output->write(0); //nastavi puvodni kanal na 0
			output->change_channel('O', Dev, chann);
			output->write(0); //novy kanal na 0
		}
		err[1] = output->error; //nejdriv se totiz ma vypsat chyba pro vstup proto err[1]

		chann = (char*)(void*)Marshal::StringToHGlobalAnsi(combo_ai->Text->ToString());
		if (input == nullptr)
			input = new NI_DAQ('I', Dev, chann);
		else
			input->change_channel('I', Dev, chann);
		err[0] = input->error;

		Marshal::FreeHGlobal((System::IntPtr)(void*)Dev);
		Marshal::FreeHGlobal((System::IntPtr)(void*)chann);
		
		return err;
	}

	System::Void v_amp_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		try
		{
			v = Convert::ToDouble(v_amp->Text->ToString());
		}
		catch(...)
		{
			v_amp->Text = v.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}
	}

	System::Void v_time_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		try
		{
			v_t = Convert::ToDouble(v_time->Text->ToString());
		}
		catch(...)
		{
			v_time->Text = v_t.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}
	}

	System::Void n_amp_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		try
		{
			n = Convert::ToDouble(n_amp->Text->ToString());
		}
		catch(...)
		{
			n_amp->Text = n.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}
	}

	System::Void n_time_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		try
		{
			n_t = Convert::ToDouble(n_time->Text->ToString());
		}
		catch(...)
		{
			n_time->Text = n_t.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}
	}

	System::Void mean_v_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		try
		{
			v_mean = Convert::ToDouble(mean_v->Text->ToString());
		}
		catch(...)
		{
			mean_v->Text = v_mean.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}

	}

	System::Void variance_v_Leave(System::Object^  sender, System::EventArgs^  e)
	{
		try
		{
			if	(Convert::ToDouble(variance_v->Text->ToString()) >= 0)
				v_variance = Convert::ToDouble(variance_v->Text->ToString());
			else
			{
				variance_v->Text = v_variance.ToString();
				System::Windows::Forms::MessageBox::Show( L"Rozptyl nemůže být záporný", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
			}
		}
		catch(...)
		{
			variance_v->Text = v_variance.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}
	}

	System::Void mean_n_Leave(System::Object^  sender, System::EventArgs^  e) 
	{
		try
		{
			n_mean = Convert::ToDouble(mean_n->Text->ToString());
		}
		catch(...)
		{
			mean_n->Text = n_mean.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}
	}

	System::Void variance_n_Leave(System::Object^  sender, System::EventArgs^  e)
	{
		try
		{
			if (Convert::ToDouble(variance_n->Text->ToString()) >= 0)
				n_variance = Convert::ToDouble(variance_n->Text->ToString());
			else
			{
				variance_n->Text = n_variance.ToString();
				System::Windows::Forms::MessageBox::Show( L"Rozptyl nemůže být záporný", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
			}
		}
		catch(...)
		{
			variance_n->Text = n_variance.ToString();
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
		}
	}
	
	System::Void step_butt_Click(System::Object^  sender, System::EventArgs^  e)
	{
		float y, y_prev;
		if (F == nullptr)
		{
			F = gcnew discrete;
			set_transfer_function();
		}

		F->clear_states();
		Chart1->Chart_Clear();
		chart_layout->Refresh();
		t = 0;

		y = (float)F_output(1);
		Chart1->Chart_Draw(t, y, 0);
		t += Tvz;
		do 
		{
			y_prev = y;
			y = (float)F_output(1);
			if (y < float::MinValue || y > float::MaxValue)
				break;

			Chart1->Chart_Draw(t, y, 0);
			t += Tvz;
		}
		while ((System::Math::Abs(y-y_prev) > 0.00001) && (Chart1->array_index < 10000-2));
		F->clear_states();
	}

	System::Void trans_fct_actual_butt_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		set_transfer_function();
	}

	void set_transfer_function(void)
	{
		System::Windows::Forms::PaintEventArgs^  _e = nullptr;
		set_transfer_function(_e);
	}

	void set_transfer_function(System::Windows::Forms::PaintEventArgs^  e)
	{
		array<double>^num;
		array<double>^den;
		array<double>^auxnum = gcnew array<double>(0);		
		int len;

		Tvz = Double::Parse(this->TvzTEXTbox->Text->ToString());		 				 

		if (tabPage1 == tabControl_transfer_fce->SelectedTab)//provede se, kdyz je vybrana metoda zadavani soustavy pomoci citatele a jmenovatele
		{
			num = Read_from_textBox(this->soustava_num);
			den = Read_from_textBox(this->soustava_den);
			if ((num != nullptr) && (den != nullptr)) //jestli prevod probehl v poradku
			{
				if (num->Length < den->Length) // jestli je citatel mensi nez jmenovatel
				{	
					Array::Resize(auxnum,den->Length-1); //velikost vektoru citatele musi byt stejna jako jmenovatele (pro dalsi vypocty)
					num->CopyTo(auxnum,den->Length - num->Length - 1);
					if (F == nullptr)
						F = gcnew discrete(auxnum,den,Tvz);
					else
						F->create_transfer_function(auxnum,den,Tvz);//tady vytrorit/zmenit prenos F !!!!!!!!!!!!!!!!!
					
					trans_num_text->Clear();
					trans_den_text->Clear();
					trans_num_text->SelectionAlignment = HorizontalAlignment::Center;
					trans_den_text->SelectionAlignment = HorizontalAlignment::Center;
					trans_num_text->SelectionFont = gcnew System::Drawing::Font( "Arial",10 );
					trans_den_text->SelectionFont = gcnew System::Drawing::Font( "Arial",10 );
		
					for(int j=0;j<num->Length;j++)
					{
						if (num[j] != 0)
						{
							if (num[j] > 0 && j > 0)
								trans_num_text->AppendText("+");
							trans_num_text->SelectedText = num[j].ToString();
							if (num->Length-j-1 > 0)
							{
								trans_num_text->AppendText("p");
								trans_num_text->SelectionCharOffset = 5;
								trans_num_text->SelectedText = (num->Length-j-1).ToString();
								trans_num_text->SelectionCharOffset = 0;
								trans_num_text->AppendText(" ");
							}
						}
					}

					for(int j=0;j<den->Length;j++)
					{
						if (den[j] != 0)
						{
							if (den[j] > 0 && j > 0)
								trans_den_text->AppendText("+");
							trans_den_text->SelectedText = den[j].ToString();
							if (den->Length-j-1 > 0)
							{
								trans_den_text->AppendText("p");
								trans_den_text->SelectionCharOffset = 5;
								trans_den_text->SelectedText = (den->Length-j-1).ToString();
								trans_den_text->SelectionCharOffset = 0;
								trans_den_text->AppendText(" ");
							}
						}
					}

					if (trans_den_text->TextLength >= trans_num_text->TextLength)
						len = trans_den_text->TextLength;
					else
						len = trans_num_text->TextLength;
					
					if (e != nullptr)
					{
						e->Graphics->Clear(SystemColors::Control);
						e->Graphics->DrawLine(line2, 216/2-(7*len)/2, 0, 216/2+(7*len)/2, 0);
					}
					else
					{
						plant_over->Clear(SystemColors::Control);
						plant_over->DrawLine(line2, 216/2-(7*len)/2, 0, 216/2+(7*len)/2, 0); //x1 y1 x2 y2, size textboxu = 216
					}

					//Array::Resize(auxnum,den->Length-1); //velikost vektoru citatele musi byt stejna jako jmenovatele (pro dalsi vypocty)
					//num->CopyTo(auxnum,den->Length - num->Length - 1);
					//F = gcnew discrete(auxnum,den,Tvz);
				}
				else
					System::Windows::Forms::MessageBox::Show( L"Řád jmenovatele musí být větší než řád čitatele!", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
			}
		}

		if (tabPage2 == tabControl_transfer_fce->SelectedTab) //kdyz je vybrana metoda zadavani soustavy jako poly a nuly
		{
			bool no_zeros = false;
			array<double>^ _zeros;
			array<double>^ _poles;
			array<double>^ _gain;

			if (text_zeros->Text == "")
			{
				no_zeros = true;
				_zeros = gcnew array<double>{0};
			}
			else
				_zeros = Read_from_textBox(this->text_zeros);

			_poles = Read_from_textBox(this->text_poles);
			_gain = Read_from_textBox(this->text_gain);

			if ((_zeros != nullptr) && (_poles != nullptr) && (_gain != nullptr)) //jestli prevod probehl v poradku
			{
				if (_gain->Length > 1) //tohle spis dat do akce, nebo zalezi, na tom, jak bude udelany to nacteni, jestli tam bude tlacitko
				{
					System::Windows::Forms::MessageBox::Show( L"Zesílení musí být skalár!", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
				}
				else
				{
					mat A, B, aux;
					
					if (!no_zeros)
					{
						num = gcnew array<double>(_zeros->Length+1); //citatel

						for (int j=0;j<_zeros->Length;j++)
							_zeros[j] *= -1;

						A = discrete::array2mat(_zeros, false); //funce pro prevedeni pole na matici je uz udelana v tride discrete
						B.zeros(_zeros->Length,_zeros->Length);
						for (int j=1;j<_zeros->Length;j++)
						{
							B.submat(j,0,j,j-1) = A.submat(0,0,0,j-1); //na a nad hlavni diagonale jsou 0
						}

						num[0] = 1 * _gain[0]; //nejvyssi mocnina polynomu je vzdy
						num[1] = accu(A) * _gain[0]; //dalsi mocnina je soucet korenu
						aux = A;
						for (int j=0;j<(_zeros->Length-2);j++) // - 2 proto, protoze 1. a posledni se proste bud vsechno secte nebo vynasobi
						{
							aux *= B;
							num[j+2] = accu(aux) * _gain[0];
						}
						num[_zeros->Length] = 1;
						for(int j=0;j<_zeros->Length;j++)
						{
							num[_zeros->Length] *= _zeros[j];// a posledni mocnina je soucin korenu
						}
						num[_zeros->Length] *= _gain[0];
					}
					else
					{
						num = gcnew array<double>(1);
						num[0] = 1 *_gain[0]; 
					}
/* Pro jmenovatel -------------------------------------------------------------------------------------------------------------*/
					den = gcnew array<double>(_poles->Length+1); //jmenovatel

					for (int j=0;j<_poles->Length;j++)
						_poles[j] *= -1;

					A = discrete::array2mat(_poles, false); //funce pro prevedeni pole na matici je uz udelana v tride discrete
					B.zeros(_poles->Length,_poles->Length);
					for (int j=1;j<_poles->Length;j++)
					{
						B.submat(j,0,j,j-1) = A.submat(0,0,0,j-1); //na a nad hlavni diagonale jsou 0
					}

					den[0] = 1; //nejvyssi mocnina polynomu je vzdy
					den[1] = accu(A); //dalsi mocnina je soucet korenu
					aux = A;
					for (int j=0;j<(_poles->Length-2);j++) // - 2 proto, protoze 1. a posledni se proste bud vsechno secte nebo vynasobi
					{
						aux *= B;
						den[j+2] = accu(aux);
					}
					den[_poles->Length] = 1;
					for(int j=0;j<_poles->Length;j++)// a posledni mocnina je soucin
					{
						den[_poles->Length] *= _poles[j];
					}
					
					if (num->Length < den->Length) // jestli je citatel mensi nez jmenovatel
					{
						Array::Resize(auxnum,den->Length-1); //velikost vektoru citatele musi byt stejna jako jmenovatele (pro dalsi vypocty)
						num->CopyTo(auxnum,den->Length - num->Length - 1);
						if (F == nullptr)
							F = gcnew discrete(auxnum,den,Tvz);
						else
							F->create_transfer_function(auxnum,den,Tvz);//tady vytrorit/zmenit prenos F !!!!!!!!!!!!!!!!!

						trans_num_text->Clear();
						trans_den_text->Clear();
						trans_num_text->SelectionAlignment = HorizontalAlignment::Center;
						trans_den_text->SelectionAlignment = HorizontalAlignment::Center;
						trans_num_text->SelectionFont = gcnew System::Drawing::Font( "Arial",10 );
						trans_den_text->SelectionFont = gcnew System::Drawing::Font( "Arial",10 );

						if (!no_zeros)
						{
							for (int j=0;j<_zeros->Length;j++)
							{
								//_zeros[j] *= -1;
								if (j == 0 && _gain[0] != 1)
									trans_num_text->SelectedText = _gain[0].ToString();
								trans_num_text->AppendText("(p ");
								if (_zeros[j] > 0)
									trans_num_text->AppendText("+");
								if (_zeros[j] != 0)
									trans_num_text->SelectedText = _zeros[j].ToString();
								trans_num_text->AppendText(")");
							}
						}
						else
							trans_num_text->SelectedText = num[0].ToString();

						for (int j=0;j<_poles->Length;j++)
						{
							//_poles[j] *= -1;
							trans_den_text->AppendText("(p ");
							if (_poles[j] > 0)
								trans_den_text->AppendText("+");
							if (_poles[j] != 0)
								trans_den_text->SelectedText = _poles[j].ToString();
							trans_den_text->AppendText(")");
						}

						if (trans_den_text->TextLength >= trans_num_text->TextLength)
							len = trans_den_text->TextLength;
						else
							len = trans_num_text->TextLength;
					
						if (e != nullptr)
						{
							e->Graphics->Clear(SystemColors::Control);
							e->Graphics->DrawLine(line2, 216/2-(6*len)/2, 0, 216/2+(6*len)/2, 0);
						}
						else
						{
							plant_over->Clear(SystemColors::Control);
							plant_over->DrawLine(line2, 216/2-(6*len)/2, 0, 216/2+(6*len)/2, 0); //x1 y1 x2 y2, size textboxu = 216
						}
					}
					else
						System::Windows::Forms::MessageBox::Show( L"Řád jmenovatele musí být větší než řád čitatele!", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
				}
			}
		}		
	}

	System::Void TvzTEXTbox_Leave(System::Object^  sender, System::EventArgs^  e)
	{
		try
		{
			if (Tvz != (float)Convert::ToDouble(TvzTEXTbox->Text->ToString())) //kdyz se zmeni Tvz, bude potreba prepocitat diskretni ekvivalent soustavy
				set_transfer_function();
		}
		catch (...)
		{
			System::Windows::Forms::MessageBox::Show( L"Data zadána ve špatném formátu", L"CHYBA", MessageBoxButtons::OK, MessageBoxIcon::Error);
			TvzTEXTbox->Text = Tvz.ToString();
		}


	}

	System::Void groupBox2_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
	{
		e->Graphics->DrawLine(gcnew Pen(Color::Yellow, 8.0), 155, 430, 174, 430);
		e->Graphics->DrawLine(gcnew Pen(Color::Red, 8.0), 155, 450, 174, 450);
	}

	System::Void over_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
	{
		set_transfer_function(e);
	}
};
}

