Unit Applic1;
{$F+,O+,X+,V-,R-,I-,S-}
Interface
Uses
Crt,
Objects, Drivers, Dialogs, Views, Menus, App, StdDlg,
Fonts, HelpFile, MsgBox, TxtRead, WInDows,
PalObj, Grv16, DemoHlp, Types2;
Const
cmAbout = 100;
cmReCounte = 101;
cmTxtWInDow = 102;
cmDialog = 103;
cmDemOfonts = 104;
cmDemoPic = 105;
cmWInWIn = 106;
cmCur = 107;
cmRes = 108;
cmIdle = 6000;
HelpName:String ='Sheme.hlp';
Var
ValDel: LongInt;
Ticks: WOrd absolute $40:$6C; { BIOS Timer ticks counter }
Type
TMyApp = Object(TApplication)
MemoAvail: LongInt; {Свободная мем}
ShemeWInDow: PShemeWIn; {Окно}
ShemeName: String; {Имя схемы}
ConstructOr Init; {Добавление нового }
Procedure HAndleEvent(Var Event: TEvent); Virtual;
Procedure InitMenuBar; Virtual;
Procedure InitStatusLIne; Virtual;
Procedure ReCounte; Virtual;
Procedure About;
Procedure HlpWInDow;
Procedure NewSheme;
Procedure OpenSheme;
Procedure SaveSheme;
Procedure SaveShemeAs;
Procedure Idle; Virtual; {Обновление показ. памяти}
End;
Implementation
ConstructOr TMyApp.Init;
Var
R: TRect;
Begin
Inherited Init;
InitSheme(Sheme);
ShemeName:='';
Changed:=False;
StatusLIne^.GetBounds(R);
R.A.X:= R.B.X - 65;
Insert(New(PMemoView, Init(R)));
MemoAvail:= MemAvail;
ValDel:= Ticks;
DeskTop^.GeTextent(R);
ShemeWInDow:=New(PShemeWIn,Init(R));
DeskTop^.Insert(ShemeWInDow);
DisableCommAnds([cmRes]);
EnableCommAnds([cmCur]);
End;
Procedure TMyApp.Idle;
Function IsTileable(P: PView): Boolean;
Begin
IsTileable:= (P^.Options And OfTileable) <> 0;
End;
Begin
Inherited Idle;
Message(@Self, evBroadCast, cmIdle, Nil);
If MemoAvail <> MemAvail Then Begin
Message(@Self, evBroadCast, cmMemoViewChange, Nil);
MemoAvail:= MemAvail;
End;
If Desktop^.FirstThat(@IsTileable) <> Nil
Then EnableCommAnds([cmTile, cmCascade])
Else DisableCommAnds([cmTile, cmCascade]);
End;
Procedure TMyApp.InitMenuBar;
Var R: TRect;
Begin
GeTextent (R);
R.B.Y:= R.A.Y + CurrentFont^.Height + 1;
MenuBar:= New(PMenuBar, Init(R, NewMenu(
NewItem('~Ё~', '', kbAltSpace, cmAbout, hcMenu10,
NewSubMenu('~Ф~айл', hcMenu20, NewMenu(
NewItem('~Н~овая схема', '', kbNoKey, cmNew, hcNoConText,
NewItem('~Ч~итать схему с диска', 'F3', kbF3, cmOpen, hcNoConText,
NewItem('~C~охранить схему', 'F2', kbF2, cmSave, hcNoConText,
NewItem('Cохранить ~к~ак...', 'ShIft-F2', kbShIftF2, cmSaveAs, hcNoConText,
NewLIne(
NewItem('~В~ыход', 'Alt-X', kbAltX, cmQuit, hcNoConText,
Nil))))))),
NewSubMenu('~О~кно', hcMenu30, NewMenu(
NewItem('~С~ледующее', 'F6', kbF6, cmNext, hcNoConText,
NewItem('~П~редыдущее', 'F5', kbF5, cmPrev, hcNoConText,
NewItem('~З~акрыть', 'AltF3', kbAltF3, cmClose, hcNoConText,
Nil)))),
Nil)
)))));
MenuBar^.State:= MenuBar^.State Or sfActive;
End;
Procedure TMyApp.InitStatusLIne;
Var R: TRect;
Begin
GeTextent(R);
R.A.Y:= R.B.Y - 19;
SetFont(@Font8x14);
StatusLIne:= New(PStatusLIne, Init(R,
NewStatusDef(0, $0FFF,
NewStatusKey('', kbAltF3, cmClose,
NewStatusKey('~F1~ Помощь', kbF1, cmHelp,
NewStatusKey('', kbF10, cmMenu,
NewStatusKey('~Alt-X~ Выход', kbAltX, cmQuit,
NewStatusKey('~F7~Токи', kbF7, cmCur,
NewStatusKey('~F8~Резисторы', kbF8, cmRes,
NewStatusKey('~F9~ Обсчет', kbF9, cmReCounte,
Nil))))))),
NewStatusDef($1000, $1001,
NewStatusKey('~Ctrl-'#24#25#26#27'~ Перемещение', kbNoKey, cmNo,
NewStatusKey('~Shft-'#24#25#26#27'~ Размер', kbNoKey, cmNo,
NewStatusKey('~'#17#217'~ Подтвердить', kbNoKey, cmNo,
NewStatusKey('~Esc~ Отменить', kbNoKey, cmNo,
Nil)))),
NewStatusDef($FFFE, $FFFF,
NewStatusKey('', kbAltF3, cmClose,
NewStatusKey('~Tab~ След. индекс', kbTab, cmNextTopic,
NewStatusKey('~ShIft-Tab~ Пред. индекс', kbShIftTab, cmPrevTopic,
NewStatusKey('~Esc~ Закрыть', kbEsc, cmClose,
Nil)))),
Nil)))
));
RestOreFont;
End;
Procedure TMyApp.HAndleEvent(Var Event: TEvent);
Var
R: TRect;
P: PView;
Control: WOrd;
SavePalette: PaletteType;
Begin
Inherited HAndleEvent(Event);
If Event.What = evCommAnd Then
Begin
Case Event.CommAnd Of
cmNew : NewSheme;
cmOpen : OpenSheme;
cmSave : If ShemeName=''
Then SaveShemeAs
Else SaveSheme;
cmSaveAs : SaveShemeAs;
cmReCounte : ReCounte;
cmAbout : About;
cmHelp : HlpWInDow;
cmCur : Begin
IsResist:=False;
DisableCommAnds([cmCur]);
EnableCommAnds([cmRes]);
ShemeWInDow^.DrawView;
End;
cmRes : Begin
IsResist:=True;
DisableCommAnds([cmRes]);
EnableCommAnds([cmCur]);
ShemeWInDow^.DrawView;
End;
Else
Exit;
End;
ClearEvent(Event);
End;
End;
Procedure TMyApp.OpenSheme;
Var
D: PFileDialog;
FileName: String[79];
i,j:Integer;
f:Text;
c:wOrd;
Begin
If Not Exist
Then NewSheme;
D:= PFileDialog(ValidView(New(PFileDialog, Init('*.shm', 'Выбор файла',
'~И~мя файла со схемой', fDopenButton, 100))));
If D <> Nil Then
Begin
c:=Desktop^.ExecView(D);
If c <> cmCancel Then
Begin
D^.GetFileName(FileName);
Assign(f,FileName);
reset(f);
For i:=1 To nS Do Begin For j:=1 To mS Do Read (f,Sheme[i,j,1]); Readln(f);
End;
For i:=1 To nS Do Begin For j:=1 To mS Do Read(f,EDS[i,j]); Readln(f); End;
For i:=1 To nS Do Begin For j:=1 To mS Do Read(f,Res[i,j]); Readln(f); End;
Close(f); ShemeName:=FileName;
DisposeStr(ShemeWInDow^.Title);
ShemeWInDow^.Title:=NewStr('Схема '+ShemeName);
ElNumbers(Sheme);
ShemeWInDow^.DrawView;
End; Dispose(D, Done); End;
End;
Procedure TMyApp.SaveSheme;
Var f:Text;
i,j:Integer;
Begin
Assign (f,ShemeName); ReWrite (f);
For i:=1 To nS Do Begin
For j:=1 To mS Do Write(f,Sheme[i,j,1]:4); Writeln(f);
End;
For i:=1 To nS Do Begin For j:=1 To mS Do Write(f,EDS[i,j]:5:2,' ');
Writeln(f);
End;
For i:=1 To nS Do Begin For j:=1 To mS Do Write(f,Res[i,j]:5:2,' ');
Writeln(f);
End;
Close(f);
End;
Procedure TMyApp.SaveShemeAs;
Var
D: PFileDialog;
FileName: String[79];
W: PWInDow;
C:wOrd;
Begin
D:= New(PFileDialog, Init('*.SHM', 'Выбор файла', ShemeName,
fDokButton, 100));
C:= Desktop^.ExecView(D); D^.GetFileName(ShemeName);
Dispose(D, Done);
If ShemeName='' Then exit; SaveSheme;
ShemeWInDow^.Title:=NewStr('Схема '+ShemeName);
ShemeWInDow^.DrawView;
End;
Procedure TMyApp.HlpWInDow;
Var
W: PWInDow;
Begin
W:= PWInDow(ValidView(New(PFileWInDow,Init(HelpName))));
W^.HelpCtx:= hcMenu30; If W <> Nil Then Desktop^.Insert(W);
End;
Procedure TMyApp.NewSheme;
Var R:TRect;
c:wOrd;
Begin
If Exist And Changed
Then Begin
R.Assign((Size.X-CurrentFont^.Width*50) Div 2,(Size.Y-
CurrentFont^.Height*10) Div 2,
(Size.X+CurrentFont^.Width*50) Div 2,(Size.Y+
CurrentFont^.Height*10) Div 2);
c:=MessageBoxRect(R,
'В текущую схему внесены изменения с момента последнего '+
'сохранения, которые будут потеряны. Хотите ли Вы сохранить текущую '+
'схему?',Nil,mfYesNoCancel+mfConfirmation);
Case c Of
cmYes:If ShemeName<>'' Then SaveSheme Else SaveShemeAs;
cmCancel:Exit; End; End;
If Not Exist Then Begin
DeskTop^.GeTextent(R);
ShemeWInDow:=New(PShemeWIn,Init(R));
DeskTop^.Insert(ShemeWInDow);End;
ShemeName:=''; DisposeStr(ShemeWInDow^.Title);
ShemeWInDow^.Title:=NewStr('Схема без имени');
Changed:=False; InitSheme(Sheme); ShemeWInDow^.DrawView;
End;
Procedure TMyApp.About;
Begin
MessageBox('Обсчет разветвленных цепей. Ver.1.0.',Nil,
mfInFormation+mfOkButton);
End;
Procedure TMyApp.ReCounte;
Begin Abstract;{This method must be overriden} End;
E ND.
Дата: 2019-05-29, просмотров: 214.