-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTFigEditDialog.cpp
More file actions
282 lines (253 loc) · 7.61 KB
/
TFigEditDialog.cpp
File metadata and controls
282 lines (253 loc) · 7.61 KB
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
/********************************************************************************
* Copyright (c) 2024 Pleshkov Maksim
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
********************************************************************************/
#include <vcl.h>
#pragma hdrstop
#include "TFigEditDialog.h"
//----------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFigEditDialog *FigEditDialog;
//----------------------------------------------------------
constexpr double DEG2RAD = M_PI/180.0;
//Êëàññ äëÿ äåëåãàòà èçìåíåíèÿ ôîðìû
class field_action {
protected:
TFigEditDialog &form;
int type;
public:
field_action(TFigEditDialog &form, int type) :
form(form), type(type) {}
virtual bool operator()() const {return true;}
};
class PosAbs_action : public field_action {
public:
PosAbs_action(TFigEditDialog &form, int type) :
field_action(form, type) {}
bool operator()() const override {
//Èçìåíÿåì ïàðíûå ïîëÿ äëÿ ñîîòâåòñòâèÿ
double val = StrToFloat(form.Fields[type]->Text);
form.Fields[type+3]->Text =
FloatToStrF(val-form.Offset_old[type],
ffFixed, 15, 2);
form.Offset[type] = val;
return true;
}
};
class PosRel_action : public field_action {
public:
PosRel_action(TFigEditDialog &form, int type) :
field_action(form, type) {}
bool operator()() const override {
//Èçìåíÿåì ïàðíûå ïîëÿ äëÿ ñîîòâåòñòâèÿ
double val = StrToFloat(form.Fields[type+3]->Text)+
form.Offset_old[type];
form.Fields[type]->Text = FloatToStrF(val,
ffFixed, 15, 2);
form.Offset[type] = val;
return true;
}
};
class ScAbs_action : public field_action {
public:
ScAbs_action(TFigEditDialog &form, int type) :
field_action(form, type) {}
bool operator()() const override {
//Èçìåíÿåì ïàðíûå ïîëÿ äëÿ ñîîòâåòñòâèÿ
double val = StrToFloat(form.Fields[type+6]->Text);
if(val < 0.0) return false;
form.Scale[type] = val;
val /= form.Scale_old[type];
form.Fields[type+9]->Text =
FloatToStrF(val, ffFixed, 15, 2);
if(form.UniformCB->Checked) {
//Îäíîðîäíûé ìàñøòàá îäèíàêîâ äëÿ îòí. XYZ
for(int i = 0; i<3; ++i) {
form.Fields[i+9]->Text =
FloatToStrF(val, ffFixed, 15, 2);
form.Scale[i] = val*form.Scale_old[i];
form.Fields[i+6]->Text = FloatToStrF(
form.Scale[i], ffFixed, 15, 2);
}
}
return true;
}
};
class ScRel_action : public field_action {
public:
ScRel_action(TFigEditDialog &form, int type) :
field_action(form, type) {}
bool operator()() const override {
//Èçìåíÿåì ïàðíûå ïîëÿ äëÿ ñîîòâåòñòâèÿ
double val = StrToFloat(form.Fields[type+9]->Text);
if(val < 0.0) return false;
form.Scale[type] = val*form.Scale_old[type];
form.Fields[type+6]->Text =
FloatToStrF(form.Scale[type], ffFixed, 15, 2);
if(form.UniformCB->Checked) {
//Îäíîðîäíûé ìàñøòàá îäèíàêîâ äëÿ îòí. XYZ
for(int i = 0; i<3; ++i) {
form.Fields[i+9]->Text =
FloatToStrF(val, ffFixed, 15, 2);
form.Scale[i] = val*form.Scale_old[i];
form.Fields[i+6]->Text = FloatToStrF(
form.Scale[i], ffFixed, 15, 2);
}
}
return true;
}
};
class Rot_action : public field_action {
public:
Rot_action(TFigEditDialog &form, int type) :
field_action(form, type) {}
bool operator()() const override {
form.Rotation[type] =
DEG2RAD*StrToFloat(form.Fields[type+12]->Text);
return true;
}
};
//Êîíñòðóêòîð ñ ðîäèòåëüñêîé ôîðìîé è èçìåíÿåìîé ôèãóðîé
__fastcall TFigEditDialog::TFigEditDialog(TComponent* Owner,
Figure3d_unit* figure) : TForm(Owner), figure(figure) {
figure->GetCenterPos(Offset);
figure->GetScale(Scale);
figure->GetCenterPos(Offset_old);
figure->GetScale(Scale_old);
edit_flag = true;
//Íàïîëíåíèå ïîëåé òåêóùèìè ïàðàìåòðàìè
PosXAbs->Text = FloatToStrF(Offset[0], ffFixed, 15, 2);
PosYAbs->Text = FloatToStrF(Offset[1], ffFixed, 15, 2);
PosZAbs->Text = FloatToStrF(Offset[2], ffFixed, 15, 2);
PosXRel->Text = FloatToStrF(0.0, ffFixed, 15, 2);
PosYRel->Text = FloatToStrF(0.0, ffFixed, 15, 2);
PosZRel->Text = FloatToStrF(0.0, ffFixed, 15, 2);
RotX->Text = FloatToStrF(0.0, ffFixed, 15, 2);
RotY->Text = FloatToStrF(0.0, ffFixed, 15, 2);
RotZ->Text = FloatToStrF(0.0, ffFixed, 15, 2);
ScXAbs->Text = FloatToStrF(Scale[0], ffFixed, 15, 2);
ScYAbs->Text = FloatToStrF(Scale[1], ffFixed, 15, 2);
ScZAbs->Text = FloatToStrF(Scale[2], ffFixed, 15, 2);
ScXRel->Text = FloatToStrF(1.0, ffFixed, 15, 2);
ScYRel->Text = FloatToStrF(1.0, ffFixed, 15, 2);
ScZRel->Text = FloatToStrF(1.0, ffFixed, 15, 2);
edit_flag = false;
const TEdit* fields[15] = {
PosXAbs, PosYAbs, PosZAbs, PosXRel, PosYRel, PosZRel,
ScXAbs, ScYAbs, ScZAbs, ScXRel, ScYRel, ScZRel,
RotX, RotY, RotZ
};
std::memcpy(Fields, fields, sizeof(Fields));
}
//Âûçâàòü äèàëîã (true ëèøü ïðè "ÎÊ")
bool TFigEditDialog::Execute() {
ShowModal();
return (ModalResult == mrOk);
}
//Îá¸ðòêà îáðàáîòêè ïîëåé ââîäà
void TFigEditDialog::FieldActionWrap(
const field_action &act) {
if(edit_flag) return;
edit_flag = true;
try {
if(act()) {
if(!OkBtn->Enabled) OkBtn->Enabled = TestFields();
}
else {
OkBtn->Enabled = false;
}
edit_flag = false;
} catch (...) {
//Îøèáêà ïàðñèíãà - áëîêèðóåì ÎÊ
OkBtn->Enabled = false;
edit_flag = false;
}
}
//Ñîáûòèÿ èçìåíåíèÿ çíà÷åíèé â ïîëÿõ ââîäà
void __fastcall TFigEditDialog::PosXAbsChange(
TObject *Sender) {
FieldActionWrap(PosAbs_action(*this, 0));
}
void __fastcall TFigEditDialog::PosYAbsChange(
TObject *Sender) {
FieldActionWrap(PosAbs_action(*this, 1));
}
void __fastcall TFigEditDialog::PosZAbsChange(
TObject *Sender) {
FieldActionWrap(PosAbs_action(*this, 2));
}
void __fastcall TFigEditDialog::PosXRelChange(
TObject *Sender) {
FieldActionWrap(PosRel_action(*this, 0));
}
void __fastcall TFigEditDialog::PosYRelChange(
TObject *Sender) {
FieldActionWrap(PosRel_action(*this, 1));
}
void __fastcall TFigEditDialog::PosZRelChange(
TObject *Sender) {
FieldActionWrap(PosRel_action(*this, 2));
}
void __fastcall TFigEditDialog::RotXChange(
TObject *Sender) {
FieldActionWrap(Rot_action(*this, 0));
}
void __fastcall TFigEditDialog::RotYChange(
TObject *Sender) {
FieldActionWrap(Rot_action(*this, 1));
}
void __fastcall TFigEditDialog::RotZChange(
TObject *Sender) {
FieldActionWrap(Rot_action(*this, 2));
}
void __fastcall TFigEditDialog::ScXAbsChange(
TObject *Sender) {
FieldActionWrap(ScAbs_action(*this, 0));
}
void __fastcall TFigEditDialog::ScYAbsChange(
TObject *Sender) {
FieldActionWrap(ScAbs_action(*this, 1));
}
void __fastcall TFigEditDialog::ScZAbsChange(
TObject *Sender) {
FieldActionWrap(ScAbs_action(*this, 2));
}
void __fastcall TFigEditDialog::ScXRelChange(
TObject *Sender) {
FieldActionWrap(ScRel_action(*this, 0));
}
void __fastcall TFigEditDialog::ScYRelChange(
TObject *Sender) {
FieldActionWrap(ScRel_action(*this, 1));
}
void __fastcall TFigEditDialog::ScZRelChange(
TObject *Sender) {
FieldActionWrap(ScRel_action(*this, 2));
}
//Ïðîâåðèòü âàëèäíîñòü âñåõ ïîëåé ââîäà
bool TFigEditDialog::TestFields() {
try {
volatile double val;
int i=0;
for(; i<6; ++i) {
val = StrToFloat(Fields[i]->Text);
}
for(; i<12; ++i) {
val = StrToFloat(Fields[i]->Text);
if(val < 0.0) return false;
}
for(; i<15; ++i) {
val = StrToFloat(Fields[i]->Text);
}
return true;
} catch(...) {
return false;
}
}