#pragma once

#include <wtypes.h>
#include <windef.h>						// BYTE a DWORD definition
#include <setupapi.h>				
#include <windows.h> 
#include <sstream>
#include <string> 
#include <math.h>						// matematicka knihovna
#include <iomanip>			
#include "form2.h"						// Form2 - nastaveni digitalnich linek
#include "my_functions.h"				// funkce pro detekci, připojení a ovládání HID


//============================== DEFINICE GLOBALNICH PROMENNYCH ===============================================
//int i;
int index = 0;
unsigned long adr;						//docasna promena
unsigned short d16;						//docasna promena
bool form2created = false;				// true je li form2(nastaveni linek) vytvoren 

PopisKanalu Kanaly[16];					// struktura - popisy digitalnich kanalu (prebira se z Form2)
PopisKanalu Vstupy[16];					// struktura - popisy digitalnich kanalu (prebira se z Form2)

float PeriodaAnalog1 = 1.0f;			// PeriodaAnalog1 analogoveno signalu
float AmplitudaAnalog1 = 1.0f;			// AmplitudaAnalog1 analogoveno signalu
float PeriodaAnalog2 = 1.0f;			// PeriodaAnalog1 analogoveno signalu
float AmplitudaAnalog2 = 1.0f;			// AmplitudaAnalog1 analogoveno signalu


	struct SAMPLE						// struktura - sample analogovych signalu - pro hodnoty bodu grafu
	{
		float HodnotaY;
		float HodnotaX;
		bool Existuje;
	};

	struct Vzorky
	{
		int PocetVzorku;
		int Poradi;
		int Nasobitel;
	};
	int PoctyVzorku1 ;
	int PoctyVzorku2 ;
	int PoctyVzorku3 ;
	int NasobiteleVzorku1 ;
	int NasobiteleVzorku2 ;
	int NasobiteleVzorku3 ;
	unsigned short VzorkyDoPameti1[80000];
	unsigned short VzorkyDoPameti2[80000];
	unsigned short VzorkyDoPameti3[80000];
	unsigned int PocatecniAdresaAnalog1 = 0;
	unsigned int PocatecniAdresaAnalog2 = 0;
	unsigned int PocatecniAdresaDigital = 0;

	unsigned int KonecnaAdresaAnalog1 = 0;
	unsigned int KonecnaAdresaAnalog2 = 0;
	unsigned int KonecnaAdresaDigital = 0;


	SAMPLE AnalogDataPB1[1000];					//data v analog grafu
	SAMPLE vzorkyFinal1[80000];
	SAMPLE vzorkyProGen1[1000];

	SAMPLE AnalogDataPB2[1000];	
	SAMPLE vzorkyFinal2[80000];
	SAMPLE vzorkyProGen2[1000];

int PocetDigitalnichVzorku = 20;			// pocet vzorku digitalnich signalu
int PocetDigitalnichVzorkuNaStranku = 20;	// pocet vzorku digitalnich signalu zobrazenych najednou
float DobaDigitalnihoVzorku = 1;			// doba jednoho digitalniho vzorku
float PomernaDobaDigitalnihoVzorku = 1;
float VzorkovaciFrekvence = 250000;

//Vzorky VzorkyStr[3];

bool *DigSample[16];					// 16 ukazatelu na zacatek 1D pole boolu (data pro kazdej jeden digit. kanal)

const int POCETHODNOT = 1000;			// pocet hodnot zadatelnych do grafu analog signalu (chtelo by udelat dynamicky)

bool NaslouchamKlikum = FALSE;			// naslouchani klikum pro zadavani bodu / zmeny digitalnich signalu

bool IsDragging = FALSE;				// true když je mys v dragu (presouvani bodu)

int SelectedSample = -1;				// index vybraneho samplu nebo -1 znamena zadny

int HighlightedDigitalSample = -1;		//zvyrazneni digitalniho samplu, 
int HighlightedDigitalSampleChannel = -1;// zvyrazneni digitalniho kanalu



namespace Generator_20 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;


	
	/// <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 Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//

			for(int k=0;k<16;k++)
			{
				Vstupy[k].PoradiKanalu = 0;
				Vstupy[k].Existuje = false;
			}

//============================= Uzivatelske konstruktory a inicializace ====================================================
			this->pictureBox2->BackColor = Color::Black;	//barva pozadi analog grafu
			this->pictureBox4->BackColor = Color::Black;	//barva pozadi analog grafu
			this->pictureBox3->BackColor = Color::Black;	//barva pozadi digital grafu grafu
			
			this->textBox2->Text += AmplitudaAnalog1;
			this->textBox3->Text += PeriodaAnalog1;
			this->textBox8->Text += AmplitudaAnalog2;
			this->textBox7->Text += PeriodaAnalog2;
			this->comboBox1->SelectedIndex::set(0);
			this->comboBox2->SelectedIndex::set(0);
			this->comboBox3->SelectedIndex::set(0);
			this->comboBox4->SelectedIndex::set(0);
			this->dataGridView1->Rows->Add(1);
			this->dataGridView2->Rows->Add(1);
			this->button3->Enabled = false;
			this->button4->Enabled = false;
			this->button5->Enabled = false;
			this->button9->Enabled = false;
			
			for(int i=0;i<1000;i++)							//inicializace datoveho pole analogovych signalu 
			{
				AnalogDataPB1[i].Existuje=FALSE;
				AnalogDataPB1[i].HodnotaX=0.0f;
				AnalogDataPB1[i].HodnotaY=0.0f;
			};
			AnalogDataPB1[0].Existuje=TRUE;
			AnalogDataPB1[0].HodnotaX=0.0f;
			AnalogDataPB1[0].HodnotaY=0.0f;
			AnalogDataPB1[1].Existuje=TRUE;
			AnalogDataPB1[1].HodnotaX=1.0f;	
			AnalogDataPB1[1].HodnotaY=0.0f;

			//&PoctyVzorku[0] = new int;




			this->KeyPreview = TRUE;						//potřeba aby zachycoval mackani klaves

			//tady se alokace pameti pro digitalni pole booleanu,
			for(int i = 0;i<16;i++)
			{
				DigSample[i] = new bool[PocetDigitalnichVzorku];
				for(int j = 0;j<PocetDigitalnichVzorku;j++)
				{
					*(DigSample[i]+j)=0;
				};
			};

			this->SetStyle(System::Windows::Forms::ControlStyles::AllPaintingInWmPaint,TRUE);

//---------------------------- nastaveni doublebufferu pictureBoxu ---------------------------------------------------------
			context_pb3 = BufferedGraphicsManager::Current;
			context_pb3->MaximumBuffer = System::Drawing::Size( this->pictureBox3->Width + 1, this->pictureBox3->Height + 1 );
			grafx_pb3 = context_pb3->Allocate( this->pictureBox3->CreateGraphics(), System::Drawing::Rectangle(0,0,this->pictureBox3->Width,this->pictureBox3->Height) );

			context_pb2 = BufferedGraphicsManager::Current;
			context_pb2->MaximumBuffer = System::Drawing::Size( this->pictureBox2->Width + 1, this->pictureBox2->Height + 1 );
			grafx_pb2 = context_pb2->Allocate( this->pictureBox2->CreateGraphics(), System::Drawing::Rectangle(0,0,this->pictureBox2->Width,this->pictureBox2->Height) );
			
			context_pb4 = BufferedGraphicsManager::Current;
			context_pb4->MaximumBuffer = System::Drawing::Size( this->pictureBox4->Width + 1, this->pictureBox4->Height + 1 );
			grafx_pb4 = context_pb2->Allocate( this->pictureBox4->CreateGraphics(), System::Drawing::Rectangle(0,0,this->pictureBox4->Width,this->pictureBox4->Height) );
//--------------------------------------------------------------------------------------------------------------------------
			NastaveniKanalu = gcnew form2;					// vytvoří Form2 - nastavovani kanalu
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::PictureBox^  pictureBox1;
	private: System::Windows::Forms::CheckBox^  checkBox1;
	private: System::Windows::Forms::CheckBox^  checkBox2;
	private: System::Windows::Forms::CheckBox^  checkBox3;
	private: System::Windows::Forms::CheckBox^  checkBox4;
	private: System::Windows::Forms::CheckBox^  checkBox5;

	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::Timer^  timer1;
	private: System::Windows::Forms::DataGridView^  dataGridView1;

	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::PictureBox^  pictureBox2;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::PictureBox^  pictureBox3;

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

	protected: 

	private:
		/// <summary>
		/// Required designer variable.

			//nastaveni bufferovych obrazku
			BufferedGraphicsContext^ context_pb2;
			BufferedGraphicsContext^ context_pb3;
			BufferedGraphicsContext^ context_pb4;
			BufferedGraphics^ grafx_pb2;
			BufferedGraphics^ grafx_pb4;
			form2 ^NastaveniKanalu;

private: System::Windows::Forms::StatusStrip^  statusStrip1;
private: System::Windows::Forms::MenuStrip^  menuStrip1;
private: System::Windows::Forms::TabControl^  tabControl1;
private: System::Windows::Forms::TabPage^  tabPage1;
private: System::Windows::Forms::TabPage^  tabPage2;
private: System::Windows::Forms::Label^  label1;
private: System::Windows::Forms::TextBox^  textBox3;
private: System::Windows::Forms::TextBox^  textBox2;
private: System::Windows::Forms::Label^  label2;
private: System::Windows::Forms::ComboBox^  comboBox1;




private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel1;
private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel2;
private: System::Windows::Forms::GroupBox^  groupBox2;
private: System::Windows::Forms::ComboBox^  comboBox2;
private: System::Windows::Forms::Timer^  timer2;
private: System::Windows::Forms::GroupBox^  groupBox3;
private: System::Windows::Forms::ToolStripMenuItem^  souborToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  konecToolStripMenuItem;
private: System::Windows::Forms::TextBox^  textBox4;
private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel3;
private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel4;
private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel5;
private: System::Windows::Forms::Button^  button8;
private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel6;
private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel7;
private: System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel8;
private: System::Windows::Forms::Button^  button9;
private: System::Windows::Forms::GroupBox^  groupBox4;
private: System::Windows::Forms::Button^  button10;
private: System::Windows::Forms::Button^  button11;
private: System::Windows::Forms::Label^  label3;
private: System::Windows::Forms::Label^  label4;
private: System::Windows::Forms::TextBox^  textBox5;
private: System::Windows::Forms::Label^  label5;
private: System::Windows::Forms::TextBox^  textBox6;
private: System::Windows::Forms::ComboBox^  comboBox3;
private: System::Windows::Forms::Label^  label6;
private: System::Windows::Forms::Button^  button13;
private: System::Windows::Forms::Button^  button12;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column1;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column2;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column3;
private: System::Windows::Forms::ComboBox^  comboBox4;
private: System::Windows::Forms::Label^  label7;
private: System::Windows::Forms::Label^  label8;
private: System::Windows::Forms::TextBox^  textBox7;
private: System::Windows::Forms::TextBox^  textBox8;
private: System::Windows::Forms::PictureBox^  pictureBox4;
private: System::Windows::Forms::DataGridView^  dataGridView2;



private: System::Windows::Forms::Button^  button14;
private: System::Windows::Forms::TabPage^  tabPage3;
private: System::Windows::Forms::GroupBox^  groupBox5;
private: System::Windows::Forms::Label^  label10;
private: System::Windows::Forms::Label^  label9;
private: System::Windows::Forms::TextBox^  textBox9;
private: System::Windows::Forms::GroupBox^  groupBox6;
private: System::Windows::Forms::Button^  button16;
private: System::Windows::Forms::Button^  button15;
private: System::Windows::Forms::GroupBox^  groupBox7;
private: System::Windows::Forms::Label^  label11;
private: System::Windows::Forms::TextBox^  textBox10;
private: System::Windows::Forms::Button^  button17;
private: System::Windows::Forms::Label^  label12;
private: System::Windows::Forms::TextBox^  textBox11;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column1_2;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column2_2;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  Column3_2;




		 BufferedGraphics^ grafx_pb3;
		/// </summary>

