Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit OutputGraph;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, MatrixInt, Vcl.StdCtrls, LinkList,
- Vcl.Menus;
- type
- TIntMatrix = TMatrixInt;
- TIntArr = TArrInt;
- TFormOutputGraph = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- ImageGraph: TImage;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- SaveDialog1: TSaveDialog;
- ButtonResult: TButton;
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure N1Click(Sender: TObject);
- procedure ButtonResultClick(Sender: TObject);
- private
- var
- ArrLabel: Array of TLabel;
- public
- procedure PrintGraph(AdjMat: TIntMatrix; ArrCycle: TIntArr);
- procedure FillLabelCyrcle(List: TLinkList<String>);
- end;
- var
- FormOutputGraph: TFormOutputGraph;
- implementation
- {$R *.dfm}
- uses Unit2, Graph;
- procedure TFormOutputGraph.FormCloseQuery(Sender: TObject;
- var CanClose: Boolean);
- var
- I: Integer;
- NewImage: TImage;
- begin
- for I := 0 to High(ArrLabel) do
- ArrLabel[I].DisposeOf;
- ImageGraph.DisposeOf;
- NewImage := TImage.Create(FormOutputGraph);
- NewImage.Parent := FormOutputGraph;
- NewImage.Name := 'ImageGraph';
- NewImage.Left := 50;
- NewImage.Top := 120;
- NewImage.Height := 450;
- NewImage.Width := 540;
- end;
- procedure TFormOutputGraph.N1Click(Sender: TObject);
- var
- IsCorrect : Boolean;
- begin
- repeat
- IsCorrect := True;
- if SaveDialog1.Execute then
- begin
- IsCorrect := MainForm.CheckFileExtension(SaveDialog1.FileName);
- if IsCorrect then
- begin
- MainForm.OutputFile(SaveDialog1.FileName);
- ShowMessage('Результат успешно сохранён');
- end;
- end;
- until IsCorrect;
- end;
- procedure FillCoord(AdjMat: TIntMatrix; var X, Y: TIntArr);
- var
- I: Integer;
- begin
- for I := 0 to High(AdjMat) do
- begin
- X[I]:= round(150*sin(2*pi/Length(AdjMat) * I)) + 280;
- Y[I]:= round(150*cos(2*pi/Length(AdjMat) * I)) + 220;
- end;
- end;
- procedure PrintLines(AdjMat: TIntMatrix; var X, Y: TIntArr);
- var
- I, J: Integer;
- begin
- for I:=0 to High(AdjMat) do
- for J:=0 to High(AdjMat) do
- begin
- if AdjMat[J][I] = 1 then
- begin
- FormOutputGraph.ImageGraph.Canvas.MoveTo(x[I],y[I]);
- FormOutputGraph.ImageGraph.Canvas.LineTo(x[J],y[J]);
- end;
- end;
- end;
- procedure PrintCycleLines(AdjMat: TIntMatrix; var X, Y: TIntArr; ArrCycle: TIntArr);
- var
- I: Integer;
- begin
- for I := 0 to High(AdjMat)-1 do
- begin
- FormOutputGraph.ImageGraph.Canvas.Pen.Color:=clRed;
- FormOutputGraph.ImageGraph.Canvas.MoveTo(x[ArrCycle[I]-1],y[ArrCycle[I]-1]);
- FormOutputGraph.ImageGraph.Canvas.LineTo(x[ArrCycle[I+1]-1],y[ArrCycle[I+1]-1]);
- end;
- FormOutputGraph.ImageGraph.Canvas.MoveTo(x[ArrCycle[High(ArrCycle)]-1],y[ArrCycle[High(ArrCycle)]-1]);
- FormOutputGraph.ImageGraph.Canvas.LineTo(x[ArrCycle[0]-1],y[ArrCycle[0]-1]);
- end;
- procedure PrintVertex(AdjMat: TIntMatrix; var X, Y: TIntArr);
- var
- I: Integer;
- begin
- for I:=0 to High(AdjMat) do
- begin
- FormOutputGraph.ImageGraph.Canvas.Brush.Color:=clRed;
- FormOutputGraph.ImageGraph.Canvas.Ellipse(X[I]-20, Y[I]-20, X[I]+20, Y[I]+20);
- FormOutputGraph.ImageGraph.Canvas.TextOut(X[I]-3, Y[I]-7, IntToStr(I+1));
- end;
- end;
- procedure TFormOutputGraph.PrintGraph(AdjMat: TIntMatrix; ArrCycle: TIntArr);
- Var
- X, Y: TIntArr;
- Begin
- SetLength(X, Length(AdjMat));
- SetLength(Y, Length(AdjMat));
- FillCoord(AdjMat, X, Y);
- PrintLines(AdjMat, X, Y);
- PrintCycleLines(AdjMat, X, Y, ArrCycle);
- PrintVertex(AdjMat, X, Y);
- End;
- procedure TFormOutputGraph.ButtonResultClick(Sender: TObject);
- begin
- FormOutputGraph.Close;
- end;
- procedure TFormOutputGraph.FillLabelCyrcle(List: TLinkList<String>);
- var
- I, Top: Integer;
- begin
- SetLength(ArrLabel, List.GetSize);
- Top := 110;
- for I := 0 to List.GetSize - 1 do
- begin
- ArrLabel[I] := TLabel.Create(FormOutputGraph);
- ArrLabel[I].Parent := FormOutputGraph;
- ArrLabel[I].Font.Size := 14;
- ArrLabel[I].Left := 650;
- ArrLabel[I].Top := Top;
- ArrLabel[I].Caption := IntToStr(I + 1) + '-ый ' + List.GetLinkByIndex(I+1).getData;
- Top := Top + 50;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement