@phoenix-wing/kt-codegen 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/KtCodegenRenderer.d.ts +1 -1
- package/dist/KtCodegenRenderer.d.ts.map +1 -1
- package/dist/KtCodegenRenderer.js +3 -1293
- package/dist/KtCodegenRenderer.js.map +1 -1
- package/dist/api/compatibility.d.ts +21 -0
- package/dist/api/compatibility.d.ts.map +1 -0
- package/dist/api/compatibility.js +43 -0
- package/dist/api/compatibility.js.map +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/renderer/caa-command-families.d.ts +4 -0
- package/dist/renderer/caa-command-families.d.ts.map +1 -0
- package/dist/renderer/caa-command-families.js +336 -0
- package/dist/renderer/caa-command-families.js.map +1 -0
- package/dist/renderer/caa-dialog-family.d.ts +5 -0
- package/dist/renderer/caa-dialog-family.d.ts.map +1 -0
- package/dist/renderer/caa-dialog-family.js +323 -0
- package/dist/renderer/caa-dialog-family.js.map +1 -0
- package/dist/renderer/caa-feature-families.d.ts +4 -0
- package/dist/renderer/caa-feature-families.d.ts.map +1 -0
- package/dist/renderer/caa-feature-families.js +250 -0
- package/dist/renderer/caa-feature-families.js.map +1 -0
- package/dist/renderer/caa-renderer.d.ts +6 -0
- package/dist/renderer/caa-renderer.d.ts.map +1 -0
- package/dist/renderer/caa-renderer.js +25 -0
- package/dist/renderer/caa-renderer.js.map +1 -0
- package/dist/renderer/cpp-parameter-family.d.ts +7 -0
- package/dist/renderer/cpp-parameter-family.d.ts.map +1 -0
- package/dist/renderer/cpp-parameter-family.js +77 -0
- package/dist/renderer/cpp-parameter-family.js.map +1 -0
- package/dist/renderer/dialog-support.d.ts +6 -0
- package/dist/renderer/dialog-support.d.ts.map +1 -0
- package/dist/renderer/dialog-support.js +16 -0
- package/dist/renderer/dialog-support.js.map +1 -0
- package/dist/renderer/family-registry.d.ts +28 -0
- package/dist/renderer/family-registry.d.ts.map +1 -0
- package/dist/renderer/family-registry.js +55 -0
- package/dist/renderer/family-registry.js.map +1 -0
- package/dist/renderer/legacy-compatibility.d.ts +16 -0
- package/dist/renderer/legacy-compatibility.d.ts.map +1 -0
- package/dist/renderer/legacy-compatibility.js +77 -0
- package/dist/renderer/legacy-compatibility.js.map +1 -0
- package/dist/renderer/qt-dialog-family.d.ts +7 -0
- package/dist/renderer/qt-dialog-family.d.ts.map +1 -0
- package/dist/renderer/qt-dialog-family.js +231 -0
- package/dist/renderer/qt-dialog-family.js.map +1 -0
- package/package.json +4 -2
- package/tests/fixtures/contracts/apply-projection-v1.json +82 -0
- package/tests/fixtures/contracts/codegen-host-contract-v1.json +280 -0
|
@@ -1,1297 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"PARAM DECLARATION",
|
|
6
|
-
"PARAM DESTRUCTOR",
|
|
7
|
-
"PARAM EQUAL",
|
|
8
|
-
]);
|
|
9
|
-
const KT_CODEGEN_CAA_INTERFACE_BLOCKS = new Set([
|
|
10
|
-
"IMPLEMENTS HEAD GET",
|
|
11
|
-
"IMPLEMENTS HEAD SET",
|
|
12
|
-
"INTERFACES HEAD GET",
|
|
13
|
-
"INTERFACES HEAD SET",
|
|
14
|
-
]);
|
|
15
|
-
const KT_CODEGEN_CAA_FEATURE_IO_BLOCKS = new Set([
|
|
16
|
-
"IMPLEMENTS CPP GET",
|
|
17
|
-
"IMPLEMENTS CPP SET",
|
|
18
|
-
"IMPLEMENTS PARAM GET",
|
|
19
|
-
"IMPLEMENTS PARAM SET",
|
|
20
|
-
]);
|
|
21
|
-
const KT_CODEGEN_CAA_COMMAND_AGENT_LIFECYCLE_BLOCKS = new Set([
|
|
22
|
-
"CMD AGENT DECLARE",
|
|
23
|
-
"CMD AGENT CONSTRUCTOR",
|
|
24
|
-
"CMD AGENT DESTRUCTOR",
|
|
25
|
-
]);
|
|
26
|
-
const KT_CODEGEN_CAA_COMMAND_GRAPH_STATE_BLOCKS = new Set([
|
|
27
|
-
"CMD AGENT BUILD GRAPH",
|
|
28
|
-
"CMD AGENT UPDATE STATE",
|
|
29
|
-
"CMD AGENT FIA CLEAR",
|
|
30
|
-
]);
|
|
31
|
-
const KT_CODEGEN_CAA_COMMAND_ACTION_BLOCKS = new Set([
|
|
32
|
-
"CMD ACTION PDA",
|
|
33
|
-
"CMD ACTION FIA",
|
|
34
|
-
"CMD ELEMENT SELECTED",
|
|
35
|
-
"CMD SET ACTIVE FIELD",
|
|
36
|
-
]);
|
|
37
|
-
const KT_CODEGEN_CAA_MIGRATED_BLOCKS = new Set([
|
|
38
|
-
...KT_CODEGEN_CAA_INTERFACE_BLOCKS,
|
|
39
|
-
...KT_CODEGEN_CAA_FEATURE_IO_BLOCKS,
|
|
40
|
-
"CATALOG PARAMS",
|
|
41
|
-
"FACTRY ON TREE",
|
|
42
|
-
"DIALOG NOTIFY",
|
|
43
|
-
"UPDATE DIALOG",
|
|
44
|
-
"UPDATE INFORS",
|
|
45
|
-
"DLG DEFINE FIELD TYPE",
|
|
46
|
-
"DLG SET ACTIVE FIELD",
|
|
47
|
-
"DLG GET SELECTOR LIST",
|
|
48
|
-
...KT_CODEGEN_CAA_COMMAND_AGENT_LIFECYCLE_BLOCKS,
|
|
49
|
-
...KT_CODEGEN_CAA_COMMAND_GRAPH_STATE_BLOCKS,
|
|
50
|
-
...KT_CODEGEN_CAA_COMMAND_ACTION_BLOCKS,
|
|
51
|
-
]);
|
|
52
|
-
const KT_CODEGEN_QT_MIGRATED_BLOCKS = new Set([
|
|
53
|
-
"QT UPDATE DIALOG",
|
|
54
|
-
"QT UPDATE INFORS",
|
|
55
|
-
]);
|
|
56
|
-
/** 按旧 `CodeAppendNotes` 的0/1/2模式创建 Doxygen 注释。 */
|
|
57
|
-
function ktCodegenRenderLegacyNotes(item, prefix, mode = 0, isParamSpecList) {
|
|
58
|
-
const lines = [`${prefix}/**`, `${prefix} * @brief ${item.name}`];
|
|
59
|
-
if (mode === 1) {
|
|
60
|
-
lines.push(`${prefix} * @param[in] value ${item.dataType}`, `${prefix} * @return HRESULT`);
|
|
61
|
-
}
|
|
62
|
-
else if (mode === 2) {
|
|
63
|
-
lines.push(`${prefix} * @return ${isParamSpecList?.(item) ? "HRESULT" : item.dataType}`);
|
|
64
|
-
}
|
|
65
|
-
if (item.author.length > 0)
|
|
66
|
-
lines.push(`${prefix} * @author ${item.author}`);
|
|
67
|
-
if (item.createDate.length > 0)
|
|
68
|
-
lines.push(`${prefix} * @date ${item.createDate}`);
|
|
69
|
-
if (item.notes.length > 0)
|
|
70
|
-
lines.push(`${prefix} * @note ${item.notes}`);
|
|
71
|
-
lines.push(`${prefix} * @id ${item.id}`, `${prefix} */`);
|
|
72
|
-
return lines;
|
|
73
|
-
}
|
|
74
|
-
/** 创建旧 Start 标记和 clang-format off 头部。 */
|
|
75
|
-
function ktCodegenRenderLegacyStart(region) {
|
|
76
|
-
const prefix = region.start.linePrefix;
|
|
77
|
-
return [`${prefix}// ${region.start.text}`, "", `${prefix}// clang-format off`];
|
|
78
|
-
}
|
|
79
|
-
/** 创建标准旧 clang-format on 和 End 标记尾部。 */
|
|
80
|
-
function ktCodegenRenderLegacyEnd(region) {
|
|
81
|
-
const prefix = region.start.linePrefix;
|
|
82
|
-
return ["", `${prefix}// clang-format on`, `${prefix}// ${region.end.text}`];
|
|
83
|
-
}
|
|
84
|
-
/** 按旧 VB 规则生成一个普通 C++ Parameter 自动代码块的逻辑行。 */
|
|
85
|
-
function ktCodegenRenderCppParameterLines(region, items, formatDefaultValue) {
|
|
86
|
-
const prefix = region.start.linePrefix;
|
|
87
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
88
|
-
switch (region.blockKey) {
|
|
89
|
-
case "PARAM CONSTRUCTOR":
|
|
90
|
-
for (const item of items) {
|
|
91
|
-
const initializerPrefix = item.id === 1 ? ": " : ", ";
|
|
92
|
-
lines.push(`${prefix}${initializerPrefix}${item.paramString}(${formatDefaultValue(item)}) // ${item.id}`);
|
|
93
|
-
}
|
|
94
|
-
// 旧方法使用 Trim 写出 End,故 clang-format 与 End 不保留 `_prefix`。
|
|
95
|
-
lines.push("", "// clang-format on", `// ${region.end.text}`);
|
|
96
|
-
return lines;
|
|
97
|
-
case "PARAM EQUAL":
|
|
98
|
-
for (const item of items) {
|
|
99
|
-
// 旧 VB 使用 IndexOf("*") > 0;星号位于首字符时不会注释该行。
|
|
100
|
-
const pointerPrefix = item.dataType.indexOf("*") > 0 ? "// " : "";
|
|
101
|
-
lines.push(`${prefix}${pointerPrefix}${item.paramString} = iOriginal.${item.paramString}; // ${item.id}`);
|
|
102
|
-
}
|
|
103
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
104
|
-
case "PARAM DESTRUCTOR":
|
|
105
|
-
for (const item of items) {
|
|
106
|
-
if (item.dataType.toLowerCase() === "catispecobject_var") {
|
|
107
|
-
lines.push(`${prefix}${item.paramString} = NULL_var; // ${item.id}`);
|
|
108
|
-
}
|
|
109
|
-
else if (item.dataType.includes("*")) {
|
|
110
|
-
lines.push(`${prefix}${item.paramString} = NULL; // ${item.id}`);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
lines.push(`${prefix}// ${item.paramString} = ${formatDefaultValue(item, true)}; // ${item.id}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
117
|
-
case "PARAM DECLARATION":
|
|
118
|
-
lines.push("", `${prefix}// @app Kt Auto Code`, `${prefix}// @version 5.0.0, (2024)`, "");
|
|
119
|
-
items.forEach((item, index) => {
|
|
120
|
-
if (index > 0)
|
|
121
|
-
lines.push("");
|
|
122
|
-
lines.push(...ktCodegenRenderLegacyNotes(item, prefix));
|
|
123
|
-
lines.push(`${prefix}${item.dataType} ${item.paramString};`);
|
|
124
|
-
});
|
|
125
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
126
|
-
default:
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/** 从快照推断一个区域写回时应继续使用的换行符。 */
|
|
131
|
-
function ktCodegenResolveRegionEol(context, region) {
|
|
132
|
-
const file = context.snapshot.files.find((candidate) => candidate.path === region.path && candidate.fingerprint === region.sourceFingerprint);
|
|
133
|
-
if (!file)
|
|
134
|
-
return null;
|
|
135
|
-
const eol = file.eol === "crlf" || (file.eol === undefined && file.text.includes("\r\n"))
|
|
136
|
-
? "\r\n"
|
|
137
|
-
: "\n";
|
|
138
|
-
const endTail = file.text.slice(region.end.markerEndOffset, region.end.lineEndOffset);
|
|
139
|
-
return { eol, hasFinalEol: endTail.includes("\n") || endTail.includes("\r") };
|
|
140
|
-
}
|
|
141
|
-
/** 把逻辑行组装为绑定安全区域的 artifact,或返回快照缺失诊断。 */
|
|
142
|
-
function ktCodegenAppendRegionArtifact(context, region, items, lines, artifacts, diagnostics) {
|
|
143
|
-
const lineEnding = ktCodegenResolveRegionEol(context, region);
|
|
144
|
-
if (!lineEnding) {
|
|
145
|
-
diagnostics.push({
|
|
146
|
-
code: "renderer.source-snapshot-missing",
|
|
147
|
-
severity: "error",
|
|
148
|
-
message: `Marker region ${region.id} no longer has its source snapshot.`,
|
|
149
|
-
path: { source: "renderer", file: region.path, field: region.blockKey },
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const body = lines.join(lineEnding.eol);
|
|
154
|
-
artifacts.push({
|
|
155
|
-
id: `kt.codegen.artifact:${context.target}:${region.id}`,
|
|
156
|
-
regionId: region.id,
|
|
157
|
-
target: context.target,
|
|
158
|
-
blockKey: region.blockKey,
|
|
159
|
-
classId: region.classId,
|
|
160
|
-
content: lineEnding.hasFinalEol ? `${body}${lineEnding.eol}` : body,
|
|
161
|
-
sourceParameters: items.map((item) => item.paramString),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
/** 生成已迁移的四个普通 C++ Parameter block artifact。 */
|
|
165
|
-
function ktCodegenRenderCppParameter(context, formatDefaultValue) {
|
|
166
|
-
const artifacts = [];
|
|
167
|
-
const diagnostics = [];
|
|
168
|
-
const requestedBlocks = new Set(context.blockKeys);
|
|
169
|
-
for (const region of context.markerRegions) {
|
|
170
|
-
if (!KT_CODEGEN_CPP_PARAMETER_BLOCKS.has(region.blockKey) ||
|
|
171
|
-
!requestedBlocks.has(region.blockKey)) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
const items = context.param.items.filter((item) => item.nameSuffix === region.nameSuffix && item.id >= 1);
|
|
175
|
-
const lines = ktCodegenRenderCppParameterLines(region, items, formatDefaultValue);
|
|
176
|
-
ktCodegenAppendRegionArtifact(context, region, items, lines, artifacts, diagnostics);
|
|
177
|
-
}
|
|
178
|
-
return { status: "ready", artifacts, diagnostics };
|
|
179
|
-
}
|
|
180
|
-
/** 判断旧接口头文件块生成时是否保留当前 Item。 */
|
|
181
|
-
function ktCodegenIsCaaInterfaceItem(item, nameSuffix) {
|
|
182
|
-
if (item.nameSuffix !== nameSuffix || item.id === -1)
|
|
183
|
-
return false;
|
|
184
|
-
return item.id < 100 || item.id >= 200;
|
|
185
|
-
}
|
|
186
|
-
/** 按旧 VB 规则生成 CAA 实现类或纯虚接口类的 Get/Set 声明。 */
|
|
187
|
-
function ktCodegenRenderCaaInterfaceLines(region, items, isParamSpecList) {
|
|
188
|
-
const prefix = region.start.linePrefix;
|
|
189
|
-
const isGet = region.blockKey === "IMPLEMENTS HEAD GET" ||
|
|
190
|
-
region.blockKey === "INTERFACES HEAD GET";
|
|
191
|
-
const isVirtual = region.blockKey === "INTERFACES HEAD GET" ||
|
|
192
|
-
region.blockKey === "INTERFACES HEAD SET";
|
|
193
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
194
|
-
// 旧方法使用 CodeAppendLine,public 标签不附加 `_prefix`。
|
|
195
|
-
lines.push(`public: // ${isGet ? "Get" : "Set"}`);
|
|
196
|
-
items.forEach((item, index) => {
|
|
197
|
-
if (index > 0)
|
|
198
|
-
lines.push("");
|
|
199
|
-
lines.push(...ktCodegenRenderLegacyNotes(item, prefix, isGet ? 2 : 1, isParamSpecList));
|
|
200
|
-
if (isGet) {
|
|
201
|
-
const listSpec = isParamSpecList(item);
|
|
202
|
-
const declaration = listSpec
|
|
203
|
-
? `HRESULT Get${item.paramString}(${item.dataType}& value) const`
|
|
204
|
-
: `${item.dataType} Get${item.paramString}() const`;
|
|
205
|
-
lines.push(`${prefix}${isVirtual ? "virtual " : ""}${declaration}${isVirtual ? " = 0" : ""};`);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
const declaration = `HRESULT Set${item.paramString}(const ${item.dataType}& value, const CATBoolean& checkExist = CATTrue)`;
|
|
209
|
-
lines.push(`${prefix}${isVirtual ? "virtual " : ""}${declaration}${isVirtual ? " = 0" : ""};`);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
213
|
-
}
|
|
214
|
-
/** 判断旧 Params Class Get/Set 是否保留当前 Item:仅允许 ID 1~99。 */
|
|
215
|
-
function ktCodegenIsCaaParamsClassItem(item, nameSuffix) {
|
|
216
|
-
return item.nameSuffix === nameSuffix && item.id > 0 && item.id < 100;
|
|
217
|
-
}
|
|
218
|
-
/** 按旧 VB 规则生成 CAA 实现类 CPP 中的单参数 Get/Set 函数。 */
|
|
219
|
-
function ktCodegenRenderCaaFeatureCppLines(context, region, items, algorithms) {
|
|
220
|
-
const prefix = region.start.linePrefix;
|
|
221
|
-
const isGet = region.blockKey === "IMPLEMENTS CPP GET";
|
|
222
|
-
const className = `${context.param.namePrefix}E${context.param.nameMiddle}${region.nameSuffix}`;
|
|
223
|
-
const lines = [...ktCodegenRenderLegacyStart(region), ""];
|
|
224
|
-
for (const item of items) {
|
|
225
|
-
const listSpec = algorithms.isParamSpecList(item);
|
|
226
|
-
lines.push(`${prefix}//-----------------------------------------------`);
|
|
227
|
-
if (isGet) {
|
|
228
|
-
const returnType = listSpec ? "HRESULT" : item.dataType;
|
|
229
|
-
const parameter = listSpec ? `${item.dataType}& value` : "";
|
|
230
|
-
lines.push(`${prefix}${returnType} ${className}::Get${item.paramString}(${parameter}) const // ${item.id}`, `${prefix}{`);
|
|
231
|
-
const convertToInt = !listSpec && item.tcKind === "tk_integer" && item.dataType.toLowerCase() !== "int";
|
|
232
|
-
if (!listSpec) {
|
|
233
|
-
const defaultValue = algorithms.formatDefaultValue(item);
|
|
234
|
-
if (convertToInt) {
|
|
235
|
-
lines.push(`${prefix} int value = (int)(${defaultValue});`);
|
|
236
|
-
}
|
|
237
|
-
else if (defaultValue.length > 0) {
|
|
238
|
-
lines.push(`${prefix} ${item.dataType} value(${defaultValue});`);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
lines.push(`${prefix} ${item.dataType} value;`);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (listSpec) {
|
|
245
|
-
if (item.dataType === `${context.param.nameSpace}::SpecObjectCollect`) {
|
|
246
|
-
const orderSuffix = algorithms.getLastStandaloneUppercase(item.paramString);
|
|
247
|
-
lines.push(`${prefix} value.RemoveAll();`, `${prefix} value.SetIsOrderBySerial(GetIsOrderBySerial${orderSuffix}());`,
|
|
248
|
-
// 旧 StringOut 在第二个 vbNewLine 后只追加四个空格,没有 `_prefix`。
|
|
249
|
-
` return ktcSpecRW.GetListValue("${item.paramString}", value);`);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
lines.push(`${prefix} return ktcSpecRW.GetListValue("${item.paramString}", value);`);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
const getFunction = item.tcKind.toLowerCase() === "tk_specobject" ? "GetSpecValue" : "GetValue";
|
|
257
|
-
lines.push(`${prefix} ktcSpecRW.${getFunction}("${item.paramString}", value);`, `${prefix} return ${convertToInt ? `(${item.dataType})` : ""}value;`);
|
|
258
|
-
}
|
|
259
|
-
lines.push(`${prefix}}`);
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
lines.push(`${prefix}HRESULT ${className}::Set${item.paramString}(const ${item.dataType}& value, const CATBoolean& checkExist) // ${item.id}`, `${prefix}{`);
|
|
263
|
-
if (listSpec) {
|
|
264
|
-
lines.push(`${prefix} return ktcSpecRW.SetListValue("${item.paramString}", value, checkExist);`);
|
|
265
|
-
}
|
|
266
|
-
else if (item.tcKind.toLowerCase() === "tk_specobject") {
|
|
267
|
-
lines.push(`${prefix} return ktcSpecRW.SetSpecValue("${item.paramString}", value, checkExist);`);
|
|
268
|
-
}
|
|
269
|
-
else if (item.tcKind === "tk_integer" && item.dataType.toLowerCase() !== "int") {
|
|
270
|
-
lines.push(`${prefix} int valueInput = (int)value;`, `${prefix} return ktcSpecRW.SetValue("${item.paramString}", valueInput, checkExist);`);
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
lines.push(`${prefix} return ktcSpecRW.SetValue("${item.paramString}", value, checkExist);`);
|
|
274
|
-
}
|
|
275
|
-
lines.push(`${prefix}}`);
|
|
276
|
-
}
|
|
277
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
278
|
-
}
|
|
279
|
-
/** 按旧 VB 规则生成 Param 聚合对象与单参数 Get/Set 之间的桥接语句。 */
|
|
280
|
-
function ktCodegenRenderCaaParamsClassLines(region, items, isParamSpecList) {
|
|
281
|
-
const prefix = region.start.linePrefix;
|
|
282
|
-
const isGet = region.blockKey === "IMPLEMENTS PARAM GET";
|
|
283
|
-
const lines = [...ktCodegenRenderLegacyStart(region), ""];
|
|
284
|
-
for (const item of items) {
|
|
285
|
-
if (isGet) {
|
|
286
|
-
lines.push(isParamSpecList(item)
|
|
287
|
-
? `${prefix}Get${item.paramString}(value.${item.paramString}); // ${item.id}`
|
|
288
|
-
: `${prefix}value.${item.paramString} = Get${item.paramString}(); // ${item.id}`);
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
lines.push(`${prefix}hr = Set${item.paramString}(value.${item.paramString}); // ${item.id}`, `${prefix}if (FAILED(hr)) {`, `${prefix} msg.Append("\\nSet Parameter of ${item.paramString} Error!");`, `${prefix} findError = TRUE;`, `${prefix}}`);
|
|
292
|
-
}
|
|
293
|
-
if (!isGet) {
|
|
294
|
-
lines.push(`${prefix}if (findError) {`, `${prefix} SetErrMsg(msg);`, `${prefix} return E_FAIL;`, `${prefix}}`);
|
|
295
|
-
}
|
|
296
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
297
|
-
}
|
|
298
|
-
/** 判断 Catalog 块是否保留 Item:仅排除旧保留段 ID 100~199。 */
|
|
299
|
-
function ktCodegenIsCaaCatalogItem(item, nameSuffix) {
|
|
300
|
-
return (item.nameSuffix === nameSuffix &&
|
|
301
|
-
!(item.id >= 100 && item.id < 200));
|
|
302
|
-
}
|
|
303
|
-
/** 按旧 Catalog 参数注册格式生成注释、SetValue 和列表追加语句。 */
|
|
304
|
-
function ktCodegenRenderCaaCatalogLines(region, items, algorithms) {
|
|
305
|
-
const prefix = region.start.linePrefix;
|
|
306
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
307
|
-
for (const item of items) {
|
|
308
|
-
const notes = item.notes.length > 0 ? `\t${item.notes}` : "";
|
|
309
|
-
lines.push(`${prefix}// ${item.id}; \t${item.name}; ${item.author}; ${item.createDate};${notes}`);
|
|
310
|
-
const listValue = item.isList || algorithms.isPointOrVector3DType(item.dataType);
|
|
311
|
-
const setFunction = listValue ? "SetTKListValue" : "SetValue";
|
|
312
|
-
lines.push(`${prefix}item.${setFunction}("${item.paramString}", ${item.tcKind}, ${item.catAttrInOut});`, `${prefix}itemList.push_back(item);`);
|
|
313
|
-
}
|
|
314
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
315
|
-
}
|
|
316
|
-
/** 判断 Factory On Tree 块是否保留 Item。 */
|
|
317
|
-
function ktCodegenIsCaaFactoryTreeItem(item, nameSuffix) {
|
|
318
|
-
return (item.nameSuffix === nameSuffix &&
|
|
319
|
-
item.id >= -1 &&
|
|
320
|
-
(item.isOnTree || item.id === -1));
|
|
321
|
-
}
|
|
322
|
-
/** 按旧 Factory On Tree 规则生成参数工厂创建和树显示标志。 */
|
|
323
|
-
function ktCodegenRenderCaaFactoryTreeLines(region, items, formatTreeName) {
|
|
324
|
-
const prefix = region.start.linePrefix;
|
|
325
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
326
|
-
for (const item of items) {
|
|
327
|
-
lines.push("");
|
|
328
|
-
const notes = item.notes.length > 0 ? ` ${item.notes}` : "";
|
|
329
|
-
lines.push(`${prefix}// ${item.id}, ${item.paramString},${notes}`);
|
|
330
|
-
if (item.tcKind !== "tk_specobject") {
|
|
331
|
-
// 旧代码把校验错误直接写进候选代码,且不附加 `_prefix`。
|
|
332
|
-
lines.push("发现错误,TCKKind应该是tk_specobject");
|
|
333
|
-
}
|
|
334
|
-
lines.push(`${prefix}spListParmName.Append("${item.paramString}");`);
|
|
335
|
-
if (item.id === -1) {
|
|
336
|
-
lines.push(`${prefix}spListParm.Append(piParmFactory->CreateInteger("Temp Spec", 0));`);
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
const unit = item.unit.toLowerCase();
|
|
340
|
-
let createFunction;
|
|
341
|
-
if (unit === "mm") {
|
|
342
|
-
if (item.dataType !== "double")
|
|
343
|
-
lines.push("发现错误,DataType应该是double");
|
|
344
|
-
createFunction = "CreateLength";
|
|
345
|
-
}
|
|
346
|
-
else if (unit === "degree") {
|
|
347
|
-
if (item.dataType !== "double")
|
|
348
|
-
lines.push("发现错误,DataType应该是double");
|
|
349
|
-
createFunction = "CreateAngle";
|
|
350
|
-
}
|
|
351
|
-
else if (item.dataType === "int") {
|
|
352
|
-
createFunction = "CreateInteger";
|
|
353
|
-
}
|
|
354
|
-
else if (item.dataType === "double") {
|
|
355
|
-
createFunction = "CreateReal";
|
|
356
|
-
}
|
|
357
|
-
else if (item.dataType === "CATBoolean") {
|
|
358
|
-
createFunction = "CreateBoolean";
|
|
359
|
-
}
|
|
360
|
-
else if (item.dataType === "CATUnicodeString") {
|
|
361
|
-
createFunction = "CreateString";
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
createFunction = `没有处理此类型<${item.dataType}>请告知杨海华`;
|
|
365
|
-
}
|
|
366
|
-
const title = formatTreeName(item.paramString);
|
|
367
|
-
lines.push(`${prefix}spListParm.Append(piParmFactory->${createFunction}("${title}", parameter->${item.paramString}));`);
|
|
368
|
-
}
|
|
369
|
-
lines.push(`${prefix}ListOnTree.Append(${item.id === -1 ? "false" : "true"});`);
|
|
370
|
-
}
|
|
371
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
372
|
-
}
|
|
373
|
-
/** 判断旧 CAA Dialog 通知和双向更新块是否保留当前 Item。 */
|
|
374
|
-
function ktCodegenIsCaaDialogItem(item, nameSuffix) {
|
|
375
|
-
return item.nameSuffix === nameSuffix && item.id >= 1;
|
|
376
|
-
}
|
|
377
|
-
/** 按旧 CAA Dialog Agent 规则生成各控件的 AcceptOnNotify。 */
|
|
378
|
-
function ktCodegenRenderCaaDialogNotifyLines(region, items, isCaaVector) {
|
|
379
|
-
const prefix = region.start.linePrefix;
|
|
380
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
381
|
-
for (const item of items) {
|
|
382
|
-
lines.push("");
|
|
383
|
-
const dialogPointer = item.isParamDlg ? "dialogMore->" : "";
|
|
384
|
-
const paramName = item.paramString.replaceAll("_", "");
|
|
385
|
-
const notes = `${prefix}// ${item.id}, ${item.paramString}`;
|
|
386
|
-
if (item.componentCount <= 0) {
|
|
387
|
-
lines.push(`${notes}, NO ACTION, ${item.component}, ${item.componentCount}`);
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
if (item.component === "Spinner") {
|
|
391
|
-
lines.push(notes);
|
|
392
|
-
const component = `${dialogPointer}_Spinner${paramName}`;
|
|
393
|
-
const suffixes = isCaaVector(item) ? ["X", "Y", "Z"] : [""];
|
|
394
|
-
for (const suffix of suffixes) {
|
|
395
|
-
const control = `${component}${suffix}`;
|
|
396
|
-
lines.push(`${prefix}ipDialogAgent->AcceptOnNotify(${control}, ${control}->GetSpinnerModifyNotification());`);
|
|
397
|
-
}
|
|
398
|
-
continue;
|
|
399
|
-
}
|
|
400
|
-
if (item.component.startsWith("CheckButton")) {
|
|
401
|
-
lines.push(notes);
|
|
402
|
-
const component = `${dialogPointer}_CheckButton${paramName}`;
|
|
403
|
-
if (item.componentCount === 1) {
|
|
404
|
-
lines.push(`${prefix}ipDialogAgent->AcceptOnNotify(${component}, ${component}->GetChkBModifyNotification());`);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
408
|
-
const control = `${component}${index}`;
|
|
409
|
-
lines.push(`${prefix}ipDialogAgent->AcceptOnNotify(${control}, ${control}->GetChkBModifyNotification());`);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
if (item.component.startsWith("RadioButton")) {
|
|
415
|
-
lines.push(notes);
|
|
416
|
-
const component = `${dialogPointer}_RadioButton${paramName}`;
|
|
417
|
-
// 旧代码会把共享 ComponentCount 由1改为2;这里只使用局部值保持输出。
|
|
418
|
-
const count = item.componentCount === 1 ? 2 : item.componentCount;
|
|
419
|
-
for (let index = 0; index < count; index += 1) {
|
|
420
|
-
const control = `${component}${index}`;
|
|
421
|
-
lines.push(`${prefix}ipDialogAgent->AcceptOnNotify(${control}, ${control}->GetRadBModifyNotification());`);
|
|
422
|
-
}
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
if (item.component.startsWith("Combo")) {
|
|
426
|
-
lines.push(notes);
|
|
427
|
-
const component = `${dialogPointer}_Combo${paramName}`;
|
|
428
|
-
lines.push(`${prefix}ipDialogAgent->AcceptOnNotify(${component}, ${component}->GetComboModifyNotification());`);
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
if (item.component === "Editor") {
|
|
432
|
-
lines.push(notes);
|
|
433
|
-
const component = `${dialogPointer}_Editor${paramName}`;
|
|
434
|
-
if (item.componentCount === 1) {
|
|
435
|
-
lines.push(`${prefix}ipDialogAgent->AcceptOnNotify(${component}, ${component}->GetEditModifyNotification());`);
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
439
|
-
const control = `${component}${index}`;
|
|
440
|
-
lines.push(`${prefix}ipDialogAgent->AcceptOnNotify(${control}, ${control}->GetEditModifyNotification());`);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
lines.push(`${notes}, NOT SUPPORT, ${item.component}, ${item.componentCount}`);
|
|
446
|
-
}
|
|
447
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
448
|
-
}
|
|
449
|
-
/** 取得旧 UI 多控件分支使用的集合起始下标;不支持时返回 `null`。 */
|
|
450
|
-
function ktCodegenLegacyDialogListIndex(dataType, includeFloat) {
|
|
451
|
-
if (dataType === "CATRawColldouble")
|
|
452
|
-
return 1;
|
|
453
|
-
if (dataType === "ListKtdouble" || dataType === "ListKtint")
|
|
454
|
-
return 0;
|
|
455
|
-
if (includeFloat && dataType === "ListKtfloat")
|
|
456
|
-
return 0;
|
|
457
|
-
return null;
|
|
458
|
-
}
|
|
459
|
-
/** 生成移除下划线后的旧 CAA/Qt 控件成员后缀。 */
|
|
460
|
-
function ktCodegenDialogParamName(item) {
|
|
461
|
-
return item.paramString.replaceAll("_", "");
|
|
462
|
-
}
|
|
463
|
-
/** 按旧 `CreateCAAUpdateDialog` 规则把共享参数写入 CAA 控件。 */
|
|
464
|
-
function ktCodegenRenderCaaUpdateDialogLines(context, region, items, isCaaVector) {
|
|
465
|
-
const prefix = region.start.linePrefix;
|
|
466
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
467
|
-
for (const item of items) {
|
|
468
|
-
lines.push("");
|
|
469
|
-
const dialogPointer = item.isParamDlg ? "dialogMore->" : "";
|
|
470
|
-
const param = `parameter->${item.paramString}`;
|
|
471
|
-
const name = ktCodegenDialogParamName(item);
|
|
472
|
-
const notes = `// ${item.id},${item.paramString},${item.notes}`;
|
|
473
|
-
if (item.componentCount <= 0) {
|
|
474
|
-
lines.push(`${prefix}${notes},NO ACTION,${item.component},${item.componentCount}`);
|
|
475
|
-
continue;
|
|
476
|
-
}
|
|
477
|
-
if (item.component === "Spinner") {
|
|
478
|
-
lines.push(`${prefix}${notes}`);
|
|
479
|
-
const component = `${dialogPointer}_Spinner${name}`;
|
|
480
|
-
if (isCaaVector(item)) {
|
|
481
|
-
const unitFactor = item.unit === "mm" ? " * 0.001" : "";
|
|
482
|
-
lines.push(`${prefix}${component}X->SetValue(${param}.GetX()${unitFactor}, 0);`, `${prefix}${component}Y->SetValue(${param}.GetY()${unitFactor}, 0);`, `${prefix}${component}Z->SetValue(${param}.GetZ()${unitFactor}, 0);`);
|
|
483
|
-
}
|
|
484
|
-
else if (item.componentCount === 1) {
|
|
485
|
-
lines.push(`${prefix}${component}->SetValue(${param}, 0);`);
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
const indexSub = ktCodegenLegacyDialogListIndex(item.dataType, true);
|
|
489
|
-
if (indexSub === null) {
|
|
490
|
-
// 旧 VB 故意把错误文本写入候选源码,且不附加 `_prefix`。
|
|
491
|
-
lines.push("data type is wrong!");
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
const unitFactor = item.unit === "mm" ? " * 0.001" : "";
|
|
495
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
496
|
-
lines.push(`${prefix}${component}${index}->SetValue(${param}[${index + indexSub}]${unitFactor}, 0);`);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
continue;
|
|
501
|
-
}
|
|
502
|
-
if (item.component.startsWith("CheckButton")) {
|
|
503
|
-
lines.push(`${prefix}${notes}`);
|
|
504
|
-
const component = `${dialogPointer}_CheckButton${name}`;
|
|
505
|
-
if (item.componentCount === 1) {
|
|
506
|
-
lines.push(`${prefix}${component}->SetState(${param} ? CATDlgCheck : CATDlgUncheck, 0);`);
|
|
507
|
-
}
|
|
508
|
-
else {
|
|
509
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
510
|
-
lines.push(`${prefix}${component}${index}->SetState( (${param} & (1<<${index}))? CATDlgCheck:CATDlgUncheck, 0);`);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
if (item.component.startsWith("RadioButton")) {
|
|
516
|
-
const component = `${dialogPointer}_RadioButton${name}`;
|
|
517
|
-
// 旧方法会将共享 count=1 改成2;局部修正可保持输出且不污染 Analyze。
|
|
518
|
-
const count = item.componentCount === 1 ? 2 : item.componentCount;
|
|
519
|
-
const lastIndex = count - 1;
|
|
520
|
-
// 原方法在 Radio 分支重复追加了同一条参数注释。
|
|
521
|
-
lines.push(`${prefix}${notes}`, `${prefix}${notes}`);
|
|
522
|
-
lines.push(`${prefix}if (${param} > ${lastIndex} || ${param} < 0) // BR`, `${prefix} ${param} = (${item.dataType})0;`);
|
|
523
|
-
for (let index = 0; index < count; index += 1) {
|
|
524
|
-
lines.push(`${prefix}${component}${index}->SetState((${param} == ${index}) ? CATDlgCheck : CATDlgUncheck, 0);`);
|
|
525
|
-
}
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
if (item.component.startsWith("Combo")) {
|
|
529
|
-
const component = `${dialogPointer}_Combo${name}`;
|
|
530
|
-
if (item.dataType === "int") {
|
|
531
|
-
lines.push(`${prefix}${component}->SetSelect( ${param}, 0);`);
|
|
532
|
-
}
|
|
533
|
-
else if (item.dataType === "double" || item.dataType === "CATUnicodeString") {
|
|
534
|
-
lines.push(`${prefix}${component}->SetField( ${param});`);
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
lines.push(`${prefix}${component},NO ACTION,Data Type Error, ${item.dataType}`);
|
|
538
|
-
}
|
|
539
|
-
continue;
|
|
540
|
-
}
|
|
541
|
-
if (item.component === "SelectorList") {
|
|
542
|
-
lines.push(`${prefix}${notes}`);
|
|
543
|
-
let withNoSelection = false;
|
|
544
|
-
if (item.paramString === "OriginSpec") {
|
|
545
|
-
withNoSelection = true;
|
|
546
|
-
lines.push(`${prefix}NoSelectionMsg=${context.param.nameSpace}::GetCoordString(parameter->OriginCoord);`);
|
|
547
|
-
}
|
|
548
|
-
else if (item.paramString === "XDirectionSpec") {
|
|
549
|
-
withNoSelection = true;
|
|
550
|
-
lines.push(`${prefix}NoSelectionMsg=${context.param.nameSpace}::GetCoordString(parameter->XDirectionCoord,parameter->XDirectionSign);`);
|
|
551
|
-
}
|
|
552
|
-
else if (item.paramString === "YDirectionSpec") {
|
|
553
|
-
withNoSelection = true;
|
|
554
|
-
lines.push(`${prefix}NoSelectionMsg=${context.param.nameSpace}::GetCoordString(parameter->YDirectionCoord,parameter->YDirectionSign);`);
|
|
555
|
-
}
|
|
556
|
-
else if (item.paramString === "AxisSpec") {
|
|
557
|
-
withNoSelection = true;
|
|
558
|
-
lines.push(`${prefix}NoSelectionMsg="Default(Absolute)";`);
|
|
559
|
-
}
|
|
560
|
-
const component = `${dialogPointer}_SelectorList${name}`;
|
|
561
|
-
lines.push(`${prefix}KT_AUTO_FIELD_SET_LINE(${component}, ${param}${withNoSelection ? ", &NoSelectionMsg" : ""});`);
|
|
562
|
-
continue;
|
|
563
|
-
}
|
|
564
|
-
if (item.component === "Editor") {
|
|
565
|
-
const component = `${dialogPointer}_Editor${name}`;
|
|
566
|
-
const functionName = item.dataType === "double" || item.dataType === "int" ? "SetValue" : "SetText";
|
|
567
|
-
if (item.componentCount === 1) {
|
|
568
|
-
lines.push(`${prefix}${component}->${functionName}(${param}, 0);`);
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
572
|
-
lines.push(`${prefix}${component}${index}->${functionName}(${param}[${index + 1}], 0);`);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
const supportNote = item.component.length === 0 || item.component === "PushButton"
|
|
578
|
-
? ""
|
|
579
|
-
: " (Not Support)";
|
|
580
|
-
lines.push(`${prefix}${notes},NO ACTION,${item.component}${supportNote},${item.componentCount}`);
|
|
581
|
-
}
|
|
582
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
583
|
-
}
|
|
584
|
-
/** 按旧 `CreateCAAUpdateInfors` 规则把 CAA 控件值写回共享参数。 */
|
|
585
|
-
function ktCodegenRenderCaaUpdateInforsLines(region, items, isCaaVector) {
|
|
586
|
-
const prefix = region.start.linePrefix;
|
|
587
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
588
|
-
for (const item of items) {
|
|
589
|
-
lines.push("");
|
|
590
|
-
const dialogPointer = item.isParamDlg ? "dialogMore->" : "";
|
|
591
|
-
const param = `parameter->${item.paramString}`;
|
|
592
|
-
const name = ktCodegenDialogParamName(item);
|
|
593
|
-
let notes = `// ${item.id},${item.paramString},${item.notes}`;
|
|
594
|
-
const generated = [];
|
|
595
|
-
const convertToInt = item.tcKind === "tk_integer" && item.dataType.toLowerCase() !== "int";
|
|
596
|
-
if (item.componentCount <= 0) {
|
|
597
|
-
notes += `,NO ACTION, ${item.component},${item.componentCount}`;
|
|
598
|
-
}
|
|
599
|
-
else if (item.component === "Spinner") {
|
|
600
|
-
const component = `${dialogPointer}_Spinner${name}`;
|
|
601
|
-
if (isCaaVector(item)) {
|
|
602
|
-
const unitFactor = item.unit === "mm" ? " * 1000.0" : "";
|
|
603
|
-
generated.push(`${prefix}${param}.SetX(${component}X->GetValue()${unitFactor});`, `${prefix}${param}.SetY(${component}Y->GetValue()${unitFactor});`, `${prefix}${param}.SetZ(${component}Z->GetValue()${unitFactor});`);
|
|
604
|
-
}
|
|
605
|
-
else if (item.componentCount === 1) {
|
|
606
|
-
const value = `${component}->GetValue()`;
|
|
607
|
-
generated.push(`${prefix}${param} = ${item.dataType === "int" ? `Kt::round(${value})` : value};`);
|
|
608
|
-
}
|
|
609
|
-
else {
|
|
610
|
-
const indexSub = ktCodegenLegacyDialogListIndex(item.dataType, true);
|
|
611
|
-
if (indexSub === null) {
|
|
612
|
-
notes += "data type is wrong";
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
616
|
-
const value = `${component}${index}->GetValue()`;
|
|
617
|
-
const rounded = item.dataType === "int" ? `Kt::round(${value})` : value;
|
|
618
|
-
generated.push(`${prefix}${param}[${index + indexSub}] = ${rounded};${item.dataType === "int" ? "//round" : ""}`);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
else if (item.component.startsWith("CheckButton")) {
|
|
624
|
-
const component = `${dialogPointer}_CheckButton${name}`;
|
|
625
|
-
if (item.componentCount === 1) {
|
|
626
|
-
const value = `${component}->GetState() == CATDlgCheck ? TRUE : FALSE`;
|
|
627
|
-
generated.push(`${prefix}${param} = ${item.dataType === "int" ? value : `(${item.dataType})(int)(${value})`};`);
|
|
628
|
-
}
|
|
629
|
-
else {
|
|
630
|
-
generated.push(`${prefix}${param}=0;`);
|
|
631
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
632
|
-
const linePrefix = index === 0 ? " " : prefix;
|
|
633
|
-
generated.push(`${linePrefix}if (${component}${index}->GetState() == CATDlgCheck)${param} = ${param} | (1<<${index});`);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
else if (item.component.startsWith("RadioButton")) {
|
|
638
|
-
const component = `${dialogPointer}_RadioButton${name}`;
|
|
639
|
-
const count = item.componentCount === 1 ? 2 : item.componentCount;
|
|
640
|
-
generated.push(`${prefix}${param} = (${item.dataType})0;`);
|
|
641
|
-
for (let index = 1; index < count; index += 1) {
|
|
642
|
-
generated.push(`${prefix}if (${component}${index}->GetState() == CATDlgCheck) // BR`, `${prefix} ${param} = ${convertToInt ? `(${item.dataType})` : ""}${index};`);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
else if (item.component.startsWith("Combo")) {
|
|
646
|
-
const component = `${dialogPointer}_Combo${name}`;
|
|
647
|
-
if (item.dataType === "int") {
|
|
648
|
-
generated.push(`${prefix}${param} = ${component}->GetSelect();`);
|
|
649
|
-
}
|
|
650
|
-
else if (item.dataType === "double") {
|
|
651
|
-
generated.push(`${prefix}${param} = ${component}->GetField();`);
|
|
652
|
-
}
|
|
653
|
-
else if (item.dataType === "CATUnicodeString") {
|
|
654
|
-
generated.push(`${prefix}${component}->GetField(${param});`);
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
notes += `,NO ACTION,Data Type Error,${item.dataType}`;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
else if (item.component === "Editor") {
|
|
661
|
-
const component = `${dialogPointer}_Editor${name}`;
|
|
662
|
-
const functionName = item.dataType === "double" ? "GetValue" : "GetText";
|
|
663
|
-
if (item.componentCount === 1) {
|
|
664
|
-
generated.push(`${prefix}${param} = ${component}->${functionName}();`);
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
668
|
-
generated.push(`${prefix}${param}[${index + 1}] = ${component}${index}->${functionName}();`);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
else {
|
|
673
|
-
const supportNote = item.component.length === 0 ||
|
|
674
|
-
item.component === "PushButton" ||
|
|
675
|
-
item.component === "SelectorList" ||
|
|
676
|
-
item.component === "MultiList"
|
|
677
|
-
? ""
|
|
678
|
-
: " (Not Support)";
|
|
679
|
-
notes += `,NO ACTION,${item.component}${supportNote},${item.componentCount}`;
|
|
680
|
-
}
|
|
681
|
-
lines.push(`${prefix}${notes}`, ...generated);
|
|
682
|
-
}
|
|
683
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
684
|
-
}
|
|
685
|
-
/** 按旧 `CreateQTUpdateDialog` 规则把共享参数写入 Qt 控件。 */
|
|
686
|
-
function ktCodegenRenderQtUpdateDialogLines(region, items, isPointOrVector3DType) {
|
|
687
|
-
const prefix = region.start.linePrefix;
|
|
688
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
689
|
-
for (const item of items) {
|
|
690
|
-
lines.push("");
|
|
691
|
-
const dialogPointer = item.isParamDlg ? "dialogMore->" : "ui->";
|
|
692
|
-
const param = `parameter->${item.paramString}`;
|
|
693
|
-
const name = ktCodegenDialogParamName(item);
|
|
694
|
-
let notes = `// ${item.id}, ${item.paramString}, ${item.notes}`;
|
|
695
|
-
const generated = [];
|
|
696
|
-
if (item.componentCount <= 0) {
|
|
697
|
-
notes += `,NO ACTION, ${item.component},${item.componentCount}`;
|
|
698
|
-
}
|
|
699
|
-
else if (item.component === "QListWidget") {
|
|
700
|
-
generated.push(`${prefix}KT_AUTO_FIELD_SET_LINE(${dialogPointer}listWidget${name}, ${param});`);
|
|
701
|
-
}
|
|
702
|
-
else if (item.component === "QDoubleSpinBox" || item.component === "QSpinBox") {
|
|
703
|
-
const componentStem = item.component === "QDoubleSpinBox" ? "doubleSpinBox" : "spinBox";
|
|
704
|
-
const component = `${dialogPointer}${componentStem}${name}`;
|
|
705
|
-
if (isPointOrVector3DType(item.dataType)) {
|
|
706
|
-
const unitFactor = item.unit === "mm" ? " * 0.001" : "";
|
|
707
|
-
generated.push(`${prefix}${component}X->setValue(${param}.GetX()${unitFactor});`, `${prefix}${component}Y->setValue(${param}.GetY()${unitFactor});`, `${prefix}${component}Z->setValue(${param}.GetZ()${unitFactor});`);
|
|
708
|
-
}
|
|
709
|
-
else if (item.componentCount === 1) {
|
|
710
|
-
generated.push(`${prefix}${component}->setValue(${param});`);
|
|
711
|
-
}
|
|
712
|
-
else {
|
|
713
|
-
const indexSub = ktCodegenLegacyDialogListIndex(item.dataType, item.component === "QSpinBox");
|
|
714
|
-
if (indexSub === null) {
|
|
715
|
-
notes += "Data type is not suitable for auto code.";
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
const unitFactor = item.unit === "mm" ? " * 0.001" : "";
|
|
719
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
720
|
-
generated.push(`${prefix}${component}${index}->setValue(${param}[${index + indexSub}]${unitFactor});`);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
else if (item.component.startsWith("QCheckBox")) {
|
|
726
|
-
const component = `${dialogPointer}checkBox${name}`;
|
|
727
|
-
if (item.componentCount === 1) {
|
|
728
|
-
generated.push(`${prefix}${component}->setChecked(${param});`);
|
|
729
|
-
}
|
|
730
|
-
else {
|
|
731
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
732
|
-
generated.push(`${prefix}${component}${index}->setChecked( ${param} & (1<<${index}));`);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
else if (item.component.startsWith("QRadioButton")) {
|
|
737
|
-
const component = `${dialogPointer}radioButton${name}`;
|
|
738
|
-
const count = item.componentCount === 1 ? 2 : item.componentCount;
|
|
739
|
-
const lastIndex = count - 1;
|
|
740
|
-
generated.push(`${prefix}if (${param}>${lastIndex} || ${param}<0) ${param}=0;//Correct`);
|
|
741
|
-
for (let index = 0; index < count; index += 1) {
|
|
742
|
-
generated.push(`${prefix}${component}${index}->setChecked( ${param}==${index});`);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
else if (item.component.startsWith("QComboBox")) {
|
|
746
|
-
const component = `${dialogPointer}comboBox${name}`;
|
|
747
|
-
if (item.dataType === "int" ||
|
|
748
|
-
item.dataType === "short" ||
|
|
749
|
-
item.dataType === "uint32_t") {
|
|
750
|
-
generated.push(`${prefix}${component}->setCurrentIndex(${param});`);
|
|
751
|
-
}
|
|
752
|
-
else if (item.dataType === "QString") {
|
|
753
|
-
generated.push(`${prefix}${component}->setEditText(${param});`);
|
|
754
|
-
}
|
|
755
|
-
else {
|
|
756
|
-
// 原 VB 使用普通字符串而非插值字符串,故输出中保留字面占位符。
|
|
757
|
-
generated.push(`${prefix}${component}->setEditText(QString::fromLocal8Bit({strParamSame}.str()));`);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
else if (item.component === "QLineEdit") {
|
|
761
|
-
const component = `${dialogPointer}lineEdit${name}`;
|
|
762
|
-
const value = item.dataType === "KtString"
|
|
763
|
-
? ` QString::fromLocal8Bit(${param}.str()) `
|
|
764
|
-
: param;
|
|
765
|
-
if (item.componentCount === 1) {
|
|
766
|
-
generated.push(`${prefix}${component}->setText( ${value});`);
|
|
767
|
-
}
|
|
768
|
-
else {
|
|
769
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
770
|
-
generated.push(`${prefix}${component}${index}->setText(${value}[${index + 1}]);`);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
const supportNote = item.component.length === 0 || item.component === "QPushButton"
|
|
776
|
-
? ""
|
|
777
|
-
: " (Not Support)";
|
|
778
|
-
notes += `,NO ACTION, ${item.component}${supportNote},${item.componentCount}`;
|
|
779
|
-
}
|
|
780
|
-
lines.push(`${prefix}${notes}`, ...generated);
|
|
781
|
-
}
|
|
782
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
783
|
-
}
|
|
784
|
-
/** 按旧 `CreateQTUpdateInfors` 规则把 Qt 控件值写回共享参数。 */
|
|
785
|
-
function ktCodegenRenderQtUpdateInforsLines(region, items, isPointOrVector3DType) {
|
|
786
|
-
const prefix = region.start.linePrefix;
|
|
787
|
-
const lines = ktCodegenRenderLegacyStart(region);
|
|
788
|
-
for (const item of items) {
|
|
789
|
-
lines.push("");
|
|
790
|
-
const dialogPointer = item.isParamDlg ? "dialogMore->" : "ui->";
|
|
791
|
-
const param = `parameter->${item.paramString}`;
|
|
792
|
-
const name = ktCodegenDialogParamName(item);
|
|
793
|
-
let notes = `// ${item.id}, ${item.paramString}, ${item.notes}`;
|
|
794
|
-
const generated = [];
|
|
795
|
-
const convertToInt = item.tcKind === "tk_integer" && item.dataType.toLowerCase() !== "int";
|
|
796
|
-
if (item.componentCount <= 0) {
|
|
797
|
-
notes += `,NO ACTION, ${item.component},${item.componentCount}`;
|
|
798
|
-
}
|
|
799
|
-
else if (item.component === "QDoubleSpinBox" || item.component === "QSpinBox") {
|
|
800
|
-
const componentStem = item.component === "QDoubleSpinBox" ? "doubleSpinBox" : "spinBox";
|
|
801
|
-
const component = `${dialogPointer}${componentStem}${name}`;
|
|
802
|
-
if (isPointOrVector3DType(item.dataType)) {
|
|
803
|
-
const unitFactor = item.unit === "mm" ? " * 1000.0" : "";
|
|
804
|
-
generated.push(`${prefix}${param}.SetX(${component}X->value()${unitFactor});`, `${prefix}${param}.SetY(${component}Y->value()${unitFactor});`, `${prefix}${param}.SetZ(${component}Z->value()${unitFactor});`);
|
|
805
|
-
}
|
|
806
|
-
else if (item.componentCount === 1) {
|
|
807
|
-
const value = `${component}->value()`;
|
|
808
|
-
if (item.component === "QDoubleSpinBox" && item.dataType === "int") {
|
|
809
|
-
generated.push(`${prefix}${param} = Kt::round(${value}); //round to int`);
|
|
810
|
-
}
|
|
811
|
-
else {
|
|
812
|
-
generated.push(`${prefix}${param} = ${value};`);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
else {
|
|
816
|
-
const indexSub = ktCodegenLegacyDialogListIndex(item.dataType, true);
|
|
817
|
-
if (indexSub === null) {
|
|
818
|
-
notes += "Data type is not suitable for auto code.";
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
821
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
822
|
-
const value = `${component}${index}->value()`;
|
|
823
|
-
const rounded = item.component === "QDoubleSpinBox" && item.dataType === "int"
|
|
824
|
-
? `Kt::round(${value})`
|
|
825
|
-
: value;
|
|
826
|
-
generated.push(`${prefix}${param}[${index + indexSub}] = ${rounded};${rounded !== value ? " //round to int" : ""}`);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
else if (item.component.startsWith("QCheckBox")) {
|
|
832
|
-
const component = `${dialogPointer}checkBox${name}`;
|
|
833
|
-
if (item.componentCount === 1) {
|
|
834
|
-
generated.push(`${prefix}${param} = ${component}->isChecked();`);
|
|
835
|
-
}
|
|
836
|
-
else {
|
|
837
|
-
generated.push(`${prefix}${param}=0;`);
|
|
838
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
839
|
-
generated.push(`${prefix}if (${component}${index}->isChecked()) { ${param} = ${param} | (1<<${index}); }`);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
else if (item.component.startsWith("QRadioButton")) {
|
|
844
|
-
const component = `${dialogPointer}radioButton${name}`;
|
|
845
|
-
const count = item.componentCount === 1 ? 2 : item.componentCount;
|
|
846
|
-
generated.push(`${prefix}${param} = 0;//默认值0`);
|
|
847
|
-
for (let index = 0; index < count; index += 1) {
|
|
848
|
-
generated.push(`${prefix}if (${component}${index}->isChecked())`, `${prefix} ${param} = ${convertToInt ? `(${item.dataType})` : ""}${index};${convertToInt ? "}" : ""}`);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
else if (item.component.startsWith("QComboBox")) {
|
|
852
|
-
const component = `${dialogPointer}comboBox${name}`;
|
|
853
|
-
if (item.dataType === "int" ||
|
|
854
|
-
item.dataType === "short" ||
|
|
855
|
-
item.dataType === "uint32_t") {
|
|
856
|
-
generated.push(`${prefix}${param} = ${component}->currentIndex();`);
|
|
857
|
-
}
|
|
858
|
-
else if (item.dataType === "QString") {
|
|
859
|
-
generated.push(`${prefix}${param} = ${component}->currentText();`);
|
|
860
|
-
}
|
|
861
|
-
else {
|
|
862
|
-
generated.push(`${prefix}${param} = ${component}->currentText().toLocal8Bit().constData();`);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
else if (item.component === "QLineEdit") {
|
|
866
|
-
const component = `${dialogPointer}lineEdit${name}`;
|
|
867
|
-
const conversion = item.dataType === "KtString" ? ".toLocal8Bit().constData()" : "";
|
|
868
|
-
if (item.componentCount === 1) {
|
|
869
|
-
generated.push(`${prefix}${param} = ${component}->text()${conversion};`);
|
|
870
|
-
}
|
|
871
|
-
else {
|
|
872
|
-
for (let index = 0; index < item.componentCount; index += 1) {
|
|
873
|
-
generated.push(`${prefix}${param}[${index + 1}] = ${component}${index}->text()${conversion};`);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
else {
|
|
878
|
-
notes += `,NO ACTION, ${item.component} (Not Support),${item.componentCount}`;
|
|
879
|
-
}
|
|
880
|
-
lines.push(`${prefix}${notes}`, ...generated);
|
|
881
|
-
}
|
|
882
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
883
|
-
}
|
|
884
|
-
/** 生成已迁移的 Qt Dialog/Parameter 更新块。 */
|
|
885
|
-
function ktCodegenRenderQt(context, algorithms) {
|
|
886
|
-
const artifacts = [];
|
|
887
|
-
const diagnostics = [];
|
|
888
|
-
const requestedBlocks = new Set(context.blockKeys);
|
|
889
|
-
for (const region of context.markerRegions) {
|
|
890
|
-
if (!KT_CODEGEN_QT_MIGRATED_BLOCKS.has(region.blockKey) ||
|
|
891
|
-
!requestedBlocks.has(region.blockKey) ||
|
|
892
|
-
ktCodegenGetBlock(region.blockKey).target !== context.target) {
|
|
893
|
-
continue;
|
|
894
|
-
}
|
|
895
|
-
const items = context.param.items.filter((item) => item.nameSuffix === region.nameSuffix && item.id >= 1);
|
|
896
|
-
const lines = region.blockKey === "QT UPDATE DIALOG"
|
|
897
|
-
? ktCodegenRenderQtUpdateDialogLines(region, items, algorithms.isPointOrVector3DType)
|
|
898
|
-
: ktCodegenRenderQtUpdateInforsLines(region, items, algorithms.isPointOrVector3DType);
|
|
899
|
-
ktCodegenAppendRegionArtifact(context, region, items, lines, artifacts, diagnostics);
|
|
900
|
-
}
|
|
901
|
-
const targetBlocks = context.blockKeys.filter((blockKey) => ktCodegenGetBlock(blockKey).target === context.target);
|
|
902
|
-
const pendingBlocks = targetBlocks.filter((blockKey) => !KT_CODEGEN_QT_MIGRATED_BLOCKS.has(blockKey));
|
|
903
|
-
const status = pendingBlocks.length === 0 ? "ready" : "scaffold";
|
|
904
|
-
if (status === "scaffold") {
|
|
905
|
-
diagnostics.push({
|
|
906
|
-
code: "renderer.blocks-pending",
|
|
907
|
-
severity: "info",
|
|
908
|
-
message: `${context.target} still has pending blocks: ${pendingBlocks.join(", ")}.`,
|
|
909
|
-
path: { source: "renderer", field: context.target },
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
return { status, artifacts, diagnostics };
|
|
913
|
-
}
|
|
914
|
-
/** 取得旧 `KevinControlID.ToString()` 写入 Selector 块的枚举名称。 */
|
|
915
|
-
function ktCodegenSelectorBlockTitle(blockKey) {
|
|
916
|
-
switch (blockKey) {
|
|
917
|
-
case "DLG DEFINE FIELD TYPE":
|
|
918
|
-
return "DlgDefineFieldType";
|
|
919
|
-
case "DLG SET ACTIVE FIELD":
|
|
920
|
-
return "DlgSetActiveField";
|
|
921
|
-
case "DLG GET SELECTOR LIST":
|
|
922
|
-
return "DlgGetSelectorList";
|
|
923
|
-
case "CMD AGENT DECLARE":
|
|
924
|
-
return "CmdAgentDeclare";
|
|
925
|
-
case "CMD AGENT CONSTRUCTOR":
|
|
926
|
-
return "CmdAgentConstructor";
|
|
927
|
-
case "CMD AGENT DESTRUCTOR":
|
|
928
|
-
return "CmdAgentDestructor";
|
|
929
|
-
case "CMD AGENT BUILD GRAPH":
|
|
930
|
-
return "CmdAgentBuildGraph";
|
|
931
|
-
case "CMD AGENT UPDATE STATE":
|
|
932
|
-
return "CmdAgentUpdateState";
|
|
933
|
-
case "CMD AGENT FIA CLEAR":
|
|
934
|
-
return "CmdAgentFiaClear";
|
|
935
|
-
case "CMD ACTION PDA":
|
|
936
|
-
return "CmdActionPda";
|
|
937
|
-
case "CMD ACTION FIA":
|
|
938
|
-
return "CmdActionFia";
|
|
939
|
-
case "CMD ELEMENT SELECTED":
|
|
940
|
-
return "CmdElementSelected";
|
|
941
|
-
case "CMD SET ACTIVE FIELD":
|
|
942
|
-
return "CmdSetActiveField";
|
|
943
|
-
default:
|
|
944
|
-
throw new Error(`Unsupported selector block: ${blockKey}`);
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
/** 按旧 `AutoCodeStartSelector` 规则生成 Field 块公共头部。 */
|
|
948
|
-
function ktCodegenRenderSelectorStart(region, notes = []) {
|
|
949
|
-
const prefix = region.start.linePrefix;
|
|
950
|
-
const separator = "//.............................................................................";
|
|
951
|
-
return [
|
|
952
|
-
...ktCodegenRenderLegacyStart(region),
|
|
953
|
-
`${prefix}${separator}`,
|
|
954
|
-
`${prefix}// @key ${ktCodegenSelectorBlockTitle(region.blockKey)}`,
|
|
955
|
-
...notes.map((note) => `${prefix}// ${note}`),
|
|
956
|
-
`${prefix}${separator}`,
|
|
957
|
-
];
|
|
958
|
-
}
|
|
959
|
-
/** 创建旧 Field enum 使用的 `Field_<Class>_` 公共前缀。 */
|
|
960
|
-
function ktCodegenFieldTypePrefix(context, region) {
|
|
961
|
-
return `Field_${context.param.namePrefix}${context.param.nameMiddle}${region.nameSuffix}_`;
|
|
962
|
-
}
|
|
963
|
-
/** 按旧 Dialog Selector 三个方法生成 Field 定义和兼容访问逻辑。 */
|
|
964
|
-
function ktCodegenRenderCaaDialogFieldLines(context, region, items) {
|
|
965
|
-
const prefix = region.start.linePrefix;
|
|
966
|
-
const fieldPrefix = ktCodegenFieldTypePrefix(context, region);
|
|
967
|
-
if (region.blockKey === "DLG DEFINE FIELD TYPE") {
|
|
968
|
-
const lines = ktCodegenRenderSelectorStart(region);
|
|
969
|
-
lines.push(`${prefix}${fieldPrefix}None = 0, // None`);
|
|
970
|
-
items.forEach((item, index) => {
|
|
971
|
-
lines.push(`${prefix}${fieldPrefix}${item.paramString} = ${index + 1}, // ${item.paramString}`);
|
|
972
|
-
});
|
|
973
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
974
|
-
}
|
|
975
|
-
if (region.blockKey === "DLG SET ACTIVE FIELD") {
|
|
976
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
977
|
-
"@usage put this code block into the function Dlg::SetActiveField()",
|
|
978
|
-
"@brief Set Active Field, clear other field.",
|
|
979
|
-
]);
|
|
980
|
-
for (const item of items) {
|
|
981
|
-
lines.push(`${prefix}if (${fieldPrefix}${item.paramString} != field)`, `${prefix} _SelectorList${item.paramString}->ClearSelect();`);
|
|
982
|
-
}
|
|
983
|
-
lines.push(`${prefix}_ActiveField = field;`);
|
|
984
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
985
|
-
}
|
|
986
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
987
|
-
"@usage put this code block into the function Dlg::GetSelectorList()",
|
|
988
|
-
"@brief get SelectorList",
|
|
989
|
-
]);
|
|
990
|
-
lines.push(`${prefix}// Field count = ${items.length}`);
|
|
991
|
-
if (items.length === 0) {
|
|
992
|
-
lines.push(`${prefix}return NULL;`);
|
|
993
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
994
|
-
}
|
|
995
|
-
lines.push(`${prefix}switch (field) {`);
|
|
996
|
-
for (const item of items) {
|
|
997
|
-
lines.push(`${prefix}case ${fieldPrefix}${item.paramString}:`, `${prefix} return _SelectorList${item.paramString};`);
|
|
998
|
-
}
|
|
999
|
-
lines.push(`${prefix}default:`, `${prefix} return NULL;`, `${prefix}}`);
|
|
1000
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1001
|
-
}
|
|
1002
|
-
/** 按旧 Command Selector 规则生成 Agent 声明、构造初始化和析构清理。 */
|
|
1003
|
-
function ktCodegenRenderCaaCommandAgentLifecycleLines(context, region, items) {
|
|
1004
|
-
const prefix = region.start.linePrefix;
|
|
1005
|
-
const lines = ktCodegenRenderSelectorStart(region);
|
|
1006
|
-
if (region.blockKey === "CMD AGENT DECLARE") {
|
|
1007
|
-
lines.push(`${prefix}KT_AUTO_CMD_AGENT_DECLARE_COMMON();`, `${prefix}KT_AUTO_CMD_AGENT_DECLARE_BASE(${context.param.namePrefix}, ${context.param.nameMiddle}${region.nameSuffix});`, "", `${prefix}// Field count = ${items.length}`);
|
|
1008
|
-
for (const item of items) {
|
|
1009
|
-
lines.push(`${prefix}KT_AUTO_CMD_AGENT_DECLARE_FIELD(${item.paramString});`);
|
|
1010
|
-
}
|
|
1011
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1012
|
-
}
|
|
1013
|
-
if (region.blockKey === "CMD AGENT CONSTRUCTOR") {
|
|
1014
|
-
lines.push(`${prefix}, KT_AUTO_CMD_AGENT_CONSTRUCTOR_COMMON()`);
|
|
1015
|
-
for (const item of items) {
|
|
1016
|
-
lines.push(`${prefix}, KT_AUTO_CMD_AGENT_CONSTRUCTOR_FIELD(${item.paramString})`);
|
|
1017
|
-
}
|
|
1018
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1019
|
-
}
|
|
1020
|
-
lines.push(`${prefix}// Field count = ${items.length}`);
|
|
1021
|
-
for (const item of items) {
|
|
1022
|
-
lines.push(`${prefix}KT_AUTO_CMD_AGENT_DESTRUCTOR_FIELD(${item.paramString});`);
|
|
1023
|
-
}
|
|
1024
|
-
lines.push("", `${prefix}// place at the end`, `${prefix}KT_AUTO_CMD_AGENT_DESTRUCTOR_COMMON();`);
|
|
1025
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1026
|
-
}
|
|
1027
|
-
/** 为旧 Command Field 不支持分支生成可见原因注释。 */
|
|
1028
|
-
function ktCodegenRenderUnsupportedCommandField(item, prefix, indent = "") {
|
|
1029
|
-
return [
|
|
1030
|
-
`${prefix}${indent}// Please write your own code outside.`,
|
|
1031
|
-
item.componentCount === 0
|
|
1032
|
-
? `${prefix}${indent}// Because the component count is 0.`
|
|
1033
|
-
: `${prefix}${indent}// Because ${item.component} is not supported.`,
|
|
1034
|
-
];
|
|
1035
|
-
}
|
|
1036
|
-
/** 按旧规则生成 BuildGraph、FIA Clear 和 UpdateState 三个 Command 块。 */
|
|
1037
|
-
function ktCodegenRenderCaaCommandGraphStateLines(context, region, items, algorithms) {
|
|
1038
|
-
const prefix = region.start.linePrefix;
|
|
1039
|
-
if (region.blockKey === "CMD AGENT BUILD GRAPH") {
|
|
1040
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
1041
|
-
"@usage put this code block into the function Cmd::BuildGraph()",
|
|
1042
|
-
"@brief set agent, AddTransition",
|
|
1043
|
-
"RegisterFiled() will set suggested menu id by input name. You can change it later",
|
|
1044
|
-
]);
|
|
1045
|
-
lines.push("", `${prefix}// Build Start .......................`, `${prefix}KT_AUTO_CMD_BUILD_START(${region.classId});`, "", `${prefix}// Field count = ${items.length}`);
|
|
1046
|
-
items.forEach((item, index) => {
|
|
1047
|
-
lines.push("", `${prefix}// Field ${index + 1} ${item.paramString} .......................`, `${prefix}// ${index + 1}.1 define fia`);
|
|
1048
|
-
if (algorithms.isCommandAutoField(item)) {
|
|
1049
|
-
lines.push(`${prefix}KT_AUTO_CMD_BUILD_FIA_${algorithms.getCommandSuggestedFilter(item.paramString)}(${item.paramString});`, `${prefix}// ${index + 1}.2 others`, `${prefix}KT_AUTO_CMD_BUILD_FIELD(${region.classId}, ${item.paramString});`);
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
lines.push(...ktCodegenRenderUnsupportedCommandField(item, prefix));
|
|
1053
|
-
}
|
|
1054
|
-
});
|
|
1055
|
-
lines.push("", `${prefix}// Build End .......................`, `${prefix}KT_AUTO_CMD_BUILD_END(${region.classId});`);
|
|
1056
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1057
|
-
}
|
|
1058
|
-
if (region.blockKey === "CMD AGENT FIA CLEAR") {
|
|
1059
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
1060
|
-
"@usage put this code block into the function Cmd::fiaAgentClear()",
|
|
1061
|
-
"@brief clear select state",
|
|
1062
|
-
]);
|
|
1063
|
-
for (const item of items) {
|
|
1064
|
-
lines.push(`${prefix}KT_AUTO_CMD_ACTION_FIA_CLEAR(${item.paramString});`);
|
|
1065
|
-
}
|
|
1066
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1067
|
-
}
|
|
1068
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
1069
|
-
"@usage put this code block into the function Cmd::fiaAgentUpdate()",
|
|
1070
|
-
"@brief Update select state",
|
|
1071
|
-
]);
|
|
1072
|
-
lines.push(`${prefix}// Field count = ${items.length}`);
|
|
1073
|
-
if (items.length > 0) {
|
|
1074
|
-
const fieldPrefix = ktCodegenFieldTypePrefix(context, region);
|
|
1075
|
-
lines.push(`${prefix}switch (field) {`);
|
|
1076
|
-
for (const item of items) {
|
|
1077
|
-
lines.push(`${prefix}case ${fieldPrefix}${item.paramString}:`);
|
|
1078
|
-
if (algorithms.isCommandAutoField(item)) {
|
|
1079
|
-
lines.push(`${prefix} KT_AUTO_CMD_AGENT_UPDATE_STATE(${item.paramString});`);
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
lines.push(...ktCodegenRenderUnsupportedCommandField(item, prefix, " "));
|
|
1083
|
-
}
|
|
1084
|
-
lines.push(`${prefix} break;`);
|
|
1085
|
-
}
|
|
1086
|
-
lines.push(`${prefix}case 0:`, `${prefix} KT_AUTO_CMD_AGENT_UPDATE_STATE_ERROR();`, `${prefix}}`);
|
|
1087
|
-
}
|
|
1088
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1089
|
-
}
|
|
1090
|
-
/** 生成 Command Action 自动宏或旧人工实现提示。 */
|
|
1091
|
-
function ktCodegenAppendCommandAction(lines, item, prefix, macro, isCommandAutoField) {
|
|
1092
|
-
if (isCommandAutoField(item)) {
|
|
1093
|
-
lines.push(`${prefix} ${macro}(${item.paramString});`);
|
|
1094
|
-
return;
|
|
1095
|
-
}
|
|
1096
|
-
lines.push(...ktCodegenRenderUnsupportedCommandField(item, prefix, " "));
|
|
1097
|
-
}
|
|
1098
|
-
/** 按旧规则生成 PDA、FIA、废弃 ElementSelected 和活动 Field 四个块。 */
|
|
1099
|
-
function ktCodegenRenderCaaCommandActionLines(context, region, items, algorithms) {
|
|
1100
|
-
const prefix = region.start.linePrefix;
|
|
1101
|
-
const fieldPrefix = ktCodegenFieldTypePrefix(context, region);
|
|
1102
|
-
if (region.blockKey === "CMD ACTION PDA") {
|
|
1103
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
1104
|
-
"@usage put this code block into the function Cmd::ActionSelectorListPda()",
|
|
1105
|
-
"@brief InitializeAcquisition and HSO Append",
|
|
1106
|
-
]);
|
|
1107
|
-
lines.push(`${prefix}// Field count = ${items.length}`);
|
|
1108
|
-
if (items.length > 0) {
|
|
1109
|
-
lines.push(`${prefix}if (fieldChange) KT_AUTO_HSO_CLEAR();`, `${prefix}switch (field) {`);
|
|
1110
|
-
for (const item of items) {
|
|
1111
|
-
lines.push(`${prefix}case ${fieldPrefix}${item.paramString}:`);
|
|
1112
|
-
ktCodegenAppendCommandAction(lines, item, prefix, "KT_AUTO_CMD_ACTION_PDA", algorithms.isCommandAutoField);
|
|
1113
|
-
lines.push(`${prefix} break;`);
|
|
1114
|
-
}
|
|
1115
|
-
lines.push(`${prefix}}`);
|
|
1116
|
-
}
|
|
1117
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1118
|
-
}
|
|
1119
|
-
if (region.blockKey === "CMD ACTION FIA") {
|
|
1120
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
1121
|
-
"@usage put this code block into the function Cmd::ActionSelectorListFia()",
|
|
1122
|
-
"@brief Action object selected",
|
|
1123
|
-
]);
|
|
1124
|
-
lines.push(`${prefix}// Field count = ${items.length}`, `${prefix}int count = 0;`);
|
|
1125
|
-
if (items.length > 0) {
|
|
1126
|
-
lines.push(`${prefix}switch (field) {`);
|
|
1127
|
-
for (const item of items) {
|
|
1128
|
-
lines.push(`${prefix}case ${fieldPrefix}${item.paramString}:`);
|
|
1129
|
-
ktCodegenAppendCommandAction(lines, item, prefix, "KT_AUTO_CMD_ACTION_FIA", algorithms.isCommandAutoField);
|
|
1130
|
-
lines.push(`${prefix} break;`);
|
|
1131
|
-
}
|
|
1132
|
-
lines.push(`${prefix}}`);
|
|
1133
|
-
}
|
|
1134
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1135
|
-
}
|
|
1136
|
-
if (region.blockKey === "CMD ELEMENT SELECTED") {
|
|
1137
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
1138
|
-
"@usage put this code block into the function Cmd::AfterElementSelected()",
|
|
1139
|
-
"@brief After Element Selected",
|
|
1140
|
-
"@brief !Discard. Replaced by CMD ACTION FIA",
|
|
1141
|
-
]);
|
|
1142
|
-
lines.push(`${prefix}// Field count = ${items.length}`);
|
|
1143
|
-
if (items.length > 0) {
|
|
1144
|
-
lines.push(`${prefix}switch (field) {`);
|
|
1145
|
-
for (const item of items) {
|
|
1146
|
-
const parameter = `parameter->${item.paramString}`;
|
|
1147
|
-
lines.push(`${prefix}case ${fieldPrefix}${item.paramString}:`);
|
|
1148
|
-
if (item.dataType === "CATListValCATISpecObject_var") {
|
|
1149
|
-
lines.push(`${prefix} if (${parameter}.Locate(spiSpecOnSelection) == 0)`, `${prefix} {`, `${prefix} ${parameter}.Append(spiSpecOnSelection);`, `${prefix} }`, `${prefix} else`, `${prefix} {`, `${prefix} _ktcHSO.RemoveElement(pPathElement);`, `${prefix} ${parameter}.RemoveValue(spiSpecOnSelection);`, `${prefix} }`);
|
|
1150
|
-
}
|
|
1151
|
-
else {
|
|
1152
|
-
lines.push(`${prefix} if (${parameter} == spiSpecOnSelection)`, `${prefix} {`, `${prefix} _ktcHSO.RemoveElement(pPathElement);`, `${prefix} ${parameter} = NULL_var;`, `${prefix} }`, `${prefix} else`, `${prefix} {`, `${prefix} _ktcHSO.RemoveElement(${parameter});`, `${prefix} ${parameter} = spiSpecOnSelection;`, `${prefix} }`);
|
|
1153
|
-
}
|
|
1154
|
-
lines.push(`${prefix} break;`);
|
|
1155
|
-
}
|
|
1156
|
-
lines.push(`${prefix}}`);
|
|
1157
|
-
}
|
|
1158
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1159
|
-
}
|
|
1160
|
-
const lines = ktCodegenRenderSelectorStart(region, [
|
|
1161
|
-
"@usage put this code block into the function Cmd::SetActiveField()",
|
|
1162
|
-
"@brief Set Active Field, clear other field, update select agent...",
|
|
1163
|
-
]);
|
|
1164
|
-
lines.push(`${prefix}// Field count = ${items.length}`, "", `${prefix}KT_AUTO_HSO_CLEAR();`);
|
|
1165
|
-
if (items.length > 0) {
|
|
1166
|
-
lines.push(`${prefix}switch (field) {`);
|
|
1167
|
-
for (const item of items) {
|
|
1168
|
-
lines.push(`${prefix}case ${fieldPrefix}${item.paramString}:`);
|
|
1169
|
-
ktCodegenAppendCommandAction(lines, item, prefix, "KT_AUTO_HSO_ADD", algorithms.isCommandAutoField);
|
|
1170
|
-
lines.push(`${prefix} break;`);
|
|
1171
|
-
}
|
|
1172
|
-
lines.push(`${prefix}default:`, `${prefix} break;`, `${prefix}}`);
|
|
1173
|
-
}
|
|
1174
|
-
return [...lines, ...ktCodegenRenderLegacyEnd(region)];
|
|
1175
|
-
}
|
|
1176
|
-
/** 生成当前已迁移 CAA block,并报告同目标尚未迁移的 block。 */
|
|
1177
|
-
function ktCodegenRenderCaa(context, algorithms) {
|
|
1178
|
-
const artifacts = [];
|
|
1179
|
-
const diagnostics = [];
|
|
1180
|
-
const requestedBlocks = new Set(context.blockKeys);
|
|
1181
|
-
for (const region of context.markerRegions) {
|
|
1182
|
-
if (!KT_CODEGEN_CAA_MIGRATED_BLOCKS.has(region.blockKey) ||
|
|
1183
|
-
!requestedBlocks.has(region.blockKey) ||
|
|
1184
|
-
ktCodegenGetBlock(region.blockKey).target !== context.target) {
|
|
1185
|
-
continue;
|
|
1186
|
-
}
|
|
1187
|
-
const isCatalog = region.blockKey === "CATALOG PARAMS";
|
|
1188
|
-
const isFactoryTree = region.blockKey === "FACTRY ON TREE";
|
|
1189
|
-
const isDialogNotify = region.blockKey === "DIALOG NOTIFY";
|
|
1190
|
-
const isUpdateDialog = region.blockKey === "UPDATE DIALOG";
|
|
1191
|
-
const isUpdateInfors = region.blockKey === "UPDATE INFORS";
|
|
1192
|
-
const isDialogField = region.blockKey === "DLG DEFINE FIELD TYPE" ||
|
|
1193
|
-
region.blockKey === "DLG SET ACTIVE FIELD" ||
|
|
1194
|
-
region.blockKey === "DLG GET SELECTOR LIST";
|
|
1195
|
-
const isCommandAgentLifecycle = KT_CODEGEN_CAA_COMMAND_AGENT_LIFECYCLE_BLOCKS.has(region.blockKey);
|
|
1196
|
-
const isCommandGraphState = KT_CODEGEN_CAA_COMMAND_GRAPH_STATE_BLOCKS.has(region.blockKey);
|
|
1197
|
-
const isCommandAction = KT_CODEGEN_CAA_COMMAND_ACTION_BLOCKS.has(region.blockKey);
|
|
1198
|
-
const isParamsClass = region.blockKey === "IMPLEMENTS PARAM GET" ||
|
|
1199
|
-
region.blockKey === "IMPLEMENTS PARAM SET";
|
|
1200
|
-
let items;
|
|
1201
|
-
if (isCatalog) {
|
|
1202
|
-
items = context.param.items.filter((item) => ktCodegenIsCaaCatalogItem(item, region.nameSuffix));
|
|
1203
|
-
}
|
|
1204
|
-
else if (isFactoryTree) {
|
|
1205
|
-
items = context.param.items.filter((item) => ktCodegenIsCaaFactoryTreeItem(item, region.nameSuffix));
|
|
1206
|
-
}
|
|
1207
|
-
else if (isDialogNotify || isUpdateDialog || isUpdateInfors) {
|
|
1208
|
-
items = context.param.items.filter((item) => ktCodegenIsCaaDialogItem(item, region.nameSuffix));
|
|
1209
|
-
}
|
|
1210
|
-
else if (isDialogField ||
|
|
1211
|
-
isCommandAgentLifecycle ||
|
|
1212
|
-
isCommandGraphState ||
|
|
1213
|
-
isCommandAction) {
|
|
1214
|
-
items = context.param.items.filter((item) => item.nameSuffix === region.nameSuffix && algorithms.isSelectorField(item));
|
|
1215
|
-
}
|
|
1216
|
-
else if (isParamsClass) {
|
|
1217
|
-
items = context.param.items.filter((item) => ktCodegenIsCaaParamsClassItem(item, region.nameSuffix));
|
|
1218
|
-
}
|
|
1219
|
-
else {
|
|
1220
|
-
items = context.param.items.filter((item) => ktCodegenIsCaaInterfaceItem(item, region.nameSuffix));
|
|
1221
|
-
}
|
|
1222
|
-
let lines;
|
|
1223
|
-
if (isCatalog) {
|
|
1224
|
-
lines = ktCodegenRenderCaaCatalogLines(region, items, algorithms);
|
|
1225
|
-
}
|
|
1226
|
-
else if (isFactoryTree) {
|
|
1227
|
-
lines = ktCodegenRenderCaaFactoryTreeLines(region, items, algorithms.formatTreeName);
|
|
1228
|
-
}
|
|
1229
|
-
else if (isDialogNotify) {
|
|
1230
|
-
lines = ktCodegenRenderCaaDialogNotifyLines(region, items, algorithms.isCaaVector);
|
|
1231
|
-
}
|
|
1232
|
-
else if (isUpdateDialog) {
|
|
1233
|
-
lines = ktCodegenRenderCaaUpdateDialogLines(context, region, items, algorithms.isCaaVector);
|
|
1234
|
-
}
|
|
1235
|
-
else if (isUpdateInfors) {
|
|
1236
|
-
lines = ktCodegenRenderCaaUpdateInforsLines(region, items, algorithms.isCaaVector);
|
|
1237
|
-
}
|
|
1238
|
-
else if (isDialogField) {
|
|
1239
|
-
lines = ktCodegenRenderCaaDialogFieldLines(context, region, items);
|
|
1240
|
-
}
|
|
1241
|
-
else if (isCommandAgentLifecycle) {
|
|
1242
|
-
lines = ktCodegenRenderCaaCommandAgentLifecycleLines(context, region, items);
|
|
1243
|
-
}
|
|
1244
|
-
else if (isCommandGraphState) {
|
|
1245
|
-
lines = ktCodegenRenderCaaCommandGraphStateLines(context, region, items, algorithms);
|
|
1246
|
-
}
|
|
1247
|
-
else if (isCommandAction) {
|
|
1248
|
-
lines = ktCodegenRenderCaaCommandActionLines(context, region, items, algorithms);
|
|
1249
|
-
}
|
|
1250
|
-
else if (KT_CODEGEN_CAA_INTERFACE_BLOCKS.has(region.blockKey)) {
|
|
1251
|
-
lines = ktCodegenRenderCaaInterfaceLines(region, items, algorithms.isParamSpecList);
|
|
1252
|
-
}
|
|
1253
|
-
else if (isParamsClass) {
|
|
1254
|
-
lines = ktCodegenRenderCaaParamsClassLines(region, items, algorithms.isParamSpecList);
|
|
1255
|
-
}
|
|
1256
|
-
else {
|
|
1257
|
-
lines = ktCodegenRenderCaaFeatureCppLines(context, region, items, algorithms);
|
|
1258
|
-
}
|
|
1259
|
-
const artifactCount = artifacts.length;
|
|
1260
|
-
ktCodegenAppendRegionArtifact(context, region, items, lines, artifacts, diagnostics);
|
|
1261
|
-
if (artifacts.length > artifactCount &&
|
|
1262
|
-
ktCodegenGetBlock(region.blockKey).legacyState === "legacy-deprecated") {
|
|
1263
|
-
diagnostics.push({
|
|
1264
|
-
code: "renderer.legacy-deprecated-block",
|
|
1265
|
-
severity: "warning",
|
|
1266
|
-
message: `${region.blockKey} is retained for compatibility; its archived VB method is marked discarded.`,
|
|
1267
|
-
path: {
|
|
1268
|
-
source: "renderer",
|
|
1269
|
-
file: region.path,
|
|
1270
|
-
field: region.blockKey,
|
|
1271
|
-
},
|
|
1272
|
-
});
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
const targetBlocks = context.blockKeys.filter((blockKey) => ktCodegenGetBlock(blockKey).target === context.target);
|
|
1276
|
-
const pendingBlocks = targetBlocks.filter((blockKey) => !KT_CODEGEN_CAA_MIGRATED_BLOCKS.has(blockKey));
|
|
1277
|
-
const supportsTarget = context.target === "caa.core" ||
|
|
1278
|
-
context.target === "caa.model" ||
|
|
1279
|
-
context.target === "caa.feature-io" ||
|
|
1280
|
-
context.target === "caa.control" ||
|
|
1281
|
-
context.target === "caa.dialog";
|
|
1282
|
-
const status = supportsTarget && pendingBlocks.length === 0 ? "ready" : "scaffold";
|
|
1283
|
-
if (status === "scaffold") {
|
|
1284
|
-
diagnostics.push({
|
|
1285
|
-
code: "renderer.blocks-pending",
|
|
1286
|
-
severity: "info",
|
|
1287
|
-
message: pendingBlocks.length > 0
|
|
1288
|
-
? `${context.target} still has pending blocks: ${pendingBlocks.join(", ")}.`
|
|
1289
|
-
: `${context.target} has no migrated CAA block renderer yet.`,
|
|
1290
|
-
path: { source: "renderer", field: context.target },
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
return { status, artifacts, diagnostics };
|
|
1294
|
-
}
|
|
2
|
+
import { ktCodegenRenderCaa } from "./renderer/caa-renderer.js";
|
|
3
|
+
import { ktCodegenRenderCppParameter } from "./renderer/cpp-parameter-family.js";
|
|
4
|
+
import { ktCodegenRenderQt } from "./renderer/qt-dialog-family.js";
|
|
1295
5
|
/**
|
|
1296
6
|
* 单一 Renderer 类型;不同生成目标通过元数据和 render 回调组合。
|
|
1297
7
|
*
|