#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(Form1::typeid));
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox3 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox4 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox5 = (gcnew System::Windows::Forms::CheckBox());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
			this->Column1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
			this->Column2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
			this->Column3 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->button5 = (gcnew System::Windows::Forms::Button());
			this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
			this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
			this->toolStripStatusLabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->toolStripStatusLabel2 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->toolStripStatusLabel3 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->toolStripStatusLabel4 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->toolStripStatusLabel5 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->toolStripStatusLabel6 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->toolStripStatusLabel7 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->toolStripStatusLabel8 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->souborToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->konecToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
			this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
			this->comboBox4 = (gcnew System::Windows::Forms::ComboBox());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->textBox7 = (gcnew System::Windows::Forms::TextBox());
			this->textBox8 = (gcnew System::Windows::Forms::TextBox());
			this->pictureBox4 = (gcnew System::Windows::Forms::PictureBox());
			this->dataGridView2 = (gcnew System::Windows::Forms::DataGridView());
			this->button14 = (gcnew System::Windows::Forms::Button());
			this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
			this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->button13 = (gcnew System::Windows::Forms::Button());
			this->button12 = (gcnew System::Windows::Forms::Button());
			this->comboBox3 = (gcnew System::Windows::Forms::ComboBox());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->textBox6 = (gcnew System::Windows::Forms::TextBox());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->textBox5 = (gcnew System::Windows::Forms::TextBox());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->button11 = (gcnew System::Windows::Forms::Button());
			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
			this->comboBox2 = (gcnew System::Windows::Forms::ComboBox());
			this->textBox4 = (gcnew System::Windows::Forms::TextBox());
			this->tabPage3 = (gcnew System::Windows::Forms::TabPage());
			this->groupBox7 = (gcnew System::Windows::Forms::GroupBox());
			this->label12 = (gcnew System::Windows::Forms::Label());
			this->textBox11 = (gcnew System::Windows::Forms::TextBox());
			this->label11 = (gcnew System::Windows::Forms::Label());
			this->textBox10 = (gcnew System::Windows::Forms::TextBox());
			this->button17 = (gcnew System::Windows::Forms::Button());
			this->groupBox6 = (gcnew System::Windows::Forms::GroupBox());
			this->button16 = (gcnew System::Windows::Forms::Button());
			this->button15 = (gcnew System::Windows::Forms::Button());
			this->groupBox5 = (gcnew System::Windows::Forms::GroupBox());
			this->label10 = (gcnew System::Windows::Forms::Label());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->textBox9 = (gcnew System::Windows::Forms::TextBox());
			this->button10 = (gcnew System::Windows::Forms::Button());
			this->timer2 = (gcnew System::Windows::Forms::Timer(this->components));
			this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
			this->button9 = (gcnew System::Windows::Forms::Button());
			this->button8 = (gcnew System::Windows::Forms::Button());
			this->groupBox4 = (gcnew System::Windows::Forms::GroupBox());
			this->Column1_2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
			this->Column2_2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
			this->Column3_2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			this->groupBox1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView1))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->BeginInit();
			this->statusStrip1->SuspendLayout();
			this->menuStrip1->SuspendLayout();
			this->tabControl1->SuspendLayout();
			this->tabPage1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox4))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView2))->BeginInit();
			this->tabPage2->SuspendLayout();
			this->groupBox2->SuspendLayout();
			this->tabPage3->SuspendLayout();
			this->groupBox7->SuspendLayout();
			this->groupBox6->SuspendLayout();
			this->groupBox5->SuspendLayout();
			this->groupBox3->SuspendLayout();
			this->groupBox4->SuspendLayout();
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(722, 80);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(93, 31);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Nastavení linek";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(6, 89);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(104, 31);
			this->button2->TabIndex = 1;
			this->button2->Text = L"GENERUJ";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// pictureBox1
			// 
			this->pictureBox1->InitialImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.InitialImage")));
			this->pictureBox1->Location = System::Drawing::Point(22, 19);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(51, 51);
			this->pictureBox1->TabIndex = 2;
			this->pictureBox1->TabStop = false;
			// 
			// checkBox1
			// 
			this->checkBox1->AutoSize = true;
			this->checkBox1->Location = System::Drawing::Point(13, 20);
			this->checkBox1->Name = L"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(68, 17);
			this->checkBox1->TabIndex = 3;
			this->checkBox1->Text = L"Analog 1";
			this->checkBox1->UseVisualStyleBackColor = true;
			// 
			// checkBox2
			// 
			this->checkBox2->AutoSize = true;
			this->checkBox2->Location = System::Drawing::Point(13, 43);
			this->checkBox2->Name = L"checkBox2";
			this->checkBox2->Size = System::Drawing::Size(68, 17);
			this->checkBox2->TabIndex = 4;
			this->checkBox2->Text = L"Analog 2";
			this->checkBox2->UseVisualStyleBackColor = true;
			// 
			// checkBox3
			// 
			this->checkBox3->AutoSize = true;
			this->checkBox3->Location = System::Drawing::Point(13, 66);
			this->checkBox3->Name = L"checkBox3";
			this->checkBox3->Size = System::Drawing::Size(55, 17);
			this->checkBox3->TabIndex = 5;
			this->checkBox3->Text = L"Digital";
			this->checkBox3->UseVisualStyleBackColor = true;
			// 
			// checkBox4
			// 
			this->checkBox4->AutoSize = true;
			this->checkBox4->Location = System::Drawing::Point(30, 403);
			this->checkBox4->Name = L"checkBox4";
			this->checkBox4->Size = System::Drawing::Size(53, 17);
			this->checkBox4->TabIndex = 6;
			this->checkBox4->Text = L"LED4";
			this->checkBox4->UseVisualStyleBackColor = true;
			// 
			// checkBox5
			// 
			this->checkBox5->AutoSize = true;
			this->checkBox5->Location = System::Drawing::Point(30, 426);
			this->checkBox5->Name = L"checkBox5";
			this->checkBox5->Size = System::Drawing::Size(53, 17);
			this->checkBox5->TabIndex = 7;
			this->checkBox5->Text = L"LED5";
			this->checkBox5->UseVisualStyleBackColor = true;
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(9, 71);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(100, 20);
			this->textBox1->TabIndex = 11;
			this->textBox1->Text = L"72";
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->pictureBox1);
			this->groupBox1->Location = System::Drawing::Point(34, 612);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(94, 81);
			this->groupBox1->TabIndex = 12;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"Připojení";
			// 
			// timer1
			// 
			this->timer1->Enabled = true;
			this->timer1->Interval = 1000;
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
			// 
			// dataGridView1
			// 
			this->dataGridView1->BackgroundColor = System::Drawing::SystemColors::Window;
			this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
			this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(3) {this->Column1, 
				this->Column2, this->Column3});
			this->dataGridView1->Location = System::Drawing::Point(539, 17);
			this->dataGridView1->Name = L"dataGridView1";
			this->dataGridView1->Size = System::Drawing::Size(273, 279);
			this->dataGridView1->TabIndex = 13;
			// 
			// Column1
			// 
			this->Column1->HeaderText = L"vzorek";
			this->Column1->Name = L"Column1";
			this->Column1->Width = 50;
			// 
			// Column2
			// 
			this->Column2->HeaderText = L"čas";
			this->Column2->Name = L"Column2";
			this->Column2->Width = 90;
			// 
			// Column3
			// 
			this->Column3->HeaderText = L"Napětí";
			this->Column3->Name = L"Column3";
			this->Column3->Width = 90;
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(6, 19);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(104, 31);
			this->button3->TabIndex = 14;
			this->button3->Text = L"Odpoj Analog 1";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(6, 56);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(104, 31);
			this->button4->TabIndex = 15;
			this->button4->Text = L"Odpoj Analog 2";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// button5
			// 
			this->button5->Location = System::Drawing::Point(6, 93);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(104, 31);
			this->button5->TabIndex = 16;
			this->button5->Text = L"Odpoj Digital";
			this->button5->UseVisualStyleBackColor = true;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
			// 
			// pictureBox2
			// 
			this->pictureBox2->Location = System::Drawing::Point(18, 17);
			this->pictureBox2->Name = L"pictureBox2";
			this->pictureBox2->Size = System::Drawing::Size(500, 242);
			this->pictureBox2->TabIndex = 17;
			this->pictureBox2->TabStop = false;
			this->pictureBox2->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox2_MouseMove);
			this->pictureBox2->MouseClick += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox2_MouseClick);
			this->pictureBox2->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox2_MouseDown);
			this->pictureBox2->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox2_Paint);
			this->pictureBox2->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox2_MouseUp);
			// 
			// button6
			// 
			this->button6->Location = System::Drawing::Point(5, 20);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(104, 34);
			this->button6->TabIndex = 18;
			this->button6->Text = L"Nastav";
			this->button6->UseVisualStyleBackColor = true;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
			// 
			// button7
			// 
			this->button7->Location = System::Drawing::Point(18, 265);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(104, 31);
			this->button7->TabIndex = 19;
			this->button7->Text = L"Zadej prubeh";
			this->button7->UseVisualStyleBackColor = true;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
			// 
			// pictureBox3
			// 
			this->pictureBox3->Location = System::Drawing::Point(17, 17);
			this->pictureBox3->Name = L"pictureBox3";
			this->pictureBox3->Size = System::Drawing::Size(690, 609);
			this->pictureBox3->TabIndex = 20;
			this->pictureBox3->TabStop = false;
			this->pictureBox3->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox3_MouseMove);
			this->pictureBox3->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox3_MouseDown);
			this->pictureBox3->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox3_Paint);
			// 
			// statusStrip1
			// 
			this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(8) {this->toolStripStatusLabel1, 
				this->toolStripStatusLabel2, this->toolStripStatusLabel3, this->toolStripStatusLabel4, this->toolStripStatusLabel5, this->toolStripStatusLabel6, 
				this->toolStripStatusLabel7, this->toolStripStatusLabel8});
			this->statusStrip1->Location = System::Drawing::Point(0, 700);
			this->statusStrip1->Name = L"statusStrip1";
			this->statusStrip1->Size = System::Drawing::Size(1016, 22);
			this->statusStrip1->TabIndex = 21;
			this->statusStrip1->Text = L"statusStrip1";
			// 
			// toolStripStatusLabel1
			// 
			this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
			this->toolStripStatusLabel1->Size = System::Drawing::Size(74, 17);
			this->toolStripStatusLabel1->Text = L"Stav zařízení:";
			// 
			// toolStripStatusLabel2
			// 
			this->toolStripStatusLabel2->Margin = System::Windows::Forms::Padding(5, 3, 0, 2);
			this->toolStripStatusLabel2->Name = L"toolStripStatusLabel2";
			this->toolStripStatusLabel2->Size = System::Drawing::Size(73, 17);
			this->toolStripStatusLabel2->Text = L"Nepřipojeno";
			// 
			// toolStripStatusLabel3
			// 
			this->toolStripStatusLabel3->Margin = System::Windows::Forms::Padding(15, 3, 0, 2);
			this->toolStripStatusLabel3->Name = L"toolStripStatusLabel3";
			this->toolStripStatusLabel3->Size = System::Drawing::Size(48, 17);
			this->toolStripStatusLabel3->Text = L"AOUT1:";
			// 
			// toolStripStatusLabel4
			// 
			this->toolStripStatusLabel4->Margin = System::Windows::Forms::Padding(5, 3, 0, 2);
			this->toolStripStatusLabel4->Name = L"toolStripStatusLabel4";
			this->toolStripStatusLabel4->Size = System::Drawing::Size(53, 17);
			this->toolStripStatusLabel4->Text = L"Odpojen";
			// 
			// toolStripStatusLabel5
			// 
			this->toolStripStatusLabel5->Margin = System::Windows::Forms::Padding(15, 3, 0, 2);
			this->toolStripStatusLabel5->Name = L"toolStripStatusLabel5";
			this->toolStripStatusLabel5->Size = System::Drawing::Size(48, 17);
			this->toolStripStatusLabel5->Text = L"AOUT2:";
			// 
			// toolStripStatusLabel6
			// 
			this->toolStripStatusLabel6->Name = L"toolStripStatusLabel6";
			this->toolStripStatusLabel6->Size = System::Drawing::Size(53, 17);
			this->toolStripStatusLabel6->Text = L"Odpojen";
			// 
			// toolStripStatusLabel7
			// 
			this->toolStripStatusLabel7->Margin = System::Windows::Forms::Padding(15, 3, 0, 2);
			this->toolStripStatusLabel7->Name = L"toolStripStatusLabel7";
			this->toolStripStatusLabel7->Size = System::Drawing::Size(42, 17);
			this->toolStripStatusLabel7->Text = L"DOUT:";
			// 
			// toolStripStatusLabel8
			// 
			this->toolStripStatusLabel8->Name = L"toolStripStatusLabel8";
			this->toolStripStatusLabel8->Size = System::Drawing::Size(53, 17);
			this->toolStripStatusLabel8->Text = L"Odpojen";
			// 
			// menuStrip1
			// 
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->souborToolStripMenuItem});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(1016, 24);
			this->menuStrip1->TabIndex = 22;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// souborToolStripMenuItem
			// 
			this->souborToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->konecToolStripMenuItem});
			this->souborToolStripMenuItem->Name = L"souborToolStripMenuItem";
			this->souborToolStripMenuItem->Size = System::Drawing::Size(57, 20);
			this->souborToolStripMenuItem->Text = L"Soubor";
			// 
			// konecToolStripMenuItem
			// 
			this->konecToolStripMenuItem->Name = L"konecToolStripMenuItem";
			this->konecToolStripMenuItem->Size = System::Drawing::Size(107, 22);
			this->konecToolStripMenuItem->Text = L"Konec";
			// 
			// tabControl1
			// 
			this->tabControl1->Controls->Add(this->tabPage1);
			this->tabControl1->Controls->Add(this->tabPage2);
			this->tabControl1->Controls->Add(this->tabPage3);
			this->tabControl1->Location = System::Drawing::Point(164, 27);
			this->tabControl1->Name = L"tabControl1";
			this->tabControl1->SelectedIndex = 0;
			this->tabControl1->Size = System::Drawing::Size(840, 670);
			this->tabControl1->TabIndex = 23;
			this->tabControl1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::tabControl1_SelectedIndexChanged);
			// 
			// tabPage1
			// 
			this->tabPage1->BackColor = System::Drawing::SystemColors::Control;
			this->tabPage1->Controls->Add(this->comboBox4);
			this->tabPage1->Controls->Add(this->label7);
			this->tabPage1->Controls->Add(this->label8);
			this->tabPage1->Controls->Add(this->textBox7);
			this->tabPage1->Controls->Add(this->textBox8);
			this->tabPage1->Controls->Add(this->pictureBox4);
			this->tabPage1->Controls->Add(this->dataGridView2);
			this->tabPage1->Controls->Add(this->button14);
			this->tabPage1->Controls->Add(this->comboBox1);
			this->tabPage1->Controls->Add(this->label2);
			this->tabPage1->Controls->Add(this->label1);
			this->tabPage1->Controls->Add(this->textBox3);
			this->tabPage1->Controls->Add(this->textBox2);
			this->tabPage1->Controls->Add(this->pictureBox2);
			this->tabPage1->Controls->Add(this->dataGridView1);
			this->tabPage1->Controls->Add(this->button7);
			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(832, 644);
			this->tabPage1->TabIndex = 0;
			this->tabPage1->Text = L"Analogové signály";
			// 
			// comboBox4
			// 
			this->comboBox4->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->comboBox4->FormattingEnabled = true;
			this->comboBox4->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"s", L"ms", L"us"});
			this->comboBox4->Location = System::Drawing::Point(295, 585);
			this->comboBox4->Name = L"comboBox4";
			this->comboBox4->Size = System::Drawing::Size(50, 21);
			this->comboBox4->TabIndex = 32;
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(215, 571);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(43, 13);
			this->label7->TabIndex = 31;
			this->label7->Text = L"Perioda";
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(143, 571);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(69, 13);
			this->label8->TabIndex = 30;
			this->label8->Text = L"Amplituda (V)";
			// 
			// textBox7
			// 
			this->textBox7->Location = System::Drawing::Point(218, 585);
			this->textBox7->Name = L"textBox7";
			this->textBox7->Size = System::Drawing::Size(71, 20);
			this->textBox7->TabIndex = 29;
			// 
			// textBox8
			// 
			this->textBox8->BackColor = System::Drawing::SystemColors::Window;
			this->textBox8->Location = System::Drawing::Point(143, 585);
			this->textBox8->Name = L"textBox8";
			this->textBox8->Size = System::Drawing::Size(69, 20);
			this->textBox8->TabIndex = 28;
			// 
			// pictureBox4
			// 
			this->pictureBox4->Location = System::Drawing::Point(18, 326);
			this->pictureBox4->Name = L"pictureBox4";
			this->pictureBox4->Size = System::Drawing::Size(500, 242);
			this->pictureBox4->TabIndex = 26;
			this->pictureBox4->TabStop = false;
			this->pictureBox4->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox4_MouseMove);
			this->pictureBox4->MouseClick += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox4_MouseClick);
			this->pictureBox4->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox4_MouseDown);
			this->pictureBox4->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox4_Paint);
			this->pictureBox4->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox4_MouseUp);
			// 
			// dataGridView2
			// 
			this->dataGridView2->BackgroundColor = System::Drawing::SystemColors::Window;
			this->dataGridView2->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
			this->dataGridView2->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(3) {this->Column1_2, 
				this->Column2_2, this->Column3_2});
			this->dataGridView2->Location = System::Drawing::Point(539, 326);
			this->dataGridView2->Name = L"dataGridView2";
			this->dataGridView2->Size = System::Drawing::Size(273, 279);
			this->dataGridView2->TabIndex = 25;
			// 
			// button14
			// 
			this->button14->Location = System::Drawing::Point(18, 574);
			this->button14->Name = L"button14";
			this->button14->Size = System::Drawing::Size(104, 31);
			this->button14->TabIndex = 27;
			this->button14->Text = L"Zadej prubeh";
			this->button14->UseVisualStyleBackColor = true;
			this->button14->Click += gcnew System::EventHandler(this, &Form1::button14_Click);
			// 
			// comboBox1
			// 
			this->comboBox1->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->comboBox1->FormattingEnabled = true;
			this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"s", L"ms", L"us"});
			this->comboBox1->Location = System::Drawing::Point(294, 276);
			this->comboBox1->Name = L"comboBox1";
			this->comboBox1->Size = System::Drawing::Size(50, 21);
			this->comboBox1->TabIndex = 24;
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(215, 262);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(43, 13);
			this->label2->TabIndex = 23;
			this->label2->Text = L"Perioda";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(143, 262);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(69, 13);
			this->label1->TabIndex = 22;
			this->label1->Text = L"Amplituda (V)";
			// 
			// textBox3
			// 
			this->textBox3->Location = System::Drawing::Point(218, 276);
			this->textBox3->Name = L"textBox3";
			this->textBox3->Size = System::Drawing::Size(71, 20);
			this->textBox3->TabIndex = 21;
			// 
			// textBox2
			// 
			this->textBox2->BackColor = System::Drawing::SystemColors::Window;
			this->textBox2->Location = System::Drawing::Point(143, 276);
			this->textBox2->Name = L"textBox2";
			this->textBox2->Size = System::Drawing::Size(69, 20);
			this->textBox2->TabIndex = 20;
			// 
			// tabPage2
			// 
			this->tabPage2->BackColor = System::Drawing::SystemColors::Control;
			this->tabPage2->Controls->Add(this->label6);
			this->tabPage2->Controls->Add(this->button13);
			this->tabPage2->Controls->Add(this->button12);
			this->tabPage2->Controls->Add(this->comboBox3);
			this->tabPage2->Controls->Add(this->label5);
			this->tabPage2->Controls->Add(this->textBox6);
			this->tabPage2->Controls->Add(this->label4);
			this->tabPage2->Controls->Add(this->textBox5);
			this->tabPage2->Controls->Add(this->label3);
			this->tabPage2->Controls->Add(this->button11);
			this->tabPage2->Controls->Add(this->groupBox2);
			this->tabPage2->Controls->Add(this->pictureBox3);
			this->tabPage2->Controls->Add(this->button1);
			this->tabPage2->Controls->Add(this->textBox4);
			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(832, 644);
			this->tabPage2->TabIndex = 1;
			this->tabPage2->Text = L"Digitální signály";
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(719, 356);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(49, 13);
			this->label6->TabIndex = 35;
			this->label6->Text = L"Str: (1/1)";
			// 
			// button13
			// 
			this->button13->Location = System::Drawing::Point(776, 377);
			this->button13->Name = L"button13";
			this->button13->Size = System::Drawing::Size(39, 31);
			this->button13->TabIndex = 34;
			this->button13->Text = L">>";
			this->button13->UseVisualStyleBackColor = true;
			// 
			// button12
			// 
			this->button12->Location = System::Drawing::Point(722, 377);
			this->button12->Name = L"button12";
			this->button12->Size = System::Drawing::Size(39, 31);
			this->button12->TabIndex = 33;
			this->button12->Text = L"<<";
			this->button12->UseVisualStyleBackColor = true;
			// 
			// comboBox3
			// 
			this->comboBox3->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->comboBox3->FormattingEnabled = true;
			this->comboBox3->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"s", L"ms", L"us"});
			this->comboBox3->Location = System::Drawing::Point(779, 151);
			this->comboBox3->Name = L"comboBox3";
			this->comboBox3->Size = System::Drawing::Size(36, 21);
			this->comboBox3->TabIndex = 32;
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(719, 221);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(102, 13);
			this->label5->TabIndex = 31;
			this->label5->Text = L"Počet vzorků na str:";
			// 
			// textBox6
			// 
			this->textBox6->Location = System::Drawing::Point(722, 239);
			this->textBox6->Name = L"textBox6";
			this->textBox6->Size = System::Drawing::Size(93, 20);
			this->textBox6->TabIndex = 30;
			this->textBox6->Text = L"0";
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(719, 177);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(73, 13);
			this->label4->TabIndex = 29;
			this->label4->Text = L"Počet vzorků:";
			// 
			// textBox5
			// 
			this->textBox5->Location = System::Drawing::Point(722, 195);
			this->textBox5->Name = L"textBox5";
			this->textBox5->Size = System::Drawing::Size(93, 20);
			this->textBox5->TabIndex = 28;
			this->textBox5->Text = L"10";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(719, 133);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(71, 13);
			this->label3->TabIndex = 27;
			this->label3->Text = L"Doba vzorku:";
			// 
			// button11
			// 
			this->button11->Location = System::Drawing::Point(722, 276);
			this->button11->Name = L"button11";
			this->button11->Size = System::Drawing::Size(93, 34);
			this->button11->TabIndex = 26;
			this->button11->Text = L"Zadej průběh";
			this->button11->UseVisualStyleBackColor = true;
			this->button11->Click += gcnew System::EventHandler(this, &Form1::button11_Click);
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->comboBox2);
			this->groupBox2->Location = System::Drawing::Point(722, 15);
			this->groupBox2->Name = L"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(93, 49);
			this->groupBox2->TabIndex = 21;
			this->groupBox2->TabStop = false;
			this->groupBox2->Text = L"Napětí linek";
			// 
			// comboBox2
			// 
			this->comboBox2->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->comboBox2->FormattingEnabled = true;
			this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^  >(2) {L"3,3V", L"5V"});
			this->comboBox2->Location = System::Drawing::Point(7, 20);
			this->comboBox2->Name = L"comboBox2";
			this->comboBox2->Size = System::Drawing::Size(80, 21);
			this->comboBox2->TabIndex = 0;
			// 
			// textBox4
			// 
			this->textBox4->Location = System::Drawing::Point(722, 151);
			this->textBox4->Name = L"textBox4";
			this->textBox4->Size = System::Drawing::Size(51, 20);
			this->textBox4->TabIndex = 25;
			this->textBox4->Text = L"5";
			// 
			// tabPage3
			// 
			this->tabPage3->BackColor = System::Drawing::SystemColors::Control;
			this->tabPage3->Controls->Add(this->groupBox7);
			this->tabPage3->Controls->Add(this->groupBox6);
			this->tabPage3->Controls->Add(this->groupBox5);
			this->tabPage3->Controls->Add(this->button10);
			this->tabPage3->Controls->Add(this->checkBox4);
			this->tabPage3->Controls->Add(this->checkBox5);
			this->tabPage3->Location = System::Drawing::Point(4, 22);
			this->tabPage3->Name = L"tabPage3";
			this->tabPage3->Padding = System::Windows::Forms::Padding(3);
			this->tabPage3->Size = System::Drawing::Size(832, 644);
			this->tabPage3->TabIndex = 2;
			this->tabPage3->Text = L"Testování";
			// 
			// groupBox7
			// 
			this->groupBox7->Controls->Add(this->label12);
			this->groupBox7->Controls->Add(this->textBox11);
			this->groupBox7->Controls->Add(this->label11);
			this->groupBox7->Controls->Add(this->textBox10);
			this->groupBox7->Controls->Add(this->button17);
			this->groupBox7->Location = System::Drawing::Point(312, 22);
			this->groupBox7->Name = L"groupBox7";
			this->groupBox7->Size = System::Drawing::Size(118, 155);
			this->groupBox7->TabIndex = 36;
			this->groupBox7->TabStop = false;
			this->groupBox7->Text = L"Generuj sinus";
			// 
			// label12
			// 
			this->label12->AutoSize = true;
			this->label12->Location = System::Drawing::Point(13, 98);
			this->label12->Name = L"label12";
			this->label12->Size = System::Drawing::Size(53, 13);
			this->label12->TabIndex = 37;
			this->label12->Text = L"Amplituda";
			// 
			// textBox11
			// 
			this->textBox11->Location = System::Drawing::Point(6, 114);
			this->textBox11->Name = L"textBox11";
			this->textBox11->Size = System::Drawing::Size(100, 20);
			this->textBox11->TabIndex = 36;
			this->textBox11->Text = L"10";
			// 
			// label11
			// 
			this->label11->AutoSize = true;
			this->label11->Location = System::Drawing::Point(13, 61);
			this->label11->Name = L"label11";
			this->label11->Size = System::Drawing::Size(58, 13);
			this->label11->TabIndex = 35;
			this->label11->Text = L"Frekvence";
			// 
			// textBox10
			// 
			this->textBox10->Location = System::Drawing::Point(6, 77);
			this->textBox10->Name = L"textBox10";
			this->textBox10->Size = System::Drawing::Size(100, 20);
			this->textBox10->TabIndex = 34;
			this->textBox10->Text = L"1000";
			// 
			// button17
			// 
			this->button17->Location = System::Drawing::Point(6, 17);
			this->button17->Name = L"button17";
			this->button17->Size = System::Drawing::Size(104, 34);
			this->button17->TabIndex = 33;
			this->button17->Text = L"Sinus";
			this->button17->UseVisualStyleBackColor = true;
			this->button17->Click += gcnew System::EventHandler(this, &Form1::button17_Click);
			// 
			// groupBox6
			// 
			this->groupBox6->Controls->Add(this->button16);
			this->groupBox6->Controls->Add(this->button15);
			this->groupBox6->Location = System::Drawing::Point(167, 22);
			this->groupBox6->Name = L"groupBox6";
			this->groupBox6->Size = System::Drawing::Size(122, 106);
			this->groupBox6->TabIndex = 32;
			this->groupBox6->TabStop = false;
			this->groupBox6->Text = L"Předdefinovane";
			// 
			// button16
			// 
			this->button16->Location = System::Drawing::Point(9, 61);
			this->button16->Name = L"button16";
			this->button16->Size = System::Drawing::Size(104, 34);
			this->button16->TabIndex = 32;
			this->button16->Text = L"jednotkovy impuls";
			this->button16->UseVisualStyleBackColor = true;
			this->button16->Click += gcnew System::EventHandler(this, &Form1::button16_Click);
			// 
			// button15
			// 
			this->button15->Location = System::Drawing::Point(8, 18);
			this->button15->Name = L"button15";
			this->button15->Size = System::Drawing::Size(104, 34);
			this->button15->TabIndex = 31;
			this->button15->Text = L"obdelník";
			this->button15->UseVisualStyleBackColor = true;
			this->button15->Click += gcnew System::EventHandler(this, &Form1::button15_Click);
			// 
			// groupBox5
			// 
			this->groupBox5->Controls->Add(this->label10);
			this->groupBox5->Controls->Add(this->label9);
			this->groupBox5->Controls->Add(this->textBox9);
			this->groupBox5->Controls->Add(this->button6);
			this->groupBox5->Controls->Add(this->textBox1);
			this->groupBox5->Location = System::Drawing::Point(21, 22);
			this->groupBox5->Name = L"groupBox5";
			this->groupBox5->Size = System::Drawing::Size(124, 140);
			this->groupBox5->TabIndex = 30;
			this->groupBox5->TabStop = false;
			this->groupBox5->Text = L"Nastavení timeru";
			// 
			// label10
			// 
			this->label10->AutoSize = true;
			this->label10->Location = System::Drawing::Point(12, 94);
			this->label10->Name = L"label10";
			this->label10->Size = System::Drawing::Size(65, 13);
			this->label10->TabIndex = 31;
			this->label10->Text = L"Pocet kroků";
			// 
			// label9
			// 
			this->label9->AutoSize = true;
			this->label9->Location = System::Drawing::Point(12, 57);
			this->label9->Name = L"label9";
			this->label9->Size = System::Drawing::Size(31, 13);
			this->label9->TabIndex = 30;
			this->label9->Text = L"Delič";
			// 
			// textBox9
			// 
			this->textBox9->Location = System::Drawing::Point(9, 110);
			this->textBox9->Name = L"textBox9";
			this->textBox9->Size = System::Drawing::Size(100, 20);
			this->textBox9->TabIndex = 29;
			this->textBox9->Text = L"1";
			// 
			// button10
			// 
			this->button10->Location = System::Drawing::Point(32, 347);
			this->button10->Name = L"button10";
			this->button10->Size = System::Drawing::Size(104, 34);
			this->button10->TabIndex = 28;
			this->button10->Text = L"Write memory";
			this->button10->UseVisualStyleBackColor = true;
			this->button10->Click += gcnew System::EventHandler(this, &Form1::button10_Click);
			// 
			// timer2
			// 
			this->timer2->Interval = 30;
			this->timer2->Tick += gcnew System::EventHandler(this, &Form1::timer2_Tick);
			// 
			// groupBox3
			// 
			this->groupBox3->Controls->Add(this->button9);
			this->groupBox3->Controls->Add(this->checkBox3);
			this->groupBox3->Controls->Add(this->checkBox2);
			this->groupBox3->Controls->Add(this->checkBox1);
			this->groupBox3->Controls->Add(this->button2);
			this->groupBox3->Location = System::Drawing::Point(24, 28);
			this->groupBox3->Name = L"groupBox3";
			this->groupBox3->Size = System::Drawing::Size(116, 163);
			this->groupBox3->TabIndex = 24;
			this->groupBox3->TabStop = false;
			this->groupBox3->Text = L"Generuj signály";
			// 
			// button9
			// 
			this->button9->Location = System::Drawing::Point(6, 126);
			this->button9->Name = L"button9";
			this->button9->Size = System::Drawing::Size(104, 31);
			this->button9->TabIndex = 6;
			this->button9->Text = L"STOP";
			this->button9->UseVisualStyleBackColor = true;
			this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
			// 
			// button8
			// 
			this->button8->Location = System::Drawing::Point(30, 570);
			this->button8->Name = L"button8";
			this->button8->Size = System::Drawing::Size(104, 34);
			this->button8->TabIndex = 26;
			this->button8->Text = L"Odpoj zařízení";
			this->button8->UseVisualStyleBackColor = true;
			this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
			// 
			// groupBox4
			// 
			this->groupBox4->Controls->Add(this->button3);
			this->groupBox4->Controls->Add(this->button4);
			this->groupBox4->Controls->Add(this->button5);
			this->groupBox4->Location = System::Drawing::Point(24, 205);
			this->groupBox4->Name = L"groupBox4";
			this->groupBox4->Size = System::Drawing::Size(116, 130);
			this->groupBox4->TabIndex = 27;
			this->groupBox4->TabStop = false;
			this->groupBox4->Text = L"Odpojení výstupů";
			// 
			// Column1_2
			// 
			this->Column1_2->HeaderText = L"vzorek";
			this->Column1_2->Name = L"Column1_2";
			this->Column1_2->Width = 50;
			// 
			// Column2_2
			// 
			this->Column2_2->HeaderText = L"čas";
			this->Column2_2->Name = L"Column2_2";
			this->Column2_2->Width = 90;
			// 
			// Column3_2
			// 
			this->Column3_2->HeaderText = L"Napětí";
			this->Column3_2->Name = L"Column3_2";
			this->Column3_2->Width = 90;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(1016, 722);
			this->Controls->Add(this->groupBox4);
			this->Controls->Add(this->button8);
			this->Controls->Add(this->groupBox3);
			this->Controls->Add(this->tabControl1);
			this->Controls->Add(this->statusStrip1);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->menuStrip1);
			this->MainMenuStrip = this->menuStrip1;
			this->Name = L"Form1";
			this->Text = L"Generator";
			this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			this->groupBox1->ResumeLayout(false);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView1))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->EndInit();
			this->statusStrip1->ResumeLayout(false);
			this->statusStrip1->PerformLayout();
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->tabControl1->ResumeLayout(false);
			this->tabPage1->ResumeLayout(false);
			this->tabPage1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox4))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView2))->EndInit();
			this->tabPage2->ResumeLayout(false);
			this->tabPage2->PerformLayout();
			this->groupBox2->ResumeLayout(false);
			this->tabPage3->ResumeLayout(false);
			this->tabPage3->PerformLayout();
			this->groupBox7->ResumeLayout(false);
			this->groupBox7->PerformLayout();
			this->groupBox6->ResumeLayout(false);
			this->groupBox5->ResumeLayout(false);
			this->groupBox5->PerformLayout();
			this->groupBox3->ResumeLayout(false);
			this->groupBox3->PerformLayout();
			this->groupBox4->ResumeLayout(false);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
