dsh-eplan 0.0.0-stage → 0.14.1
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/LICENSE +21 -0
- package/README.md +219 -3
- package/cordis.patch.yml +182 -0
- package/docs/INSTALL.md +86 -0
- package/docs/LESSONS.md +224 -0
- package/docs/interfaces.md +183 -0
- package/docs/merged-skills/eplan-setup.md +63 -0
- package/docs/merged-skills/eplan-troubleshooting.md +149 -0
- package/icon.png +0 -0
- package/icon.svg +13 -0
- package/knowledge/KNOWLEDGE.md +413 -0
- package/knowledge/symbols/BP.png +0 -0
- package/knowledge/symbols/CDPST.png +0 -0
- package/knowledge/symbols/CO.png +0 -0
- package/knowledge/symbols/FA3.png +0 -0
- package/knowledge/symbols/TLRO.png +0 -0
- package/knowledge/symbols/TLRU.png +0 -0
- package/knowledge/symbols/TOUL.png +0 -0
- package/knowledge/symbols/TOUR.png +0 -0
- package/knowledge/symbols/manifest.json +91 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/native/bridge/build.ps1 +73 -0
- package/native/bridge/src/Json.cs +383 -0
- package/native/bridge/src/Program.cs +1133 -0
- package/native/host/build.ps1 +74 -0
- package/native/host/src/ActionsTool.cs +225 -0
- package/native/host/src/BoxTool.cs +196 -0
- package/native/host/src/CheckTool.cs +186 -0
- package/native/host/src/Context.cs +169 -0
- package/native/host/src/DarkScheme.cs +111 -0
- package/native/host/src/DiagnoseTool.cs +115 -0
- package/native/host/src/Dispatcher.cs +51 -0
- package/native/host/src/DrawTool.cs +316 -0
- package/native/host/src/Entry.cs +111 -0
- package/native/host/src/ExportTool.cs +213 -0
- package/native/host/src/InspectTool.cs +367 -0
- package/native/host/src/KnowledgeTool.cs +166 -0
- package/native/host/src/LookTool.cs +257 -0
- package/native/host/src/OpLog.cs +289 -0
- package/native/host/src/PageCreateTool.cs +521 -0
- package/native/host/src/PageOpenTool.cs +62 -0
- package/native/host/src/PagesTool.cs +95 -0
- package/native/host/src/Paths.cs +91 -0
- package/native/host/src/PlacementEditTool.cs +234 -0
- package/native/host/src/ProbePropsTool.cs +152 -0
- package/native/host/src/ProjectCreateTool.cs +176 -0
- package/native/host/src/ProjectTool.cs +167 -0
- package/native/host/src/PropWriter.cs +70 -0
- package/native/host/src/PropsTool.cs +257 -0
- package/native/host/src/StatusTool.cs +168 -0
- package/native/host/src/SymbolInfoTool.cs +144 -0
- package/native/host/src/SymbolInsertTool.cs +261 -0
- package/native/host/src/SymbolsTool.cs +94 -0
- package/native/host/src/TagLocTool.cs +108 -0
- package/native/script/EplanMcpBootstrap.cs +221 -0
- package/native/script/build-symbol-gallery.mjs +231 -0
- package/native/script/prepare-install.ps1 +57 -0
- package/native/script/prune.mjs +132 -0
- package/native/script/verify-bootstrap.ps1 +62 -0
- package/package.json +53 -4
- package/preset/bootstrap.js +498 -0
- package/preset/experience-nudge.js +47 -0
- package/preset/image-budget.js +175 -0
- package/preset/knowledge-tool.js +180 -0
- package/preset/mcp-link.js +100 -0
- package/preset/prompt-surface.js +76 -0
- package/preset/restrict-tools.js +141 -0
- package/preset/skill-docs.js +181 -0
- package/preset/video-digest.js +294 -0
- package/preset/video-tool.js +92 -0
- package/server/compact.mjs +623 -0
- package/server/edit-args.mjs +67 -0
- package/server/fuzzy.mjs +57 -0
- package/server/launch-decision.mjs +26 -0
- package/server/measure.mjs +320 -0
- package/server/pdf.mjs +185 -0
- package/server/pdf2png.ps1 +99 -0
- package/server/server.mjs +3797 -0
- package/server/video.mjs +857 -0
- package/setup.mjs +223 -0
- package/skills/eplan-annotations/SKILL.md +55 -0
- package/skills/eplan-drawing/SKILL.md +206 -0
- package/skills/eplan-project/SKILL.md +41 -0
- package/skills/eplan-review/SKILL.md +80 -0
- package/skills/eplan-symbols/SKILL.md +142 -0
- package/test/check-docs.mjs +106 -0
- package/test/foreground.ps1 +21 -0
- package/test/smoke-all.mjs +229 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// inspect:把一个页面上**真实存在**的东西全部倒出来,包括 EPLAN 自动生成的连接。
|
|
2
|
+
//
|
|
3
|
+
// 为什么需要它:
|
|
4
|
+
// 用户指出「红线是元器件和节点摆对位置后软件自动连的」,不是画出来的。
|
|
5
|
+
// 要复现这一点,必须先看清「一个已经画好的页」里到底有哪些对象、哪些是
|
|
6
|
+
// 符号的宿主(如 Function)、哪些是自动连接(Connection)、连接点坐标在哪。
|
|
7
|
+
//
|
|
8
|
+
// SymbolReference 的成员名不确定(没有 SymbolName / VariantNr / SymbolReferences),
|
|
9
|
+
// 所以这里一律走反射,把能读到的属性都列出来,而不是硬编码。
|
|
10
|
+
using System;
|
|
11
|
+
using System.Collections;
|
|
12
|
+
using System.Reflection;
|
|
13
|
+
using Eplan.EplApi.Base;
|
|
14
|
+
using Eplan.EplApi.DataModel;
|
|
15
|
+
using Eplan.EplApi.DataModel.Graphics;
|
|
16
|
+
using Eplan.EplApi.DataModel.MasterData;
|
|
17
|
+
using EplanMcp;
|
|
18
|
+
|
|
19
|
+
namespace EplanMcpHost
|
|
20
|
+
{
|
|
21
|
+
internal static class InspectTool
|
|
22
|
+
{
|
|
23
|
+
public static JsonValue Run(JsonValue args)
|
|
24
|
+
{
|
|
25
|
+
// 只看类型清单:{"assembly":"Guiu"} —— 探索某个 EPLAN 程序集里到底有什么。
|
|
26
|
+
string assemblyFilter = args["assembly"].AsString(null);
|
|
27
|
+
if (!string.IsNullOrEmpty(assemblyFilter))
|
|
28
|
+
{
|
|
29
|
+
JsonValue only = JsonValue.NewObject();
|
|
30
|
+
only.Set("assembly", assemblyFilter);
|
|
31
|
+
only.Set("types", ListTypes(assemblyFilter));
|
|
32
|
+
return only;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
string pageName = args["page"].AsString(null);
|
|
36
|
+
Page page = Context.FindPage(pageName, args["project"].AsString(null));
|
|
37
|
+
|
|
38
|
+
JsonValue result = JsonValue.NewObject();
|
|
39
|
+
result.Set("page", page.Name);
|
|
40
|
+
result.Set("pageType", page.PageType.ToString());
|
|
41
|
+
|
|
42
|
+
int limit = args["limit"].AsInt(200);
|
|
43
|
+
|
|
44
|
+
// ── 1. 放置对象 ──────────────────────────────────────────
|
|
45
|
+
JsonValue placements = JsonValue.NewArray();
|
|
46
|
+
Placement[] all = page.AllPlacements;
|
|
47
|
+
if (all != null)
|
|
48
|
+
{
|
|
49
|
+
result.Set("placementTotal", all.Length);
|
|
50
|
+
int n = 0;
|
|
51
|
+
foreach (Placement p in all)
|
|
52
|
+
{
|
|
53
|
+
if (n >= limit) break;
|
|
54
|
+
n++;
|
|
55
|
+
placements.Add(DescribePlacement(p));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else result.Set("placementTotal", 0);
|
|
59
|
+
result.Set("placements", placements);
|
|
60
|
+
|
|
61
|
+
// ── 2. Function 列表 ─────────────────────────────────────
|
|
62
|
+
JsonValue functions = JsonValue.NewArray();
|
|
63
|
+
Function[] fns = page.Functions;
|
|
64
|
+
if (fns != null)
|
|
65
|
+
{
|
|
66
|
+
result.Set("functionTotal", fns.Length);
|
|
67
|
+
int n = 0;
|
|
68
|
+
foreach (Function f in fns)
|
|
69
|
+
{
|
|
70
|
+
if (n >= limit) break;
|
|
71
|
+
n++;
|
|
72
|
+
functions.Add(DescribeFunction(f));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else result.Set("functionTotal", 0);
|
|
76
|
+
result.Set("functions", functions);
|
|
77
|
+
|
|
78
|
+
// ── 3. 自动连接 ──────────────────────────────────────────
|
|
79
|
+
result.Set("connections", DescribeConnections(page));
|
|
80
|
+
|
|
81
|
+
// ── 4. 想看某个类型的成员时:{"page":"...","members":"SymbolReference"}
|
|
82
|
+
string members = args["members"].AsString(null);
|
|
83
|
+
if (!string.IsNullOrEmpty(members)) result.Set("members", DumpMembers(members));
|
|
84
|
+
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// <summary>把某个 EPLAN 类型的公开成员列出来,用来确认真实属性名。</summary>
|
|
89
|
+
private static JsonValue DumpMembers(string typeName)
|
|
90
|
+
{
|
|
91
|
+
JsonValue list = JsonValue.NewArray();
|
|
92
|
+
// 类型可能在 DataModel / DataModel.Graphics / DataModel.MasterData 任一命名空间下,
|
|
93
|
+
// 依次试,别只认一个(PropertyPlacement 就在 Graphics 里)。
|
|
94
|
+
string[] prefixes = {
|
|
95
|
+
"Eplan.EplApi.DataModel.",
|
|
96
|
+
"Eplan.EplApi.DataModel.Graphics.",
|
|
97
|
+
"Eplan.EplApi.DataModel.MasterData.",
|
|
98
|
+
"Eplan.EplApi.Base.",
|
|
99
|
+
"Eplan.EplApi.HEServices.",
|
|
100
|
+
"Eplan.EplApi.ApplicationFramework.",
|
|
101
|
+
};
|
|
102
|
+
Type type = null;
|
|
103
|
+
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
|
|
104
|
+
{
|
|
105
|
+
if (type != null) break;
|
|
106
|
+
foreach (string prefix in prefixes)
|
|
107
|
+
{
|
|
108
|
+
try
|
|
109
|
+
{
|
|
110
|
+
Type candidate = asm.GetType(prefix + typeName);
|
|
111
|
+
if (candidate != null) { type = candidate; break; }
|
|
112
|
+
}
|
|
113
|
+
catch { }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (type == null)
|
|
117
|
+
{
|
|
118
|
+
list.Add(JsonValue.NewString("NOT_FOUND: " + typeName));
|
|
119
|
+
return list;
|
|
120
|
+
}
|
|
121
|
+
BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
|
|
122
|
+
foreach (PropertyInfo p in type.GetProperties(flags))
|
|
123
|
+
{
|
|
124
|
+
string setter = p.SetMethod != null ? "set" : "get";
|
|
125
|
+
list.Add(JsonValue.NewString(p.PropertyType.Name + " " + p.Name + " (" + setter + ")"));
|
|
126
|
+
}
|
|
127
|
+
foreach (MethodInfo m in type.GetMethods(flags))
|
|
128
|
+
{
|
|
129
|
+
if (m.IsSpecialName) continue;
|
|
130
|
+
list.Add(JsonValue.NewString("() " + m.ReturnType.Name + " " + m.Name));
|
|
131
|
+
}
|
|
132
|
+
return list;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// <summary>列出名字里含过滤串的 EPLAN 类型(跨所有已加载程序集)。</summary>
|
|
136
|
+
private static JsonValue ListTypes(string filter)
|
|
137
|
+
{
|
|
138
|
+
JsonValue list = JsonValue.NewArray();
|
|
139
|
+
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
|
|
140
|
+
{
|
|
141
|
+
Type[] types;
|
|
142
|
+
try { types = asm.GetTypes(); }
|
|
143
|
+
catch { continue; }
|
|
144
|
+
foreach (Type type in types)
|
|
145
|
+
{
|
|
146
|
+
if (type == null) continue;
|
|
147
|
+
string full = type.FullName ?? type.Name;
|
|
148
|
+
if (full.IndexOf("Eplan.EplApi", StringComparison.OrdinalIgnoreCase) < 0) continue;
|
|
149
|
+
if (filter.Length > 0 && full.IndexOf(filter, StringComparison.OrdinalIgnoreCase) < 0) continue;
|
|
150
|
+
list.Add(JsonValue.NewString(full));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return list;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private static JsonValue DescribePlacement(Placement p)
|
|
157
|
+
{
|
|
158
|
+
JsonValue item = JsonValue.NewObject();
|
|
159
|
+
item.Set("type", p.GetType().Name);
|
|
160
|
+
try { item.Set("objectId", p.ObjectIdentifier.ToString()); } catch { }
|
|
161
|
+
try
|
|
162
|
+
{
|
|
163
|
+
JsonValue loc = JsonValue.NewArray();
|
|
164
|
+
loc.Add(JsonValue.NewNumber(p.Location.X));
|
|
165
|
+
loc.Add(JsonValue.NewNumber(p.Location.Y));
|
|
166
|
+
item.Set("location", loc);
|
|
167
|
+
}
|
|
168
|
+
catch { }
|
|
169
|
+
|
|
170
|
+
SymbolReference sr = p as SymbolReference;
|
|
171
|
+
if (sr != null)
|
|
172
|
+
{
|
|
173
|
+
// SymbolReference 上没有 SymbolName,符号名在它的 SymbolVariant 上。
|
|
174
|
+
SymbolVariant variant = TryGetVariant(sr);
|
|
175
|
+
if (variant != null)
|
|
176
|
+
{
|
|
177
|
+
CopyIfExists(item, "symbolName", variant, new string[] { "SymbolName", "Name" });
|
|
178
|
+
CopyIfExists(item, "variant", variant, new string[] { "VariantNr", "Variant" });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 自动连线靠的就是这些连接点:Location 是**绝对坐标**,Direction 是朝向。
|
|
182
|
+
// 两个符号的连接点对上(坐标相同、朝向相对),EPLAN 就自己画红线。
|
|
183
|
+
item.Set("pins", DescribePins(sr));
|
|
184
|
+
item.Set("propertyPlacements", DescribePropertyPlacements(sr));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
Function f = p as Function;
|
|
188
|
+
if (f != null)
|
|
189
|
+
{
|
|
190
|
+
try { item.Set("name", f.Name); } catch { }
|
|
191
|
+
try { item.Set("visibleName", f.VisibleName); } catch { }
|
|
192
|
+
}
|
|
193
|
+
return item;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private static JsonValue DescribeFunction(Function f)
|
|
197
|
+
{
|
|
198
|
+
JsonValue item = JsonValue.NewObject();
|
|
199
|
+
try { item.Set("name", f.Name); } catch { }
|
|
200
|
+
try { item.Set("visibleName", f.VisibleName); } catch { }
|
|
201
|
+
try { item.Set("type", f.GetType().Name); } catch { }
|
|
202
|
+
|
|
203
|
+
SymbolReference sr = f as SymbolReference;
|
|
204
|
+
if (sr != null)
|
|
205
|
+
{
|
|
206
|
+
CopyIfExists(item, "symbolName", sr, new string[] { "SymbolName", "Name" });
|
|
207
|
+
CopyIfExists(item, "variant", sr, new string[] { "VariantNr", "Variant" });
|
|
208
|
+
}
|
|
209
|
+
return item;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private static SymbolVariant TryGetVariant(SymbolReference sr)
|
|
213
|
+
{
|
|
214
|
+
string[] names = { "BasedOnSymbolVariant", "SymbolVariant", "Variant" };
|
|
215
|
+
foreach (string name in names)
|
|
216
|
+
{
|
|
217
|
+
try
|
|
218
|
+
{
|
|
219
|
+
PropertyInfo info = sr.GetType().GetProperty(name);
|
|
220
|
+
if (info == null) continue;
|
|
221
|
+
object value = info.GetValue(sr, null);
|
|
222
|
+
SymbolVariant variant = value as SymbolVariant;
|
|
223
|
+
if (variant != null) return variant;
|
|
224
|
+
}
|
|
225
|
+
catch { }
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/// <summary>
|
|
231
|
+
/// 符号上挂的每一个属性摆放(PropertyPlacement)。
|
|
232
|
+
///
|
|
233
|
+
/// 这是排查「设备标识不显示」的关键:
|
|
234
|
+
/// 对象存在不等于图上能看到字,要逐条看 Contents 有没有内容、
|
|
235
|
+
/// Location 是不是在页面外、IsFromDevice 读的是设备值还是符号局部值。
|
|
236
|
+
/// </summary>
|
|
237
|
+
private static JsonValue DescribePropertyPlacements(SymbolReference sr)
|
|
238
|
+
{
|
|
239
|
+
JsonValue list = JsonValue.NewArray();
|
|
240
|
+
try
|
|
241
|
+
{
|
|
242
|
+
PropertyPlacement[] all = sr.PropertyPlacements;
|
|
243
|
+
if (all == null) return list;
|
|
244
|
+
foreach (PropertyPlacement p in all)
|
|
245
|
+
{
|
|
246
|
+
JsonValue o = JsonValue.NewObject();
|
|
247
|
+
try
|
|
248
|
+
{
|
|
249
|
+
JsonValue at = JsonValue.NewArray();
|
|
250
|
+
at.Add(JsonValue.NewNumber(p.Location.X));
|
|
251
|
+
at.Add(JsonValue.NewNumber(p.Location.Y));
|
|
252
|
+
o.Set("at", at);
|
|
253
|
+
}
|
|
254
|
+
catch { }
|
|
255
|
+
try { o.Set("text", p.GetDisplayString()); } catch { }
|
|
256
|
+
try { o.Set("contents", p.Contents.ToString()); } catch { }
|
|
257
|
+
try { o.Set("fromDevice", p.IsFromDevice); } catch { }
|
|
258
|
+
try { o.Set("height", JsonValue.NewNumber(p.Height)); } catch { }
|
|
259
|
+
list.Add(o);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch (Exception ex) { list.Add(JsonValue.NewString("PP_ERROR " + ex.Message)); }
|
|
263
|
+
return list;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// <summary>
|
|
267
|
+
/// 符号的连接点(Pin)。
|
|
268
|
+
///
|
|
269
|
+
/// PinBase 的成员是:Location(PointD)、Direction(Directions)、Index(Int32)、Parent。
|
|
270
|
+
/// Location 已经是**绝对坐标**,不用再加符号位置。
|
|
271
|
+
/// 这一组坐标就是 EPLAN 判断"该不该画红线"的唯一依据。
|
|
272
|
+
/// </summary>
|
|
273
|
+
private static JsonValue DescribePins(SymbolReference sr)
|
|
274
|
+
{
|
|
275
|
+
JsonValue list = JsonValue.NewArray();
|
|
276
|
+
try
|
|
277
|
+
{
|
|
278
|
+
PinBase[] pins = sr.GraphicalConnectionPoints;
|
|
279
|
+
if (pins == null) return list;
|
|
280
|
+
foreach (PinBase pin in pins)
|
|
281
|
+
{
|
|
282
|
+
if (pin == null) continue;
|
|
283
|
+
JsonValue item = JsonValue.NewObject();
|
|
284
|
+
try
|
|
285
|
+
{
|
|
286
|
+
JsonValue loc = JsonValue.NewArray();
|
|
287
|
+
loc.Add(JsonValue.NewNumber(pin.Location.X));
|
|
288
|
+
loc.Add(JsonValue.NewNumber(pin.Location.Y));
|
|
289
|
+
item.Set("location", loc);
|
|
290
|
+
}
|
|
291
|
+
catch { }
|
|
292
|
+
try { item.Set("direction", pin.Direction.ToString()); } catch { }
|
|
293
|
+
try { item.Set("index", JsonValue.NewNumber(pin.Index)); } catch { }
|
|
294
|
+
list.Add(item);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (Exception ex) { list.Add(JsonValue.NewString("PINS_ERROR " + ex.Message)); }
|
|
298
|
+
return list;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
private static void CopyPoint(JsonValue item, string key, object source, string propName)
|
|
302
|
+
{
|
|
303
|
+
try
|
|
304
|
+
{
|
|
305
|
+
PropertyInfo info = source.GetType().GetProperty(propName);
|
|
306
|
+
if (info == null) return;
|
|
307
|
+
object value = info.GetValue(source, null);
|
|
308
|
+
// PointD 是**结构体**,as 一定返回 null,必须直接判类型。
|
|
309
|
+
if (!(value is PointD)) return;
|
|
310
|
+
PointD point = (PointD)value;
|
|
311
|
+
JsonValue arr = JsonValue.NewArray();
|
|
312
|
+
arr.Add(JsonValue.NewNumber(point.X));
|
|
313
|
+
arr.Add(JsonValue.NewNumber(point.Y));
|
|
314
|
+
item.Set(key, arr);
|
|
315
|
+
}
|
|
316
|
+
catch { }
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private static void CopyIfExists(JsonValue item, string key, object source, string[] names)
|
|
320
|
+
{
|
|
321
|
+
foreach (string name in names)
|
|
322
|
+
{
|
|
323
|
+
try
|
|
324
|
+
{
|
|
325
|
+
PropertyInfo info = source.GetType().GetProperty(name);
|
|
326
|
+
if (info == null) continue;
|
|
327
|
+
object value = info.GetValue(source, null);
|
|
328
|
+
if (value == null) continue;
|
|
329
|
+
if (value is int) item.Set(key, JsonValue.NewNumber((int)value));
|
|
330
|
+
else item.Set(key, value.ToString());
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
catch { }
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/// <summary>
|
|
338
|
+
/// 自动连接:EPLAN 根据连接点与导线自动生成,画出来是红线。
|
|
339
|
+
/// 数量就是「有没有连上」最直接的证据。
|
|
340
|
+
/// </summary>
|
|
341
|
+
private static JsonValue DescribeConnections(Page page)
|
|
342
|
+
{
|
|
343
|
+
JsonValue result = JsonValue.NewObject();
|
|
344
|
+
string[] names = { "Connections", "AllConnections", "ConnectionList" };
|
|
345
|
+
foreach (string name in names)
|
|
346
|
+
{
|
|
347
|
+
try
|
|
348
|
+
{
|
|
349
|
+
PropertyInfo info = page.GetType().GetProperty(name);
|
|
350
|
+
if (info == null) continue;
|
|
351
|
+
object value = info.GetValue(page, null);
|
|
352
|
+
ICollection collection = value as ICollection;
|
|
353
|
+
if (collection != null)
|
|
354
|
+
{
|
|
355
|
+
result.Set("property", name);
|
|
356
|
+
result.Set("count", collection.Count);
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch { }
|
|
361
|
+
}
|
|
362
|
+
result.Set("count", -1);
|
|
363
|
+
result.Set("note", "Page 上没有 Connections 属性。");
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// 元件语义知识库(M3 实现)。
|
|
2
|
+
//
|
|
3
|
+
// 铁律:几何永远实时从 EPLAN 取(symbol_catalog(action="pins"),实测十几毫秒),**不落盘**。
|
|
4
|
+
// 落盘的只有「这个符号在这张图里是干什么的」这类模型推断出来的语义,而且必须带 source:
|
|
5
|
+
// derived —— 模型推断的
|
|
6
|
+
// verified —— 用户确认过的
|
|
7
|
+
//
|
|
8
|
+
// 为什么要这么死板:EPLAN 符号库没有文字描述(823 个符号,只有名字/类型/变体数),
|
|
9
|
+
// 所以「F1 是熔断器」这种知识只能靠人或者推断来补。一旦把它和引脚几何混在一个文件里,
|
|
10
|
+
// 过一个版本库变了,几何就是错的,而调用方分不出哪些是 EPLAN 说的、哪些是人猜的。
|
|
11
|
+
// 分开之后,几何永远新鲜,语义永远标注来源。
|
|
12
|
+
using System;
|
|
13
|
+
using System.Collections.Generic;
|
|
14
|
+
using System.Globalization;
|
|
15
|
+
using System.IO;
|
|
16
|
+
using System.Text;
|
|
17
|
+
using EplanMcp;
|
|
18
|
+
|
|
19
|
+
namespace EplanMcpHost
|
|
20
|
+
{
|
|
21
|
+
internal static class KnowledgeTool
|
|
22
|
+
{
|
|
23
|
+
internal static string FilePath
|
|
24
|
+
{
|
|
25
|
+
get { return Path.Combine(Paths.KnowledgeDir, "symbols.json"); }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 这些键属于几何,一律拒收 —— 收下来就等于把过期的引脚坐标当真话存起来了。
|
|
29
|
+
private static readonly string[] GeometryKeys = new string[] {
|
|
30
|
+
"pins", "pin", "geometry", "location", "locations", "points", "offset", "offsets", "direction"
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
private static JsonValue LoadAll()
|
|
34
|
+
{
|
|
35
|
+
try
|
|
36
|
+
{
|
|
37
|
+
if (!File.Exists(FilePath)) return JsonValue.NewObject();
|
|
38
|
+
string text = File.ReadAllText(FilePath, Encoding.UTF8);
|
|
39
|
+
if (text.Trim().Length == 0) return JsonValue.NewObject();
|
|
40
|
+
JsonValue parsed = Json.Parse(text);
|
|
41
|
+
return parsed != null && parsed.IsObject ? parsed : JsonValue.NewObject();
|
|
42
|
+
}
|
|
43
|
+
catch
|
|
44
|
+
{
|
|
45
|
+
return JsonValue.NewObject();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static void SaveAll(JsonValue all)
|
|
50
|
+
{
|
|
51
|
+
string dir = Path.GetDirectoryName(FilePath);
|
|
52
|
+
if (!string.IsNullOrEmpty(dir)) System.IO.Directory.CreateDirectory(dir);
|
|
53
|
+
File.WriteAllText(FilePath, Json.Write(all), new UTF8Encoding(false));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// <summary>读语义。参数:symbol / library / query。</summary>
|
|
57
|
+
public static JsonValue Get(JsonValue args)
|
|
58
|
+
{
|
|
59
|
+
string symbol = args["symbol"].AsString(null);
|
|
60
|
+
string library = args["library"].AsString(null);
|
|
61
|
+
string query = args["query"].AsString(null);
|
|
62
|
+
|
|
63
|
+
JsonValue all = LoadAll();
|
|
64
|
+
|
|
65
|
+
if (!string.IsNullOrEmpty(symbol))
|
|
66
|
+
{
|
|
67
|
+
string entryKey = Key(library, symbol);
|
|
68
|
+
JsonValue hit = all[entryKey];
|
|
69
|
+
JsonValue result = JsonValue.NewObject();
|
|
70
|
+
result.Set("symbol", JsonValue.NewString(symbol));
|
|
71
|
+
result.Set("library", library == null ? JsonValue.NewNull() : JsonValue.NewString(library));
|
|
72
|
+
result.Set("known", JsonValue.NewBool(hit != null && hit.IsObject));
|
|
73
|
+
if (hit != null && hit.IsObject) result.Set("entry", hit);
|
|
74
|
+
result.Set("note", "这里只有语义。引脚坐标请用 symbol_catalog(action=\"pins\") 实时取 —— 几何不落盘。");
|
|
75
|
+
result.Set("file", JsonValue.NewString(FilePath));
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
JsonValue matches = JsonValue.NewArray();
|
|
80
|
+
int total = all.Count;
|
|
81
|
+
if (all.IsObject)
|
|
82
|
+
{
|
|
83
|
+
foreach (string key in all.Keys)
|
|
84
|
+
{
|
|
85
|
+
JsonValue entry = all[key];
|
|
86
|
+
if (entry == null || !entry.IsObject) continue;
|
|
87
|
+
if (!string.IsNullOrEmpty(query))
|
|
88
|
+
{
|
|
89
|
+
string hay = (entry["concept"].AsString("") + " " + entry["usage"].AsString("") + " " + key);
|
|
90
|
+
if (hay.IndexOf(query, StringComparison.OrdinalIgnoreCase) < 0) continue;
|
|
91
|
+
}
|
|
92
|
+
matches.Add(entry);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
JsonValue result2 = JsonValue.NewObject();
|
|
97
|
+
result2.Set("query", query == null ? JsonValue.NewNull() : JsonValue.NewString(query));
|
|
98
|
+
result2.Set("total", JsonValue.NewNumber(total));
|
|
99
|
+
result2.Set("matchedCount", JsonValue.NewNumber(matches.Count));
|
|
100
|
+
result2.Set("entries", matches);
|
|
101
|
+
result2.Set("file", JsonValue.NewString(FilePath));
|
|
102
|
+
if (total == 0)
|
|
103
|
+
result2.Set("note", "知识库还是空的。用 symbol_catalog(action=\"annotate\") 把你确认过的元件含义写进来。");
|
|
104
|
+
return result2;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/// <summary>写回语义。参数:symbol / library / concept / usage / verified。</summary>
|
|
108
|
+
public static JsonValue Annotate(JsonValue args)
|
|
109
|
+
{
|
|
110
|
+
string symbol = args["symbol"].AsString(null);
|
|
111
|
+
if (string.IsNullOrEmpty(symbol))
|
|
112
|
+
throw new HostException("BAD_ARGUMENT", "要给 symbol,例如 \"F1\"。", "只记录语义,几何不用传。");
|
|
113
|
+
|
|
114
|
+
string library = args["library"].AsString(null);
|
|
115
|
+
string concept = args["concept"].AsString(null);
|
|
116
|
+
string usage = args["usage"].AsString(null);
|
|
117
|
+
bool verified = args["verified"].AsBool(false);
|
|
118
|
+
|
|
119
|
+
JsonValue ignored = JsonValue.NewArray();
|
|
120
|
+
if (args.IsObject)
|
|
121
|
+
{
|
|
122
|
+
foreach (string key in args.Keys)
|
|
123
|
+
{
|
|
124
|
+
foreach (string geometryKey in GeometryKeys)
|
|
125
|
+
{
|
|
126
|
+
if (string.Equals(key, geometryKey, StringComparison.OrdinalIgnoreCase))
|
|
127
|
+
{
|
|
128
|
+
ignored.Add(JsonValue.NewString(key));
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
JsonValue all = LoadAll();
|
|
136
|
+
string entryKey = Key(library, symbol);
|
|
137
|
+
JsonValue existing = all[entryKey];
|
|
138
|
+
JsonValue entry = existing != null && existing.IsObject ? existing : JsonValue.NewObject();
|
|
139
|
+
|
|
140
|
+
entry.Set("symbol", JsonValue.NewString(symbol));
|
|
141
|
+
if (!string.IsNullOrEmpty(library)) entry.Set("library", JsonValue.NewString(library));
|
|
142
|
+
if (!string.IsNullOrEmpty(concept)) entry.Set("concept", JsonValue.NewString(concept));
|
|
143
|
+
if (!string.IsNullOrEmpty(usage)) entry.Set("usage", JsonValue.NewString(usage));
|
|
144
|
+
entry.Set("source", JsonValue.NewString(verified ? "verified" : "derived"));
|
|
145
|
+
entry.Set("updatedAt", JsonValue.NewString(DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture)));
|
|
146
|
+
|
|
147
|
+
all.Set(entryKey, entry);
|
|
148
|
+
SaveAll(all);
|
|
149
|
+
|
|
150
|
+
JsonValue result = JsonValue.NewObject();
|
|
151
|
+
result.Set("saved", JsonValue.NewBool(true));
|
|
152
|
+
result.Set("key", JsonValue.NewString(entryKey));
|
|
153
|
+
result.Set("entry", entry);
|
|
154
|
+
result.Set("file", JsonValue.NewString(FilePath));
|
|
155
|
+
if (ignored.Count > 0)
|
|
156
|
+
result.Set("ignoredGeometryKeys", ignored);
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static string Key(string library, string symbol)
|
|
161
|
+
{
|
|
162
|
+
string lib = string.IsNullOrEmpty(library) ? "?" : library;
|
|
163
|
+
return lib + "|" + symbol;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|