-
Notifications
You must be signed in to change notification settings - Fork 34
/
BatchForm.pas
228 lines (203 loc) · 6.6 KB
/
BatchForm.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
unit BatchForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, ShellApi, Menus;
type
TBatchForm1 = class(TForm)
ListView1: TListView;
Panel1: TPanel;
Button1: TButton;
CheckBox1: TCheckBox;
Button2: TButton;
Button3: TButton;
CheckBox2: TCheckBox;
Button4: TButton;
PopupMenu1: TPopupMenu;
Deleteselectedfilesfromlist1: TMenuItem;
Clearthewholelist1: TMenuItem;
SavePNGPreviewCBx: TCheckBox;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure ListView1Insert(Sender: TObject; Item: TListItem);
procedure Button1Click(Sender: TObject);
procedure ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure Button4Click(Sender: TObject);
procedure Clearthewholelist1Click(Sender: TObject);
procedure Deleteselectedfilesfromlist1Click(Sender: TObject);
private
{ Private-Deklarationen }
procedure WMDROPFILES(var Msg: TMessage); message WM_DROPFILES;
function CanLoadParas(M3Pfile: String): Boolean;
function NotDouble(s: String): Boolean;
procedure AddProofItem(s: String);
public
{ Public-Deklarationen }
CurrentListIndex: Integer;
procedure NextFile;
end;
var
BatchForm1: TBatchForm1;
BatchStatus: Integer = 0;
BatchFormCreated: LongBool = False;
implementation
uses Mand, TypeDefinitions, FileHandling, CustomFormulas;
{$R *.dfm}
const
Caption_Start_Rendering = 'Start batch rendering';
Caption_Stop_Rendering = 'Stop batch rendering';
function TBatchForm1.CanLoadParas(M3Pfile: String): Boolean;
var x: Integer;
HybridCustoms: array[0..5] of TCustomFormula;
Header: TMandHeader10;
HAddOn: THeaderCustomAddon;
begin
if UpperCase(ExtractFileExt(M3Pfile)) <> '.M3P' then Result := False else
begin
Header.PCFAddon := @HAddOn;
for x := 0 to 5 do Header.PHCustomF[x] := @HybridCustoms[x];
for x := 0 to 5 do IniCustomF(@HybridCustoms[x]);
Result := LoadParameter(Header, M3Pfile, False);
end;
end;
function TBatchForm1.NotDouble(s: String): Boolean;
var x: Integer;
begin
Result := True;
for x := 0 to ListView1.Items.Count - 1 do
if ListView1.Items[x].Caption = s then Result := False;
end;
procedure TBatchForm1.AddProofItem(s: String);
begin
if NotDouble(s) and CanLoadParas(s) then ListView1.AddItem(s, nil);
end;
procedure TBatchForm1.Button2Click(Sender: TObject);
begin
Visible := False;
end;
procedure TBatchForm1.Button3Click(Sender: TObject); //open M3P files
var x: Integer;
begin
Mand3DForm.OpenDialog1.Options := Mand3DForm.OpenDialog1.Options + [ofAllowMultiSelect];
if Mand3DForm.OpenDialog1.Execute then
begin
for x := 0 to Mand3DForm.OpenDialog1.Files.Count - 1 do
AddProofItem(Mand3DForm.OpenDialog1.Files.Strings[x]);
end;
end;
procedure TBatchForm1.ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var x: Integer;
begin
if (BatchStatus = 0) and (Key = 46) then //delete
begin
x := 0;
while x < ListView1.Items.Count do
if ListView1.Items[x].Selected then ListView1.Items[x].Delete else Inc(x);
end;
end;
procedure TBatchForm1.WMDROPFILES(var Msg: TMessage);
var i, count, size: integer;
FileName: PChar;
begin
inherited;
count := DragQueryFile(Msg.WParam, $FFFFFFFF, FileName, 255);
for i := 0 to count - 1 do
begin
size := DragQueryFile(Msg.WParam, i, nil, 0) + 1;
FileName := StrAlloc(size);
DragQueryFile(Msg.WParam, i, FileName, size);
AddProofItem(StrPas(FileName));
StrDispose(FileName);
end;
DragFinish(Msg.WParam);
end;
procedure TBatchForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := Caption_Start_Rendering;
DragAcceptFiles(Self.Handle, True);
BatchFormCreated := True;
end;
procedure TBatchForm1.ListView1Insert(Sender: TObject; Item: TListItem);
begin
Item.Checked := True;
end;
procedure TBatchForm1.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
if BatchStatus = 0 then
begin
if Item.SubItems.Count < 1 then Item.SubItems.Add('');
if Item.Checked then Item.SubItems[0] := 'Selected'
else Item.SubItems[0] := 'Not selected';
end;
end;
procedure TBatchForm1.NextFile;
begin
if BatchStatus < 0 then CurrentListIndex := ListView1.Items.Count;
if (CurrentListIndex < ListView1.Items.Count) and (CurrentListIndex >= 0) then
begin
ListView1.Items[CurrentListIndex].Checked := False;
ListView1.Items[CurrentListIndex].SubItems[0] := 'M3I done';
end;
repeat
Inc(CurrentListIndex)
until (CurrentListIndex >= ListView1.Items.Count) or (ListView1.Items[CurrentListIndex].Checked and
LoadParameter(Mand3DForm.MHeader, ListView1.Items[CurrentListIndex].Caption, True));
if CurrentListIndex < ListView1.Items.Count then
begin
Mand3DForm.MHeader.bCalc3D := 1;
Mand3DForm.CalcMand(True);
end
else
begin
BatchStatus := 0;
Mand3DForm.EnableButtons;
Button1.Enabled := True;
Button1.Caption := Caption_Start_Rendering;
ListView1.PopupMenu := PopupMenu1;
end;
end;
procedure TBatchForm1.Button1Click(Sender: TObject); //start batch
begin
if Button1.Caption = Caption_Stop_Rendering then begin
MCalcStop := True;
Button1.Caption := 'Stopping batch...';
Button1.Enabled := False;
BatchStatus := -1;
Mand3DForm.CancelRendering;
Button1.Caption := Caption_Start_Rendering;
end
else begin
//proof free disc space: must be calc all needed space of files and add for each disc the amount of space needed
// DiscFreeMB(disc: String; var FreeMB: Integer): LongBool;
Button1.Caption := Caption_Stop_Rendering;
BatchStatus := 1;
CurrentListIndex := -1;
ListView1.PopupMenu := nil;
NextFile;
end;
end;
procedure TBatchForm1.Button4Click(Sender: TObject);
begin
ShellExecute(Application.Handle, 'open', nil , nil, PCHar(extractfiledir(IniDirs[1])), SW_ShowNormal)
end;
procedure TBatchForm1.Clearthewholelist1Click(Sender: TObject);
begin
if BatchStatus = 0 then ListView1.Clear;
end;
procedure TBatchForm1.Deleteselectedfilesfromlist1Click(Sender: TObject);
var x: Integer;
begin
if BatchStatus = 0 then //delete
begin
x := 0;
while x < ListView1.Items.Count do
if ListView1.Items[x].Selected then ListView1.Items[x].Delete else Inc(x);
end;
end;
end.