//**************************************************************************************************************************
//								VLASTNI PROGRAMOVA CAST
//**************************************************************************************************************************
// ---------------Timer - detekce zarizeni/vykreslovani grafu kazdou sec----------------------------------------------------
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
			bool pripojeno = FALSE;

			if ( DetekcePripojeni())
			{
				pripojeno = PripojeniZarizeni();
			}
			if ( pripojeno )
			{
				pictureBox1->Load("ok1.png");
				this->toolStripStatusLabel2->Text = "Připojeno";
			}
			else 
			{
				pictureBox1->Load("del1.png");
				this->toolStripStatusLabel2->Text = "Odpojeno";
			}

			// vykresleni grafu každou vteřinu
	//		System::Windows::Forms::PaintEventArgs^ temp;
	//		this->pictureBox3_Paint(sender,temp);
	//		this->pictureBox2_Paint(sender,temp);
			
			//vypis inreportu
	//		int vysledek = MyGetInReport();	
	//		this->textBox1->Text = "";
	//		this->textBox1->Text += vysledek;
		};	 
//--------------------------------------------------------------------------------------------------------------------------

//----------------------vykresleni digitalnich os---------------------------------------------------------------------------

//==========================================================================================================================
//									Digitalni signaly
//seznam funkcí:
//					NakresliOsyDigital()		- vykresli osy grafu
//					NakresliDataDigital()		- vykresli digitalni data do grafu
//					pictureBox3_MouseMove()		- MouseMove - najde nad kterym kanalem a samplem se nachazi mys a zvyrayni ho 
//					pictureBox3_MouseDown()		- MouseDown - prepina stavy na kliknuti mysi
//					button1_Click(..)			- vyvola Form2 nastaveni kanalu
//					
//==========================================================================================================================
private: System::Void NakresliOsyDigital()
		 {
			Graphics^ grafika = grafx_pb3->Graphics;

			//font
			System::Drawing::Font^ font = gcnew System::Drawing::Font("Arial", 8,FontStyle::Regular);
			//brush
			System::Drawing::Brush^ brush = gcnew System::Drawing::SolidBrush(System::Drawing::Color::Blue);
			//penD - plna cara, penD2 - carkovana cara
			System::Drawing::Pen^ penD = gcnew System::Drawing::Pen(System::Drawing::Color::LightGreen);
			System::Drawing::Pen^ penD2 = gcnew System::Drawing::Pen(System::Drawing::Color::FromArgb(0xFF404040) );
			penD2->DashStyle = System::Drawing::Drawing2D::DashStyle(1);
			// velikosti oken urceny rozmerem pictureboxu
			int VelikostOknaX = this->pictureBox3->Width;
			int VelikostOknaY = this->pictureBox3->Height;
			
			grafika->DrawLine(penD,(float)0.05*VelikostOknaX,(float)0.05*VelikostOknaY,(float)0.05*VelikostOknaX,(float)0.95*VelikostOknaY); //osa svisla
			int i = 0;
			for(float f = 0.1f;i<16;i++)				// vykresli vsechny horizontalni osy
			{
				grafika->DrawLine(penD,0.05f*VelikostOknaX,  f*VelikostOknaY,                           0.95f*VelikostOknaX, f*VelikostOknaY); //osa vodorovna 1
				grafika->DrawLine(penD2,0.05f*VelikostOknaX, f*VelikostOknaY-0.055f*0.8f*VelikostOknaY, 0.94f*VelikostOknaX, f*VelikostOknaY-0.055f*0.8f*VelikostOknaY);
				grafika->DrawLine(penD2,0.05f*VelikostOknaX, f*VelikostOknaY-2,                         0.94f*VelikostOknaX, f*VelikostOknaY-2);
				f=f+0.055f;
			};

			penD->Color = System::Drawing::Color::Green;

			int PocetPopiskuXOsy = PocetDigitalnichVzorku;
			System::String^ tempPopisek;

			for(int i = 0;i<PocetPopiskuXOsy+1;i++)		//vykresli vsechny vertikalni cary
			{
				int casPopisek = PomernaDobaDigitalnihoVzorku * i;
				tempPopisek = "";
				tempPopisek += casPopisek; 

				grafika->DrawString(tempPopisek,font,brush,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,0.95f*VelikostOknaY);
				grafika->DrawLine(penD,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.94f*VelikostOknaY,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.96f*VelikostOknaY);
				if(i>0) grafika->DrawLine(penD2,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.93f*VelikostOknaY,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.06f*VelikostOknaY);
			};

			i = 0;
			while(Kanaly[i].Existuje == true)
			{
				String^ s = gcnew String(Kanaly[i].PopisKanaluSelection);
				tempPopisek = s;
				grafika->DrawString(tempPopisek,font,brush,0.01f*VelikostOknaX,(float)i/16.0f*VelikostOknaY*(0.9f)+0.05f*VelikostOknaY);	
				i++;
			}
			
				font = gcnew System::Drawing::Font("Arial", 10,FontStyle::Regular);
				tempPopisek = "t [" + this->comboBox3->SelectedItem->ToString() + "]";
				grafika->DrawString(tempPopisek,font,brush,0.90f*this->pictureBox3->Width,0.97f*this->pictureBox3->Height);
				tempPopisek = "Linky";
				grafika->DrawString(tempPopisek,font,brush,0.03f*this->pictureBox3->Width,0.02f*this->pictureBox3->Height);
};
//--------------------------------------------------------------------------------------------------------------------------
//-------------------------- Vykresleni digitalnich dat --------------------------------------------------------------------
private: System::Void NakresliDataDigital()
		{	
			Graphics^ grafika = grafx_pb3->Graphics;

			int VelikostOknaX = this->pictureBox3->Width;
			int VelikostOknaY = this->pictureBox3->Height;

			System::Drawing::Pen^ pen = gcnew System::Drawing::Pen(System::Drawing::Color::Red);
			pen->Width=3;

			int ii = 0;
			for(float f = 0.1f;ii<16;ii++)
			{
				for(int j =0;j<PocetDigitalnichVzorku;j++)
				{
					pen->Color=System::Drawing::Color::FromArgb(255,200-ii*7,0);
					if(*(DigSample[ii]+j)==1)
					{					// vodorovna cara - horni
						grafika->DrawLine(pen,0.05f*VelikostOknaX+VelikostOknaX*0.9f*j/PocetDigitalnichVzorku,f*VelikostOknaY-0.055f*0.8f*VelikostOknaY,0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku,f*VelikostOknaY-0.055f*0.8f*VelikostOknaY);
						if(j<PocetDigitalnichVzorku-1)
						{
							if(*(DigSample[ii]+j+1)==0)
							{			// svisla cara - sestupna
								grafika->DrawLine(pen,0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku,f*VelikostOknaY-3,0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku,f*VelikostOknaY-0.055f*0.8f*VelikostOknaY);
							};
						};
					}
					else
					{					// vodorovna cara - dolni
						grafika->DrawLine(pen,0.05f*VelikostOknaX+VelikostOknaX*0.9f*j/PocetDigitalnichVzorku,f*VelikostOknaY-3,0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku,f*VelikostOknaY-3);
						if(j<PocetDigitalnichVzorku-1)
						{
							if(*(DigSample[ii]+j+1)==1)
							{			// svisla cara - nabezna
								grafika->DrawLine(pen,0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku,f*VelikostOknaY-3,0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku,f*VelikostOknaY-0.055f*0.8f*VelikostOknaY);
							};
						};
					};
				};
				f=f+0.055f;
			};

			// nakresli zvyrazneni samplu na pozici mysi

			if(HighlightedDigitalSample > -1)//!= -1 )
			{
				System::Drawing::Pen^ pen = gcnew System::Drawing::Pen(System::Drawing::Color::Yellow);
				pen->Width=2;
				float f = 0.1f+0.055f*HighlightedDigitalSampleChannel;
				grafika->DrawRectangle(pen,System::Drawing::Rectangle(int(0.05f*VelikostOknaX+VelikostOknaX*0.9f*HighlightedDigitalSample/PocetDigitalnichVzorku),
					int(f*VelikostOknaY-0.055f*0.8f*VelikostOknaY),
					int(VelikostOknaX*0.9f/PocetDigitalnichVzorku),
					int(0.055f*0.8f*VelikostOknaY) ));
			};			
		}
