Advertisement
Tevronis

MyForm.h

Oct 1st, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.64 KB | None | 0 0
  1. MyForm.h
  2.  
  3. #pragma once
  4.  
  5. ; namespace ProjectForm {
  6.  
  7.     using namespace System;
  8.     using namespace System::ComponentModel;
  9.     using namespace System::Collections;
  10.     using namespace System::Windows::Forms;
  11.     using namespace System::Data;
  12.     using namespace System::Drawing;
  13.  
  14.     /// <summary>
  15.     /// Summary for MyForm
  16.     /// </summary>
  17.     public ref class MyForm : public System::Windows::Forms::Form
  18.     {
  19.     public:
  20.         MyForm(void)
  21.         {
  22.             InitializeComponent();
  23.             //
  24.             //TODO: Add the constructor code here
  25.             //
  26.         }
  27.  
  28.     protected:
  29.         /// <summary>
  30.         /// Clean up any resources being used.
  31.         /// </summary>
  32.         ~MyForm()
  33.         {
  34.             if (components)
  35.             {
  36.                 delete components;
  37.             }
  38.         }
  39.     private:
  40.         System::Collections::Generic::List<line> lines;
  41.         float left, right, top, bottom;
  42.         float Wcx, Wcy, Wx, Wy;
  43.         float Vcx, Vcy, Vx, Vy;
  44.         float oldWx, oldWy;
  45.  
  46.     private: System::Windows::Forms::OpenFileDialog^  openFileDialog;
  47.  
  48.     private: System::Windows::Forms::Button^  btnOpen;
  49.     private:
  50.         /// <summary>
  51.         /// Required designer variable.
  52.         /// </summary>
  53.         System::ComponentModel::Container ^components;
  54.  
  55. #pragma region Windows Form Designer generated code
  56.         /// <summary>
  57.         /// Required method for Designer support - do not modify
  58.         /// the contents of this method with the code editor.
  59.         /// </summary>
  60.         void InitializeComponent(void)
  61.         {
  62.             this->openFileDialog = (gcnew System::Windows::Forms::OpenFileDialog());
  63.             this->btnOpen = (gcnew System::Windows::Forms::Button());
  64.             this->SuspendLayout();
  65.             //
  66.             // openFileDialog
  67.             //
  68.             this->openFileDialog->DefaultExt = L"txt";
  69.             this->openFileDialog->FileName = L"openFileDialog";
  70.             this->openFileDialog->Filter = L"Текстовые файлы (*.txt)|*.txt|Все файлы (*.*)|*.*";
  71.             this->openFileDialog->Title = L"Открыть файл";
  72.             this->openFileDialog->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &MyForm::openFileDialog_FileOk);
  73.             //
  74.             // btnOpen
  75.             //
  76.             this->btnOpen->Location = System::Drawing::Point(15,15);
  77.             this->btnOpen->Name = L"btnOpen";
  78.             this->btnOpen->Size = System::Drawing::Size(100, 100);
  79.             this->btnOpen->TabIndex = 0;
  80.             this->btnOpen->Text = L"Открыть";
  81.             this->btnOpen->UseVisualStyleBackColor = true;
  82.             this->btnOpen->Click += gcnew System::EventHandler(this, &MyForm::btnOpen_Click_1);
  83.             //
  84.             // MyForm
  85.             //
  86.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  87.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  88.             this->ClientSize = System::Drawing::Size(597, 553);
  89.             this->Controls->Add(this->btnOpen);
  90.             this->KeyPreview = true;
  91.             this->Name = L"MyForm";
  92.             this->Text = L"MyForm";
  93.             this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
  94.             this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
  95.             this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MyForm::MyForm_KeyDown);
  96.             this->Resize += gcnew System::EventHandler(this, &MyForm::MyForm_Resize);
  97.             this->ResumeLayout(false);
  98.  
  99.         }
  100. #pragma endregion
  101.     private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
  102.                  lines.Clear();
  103.                  unit(T);
  104.                  Wcx = left;
  105.                  Wcy = Form::ClientRectangle.Height - bottom;
  106.                  Wx = Form::ClientRectangle.Width - left - right;
  107.                  Wy = Form::ClientRectangle.Height - top - bottom;
  108.     }
  109.     private: System::Void MyForm_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e)
  110.     {
  111.                  Graphics^ g = e->Graphics;
  112.                  g->Clear(Color::LightGreen);
  113.                  Rectangle rect = Form::ClientRectangle;
  114.  
  115.                  
  116.  
  117.                  Pen^ blackPen = gcnew Pen(Color::Blue);
  118.                  blackPen->Width = 4;
  119.  
  120.                  for (int i = 0; i < lines.Count; i++)
  121.                  {
  122.                     vec A, B;
  123.                     point2vec(lines[i].start, A);
  124.                     point2vec(lines[i].end, B);
  125.                    
  126.                     vec A1, B1;
  127.                     timesMatVec(T, A, A1);
  128.                     timesMatVec(T, B, B1);
  129.  
  130.                     point a, b;
  131.                     vec2point(A1, a);
  132.                     vec2point(B1, b);
  133.                     g->DrawLine(blackPen, a.x,a.y, b.x,b.y);
  134.                  }
  135.                  Pen^ rectPen = gcnew Pen(Color::Yellow);
  136.                  rectPen->Width = 15;
  137.                  g->DrawRectangle(rectPen, Wcx, top, Wx, Wy);
  138.                  
  139.     }
  140.     private: System::Void openFileDialog_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e)
  141.     {
  142.  
  143.     }
  144.    
  145. private: System::Void btnOpen_Click_1(System::Object^  sender, System::EventArgs^  e)
  146. {
  147.              if (this->openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
  148.              {
  149.                  wchar_t fileName[1024];
  150.                  for (int i = 0; i < openFileDialog->FileName->Length; i++)
  151.                      fileName[i] = openFileDialog->FileName[i];
  152.                  fileName[openFileDialog->FileName->Length] = '\0';
  153.                  std::ifstream in;
  154.                  in.open(fileName);
  155.                  if (in.is_open())
  156.                  {
  157.                      lines.Clear();
  158.                      unit(T);
  159.                      std::string str;
  160.                      mat R, T1;
  161.                      getline(in, str);
  162.                      std::stringstream s(str);
  163.                      line l;
  164.                      s >> l.start.x >> l.start.y >> l.end.x >> l.end.y;
  165.                      Vcx = l.start.x;
  166.                      Vcy = l.start.y;
  167.                      Vx = l.end.x;
  168.                      Vy = l.end.y;
  169.                      getline(in, str);
  170.                      while (in)
  171.                      {
  172.                          if ((str.find_first_not_of(" \t\r\n") != std::string::npos) && (str[0] != '#'))
  173.                          {
  174.                              std::stringstream s(str);
  175.                              line l;
  176.                              s >> l.start.x >> l.start.y >> l.end.x >> l.end.y;
  177.                              std::string linename;
  178.                              s >> linename;
  179.                              l.name = gcnew String(linename.c_str());
  180.                              lines.Add(l);
  181.                          }
  182.                          getline(in, str);
  183.                      }
  184.                     //mirror2(this->ClientRectangle.Height, R);
  185.                     frame(Vx, Vy, Vcx, Vcy, Wx, Wy, Wcx, Wcy, R);
  186.                     times(R, T, T1);
  187.                     set(T1, T);
  188.                     this->Refresh();
  189.                  }
  190.                  this->Refresh();
  191.              }
  192. }
  193. private: System::Void MyForm_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
  194.             mat R, T1;
  195.             switch (e->KeyCode)
  196.             {
  197.                 case Keys::W:move(0,    -1, R); break;
  198.                 case Keys::S:move(0,    1,  R); break;
  199.                 case Keys::A:move(-1,   0,  R); break;
  200.                 case Keys::D:move(1,    0,  R); break;
  201.  
  202.                 case Keys::G:move(0,    10,R); break;
  203.                 case Keys::T:move(0,    -10,    R); break;
  204.                 case Keys::F:move(-100,  R); break;
  205.                 case Keys::H:move(10,   0,  R); break;
  206.  
  207.                 case Keys::E:rotate(0.05,   R); break;
  208.                 case Keys::Q:rotate(-0.05,  R); break;
  209.  
  210.                 case Keys::X:scale(1 / 1.1, R); break;
  211.                 case Keys::Z:scale(1 / 0.9, R); break;
  212.  
  213.                 case Keys::R:rotate_2(this->ClientRectangle.Width, this->ClientRectangle.Height, -0.05, R); break;
  214.                 case Keys::Y:rotate_2(this->ClientRectangle.Width, this->ClientRectangle.Height, 0.05, R); break;
  215.  
  216.                 case Keys::U:mirror1(this->ClientRectangle.Width,   R); break;
  217.                 case Keys::J:mirror2(this->ClientRectangle.Height,  R); break;
  218.  
  219.                 case Keys::C:scale_2(1.1,       this->ClientRectangle.Height / 2, this->ClientRectangle.Width / 2, R); break;
  220.                 case Keys::V:scale_2(1 / 1.1,   this->ClientRectangle.Height / 2, this->ClientRectangle.Width / 2, R); break;
  221.  
  222.                 case Keys::Escape:unit(R); unit(T); unit(T1); frame(Vx, Vy, Vcx, Vcy, Wx, Wy, Wcx, Wcy, T); break;
  223.  
  224.                 case Keys::I :sdvig_g(1/1.1,this->ClientRectangle.Width /2,R);break;
  225.                 case Keys::O :sdvig_g(1*1.1,this->ClientRectangle.Width /2,R);break;
  226.                 case Keys::K :sdvig_v(1/1.1,this->ClientRectangle.Height/2,R);break;
  227.                 case Keys::L :sdvig_v(1*1.1,this->ClientRectangle.Height/2,R);break;
  228.  
  229.                 default:unit(R);
  230.             }
  231.             times(R, T, T1);
  232.             set(T1, T);
  233.             this->Refresh();
  234. }
  235. private: System::Void MyForm_Resize(System::Object^  sender, System::EventArgs^  e)
  236.          {
  237.              this->Refresh();
  238.              oldWx = Wx, oldWy = Wy;
  239.              Wcx = left;
  240.              Wcy = Form::ClientRectangle.Height - bottom;
  241.              Wx = Form::ClientRectangle.Width - left - right;
  242.              Wy = Form::ClientRectangle.Height - top - bottom;
  243.          }
  244. };
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement