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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -3
  3. package/cordis.patch.yml +182 -0
  4. package/docs/INSTALL.md +86 -0
  5. package/docs/LESSONS.md +224 -0
  6. package/docs/interfaces.md +183 -0
  7. package/docs/merged-skills/eplan-setup.md +63 -0
  8. package/docs/merged-skills/eplan-troubleshooting.md +149 -0
  9. package/icon.png +0 -0
  10. package/icon.svg +13 -0
  11. package/knowledge/KNOWLEDGE.md +413 -0
  12. package/knowledge/symbols/BP.png +0 -0
  13. package/knowledge/symbols/CDPST.png +0 -0
  14. package/knowledge/symbols/CO.png +0 -0
  15. package/knowledge/symbols/FA3.png +0 -0
  16. package/knowledge/symbols/TLRO.png +0 -0
  17. package/knowledge/symbols/TLRU.png +0 -0
  18. package/knowledge/symbols/TOUL.png +0 -0
  19. package/knowledge/symbols/TOUR.png +0 -0
  20. package/knowledge/symbols/manifest.json +91 -0
  21. package/locale/en.json +6 -0
  22. package/locale/zh.json +6 -0
  23. package/native/bridge/build.ps1 +73 -0
  24. package/native/bridge/src/Json.cs +383 -0
  25. package/native/bridge/src/Program.cs +1133 -0
  26. package/native/host/build.ps1 +74 -0
  27. package/native/host/src/ActionsTool.cs +225 -0
  28. package/native/host/src/BoxTool.cs +196 -0
  29. package/native/host/src/CheckTool.cs +186 -0
  30. package/native/host/src/Context.cs +169 -0
  31. package/native/host/src/DarkScheme.cs +111 -0
  32. package/native/host/src/DiagnoseTool.cs +115 -0
  33. package/native/host/src/Dispatcher.cs +51 -0
  34. package/native/host/src/DrawTool.cs +316 -0
  35. package/native/host/src/Entry.cs +111 -0
  36. package/native/host/src/ExportTool.cs +213 -0
  37. package/native/host/src/InspectTool.cs +367 -0
  38. package/native/host/src/KnowledgeTool.cs +166 -0
  39. package/native/host/src/LookTool.cs +257 -0
  40. package/native/host/src/OpLog.cs +289 -0
  41. package/native/host/src/PageCreateTool.cs +521 -0
  42. package/native/host/src/PageOpenTool.cs +62 -0
  43. package/native/host/src/PagesTool.cs +95 -0
  44. package/native/host/src/Paths.cs +91 -0
  45. package/native/host/src/PlacementEditTool.cs +234 -0
  46. package/native/host/src/ProbePropsTool.cs +152 -0
  47. package/native/host/src/ProjectCreateTool.cs +176 -0
  48. package/native/host/src/ProjectTool.cs +167 -0
  49. package/native/host/src/PropWriter.cs +70 -0
  50. package/native/host/src/PropsTool.cs +257 -0
  51. package/native/host/src/StatusTool.cs +168 -0
  52. package/native/host/src/SymbolInfoTool.cs +144 -0
  53. package/native/host/src/SymbolInsertTool.cs +261 -0
  54. package/native/host/src/SymbolsTool.cs +94 -0
  55. package/native/host/src/TagLocTool.cs +108 -0
  56. package/native/script/EplanMcpBootstrap.cs +221 -0
  57. package/native/script/build-symbol-gallery.mjs +231 -0
  58. package/native/script/prepare-install.ps1 +57 -0
  59. package/native/script/prune.mjs +132 -0
  60. package/native/script/verify-bootstrap.ps1 +62 -0
  61. package/package.json +53 -4
  62. package/preset/bootstrap.js +498 -0
  63. package/preset/experience-nudge.js +47 -0
  64. package/preset/image-budget.js +175 -0
  65. package/preset/knowledge-tool.js +180 -0
  66. package/preset/mcp-link.js +100 -0
  67. package/preset/prompt-surface.js +76 -0
  68. package/preset/restrict-tools.js +141 -0
  69. package/preset/skill-docs.js +181 -0
  70. package/preset/video-digest.js +294 -0
  71. package/preset/video-tool.js +92 -0
  72. package/server/compact.mjs +623 -0
  73. package/server/edit-args.mjs +67 -0
  74. package/server/fuzzy.mjs +57 -0
  75. package/server/launch-decision.mjs +26 -0
  76. package/server/measure.mjs +320 -0
  77. package/server/pdf.mjs +185 -0
  78. package/server/pdf2png.ps1 +99 -0
  79. package/server/server.mjs +3797 -0
  80. package/server/video.mjs +857 -0
  81. package/setup.mjs +223 -0
  82. package/skills/eplan-annotations/SKILL.md +55 -0
  83. package/skills/eplan-drawing/SKILL.md +206 -0
  84. package/skills/eplan-project/SKILL.md +41 -0
  85. package/skills/eplan-review/SKILL.md +80 -0
  86. package/skills/eplan-symbols/SKILL.md +142 -0
  87. package/test/check-docs.mjs +106 -0
  88. package/test/foreground.ps1 +21 -0
  89. package/test/smoke-all.mjs +229 -0