//--------------------------------------------------------------------------------------------------------------------------
//-------------------------- MouseMove v digitalnim grafu ------------------------------------------------------------------
		 private: System::Void pictureBox3_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {

			 //najdi nad kterym polem je mys, pokud neni nad zadnym tak HighlightedDigitalSample = -1;

			int VelikostOknaX = this->pictureBox3->Width;
			int VelikostOknaY = this->pictureBox3->Height;

			int indexKanal = 0;
			int oldHighlightedDigitalSample = HighlightedDigitalSample;
			int oldHighlightedDigitalSampleChannel = HighlightedDigitalSampleChannel;
			bool Nasel = FALSE;
			for(float f = 0.1f;indexKanal<16;indexKanal++)
			{
			if(
					(e->X > 0)
					&&
					(e->X < 0.05f*VelikostOknaX)
					&&
					(e->Y < f*VelikostOknaY)
					&&
					(e->Y > f*VelikostOknaY-0.055*0.8*VelikostOknaY)
					)				//kontrola kurzoru v Y-ose
				{
					HighlightedDigitalSampleChannel = indexKanal;
					HighlightedDigitalSample = -2;
					Nasel = TRUE;
				};

				for(int j =0;j<PocetDigitalnichVzorku;j++)
				{
					if(
						(e->X > 0.05f*VelikostOknaX+VelikostOknaX*0.9f*j/PocetDigitalnichVzorku)
						&&
						(e->X < 0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku)
						&&
						(e->Y < f*VelikostOknaY)
						&&
						(e->Y > f*VelikostOknaY-0.055*0.8*VelikostOknaY)
						)			// kontrola kurzoru v X-ose
					{
						HighlightedDigitalSampleChannel = indexKanal;
						HighlightedDigitalSample = j;
						Nasel = TRUE;
					};
				};
				f=f+0.055f;
			};
			if(!Nasel)
			{
				HighlightedDigitalSampleChannel = -1;
				HighlightedDigitalSample = -1;
			};
			
			if((oldHighlightedDigitalSample!=HighlightedDigitalSample)||(oldHighlightedDigitalSampleChannel!=HighlightedDigitalSampleChannel))
			{
				System::Windows::Forms::PaintEventArgs^ nullargs;
				this->pictureBox3_Paint(sender,nullargs);
			}
		 };
//--------------------------------------------------------------------------------------------------------------------------
//-------------------------- MouseDown v digitalnim grafu ------------------------------------------------------------------
private: System::Void pictureBox3_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {

			int indexKanal = 0;
			bool Nasel = FALSE;
			int VelikostOknaX = this->pictureBox3->Width;
			int VelikostOknaY = this->pictureBox3->Height;
			for(float f = 0.1f;indexKanal<16;indexKanal++)		// najde kanal a sample podle kurzoru
			{
				for(int j = 0;j<PocetDigitalnichVzorku;j++)
				{
					if(
						(e->X > 0.05f*VelikostOknaX+VelikostOknaX*0.9f*j/PocetDigitalnichVzorku)
						&&
						(e->X < 0.05f*VelikostOknaX+VelikostOknaX*0.9f*(j+1)/PocetDigitalnichVzorku)
						&&
						(e->Y < f*VelikostOknaY)
						&&
						(e->Y > f*VelikostOknaY-0.055*0.8*VelikostOknaY)
						)
					{
						HighlightedDigitalSampleChannel = indexKanal;
						HighlightedDigitalSample = j;
						Nasel = TRUE;
					};
				};
				f=f+0.055f;
			};

			if(Nasel)
			{
				bool ZmenitRadek = TRUE;
				for(int m = HighlightedDigitalSample;m<PocetDigitalnichVzorku;m++)		// zjisti zda je za vybranym samplam nejaka zmena
				{
					if(*(DigSample[HighlightedDigitalSampleChannel]+HighlightedDigitalSample)!= *(DigSample[HighlightedDigitalSampleChannel]+m))
					{
						ZmenitRadek=FALSE;
					};
				};
				if(ZmenitRadek)
				{
					for(int l = HighlightedDigitalSample;l<PocetDigitalnichVzorku;l++)	// neguje vsechy samply od vybraneho
					{
						*(DigSample[HighlightedDigitalSampleChannel]+l) = !*(DigSample[HighlightedDigitalSampleChannel]+l);
					};
				}
				else																	// neguje pouze vybrany sample
				{
					*(DigSample[HighlightedDigitalSampleChannel]+HighlightedDigitalSample) = !*(DigSample[HighlightedDigitalSampleChannel]+HighlightedDigitalSample);
				};
			};

				System::Windows::Forms::PaintEventArgs^ nullargs;
				this->pictureBox3_Paint(sender,nullargs);
		 };
//--------------------------------------------------------------------------------------------------------------------------
// -----------------------Vyvola form 2 - nastaveni kanalu -----------------------------------------------------------------
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		
		NastaveniKanalu->ShowDialog();
			
		 };
// ----------------------- Nastaveni parametru z textboxu ------------------------------------------------------------------
private: System::Void button11_Click(System::Object^  sender, System::EventArgs^  e) {
			
//---------------------nacteni parametru z TB----------------------------------------			
			try			//Nacteni dobu digitalniho vzorku
			{PomernaDobaDigitalnihoVzorku = Convert::ToDouble(textBox4->Text);}
			catch(FormatException^ e){
				e;
				textBox4->BackColor = Color::LightCoral;
			return;}
			catch(OverflowException^ e){
				e;
				textBox4->BackColor = Color::LightCoral;
			return;}
			textBox4->BackColor = SystemColors::Window;

			try			//Nacteni poctu vzorku
			{PocetDigitalnichVzorku = Convert::ToInt32(textBox5->Text);}
			catch(FormatException^ e){
				e;
				textBox5->BackColor = Color::LightCoral;
				return;}
			catch(OverflowException^ e){
				e;
				textBox5->BackColor = Color::LightCoral;
			return;}
			textBox5->BackColor = SystemColors::Window;

			try			//Nacteni poctu vzorku zobrazenych na stracne
			{PocetDigitalnichVzorkuNaStranku = Convert::ToInt32(textBox6->Text);}
			catch(FormatException^ e){
				e;
				textBox6->BackColor = Color::LightCoral;
			return;}
			catch(OverflowException^ e){
				e;
				textBox6->BackColor = Color::LightCoral;
			return;}
			
			switch (this->comboBox3->SelectedIndex::get())
			{
				case 0:
					DobaDigitalnihoVzorku = PomernaDobaDigitalnihoVzorku;
				break;
				case 1:
					DobaDigitalnihoVzorku = PomernaDobaDigitalnihoVzorku/1000;
				break;
				case 2:
					DobaDigitalnihoVzorku = PomernaDobaDigitalnihoVzorku/1000000;
				break;
			}
			for(int i = 0;i<16;i++)
			{
				DigSample[i] = new bool[PocetDigitalnichVzorku];
				for(int j = 0;j<PocetDigitalnichVzorku;j++)
				{
					*(DigSample[i]+j)=0;
				};
			};
			textBox6->BackColor = SystemColors::Window;
			System::Windows::Forms::PaintEventArgs^ nullargs;
			this->pictureBox3_Paint(sender,nullargs);


		 }
