forked from ja7ude/MMANA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValRep.cpp
202 lines (195 loc) · 5.22 KB
/
ValRep.cpp
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
//Copyright+LGPL
//-----------------------------------------------------------------------------------------------------------------------------------------------
// Copyright 1999-2013 Makoto Mori, Nobuyuki Oba
//-----------------------------------------------------------------------------------------------------------------------------------------------
// This file is part of MMANA.
// MMANA is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// MMANA is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License along with MMANA. If not, see
// <http://www.gnu.org/licenses/>.
//-----------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ValRep.h"
//---------------------------------------------------------------------
#pragma resource "*.dfm"
//TValRepDlg *ValRepDlg;
//---------------------------------------------------------------------
__fastcall TValRepDlg::TValRepDlg(TComponent* AOwner)
: TForm(AOwner)
{
}
//---------------------------------------------------------------------
// 検索と置き換えの実行
int __fastcall TValRepDlg::Execute(double &nd, double &od)
{
double od1, od2;
double nd1, nd2;
int f = FALSE;
RepSel->Enabled = FALSE;
InvSel->Enabled = FALSE;
EditOld->Text = StrDbl(od);
EditNew->Text = StrDbl(od);
Calc(od1, AnsiString(EditOld->Text).c_str());
Calc(nd1, AnsiString(EditNew->Text).c_str());
if( ShowModal() == IDOK ){
Calc(od2, AnsiString(EditOld->Text).c_str());
Calc(nd2, AnsiString(EditNew->Text).c_str());
if( od1 != od2 ){
od = od2;
}
if( nd1 != nd2 ){
nd = nd2;
}
if( od != nd ) f = TRUE;
}
return f;
}
//---------------------------------------------------------------------
// 検索と置き換えの実行
int __fastcall TValRepDlg::Execute(ANTDEF *ap, int Row, int Col)
{
Row--;
Col--;
WDEF *wp = &ap->wdef[Row];
double d, nd, od, dd;
int f = FALSE;
switch(Col){
case 0: // X1
d = wp->X1;
dd = GetRmdVal(d);
break;
case 1: // Y1
d = wp->Y1;
dd = GetRmdVal(d);
break;
case 2: // Z1
d = wp->Z1;
dd = GetRmdVal(d);
break;
case 3: // X2
d = wp->X2;
dd = GetRmdVal(d);
break;
case 4: // Y2
d = wp->Y2;
dd = GetRmdVal(d);
break;
case 5: // Z2
d = wp->Z2;
dd = GetRmdVal(d);
break;
case 6: // R
RepSel->ItemIndex = 0;
InvSel->Checked = FALSE;
RepSel->Enabled = FALSE;
InvSel->Enabled = FALSE;
d = wp->R;
dd = GetRmdValD(d * 1000.0);
break;
case 7: // Seg
RepSel->ItemIndex = 0;
InvSel->Checked = FALSE;
RepSel->Enabled = FALSE;
InvSel->Enabled = FALSE;
EditOld->Text = Seg2Str(wp->SEG);
EditNew->Text = Seg2Str(wp->SEG);
break;
}
if( Col != 7 ){
EditOld->Text = StrDbl(dd);
EditNew->Text = StrDbl(dd);
Calc(dd, AnsiString(EditOld->Text).c_str());
}
if( ShowModal() == IDOK ){
int i;
wp = ap->wdef;
if( Col == 7 ){ // SEGの変更
int oseg, nseg;
if( Str2Seg(oseg, AnsiString(EditOld->Text).c_str()) != TRUE ) return FALSE;
if( Str2Seg(nseg, AnsiString(EditNew->Text).c_str()) != TRUE ) return FALSE;
if( oseg != nseg ){
for( i = 0; i < ap->wmax; i++, wp++ ){
if( wp->SEG == oseg ){
wp->SEG = nseg;
f = TRUE;
}
}
}
return f;
}
nd = d;
Calc(od, AnsiString(EditOld->Text).c_str());
Calc(nd, AnsiString(EditNew->Text).c_str());
if( od == nd ) return FALSE;
if( Col == 6 ){ // 半径の変更
if( dd != od ){
d = SetRmdValD(od)/1000.0;
}
for( i = 0; i < ap->wmax; i++, wp++ ){
if( wp->R == d ){
wp->R = SetRmdValD(nd)/1000.0;
f = TRUE;
}
}
}
else {
if( dd != od ){
d = SetRmdVal(od);
}
nd = SetRmdVal(nd);
for( i = 0; i < ap->wmax; i++, wp++ ){
switch(RepSel->ItemIndex){
case 0:
RepJob(f, wp->X1, d, nd);
RepJob(f, wp->Y1, d, nd);
RepJob(f, wp->Z1, d, nd);
RepJob(f, wp->X2, d, nd);
RepJob(f, wp->Y2, d, nd);
RepJob(f, wp->Z2, d, nd);
break;
case 1:
RepJob(f, wp->X1, d, nd);
RepJob(f, wp->X2, d, nd);
break;
case 2:
RepJob(f, wp->Y1, d, nd);
RepJob(f, wp->Y2, d, nd);
break;
case 3:
RepJob(f, wp->Z1, d, nd);
RepJob(f, wp->Z2, d, nd);
break;
}
}
}
}
return f;
}
//---------------------------------------------------------------------
// ひとつの座標の置き換え
void TValRepDlg::RepJob(int &f, double &t, double d, double nd)
{
double dd = t;
if( dd == d ){
t = nd;
f = TRUE;
}
else if( InvSel->Checked == TRUE ){
dd = ABS(t);
if( dd == ABS(d) ){
if( d == 0.0 ){
t = nd;
}
else {
double s = SGN(d) * SGN(nd) * SGN(t);
t = s * ABS(nd);
}
f = TRUE;
}
}
}
//---------------------------------------------------------------------