@@ -0,0 +1,74 @@
1
+ # 编译 EPLAN 进程内宿主 EplanMcpHost-<ticks>.dll。
2
+ #
3
+ # 与桥接器的区别:宿主必须引用 DataModel / HEServices / Base,因为它要真的画图。
4
+ # 用 .NET Framework 4.x 的 csc.exe(C# 5 语言版本),所以源码里不能出现
5
+ # 字符串内插、? 、nameof、表达式体成员。
6
+ #
7
+ # 产物带时间戳后缀:EPLAN 加载后会锁住 DLL 文件,覆盖会报 CS0016。
8
+ # 每次构建产生新文件名,引导脚本每次调用挑最新的那个,实现热重载。
9
+ #
10
+ # 用法: powershell -NoProfile -ExecutionPolicy Bypass -File native\host\build.ps1
11
+ $ErrorActionPreference = 'Stop'
12
+
13
+ $root = Split-Path -Parent $PSScriptRoot
14
+ # EPLAN 安装目录:先看 EPLAN_BIN,再看 setup.mjs 写的配置,最后才是本机默认路径。
15
+ $eplanBin = 'D:\EPLAN\Platform\2.9.4\Bin'
16
+ if ($env:EPLAN_BIN -and (Test-Path -LiteralPath $env:EPLAN_BIN)) {
17
+ $eplanBin = $env:EPLAN_BIN
18
+ } else {
19
+ $configFile = Join-Path (Join-Path $env:LOCALAPPDATA 'eplan-mcp') 'eplan.config.json'
20
+ if (Test-Path -LiteralPath $configFile) {
21
+ try {
22
+ $configured = (Get-Content -LiteralPath $configFile -Raw -Encoding UTF8 | ConvertFrom-Json).eplanExe
23
+ if ($configured -and (Test-Path -LiteralPath $configured)) { $eplanBin = Split-Path -Parent $configured }
24
+ } catch { }
25
+ }
26
+ }
27
+ $csc = Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319\csc.exe'
28
+ $outDir = Join-Path $PSScriptRoot 'bin'
29
+
30
+ if (-not (Test-Path -LiteralPath $csc)) { throw "找不到 csc.exe: $csc" }
31
+ if (-not (Test-Path -LiteralPath $outDir)) { New-Item -ItemType Directory -Path $outDir | Out-Null }
32
+
33
+ $stamp = [DateTime]::UtcNow.Ticks
34
+ $outDll = Join-Path $outDir ("EplanMcpHost-$stamp.dll")
35
+
36
+ # 宿主 + 共用 JSON 源码一起编进同一个 DLL。
37
+ $sources = New-Object System.Collections.ArrayList
38
+ [void]$sources.Add((Join-Path $root 'bridge\src\Json.cs'))
39
+ $hostSources = Get-ChildItem -LiteralPath (Join-Path $PSScriptRoot 'src') -Filter '*.cs' | Sort-Object Name
40
+ foreach ($file in $hostSources) { [void]$sources.Add($file.FullName) }
41
+
42
+ $refs = New-Object System.Collections.ArrayList
43
+ foreach ($name in @('Eplan.EplApi.Baseu.dll', 'Eplan.EplApi.DataModelu.dll', 'Eplan.EplApi.AFu.dll', 'Eplan.EplApi.HEServicesu.dll', 'Eplan.EplApi.Systemu.dll')) {
44
+ $path = Join-Path $eplanBin $name
45
+ if (-not (Test-Path -LiteralPath $path)) { throw "缺少引用: $path" }
46
+ [void]$refs.Add($path)
47
+ }
48
+
49
+ $arguments = New-Object System.Collections.ArrayList
50
+ foreach ($a in @('-nologo', '-target:library', '-platform:x64', '-optimize+', '-langversion:5')) { [void]$arguments.Add($a) }
51
+ [void]$arguments.Add("-out:$outDll")
52
+ foreach ($r in $refs) { [void]$arguments.Add("-r:$r") }
53
+ foreach ($s in $sources) { [void]$arguments.Add($s) }
54
+
55
+ Write-Host "csc -> $(Split-Path -Leaf $outDll)"
56
+ Write-Host ("源文件 " + $sources.Count + " 个")
57
+
58
+ $argArray = $arguments.ToArray()
59
+ & $csc $argArray
60
+ if ($LASTEXITCODE -ne 0) { throw "编译失败,退出码 $LASTEXITCODE" }
61
+ if (-not (Test-Path -LiteralPath $outDll)) { throw "未产出 $outDll" }
62
+
63
+ # 只保留最近 5 个版本,免得目录里堆几百个 DLL。
64
+ $old = Get-ChildItem -LiteralPath $outDir -Filter 'EplanMcpHost-*.dll' |
65
+ Sort-Object LastWriteTimeUtc -Descending | Select-Object -Skip 5
66
+ foreach ($file in $old) {
67
+ try { Remove-Item -LiteralPath $file.FullName -Force -ErrorAction Stop }
68
+ catch {
69
+ # 被 EPLAN 锁住的删不掉,留着无妨(引导脚本只挑最新的)。
70
+ }
71
+ }
72
+
73
+ Write-Host "OK $outDll" -ForegroundColor Green
74
+ Write-Host '重新生成引导脚本: powershell -NoProfile -ExecutionPolicy Bypass -File native\script\prepare-install.ps1' -ForegroundColor DarkGray
@@ -0,0 +1,225 @@
1
+ // actions:查 EPLAN 里到底有哪些动作。
2
+ //
3
+ // 为什么需要:ActionManager 是**进程内** API,在 EPLAN 外面(通过 Remoting 连过来的
4
+ // 测试程序)调用 FindAction 对任何名字都永远返回 null。只有在 EPLAN 进程内查才有意义。
5
+ //
6
+ // 用途:
7
+ // 1. 批量探测动作名是否存在
8
+ // 2. 枚举所有已注册动作(list=true),找界面跳转之类的内部动作
9
+ using System;
10
+ using System.Collections.Generic;
11
+ using System.Reflection;
12
+ using Eplan.EplApi.ApplicationFramework;
13
+ using EplanMcp;
14
+
15
+ namespace EplanMcpHost
16
+ {
17
+ internal static class ActionsTool
18
+ {
19
+ public static JsonValue Run(JsonValue args)
20
+ {
21
+ JsonValue result = JsonValue.NewObject();
22
+ ActionManager manager = new ActionManager();
23
+
24
+ string probe = args["probe"].AsString(null);
25
+ if (!string.IsNullOrEmpty(probe))
26
+ {
27
+ result.Set("probe", probe);
28
+ result.Set("found", Exists(manager, probe));
29
+ return result;
30
+ }
31
+
32
+ JsonValue names = args["names"];
33
+ if (names != null && names.IsArray && names.Count > 0)
34
+ {
35
+ JsonValue found = JsonValue.NewArray();
36
+ JsonValue missing = JsonValue.NewArray();
37
+ for (int i = 0; i < names.Count; i++)
38
+ {
39
+ string name = names[i].AsString(null);
40
+ if (string.IsNullOrEmpty(name)) continue;
41
+ if (Exists(manager, name)) found.Add(JsonValue.NewString(name));
42
+ else missing.Add(JsonValue.NewString(name));
43
+ }
44
+ result.Set("found", found);
45
+ result.Set("missing", missing);
46
+ return result;
47
+ }
48
+
49
+ // 查一个动作的元数据(参数名就在里面)。
50
+ // 用途:像 XSeGotoGraphicOpenPageAction 这种没文档的内部动作,
51
+ // 靠它才能知道参数该叫什么,而不是一个个试。
52
+ string props = args["props"].AsString(null);
53
+ if (!string.IsNullOrEmpty(props))
54
+ {
55
+ Eplan.EplApi.ApplicationFramework.Action target = manager.FindAction(props, true);
56
+ if (target == null)
57
+ throw new HostException("ACTION_MISSING", "EPLAN 里没有动作:" + props);
58
+ result.Set("action", props);
59
+ // Action 包装类没有 GetActionProperties(那是 IEplAction 上的方法),
60
+ // 所以这里直接把这个对象能读到的成员倒出来,参数名就从里面找。
61
+ result.Set("members", DescribeProperties(target));
62
+ // ActionProperties.GetParameterProperties() 返回这个动作的全部参数定义,
63
+ // 内部动作的参数名只能从这里拿到。
64
+ try
65
+ {
66
+ System.Reflection.MethodInfo gp =
67
+ target.ActionProperties.GetType().GetMethod("GetParameterProperties");
68
+ if (gp != null)
69
+ {
70
+ object raw = gp.Invoke(target.ActionProperties, null);
71
+ JsonValue defs = JsonValue.NewArray();
72
+ System.Collections.IEnumerable items = raw as System.Collections.IEnumerable;
73
+ if (items != null)
74
+ {
75
+ foreach (object item in items)
76
+ defs.Add(DescribeProperties(item));
77
+ }
78
+ result.Set("parameterDefs", defs);
79
+ }
80
+ }
81
+ catch (Exception ex)
82
+ {
83
+ result.Set("parameterDefsError", ex.GetType().Name + ": " + ex.Message);
84
+ }
85
+ return result;
86
+ }
87
+
88
+ // 执行一个动作:参数要通过 ActionCallingContext 传。
89
+ string run = args["run"].AsString(null);
90
+ if (!string.IsNullOrEmpty(run))
91
+ {
92
+ result.Set("run", run);
93
+ JsonValue parameters = args["parameters"];
94
+ string output = Execute(manager, run, parameters);
95
+ result.Set("executed", output != null);
96
+ if (output != null) result.Set("message", output);
97
+ return result;
98
+ }
99
+
100
+ // 枚举:ActionManager 没有公开的枚举方法,用反射找私有成员。
101
+ result.Set("methods", DescribeMembers(manager.GetType()));
102
+ return result;
103
+ }
104
+
105
+ /// <summary>
106
+ /// 在当前(EPLAN 主线程)上下文里执行一个动作。
107
+ /// 返回动作写进 context.Message 的文本,没有则为空串。
108
+ /// </summary>
109
+ private static string Execute(ActionManager manager, string name, JsonValue parameters)
110
+ {
111
+ Eplan.EplApi.ApplicationFramework.Action action = manager.FindAction(name, true);
112
+ if (action == null) return null;
113
+
114
+ ActionCallingContext context = new ActionCallingContext();
115
+ if (parameters != null && parameters.IsObject)
116
+ {
117
+ foreach (string key in parameters.Keys)
118
+ context.AddParameter(key, parameters[key].AsString(string.Empty));
119
+ }
120
+
121
+ try
122
+ {
123
+ action.Execute(context);
124
+ }
125
+ catch (Exception ex)
126
+ {
127
+ return "EXECUTE_FAILED " + ex.GetType().Name + ": " + ex.Message;
128
+ }
129
+
130
+ // ActionCallingContext 没有 Message 属性;要读消息得拿它的参数块。
131
+ try
132
+ {
133
+ Eplan.EplApi.Base.ContextParameterBlock block = context.GetContextParameter();
134
+ object raw = null;
135
+ if (block != null && block.Get("Message", ref raw) && raw != null)
136
+ return raw as string ?? raw.ToString();
137
+ }
138
+ catch { }
139
+ return string.Empty;
140
+ }
141
+
142
+ /// <summary>把 ActionProperties 的公开成员和当前值倒出来。</summary>
143
+ private static JsonValue DescribeProperties(object properties)
144
+ {
145
+ JsonValue list = JsonValue.NewArray();
146
+ if (properties == null) return list;
147
+ Type type = properties.GetType();
148
+ BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
149
+
150
+ foreach (PropertyInfo p in type.GetProperties(flags))
151
+ {
152
+ JsonValue item = JsonValue.NewObject();
153
+ item.Set("kind", "property");
154
+ item.Set("name", p.Name);
155
+ item.Set("type", p.PropertyType.Name);
156
+ try
157
+ {
158
+ object value = p.GetValue(properties, null);
159
+ if (value != null) item.Set("value", value.ToString());
160
+ }
161
+ catch { }
162
+ list.Add(item);
163
+ }
164
+
165
+ foreach (MethodInfo m in type.GetMethods(flags))
166
+ {
167
+ if (m.IsSpecialName) continue;
168
+ if (m.DeclaringType == typeof(object)) continue;
169
+ JsonValue item = JsonValue.NewObject();
170
+ item.Set("kind", "method");
171
+ item.Set("name", m.Name);
172
+ JsonValue ps = JsonValue.NewArray();
173
+ foreach (ParameterInfo p in m.GetParameters())
174
+ ps.Add(JsonValue.NewString(p.ParameterType.Name + " " + p.Name));
175
+ item.Set("params", ps);
176
+ list.Add(item);
177
+ }
178
+ return list;
179
+ }
180
+
181
+ private static JsonValue DescribeMembers(Type type)
182
+ {
183
+ JsonValue list = JsonValue.NewArray();
184
+ BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
185
+
186
+ foreach (MethodInfo m in type.GetMethods(flags))
187
+ {
188
+ if (m.IsSpecialName) continue;
189
+ JsonValue item = JsonValue.NewObject();
190
+ item.Set("kind", "method");
191
+ item.Set("name", m.Name);
192
+ item.Set("isPublic", m.IsPublic);
193
+ JsonValue ps = JsonValue.NewArray();
194
+ foreach (ParameterInfo p in m.GetParameters())
195
+ ps.Add(JsonValue.NewString(p.ParameterType.Name + " " + p.Name));
196
+ item.Set("params", ps);
197
+ list.Add(item);
198
+ }
199
+ foreach (PropertyInfo p in type.GetProperties(flags))
200
+ {
201
+ JsonValue item = JsonValue.NewObject();
202
+ item.Set("kind", "property");
203
+ item.Set("name", p.Name);
204
+ item.Set("type", p.PropertyType.Name);
205
+ item.Set("isPublic", p.GetMethod != null && p.GetMethod.IsPublic);
206
+ list.Add(item);
207
+ }
208
+ return list;
209
+ }
210
+
211
+ private static bool Exists(ActionManager manager, string name)
212
+ {
213
+ try
214
+ {
215
+ // 写全名:System.Action 和 Eplan 的 Action 会撞名(CS0104)。
216
+ Eplan.EplApi.ApplicationFramework.Action action = manager.FindAction(name, true);
217
+ return action != null;
218
+ }
219
+ catch
220
+ {
221
+ return false;
222
+ }
223
+ }
224
+ }
225
+ }
@@ -0,0 +1,196 @@
1
+ // box:在页面上画「黑箱」——黄色矩形 + 边缘的连接点(DCP)。
2
+ //
3
+ // 为什么不直接用 EPLAN 的 BoxedDevice:实测(2026-11-09)API 建出来的 BoxedDevice
4
+ // 要么渲染成一个红色叉(占位符),要么按固定符号尺寸画个小方框,SetLogicalArea
5
+ // 只改 Location 不拉伸图形,AddConnectionPointPosition 也存不住。GUI 里那个
6
+ // 黄框黑箱没法从 API 复刻,所以这里用「黄色矩形 + DCP 端子」的组合表达:
7
+ // * 矩形用 Graphics.Rectangle + Pen.ColorId=2(黄),和界面里黑箱同色;
8
+ // * 连接点用 SPECIAL/DCP,deviceTag 写 "-U1:SD",DCP 自己会把 SD 渲染出来;
9
+ // * 端子朝向按所在边选变体:上=0、左=1、下=2、右=3,引脚正好落在框线上。
10
+ using System;
11
+ using Eplan.EplApi.Base;
12
+ using Eplan.EplApi.DataModel;
13
+ using Eplan.EplApi.DataModel.Graphics;
14
+ using EplanMcp;
15
+
16
+ namespace EplanMcpHost
17
+ {
18
+ internal static class BoxTool
19
+ {
20
+ public static JsonValue Run(JsonValue args)
21
+ {
22
+ Page page = Context.FindPage(args["page"].AsString(null), args["project"].AsString(null));
23
+ PointD from = Context.Point(args["from"], "from");
24
+ PointD to = Context.Point(args["to"], "to");
25
+ string color = args["color"].AsString("yellow");
26
+ double width = args["width"].AsDouble(0.35);
27
+ string deviceTag = args["deviceTag"].AsString(null);
28
+ bool dryRun = args["dryRun"].AsBool(false);
29
+ JsonValue pins = args["pins"];
30
+
31
+ Int16 colorId;
32
+ if (!DrawTool.TryColor(color, out colorId))
33
+ throw new HostException("BAD_ARGUMENT",
34
+ "不认识的颜色「" + color + "」,可用 yellow / red / green / cyan / blue / magenta / black / gray,或 1-12 的数字。");
35
+
36
+ double left = Math.Min(from.X, to.X);
37
+ double right = Math.Max(from.X, to.X);
38
+ double bottom = Math.Min(from.Y, to.Y);
39
+ double top = Math.Max(from.Y, to.Y);
40
+ bool hasPins = pins != null && pins.IsArray && pins.Count > 0;
41
+ if (hasPins && string.IsNullOrEmpty(deviceTag))
42
+ throw new HostException("BAD_ARGUMENT", "pins 需要 deviceTag(例如 -U1),否则连接点代号渲染不出来。");
43
+
44
+ JsonValue result = JsonValue.NewObject();
45
+ result.Set("page", page.Name);
46
+ result.Set("rect", Points(left, bottom, right, top));
47
+ result.Set("color", color);
48
+ result.Set("width", width);
49
+ result.Set("pinsRequested", hasPins ? pins.Count : 0);
50
+ result.Set("dryRun", dryRun);
51
+
52
+ if (dryRun)
53
+ {
54
+ result.Set("created", false);
55
+ result.Set("wouldCreate", JsonValue.NewNumber(1 + (hasPins ? pins.Count : 0) + (string.IsNullOrEmpty(deviceTag) ? 0 : 1)));
56
+ return result;
57
+ }
58
+
59
+ // 1) 矩形。Pen.ColorId 就是固定调色板编号,2 = 黄。
60
+ Rectangle rect = new Rectangle();
61
+ rect.Create(page);
62
+ rect.SetArea(new PointD(left, bottom), new PointD(right, top));
63
+ Pen pen = new Pen();
64
+ pen.ColorId = colorId;
65
+ if (width > 0) pen.Width = width;
66
+ rect.Pen = pen;
67
+ JsonValue rectInfo = JsonValue.NewObject();
68
+ rectInfo.Set("kind", "rect");
69
+ try { rectInfo.Set("objectId", rect.ObjectIdentifier.ToString()); } catch { }
70
+ result.Set("rectObject", rectInfo);
71
+
72
+ // 2) 器件标识写在框左上角外面,和界面里黑箱的 -U1 同位。
73
+ JsonValue texts = JsonValue.NewArray();
74
+ if (!string.IsNullOrEmpty(deviceTag))
75
+ {
76
+ try
77
+ {
78
+ Text label = new Text();
79
+ label.Create(page, deviceTag, 2.5);
80
+ label.Location = new PointD(left, top + 1.5);
81
+ JsonValue t = JsonValue.NewObject();
82
+ t.Set("text", deviceTag);
83
+ t.Set("at", Point2(left, top + 1.5));
84
+ texts.Add(t);
85
+ }
86
+ catch (Exception ex)
87
+ {
88
+ result.Set("tagWarning", "器件标识已作为连接点前缀使用,文本框没画出来:" + ex.Message);
89
+ }
90
+ }
91
+ result.Set("texts", texts);
92
+
93
+ // 3) 连接点:DCP 变体按边选,位置沿边分布。
94
+ JsonValue placed = JsonValue.NewArray();
95
+ JsonValue failed = JsonValue.NewArray();
96
+ if (hasPins)
97
+ {
98
+ for (int i = 0; i < pins.Count; i++)
99
+ {
100
+ JsonValue pin = pins[i];
101
+ string name = pin["name"].AsString(null);
102
+ if (string.IsNullOrEmpty(name))
103
+ {
104
+ JsonValue bad = JsonValue.NewObject();
105
+ bad.Set("index", JsonValue.NewNumber(i));
106
+ bad.Set("error", "缺少 name");
107
+ failed.Add(bad);
108
+ continue;
109
+ }
110
+ string side = (pin["side"].AsString("top") ?? "top").ToLowerInvariant();
111
+ double at = pin["at"] == null ? double.NaN : pin["at"].AsDouble(double.NaN);
112
+ double x;
113
+ double y;
114
+ int variant;
115
+ if (side == "top") { x = Slot(at, left, right, i, pins.Count); y = top - 4; variant = 0; }
116
+ else if (side == "bottom") { x = Slot(at, left, right, i, pins.Count); y = bottom + 4; variant = 2; }
117
+ else if (side == "left") { y = Slot(at, bottom, top, i, pins.Count); x = left + 2; variant = 1; }
118
+ else if (side == "right") { y = Slot(at, bottom, top, i, pins.Count); x = right - 2; variant = 3; }
119
+ else
120
+ {
121
+ JsonValue bad = JsonValue.NewObject();
122
+ bad.Set("index", JsonValue.NewNumber(i));
123
+ bad.Set("error", "side 只能是 top / bottom / left / right,收到「" + side + "」");
124
+ failed.Add(bad);
125
+ continue;
126
+ }
127
+
128
+ JsonValue nodeArgs = JsonValue.NewObject();
129
+ nodeArgs.Set("page", page.Name);
130
+ nodeArgs.Set("project", page.Project.ProjectName);
131
+ nodeArgs.Set("library", "SPECIAL");
132
+ nodeArgs.Set("symbol", "DCP");
133
+ nodeArgs.Set("variant", JsonValue.NewNumber(variant));
134
+ nodeArgs.Set("at", Point2(x, y));
135
+ nodeArgs.Set("deviceTag", deviceTag + ":" + name);
136
+ nodeArgs.Set("showDeviceTag", JsonValue.NewBool(false));
137
+ try
138
+ {
139
+ JsonValue one = SymbolInsertTool.Run(nodeArgs);
140
+ JsonValue brief = JsonValue.NewObject();
141
+ brief.Set("index", JsonValue.NewNumber(i));
142
+ brief.Set("name", name);
143
+ brief.Set("side", side);
144
+ brief.Set("at", Point2(x, y));
145
+ brief.Set("variant", JsonValue.NewNumber(variant));
146
+ brief.Set("deviceTag", deviceTag + ":" + name);
147
+ if (one != null) brief.Set("object", one["object"]);
148
+ placed.Add(brief);
149
+ }
150
+ catch (Exception ex)
151
+ {
152
+ JsonValue bad = JsonValue.NewObject();
153
+ bad.Set("index", JsonValue.NewNumber(i));
154
+ bad.Set("name", name);
155
+ bad.Set("error", ex.Message);
156
+ failed.Add(bad);
157
+ }
158
+ }
159
+ }
160
+ result.Set("pins", placed);
161
+ if (failed.Count > 0) result.Set("failed", failed);
162
+ result.Set("ok", failed.Count == 0);
163
+ return result;
164
+ }
165
+
166
+ /// <summary>给一个坐标就吸附到 [lo,hi],没给就按序号平均分。</summary>
167
+ private static double Slot(double at, double lo, double hi, int index, int count)
168
+ {
169
+ if (!double.IsNaN(at)) return Math.Min(Math.Max(at, lo + 2), hi - 2);
170
+ return lo + (hi - lo) * (index + 1) / (count + 1);
171
+ }
172
+
173
+ private static JsonValue Point2(double x, double y)
174
+ {
175
+ JsonValue a = JsonValue.NewArray();
176
+ a.Add(JsonValue.NewNumber(x));
177
+ a.Add(JsonValue.NewNumber(y));
178
+ return a;
179
+ }
180
+
181
+ private static JsonValue Points(double x1, double y1, double x2, double y2)
182
+ {
183
+ JsonValue a = JsonValue.NewArray();
184
+ a.Add(JsonValue.NewNumber(x1));
185
+ a.Add(JsonValue.NewNumber(y1));
186
+ JsonValue b = JsonValue.NewArray();
187
+ b.Add(JsonValue.NewNumber(x2));
188
+ b.Add(JsonValue.NewNumber(y2));
189
+ JsonValue pair = JsonValue.NewArray();
190
+ pair.Add(a);
191
+ pair.Add(b);
192
+ return pair;
193
+ }
194
+ }
195
+ }
196
+
@@ -0,0 +1,186 @@
1
+ // check:把「这页画得规不规范」变成可验收的检查,而不是靠眼看。
2
+ //
3
+ // 为什么需要它:EPLAN 不会因为你摆错位置就报错。元件歪了、引脚没对齐、
4
+ // 设备标识重复、拿画笔画了条绿线冒充导线 —— 这些都能存盘、都能导出,
5
+ // 但在真正的电气设计里全是错的。这个工具把这类问题逐条挑出来。
6
+ using System;
7
+ using System.Collections.Generic;
8
+ using Eplan.EplApi.DataModel;
9
+ using Eplan.EplApi.DataModel.Graphics;
10
+ using EplanMcp;
11
+
12
+ namespace EplanMcpHost
13
+ {
14
+ internal static class CheckTool
15
+ {
16
+ public static JsonValue Run(JsonValue args)
17
+ {
18
+ Page page = Context.FindPage(args["page"].AsString(null), args["project"].AsString(null));
19
+ Project project = page.Project;
20
+
21
+ JsonValue result = JsonValue.NewObject();
22
+ result.Set("page", page.Name);
23
+ result.Set("project", project.ProjectName);
24
+
25
+ double grid = args["grid"].AsDouble(4.0);
26
+
27
+ List<string> problems = new List<string>();
28
+ List<string> warnings = new List<string>();
29
+ List<string> info = new List<string>();
30
+
31
+ // ── 1. 手绘线:draw 画出来的绿线不是电气连接,EPLAN 不会把它当导线 ──
32
+ int handDrawn = 0;
33
+ JsonValue handDrawnSample = JsonValue.NewArray();
34
+ foreach (Placement placement in page.AllPlacements)
35
+ {
36
+ if (!(placement is Line)) continue;
37
+ handDrawn++;
38
+ if (handDrawnSample.Count < 6)
39
+ {
40
+ Line line = (Line)placement;
41
+ handDrawnSample.Add(JsonValue.NewString(
42
+ "(" + line.StartPoint.X + "," + line.StartPoint.Y + ") → (" +
43
+ line.EndPoint.X + "," + line.EndPoint.Y + ")"));
44
+ }
45
+ }
46
+ if (handDrawn > 0)
47
+ problems.Add("有 " + handDrawn + " 条手绘线。红线应由符号引脚自动生成,手绘线不会形成连接关系。");
48
+
49
+ // ── 2. 元件:设备标识、栅格、引脚 ──
50
+ List<SymbolReference> symbols = new List<SymbolReference>();
51
+ foreach (Placement placement in page.AllPlacements)
52
+ {
53
+ SymbolReference reference = placement as SymbolReference;
54
+ if (reference != null) symbols.Add(reference);
55
+ }
56
+
57
+ Dictionary<string, int> tagCounts = new Dictionary<string, int>();
58
+ JsonValue offGrid = JsonValue.NewArray();
59
+ JsonValue noTag = JsonValue.NewArray();
60
+ int pinTotal = 0;
61
+
62
+ foreach (SymbolReference reference in symbols)
63
+ {
64
+ Function function = reference as Function;
65
+
66
+ string tag = function == null ? null : function.Name;
67
+ if (IsPlaceholderTag(tag))
68
+ {
69
+ if (noTag.Count < 10)
70
+ noTag.Add(JsonValue.NewString(
71
+ "(" + reference.Location.X + "," + reference.Location.Y + ")"));
72
+ }
73
+ else
74
+ {
75
+ if (!tagCounts.ContainsKey(tag)) tagCounts[tag] = 0;
76
+ tagCounts[tag]++;
77
+ }
78
+
79
+ double x = reference.Location.X;
80
+ double y = reference.Location.Y;
81
+ if (Math.Abs(x / grid - Math.Round(x / grid)) > 0.001 ||
82
+ Math.Abs(y / grid - Math.Round(y / grid)) > 0.001)
83
+ {
84
+ if (offGrid.Count < 10)
85
+ offGrid.Add(JsonValue.NewString("(" + x + "," + y + ")"));
86
+ }
87
+
88
+ try
89
+ {
90
+ PinBase[] pins = reference.GraphicalConnectionPoints;
91
+ if (pins != null) pinTotal += pins.Length;
92
+ }
93
+ catch { }
94
+ }
95
+
96
+ JsonValue duplicates = JsonValue.NewArray();
97
+ foreach (KeyValuePair<string, int> pair in tagCounts)
98
+ {
99
+ if (pair.Value > 1)
100
+ duplicates.Add(JsonValue.NewString(pair.Key + " ×" + pair.Value));
101
+ }
102
+ if (duplicates.Count > 0)
103
+ warnings.Add("设备标识重复:" + duplicates.Count + " 组。同一个设备分多个部件、或跨页引用时会这样;确认不是重复插入即可,不必为此重建整页。");
104
+
105
+ if (offGrid.Count > 0)
106
+ warnings.Add("有元件不在 " + grid + " mm 栅格上。EPLAN 靠栅格对齐,偏离后引脚对不上,红线连不出来。");
107
+
108
+ // 没有设备标识不一定是错:T 节点、连接点这类纯结构符号本来就不该有编号。
109
+ // 所以只作为信息报出来,让模型自己判断是不是漏了。
110
+ if (noTag.Count > 0)
111
+ info.Add("有 " + noTag.Count + " 个符号没有设备标识。T 节点 / 连接点属于正常情况;如果是器件,说明漏了编号。");
112
+
113
+ // ── 3. 孤立引脚:同一坐标上没有别的引脚,就连不出线 ──
114
+ Dictionary<string, int> pinAt = new Dictionary<string, int>();
115
+ foreach (SymbolReference reference in symbols)
116
+ {
117
+ try
118
+ {
119
+ PinBase[] pins = reference.GraphicalConnectionPoints;
120
+ if (pins == null) continue;
121
+ foreach (PinBase pin in pins)
122
+ {
123
+ string key = Math.Round(pin.Location.X, 2) + "|" + Math.Round(pin.Location.Y, 2);
124
+ if (!pinAt.ContainsKey(key)) pinAt[key] = 0;
125
+ pinAt[key]++;
126
+ }
127
+ }
128
+ catch { }
129
+ }
130
+ int shared = 0;
131
+ foreach (KeyValuePair<string, int> pair in pinAt) if (pair.Value > 1) shared++;
132
+
133
+ JsonValue resultSummary = JsonValue.NewObject();
134
+ resultSummary.Set("symbols", symbols.Count);
135
+ resultSummary.Set("pins", pinTotal);
136
+ resultSummary.Set("sharedPinPoints", shared);
137
+ resultSummary.Set("handDrawnLines", handDrawn);
138
+ resultSummary.Set("distinctDeviceTags", tagCounts.Count);
139
+ result.Set("summary", resultSummary);
140
+
141
+ if (handDrawnSample.Count > 0) result.Set("handDrawnSample", handDrawnSample);
142
+ if (offGrid.Count > 0) result.Set("offGridSample", offGrid);
143
+ if (noTag.Count > 0) result.Set("noTagSample", noTag);
144
+ if (duplicates.Count > 0) result.Set("duplicateTags", duplicates);
145
+
146
+ JsonValue problemsJson = JsonValue.NewArray();
147
+ foreach (string text in problems) problemsJson.Add(JsonValue.NewString(text));
148
+ JsonValue warningsJson = JsonValue.NewArray();
149
+ foreach (string text in warnings) warningsJson.Add(JsonValue.NewString(text));
150
+ JsonValue infoJson = JsonValue.NewArray();
151
+ foreach (string text in info) infoJson.Add(JsonValue.NewString(text));
152
+ result.Set("info", infoJson);
153
+
154
+ result.Set("problems", problemsJson);
155
+ result.Set("warnings", warningsJson);
156
+ result.Set("ok", problems.Count == 0);
157
+
158
+ // 给模型一句结论,省得它自己从数字里推。
159
+ string verdict;
160
+ if (problems.Count == 0 && warnings.Count == 0)
161
+ verdict = "这页没问题,可以交付。";
162
+ else if (problems.Count == 0)
163
+ verdict = "没有硬伤,但有 " + warnings.Count + " 处值得看一眼。";
164
+ else
165
+ verdict = "有 " + problems.Count + " 个必须修的问题。";
166
+ result.Set("verdict", verdict);
167
+
168
+ return result;
169
+ }
170
+
171
+ // EPLAN 对没有编号的连接点(DCP / CO / 中断点)返回的是结构分隔符本身,
172
+ // 常见 "=+"、"+"、"-"。它们不是设备标识,不能算「同名重复」——
173
+ // 8023dacf 里 11 个这样的占位符被误报成重复,害得整页重建过两次。
174
+ private static bool IsPlaceholderTag(string tag)
175
+ {
176
+ if (string.IsNullOrEmpty(tag)) return true;
177
+ string trimmed = tag.Trim();
178
+ if (trimmed.Length == 0) return true;
179
+ foreach (char c in trimmed)
180
+ {
181
+ if (c != '=' && c != '+' && c != '-') return false;
182
+ }
183
+ return true;
184
+ }
185
+ }
186
+ }