-
Notifications
You must be signed in to change notification settings - Fork 0
/
UModel.pas
executable file
·571 lines (501 loc) · 15.4 KB
/
UModel.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
unit UModel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, ExtCtrls, StdCtrls, ImgList, ActnList, tc;
type
TFModel = class(TForm)
Panel1: TPanel;
Splitter1: TSplitter;
Panel2: TPanel;
ToolBar1: TToolBar;
Panel3: TPanel;
Panel4: TPanel;
Label1: TLabel;
Label2: TLabel;
TreeView1: TTreeView;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ModelParamsActions: TActionList;
AAddElement: TAction;
ADeleteElement: TAction;
AApply: TAction;
AllImages: TImageList;
OpenD: TOpenDialog;
SaveD: TSaveDialog;
ASave: TAction;
ALoad: TAction;
Status: TStatusBar;
TreeImages: TImageList;
ToolButton8: TToolButton;
APrint: TAction;
ToolButton9: TToolButton;
NoObjectLabel: TLabel;
AClear: TAction;
ToolButton10: TToolButton;
procedure AApplyExecute(Sender: TObject);
procedure ALoadExecute(Sender: TObject);
procedure ASaveExecute(Sender: TObject);
procedure TreeView1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure AAddElementExecute(Sender: TObject);
procedure TreeView1Editing(Sender: TObject; Node: TTreeNode;
var AllowEdit: Boolean);
procedure ADeleteElementExecute(Sender: TObject);
procedure TreeView1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
procedure TreeView1Changing(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
procedure FormActivate(Sender: TObject);
procedure TreeView1Expanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
procedure APrintExecute(Sender: TObject);
procedure AClearExecute(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
Model : TModel;
ModelCopy : TModel;
ModelName : string;
Modified : boolean;
procedure InitTreeView;
procedure SaveToModel;
procedure LoadFromModel;
procedure Ref;
end;
var
FModel: TFModel;
implementation
uses UAllTime, UBunker, UMaterial, ULine, UModelReport;
{$R *.DFM}
procedure TFModel.AApplyExecute(Sender: TObject);
begin
SaveToModel;
ModalResult := mrOK;
end;
procedure TFModel.ALoadExecute(Sender: TObject);
begin
if not OpenD.Execute then exit;
if visible then TreeView1.FullCollapse;
if visible then TreeView1Change(TreeView1,TreeView1.Selected);
Model.LoadFromFile (OPenD.FileName);
Modified := false;
if visible then LoadFromModel;
ModelName := ExtractFileName(OpenD.FileName);
MessageDlg(LoadSuccesfully, mtInformation, [mbOk], 0);
end;
procedure TFModel.ASaveExecute(Sender: TObject);
begin
if not SaveD.Execute then exit;
SaveToModel;
TreeView1.FullCollapse;
Model.SaveToFile (SaveD.FileName);
Modified := false;
ModelName := ExtractFileName(SaveD.FileName);
MessageDlg(SaveSuccesfully, mtInformation, [mbOk], 0);
end;
procedure TFModel.TreeView1Click(Sender: TObject);
begin
TreeView1Change(Sender, TreeView1.Selected);
end;
procedure TFModel.FormCreate(Sender: TObject);
begin
InitTreeView;
Model := TModel.Create;
ModelCopy := TModel.Create;
ModelName := NO_NAME;
Modified := false;
FAllTime := TFAllTime.CreateEmbedded(self, Panel2);
FAllTime.SetBounds (10, 30, FAllTime.width, FAllTime.Height);
FBunker := TFBunker.CreateEmbedded(self, Panel2);
FBunker.SetBounds(10, 30, FBunker.width, FBunker.Height);
FMaterial := TFMaterial.CreateEmbedded(self, Panel2);
FMaterial.SetBounds(10, 30, FMaterial.width, FMaterial.Height);
FLine := TFLine.CreateEmbedded (self, Panel2);
FLine.SetBounds(10, 30, FLine.width, FLine.Height);
end;
procedure TFModel.InitTreeView;
var
Data : ^TNodeData;
ModelFolder : TTreeNode;
BunkerFolder : TTreeNode;
GivenFolder : TTreeNode;
CommFolder : TTreeNode;
LineFolder : TTreeNode;
MaterialFolder : TTreeNode;
begin
with TreeView1 do
begin
repeat
Items[0].Delete;
until items.count = 0;
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntModelFolder;
Data^.LinkedObject := Model;
ModelFolder := Items.AddObjectFirst(nil, 'Ìîäåëü', Data);
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntBunkerFolder;
Data^.LinkedObject := nil;
BunkerFolder := Items.AddChildObject(ModelFolder, 'Áóíêåðû', Data);
BunkerFolder.ImageIndex := 2;
BunkerFolder.SelectedIndex := 2;
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntCommFolder;
Data^.LinkedObject := nil;
CommFolder := Items.AddChildObject(BunkerFolder, 'Êîììåð÷åñêîå', Data);
CommFolder.ImageIndex := 2;
CommFolder.SelectedIndex := 2;
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntGivenFolder;
Data^.LinkedObject := nil;
GivenFolder := Items.AddChildObject(BunkerFolder, 'Äàâàëü÷åñêîå', Data);
GivenFolder.ImageIndex := 2;
GivenFolder.SelectedIndex := 2;
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntLineFolder;
Data^.LinkedObject := nil;
LineFolder := Items.AddChildObject(ModelFolder, 'Ëèíèè îáðàáîòêè', Data);
LineFolder.ImageIndex := 2;
LineFolder.SelectedIndex := 2;
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntMaterialFolder;
Data^.LinkedObject := nil;
MaterialFolder := Items.AddChildObject(ModelFolder, 'Òèïû ñûðüÿ', Data);
MaterialFolder.ImageIndex := 2;
MaterialFolder.SelectedIndex := 2;
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntAllTime;
Data^.LinkedObject := nil;
MaterialFolder := Items.AddChildObject(ModelFolder, 'Âðåìÿ ìîäåëèðîâàíèÿ', Data);
MaterialFolder.ImageIndex := 3;
MaterialFolder.SelectedIndex := 3;
end;
AAddElement.Enabled := false;
ADeleteElement.Enabled := false;
end;
procedure TFModel.AAddElementExecute(Sender: TObject);
var
SelNode, node : TTreeNode;
Data : ^TNodeData;
Bunker : TBunker;
Line : TAssembleLine;
Material : TMaterial;
begin
node := nil;
SelNode := TreeView1.Selected;
case TNodeData(SelNode.Data^).NodeType of
ntCommFolder,
ntGivenFolder :
begin
Data := nil;
case TNodeData(SelNode.Data^).NodeType of
ntCommFolder : Bunker := TBunker.Create(Model.CommBunkers);
ntGivenFolder : Bunker := TBunker.Create(Model.GivenBunkers);
end;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntBunker;
case TNodeData(SelNode.Data^).NodeType of
ntCommFolder : Model.CommBunkers.Append(Bunker);
ntGivenFolder : Model.GivenBunkers.Append(Bunker);
end;
Data^.LinkedObject := Bunker;
node := TreeView1.Items.AddChildObject(SelNode, Bunker.Name , Data);
node.ImageIndex := 1;
node.SelectedIndex := 1;
end;
ntLineFolder :
begin
Data := nil;
Line := TAssembleLine.Create(Model.Lines);
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntLine;
Model.Lines.Append (Line);
Data^.LinkedObject := Line;
node := TreeView1.Items.AddChildObject(SelNode, Line.Name , Data);
node.ImageIndex := 4;
node.SelectedIndex := 4;
end;
ntMaterialFolder:
begin
Data := nil;
Material := TMaterial.Create(Model.Materials);
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntMaterial;
Model.Materials.Append(Material);
Data^.LinkedObject := Material;
node := TreeView1.Items.AddChildObject(SelNode, Material.Name, Data);
node.ImageIndex := 5;
node.SelectedIndex := 5;
end;
end;
SelNode.Expand(false);
if assigned(node) then
begin
node.Selected := true;
node.EditText;
end;
TreeView1Click(TreeView1);
end;
procedure TFModel.TreeView1Editing(Sender: TObject; Node: TTreeNode;
var AllowEdit: Boolean);
var
Data : TNodeData;
begin
Data := TNodeData(TreeView1.Selected.Data^);
case Data.NodeType of
ntBunker,
ntLine,
ntMaterial :
AllowEdit := true;
else
AllowEdit := false;
end;
end;
procedure TFModel.ADeleteElementExecute(Sender: TObject);
var
Data : TNodeData;
begin
Data := TNodeData(TreeView1.Selected.Data^);
if not (Data.LinkedObject is TListObject) then
begin
ShowMessage('ooops!');
exit;
end;
if Data.NodeType = ntMaterial then
if Model.IsMaterialUsed((Data.LinkedObject as TMaterial).Number) then
begin
MessageDlg(mCantDeleteMaterial,mtWarning, [mbOK], 0);
exit;
end;
if Data.NodeType = ntLine then
if Model.IsLineUsed((Data.LinkedObject as TAssembleLine).Number) then
begin
MessageDlg(mCantDeleteLine,mtWarning, [mbOK], 0);
exit;
end;
(Data.LinkedObject as TListObject).ObjectList.Delete(TreeView1.Selected.Index);
Data.LinkedObject.free;
TreeView1.Items.Delete(TreeView1.Selected);
TreeView1Click(TreeView1);
end;
procedure TFModel.TreeView1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_F2 : TreeView1.Selected.editText;
VK_NEXT : TreeView1.Selected.Expand(false);
VK_PRIOR : TreeView1.Selected.Collapse(false);
end;
end;
procedure HideAllEditors;
begin
FAllTime.hide;
FBunker.Hide;
FMaterial.Hide;
FLine.Hide;
end;
procedure TFModel.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
Data : TNodeData;
begin
Data := TNodeData(TreeView1.Selected.Data^);
case Data.NodeType of
ntBunker,
ntLine,
ntMaterial :
begin
AAddElement.Enabled := false;
ADeleteElement.Enabled := true;
end;
ntModelFolder,
ntAllTime,
ntBunkerFolder :
begin
AAddElement.Enabled := false;
ADeleteElement.Enabled := false;
end;
else
begin
AAddElement.Enabled := true;
ADeleteElement.Enabled := false;
end;
end;
case Data.NodeType of
ntAllTime :
begin
NoObjectLabel.Hide;
FAllTime.Load(Model);
FAllTime.Show;
FAllTime.ActivateFocus;
end;
ntBunker :
begin
NoObjectLabel.Hide;
FBunker.Load(Data.LinkedObject as TBunker);
FBunker.Show;
end;
ntMaterial :
begin
NoObjectLabel.Hide;
FMaterial.Load(Data.LinkedObject as TMaterial);
FMaterial.Show;
end;
ntLine :
begin
NoObjectLabel.Hide;
FLine.Load(Data.LinkedObject as TAssembleLine);
FLine.Show;
end;
else
begin
HideAllEditors;
NoObjectLabel.Show;
NoObjectLabel.BringToFront;
end;
end;
end;
procedure TFModel.TreeView1Changing(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
var
Data : TNodeData;
begin
if TreeView1.Selected = nil then exit;
Data := TNodeData(TreeView1.Selected.Data^);
HideAllEditors;
case Data.NodeType of
ntAllTime : FAllTime.Save(Model);
ntBunker : FBunker.Save(Data.LinkedObject as TBunker);
ntMaterial : FMaterial.Save(Data.LinkedObject as TMaterial);
ntLine : FLine.Save(Data.LinkedObject as TAssembleLine);
end;
end;
procedure TFModel.TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
begin
(TNodeData(Node.Data^).LinkedObject as TListObject).Name := S;
end;
procedure TFModel.LoadFromModel;
var
i : integer;
Data : ^TNodeData;
node , root: TTreeNode;
begin
TreeView1.FullCollapse;
InitTreeView;
root := TreeView1.Items[0];
// êîììåð÷åñêèå áóíêåðû
with Model.CommBunkers do
for i := Low(List) to High(List) do
begin
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntBunker;
Data^.LinkedObject := List[i];
node := TreeView1.Items.AddChildObject(root.Item[0].Item[0] , List[i].Name , Data);
node.ImageIndex := 1;
node.SelectedIndex := 1;
end;
// äàâàëü÷åñêèå áóíêåðû
with Model.GivenBunkers do
for i := Low(List) to High(List) do
begin
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntBunker;
Data^.LinkedObject := List[i];
node := TreeView1.Items.AddChildObject(root.Item[0].Item[1], List[i].Name , Data);
node.ImageIndex := 1;
node.SelectedIndex := 1;
end;
// Ëèíèè îáðàáîòêè
with Model.Lines do
for i := Low(List) to High(List) do
begin
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntLine;
Data^.LinkedObject := List[i];
node := TreeView1.Items.AddChildObject(root.item[1], List[i].Name , Data);
node.ImageIndex := 4;
node.SelectedIndex := 4;
end;
// Òèïû ñûðüÿ
with Model.Materials do
for i := Low(List) to High(List) do
begin
Data := nil;
GetMem(Data, sizeof(TNodeData));
Data^.NodeType := ntMaterial;
Data^.LinkedObject := List[i];
node := TreeView1.Items.AddChildObject(root.item[2], List[i].Name , Data);
node.ImageIndex := 5;
node.SelectedIndex := 5;
end;
end;
procedure TFModel.SaveToModel;
var
temp : boolean;
begin
TreeView1Changing(TreeView1, TreeView1.Selected, temp);
end;
procedure TFModel.Ref;
begin
TreeView1Change(TreeView1, TreeView1.Selected);
end;
procedure TFModel.FormActivate(Sender: TObject);
begin
// LoadFromModel;
TreeView1.OnExpanding := TreeView1Expanding;
TreeView1.FullCollapse;
HideAllEditors;
Modified := true;
// Ref;
end;
procedure TFModel.TreeView1Expanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
begin
if TNodeData(Node.Data^).NodeType = ntModelFolder then
LoadFromModel;
TreeView1.OnExpanding := nil;
TreeView1.Items[0].Expand(false);
AllowExpansion := false;
end;
procedure TFModel.APrintExecute(Sender: TObject);
begin
SaveToModel;
if assigned(ModelReport) then ModelReport.free;
ModelReport := TModelReport.Create(nil);
ModelReport.Model := Model;
ModelReport.loadFromModel;
ModelReport.Update;
ModelReport.Preview;
end;
procedure TFModel.AClearExecute(Sender: TObject);
begin
if visible then TreeView1.FullCollapse;
if visible then TreeView1Change(TreeView1,TreeView1.Selected);
Model.Clear;
if visible then LoadFromModel;
end;
procedure TFModel.FormDestroy(Sender: TObject);
begin
Model.Free;
ModelCopy.Free;
end;
end.