//--------------------------------------------------------------------------------------------------------------------------
//==========================================================================================================================
//									Analogove signaly
//seznam funkcí:
//					NakresliOsy()					- vykresli osy analog grafu
//					NakresliData()					- vykresli data analogoveho grafu
//					button7_Click(..)				- inicializace grafu na tlacitko button7
//					pictureBox2_MouseClick(..)		- kliknuti mysi - vubere stavajici nebo vytvori novy bod 
//					pictureBox2_MouseDown(..)		- zacatek draggingu
//					pictureBox2_MouseMove(..)		- pohyb mysi
//					pictureBox2_MouseUp(..)			- konec draggingu
//					Form1_KeyDown					- funkce pro zmacknute klavesy / esc-deselect bodu, del-vymazani bodu
//					
//==========================================================================================================================
 private: System::Void NakresliOsy()
		 {
			Graphics^ grafika = grafx_pb2->Graphics;


			//font
			System::Drawing::Font^ font = gcnew System::Drawing::Font("Arial", 8,FontStyle::Regular);
			//brush
			System::Drawing::Brush^ brush = gcnew System::Drawing::SolidBrush(System::Drawing::Color::Blue);
			//pen
			System::Drawing::Pen^ pen = gcnew System::Drawing::Pen(System::Drawing::Color::LightGreen);
			System::Drawing::Pen^ pen2 = gcnew System::Drawing::Pen(System::Drawing::Color::Chocolate);
			pen2->DashStyle = System::Drawing::Drawing2D::DashStyle(1);

			int VelikostOknaX = this->pictureBox2->Width;
			int VelikostOknaY = this->pictureBox2->Height;

			grafika->DrawLine(pen,(float)0.05*VelikostOknaX,(float)0.05*VelikostOknaY,(float)0.05*VelikostOknaX,(float)0.95*VelikostOknaY); //osa svisla
			grafika->DrawLine(pen,(float)0.05*VelikostOknaX,(float)0.95*VelikostOknaY,(float)0.95*VelikostOknaX,(float)0.95*VelikostOknaY); //osa vodorovna

			//popisky X osy
			pen->Color = System::Drawing::Color::Green;
			int PocetPopiskuXOsy = 10;

			System::String^ tempPopisek;

			for(int i = 0;i<PocetPopiskuXOsy+1;i++)
			{
				if(PeriodaAnalog1>=1.0)			//popisky v s
				{
					tempPopisek = gcnew System::String((PeriodaAnalog1*i/PocetPopiskuXOsy).ToString()+" s");
				}
				else
				{
					if(PeriodaAnalog1>0.001)	//popisky v ms
					{
						tempPopisek = gcnew System::String((1000*PeriodaAnalog1*i/PocetPopiskuXOsy).ToString()+" ms");
					}
					else						//popisky v us
					{
						tempPopisek = gcnew System::String((1000000*PeriodaAnalog1*i/PocetPopiskuXOsy).ToString()+" us");
					};
				};
				grafika->DrawString(tempPopisek,font,brush,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,0.95f*VelikostOknaY);			// popisky X osy
				grafika->DrawLine(pen,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.94f*VelikostOknaY,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.96f*VelikostOknaY);			//vedlejci X-osy
				if(i>0) grafika->DrawLine(pen2,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.93f*VelikostOknaY,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.06f*VelikostOknaY);	// znacky na ose X u popisku
			};
			//popisky Y osy
			int PocetPopiskuYOsy = 10;			//musi byt sudy
			for(int i = 0;i<PocetPopiskuYOsy+1;i++)
			{
				System::String^ tempPopisek;
				short RoundKonst = 3;
				if(AmplitudaAnalog1>1.0)		// popisky ve V
				{
					tempPopisek=gcnew System::String(
						System::Math::Round(((System::Math::Round(AmplitudaAnalog1,RoundKonst)*(((float)i-PocetPopiskuYOsy/2.0f)/(-PocetPopiskuYOsy/2.0f)))),2).ToString()+" V"
						);
				}
				else
				{
					if(AmplitudaAnalog1>0.001)	// popisky v mV
					{
						tempPopisek=gcnew System::String(
							System::Math::Round(((int)(1000*System::Math::Round(AmplitudaAnalog1,RoundKonst)*(((float)i-PocetPopiskuYOsy/2.0f)/(-PocetPopiskuYOsy/2.0f)))),2).ToString()+" mV"
							);
					}
					else				// popisky v uV
					{
						tempPopisek=gcnew System::String(
							System::Math::Round(((int)(1000000*System::Math::Round(AmplitudaAnalog1,RoundKonst)*(((float)i-PocetPopiskuYOsy/2.0f)/(-PocetPopiskuYOsy/2.0f)))),2).ToString()+" uV"
							);
					};
				};
				grafika->DrawString(tempPopisek,font,brush,0.01f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy);		//popisky Y osy
				grafika->DrawLine(pen2,0.07f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy,0.94f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy);  // vedlejsi Y-osy
				grafika->DrawLine(pen,0.04f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy,0.06f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy);	// znacky na ose Y u popisku
			};
				grafika->DrawLine(pen,(float)0.05*VelikostOknaX,(float)0.5*VelikostOknaY,(float)0.95*VelikostOknaX,(float)0.5*VelikostOknaY); //osa nula voltu
};
//--------------------------------------------------------------------------------------------------------------------------
//-------------------- Vykresleni dat - analog -----------------------------------------------------------------------------
private: System::Void NakresliData()						
		 {
			 Graphics^ grafika = grafx_pb2->Graphics;
		
			 int SamplesExist=0;
			 for(int i = 0;i<POCETHODNOT;i++)				//zjisteni poctu vyuzivanych samplu
			{
				if(!AnalogDataPB1[i].Existuje)
				{
					SamplesExist = i+1; 
				}
			};

			//serazeni samplu ve strukture podle casu
	bool swapped = FALSE;
	do
	{
		swapped = FALSE;
		for(int i = 0;i<SamplesExist-1;i++)
		{
			if((AnalogDataPB1[i].HodnotaX>AnalogDataPB1[i+1].HodnotaX)&&(AnalogDataPB1[i].Existuje)&&(AnalogDataPB1[i+1].Existuje))
			{
				if(SelectedSample == i)
				{
					SelectedSample = i+1;					// jinak se pri presouvani zmeni oznaceny sample
				};
				SAMPLE Stemp;
				Stemp.Existuje = AnalogDataPB1[i].Existuje;
				Stemp.HodnotaX = AnalogDataPB1[i].HodnotaX;
				Stemp.HodnotaY = AnalogDataPB1[i].HodnotaY;

				AnalogDataPB1[i].Existuje=AnalogDataPB1[i+1].Existuje;
				AnalogDataPB1[i].HodnotaX=AnalogDataPB1[i+1].HodnotaX;
				AnalogDataPB1[i].HodnotaY=AnalogDataPB1[i+1].HodnotaY;

				AnalogDataPB1[i+1].Existuje=Stemp.Existuje;
				AnalogDataPB1[i+1].HodnotaX=Stemp.HodnotaX;
				AnalogDataPB1[i+1].HodnotaY=Stemp.HodnotaY;
				swapped = TRUE;
			};
		};
	}while(swapped);
			
			int VelikostOknaX = this->pictureBox2->Width;
			int VelikostOknaY = this->pictureBox2->Height;

			System::Drawing::Pen^ pen = gcnew System::Drawing::Pen(System::Drawing::Color::LightGreen);

			pen->Color = System::Drawing::Color::White;


			// vykreslovani dat
			float Offset = this->pictureBox2->Height*0.5f;
			float KurzorX=0.05f*this->pictureBox2->Width;
			float KurzorY=Offset-AnalogDataPB1[0].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog1);
			for(int i = 0;i<SamplesExist;i++)	
			{
				if(AnalogDataPB1[i].Existuje)
				{
					float NoveX = (AnalogDataPB1[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog1)+0.05f*VelikostOknaX;
					float NoveY=Offset-AnalogDataPB1[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog1);
					grafika->DrawLine(pen,(float)KurzorX,(float)KurzorY,NoveX,NoveY);		// vykresleni spojovacich car
					KurzorX = NoveX;KurzorY=NoveY;		

				};
			};

			// vykreslovani krizku v bodech
			const int VelikostKrizku = 5;
			pen->Color = System::Drawing::Color::Red;
			Offset = this->pictureBox2->Height*0.5f;
			KurzorX=0.05f*this->pictureBox2->Width;
			KurzorY=Offset-AnalogDataPB1[0].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog1);
			for(int i = 0;i<SamplesExist;i++)
			{
				if(AnalogDataPB1[i].Existuje)
				{
					grafika->DrawLine(pen,KurzorX-VelikostKrizku,KurzorY,KurzorX+VelikostKrizku,KurzorY);
					grafika->DrawLine(pen,KurzorX,KurzorY-VelikostKrizku,KurzorX,KurzorY+VelikostKrizku);
					float NoveX = (AnalogDataPB1[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog1)+0.05f*VelikostOknaX;
					float NoveY=Offset-AnalogDataPB1[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog1);
					KurzorX = NoveX;KurzorY=NoveY;

				}; 
	/*			if(vzorkyFinal1[i].Existuje)		//vykresleni dopocitanych vzorku do PB
				{
					grafika->DrawLine(pen,KurzorX-VelikostKrizku,KurzorY,KurzorX+VelikostKrizku,KurzorY);
					grafika->DrawLine(pen,KurzorX,KurzorY-VelikostKrizku,KurzorX,KurzorY+VelikostKrizku);
					float NoveX = (vzorkyFinal1[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog1)+0.05f*VelikostOknaX;
					float NoveY=Offset-vzorkyFinal1[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog1);
					KurzorX = NoveX;KurzorY=NoveY;

					//vzorkyFinal1[poradiVz].Existuje == true;
				};
*/
			};

			// vykresleni vybraneho bodu
			const int VelikostCtverecku = 5;
			if(SelectedSample != -1)
			{
				KurzorX = (AnalogDataPB1[SelectedSample].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog1)+0.05f*VelikostOknaX;
				KurzorY = Offset-AnalogDataPB1[SelectedSample].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog1);
				pen->Color = System::Drawing::Color::White;
				grafika->DrawLine(pen,KurzorX-VelikostCtverecku,KurzorY-VelikostCtverecku,KurzorX+VelikostCtverecku,KurzorY-VelikostCtverecku);
				grafika->DrawLine(pen,KurzorX+VelikostCtverecku,KurzorY-VelikostCtverecku,KurzorX+VelikostCtverecku,KurzorY+VelikostCtverecku);
				grafika->DrawLine(pen,KurzorX-VelikostCtverecku,KurzorY+VelikostCtverecku,KurzorX+VelikostCtverecku,KurzorY+VelikostCtverecku);
				grafika->DrawLine(pen,KurzorX-VelikostCtverecku,KurzorY+VelikostCtverecku,KurzorX-VelikostCtverecku,KurzorY-VelikostCtverecku);
			};

	};
//--------------------------------------------------------------------------------------------------------------------------
//--------------------------------- Button7_Click inicializace grafu analogu -----------------------------------------------
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {
			float temp;
			
			try			//Nacteni amplitudy
				{temp = Convert::ToSingle(textBox2->Text);}
			catch(FormatException^ e){
				e;
				textBox2->BackColor = Color::LightCoral;
				return;}
			catch(OverflowException^ e){
				e;
				textBox2->BackColor = Color::LightCoral;
				return;}
			if(temp == 0)
				{AmplitudaAnalog1 = 1;}
			else{AmplitudaAnalog1 = temp;}
			textBox2->BackColor = SystemColors::Window;

			try			//Nacteni periody
				{temp = Convert::ToSingle(textBox3->Text);}
			catch(FormatException^ e){
				e;
				textBox3->BackColor = Color::LightCoral;
				return;}
			catch(OverflowException^ e){
				e;
				textBox3->BackColor = Color::LightCoral;
				return;}
			if(temp == 0)
				{PeriodaAnalog1 = 1;}
			else{PeriodaAnalog1 = temp;}
			switch (comboBox1->SelectedIndex)
				{
				case 1: PeriodaAnalog1 = PeriodaAnalog1/1000;
					this->Column2->HeaderText = "Čas (ms)";  
				break;
				case 2: PeriodaAnalog1 = PeriodaAnalog1/1000000;
					this->Column2->HeaderText = "Čas (us)";					
				break;
				default:
					this->Column2->HeaderText = "Čas (s)";
				break;
				}

			textBox3->BackColor = SystemColors::Window;

			// priprava bufferu pro picturebox
			context_pb2 = BufferedGraphicsManager::Current;
			context_pb2->MaximumBuffer = System::Drawing::Size( this->pictureBox2->Width + 1, this->pictureBox2->Height + 1 );
			grafx_pb2 = context_pb2->Allocate( this->pictureBox2->CreateGraphics(), System::Drawing::Rectangle(0,0,this->pictureBox2->Width,this->pictureBox2->Height) );
			grafx_pb2->Graphics->FillRectangle(Brushes::Black , 0, 0, this->pictureBox2->Width, this->pictureBox2->Height);


	
			NaslouchamKlikum = TRUE;

			for(int i=0;i<1000;i++)				//nulovani pole bodu
			{
				AnalogDataPB1[i].Existuje=FALSE;
				AnalogDataPB1[i].HodnotaX=0.0f;
				AnalogDataPB1[i].HodnotaY=0.0f;
			};
			AnalogDataPB1[0].Existuje=TRUE;		// nastavi prvni bod Amp=0, t=0
			AnalogDataPB1[0].HodnotaX=0.0f;
			AnalogDataPB1[0].HodnotaY=0.0f;
			AnalogDataPB1[1].Existuje=TRUE;		// nastavi posledni bod do Amp=0, t=per
			AnalogDataPB1[1].HodnotaX=PeriodaAnalog1;
			AnalogDataPB1[1].HodnotaY=0.0f;
		NakresliOsy();
		NakresliData();
		grafx_pb2->Render();

		while(this->dataGridView1->Rows->Count != 2)
		{
			this->dataGridView1->Rows->RemoveAt(1);
		}
			switch (comboBox1->SelectedIndex)
				{
				case 1: this->dataGridView1[1,1]->Value = PeriodaAnalog1*1000;
				break;
				case 2: this->dataGridView1[1,1]->Value = PeriodaAnalog1*1000000;
				break;
				default:this->dataGridView1[1,1]->Value = PeriodaAnalog1;
				break;
				}
		this->dataGridView1[0,0]->Value = 1;
		this->dataGridView1[1,0]->Value = "0";
		this->dataGridView1[2,0]->Value = "0";
		this->dataGridView1[0,1]->Value = 2;
		this->dataGridView1[2,1]->Value = "0";
		}
//--------------------------------------------------------------------------------------------------------------------------
//--------------------------------- kliknuti do grafu analogu --------------------------------------------------------------
private: System::Void pictureBox2_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			if(!NaslouchamKlikum)
			{
				return; 
			};

			int VelikostOknaX = this->pictureBox2->Width;
			int VelikostOknaY = this->pictureBox2->Height;

			bool UdelejBod=TRUE;
			if(SelectedSample != -1)
			{
				UdelejBod=FALSE;
			};
			
			SelectedSample=-1;
						const int PixelovaRoztecProSelekci=10;
			for(int i=0;i<1000;i++)			// vybere sample kdyz se klikne do jeho okoli
				{
					if(AnalogDataPB1[i].Existuje)
					{
						if(abs(((AnalogDataPB1[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog1)+0.05f*VelikostOknaX)-e->X)<PixelovaRoztecProSelekci)
						{
							if(abs(VelikostOknaY*0.5f-AnalogDataPB1[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog1)-e->Y)<PixelovaRoztecProSelekci)
							{
								SelectedSample = i;
								UdelejBod=FALSE;
								break;
							};
						};
					};
				};

			if((e->X<0.95f*VelikostOknaX)&&(e->X>0.05f*VelikostOknaX)&&(e->Y>0.1f*VelikostOknaY)&&(e->Y<0.9f*VelikostOknaY)&&(UdelejBod))
			{
				for(int i=0;i<1000;i++)		// pokud neni zadny bod v blizkosti vytvori novy bod
				{
					if(!AnalogDataPB1[i].Existuje)
					{
						AnalogDataPB1[i].Existuje=TRUE;
						AnalogDataPB1[i].HodnotaX=((e->X-0.05f*VelikostOknaX)*PeriodaAnalog1)/(0.9f*(float)VelikostOknaX);	
						AnalogDataPB1[i].HodnotaY=((VelikostOknaY/2.0f)-e->Y)*AmplitudaAnalog1/(0.4f*VelikostOknaY);
						this->dataGridView1->Rows->Add(1);
						break;
					};
				};
			};

			System::Windows::Forms::PaintEventArgs^ nullargs;
			this->pictureBox2_Paint(sender,nullargs);
			int j = 0;
			for(int i=0;i<this->dataGridView1->Rows->Count::get();i++)		// vypis do datagridu
			{
				if(AnalogDataPB1[i].Existuje == true)
				{
					this->dataGridView1[0,j]->Value = j+1;
					double temp = AnalogDataPB1[i].HodnotaX;
					this->Column2->Name = "Čas (s)";
					if( this->comboBox1->SelectedIndex == 1)
					{ temp = temp * 1000;}
					if( this->comboBox1->SelectedIndex == 2)
					{ temp = temp * 1000000;}
					this->dataGridView1[1,j]->Value = Math::Round(temp,2);
					temp = AnalogDataPB1[i].HodnotaY;
					this->dataGridView1[2,j]->Value = Math::Round(temp,2);
					j++;
				};
			};
		 }

