Advertisement
Tevronis

123

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