-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit1.pas
161 lines (135 loc) · 3.56 KB
/
unit1.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
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
Unit2,Unit3,Unit4,Unit5,Unit6;
const
filename='density_table_en.csv';
type
{ UT8FString=type AnsiString(CP_UTF8);}
UT8FString=UTF8String;
price=Record
d:Single;
name:UT8FString;
end;
{ TFShapePicker }
TFShapePicker = class(TForm)
BGetDataTable: TButton;
BPickSphere: TButton;
BPickCylinder: TButton;
BPickCube: TButton;
BPick3DBar: TButton;
BPickComplex: TButton;
LblInstruction: TLabel;
procedure BGetDataTableClick(Sender: TObject);
procedure BPick3DBarClick(Sender: TObject);
procedure BPickComplexClick(Sender : TObject);
procedure BPickCubeClick(Sender: TObject);
procedure BPickSphereClick(Sender:TObject);
procedure BPickCylinderClick(Sender:TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
FShapePicker: TFShapePicker;
dt:array of Price;
buf,strmaterialdens,materialname:UT8FString;
materialdens:Single;
namelen,sci:Word;
n:LongInt;
F:System.Text;
implementation
procedure TFShapePicker.BPickSphereClick(Sender:TObject);
begin
FSphere.Show; //Показать окно для шара
end;
procedure FindTableBound(var F:Text);
var buf:String;
i:LongInt;
Ftmp:Text;
begin
System.Assign(Ftmp,'temp.csv');
Reset(F);
i:=0;
while not EOF(F) do
begin
Readln(F,buf);
Inc(i);
end;
ReWrite(Ftmp);
WriteLn(Ftmp,i);
Reset(F);
while not EOF(F) do
begin
ReadLn(F,buf);
WriteLn(Ftmp,buf);
end;
Close(Ftmp);
Close(F);
RenameFile(filename,filename+'.old');
RenameFile('temp.csv',filename);
end;
procedure ReadDTableData;
begin
if FileExists(filename) then
begin
System.Assign(F,filename);
Reset(F);
ReadLn(F,buf);
Val(buf,n,valcode);
if (n<0) or (valcode<>0) then FindTableBound(F);
Reset(F);
ReadLn(F,buf);
Val(buf,n,valcode);
SetLength(dt,n+1);
dt[0].d:=0;
for i:=1 to n do
begin
ReadLn(F,buf);
sci:=Pos(';',buf); {first semicolon index}
strmaterialdens:=Copy(buf,1,sci-1);
namelen:=Length(buf)-sci; {material label length}
materialname:=Copy(buf,sci+1,namelen);
Val(strmaterialdens,materialdens,valcode);
dt[i].d:=materialdens;
dt[i].name:=materialname;
{TODO: push it into an array}
end;
end else
begin
ShowMessage('Resource not found near the exe, using embedded restricted set');
{TODO Init da table with code data}
end;
end;
procedure TFShapePicker.BGetDataTableClick(Sender: TObject);
begin
ReadDTableData;
end;
procedure TFShapePicker.BPick3DBarClick(Sender: TObject);
begin
FBar.Show; // показать окно для бруска
end;
procedure TFShapePicker.BPickComplexClick(Sender : TObject);
begin
FComplex.Show;
end;
procedure TFShapePicker.BPickCubeClick(Sender: TObject);
begin
FCube.Show;
end;
procedure TFShapePicker.BPickCylinderClick(Sender:TObject);
begin
FCylinder.Show; // показать окно для цилиндра
end;
procedure TFShapePicker.FormCreate(Sender: TObject);
begin
SetLength(dt,2);
dt[0].d:=-1;
end;
{$R *.lfm}
{ TFShapePicker }
end.