//-------------------------------------------------------------------------------------------------------------------------
//------------------------ MouseDown v grafu analogu ----------------------------------------------------------------------
private: System::Void pictureBox2_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 if(SelectedSample!=-1)
			 {
				 IsDragging = TRUE;				//zapoceti dragu
			 };
		 }
//--------------------------------------------------------------------------------------------------------------------------
//------------------------ MouseMove v grafu analogu -----------------------------------------------------------------------

private: System::Void pictureBox2_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			if(IsDragging)
			 {
						int VelikostOknaX = this->pictureBox2->Width;
						int VelikostOknaY = this->pictureBox2->Height;

						// vyhledaji se sousedni body, aby nesly prez sebe
						float MinX=0.0f;float MaxX=(float)VelikostOknaY;
						if(SelectedSample>0)
						{
							MinX = (AnalogDataPB1[SelectedSample-1].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog1)+0.05f*VelikostOknaX;
						};
						if(SelectedSample < 999) 
						{
							MaxX = (AnalogDataPB1[SelectedSample+1].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog1)+0.05f*VelikostOknaX;
						};
						// zmeni se data vybraneho bodu a zavola vykresleni
						if((e->X<0.95f*VelikostOknaX)&&(e->X>0.05f*VelikostOknaX)&&(e->Y>0.1f*VelikostOknaY)&&(e->Y<0.9f*VelikostOknaY)&&(e->X<MaxX)&&(e->X>MinX))
						{
				 			AnalogDataPB1[SelectedSample].HodnotaX=((e->X-0.05f*VelikostOknaX)*PeriodaAnalog1)/(0.9f*(float)VelikostOknaX);	
							AnalogDataPB1[SelectedSample].HodnotaY=( (VelikostOknaY/2.0f)-e->Y)*AmplitudaAnalog1/(0.4f*VelikostOknaY);
						};

				System::Windows::Forms::PaintEventArgs^ nullargs;
				this->pictureBox2_Paint(sender,nullargs);
			 };
		 }
//--------------------------------------------------------------------------------------------------------------------------
//------------------------ MouseUp v grafu analogu -------------------------------------------------------------------------
private: System::Void pictureBox2_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 IsDragging = FALSE;										// ukonceni dragu
		 }
//--------------------------------------------------------------------------------------------------------------------------
//==========================================================================================================================
//									Analogove signaly
//seznam funkcí:
//					NakresliOsy2()					- vykresli osy analog grafu
//					NakresliData2()					- vykresli data analogoveho grafu
//					button14_Click(..)				- inicializace grafu na tlacitko button14
//					pictureBox4_MouseClick(..)		- kliknuti mysi - vubere stavajici nebo vytvori novy bod 
//					pictureBox4_MouseDown(..)		- zacatek draggingu
//					pictureBox4_MouseMove(..)		- pohyb mysi
//					pictureBox4_MouseUp(..)			- konec draggingu
//					Form1_KeyDown					- funkce pro zmacknute klavesy / esc-deselect bodu, del-vymazani bodu
//					
//==========================================================================================================================
 private: System::Void NakresliOsy2()
		 {
			Graphics^ grafika = grafx_pb4->Graphics;


			//font
			System::Drawing::Font^ font = gcnew System::Drawing::Font("Arial", 8,FontStyle::Regular);
			//brush
			System::Drawing::Brush^ brush = gcnew System::Drawing::SolidBrush(System::Drawing::Color::Blue);
			//pen
			System::Drawing::Pen^ pen = gcnew System::Drawing::Pen(System::Drawing::Color::LightGreen);
			System::Drawing::Pen^ pen2 = gcnew System::Drawing::Pen(System::Drawing::Color::Chocolate);
			pen2->DashStyle = System::Drawing::Drawing2D::DashStyle(1);

			int VelikostOknaX = this->pictureBox4->Width;
			int VelikostOknaY = this->pictureBox4->Height;

			grafika->DrawLine(pen,(float)0.05*VelikostOknaX,(float)0.05*VelikostOknaY,(float)0.05*VelikostOknaX,(float)0.95*VelikostOknaY); //osa svisla
			grafika->DrawLine(pen,(float)0.05*VelikostOknaX,(float)0.95*VelikostOknaY,(float)0.95*VelikostOknaX,(float)0.95*VelikostOknaY); //osa vodorovna

			//popisky X osy
			pen->Color = System::Drawing::Color::Green;
			int PocetPopiskuXOsy = 10;

			System::String^ tempPopisek;

			for(int i = 0;i<PocetPopiskuXOsy+1;i++)
			{
				if(PeriodaAnalog2>=1.0)			//popisky v s
				{
					tempPopisek = gcnew System::String((PeriodaAnalog2*i/PocetPopiskuXOsy).ToString()+" s");
				}
				else
				{
					if(PeriodaAnalog2>0.001)	//popisky v ms
					{
						tempPopisek = gcnew System::String((1000*PeriodaAnalog2*i/PocetPopiskuXOsy).ToString()+" ms");
					}
					else						//popisky v us
					{
						tempPopisek = gcnew System::String((1000000*PeriodaAnalog2*i/PocetPopiskuXOsy).ToString()+" us");
					};
				};
				grafika->DrawString(tempPopisek,font,brush,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,0.95f*VelikostOknaY);			// popisky X osy
				grafika->DrawLine(pen,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.94f*VelikostOknaY,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.96f*VelikostOknaY);			//vedlejci X-osy
				if(i>0) grafika->DrawLine(pen2,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.93f*VelikostOknaY,0.05f*VelikostOknaX+VelikostOknaX*0.9f*i/PocetPopiskuXOsy,(float)0.06f*VelikostOknaY);	// znacky na ose X u popisku
			};
			//popisky Y osy
			int PocetPopiskuYOsy = 10;			//musi byt sudy
			for(int i = 0;i<PocetPopiskuYOsy+1;i++)
			{
				System::String^ tempPopisek;
				short RoundKonst = 3;
				if(AmplitudaAnalog2>1.0)		// popisky ve V
				{
					tempPopisek=gcnew System::String(
						System::Math::Round(((System::Math::Round(AmplitudaAnalog2,RoundKonst)*(((float)i-PocetPopiskuYOsy/2.0f)/(-PocetPopiskuYOsy/2.0f)))),2).ToString()+" V"
						);
				}
				else
				{
					if(AmplitudaAnalog2>0.001)	// popisky ve mV
					{
						tempPopisek=gcnew System::String(
							System::Math::Round(((int)(1000*System::Math::Round(AmplitudaAnalog2,RoundKonst)*(((float)i-PocetPopiskuYOsy/2.0f)/(-PocetPopiskuYOsy/2.0f)))),2).ToString()+" mV"
							);
					}
					else						// popisky ve uV
					{
						tempPopisek=gcnew System::String(
							System::Math::Round(((int)(1000000*System::Math::Round(AmplitudaAnalog2,RoundKonst)*(((float)i-PocetPopiskuYOsy/2.0f)/(-PocetPopiskuYOsy/2.0f)))),2).ToString()+" uV"
							);
					};
				};
				grafika->DrawString(tempPopisek,font,brush,0.01f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy);		//popisky Y osy
				grafika->DrawLine(pen2,0.07f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy,0.94f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy);  // vedlejsi Y-osy
				grafika->DrawLine(pen,0.04f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy,0.06f*VelikostOknaX,0.1f*VelikostOknaY+VelikostOknaY*0.8f*i/PocetPopiskuYOsy);	// znacky na ose Y u popisku
			};
				grafika->DrawLine(pen,(float)0.05*VelikostOknaX,(float)0.5*VelikostOknaY,(float)0.95*VelikostOknaX,(float)0.5*VelikostOknaY); //osa nula voltu
};
//--------------------------------------------------------------------------------------------------------------------------
//-------------------- Vykresleni dat - analog -----------------------------------------------------------------------------
private: System::Void NakresliData2()						
		 {
			 Graphics^ grafika = grafx_pb4->Graphics;
		
			 int SamplesExist=0;
			 for(int i = 0;i<POCETHODNOT;i++)				//zjisteni poctu vyuzivanych samplu
			{
				if(!AnalogDataPB2[i].Existuje)
				{
					SamplesExist = i+1; 
				}
			};

			//serazeni samplu ve strukture podle casu
	bool swapped = FALSE;
	do
	{
		swapped = FALSE;
		for(int i = 0;i<SamplesExist-1;i++)
		{
			if((AnalogDataPB2[i].HodnotaX>AnalogDataPB2[i+1].HodnotaX)&&(AnalogDataPB2[i].Existuje)&&(AnalogDataPB2[i+1].Existuje))
			{
				if(SelectedSample == i)
				{
					SelectedSample = i+1;					// jinak se pri presouvani zmeni oznaceny sample
				};
				SAMPLE Stemp;
				Stemp.Existuje = AnalogDataPB2[i].Existuje;
				Stemp.HodnotaX = AnalogDataPB2[i].HodnotaX;
				Stemp.HodnotaY = AnalogDataPB2[i].HodnotaY;

				AnalogDataPB2[i].Existuje=AnalogDataPB2[i+1].Existuje;
				AnalogDataPB2[i].HodnotaX=AnalogDataPB2[i+1].HodnotaX;
				AnalogDataPB2[i].HodnotaY=AnalogDataPB2[i+1].HodnotaY;

				AnalogDataPB2[i+1].Existuje=Stemp.Existuje;
				AnalogDataPB2[i+1].HodnotaX=Stemp.HodnotaX;
				AnalogDataPB2[i+1].HodnotaY=Stemp.HodnotaY;
				swapped = TRUE;
			};
		};
	}while(swapped);
			
			int VelikostOknaX = this->pictureBox4->Width;
			int VelikostOknaY = this->pictureBox4->Height;

			System::Drawing::Pen^ pen = gcnew System::Drawing::Pen(System::Drawing::Color::LightGreen);

			pen->Color = System::Drawing::Color::White;


			// vykreslovani dat
			float Offset = this->pictureBox4->Height*0.5f;
			float KurzorX=0.05f*this->pictureBox4->Width;
			float KurzorY=Offset-AnalogDataPB2[0].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog2);
			for(int i = 0;i<SamplesExist;i++)	
			{
				if(AnalogDataPB2[i].Existuje)
				{
					float NoveX = (AnalogDataPB2[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog2)+0.05f*VelikostOknaX;
					float NoveY=Offset-AnalogDataPB2[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog2);
					grafika->DrawLine(pen,(float)KurzorX,(float)KurzorY,NoveX,NoveY);		// vykresleni spojovacich car
					KurzorX = NoveX;KurzorY=NoveY;		

				};
			};

			// vykreslovani krizku v bodech
			const int VelikostKrizku = 5;
			pen->Color = System::Drawing::Color::Red;
			Offset = this->pictureBox4->Height*0.5f;
			KurzorX=0.05f*this->pictureBox4->Width;
			KurzorY=Offset-AnalogDataPB2[0].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog2);
			for(int i = 0;i<SamplesExist;i++)
			{
			if(AnalogDataPB2[i].Existuje)
				{
					grafika->DrawLine(pen,KurzorX-VelikostKrizku,KurzorY,KurzorX+VelikostKrizku,KurzorY);
					grafika->DrawLine(pen,KurzorX,KurzorY-VelikostKrizku,KurzorX,KurzorY+VelikostKrizku);
					float NoveX = (AnalogDataPB2[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog2)+0.05f*VelikostOknaX;
					float NoveY=Offset-AnalogDataPB2[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog2);
					KurzorX = NoveX;KurzorY=NoveY;

					
				}; 
			/*
				if(vzorkyFinal2[i].Existuje)		// vykreslovani dopocitanych vzorku
				{
					grafika->DrawLine(pen,KurzorX-VelikostKrizku,KurzorY,KurzorX+VelikostKrizku,KurzorY);
					grafika->DrawLine(pen,KurzorX,KurzorY-VelikostKrizku,KurzorX,KurzorY+VelikostKrizku);
					float NoveX = (vzorkyFinal2[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog2)+0.05f*VelikostOknaX;
					float NoveY=Offset-vzorkyFinal2[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog2);
					KurzorX = NoveX;KurzorY=NoveY;

					//vzorkyFinal1[poradiVz].Existuje == true;
				};*/

			};

			// vykresleni vybraneho bodu
			const int VelikostCtverecku = 5;
			if(SelectedSample != -1)
			{
				KurzorX = (AnalogDataPB2[SelectedSample].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog2)+0.05f*VelikostOknaX;
				KurzorY = Offset-AnalogDataPB2[SelectedSample].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog2);
				pen->Color = System::Drawing::Color::White;
				grafika->DrawLine(pen,KurzorX-VelikostCtverecku,KurzorY-VelikostCtverecku,KurzorX+VelikostCtverecku,KurzorY-VelikostCtverecku);
				grafika->DrawLine(pen,KurzorX+VelikostCtverecku,KurzorY-VelikostCtverecku,KurzorX+VelikostCtverecku,KurzorY+VelikostCtverecku);
				grafika->DrawLine(pen,KurzorX-VelikostCtverecku,KurzorY+VelikostCtverecku,KurzorX+VelikostCtverecku,KurzorY+VelikostCtverecku);
				grafika->DrawLine(pen,KurzorX-VelikostCtverecku,KurzorY+VelikostCtverecku,KurzorX-VelikostCtverecku,KurzorY-VelikostCtverecku);
			};

	};
