Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

SALAST / DIALOGI

.PAS
Скачиваний:
13
Добавлен:
16.04.2013
Размер:
15.92 Кб
Скачать
{ Лабораторная работа по АиСД }
{Александра Циммермана }
{Суть - реализация алгоритма сортировки }
{ методом СЛИЯНИЯ & СЛИЯНИЯ-подобных }
{ Typed at 22.09.1996 }
{диалоговые окна программы }

Unit Dialogi;
Interface
Uses WObjects,Commons,WinTypes;
{$R Dialogi}
{$I dialogi.inc}
{$D CopyRight '96 by A.Tsimmerman}

Type
PDesignDialog = ^TDesignDialog;
TDesignDialog = Object(TDialog)
Constructor Init ( AParent : PWindowsObject; AName : PChar);
End;
Type
PParamsDialog = ^TParamsDialog;
TParamsDialog = Object(TDialog)
Constructor Init ( AParent : PWindowsObject; AName : PChar);

End;
Type
PSortDialog = ^TSortDialog;
TSortDialog = Object(TDialog)
Constructor Init ( AParent : PWindowsObject; AName : PChar);
End;
Type
PResultDialog = ^TResultDialog;
TResultDialog = Object(TDialog)
Constructor Init ( AParent : PWindowsObject; AName : PChar);
Procedure SetUpWindow; Virtual;
End;

Type
PMethodsInfoDialog = ^TMethodsInfoDialog;
TMethodsInfoDialog = Object(TDialog)
PC : PListBox;
Constructor Init ( AParent : PWindowsObject; AName : PChar);
Procedure SetUpWindow; Virtual;
Procedure idUpDate (Var Msg : TMessage);
Virtual id_First + id_UpDate;
Procedure UpDate; Virtual;
End;
Type
PPointsDialog = ^TPointsDialog;
TPointsDialog = Object(TDialog)
PL : PListBox;
P : PGraphicPoint;
Constructor Init ( AParent : PWindowsObject; AName : PChar);
Procedure SetUpWindow; Virtual;
Procedure idDetail (Var Msg : TMessage);
Virtual id_First + id_Detail;
Procedure idDeleteOne (Var Msg : TMessage);
Virtual id_First + id_DeleteOne;
Procedure idDeleteAll (Var Msg : TMessage);
Virtual id_First + id_DeleteAll;
Procedure UpDate; Virtual;

End;

Type
PGraphicDialog = ^TGraphicDialog;
TGraphicDialog = Object(TDialog)
nAxe : Integer;
TS : Array [1004..1007] Of Boolean;
Misc : Boolean;
ZeroX,ZeroY,LenX,LenY : Integer;
ZeroT,LenT,LenT1 : Real;
ZeroN : Integer;
KeyX,KeyY : Integer;
LowLimit : Integer;
DC : hDC;
PSb,PSc : PScrollBar;
Constructor Init ( AParent : PWindowsObject; AName : PChar);
Procedure SetUpWindow;
Virtual;
Procedure idScrollN (Var Msg : TMessage);
Virtual id_First + id_ScrollN;
Procedure idScrollT (Var Msg : TMessage);
Virtual id_First + id_ScrollT;
Procedure idTS1 (Var Msg : TMessage);
Virtual id_First + id_TS1;
Procedure idTS2 (Var Msg : TMessage);
Virtual id_First + id_TS2;
Procedure idTS3 (Var Msg : TMessage);
Virtual id_First + id_TS3;
Procedure idTS4 (Var Msg : TMessage);
Virtual id_First + id_TS4;
Procedure idGrid (Var Msg : TMessage);
Virtual id_First + id_Grid;
Procedure wmMouseMove (Var Msg : TMessage);
Virtual wm_First + wm_MouseMove;
Procedure UpDate;
Virtual;
Procedure UpDateTime;
Virtual;
Procedure DrawPoints(Switch : Boolean);
Virtual;
End;

Implementation
Uses WinProcs,Strings;
{--------------TDesignDialog----Methods realization}
Constructor TDesignDialog.Init( AParent : PWindowsObject; AName : PChar);
Var Co : Word;
Check : PCheckBox;
Begin
TDialog.Init(AParent, AName);
For Co := 3001 To 3002 Do
Check := New(PCheckBox, InitResource(@Self, Co));
End;

{--------------TParamsDialog----Methods realization}
Constructor TParamsDialog.Init( AParent : PWindowsObject; AName : PChar);
Var Edit : PEdit;
PC : PListBox;
Begin
TDialog.Init(AParent, AName);
Edit := New(PEdit, InitResource(@Self,4000,6));
Edit := New(PEdit, InitResource(@Self,4001,6));
PC := New(PListBox,InitResource(@Self,4002));
PC := New(PListBox,InitResource(@Self,4003));
End;

{--------------TSortDialog----Methods realization}
Constructor TSortDialog.Init( AParent : PWindowsObject; AName : PChar);
Var PB : PRadioButton;
PC : PCheckBox;
Begin
TDialog.Init(AParent, AName);
PB := New(PRadioButton, InitResource(@Self, 3001));
PB := New(PRadioButton, InitResource(@Self, 3002));
PC := New(PCheckBox, InitResource(@Self,3003));
End;

{--------------TResultDialog----Methods realization}
Constructor TResultDialog.Init( AParent : PWindowsObject; AName : PChar);
Begin
TDialog.Init(AParent, AName);
End;

Procedure TResultDialog.SetUpWindow;
Begin
TDialog.SetUpWindow;
SetDlgItemText(hWindow, 100, SortName[SortCurrent]);
SetDlgItemText(hWindow, 101, Result.StElMas);
SetDlgItemText(hWindow, 102, Result.StElDiap);
SetDlgItemText(hWindow, 103, Result.SortTime);
SetDlgItemText(hWindow, 104, Result.Length);
SetDlgItemText(hWindow, 105, Result.Value);
SetDlgItemText(hWindow, 106, Result.Direction);
End;

{--------------TMethodsInfoDialog----Methods realization}
Constructor TMethodsInfoDialog.Init( AParent : PWindowsObject; AName : PChar);
Var PB : PButton;
Begin
TDialog.Init(AParent, AName);
PC := New(PListBox,InitResource(@Self,102));
PB := New(PButton, InitResource(@Self,109));
End;

Procedure TMethodsInfoDialog.SetUpWindow;
Begin
TDialog.SetUpWindow;
UpDate;
End;

Procedure TMethodsInfoDialog.idUpDate(Var Msg : TMessage);
Begin
MInfo.Sel := PC^.GetSelIndex;
UpDate;
End;

Procedure TMethodsInfoDialog.UpDate;
Begin
SetDlgItemText(hWindow, 103, Difficult[MInfo.Sel]);
SetDlgItemText(hWindow, 104, HighLimit[MInfo.Sel]);
SetDlgItemText(hWindow, 105, TypeMassiw[SortBestTypeMassiw[MInfo.Sel]]);
SetDlgItemText(hWindow, 106, TypeMassiw[SortWorstTypeMassiw[MInfo.Sel]]);
SetDlgItemText(hWindow, 108, TypeRequare[SortTypeRequare[MInfo.Sel]]);
End;

{--------------TPointsDialog----Methods realization}
Constructor TPointsDialog.Init( AParent : PWindowsObject; AName : PChar);
Var Edit : PButton;
Begin
TDialog.Init(AParent, AName);
Edit := New(PButton, InitResource(@Self,108));
Edit := New(PButton, InitResource(@Self,109));
Edit := New(PButton, InitResource(@Self,110));
PL := New(PListBox,InitResource(@Self,99));
End;

Procedure TPointsDialog.SetUpWindow;
Var i : Word;
No : Array [0..4] Of Char;
Function NumStr(Num : Word) : String;
Var St : String;
Begin
Str(Num:2,St);
NumStr := ConCat('#',St);
End;
Begin
TDialog.SetUpWindow;
For i := 1 To Graphic^.Count Do PL^.AddString(StrPCopy(No,NumStr(i)));
PL^.SetSelIndex(0);
UpDate;
End;

Procedure TPointsDialog.idDetail(Var Msg : TMessage);
Begin
UpDate;
End;

Procedure TPointsDialog.idDeleteOne(Var Msg : TMessage);
Begin
Graphic^.AtDelete(PL^.GetSelIndex);
PL^.ClearList;
If Graphic^.Count=0 Then MessageBox(hWindow,'Все записанные результаты удалены','Внимание!',mb_Ok);
SetUpWindow;
End;

Procedure TPointsDialog.idDeleteAll(Var Msg : TMessage);
Begin
If MessageBox(hWindow,'Вы действительно хотите удалить все результаты?',
'Внимание!',mb_OkCancel) = id_Cancel Then Exit;
Graphic^.DeleteAll;
PL^.ClearList;
MessageBox(hWindow,'Все записанные результаты удалены','Внимание!',mb_Ok);
SetUpWindow;
End;

Procedure TPointsDialog.UpDate;
Begin
If Graphic^.Count>0 Then
Begin
P := Graphic^.At(PL^.GetSelIndex);
Begin
SetDlgItemText(hWindow, 100, SortName[P^._SortIndex]);
SetDlgItemText(hWindow, 101, ElMas[P^._ElMasIndex]);
SetDlgItemText(hWindow, 102, ElDiap[P^._ElDiapIndex]);
SetDlgItemText(hWindow, 103, P^._SortTime);
SetDlgItemText(hWindow, 104, P^._Length);
SetDlgItemText(hWindow, 105, P^._Value);
SetDlgItemText(hWindow, 106, DirectionName[P^._DirIndex]);
End;
End Else
Begin
EnableWindow(GetItemHandle(id_DeleteOne),False);
EnableWindow(GetItemHandle(id_DeleteAll),False);
EnableWindow(GetItemHandle(id_Detail),False);
SetDlgItemText(hWindow, 100, 'не определено');
SetDlgItemText(hWindow, 101, 'не определено');
SetDlgItemText(hWindow, 102, 'не определено');
SetDlgItemText(hWindow, 103, '0.00');
SetDlgItemText(hWindow, 104, '0');
SetDlgItemText(hWindow, 105, '0');
SetDlgItemText(hWindow, 106, 'не определено');
End;
End;

{--------------TGraphicDialog----Methods realization}

Constructor TGraphicDialog.Init( AParent : PWindowsObject; AName : PChar);
Var RB : PRadioButton;
CB : PCheckbox;
i : Word;
Begin
TDialog.Init(AParent, AName);
For i := 1004 To 1008 Do
CB := New(PCheckBox, InitResource(@Self,i));
PSb := New(PScrollBar, InitResource(@Self,1002));
PSc := New(PScrollBar, InitResource(@Self,1001));
nAxe := 16000;
For i := 1004 To 1007 Do TS[i] := False;
Misc := False;
ZeroX := 51 ; LenX := 480;
ZeroY := 229 ; LenY := 220;
ZeroT := -0.001; LenT1:= Trunc(GetMaxInCollection)+1;
ZeroN := 0; LenT := LenT1;
LowLimit := ZeroY - LenY;
KeyX := LenX Div 8; KeyY := LenY Div 16;
End;

Procedure TGraphicDialog.SetUpWindow;
Begin
TDialog.SetUpWindow;
DC := GetDC(hWindow);
SetDlgItemText(hWindow,id_NPos,'???');
SetDlgItemText(hWindow,id_TPos,'???');
PSb^.SetRange(1000,32000);
PSb^.LineMagnitude := 100;
PSb^.PageMagnitude := 1000;
PSb^.SetPosition(16000);
PSc^.SetRange(10,210);
PSc^.LineMagnitude := 1;
PSc^.PageMagnitude := 10;
PSc^.SetPosition(120);
UpDate;
UpDateTime;
End;


Procedure TGraphicDialog.DrawPoints(Switch : Boolean);
Var i : Integer;
hp,op: hPen;
hb,ob: hBrush;
P : PGraphicPoint;
X,Y : Integer;
Begin
If Graphic^.Count <> 0 Then
Begin
hp := CreatePen(ps_Solid,1,$FFFFFFFF*Byte(Switch));
op := SelectObject(DC,hp);
hb := CreateSolidBrush($FFFFFFFF*Byte(Switch));
ob := SelectObject(DC,hb);
For i := 0 To Graphic^.Count-1 Do
Begin
P := Graphic^.At(i);
X := ZeroX+Round(P^._LengthW/nAxe*LenX);
Y := ZeroY - Round(P^._SortTimeR*LenY/LenT);
If (X > 2) And (X < ZeroX+LenX-2) And
(Y > LowLimit+2) And (Y < ZeroY-2) Then

Ellipse(DC,X-1,Y-1,X+1,Y+1);
End;
SelectObject(DC,op);
DeleteObject(hp);
SelectObject(DC,ob);
DeleteObject(hb);
End;
End;

Procedure TGraphicDialog.idScrollN(Var Msg : TMessage);
Begin
DrawPoints(False);
nAxe := PSb^.GetPosition;
UpDate;
DrawPoints(True);
End;

Procedure TGraphicDialog.idScrollT(Var Msg : TMessage);
Begin
DrawPoints(False);
LenT := LenT1*(220-PSc^.GetPosition)/100;
UpDateTime;
DrawPoints(True);
End;

Procedure TGraphicDialog.idTS1(Var Msg : TMessage);
Var i : Word;
k : Real;
X : Word;
Y : LongInt;
Divider : Byte;
Color : LongInt;
Begin
TS[1004] := Not TS[1004];
Color := PaletteRGB($00,$7F,$00)*Byte(TS[1004]);
k := KeyY/KeyX;
Divider := 3;
For i := 1 To 480 Div Divider Do
Begin
X := i*Divider;
Y := ZeroY-Trunc(k*X);
If Y > LowLimit Then
SetPixel(DC, ZeroX+X, Y, Color);
End;
End;

Procedure TGraphicDialog.idTS2(Var Msg : TMessage);
Var i : Word;
k : Real;
X : Word;
Y : LongInt;
Divider : Byte;
Color : LongInt;
Begin
TS[1005] := Not TS[1005];
Color := PaletteRGB($00,$7F,$00)*Byte(TS[1005]);
k := KeyY/(KeyX*Log2(KeyX));
Divider := 3;
For i := 1 To LenX Div Divider Do
Begin
X := i*Divider;
Y := ZeroY-Trunc(k*X*Log2(X));
If Y > LowLimit Then
SetPixel(DC,ZeroX+X,Y,Color);
End;
End;

Procedure TGraphicDialog.idTS3(Var Msg : TMessage);
Var i : Word;
k : Real;
X : Word;
Y : LongInt;
Divider : Byte;
Color : LongInt;
Begin
TS[1006] := Not TS[1006];
Color := PaletteRGB($00,$7F,$00)*Byte(TS[1006]);
k := KeyY/(KeyX*Log2(KeyX)*Log2(KeyX));
Divider := 3;
For i := 1 To LenX Div Divider Do
Begin
X := i*Divider;
Y := ZeroY-Trunc(k*X*Log2(X)*Log2(X));
If Y > LowLimit Then
SetPixel(DC,ZeroX+X,Y,Color);
End;
End;

Procedure TGraphicDialog.idTS4(Var Msg : TMessage);
Var i : Word;
k : Real;
X : Word;
Y : LongInt;
Divider : Byte;
Color : LongInt;
Begin
TS[1007] := Not TS[1007];
Color := PaletteRGB($00,$7F,$00)*Byte(TS[1007]);
k := KeyY/(KeyX*KeyX);
Divider := 3;
For i := 1 To LenX Div Divider Do
Begin
X := i*Divider;
Y := ZeroY-Trunc(k*X*X);
If Y > LowLimit Then
SetPixel(DC,ZeroX+X,Y,Color);
End;
End;

Procedure TGraphicDialog.idGrid(Var Msg : TMessage);
Var Step : Word; {pels per axe-unit}
i : Word;
hp,op: hPen;
Begin
Misc := Not Misc;
hp := CreatePen(ps_Solid,0,PaletteRGB($00,$00,$7F)*Byte(Misc));
op := SelectObject(DC,hp);
Step := LenX Div 8;
For i := 1 To 7 Do
Begin
MoveTo(DC,ZeroX+i*Step,ZeroY);
LineTo(DC,ZeroX+i*Step,ZeroY-LenY);
End;
MoveTo(DC,ZeroX,ZeroY-Trunc(LenY/2));
LineTo(DC,ZeroX+LenX,ZeroY-Trunc(LenY/2));
SelectObject(DC,op);
DeleteObject(hp);
End;

Procedure TGraphicDialog.UpDate;
Function StrNum (W : Word) : String;
Var St : String;
Begin
Str(W:5,St);
StrNum := St;
End;
Var No : Array [0..5] Of Char;
i : Word;
Begin
For i := 1 To 4 Do
SetDlgItemText(hWindow, 1011+i, StrPCopy(No,StrNum((nAxe Div 4)* i)));
End;

Procedure TGraphicDialog.UpDateTime;
Var Ar : Array [0..6] Of Char;
St : String;
Begin
Str(LenT:3:2,St);
SetDlgItemText(hWindow,id_MaxTime,StrPCopy(Ar,St));
Str((LenT/2):3:2,St);
SetDlgItemText(hWindow,id_HalfTime,StrPCopy(Ar,St));
End;

Procedure TGraphicDialog.wmMouseMove(Var Msg : TMessage);
Var Pt : TPoint;
X : Integer;
Y : Real;
Er : Integer;
YPChar : Array [0..20] Of Char;
Begin
GetCursorPos(Pt);
ScreenToClient(hWindow,Pt);
X := Pt.X - ZeroX;
Y := Pt.Y - (ZeroY-LenY);
If (X >= 0) And (X <= LenX)
And (Y >= 0) And (Y <= LenY) Then
Begin
X := Round(nAxe/LenX*X);
SetDlgItemInt(hWindow,id_NPos,X,False);
Y := (LenY-Y)/LenY*LenT;
Str(Y:5:2,YPChar);
SetDlgItemText(hWindow,id_TPos,YPChar);
End;
End;
Begin
End.

Тут вы можете оставить комментарий к выбранному абзацу или сообщить об ошибке.

Оставленные комментарии видны всем.

Соседние файлы в папке SALAST