Исследование методов автоматизированного проектирования динамических систем
Структурно-информационный анализ методов моделирования динамических систем. Математическое моделирование. Численные методы решения систем дифференциальных уравнений. Разработка структуры програмного комплекса для анализа динамики механических систем.
Рубрика | Программирование, компьютеры и кибернетика |
Вид | дипломная работа |
Язык | русский |
Дата добавления | 14.05.2010 |
Размер файла | 1,1 M |
Отправить свою хорошую работу в базу знаний просто. Используйте форму, расположенную ниже
Студенты, аспиранты, молодые ученые, использующие базу знаний в своей учебе и работе, будут вам очень благодарны.
l:=l+2;
until links[i].relations[j].Param.Count=l;
k:=k+1;
end;
end;
end;
procedure TForm1.ToolButton5Click(Sender: TObject);
var
i, k, j: Integer;
idx, l1, l2: Integer;
Sel_Item: Tprocess;
Sel_Link: Tlink;
b16_check,b2_check: boolean;
begin
for i:=0 to ToolBar1.ButtonCount-1 do ToolBar1.Buttons[i].Down:=False;
if (Sender as TToolButton).Down then
begin
idx:=(Sender as TToolButton).Index;
for i:=0 to ToolBar2.ButtonCount-1 do
if i<>idx then ToolBar2.Buttons[i].Down:=False;
end;
if ((Sender as TToolButton).Hint = 'Lфрыхэшх') and
(SelectedItems.Count + SelectedLinks.Count > 0) then
if MessageDlg('LфрышЄ№ '+ IntToStr(SelectedItems.Count) + ' ¤ыхьхэЄ(ют) ш ' +
IntToStr(SelectedLinks.Count) + ' ёт чхщ?', mtWarning, [mbYes, mbNo], 0) = mrYes then
begin
for k := 0 to SelectedItems.Count - 1 do
begin
Sel_Item := SelectedItems.Items[k];
l1:=1;
while l1<link_index do
begin
if (links[l1].First=Sel_Item) or
(links[l1].Second=Sel_Item) then
begin
links[l1].Free;
links[l1] := nil;
for l2:=l1 to link_index-2 do
begin
links[l2]:=links[l2+1];
// links[l2].Caption:=inttostr(l2);
end;
links[link_index-1] := nil;
dec(link_index);
dec(l1);
end;
inc(l1);
if l1<=0 then break;
end;
i := 1;
while (i < item_index) and (Sel_Item <> Item[i]) do
Inc(i);
FreeAndNil(item[i]);
destroy_flag:=True;
for j:=i to item_index-2 do item[j]:=item[j+1];
item_index:=item_index-1;
end;
for k := 0 to SelectedLinks.Count - 1 do
begin
Sel_Link := SelectedLinks.Items[k];
i := 1;
while (i < Link_index) and (links[i]<>Sel_Link) do
Inc(i);
if i = Link_Index then Continue;
try
links[i].Free;
except
end;
links[i] := nil;
for j:=i to link_index-2 do
begin
links[j]:=links[j+1];
end;
links[link_index-1] := nil;
link_index:=link_index-1;
end;
current_item := 1;
SelectedItems.Clear;
SelectedLinks.Clear;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var form:TInputDlg;
begin
form:=TInputDlg.Create(form1);
form.ShowModal;
t:=StrToFloat(form.Edit1.Text);
ht:=StrToFloat(form.Edit2.Text);
e:=StrToFloat(form.Edit3.Text);
method:=form.RadioGroup1.ItemIndex;
desc:=form.Edit4.Text;
form.Destroy;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//ShellExecute();
end;
end.
ПРИЛОЖЕНИЕ В
Главный модуль прграммы расчётов.
unit modell;
interface
uses classes, stdctrls, graphics, extctrls, QUICKRPT, QRCTRLS, qrprntr,
ShellAPI, Windows, ComObj, inifiles,
types, model_edit_dlg,
model_param_dlg, visual_dlg, report_dlg, waitreportcreate_dlg;
type
TCount=record
Masses, Relations: integer;
end;
TMethod=record
code : TFloat;
digree: integer;
end;
TModel = class(TAbstractObject)
public
Count: TCount;
flIsSaved : boolean; // flag of is model saved
flIsModelling: boolean;
constructor Create;
destructor Destroy; override;
procedure AddElement; virtual;
function ShowDialog(wind: integer): integer;
procedure SaveModel(FileName: string); virtual;
function LoadModel(FileName: string):boolean; virtual;
procedure SetParamsInZero; virtual;
procedure Visio; virtual;
procedure ShowReport(FName: string); virtual;
procedure MakeReport(FName: string); virtual;
protected
t: TFloat; //time
ht: TFloat; // time step
e: TFloat; // inaccuracy
CalcMethod: TMethod; // digital modelling method
WDoc: variant; //for winword report automation;
NewElement: TObject; //current created element
flReadFromFile: boolean; // flag - true if now data read from file
Editor: TEditDlg;
VisualDlg: TVisualDlg;
ReportDlg: TReportDlg;
WaitReportCreateDlg: TWaitReportCreateDlg;
procedure InitInputParamDlg; override;
procedure InitParameters; override;
procedure DeleteElement; virtual;
function EditElementParams: integer; virtual;
procedure ClearData; virtual;
procedure SaveToFile(Stream: TStream);override;
procedure SaveToIniFile(iniF: TIniFile; Section: string);override;
procedure LoadFromFile(Stream: TStream); override;
procedure LoadFromIniFile(IniF: TIniFile; Section: string); override;
procedure EditorOnHide(Sender: TObject); virtual;
procedure ListBox1Click(Sender: TObject); virtual;
procedure ListBox1DblClick(Sender: TObject); virtual;
procedure SpeedButton1Click(Sender: TObject); virtual;
procedure SpeedButton2Click(Sender: TObject); virtual;
procedure OnChangeModelName(Sender: TObject); virtual;
procedure OnClickOkButtonOnParamDlg(Sender: TObject); virtual;
procedure OnClickOkButtonOnEditorDlg(Sender: TObject); virtual;
procedure OnClickToolButton(Sender: TObject); virtual;
procedure CheckState;
function ElementPos(elType: boolean; var elPos: integer):integer; virtual;
function CheckModel: boolean;
procedure Calculate(Sender: TObject); virtual;
procedure ShowGraphs(Sender: TObject); virtual;
procedure HideGraphs(Sender: TObject); virtual;
procedure ModelInformation(Sender: TObject); virtual;
function GetModelInformation:string; virtual;
function MakeReportDlg(where: integer): integer;
function CreateReport(FName: string): boolean;
procedure OnClickSeriesCheckBox(Sender: TObject); virtual;
procedure OnClickSaveButtonOnReportDlg(Sender: TObject); virtual;
procedure WaitReportCreateDlgOnShow(Sender: TObject); virtual;
private
TempFName: string;
end;
var
Model : TModel;
implementation
uses SysUtils, Dialogs, Controls, Comctrls, clipbrd, Chart, TeEngine, Series,
Imglist,
main, massa, relation;
constructor TModel.Create;
var
i: integer;
ResType: TResType;
flType: boolean;
s: shortstring;
begin
inherited Create;
Count.Masses:=0;
Count.Relations:=0;
flIsSaved:=true;
VisualDlg:=TVisualDlg.CreateParented(0);
VisualDlg.Timer1.OnTimer:=Calculate;
VisualDlg.ToolButton3.OnClick:=ShowGraphs;
VisualDlg.ToolButton4.OnClick:=ModelInformation;
VisualDlg.OnHide:=HideGraphs;
with Editor do
begin
OnHide:=EditorOnHide;
ListBox1.OnClick:=ListBox1Click;
ListBox1.OnDblClick:=ListBox1DblClick;
SpeedButton1.OnClick:=SpeedButton1Click;
SpeedButton2.OnClick:=SpeedButton2Click;
Edit1.OnChange:=OnChangeModelName;
if ClassList.Count>0 then
for i:=0 to ClassList.Count-1 do begin
if StrUpper(PChar(ExtractFileExt(TToolButton(ClassList.Items[i]).Caption)))='.BMP'
then ResType:=rtBitmap
else ResType:=rtIcon;
if not ImageList1.FileLoad(ResType, TToolButton(ClassList.Items[i]).Caption, clBtnFace)
then ImageList1.Add(nil,nil);
TToolButton(ClassList.Items[i]).ImageIndex:=i;
TToolButton(ClassList.Items[i]).OnClick:=OnClickToolButton;
flType:=TToolButton(ClassList.Items[i]).Wrap;
TToolButton(ClassList.Items[i]).Wrap:=false;
if flType then
ToolBar1.InsertControl(TToolButton(ClassList.Items[i]))
else
ToolBar2.InsertControl(TToolButton(ClassList.Items[i]));
end;
ToolBar2.Enabled:=false;
end;
WaitReportCreateDlg:=TWaitReportCreateDlg.CreateParented(0);
WaitReportCreateDlg.OnActivate:=WaitReportCreateDlgOnShow;
NewElement:=nil;
flReadFromFile:=false;
flIsModelling:=false;
i:=GetEnvironmentVariable('TEMP',@s[1],255);
SetLength(s,i);
TempFName:=s+'\$$$_mdl_$$$.';
end;
destructor TModel.Destroy;
begin
inherited Destroy;
ClearData;
Editor.Destroy;
VisualDlg.Destroy;
ClassList.Destroy;
WaitReportCreateDlg.Destroy;
end;
procedure TModel.InitInputParamDlg;
begin
TInputDlg(InputParamDlg):=TInputDlg.CreateParented(0);
TInputDlg(InputParamDlg).OKBtn.OnClick:=OnClickOkButtonOnParamDlg;
TInputDlg(InputParamDlg).OnHide:=OnHideParamDlg;
Editor:=TEditDlg.CreateParented(0);
Editor.OKBtn.OnClick:=OnClickOkButtonOnEditorDlg;
end;
procedure TModel.InitParameters;
begin
t:=10;
Params.Add(TParam.Create(@t, varDouble, 'T', 0.001, 1e20, TInputDlg(InputParamDlg).Edit1)); //t
ht:=0.01;
Params.Add(TParam.Create(@ht, varDouble, 'Ht', 1e-10, 10, TInputDlg(InputParamDlg).Edit2)); //ht
e:=1;
Params.Add(TParam.Create(@e, varDouble, 'E', 0.00001, 1, TInputDlg(InputParamDlg).Edit3)); //e
CalcMethod.code:=0;
Params.Add(TParam.Create(@CalcMethod.code, varDouble,'Method', 0, 3, nil)); //CalcMethod
ObjName:='Колебательная система';
Params.Add(TParam.Create(@ObjName, varString, 'Description', '', '', Editor.Edit1)); //string description
end;
procedure TModel.OnClickOkButtonOnEditorDlg(Sender: TObject);
begin
Model.GetParams;
end;
procedure TModel.OnClickOkButtonOnParamDlg(Sender: TObject);
begin
inherited OnClickOkButtonOnParamDlg(Sender);
if Editor.ListBox1.Items.Count > 0 then flIsSaved:=false;
CalcMethod.code:=TInputDlg(InputParamDlg).RadioGroup1.ItemIndex;
end;
procedure TModel.ClearData;
var i: integer;
begin
if Editor.ListBox1.Items.Count > 0 then
for i:=0 to Editor.ListBox1.Items.Count-1 do
TAbstractElement(Editor.ListBox1.Items.Objects[i]).Destroy;
flIsSaved:=true;
Count.Masses:=0;
Count.Relations:=0;
with Editor do ListBox1.Clear;
flIsModelling:=false;
end;
function TModel.ShowDialog(wind: integer) :integer;
begin
case wind of
0: Result:=Editor.ShowModal;
1: Result:=InputParamDlg.ShowModal;
2: Result:=MakeReportDlg(1);
end;
end;
procedure TModel.EditorOnHide(Sender: TObject);
begin
if not flIssaved then
flIsSaved:= (Editor.ListBox1.Items.Count=0);
end;
procedure TModel.OnChangeModelName(Sender: TObject);
begin
flIsSaved:= false;
end;
procedure TModel.ListBox1Click(Sender: TObject);
begin
with Editor do
begin
Memo1.Lines.Clear;
Memo1.Lines.Append(TAbstractElement(ListBox1.Items.Objects[ListBox1.ItemIndex]).AboutStr);
end;
end;
procedure TModel.ListBox1DblClick(Sender: TObject);
begin
SpeedButton2Click(Sender);
end;
procedure TModel.SpeedButton1Click(Sender: TObject);
var
index: integer;
s:string;
begin
with Editor do
if ListBox1.ItemIndex>=0 then
begin
if MessageDlg('Удалить элемент'#10+ListBox1.Items.Strings[ListBox1.ItemIndex],
mtConfirmation, [mbYes, mbNo], 0) <> mrYes then exit;
index:=ListBox1.ItemIndex;
s:=ListBox1.Items.Strings[index];
DeleteElement;
ListBox1.Items.Delete(ListBox1.ItemIndex);
Memo1.Lines.Clear;
CheckState;
end
else ListBox1.SetFocus;
end;
procedure TModel.SpeedButton2Click(Sender: TObject);
begin
with Editor do
if ListBox1.ItemIndex>=0 then begin
if EditElementParams =1 then begin
ListBox1Click(Sender);
flIsSaved:=false;
end;
end
else ListBox1.SetFocus;
end;
procedure TModel.OnClickToolButton(Sender: TObject);
begin
try
NewElement:=TNewObject(TToolButton(Sender).Tag);
if not flReadFromFile then AddElement;
except raise ERangeError.Create('Критическая ошибка. Недостаточно памяти');
end;
end;
procedure TModel.CheckState;
begin
with Editor do begin
ToolBar2.Enabled:= Count.Masses>1;
SpeedButton1.Enabled:= ListBox1.Items.Count <>0;
SpeedButton2.Enabled:= SpeedButton1.Enabled;
end;
end;
function TModel.ElementPos(elType: boolean; var elPos: integer):integer;
var
i,n1,n2: integer;
begin
elPos:=0;
Result:=1;
if Editor.ListBox1.Items.Count=0 then exit;
n1:=0;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType = elType then
begin
n2:=StrToInt(Copy(Editor.ListBox1.Items.Strings[i],Pos(' ',Editor.ListBox1.Items.Strings[i]),
length(Editor.ListBox1.Items.Strings[i])));
if (n2-n1)>1 then
begin
break;
end
else n1:=n2;
end;
elPos:=i;
Result:=n1+1;
end;
procedure TModel.AddElement;
var
ps,i: integer;
begin
i:=ElementPos(TAbstractElement(NewElement).flType,ps);
if TAbstractElement(NewElement).flType then
TAbstractElement(NewElement).InputParamDlg.Caption:='Масса '+IntToStr(i)
else
TAbstractElement(NewElement).InputParamDlg.Caption:='Связь '+IntToStr(i);
if (TAbstractElement(NewElement).InputParamDlg.ShowModal=mrOk) then begin
TAbstractElement(NewElement).ObjName:=TAbstractElement(NewElement).InputParamDlg.Caption;
TAbstractElement(NewElement).GraphDlg.Caption:=TAbstractElement(NewElement).ObjName;
Editor.ListBox1.Items.InsertObject(ps,TAbstractElement(NewElement).ObjName, NewElement);
if TAbstractElement(NewElement).flType then inc(Count.Masses)
else inc(Count.Relations);
NewElement:=nil;
flIsSaved:=false;
CheckState;
end
else TAbstractElement(NewElement).Destroy;
end;
function TModel.EditElementParams: integer;
begin
with Editor do
Result:=TAbstractElement(ListBox1.Items.Objects[ListBox1.ItemIndex]).InputParamDlg.ShowModal;
end;
procedure TModel.DeleteElement;
var
num, code, i, index: integer;
flag: boolean;
s: string;
begin
with Editor do
begin
index:=ListBox1.ItemIndex;
s:=ListBox1.Items.Strings[index];
end;
val(Copy(s,Pos(' ', s)+1, length(s)), num, code);
flag:=TAbstractElement(Editor.ListBox1.Items.Objects[Editor.ListBox1.ItemIndex]).flType;
if flag then begin
for i:=0 to Editor.ListBox1.Items.Count-1 do
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
if (TAbstractRelation(Editor.ListBox1.Items.Objects[i]).m1=num) or
(TAbstractRelation(Editor.ListBox1.Items.Objects[i]).m2=num) then begin
MessageDlg(TAbstractRelation(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+
' была присоединена к удаляемой массе.'#10'Откорректируйте параметры элемента '+
TAbstractRelation(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption,
mtWarning, [mbOk], 0);
TAbstractRelation(Editor.ListBox1.Items.Objects[i]).InputParamDlg.ShowModal;
end;
dec(Count.Masses);
end
else dec(Count.Relations);
TAbstractElement(Editor.ListBox1.Items.Objects[Editor.ListBox1.ItemIndex]).Destroy;
flIsSaved:=false;
end;
procedure TModel.SaveToIniFile(iniF: TIniFile; Section: string);
var i: integer;
begin
inherited SaveToIniFile(iniF,Section);
try
for i:=0 to Editor.ListBox1.Items.Count-1 do
TAbstractElement(Editor.ListBox1.Items.Objects[i]).SaveToIniFile(iniF, IntToStr(i));
except
raise ERangeError.Create('Ошибка записи');
end;
end;
procedure TModel.SaveToFile(Stream: TStream);
var i: integer;
begin
inherited SaveToFile(Stream);
try
for i:=0 to Editor.ListBox1.Items.Count-1 do
TAbstractElement(Editor.ListBox1.Items.Objects[i]).SaveToFile(Stream);
except
raise ERangeError.Create('Ошибка записи');
end;
end;
procedure TModel.SaveModel(FileName: string);
var
Stream: TStream;
IniF: TIniFile;
Ext: string;
begin
Ext:=UpperCase(ExtractFileExt(FileName));
if Ext='.MDL' then
begin
try
Stream:= TFileStream.Create(FileName, fmCreate);
SaveToFile(Stream);
finally
Stream.Free;
end;
end
else begin
try
IniF:=TIniFile.Create(FileName);
SaveToIniFile(IniF,'Model');
finally
IniF.Free;
end;
end;
end;
procedure TModel.LoadFromIniFile(IniF: TIniFile; Section: string);
var
i: integer;
InstControl: TControl;
InstComponentName: string;
begin
inherited LoadFromIniFile(IniF, Section);
i:=0;
while IniF.SectionExists(IntToStr(i)) do
begin
Section:=IntToStr(i);
InstComponentName:=IniF.ReadString(Section,'Class','');
InstControl:=Editor.FindControl(InstComponentName);
if InstControl<>nil then
begin
TToolButton(InstControl).OnClick(InstControl);
TAbstractElement(NewElement).LoadFromIniFile(IniF, Section);
Editor.ListBox1.Items.AddObject(TAbstractElement(NewElement).ObjName, NewElement);
TAbstractElement(NewElement).InputParamDlg.Caption:=TAbstractElement(NewElement).ObjName;
TAbstractElement(NewElement).GraphDlg.Caption:=TAbstractElement(NewElement).ObjName;
if TAbstractElement(NewElement).flType then inc(Count.Masses)
else inc(Count.Relations);
end
else MessageDlg('Неизвестный компонент "'+InstComponentName+'"', mtError, [mbOk], 0 );
CheckState;
inc(i);
end;
end;
procedure TModel.LoadFromFile(Stream: TStream);
var
InstControl: TControl;
InstComponentName: string;
begin
try
InstComponentName:=LoadStrFromStream(Stream);
if InstComponentName<>InstName then
begin
MessageDlg('Файл не содержит необходимых данных', mtError, [mbOk], 0 );
exit;
end;
inherited LoadFromFile(Stream);
while Stream.Position < Stream.Size do
begin
InstComponentName:=LoadStrFromStream(Stream);
InstControl:=Editor.FindControl(InstComponentName);
if InstControl<>nil then
begin
TToolButton(InstControl).OnClick(InstControl);
TAbstractElement(NewElement).LoadFromFile(Stream);
Editor.ListBox1.Items.AddObject(TAbstractElement(NewElement).ObjName, NewElement);
TAbstractElement(NewElement).InputParamDlg.Caption:=TAbstractElement(NewElement).ObjName;
TAbstractElement(NewElement).GraphDlg.Caption:=TAbstractElement(NewElement).ObjName;
if TAbstractElement(NewElement).flType then inc(Count.Masses)
else inc(Count.Relations);
end
else begin
MessageDlg('Неизвестный компонент "'+InstComponentName+'"', mtError, [mbOk], 0 );
exit;
end;
end;
CheckState;
except
raise ERangeError.Create('Ошибка чтения');
end;
end;
function TModel.LoadModel(FileName: string):boolean;
var
i: integer;
Stream: TStream;
Ext: string;
IniF: TIniFile;
begin
Result:=false;
Ext:=UpperCase(ExtractFileExt(FileName));
if Ext='.MDL' then
try
Stream := TFileStream.Create(fileName, fmOpenRead);
ClearData;
flReadFromFile:=true;
LoadFromFile(Stream);
finally
Stream.Free;
Editor.Memo1.Lines.Clear;
TInputDlg(InputParamDlg).RadioGroup1.ItemIndex:=Round(CalcMethod.code);
flReadFromFile:=false;
flIsSaved:=true;
Result:=true;
{//Warning! Add new parameters !
for i:=0 to Editor.ListBox1.Items.Count-1 do
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractElement(Editor.ListBox1.Items.Objects[i]).AddParam;
flIsSaved:=false;
}
end
else
try
IniF:=TIniFile.Create(FileName);
ClearData;
flReadFromFile:=true;
LoadFromIniFile(IniF,'Model');
finally
IniF.Free;
Editor.Memo1.Lines.Clear;
TInputDlg(InputParamDlg).RadioGroup1.ItemIndex:=Round(CalcMethod.code);
flReadFromFile:=false;
flIsSaved:=true;
Result:=true;
end;
end;
function TModel.CheckModel: boolean;
var i: integer;
begin
Result:=true;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractRelation(Editor.ListBox1.Items.Objects[i]).SetPointers(Editor.ListBox1.Items);
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
if not TAbstractMassa(Editor.ListBox1.Items.Objects[i]).flIsRelated then
begin
Result:=false;
MessageDlg(TAbstractMassa(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+' не связана',
mtError, [mbOk], 0);
exit;
end;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
if TAbstractRelation(Editor.ListBox1.Items.Objects[i]).CheckPointers then
begin
Result:=false;
MessageDlg(TAbstractRelation(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+
' не объединяет 2 массы', mtError, [mbOk], 0);
exit;
end;
end;
procedure TModel.SetParamsInZero;
var i: integer;
begin
for i:=0 to Editor.ListBox1.Items.Count-1 do
TAbstractElement(Editor.ListBox1.Items.Objects[i]).SetParamsInZero;
with VisualDlg do begin
Time:=0;
CountSteps:=0;
Caption:=Editor.Edit1.Text;
RealModelTime:=0;
StartT:=0;
end;
case Round(CalcMethod.code) of
0: CalcMethod.digree:=4;
1: CalcMethod.digree:=2;
2: CalcMethod.digree:=1;
end;//case
end;
procedure TModel.Visio;
var i,j: integer;
begin
SetParamsInZero;
if not CheckModel then exit;
with VisualDlg do begin
TopMargin:= 32000 div 2;
MaxX:=-1e20;
MaxY:=-1e20;
MinX:=1e20;
MinY:=1e20;
for i:=0 to Editor.ListBox1.Items.Count-1 do
begin
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecLeft<MinX then MinX:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecLeft;
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecRight>MaxX then MaxX:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecRight;
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecTop<MinY then MinY:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecTop;
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecBottom>MaxY then MaxY:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).RecBottom;
end;
try
ScaleX:= ScrollBox1.ClientWidth*0.8 / abs(MaxX-MinX);
ScaleY:=ScrollBox1.ClientHeight*0.95 / abs(MaxY-MinY);
except
raise ERangeError.Create('Деление на ноль'#10'Некорректные геометрические параметры модели');
exit;
end;
LeftMargin:=(ScrollBox1.ClientWidth - Round((MaxX-MinX)*ScaleX)) div 2 ;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractElement(Editor.ListBox1.Items.Objects[i]).SetImageSize(MinX, MinY, ScaleX, ScaleY, TopMargin, LeftMargin);
for i:=0 to Editor.ListBox1.Items.Count-1 do
begin
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractElement(Editor.ListBox1.Items.Objects[i]).SetImageSize(MinX, MinY, ScaleX, ScaleY, TopMargin, LeftMargin);
ScrollBox1.InsertControl(TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image);
end;
//Sort relation by order
Editor.SortRelationListBox.Clear;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
Editor.SortRelationListBox.Items.AddObject(Editor.ListBox1.Items.Strings[i],
Editor.ListBox1.Items.Objects[i]);
for i:=0 to Editor.SortRelationListBox.Items.Count-2 do
for j:=i+1 to Editor.SortRelationListBox.Items.Count-1 do
if TAbstractRelation(Editor.SortRelationListBox.Items.Objects[i]).Order>
TAbstractRelation(Editor.SortRelationListBox.Items.Objects[j]).Order
then Editor.SortRelationListBox.Items.Exchange(i,j);
//Set range image
RangeImage:= TImage.Create(ScrollBox1);
RangeImage.Left:=LeftMargin;
RangeImage.Top:=TopMargin *2;
RangeImage.Height:=1;
RangeImage.Width:=1;
ScrollBox1.InsertControl(RangeImage);
ScrollBox1.VertScrollBar.Position:=TopMargin;
VisualDlg.StatusBar1.SimpleText:=Format(' Итерация %d Время %-10.4f ( %d%% ) Текущий шаг %-10.4f',
[VisualDlg.CountSteps, VisualDlg.time, Round(100*VisualDlg.time/t), VisualDlg.StepT] );
ShowModal;
flIsModelling:=true;
for i:=0 to Editor.ListBox1.Items.Count-1 do
ScrollBox1.RemoveControl(TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image);
ScrollBox1.RemoveControl(RangeImage);
RangeImage.Destroy;
end;
Editor.SortRelationListBox.Clear;
for i:=0 to Editor.ListBox1.Items.Count-1 do
TAbstractElement(Editor.ListBox1.Items.Objects[i]).GetParams; //restore parameters
end;
procedure TModel.Calculate(Sender: TObject);
var
i, j, code: integer;
h: TFloat;
begin
if VisualDlg.Time < t then
begin
VisualDlg.Timer1.Enabled:=false;
inc(VisualDlg.CountSteps);
code:=Round(CalcMethod.code);
for j:=1 to CalcMethod.digree do
begin
for i:=0 to Editor.SortRelationListBox.Items.Count-1 do
begin
TAbstractRelation(Editor.SortRelationListBox.Items.Objects[i]).CalcForce([VisualDlg.Time, j]);
if j=1 then TAbstractRelation(Editor.SortRelationListBox.Items.Objects[i]).AddValueToChart(VisualDlg.Time);
end;
{
for i:=0 to Editor.ListBox1.Items.Count-1 do
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractRelation(Editor.ListBox1.Items.Objects[i]).CalcForce([VisualDlg.Time]);
}
if j = 1 then begin //calculate min step
VisualDlg.StepT:=ht;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
begin
h:=TAbstractMassa(Editor.ListBox1.Items.Objects[i]).CalcStep(e, ht);
if h < VisualDlg.StepT then VisualDlg.StepT:=h;
if VisualDlg.Time = 0 then
TAbstractMassa(Editor.ListBox1.Items.Objects[i]).AddValueToChart(VisualDlg.Time);
end;
VisualDlg.Time:=VisualDlg.Time + VisualDlg.StepT;
end;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractMassa(Editor.ListBox1.Items.Objects[i]).Calculate(VisualDlg.StepT, VisualDlg.Time, Code, j);
end; //for j
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
with VisualDlg do
TAbstractElement(Editor.ListBox1.Items.Objects[i]).MoveImage(MinX, MinY, ScaleX, ScaleY, TopMargin, LeftMargin);
for i:=0 to Editor.ListBox1.Items.Count-1 do
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
with VisualDlg do
TAbstractElement(Editor.ListBox1.Items.Objects[i]).MoveImage(MinX, MinY, ScaleX, ScaleY, TopMargin, LeftMargin);
VisualDlg.StatusBar1.SimpleText:=Format(' Итерация %d Время %-10.4f ( %d%% ) Текущий шаг %-8.6f',
[VisualDlg.CountSteps, VisualDlg.Time, Round(100*VisualDlg.time/t), VisualDlg.StepT] );
VisualDlg.Timer1.Enabled:=true;
end
else begin
VisualDlg.ToolButton1Click(Sender);
VisualDlg.ToolButton1.Enabled:=false;
MessageDlg('Расчет окончен'#10+'Время моделирования '+TimeToStr(VisualDlg.RealModelTime)+
#10+format('Средний шаг интегрирования %-7.6f',[VisualDlg.Time/VisualDlg.CountSteps]),
mtInformation, [mbOk], 0);
end;
end;
procedure TModel.ShowGraphs;
var i: integer;
begin
{
for i:=0 to Editor.ListBox1.Items.Count-1 do
TAbstractMassa(Editor.ListBox1.Items.Objects[i]).ShowGraphs;
}
MakeReportDlg(1);
end;
procedure TModel.HideGraphs;
var i: integer;
begin
VisualDlg.Timer1.Enabled:=false;
for i:=0 to Editor.ListBox1.Items.Count-1 do
TAbstractMassa(Editor.ListBox1.Items.Objects[i]).HideGraphs;
end;
procedure TModel.ShowReport(FName: string);
var
FN: array[0..255] of Char;
begin
ShellExecute(Editor.Handle, nil,
StrPCopy(FN, FName), nil, nil, Sw_Show);
end;
procedure TModel.MakeReport(FName: string);
begin
WaitReportCreateDlg.Hint:=FName;
WaitReportCreateDlg.ShowModal;
end;
procedure TModel.WaitReportCreateDlgOnShow(Sender: TObject);
begin
with TWaitReportCreateDlg(Sender) do
begin
StaticText1.Font.Color:=clBlue;
StaticText1.Caption:='Создаётся отчёт...';
WaitReportCreateDlg.Refresh;
Animate1.Active:=true;
Animate1.CommonAVI:=aviCopyFile;
if CreateReport(WaitReportCreateDlg.Hint) then
begin
StaticText1.Caption:='Отчёт создан';
ModalResult:=mrOk;
end
else
begin
StaticText1.Font.Color:=clRed;
StaticText1.Caption:='Ошибка создания документа WinWord';
ModalResult:=mrCancel;
end;
Animate1.Active:=false;
end;
end;
function TModel.CreateReport(FName: string): boolean;
var
qi: TQRImage;
i: integer;
ScaleX, ScaleY: TFloat;
TopMargin, LeftMargin: integer;
m: TMetafile;
Report: TQuickRep;
begin
//Result:=true;
WDoc := CreateOleObject('Word.Basic');
Result:= VarType(WDoc) = VarDispatch;
if Result then
try
WDoc.FileNew('Normal');
WDoc.FilePageSetup(PaperSize:='9', TopMargin:='2 см', BottomMargin:='2 см',
LeftMargin:='2 см', RightMargin:='2 см', PageWidth:='21 см',
PageHeight:='29,7 см', Orientation:=0);
WDoc.FormatFont(Points:=14, Font:='Times New Roman Cyr',Bold:=1);
WDoc.FormatParagraph(After:='12 пт',LineSpacingRule:=1,Alignment:=1);
WDoc.Insert('Результаты моделирования'+ #13);
WDoc.FormatFont(Points:=14, Font:='Times New Roman Cyr',Bold:=0);
WDoc.FormatParagraph(Alignment:=1);
WDoc.Insert('Модель: '+Editor.Edit1.Text+#13);
Report:= TQuickRep.CreateParented(0);
Report.Units:=pixels;//TQRUNIT(2);
TopMargin:=0;
ScaleX:= Report.Page.Width / abs(VisualDlg.MaxX-VisualDlg.MinX);
ScaleY:= Report.Page.Length / abs(VisualDlg.MaxY-VisualDlg.MinY);
LeftMargin:=Round(Report.Page.Width - (VisualDlg.MaxX-VisualDlg.MinX)*ScaleX) div 2 ;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractElement(Editor.ListBox1.Items.Objects[i]).SetImageSize(VisualDlg.MinX,
VisualDlg.MinY, ScaleX, ScaleY, TopMargin, LeftMargin);
for i:=0 to Editor.ListBox1.Items.Count-1 do
begin
if not TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
TAbstractElement(Editor.ListBox1.Items.Objects[i]).SetImageSize(VisualDlg.MinX,
VisualDlg.MinY, ScaleX, ScaleY, TopMargin, LeftMargin);
qi:= TQRImage.Create(Report);
qi.AutoSize:=false;
qi.Center:=true;
qi.Stretch:=true;
qi.Name:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image.Name;
qi.Left:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image.Left;
qi.Top:= TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image.Top;
qi.Height:= TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image.Height;
qi.Width:= TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image.Width;
qi.Picture:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image.Picture;
Report.InsertControl(qi);
qi:=nil;
end; //for
Report.Prepare;
m:=Report.QRPrinter.GetPage(Report.QRPrinter.PageNumber);
if m<>nil then begin
m.SaveToFile(TempFName+'wmf');
WDoc.InsertPicture(Name:=TempFName+'wmf',LinkToFile:='0');
{
clipboard.Assign(m);
WDoc.EditPaste;
}
end
else
Result:=false;
Report.Destroy;
WDoc.InsertPara;
for i:=0 to Editor.ListBox1.Items.Count-1 do
begin
WDoc.FormatFont(Points:=14);
WDoc.FormatParagraph(After:='0 пт',Alignment:=3);
WDoc.Insert(IntToStr(i+1)+' - '+TAbstractElement(Editor.ListBox1.Items.Objects[i]).AboutStr+#13);
end;
MakeReportDlg(0);
WaitReportCreateDlg.Refresh;
WDoc.FileSaveAs(ChangeFileExt(FName, '.doc'));
WDoc.FileClose;
except
Result:=false;
end;
WDoc:= UnAssigned;
end;
procedure TModel.OnClickSeriesCheckBox(Sender: TObject);
begin
ReportDlg.Chart1.Series[TCheckBox(Sender).Tag].Active:=TCheckBox(Sender).Checked;
//ReportDlg.Chart1.Series[TCheckBox(Sender).Tag].ShowInLegend:=TCheckBox(Sender).Checked;
end;
procedure TModel.OnClickSaveButtonOnReportDlg(Sender: TObject);
var
i: integer;
begin
try
if ReportDlg.Tag = 0 then
begin
WDoc.Insert(#13);
ReportDlg.Chart1.SaveToMetafile(TempFName+'wmf');
WDoc.InsertPicture(Name:=TempFName+'wmf',LinkToFile:='0');
WDoc.Insert(#13);
for i:=0 to ReportDlg.Chart1.SeriesCount-1 do
if ReportDlg.Chart1.Series[i].Active then
begin
WDoc.Insert(ReportDlg.Chart1.Series[i].Title+#13);
end;
end
else
ReportDlg.Chart1.CopyToClipboardMetafile(true);
except
MessageDlg('Сбой при создания отчета', mtError, [mbOk], 0 );
end;
end;
function TModel.GetModelInformation:string;
var
i: integer;
Mas, C: TFloat;
begin
Mas:=0;
C:=0;
for i:=0 to Editor.ListBox1.Items.Count-1 do
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
Mas:=Mas+TAbstractMassa(Editor.ListBox1.Items.Objects[i]).GetMassa
else
if TAbstractRelation(Editor.ListBox1.Items.Objects[i]).c<>0
then
C:=C+1/TAbstractRelation(Editor.ListBox1.Items.Objects[i]).c;
Result:=format('Масса колебательной системы = %-10.3f'#13+
'Жесткость системы %-10.3f',[Mas,1/C]);
end;
procedure TModel.ModelInformation(Sender: TObject);
begin
MessageDlg(GetModelInformation,
mtInformation, [mbOK], 0) ;
end;
function TModel.MakeReportDlg;
var
j,n,i,k: integer;
chart: TChart;
ser: TChartSeries;
st,bst: TStaticText;
ch: TCheckBox;
ss: string;
begin
ReportDlg:= TReportDlg.CreateParented(0);
ReportDlg.SaveBtn.OnClick:=OnClickSaveButtonOnReportDlg;
ReportDlg.Tag:=Where;
j:=0;
n:=-1;
for i:=0 to Editor.ListBox1.Items.Count-1 do
//if TAbstractElement(Editor.ListBox1.Items.Objects[i]).flType then
if TAbstractElement(Editor.ListBox1.Items.Objects[i]).GraphFlag then
begin
st := TStaticText.CreateParented(0);
st.Left:=3;
st.AutoSize:= true;
st.Top:=17*j+2;
st.Caption:=Editor.ListBox1.Items.Strings[i];
st.ShowHint:=true;
st.Hint:=TAbstractElement(Editor.ListBox1.Items.Objects[i]).Image.Hint;
ReportDlg.ScrollBox1.InsertControl(st);
chart:=TAbstractMassa(Editor.ListBox1.Items.Objects[i]).GraphChart;
if chart<>nil then
for k:=1 to chart.SeriesCount do
begin
inc(n);
ch:= TCheckBox.CreateParented(0);
ch.Width:=17;
ch.Checked:=false;
ch.Top:=st.Top;
ch.Tag:=n;
ch.OnClick:=OnClickSeriesCheckBox;
ch.ShowHint:=true;
ch.Hint:=chart.Series[k-1].Title;
if chart.SeriesCount>1 then ch.Left:=64+24*k
else ch.Left:=64+24*3;
ReportDlg.ScrollBox1.InsertControl(ch);
ss:=ColorToString(ReportDlg.Chart1.GetFreeSeriesColor(true));
ser:=TLineSeries.Create(ReportDlg.Chart1);
ser.Active:=false;
ser.ShowInLegend:=false;
ser.Title:=chart.Series[k-1].Title+' ('+TAbstractElement(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+')';
{
case k of
1: if chart.SeriesCount>1 then ser.Title:='перемещение ('+TAbstractMassa(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+')'
else ser.Title:='сила ('+TAbstractElement(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+')';
2: ser.Title:='скорость ('+TAbstractElement(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+')';
3: ser.Title:='сила ('+TAbstractElement(Editor.ListBox1.Items.Objects[i]).InputParamDlg.Caption+')';
end; //case
}
ser.Title:=ser.Title+' (цвет - '+Copy(ss,3,length(ss)-2)+' )';
ser.AssignValues(chart.Series[k-1]);
ReportDlg.Chart1.AddSeries(Ser);
ch:=nil;
end;
st:=nil;
inc(j);
end;
Result:=ReportDlg.ShowModal;
ReportDlg.Destroy;
end;
end
Подобные документы
Исследование свойств и поведения динамических объектов, описываемых системами обыкновенных нелинейных дифференциальных уравнений. Описание методов, программ и алгоритмов решения систем линейных и нелинейных алгебраических уравнений в системе MathCAD.
контрольная работа [255,1 K], добавлен 16.01.2009Исследование полных динамических характеристик систем Simulink. Параметрическая идентификация в классе APCC-моделей. Идентификация характеристик пьезокерамических датчиков с использованием обратного эффекта. Синтез систем автоматического управления.
курсовая работа [2,7 M], добавлен 14.06.2019Численные методы решения нелинейных уравнений, систем линейных и нелинейных алгебраических уравнений, дифференциальных уравнений, определенных интегралов. Методы аппроксимации дискретных функций и методы решения задач линейного программирования.
методичка [185,7 K], добавлен 18.12.2014Опытное исследование свойств методов Рунге-Кутты. Реализация численных методов приближенного интегрирования обыкновенных дифференциальных уравнений, наиболее часто применяющихся в практике моделирования и проектирования систем автоматизации и управления.
курсовая работа [311,5 K], добавлен 05.03.2009Практические навыки моделирования законов движения многосвязных механических систем на примере трехзвенного манипулятора. Основные этапы моделирования: исходная система; формирование исходных данных, геометрической, динамической и математической модели.
презентация [535,0 K], добавлен 25.06.2013Имитационное моделирование как один из наиболее широко используемых методов при решении задач анализа и синтеза сложных систем. Особенности имитационного моделирования систем массового обслуживания. Анализ структурной схемы системы передачи пакетов.
курсовая работа [1,2 M], добавлен 28.05.2013Назначение и основные особенности программного комплекса Euler 6.0. Практические навыки моделирования законов движения многокомпонентных механических систем на примере трехзвенного манипулятора. Этапы моделирования, формирование динамической модели.
методичка [1,3 M], добавлен 25.06.2013Изучение численных методов решения нелинейных уравнений. Построение годографа АФЧХ, графиков АЧХ и ФЧХ с указанием частот. Практическое изучение численных методов интегрирования дифференциальных уравнений высокого порядка, метод Рунге-Кутта 5-го порядка.
курсовая работа [398,3 K], добавлен 16.06.2009Изучение современных принципов, подходов и методов моделирования сложно формализуемых объектов. Решение задач структурной и параметрической идентификации. Характеристики вычислительных систем как сложных систем массового обслуживания. Теория потоков.
курс лекций [2,3 M], добавлен 18.02.2012Создание функциональной структуры фирмы. Методологии проектирования информационных систем. Состав стандарта IDEF. Средства структурного системного анализа. Метод функционального моделирования SADT. Стратегии декомпозиции. Диаграмма потоков данных DFD.
презентация [324,1 K], добавлен 27.12.2013