//--------------------------------------------------------------------------------------------------------------------------
//--------------------------------- Button14_Click inicializace grafu analogu -----------------------------------------------
private: System::Void button14_Click(System::Object^  sender, System::EventArgs^  e) {
			float temp;
			
			try			//Nacteni amplitudy
				{temp = Convert::ToSingle(textBox8->Text);}
			catch(FormatException^ e){
				e;
				textBox8->BackColor = Color::LightCoral;
				return;}
			catch(OverflowException^ e){
				e;
				textBox8->BackColor = Color::LightCoral;
				return;}
			if(temp == 0)
				{AmplitudaAnalog2 = 1;}
			else{AmplitudaAnalog2 = temp;}
			textBox8->BackColor = SystemColors::Window;

			try			//Nacteni periody
				{temp = Convert::ToSingle(textBox7->Text);}
			catch(FormatException^ e){
				e;
				textBox7->BackColor = Color::LightCoral;
				return;}
			catch(OverflowException^ e){
				e;
				textBox7->BackColor = Color::LightCoral;
				return;}
			if(temp == 0)
				{PeriodaAnalog2 = 1;}
			else{PeriodaAnalog2 = temp;}
			switch (comboBox4->SelectedIndex)
				{
				case 1: PeriodaAnalog2 = PeriodaAnalog2/1000;
					this->Column2_2->HeaderText = "Čas (ms)";  
				break;
				case 2: PeriodaAnalog2 = PeriodaAnalog2/1000000;
					this->Column2_2->HeaderText = "Čas (us)";					
				break;
				default:
					this->Column2_2->HeaderText = "Čas (s)";
				break;
				}

			textBox7->BackColor = SystemColors::Window;

			// priprava bufferu pro picturebox
			context_pb4 = BufferedGraphicsManager::Current;
			context_pb4->MaximumBuffer = System::Drawing::Size( this->pictureBox4->Width + 1, this->pictureBox4->Height + 1 );
			grafx_pb4 = context_pb4->Allocate( this->pictureBox4->CreateGraphics(), System::Drawing::Rectangle(0,0,this->pictureBox4->Width,this->pictureBox4->Height) );
			grafx_pb4->Graphics->FillRectangle(Brushes::Black , 0, 0, this->pictureBox4->Width, this->pictureBox4->Height);

			
	
			NaslouchamKlikum = TRUE;

			for(int i=0;i<1000;i++)				//nulovani pole bodu
			{
				AnalogDataPB2[i].Existuje=FALSE;
				AnalogDataPB2[i].HodnotaX=0.0f;
				AnalogDataPB2[i].HodnotaY=0.0f;
			};
			AnalogDataPB2[0].Existuje=TRUE;		// nastavi prvni bod Amp=0, t=0
			AnalogDataPB2[0].HodnotaX=0.0f;
			AnalogDataPB2[0].HodnotaY=0.0f;
			AnalogDataPB2[1].Existuje=TRUE;		// nastavi posledni bod do Amp=0, t=per
			AnalogDataPB2[1].HodnotaX=PeriodaAnalog2;
			AnalogDataPB2[1].HodnotaY=0.0f;
		
		NakresliOsy2();
		NakresliData2();
		grafx_pb4->Render();

		while(this->dataGridView2->Rows->Count != 2)
		{
			this->dataGridView2->Rows->RemoveAt(1);
		}
			switch (comboBox4->SelectedIndex)
				{
				case 1: this->dataGridView2[1,1]->Value = PeriodaAnalog2*1000;
				break;
				case 2: this->dataGridView2[1,1]->Value = PeriodaAnalog2*1000000;
				break;
				default:this->dataGridView2[1,1]->Value = PeriodaAnalog2;
				break;
				}
		this->dataGridView2[0,0]->Value = 1;
		this->dataGridView2[1,0]->Value = "0";
		this->dataGridView2[2,0]->Value = "0";
		this->dataGridView2[0,1]->Value = 2;
		this->dataGridView2[2,1]->Value = "0";
		}
//--------------------------------------------------------------------------------------------------------------------------
//--------------------------------- kliknuti do grafu analogu --------------------------------------------------------------
private: System::Void pictureBox4_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			if(!NaslouchamKlikum)
			{
				return; 
			};

			int VelikostOknaX = this->pictureBox4->Width;
			int VelikostOknaY = this->pictureBox4->Height;

			bool UdelejBod=TRUE;
			if(SelectedSample != -1)
			{
				UdelejBod=FALSE;
			};
			
			SelectedSample=-1;
						const int PixelovaRoztecProSelekci=10;
			for(int i=0;i<1000;i++)			// vybere sample kdyz se klikne do jeho okoli
				{
					if(AnalogDataPB2[i].Existuje)
					{
						if(abs(((AnalogDataPB2[i].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog2)+0.05f*VelikostOknaX)-e->X)<PixelovaRoztecProSelekci)
						{
							if(abs(VelikostOknaY*0.5f-AnalogDataPB2[i].HodnotaY*(0.4f*VelikostOknaY/AmplitudaAnalog2)-e->Y)<PixelovaRoztecProSelekci)
							{
								SelectedSample = i;
								UdelejBod=FALSE;
								break;
							};
						};
					};
				};

			if((e->X<0.95f*VelikostOknaX)&&(e->X>0.05f*VelikostOknaX)&&(e->Y>0.1f*VelikostOknaY)&&(e->Y<0.9f*VelikostOknaY)&&(UdelejBod))
			{
				for(int i=0;i<1000;i++)		// pokud neni zadny bod v blizkosti vytvori novy bod
				{
					if(!AnalogDataPB2[i].Existuje)
					{
						AnalogDataPB2[i].Existuje=TRUE;
						AnalogDataPB2[i].HodnotaX=((e->X-0.05f*VelikostOknaX)*PeriodaAnalog2)/(0.9f*(float)VelikostOknaX);	
						AnalogDataPB2[i].HodnotaY=((VelikostOknaY/2.0f)-e->Y)*AmplitudaAnalog2/(0.4f*VelikostOknaY);
						this->dataGridView2->Rows->Add(1);
						break;
					};
				};
			};

			System::Windows::Forms::PaintEventArgs^ nullargs;
			this->pictureBox4_Paint(sender,nullargs);
			int j = 0;
			for(int i=0;i<this->dataGridView2->Rows->Count::get();i++)		// vypis do datagridu
			{
				if(AnalogDataPB2[i].Existuje == true)
				{
					this->dataGridView2[0,j]->Value = j+1;
					double temp = AnalogDataPB2[i].HodnotaX;
					this->Column2->Name = "Čas (s)";
					if( this->comboBox4->SelectedIndex == 1)
					{ temp = temp * 1000;}
					if( this->comboBox4->SelectedIndex == 2)
					{ temp = temp * 1000000;}
					this->dataGridView2[1,j]->Value = Math::Round(temp,2);
					temp = AnalogDataPB2[i].HodnotaY;
					this->dataGridView2[2,j]->Value = Math::Round(temp,2);
					j++;
				};
			};
		 }

//-------------------------------------------------------------------------------------------------------------------------
//------------------------ MouseDown v grafu analogu ----------------------------------------------------------------------
private: System::Void pictureBox4_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 if(SelectedSample!=-1)
			 {
				 IsDragging = TRUE;				//zapoceti dragu
			 };
		 }
//--------------------------------------------------------------------------------------------------------------------------
//------------------------ MouseMove v grafu analogu -----------------------------------------------------------------------

private: System::Void pictureBox4_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			if(IsDragging)
			 {
						int VelikostOknaX = this->pictureBox4->Width;
						int VelikostOknaY = this->pictureBox4->Height;

						// vyhledaji se sousedni body, aby nesly prez sebe
						float MinX=0.0f;float MaxX=(float)VelikostOknaY;
						if(SelectedSample>0)
						{
							MinX = (AnalogDataPB2[SelectedSample-1].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog2)+0.05f*VelikostOknaX;
						};
						if(SelectedSample < 999) 
						{
							MaxX = (AnalogDataPB2[SelectedSample+1].HodnotaX*VelikostOknaX*0.9f/PeriodaAnalog2)+0.05f*VelikostOknaX;
						};
						// zmeni se data vybraneho bodu a zavola vykresleni
						if((e->X<0.95f*VelikostOknaX)&&(e->X>0.05f*VelikostOknaX)&&(e->Y>0.1f*VelikostOknaY)&&(e->Y<0.9f*VelikostOknaY)&&(e->X<MaxX)&&(e->X>MinX))
						{
				 			AnalogDataPB2[SelectedSample].HodnotaX=((e->X-0.05f*VelikostOknaX)*PeriodaAnalog2)/(0.9f*(float)VelikostOknaX);	
							AnalogDataPB2[SelectedSample].HodnotaY=( (VelikostOknaY/2.0f)-e->Y)*AmplitudaAnalog2/(0.4f*VelikostOknaY);
						};

				System::Windows::Forms::PaintEventArgs^ nullargs;
				this->pictureBox4_Paint(sender,nullargs);
			 };
		 }
//--------------------------------------------------------------------------------------------------------------------------
//------------------------ MouseUp v grafu analogu -------------------------------------------------------------------------
private: System::Void pictureBox4_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 IsDragging = FALSE;										// ukonceni dragu
		 }
//--------------------------------------------------------------------------------------------------------------------------

//------------------------ Stisknuti tlacitka ------------------------------------------------------------------------------
private: System::Void Form1_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			 if((e->KeyCode==Keys::Escape )&&(NaslouchamKlikum))		// Esc - odznaceni bodu
			 {
				SelectedSample=-1;
				System::Windows::Forms::PaintEventArgs^ nullargs;
				this->pictureBox2_Paint(sender,nullargs);
				this->pictureBox4_Paint(sender,nullargs);
			 }; 
			 if((e->KeyCode==Keys::Delete )&&(NaslouchamKlikum)&&(SelectedSample!=-1))		// delete - vymazani bodu
			 {
				AnalogDataPB1[SelectedSample].Existuje=FALSE;
				
				SelectedSample=-1;
				System::Windows::Forms::PaintEventArgs^ nullargs;
				this->pictureBox2_Paint(sender,nullargs);
				

			int j=0;
			this->dataGridView1->Rows->RemoveAt(1);
			for(int i=0;i<1000;i++)										// vypis do datagridu
			{
				if(AnalogDataPB1[i].Existuje == true)
				{	
					this->dataGridView1[0,j]->Value = j+1;
					this->dataGridView1[1,j]->Value = AnalogDataPB1[i].HodnotaX;
					this->dataGridView1[2,j]->Value = AnalogDataPB1[i].HodnotaY;
					j++;
				};
			};
			


			 };
		 }
//--------------------------------------------------------------------------------------------------------------------------
//========================= Funkce vykreslovani grafů=======================================================================
private: System::Void pictureBox3_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
			grafx_pb3->Graphics->FillRectangle(Brushes::Black , 0, 0, this->pictureBox3->Width, this->pictureBox3->Height);
			NakresliOsyDigital();
			NakresliDataDigital();
			grafx_pb3->Render();
		 }
private: System::Void pictureBox2_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
			grafx_pb2->Graphics->FillRectangle(Brushes::Black , 0, 0, this->pictureBox2->Width, this->pictureBox2->Height);
			NakresliOsy();
			NakresliData();
			grafx_pb2->Render();
		 }
private: System::Void pictureBox4_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
			grafx_pb4->Graphics->FillRectangle(Brushes::Black , 0, 0, this->pictureBox4->Width, this->pictureBox4->Height);
			NakresliOsy2();
			NakresliData2();
			grafx_pb4->Render();
		 }
private: System::Void timer2_Tick(System::Object^  sender, System::EventArgs^  e) {
			System::Windows::Forms::PaintEventArgs^ nullargs;
			if(this->tabControl1->SelectedIndex::get() == 0)
			{
				this->pictureBox2_Paint(sender,nullargs);
			}
			else
			{
				this->pictureBox3_Paint(sender,nullargs);
			}
			this->timer2->Enabled::set(false);
		 }
//==========================================================================================================================

//==========================================================================================================================
//							Generovani atp.
//==========================================================================================================================

// ----------------------- Start generovani ---------------------------- 
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			
			if(this->checkBox1->Checked == true)			// pocitani vzorku analog 1
			{
				SpoctiVzorky1();
				if(this->checkBox2->Checked == false)
				{
					PocatecniAdresaAnalog2 = KonecnaAdresaAnalog1 + 2, 
					KonecnaAdresaAnalog2 =  PocatecniAdresaAnalog2;
					if(this->checkBox3->Checked == false)
					{
						PocatecniAdresaDigital = KonecnaAdresaAnalog2 + 2, 
						KonecnaAdresaDigital =  PocatecniAdresaDigital;
					}
				}
				
			}
		
			if(this->checkBox2->Checked == true)			// pocitani vzorku analog 2
			{
				if(this->checkBox1->Checked == false)
				{
					PocatecniAdresaAnalog1 = 0;
					KonecnaAdresaAnalog2 =  0;
				}
				SpoctiVzorky2();
				if(this->checkBox3->Checked == false)
				{
					PocatecniAdresaDigital = KonecnaAdresaAnalog2 +2, 
					KonecnaAdresaDigital =  PocatecniAdresaDigital;
				}
			}
		
			if(this->checkBox3->Checked == true)			// pocitani vzorku Digital
			{
				
				if(this->checkBox1->Checked == false)
				{
					PocatecniAdresaAnalog2 = 0;
					KonecnaAdresaAnalog2 =  0;
				}
				if(this->checkBox2->Checked == false)
				{
					PocatecniAdresaDigital = 0;
					KonecnaAdresaDigital =  0;
				}
				SpoctiVzorky3();
			}

			NahrajPamet();										// kopirovani vzorku do pameti
			StartStopAddressSetting(PocatecniAdresaAnalog1,		// nastaveni pocatecnich a koncovych adres pro generovani
									KonecnaAdresaAnalog1, 
									PocatecniAdresaAnalog2, 
									KonecnaAdresaAnalog2, 
									PocatecniAdresaDigital, 
									KonecnaAdresaDigital);

			if(this->checkBox1->Checked == true) 
			{Report01_control(0x01,true);}						// pripoji AOUT1
			if(this->checkBox2->Checked == true) 
			{Report01_control(0x02,true);}						// pripoji AOUT2
			if(this->checkBox3->Checked == true)	
			{
				Report01_control(0x03,false);					// pripoji DOUT 0-7
				Report01_control(0x04,false);					// pripoji DOUT 8-15
			}
			this->button3->Text = "Odpoj Analog 1";
			this->toolStripStatusLabel4->Text = "Připojen";
			this->button3->Enabled = true;
			this->button4->Text = "Odpoj Analog 2";
			this->toolStripStatusLabel6->Text = "Připojen";
			this->button4->Enabled = true;
			this->button5->Text = "Odpoj Digital";
			this->toolStripStatusLabel8->Text = "Připojen";
			this->button5->Enabled = true;
			this->button9->Enabled = true;
			
			TimerSetting(72,4);									// nastaveni periody timeru
			Report01_control(0x08,true);						// timer start
		
		
		};
// ------------------------ fullstop generovani --------------------------------------------------
private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) {
			Report01_control(0x01,false);			// odpoji AOUT1
			Report01_control(0x02,false);			// odpoji AOUT2
			Report01_control(0x03,false);			// odpoji DOUT 0-7
			Report01_control(0x04,false);			// odpoji DOUT 8-15
			Report01_control(0x08,false);			// timer stop
			this->button3->Text = "Připoj Analog 1";
			this->toolStripStatusLabel4->Text = "Odpojen";
			this->button3->Enabled = false;
			this->button4->Text = "Připoj Analog 2";
			this->toolStripStatusLabel6->Text = "Odpojen";
			this->button4->Enabled = false;
			this->button5->Text = "Připoj Digital";
			this->toolStripStatusLabel8->Text = "Odpojen";
			this->button5->Enabled = false;
			
		 }
// ------------------------ Odpojeni vystupu --------------------------------------------------
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(this->button3->Text == "Odpoj Analog 1")
			 {
				 this->button3->Text = "Připoj Analog 1";
				 this->toolStripStatusLabel4->Text = "Odpojen";
				 Report01_control(0x01,false);
			 }
			 else
			 {
				 this->button3->Text = "Odpoj Analog 1";
				 this->toolStripStatusLabel4->Text = "Připojen";
				 Report01_control(0x01,true);
			 }
		}
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(this->button4->Text == "Odpoj Analog 2")
			 {
				 this->button4->Text = "Připoj Analog 2";
				 this->toolStripStatusLabel6->Text = "Odpojen";
				 Report01_control(0x02,false);
			 }
			 else
			 {
				 this->button4->Text = "Odpoj Analog 2";
				 this->toolStripStatusLabel6->Text = "Připojen";
				 Report01_control(0x02,true);
			 }
		 }

