Advertisement
deced

Untitled

May 25th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. unit OutputGraph;
  2.  
  3. interface
  4.  
  5. uses
  6. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, MatrixInt, Vcl.StdCtrls, LinkList,
  8. Vcl.Menus;
  9.  
  10. type
  11. TIntMatrix = TMatrixInt;
  12. TIntArr = TArrInt;
  13. TFormOutputGraph = class(TForm)
  14. Label1: TLabel;
  15. Label2: TLabel;
  16. Label3: TLabel;
  17. ImageGraph: TImage;
  18. MainMenu1: TMainMenu;
  19. N1: TMenuItem;
  20. SaveDialog1: TSaveDialog;
  21. ButtonResult: TButton;
  22. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  23. procedure N1Click(Sender: TObject);
  24. procedure ButtonResultClick(Sender: TObject);
  25. private
  26. var
  27. ArrLabel: Array of TLabel;
  28. public
  29. procedure PrintGraph(AdjMat: TIntMatrix; ArrCycle: TIntArr);
  30. procedure FillLabelCyrcle(List: TLinkList<String>);
  31. end;
  32.  
  33. var
  34. FormOutputGraph: TFormOutputGraph;
  35.  
  36. implementation
  37.  
  38. {$R *.dfm}
  39.  
  40. uses Unit2, Graph;
  41.  
  42.  
  43. procedure TFormOutputGraph.FormCloseQuery(Sender: TObject;
  44. var CanClose: Boolean);
  45. var
  46. I: Integer;
  47. NewImage: TImage;
  48. begin
  49. for I := 0 to High(ArrLabel) do
  50. ArrLabel[I].DisposeOf;
  51. ImageGraph.DisposeOf;
  52. NewImage := TImage.Create(FormOutputGraph);
  53. NewImage.Parent := FormOutputGraph;
  54. NewImage.Name := 'ImageGraph';
  55. NewImage.Left := 50;
  56. NewImage.Top := 120;
  57. NewImage.Height := 450;
  58. NewImage.Width := 540;
  59. end;
  60.  
  61. procedure TFormOutputGraph.N1Click(Sender: TObject);
  62. var
  63. IsCorrect : Boolean;
  64. begin
  65. repeat
  66. IsCorrect := True;
  67. if SaveDialog1.Execute then
  68. begin
  69. IsCorrect := MainForm.CheckFileExtension(SaveDialog1.FileName);
  70. if IsCorrect then
  71. begin
  72. MainForm.OutputFile(SaveDialog1.FileName);
  73. ShowMessage('Результат успешно сохранён');
  74. end;
  75. end;
  76. until IsCorrect;
  77. end;
  78.  
  79. procedure FillCoord(AdjMat: TIntMatrix; var X, Y: TIntArr);
  80. var
  81. I: Integer;
  82. begin
  83. for I := 0 to High(AdjMat) do
  84. begin
  85. X[I]:= round(150*sin(2*pi/Length(AdjMat) * I)) + 280;
  86. Y[I]:= round(150*cos(2*pi/Length(AdjMat) * I)) + 220;
  87. end;
  88. end;
  89.  
  90. procedure PrintLines(AdjMat: TIntMatrix; var X, Y: TIntArr);
  91. var
  92. I, J: Integer;
  93. begin
  94. for I:=0 to High(AdjMat) do
  95. for J:=0 to High(AdjMat) do
  96. begin
  97. if AdjMat[J][I] = 1 then
  98. begin
  99. FormOutputGraph.ImageGraph.Canvas.MoveTo(x[I],y[I]);
  100. FormOutputGraph.ImageGraph.Canvas.LineTo(x[J],y[J]);
  101. end;
  102. end;
  103. end;
  104.  
  105. procedure PrintCycleLines(AdjMat: TIntMatrix; var X, Y: TIntArr; ArrCycle: TIntArr);
  106. var
  107. I: Integer;
  108. begin
  109. for I := 0 to High(AdjMat)-1 do
  110. begin
  111. FormOutputGraph.ImageGraph.Canvas.Pen.Color:=clRed;
  112. FormOutputGraph.ImageGraph.Canvas.MoveTo(x[ArrCycle[I]-1],y[ArrCycle[I]-1]);
  113. FormOutputGraph.ImageGraph.Canvas.LineTo(x[ArrCycle[I+1]-1],y[ArrCycle[I+1]-1]);
  114. end;
  115. FormOutputGraph.ImageGraph.Canvas.MoveTo(x[ArrCycle[High(ArrCycle)]-1],y[ArrCycle[High(ArrCycle)]-1]);
  116. FormOutputGraph.ImageGraph.Canvas.LineTo(x[ArrCycle[0]-1],y[ArrCycle[0]-1]);
  117. end;
  118.  
  119. procedure PrintVertex(AdjMat: TIntMatrix; var X, Y: TIntArr);
  120. var
  121. I: Integer;
  122. begin
  123. for I:=0 to High(AdjMat) do
  124. begin
  125. FormOutputGraph.ImageGraph.Canvas.Brush.Color:=clRed;
  126. FormOutputGraph.ImageGraph.Canvas.Ellipse(X[I]-20, Y[I]-20, X[I]+20, Y[I]+20);
  127. FormOutputGraph.ImageGraph.Canvas.TextOut(X[I]-3, Y[I]-7, IntToStr(I+1));
  128. end;
  129. end;
  130.  
  131. procedure TFormOutputGraph.PrintGraph(AdjMat: TIntMatrix; ArrCycle: TIntArr);
  132. Var
  133. X, Y: TIntArr;
  134. Begin
  135. SetLength(X, Length(AdjMat));
  136. SetLength(Y, Length(AdjMat));
  137. FillCoord(AdjMat, X, Y);
  138. PrintLines(AdjMat, X, Y);
  139. PrintCycleLines(AdjMat, X, Y, ArrCycle);
  140. PrintVertex(AdjMat, X, Y);
  141. End;
  142.  
  143. procedure TFormOutputGraph.ButtonResultClick(Sender: TObject);
  144. begin
  145. FormOutputGraph.Close;
  146. end;
  147.  
  148. procedure TFormOutputGraph.FillLabelCyrcle(List: TLinkList<String>);
  149. var
  150. I, Top: Integer;
  151. begin
  152. SetLength(ArrLabel, List.GetSize);
  153. Top := 110;
  154. for I := 0 to List.GetSize - 1 do
  155. begin
  156. ArrLabel[I] := TLabel.Create(FormOutputGraph);
  157. ArrLabel[I].Parent := FormOutputGraph;
  158. ArrLabel[I].Font.Size := 14;
  159. ArrLabel[I].Left := 650;
  160. ArrLabel[I].Top := Top;
  161. ArrLabel[I].Caption := IntToStr(I + 1) + '-ый ' + List.GetLinkByIndex(I+1).getData;
  162. Top := Top + 50;
  163. end;
  164. end;
  165.  
  166. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement