135481 (Программная реализация модального управления для линейных стационарных систем), страница 2
Описание файла
Документ из архива "Программная реализация модального управления для линейных стационарных систем", который расположен в категории "". Всё это находится в предмете "радиофизика и электроника" из , которые можно найти в файловом архиве . Не смотря на прямую связь этого архива с , его также можно найти и в других разделах. Архив можно найти в разделе "рефераты, доклады и презентации", в предмете "радиоэлектроника" в общих файлах.
Онлайн просмотр документа "135481"
Текст 2 страницы из документа "135481"
RadioGroupChart: TRadioGroup;
ChartFX: TChartFX;
LabelW1: TLabel;
StringGrid_Solve1: TStringGrid;
StringGrid_Solve2: TStringGrid;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure BitBtn_CloseClick(Sender: TObject);
procedure BitBtn_OptionsClick(Sender: TObject);
procedure BitBtn_ComputeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpinEdit_DimChange(Sender: TObject);
procedure StringGrid_RootsSetEditText(Sender: TObject; ACol,
ARow: Longint; const Value: string);
procedure RadioGroup_RootsTypeClick(Sender: TObject);
procedure TabbedNotebook_MainChange(Sender: TObject; NewTab: Integer;
var AllowChange: Boolean);
procedure StringGrid_SetEditText(Sender: TObject; ACol,
ARow: Longint; const Value: string);
procedure BitBtn_HelpClick(Sender: TObject);
procedure RadioGroupChartClick(Sender: TObject);
private
procedure FillFixedCellsInAllGrids;
procedure FillCellsInAllGrids;
public
procedure BindGrids;
procedure UnBindGrids;
end;
var
Form_Main: TForm_Main;
implementation
uses Matrix, SubUnit, OptsUnit, Operates, CFXOCX2, HelpUnit;
const
DefOptions = [goFixedVertLine, goFixedHorzLine,
goVertLine, goHorzLine,
goColSizing, goEditing,
goAlwaysShowEditor, goThumbTracking];
{$R *.DFM}
procedure TForm_Main.FillFixedCellsInAllGrids;
var
Order : TOrder;
i: byte;
Str: string;
begin
Order := SpinEdit_Dim.Value;
for i := 1 to Order do
begin
Str := IntToStr(i);
StringGrid_Ap0.Cells[0, i] := Str;
StringGrid_Ap0.Cells[i, 0] := Str;
StringGrid_Bp0.Cells[0, i] := Str;
StringGrid_ANp0.Cells[i, 0] := Str;
StringGrid_ANp0.Cells[0, i] := Str;
StringGrid_Roots.Cells[i, 0] := Str;
StringGrid_Kpp0.Cells[i, 0] := Str;
StringGrid_Ap1.Cells[0, i] := Str;
StringGrid_Ap1.Cells[i, 0] := Str;
StringGrid_Bp1.Cells[0, i] := Str;
StringGrid_ABKpp1.Cells[i, 0] := Str;
StringGrid_ABKpp1.Cells[0, i] := Str;
StringGrid_InCond.Cells[i, 0] := Str;
StringGrid_Kpp1.Cells[i, 0] := Str;
StringGrid_Solve1.Cells[i, 0] := 'X' + IntToStr(i);
StringGrid_Solve2.Cells[i, 0] := 'X' + IntToStr(i);
StringGrid_Solve1.Cells[0, 0] := 'Время';
StringGrid_Solve2.Cells[0, 0] := 'Время';
end;
end;
procedure TForm_Main.FillCellsInAllGrids;
var
Order : TOrder;
i, j : byte;
begin
Order := SpinEdit_Dim.Value;
for i := 1 to Order do
for j := 1 to Order do
begin
StringGrid_Ap0.Cells[j, i] := '0';
StringGrid_Ap0.Cells[i, i] := '1';
StringGrid_Bp0.Cells[1, i] := '0';
StringGrid_Roots.Cells[i, 1] := '-1';
StringGrid_Roots.Cells[i, 2] := '0';
StringGrid_Kpp0.Cells[i, 1] := '0';
StringGrid_Ap1.Cells[j, i] := '0';
StringGrid_Ap1.Cells[i, i] := '1';
StringGrid_Bp1.Cells[1, i] := '0';
StringGrid_ABKpp1.Cells[j, i] := '0';
StringGrid_ABKpp1.Cells[i, i] := '1';
StringGrid_InCond.Cells[i, 1] := '0';
StringGrid_Kpp1.Cells[i, 1] := '0';
end;
FillFixedCellsInAllGrids;
StringGrid_Roots.Cells[0, 1] := 'Re';
StringGrid_Roots.Cells[0, 2] := 'Im';
StringGrid_Bp1.Cells[1, 0] := '1';
StringGrid_Bp0.Cells[1, 0] := '1';
end;
procedure TForm_Main.BindGrids;
begin
CopyGrid(StringGrid_Ap1, StringGrid_Ap0);
CopyGrid(StringGrid_Bp1, StringGrid_Bp0);
CopyGrid(StringGrid_Kpp1, StringGrid_Kpp0);
StringGrid_Ap1.Options := DefOptions - [goEditing];
StringGrid_Bp1.Options := DefOptions - [goEditing];
StringGrid_Kpp1.Options := DefOptions - [goEditing];
end;
procedure TForm_Main.UnBindGrids;
begin
StringGrid_Ap1.Options := DefOptions;
StringGrid_Bp1.Options := DefOptions;
StringGrid_Kpp1.Options := DefOptions;
end;
procedure TForm_Main.BitBtn_CloseClick(Sender: TObject);
begin
Close;
end;
procedure TForm_Main.BitBtn_OptionsClick(Sender: TObject);
var
V0, V1, V2, V3: LongInt;
LS: TCheckBoxState;
begin
with Form_Options do
begin
V0 := SpinEdit0.Value;
V1 := SpinEdit1.Value;
V2 := SpinEdit2.Value;
V3 := SpinEdit3.Value;
LS := CheckBox_Link.State;
ShowModal;
if ModalResult = mrCancel then
begin
SpinEdit0.Value := V0;
SpinEdit1.Value := V1;
SpinEdit2.Value := V2;
SpinEdit3.Value := V3;
CheckBox_Link.State := LS;
end
else
if ((SpinEdit0.Value <> V0) or (SpinEdit1.Value <> V1)) or
((SpinEdit2.Value <> V2) or (SpinEdit3.Value <> V3)) then
begin
BitBtn_Compute.Enabled := True;
case BitBtn_Compute.Tag of
4, 5 :BitBtn_Compute.Tag := BitBtn_Compute.Tag - 4;
6, 7 :BitBtn_Compute.Tag := BitBtn_Compute.Tag - 4;
8, 9 :BitBtn_Compute.Tag := BitBtn_Compute.Tag - 8;
10, 11 :BitBtn_Compute.Tag := BitBtn_Compute.Tag - 8;
12, 13 :BitBtn_Compute.Tag := BitBtn_Compute.Tag - 12;
14, 15 :BitBtn_Compute.Tag := BitBtn_Compute.Tag - 12;
end;
end;
end;
end;
procedure TForm_Main.BitBtn_ComputeClick(Sender: TObject);
begin
BitBtn_Compute.Enabled := False;
if Form_Options.CheckBox_Link.State = cbChecked then BindGrids;
case TabbedNotebook_Main.PageIndex of
0 : begin
ComputeFromPage0;
BitBtn_Compute.Tag := BitBtn_Compute.Tag + 1;
end;
1 : begin
ComputeFromPage1;
ShowChart(Succ(RadioGroupChart.ItemIndex));
BitBtn_Compute.Tag := BitBtn_Compute.Tag + 14;
end;
2 : begin
ComputeFromPage2;
BitBtn_Compute.Tag := BitBtn_Compute.Tag + 4;
end;
3 : begin
ComputeFromPage3;
BitBtn_Compute.Tag := BitBtn_Compute.Tag + 8;
end;
end;
end;
procedure TForm_Main.FormCreate(Sender: TObject);
const
FirstColWidth = 20;
begin
StringGrid_Ap0.ColWidths [0] := FirstColWidth;
StringGrid_Anp0.ColWidths [0] := FirstColWidth;
StringGrid_Bp0.ColWidths [0] := FirstColWidth;
StringGrid_Roots.ColWidths [0] := FirstColWidth;
StringGrid_Ap1.ColWidths [0] := FirstColWidth;
StringGrid_ABKpp1.ColWidths [0] := FirstColWidth;
StringGrid_Bp1.ColWidths [0] := FirstColWidth;
StringGrid_Kpp0.ColWidths [0] := FirstColWidth;
StringGrid_Kpp1.ColWidths [0] := FirstColWidth;
StringGrid_InCond.ColWidths [0] := FirstColWidth;
FillCellsInAllGrids;
BindGrids;
end;
procedure TForm_Main.SpinEdit_DimChange(Sender: TObject);
var
Order: byte;
begin
Order := Succ(SpinEdit_Dim.Value);
StringGrid_Ap0.ColCount := Order;
StringGrid_Ap0.RowCount := Order;
StringGrid_Anp0.ColCount := Order;
StringGrid_Anp0.RowCount := Order;
StringGrid_Bp0.RowCount := Order;
StringGrid_Roots.ColCount := Order;
StringGrid_Kpp0.ColCount := Order;
StringGrid_Ap1.ColCount := Order;
StringGrid_Ap1.RowCount := Order;
StringGrid_Bp1.RowCount := Order;
StringGrid_ABKpp1.ColCount := Order;
StringGrid_ABKpp1.RowCount := Order;
StringGrid_InCond.ColCount := Order;
StringGrid_Kpp1.ColCount := Order;
FillFixedCellsInAllGrids;
BitBtn_Compute.Enabled := True;
end;
procedure TForm_Main.StringGrid_RootsSetEditText(Sender: TObject; ACol,
ARow: Longint; const Value: string);
var
Val : string;
begin
if (ARow = 2) and (Value <> '') then
begin
Val := StringGrid_Roots.Cells [ACol, ARow];
if StrToFloat (Value) <> 0 then
StringGrid_Roots.Cells[Succ(ACol),ARow]:=FloatToStr(- StrToFloat(Value));
if StrToFloat (Value) = 0 then
StringGrid_Roots.Cells [Succ(ACol),ARow] := FloatToStr(0);
end;
end;
procedure TForm_Main.RadioGroup_RootsTypeClick(Sender: TObject);
var
Order: TOrder;
j: byte;
NHalf: byte;
StartAlfa, NAlfa, dAlfa: Float;
W: Float;
begin
Order := SpinEdit_Dim.Value;
W := StrToFloat (Edit_W.Text);
case RadioGroup_RootsType.ItemIndex of
0 :StringGrid_Roots.Options := DefOptions;
1 :begin
for j := 1 to Order do
begin
StringGrid_Roots.Cells [j, 1] := FloatToStr (-W);
StringGrid_Roots.Cells [j, 2] := '0';
StringGrid_Roots.Options := DefOptions - [goEditing];
end
end;
2 :begin
dAlfa := Pi / Order;
StartAlfa := Pi/2 - dAlfa/2;
NHalf := Order div 2;
for j := 1 to NHalf do
begin
NAlfa := StartAlfa + dAlfa * j;
StringGrid_Roots.Cells [j, 1] := FloatToStr (Cos (NAlfa) * W);
StringGrid_Roots.Cells [Order - Pred (j), 1] := FloatToStr (Cos (-NAlfa) * W);
StringGrid_Roots.Cells [j, 2] := FloatToStr (Sin (NAlfa) * W);
StringGrid_Roots.Cells [Order - Pred (j), 2] := FloatToStr (Sin (-NAlfa) * W);
end;
if Odd (Order) then
begin
StringGrid_Roots.Cells [NHalf +1, 1] := FloatToStr (-W);
StringGrid_Roots.Cells [NHalf +1, 2] := '0';
end;
StringGrid_Roots.Options := DefOptions - [goEditing];
end;
end;
end;
procedure TForm_Main.TabbedNotebook_MainChange(Sender: TObject;
NewTab: Integer; var AllowChange: Boolean);
begin
with BitBtn_Compute do
case NewTab of
0 :begin
SpinEdit_Dim.Enabled := True;
if Tag in [1, 3, 5, 7, 9, 11, 13, 15] then Enabled := False
else Enabled := True;
BitBtn_Compute.Caption := 'Рассчитать модальное управление';
end;
1 :begin
SpinEdit_Dim.Enabled := True;
if Tag in [2, 3, 6, 7, 10, 11, 14, 15] then Enabled := False
else Enabled := True;
BitBtn_Compute.Caption := 'Решить системы дифф. уравнений ';
if Form_Options.CheckBox_Link.State = cbChecked then BindGrids;
end;
2 :begin
SpinEdit_Dim.Enabled := False;
if Tag in [4, 5, 6, 7, 12, 13, 14, 15] then Enabled := False
else Enabled := True;
BitBtn_Compute.Caption := 'Обновить результаты решений ';
end;
3 :begin
SpinEdit_Dim.Enabled := False;
if Tag in [8, 9, 10, 11, 12, 13, 14, 15] then Enabled := False
else Enabled := True;
BitBtn_Compute.Caption := 'Обновить диаграмму решения ';
end;
end;
end;
procedure TForm_Main.StringGrid_SetEditText(Sender: TObject; ACol,
ARow: Longint; const Value: string);
begin
if not BitBtn_Compute.Enabled then
case TabbedNotebook_Main.PageIndex of
0 :if Form_Options.CheckBox_Link.State = cbChecked then
BitBtn_Compute.Tag := BitBtn_Compute.Tag - 3
else
BitBtn_Compute.Tag := BitBtn_Compute.Tag - 1;
1 :BitBtn_Compute.Tag := BitBtn_Compute.Tag - 2;
end;
BitBtn_Compute.Enabled := True;
end;
procedure TForm_Main.BitBtn_HelpClick(Sender: TObject);
begin
Form_Help.ShowModal;
end;
procedure TForm_Main.RadioGroupChartClick(Sender: TObject);
begin
case RadioGroupChart.ItemIndex of
0 :ShowChart(1);
1 :ShowChart(2);
end;
end;
end.
unit SubUnit;
interface
uses
SysUtils, Matrix, Operates, Grids;
procedure CopyGrid(AGrid, BGrid: TStringGrid);
procedure LoadMatrixSolveFromStrGrd (AMatrix: TMatrix; AGrid: TStringGrid);
procedure ComputeFromPage0;
procedure ComputeFromPage1;
procedure ComputeFromPage2;
procedure ComputeFromPage3;
procedure ShowChart(NumberOfChart: Byte);
implementation
uses
MainUnit, OptsUnit, CFXOCX2;
procedure CopyGrid(AGrid, BGrid: TStringGrid);
var
i, j: LongInt;
begin
AGrid.ColCount := BGrid.ColCount;
AGrid.RowCount := BGrid.RowCount;
for j := 0 to AGrid.ColCount do
for i := 0 to AGrid.RowCount do
AGrid.Cells[j, i] := BGrid.Cells[j, i];
end;
function CropStr (Str: String): String;
var
i: Byte;
Str_1: String;
Begin
for i := Length(Str) downto 1 do
if Str [i] = ' ' then Str := Copy(Str, 1, i-1)
else Break;
Str_1 := Str;
for i := 1 to Length(Str) do
if Str[i] = ' ' then Str_1 := Copy(Str, i+1, Length(Str) - i)
else Break;
CropStr := Str_1;
End;
procedure LoadMatrixFromStrGrd (AMatrix: TMatrix; AGrid: TStringGrid);
var
i, j: Word;
begin