private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(this->button5->Text == "Odpoj Digital")
			 {
				 this->button5->Text = "Připoj Digital";
				 this->toolStripStatusLabel8->Text = "Odpojen";
				 Report01_control(0x03,true);
				 Report01_control(0x04,true);
			 }
			 else
			 {
				 this->button5->Text = "Odpoj Digital";
				 this->toolStripStatusLabel8->Text = "Připojen";
				 Report01_control(0x03,false);
				 Report01_control(0x04,false);
			 }
		}
//--------------------------- odpojeni zarizeni ----------------------------------------------------
private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) {
			Report01_control(0x09,false);
		 }

private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
			 unsigned short TimerPeriode;
			 unsigned short TimerPrescaler;
			 TimerPeriode = System::Convert::ToUInt16(this->textBox9->Text);
			 TimerPrescaler =  System::Convert::ToUInt16(this->textBox1->Text);
			 TimerSetting(TimerPeriode,TimerPrescaler);
		 }

//--------------------------- zmena tabu -----------------------------------------------------------------------------------
private: System::Void tabControl1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 this->timer2->Enabled::set(true);
		 }
//--------------------------------------------------------------------------------------------------------------------------

private: System::Void button10_Click(System::Object^  sender, System::EventArgs^  e) {

		 unsigned short DataToSend[29];
		 unsigned long StartingAddress;
		 StartingAddress = System::Convert::ToUInt32(this->textBox1->Text);
		 for(int i = 0;i < 29; i++)
		 { 
			 DataToSend[i] = i;
		 }

		 WriteToMemory(StartingAddress,&DataToSend[0],29);

		 StartStopAddressSetting(100000,120000,140000,160000,180000,200000);

		 }
//==========================================================================================================================
//							Vypocty vzorku
//==========================================================================================================================

//--------------------------------- Vypoctet Vzorku ------------------------------------------------------------------------
private: System::Void SpoctiVzorky1()
{	
	PoctyVzorku1 = (int)(VzorkovaciFrekvence*PeriodaAnalog1);	// urci pocet Vzorku 
	float CasVzorku; 
	CasVzorku = 1.0f/VzorkovaciFrekvence;						// urci periodu vzorku
	int i = 0; 
	int PocetVzorkuNaPeriodu;									// pocet vzorku v datech z PB
	SAMPLE vzorkyProGen1[1000];									// 

	while( AnalogDataPB1[i].Existuje == true )					// urci pocet podu v PB		
	{
		i++;
		PocetVzorkuNaPeriodu = i ;
	}
		vzorkyProGen1[0].HodnotaX = 0;							// 1. vzorek = 0;
		vzorkyProGen1[0].HodnotaY = 0;
	
	for(int j = 0; j < PocetVzorkuNaPeriodu; j++)				// posune vzorky do nasobku vzorkovaci periody	
	{
		i = 0;
		while( (AnalogDataPB1[j].HodnotaX - i*CasVzorku) > CasVzorku)
		{
			vzorkyProGen1[j].HodnotaX = i*CasVzorku;
			vzorkyProGen1[j].HodnotaY = AnalogDataPB1[j].HodnotaY;
			i++;
		}
	}

	int poradiVz = 0;
	vzorkyFinal1[poradiVz].HodnotaX = 0;
	vzorkyFinal1[poradiVz].HodnotaY = 0;
	vzorkyFinal1[poradiVz].Existuje = true;

	for(int j = 0; j <= PocetVzorkuNaPeriodu +1 ; j++)			// vypocita vzorky mezi body grafu z PB
	{
		float linX1 = vzorkyFinal1[poradiVz].HodnotaX;						// Xa
		float linX2 = vzorkyProGen1[j+1].HodnotaX;							// Xb
		float linY1 = vzorkyProGen1[j].HodnotaY;							// Ya
		float linY2 = vzorkyProGen1[j+1].HodnotaY;							// Yb
		float linB = linY1;													// b = Y0 - prusecik s nulou
		float linA = (linY2 - linB)/(linX2 - linX1 + CasVzorku );			// a smernice linearni fce
		

		int pocetVzMeziAB = (int)(Math::Ceiling((linX2 - linX1)/CasVzorku));

		for(int k = 0; k <= pocetVzMeziAB; k++)
		{		
			poradiVz++;
			// cas vzorku = Cas minuleho vzorku  + perioda vzorku = X = X + CasVzorku
			vzorkyFinal1[poradiVz].HodnotaX = vzorkyFinal1[poradiVz-1].HodnotaX + CasVzorku;	
			// hodnota vzorku Y = AX + B
			vzorkyFinal1[poradiVz].HodnotaY = ( linA * (vzorkyFinal1[poradiVz].HodnotaX - linX1) ) + linB ;
			vzorkyFinal1[poradiVz].Existuje = true;
		}
	}

	vzorkyFinal1[poradiVz+1].HodnotaY = 0;
	vzorkyFinal1[poradiVz+1].Existuje = false;						// ukoncovaci vzorek

	i = 0;
	while( vzorkyFinal1[i].Existuje == true)
	{
		VzorkyDoPameti1[i] = (unsigned short)(vzorkyFinal1[i].HodnotaY/0.005 + 2048);
		i++;
	}
	PocatecniAdresaAnalog1 = 0;
	KonecnaAdresaAnalog1 = i ;	

}
//--------------------------------------------------------------
private: System::Void SpoctiVzorky2( )
{	
	PoctyVzorku2 = (int)(VzorkovaciFrekvence*PeriodaAnalog2);
	float CasVzorku = 1.0f/VzorkovaciFrekvence;		// urci periodu vzorku
	int i = 0; 
	int PocetVzorkuNaPeriodu;						// nacte pocet vzorku v datungu
	SAMPLE vzorkyProGen2[1000];						// 
  
	while( AnalogDataPB2[i].Existuje == true )		// urci pocet podu v PB		
	{
		i++;
		PocetVzorkuNaPeriodu = i ;
	}
		vzorkyProGen2[0].HodnotaX = 0;				// 1. vzorek = 0;
		vzorkyProGen2[0].HodnotaY = 0;
	
	for(int j = 0; j < PocetVzorkuNaPeriodu; j++)	// posune vzorky do nasobku vzorkovaci periody	
	{
		i = 0;
		while( (AnalogDataPB2[j].HodnotaX - i*CasVzorku) > CasVzorku)
		{
			vzorkyProGen2[j].HodnotaX = i*CasVzorku;
			vzorkyProGen2[j].HodnotaY = AnalogDataPB2[j].HodnotaY;
			i++;
		}
	}

	int poradiVz = 0;
	vzorkyFinal2[poradiVz].HodnotaX = 0;
	vzorkyFinal2[poradiVz].HodnotaY = 0;
	vzorkyFinal2[poradiVz].Existuje = true;

	for(int j = 0; j <= PocetVzorkuNaPeriodu +1 ; j++)			// vypocita vzorky mezi body grafu z PB
	{
		float linX1 = vzorkyFinal2[poradiVz].HodnotaX;						// Xa
		float linX2 = vzorkyProGen2[j+1].HodnotaX;							// Xb
		float linY1 = vzorkyProGen2[j].HodnotaY;							// Ya
		float linY2 = vzorkyProGen2[j+1].HodnotaY;							// Yb
		float linB = linY1;													// b = Y0 - prusecik s nulou
		float linA = (linY2 - linB)/(linX2 - linX1 + CasVzorku );			// a smernice linearni fce
		

		int pocetVzMeziAB = (int)(Math::Ceiling((linX2 - linX1)/CasVzorku));

		for(int k = 0; k <= pocetVzMeziAB; k++)
		{		
			poradiVz++;
			// cas vzorku = Cas minuleho vzorku  + perioda vzorku = X = X + CasVzorku
			vzorkyFinal2[poradiVz].HodnotaX = vzorkyFinal2[poradiVz-1].HodnotaX + CasVzorku;	
			// hodnota vzorku Y = AX + B
			vzorkyFinal2[poradiVz].HodnotaY = ( linA * (vzorkyFinal2[poradiVz].HodnotaX - linX1) ) + linB ;
			vzorkyFinal2[poradiVz].Existuje = true;
		}
	}
		vzorkyFinal2[poradiVz+1].Existuje = false;						// ukoncovaci vzorek
int temp;
int temp2;
		i = 0;
			while( vzorkyFinal2[i].Existuje == true)
			{
				VzorkyDoPameti2[i] = (unsigned short)(vzorkyFinal2[i].HodnotaY/0.005 + 2048);
				temp = VzorkyDoPameti2[i];
				temp2 = vzorkyFinal2[i].HodnotaY;
				i++;
			}
			PocatecniAdresaAnalog2 = KonecnaAdresaAnalog1 + 1;
			KonecnaAdresaAnalog2 = PocatecniAdresaAnalog2 + i;	

}
private: System::Void SpoctiVzorky3( )
{
	unsigned short temp = 0;
	for(int i = 0; i<80000 ;i++)					//vynulovat
	{
		VzorkyDoPameti3[i] = 0;
	}

	int poradiVzorku = 0;
	for(int i = 0 ; i < PocetDigitalnichVzorku ; i++)
		{
			for(int k = 0; k <= (int)(DobaDigitalnihoVzorku * VzorkovaciFrekvence); k++)
			{
				temp = 0;
				for(int j = 15; j >=0 ; j--)
					{
						if(*(DigSample[j] + i ) == true)
						{
							temp |= 0x01;
						}
						if (j != 0)
						{
							temp = (temp << 1);
						}
						 
					}
			VzorkyDoPameti3[poradiVzorku] = temp;
			poradiVzorku++;
			}
		}


	
	PocatecniAdresaDigital = KonecnaAdresaAnalog2 + 1;
	KonecnaAdresaDigital = PocatecniAdresaDigital + PocetDigitalnichVzorku*(DobaDigitalnihoVzorku * VzorkovaciFrekvence);

}
private: System::Void NahrajPamet( )
{

	
	PocatecniAdresaAnalog1 = PocatecniAdresaAnalog1*2;		// prizpusobeni adres na adresy pameti
	KonecnaAdresaAnalog1 = KonecnaAdresaAnalog1*2;

	PocatecniAdresaAnalog2 = PocatecniAdresaAnalog2*2;
	KonecnaAdresaAnalog2 = KonecnaAdresaAnalog2*2;

	PocatecniAdresaDigital = PocatecniAdresaDigital*2;		
	KonecnaAdresaDigital = KonecnaAdresaDigital*2;

	unsigned short memData[60];
	unsigned int memAdresa = 0;
	
	if(this->checkBox1->Checked == true)					//nahrani vzorku analog1
	{
		memAdresa = PocatecniAdresaAnalog1;
		while( memAdresa <= KonecnaAdresaAnalog1)
		{		
			
			for(int i=0; i < 29; i++)
			{
				memData[i] = VzorkyDoPameti1[i + memAdresa/2];
			}
			WriteToMemory(memAdresa , memData , 29);
			memAdresa = memAdresa + 58;
		}
	}
	unsigned char temp;
	if(this->checkBox2->Checked == true)					//nahrani vzorku analog2
	{
		memAdresa = PocatecniAdresaAnalog2;
		while( memAdresa <= KonecnaAdresaAnalog2)
		{		
			
			for(int i=0; i < 29; i++)
			{
				memData[i] = VzorkyDoPameti2[i+ memAdresa/2 - PocatecniAdresaAnalog2/2];
				temp = memData[i];
			}
			WriteToMemory(memAdresa , memData , 29);
			memAdresa = memAdresa + 58;
		}
	}
	if(this->checkBox3->Checked == true)					//nahrani vzorku digital
	{
		int poradiVzorku = 0;
		memAdresa = PocatecniAdresaDigital;
		while( memAdresa < KonecnaAdresaDigital)
		{		
			
			for(int i=0; i < 29; i++)
			{
				memData[i] = VzorkyDoPameti3[poradiVzorku];
				int Result = memData[i];
				poradiVzorku++;
			}
			WriteToMemory(memAdresa , memData , 29);
			memAdresa = memAdresa + 58;
		}
	}



}

//==========================================================================================================================
//							Testovani
//==========================================================================================================================
// obdelník
private: System::Void button15_Click(System::Object^  sender, System::EventArgs^  e) {

			 unsigned short memData [10];
			 unsigned int memAdresa = 0;
			 for(int i = 0; i<5; i++)
			 {
				 memData[i] = 0;
				 memData[i+5] = 4095;
			 }

			 WriteToMemory(memAdresa , memData , 29);
			 StartStopAddressSetting(0,	20, 0, 18, 22, 22);
			 Report01_control(0x01,true);
			 Report01_control(0x02,true);
			 Report01_control(0x08,true);
		 }
private: System::Void button16_Click(System::Object^  sender, System::EventArgs^  e) {
			 
			 unsigned short memData [20];
			 unsigned int memAdresa = 0;
				 memData[0] = 0;
				 memData[1] = 4095;
				 for(int i = 2; i<20; i++)
				 {
					memData[i] = 0;
				 }

			 WriteToMemory(memAdresa , memData , 29);
			 StartStopAddressSetting(0,	40, 0, 40, 42, 42);
			 Report01_control(0x01,true);
			 Report01_control(0x02,true);
			 Report01_control(0x08,true);

		 }
private: System::Void button17_Click(System::Object^  sender, System::EventArgs^  e) {
			int amp = 10;
			int freq = 10000;

			try			//Nacte dobu digitalniho vzorku
			{freq = Convert::ToDouble(textBox10->Text);}
			catch(FormatException^ e){
				e;
				textBox10->BackColor = Color::LightCoral;
			return;}
			catch(OverflowException^ e){
				e;
				textBox10->BackColor = Color::LightCoral;
			return;}
			textBox4->BackColor = SystemColors::Window;
			
			try			//Nacte dobu digitalniho vzorku
			{amp = Convert::ToDouble(textBox11->Text);}
			catch(FormatException^ e){
				e;
				textBox11->BackColor = Color::LightCoral;
			return;}
			catch(OverflowException^ e){
				e;
				textBox11->BackColor = Color::LightCoral;
			return;}
			textBox4->BackColor = SystemColors::Window;
		
		unsigned int pocVz = VzorkovaciFrekvence/freq;
		unsigned int temp = 0;
		float temp2;
		unsigned int memAdresa = 0;
		unsigned short memData[60];
		for(int i = 0; i<pocVz;i++)
		{
			temp2 = amp*Math::Sin(2*3.141528*freq*i*0.000001);
			VzorkyDoPameti1[i] = (unsigned short)(temp2/0.005 + 2048);

		}

		while( memAdresa <= pocVz*2)
		{		
			
			for(int i=0; i < 29; i++)
			{
				memData[i] = VzorkyDoPameti1[i + memAdresa/2];
			}
			WriteToMemory(memAdresa , memData , 29);
			memAdresa = memAdresa + 58;
		}
		pocVz = pocVz*2;
		StartStopAddressSetting(0,		// nastaveni pocatecnich a koncovych adres pro generovani
									pocVz, 
									pocVz,
									pocVz,
									pocVz,
									pocVz);
		
		Report01_control(0x01,true);	
		Report01_control(0x08,true);						// timer start


		 }
};
};