dsh-eplan 0.0.0-stage → 0.14.0
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,144 @@
|
|
|
1
|
+
// symbol_info:查符号库里的符号「有几个变体、每个变体的连接点在哪、朝哪个方向」。
|
|
2
|
+
//
|
|
3
|
+
// 为什么必须能查:
|
|
4
|
+
// EPLAN 的红线是它根据「连接点是否对齐、是否面对面」自动画的。
|
|
5
|
+
// 所以要摆出正确的图,必须先知道每个符号的连接点在符号坐标系里的偏移和朝向。
|
|
6
|
+
// 靠往页面上试插再量太慢,这里直接读书里的定义。
|
|
7
|
+
//
|
|
8
|
+
// 用法:
|
|
9
|
+
// symbol_info {"library":"SPECIAL","symbols":["TLRU","TLRO","CO"]}
|
|
10
|
+
// symbol_info {"library":"GB_symbol","symbols":["F1","FA3"],"project":"test"}
|
|
11
|
+
using System;
|
|
12
|
+
using System.Collections;
|
|
13
|
+
using System.Reflection;
|
|
14
|
+
using Eplan.EplApi.Base;
|
|
15
|
+
using Eplan.EplApi.DataModel;
|
|
16
|
+
using Eplan.EplApi.DataModel.MasterData;
|
|
17
|
+
using EplanMcp;
|
|
18
|
+
|
|
19
|
+
namespace EplanMcpHost
|
|
20
|
+
{
|
|
21
|
+
internal static class SymbolInfoTool
|
|
22
|
+
{
|
|
23
|
+
public static JsonValue Run(JsonValue args)
|
|
24
|
+
{
|
|
25
|
+
SymbolLibrary library = Context.Library(
|
|
26
|
+
args["library"].AsString("GB_symbol"), args["project"].AsString(null));
|
|
27
|
+
|
|
28
|
+
JsonValue names = args["symbols"];
|
|
29
|
+
if (names == null || !names.IsArray || names.Count == 0)
|
|
30
|
+
throw new HostException("BAD_ARGUMENT", "symbols 必须是非空的符号名数组。");
|
|
31
|
+
|
|
32
|
+
JsonValue list = JsonValue.NewArray();
|
|
33
|
+
for (int i = 0; i < names.Count; i++)
|
|
34
|
+
{
|
|
35
|
+
string name = names[i].AsString(null);
|
|
36
|
+
if (string.IsNullOrEmpty(name)) continue;
|
|
37
|
+
list.Add(Describe(library, name));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
JsonValue result = JsonValue.NewObject();
|
|
41
|
+
result.Set("library", library.Name);
|
|
42
|
+
result.Set("symbols", list);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private static JsonValue Describe(SymbolLibrary library, string name)
|
|
47
|
+
{
|
|
48
|
+
JsonValue item = JsonValue.NewObject();
|
|
49
|
+
item.Set("name", name);
|
|
50
|
+
|
|
51
|
+
Symbol symbol;
|
|
52
|
+
try
|
|
53
|
+
{
|
|
54
|
+
symbol = new Symbol(library, name);
|
|
55
|
+
}
|
|
56
|
+
catch (Exception ex)
|
|
57
|
+
{
|
|
58
|
+
item.Set("error", ex.Message);
|
|
59
|
+
return item;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
SymbolVariant[] variants = symbol.Variants;
|
|
63
|
+
item.Set("variantCount", variants == null ? 0 : variants.Length);
|
|
64
|
+
|
|
65
|
+
JsonValue list = JsonValue.NewArray();
|
|
66
|
+
if (variants != null)
|
|
67
|
+
{
|
|
68
|
+
int limit = Math.Min(variants.Length, 8);
|
|
69
|
+
for (int i = 0; i < limit; i++)
|
|
70
|
+
{
|
|
71
|
+
JsonValue variantItem = JsonValue.NewObject();
|
|
72
|
+
variantItem.Set("nr", variants[i].VariantNr);
|
|
73
|
+
variantItem.Set("points", Points(variants[i]));
|
|
74
|
+
list.Add(variantItem);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
item.Set("variants", list);
|
|
78
|
+
return item;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private static JsonValue Points(SymbolVariant variant)
|
|
82
|
+
{
|
|
83
|
+
JsonValue list = JsonValue.NewArray();
|
|
84
|
+
try
|
|
85
|
+
{
|
|
86
|
+
IEnumerable points = variant.ConnectionPoints as IEnumerable;
|
|
87
|
+
if (points == null) return list;
|
|
88
|
+
foreach (object point in points)
|
|
89
|
+
{
|
|
90
|
+
if (point == null) continue;
|
|
91
|
+
list.Add(Dump(point));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch { }
|
|
95
|
+
return list;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// <summary>
|
|
99
|
+
/// 连接点对象的公开成员不确定,全量反射,把能读到的标量都吐出来。
|
|
100
|
+
/// 关心的是 Location(相对偏移)和 Direction(朝向)。
|
|
101
|
+
/// </summary>
|
|
102
|
+
private static JsonValue Dump(object source)
|
|
103
|
+
{
|
|
104
|
+
JsonValue item = JsonValue.NewObject();
|
|
105
|
+
foreach (PropertyInfo info in source.GetType().GetProperties(
|
|
106
|
+
BindingFlags.Public | BindingFlags.Instance))
|
|
107
|
+
{
|
|
108
|
+
try
|
|
109
|
+
{
|
|
110
|
+
object value = info.GetValue(source, null);
|
|
111
|
+
if (value == null) continue;
|
|
112
|
+
string key = info.Name.ToLowerInvariant();
|
|
113
|
+
|
|
114
|
+
if (value is PointD)
|
|
115
|
+
{
|
|
116
|
+
PointD point = (PointD)value;
|
|
117
|
+
JsonValue pair = JsonValue.NewArray();
|
|
118
|
+
pair.Add(JsonValue.NewNumber(point.X));
|
|
119
|
+
pair.Add(JsonValue.NewNumber(point.Y));
|
|
120
|
+
item.Set(key, pair);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (value.GetType().IsEnum)
|
|
124
|
+
{
|
|
125
|
+
item.Set(key, value.ToString());
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (value is int || value is short || value is byte)
|
|
129
|
+
{
|
|
130
|
+
item.Set(key, JsonValue.NewNumber(Convert.ToDouble(value)));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (value is string)
|
|
134
|
+
{
|
|
135
|
+
item.Set(key, (string)value);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch { }
|
|
140
|
+
}
|
|
141
|
+
return item;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// symbol_insert:插元件 + 写设备标识。
|
|
2
|
+
// 用 SymbolVariant.Create(page) 拿到 SymbolReference,再设位置与属性。
|
|
3
|
+
using System;
|
|
4
|
+
using Eplan.EplApi.Base;
|
|
5
|
+
using Eplan.EplApi.DataModel;
|
|
6
|
+
using Eplan.EplApi.DataModel.Graphics;
|
|
7
|
+
using Eplan.EplApi.DataModel.MasterData;
|
|
8
|
+
using EplanMcp;
|
|
9
|
+
|
|
10
|
+
namespace EplanMcpHost
|
|
11
|
+
{
|
|
12
|
+
internal static class SymbolInsertTool
|
|
13
|
+
{
|
|
14
|
+
public static JsonValue Run(JsonValue args)
|
|
15
|
+
{
|
|
16
|
+
string pageName = args["page"].AsString(null);
|
|
17
|
+
string libraryName = args["library"].AsString("GB_symbol");
|
|
18
|
+
string symbolName = args["symbol"].AsString(null);
|
|
19
|
+
int variantNr = args["variant"].AsInt(0);
|
|
20
|
+
string deviceTag = args["deviceTag"].AsString(null);
|
|
21
|
+
bool dryRun = args["dryRun"].AsBool(false);
|
|
22
|
+
// 默认把设备标识显示到图上;关掉可以少一个图元。
|
|
23
|
+
bool showDeviceTag = args["showDeviceTag"].AsBool(true);
|
|
24
|
+
JsonValue props = args["props"];
|
|
25
|
+
|
|
26
|
+
if (string.IsNullOrEmpty(symbolName))
|
|
27
|
+
throw new HostException("BAD_ARGUMENT", "缺少符号名(symbol),例如 FA3。可以先用 symbols 查询。");
|
|
28
|
+
|
|
29
|
+
Page page = Context.FindPage(pageName, args["project"].AsString(null));
|
|
30
|
+
PointD at = Context.Point(args["at"], "at");
|
|
31
|
+
|
|
32
|
+
SymbolLibrary library;
|
|
33
|
+
try
|
|
34
|
+
{
|
|
35
|
+
library = Context.Library(libraryName, args["project"].AsString(null));
|
|
36
|
+
}
|
|
37
|
+
catch (Exception ex)
|
|
38
|
+
{
|
|
39
|
+
throw new HostException("LIBRARY_NOT_FOUND",
|
|
40
|
+
"打不开符号库「" + libraryName + "」:" + ex.Message, null);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Symbol symbol;
|
|
44
|
+
try
|
|
45
|
+
{
|
|
46
|
+
symbol = new Symbol(library, symbolName);
|
|
47
|
+
}
|
|
48
|
+
catch (Exception ex)
|
|
49
|
+
{
|
|
50
|
+
throw new HostException("SYMBOL_NOT_FOUND",
|
|
51
|
+
"符号库「" + libraryName + "」里没有符号「" + symbolName + "」:" + ex.Message +
|
|
52
|
+
"。先用 symbols 工具查询确切的符号名。");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
SymbolVariant variant;
|
|
56
|
+
try
|
|
57
|
+
{
|
|
58
|
+
variant = new SymbolVariant(symbol, variantNr);
|
|
59
|
+
}
|
|
60
|
+
catch (Exception ex)
|
|
61
|
+
{
|
|
62
|
+
throw new HostException("VARIANT_NOT_FOUND",
|
|
63
|
+
"符号「" + symbolName + "」没有变体 " + variantNr + ":" + ex.Message);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
JsonValue result = JsonValue.NewObject();
|
|
67
|
+
result.Set("page", page.Name);
|
|
68
|
+
result.Set("library", libraryName);
|
|
69
|
+
result.Set("symbol", symbol.Name);
|
|
70
|
+
result.Set("variant", variantNr);
|
|
71
|
+
result.Set("at", Context.PointJson(at));
|
|
72
|
+
result.Set("deviceTag", deviceTag);
|
|
73
|
+
result.Set("dryRun", dryRun);
|
|
74
|
+
|
|
75
|
+
if (dryRun)
|
|
76
|
+
{
|
|
77
|
+
result.Set("inserted", false);
|
|
78
|
+
result.Set("wouldInsert", true);
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Placement placement = null;
|
|
83
|
+
try
|
|
84
|
+
{
|
|
85
|
+
placement = variant.Create(page);
|
|
86
|
+
placement.Location = at;
|
|
87
|
+
|
|
88
|
+
if (!string.IsNullOrEmpty(deviceTag))
|
|
89
|
+
{
|
|
90
|
+
Function function = placement as Function;
|
|
91
|
+
if (function != null)
|
|
92
|
+
{
|
|
93
|
+
function.Name = deviceTag;
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
{
|
|
97
|
+
result.Set("deviceTagWarning",
|
|
98
|
+
"插入的对象不是 Function(是 " + placement.GetType().Name + "),设备标识未写入。");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (props != null && props.IsObject)
|
|
103
|
+
{
|
|
104
|
+
Function function = placement as Function;
|
|
105
|
+
if (function != null)
|
|
106
|
+
ApplyProperties(function, props, result);
|
|
107
|
+
else
|
|
108
|
+
result.Set("propsWarning", "对象不是 Function,属性未写入。");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (Exception ex)
|
|
112
|
+
{
|
|
113
|
+
try { if (placement != null) placement.Remove(); } catch { }
|
|
114
|
+
throw new HostException("INSERT_FAILED", "插入符号失败:" + ex.Message, ex.ToString());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 设备标识写进属性只是存了数据,图上默认不显示;
|
|
118
|
+
// 要让 -F4 这种文字出现在符号旁边,必须额外放一个 PropertyPlacement。
|
|
119
|
+
// 这是 EPLAN 的规矩,不是我们的选择。
|
|
120
|
+
if (!string.IsNullOrEmpty(deviceTag) && showDeviceTag)
|
|
121
|
+
{
|
|
122
|
+
try
|
|
123
|
+
{
|
|
124
|
+
SymbolReference reference = placement as SymbolReference;
|
|
125
|
+
if (reference == null)
|
|
126
|
+
{
|
|
127
|
+
result.Set("tagDisplayWarning",
|
|
128
|
+
"插入对象不是 SymbolReference(是 " + placement.GetType().Name + "),无法挂属性显示。");
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
{
|
|
132
|
+
PlaceDeviceTag(reference, at, deviceTag, result);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (Exception ex)
|
|
136
|
+
{
|
|
137
|
+
result.Set("tagDisplayWarning", "设备标识已写入,但显示到图上失败:" + ex.Message);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
result.Set("inserted", true);
|
|
142
|
+
JsonValue created = Describe(placement);
|
|
143
|
+
result.Set("object", created);
|
|
144
|
+
|
|
145
|
+
// 记一笔,好在事后撤回:按页名 + 对象名定位,回退时把它删掉。
|
|
146
|
+
// 名字必须用 EPLAN 生成的那个(=+-Q1 这种),deviceTag 可能为空或重复。
|
|
147
|
+
string createdName = created == null ? null : created["name"].AsString(null);
|
|
148
|
+
if (!string.IsNullOrEmpty(createdName))
|
|
149
|
+
{
|
|
150
|
+
JsonValue undo = JsonValue.NewObject();
|
|
151
|
+
undo.Set("kind", "remove_object");
|
|
152
|
+
undo.Set("name", createdName);
|
|
153
|
+
OpJournal.Append("symbol_insert", page.Project.ProjectName, page.Name, undo, true, null);
|
|
154
|
+
}
|
|
155
|
+
else
|
|
156
|
+
{
|
|
157
|
+
OpJournal.Append("symbol_insert", page.Project.ProjectName, page.Name, null, false,
|
|
158
|
+
"插入的对象没有可用于定位的名字,无法自动回退。");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// <summary>
|
|
165
|
+
/// 在符号旁边标出设备标识。
|
|
166
|
+
///
|
|
167
|
+
/// 为什么用 Graphics.Text 而不是 PropertyPlacement:
|
|
168
|
+
/// 实测 PropertyPlacement 造出来是「看得见对象、看不见字」——
|
|
169
|
+
/// * reference.PropertyPlacements 里本来就有 12 条符号自带的,Height 全是
|
|
170
|
+
/// -16002(隐藏哨兵),GetDisplayString() 返回空字符串;
|
|
171
|
+
/// * 自己 Create 的那条 Height=2.5、GetDisplayString() 也拿到了 "F4",
|
|
172
|
+
/// 但 GraphicPageEx 渲染出来仍然是空白;
|
|
173
|
+
/// * 开不开 UseLocalPropertyPlacements、bFromDevice 传 true/false,
|
|
174
|
+
/// 这几种组合都试过,全都不显示。
|
|
175
|
+
/// 而 Graphics.Text 是确定能渲染的(页面上的 L24-1 这些标注就是它画的)。
|
|
176
|
+
///
|
|
177
|
+
/// 代价:标签是普通文字,改设备标识时不会自动跟着变。
|
|
178
|
+
/// 好处:一定能看到,且位置完全可控。
|
|
179
|
+
///
|
|
180
|
+
/// 位置规则:Location 是文字包围盒的左下角;符号占多高优先看包围盒,
|
|
181
|
+
/// 查不到就退到经验值。
|
|
182
|
+
/// </summary>
|
|
183
|
+
private static void PlaceDeviceTag(SymbolReference reference, PointD at, string deviceTag, JsonValue result)
|
|
184
|
+
{
|
|
185
|
+
double leftShift = 5.0;
|
|
186
|
+
double topOffset = 7.0;
|
|
187
|
+
try
|
|
188
|
+
{
|
|
189
|
+
PointD[] box = reference.GetBoundingBox();
|
|
190
|
+
if (box != null && box.Length >= 2)
|
|
191
|
+
{
|
|
192
|
+
double halfHeight = Math.Abs(box[1].Y - box[0].Y) / 2.0;
|
|
193
|
+
topOffset = halfHeight + 3.0;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch { }
|
|
197
|
+
|
|
198
|
+
Text label = new Text();
|
|
199
|
+
label.Create(reference.Page, deviceTag, 2.5);
|
|
200
|
+
label.Location = new PointD(at.X - leftShift, at.Y + topOffset);
|
|
201
|
+
|
|
202
|
+
result.Set("deviceTagShown", true);
|
|
203
|
+
result.Set("deviceTagMode", "text");
|
|
204
|
+
result.Set("deviceTagAt", Context.PointJson(label.Location));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private static void ApplyProperties(Function function, JsonValue props, JsonValue result)
|
|
208
|
+
{
|
|
209
|
+
JsonValue applied = JsonValue.NewArray();
|
|
210
|
+
JsonValue failed = JsonValue.NewArray();
|
|
211
|
+
foreach (string key in props.Keys)
|
|
212
|
+
{
|
|
213
|
+
try
|
|
214
|
+
{
|
|
215
|
+
// 通过属性名反射到 FunctionPropertyList 的静态属性。
|
|
216
|
+
System.Reflection.PropertyInfo info =
|
|
217
|
+
typeof(FunctionPropertyList).GetProperty(key,
|
|
218
|
+
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
|
219
|
+
if (info == null)
|
|
220
|
+
{
|
|
221
|
+
failed.Add(JsonValue.NewString(key + ":不认识的属性名"));
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
object propertyId = info.GetValue(null, null);
|
|
225
|
+
string value = props[key].AsString(null);
|
|
226
|
+
if (value == null) { failed.Add(JsonValue.NewString(key + ":值为空")); continue; }
|
|
227
|
+
function.Properties[(Eplan.EplApi.DataModel.Properties.Function)propertyId] = value;
|
|
228
|
+
applied.Add(JsonValue.NewString(key));
|
|
229
|
+
}
|
|
230
|
+
catch (Exception ex)
|
|
231
|
+
{
|
|
232
|
+
failed.Add(JsonValue.NewString(key + ":" + ex.Message));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
result.Set("propsApplied", applied);
|
|
236
|
+
if (failed.Count > 0) result.Set("propsFailed", failed);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private static JsonValue Describe(Placement placement)
|
|
240
|
+
{
|
|
241
|
+
JsonValue item = JsonValue.NewObject();
|
|
242
|
+
item.Set("type", placement.GetType().Name);
|
|
243
|
+
try { item.Set("objectId", placement.ObjectIdentifier.ToString()); } catch { }
|
|
244
|
+
Function function = placement as Function;
|
|
245
|
+
if (function != null)
|
|
246
|
+
{
|
|
247
|
+
try { item.Set("name", function.Name); } catch { }
|
|
248
|
+
try { item.Set("visibleName", function.VisibleName); } catch { }
|
|
249
|
+
}
|
|
250
|
+
try
|
|
251
|
+
{
|
|
252
|
+
JsonValue location = JsonValue.NewArray();
|
|
253
|
+
location.Add(JsonValue.NewNumber(placement.Location.X));
|
|
254
|
+
location.Add(JsonValue.NewNumber(placement.Location.Y));
|
|
255
|
+
item.Set("location", location);
|
|
256
|
+
}
|
|
257
|
+
catch { }
|
|
258
|
+
return item;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// symbols:查符号库,确认符号名存在再插。
|
|
2
|
+
// 模型最容易犯的错就是凭记忆编符号名,这个工具就是为了堵住这个错。
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using Eplan.EplApi.DataModel;
|
|
6
|
+
using Eplan.EplApi.DataModel.MasterData;
|
|
7
|
+
using EplanMcp;
|
|
8
|
+
|
|
9
|
+
namespace EplanMcpHost
|
|
10
|
+
{
|
|
11
|
+
internal static class SymbolsTool
|
|
12
|
+
{
|
|
13
|
+
public static JsonValue Run(JsonValue args)
|
|
14
|
+
{
|
|
15
|
+
string libraryName = args["library"].AsString("GB_symbol");
|
|
16
|
+
// query 和 filter 都接受:工具描述里写的是 query,
|
|
17
|
+
// 但 EPLAN 用户的习惯说法是 filter(和 pages 一致)。谁给了就用谁。
|
|
18
|
+
string query = args["query"].AsString(null);
|
|
19
|
+
if (string.IsNullOrEmpty(query)) query = args["filter"].AsString(null);
|
|
20
|
+
int limit = args["limit"].AsInt(50);
|
|
21
|
+
if (limit <= 0) limit = 50;
|
|
22
|
+
|
|
23
|
+
Project project = Context.Resolve(args["project"].AsString(null));
|
|
24
|
+
|
|
25
|
+
JsonValue available = JsonValue.NewArray();
|
|
26
|
+
if (project.SymbolLibraries != null)
|
|
27
|
+
{
|
|
28
|
+
foreach (SymbolLibrary lib in project.SymbolLibraries)
|
|
29
|
+
available.Add(JsonValue.NewString(lib.Name));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
SymbolLibrary library;
|
|
33
|
+
try
|
|
34
|
+
{
|
|
35
|
+
library = Context.Library(libraryName, args["project"].AsString(null));
|
|
36
|
+
}
|
|
37
|
+
catch (Exception ex)
|
|
38
|
+
{
|
|
39
|
+
throw new HostException("LIBRARY_NOT_FOUND",
|
|
40
|
+
"打不开符号库「" + libraryName + "」:" + ex.Message,
|
|
41
|
+
"当前项目可用的符号库: " + Json.Write(available));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Symbol[] symbols = library.Symbols;
|
|
45
|
+
if (symbols == null) symbols = new Symbol[0];
|
|
46
|
+
|
|
47
|
+
List<Symbol> matched = new List<Symbol>();
|
|
48
|
+
foreach (Symbol symbol in symbols)
|
|
49
|
+
{
|
|
50
|
+
if (query != null && query.Length > 0)
|
|
51
|
+
{
|
|
52
|
+
string name = symbol.Name ?? string.Empty;
|
|
53
|
+
if (name.IndexOf(query, StringComparison.OrdinalIgnoreCase) < 0) continue;
|
|
54
|
+
}
|
|
55
|
+
matched.Add(symbol);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
matched.Sort(delegate (Symbol a, Symbol b)
|
|
59
|
+
{
|
|
60
|
+
return string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
JsonValue result = JsonValue.NewObject();
|
|
64
|
+
result.Set("library", libraryName);
|
|
65
|
+
result.Set("availableLibraries", available);
|
|
66
|
+
result.Set("totalSymbols", symbols.Length);
|
|
67
|
+
result.Set("matchedCount", matched.Count);
|
|
68
|
+
|
|
69
|
+
JsonValue list = JsonValue.NewArray();
|
|
70
|
+
int emitted = 0;
|
|
71
|
+
foreach (Symbol symbol in matched)
|
|
72
|
+
{
|
|
73
|
+
if (emitted >= limit) break;
|
|
74
|
+
emitted++;
|
|
75
|
+
JsonValue item = JsonValue.NewObject();
|
|
76
|
+
item.Set("name", symbol.Name);
|
|
77
|
+
try { item.Set("type", symbol.Type.ToString()); } catch { }
|
|
78
|
+
JsonValue variants = JsonValue.NewArray();
|
|
79
|
+
try
|
|
80
|
+
{
|
|
81
|
+
if (symbol.Variants != null)
|
|
82
|
+
foreach (SymbolVariant v in symbol.Variants)
|
|
83
|
+
variants.Add(JsonValue.NewNumber(v.VariantNr));
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
86
|
+
item.Set("variants", variants);
|
|
87
|
+
list.Add(item);
|
|
88
|
+
}
|
|
89
|
+
result.Set("symbols", list);
|
|
90
|
+
if (matched.Count > emitted) result.Set("truncated", true);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// tagloc:把设备标识放到符号旁边,并回报最终实际位置。
|
|
2
|
+
//
|
|
3
|
+
// 为什么单独做一个:PropertyPlacement 的 Location 语义不直观 ——
|
|
4
|
+
// 设完之后位置不一定是你给的那个,必须读回来确认。
|
|
5
|
+
// 顺便把「符号本身多大」也报出来,方便算避让距离。
|
|
6
|
+
using System;
|
|
7
|
+
using Eplan.EplApi.Base;
|
|
8
|
+
using Eplan.EplApi.DataModel;
|
|
9
|
+
using Eplan.EplApi.DataModel.Graphics;
|
|
10
|
+
using Eplan.EplApi.DataModel.MasterData;
|
|
11
|
+
using EplanMcp;
|
|
12
|
+
|
|
13
|
+
namespace EplanMcpHost
|
|
14
|
+
{
|
|
15
|
+
internal static class TagLocTool
|
|
16
|
+
{
|
|
17
|
+
public static JsonValue Run(JsonValue args)
|
|
18
|
+
{
|
|
19
|
+
string pageName = args["page"].AsString(null);
|
|
20
|
+
string libraryName = args["library"].AsString("GB_symbol");
|
|
21
|
+
string symbolName = args["symbol"].AsString(null);
|
|
22
|
+
string deviceTag = args["deviceTag"].AsString(null);
|
|
23
|
+
int variantNr = args["variant"].AsInt(0);
|
|
24
|
+
|
|
25
|
+
Page page = Context.FindPage(pageName, args["project"].AsString(null));
|
|
26
|
+
PointD at = Context.Point(args["at"], "at");
|
|
27
|
+
PointD tagAt = Context.Point(args["tagAt"], "tagAt");
|
|
28
|
+
|
|
29
|
+
SymbolLibrary library = Context.Library(libraryName, args["project"].AsString(null));
|
|
30
|
+
Symbol symbol = new Symbol(library, symbolName);
|
|
31
|
+
SymbolVariant variant = new SymbolVariant(symbol, variantNr);
|
|
32
|
+
|
|
33
|
+
JsonValue result = JsonValue.NewObject();
|
|
34
|
+
|
|
35
|
+
SymbolReference reference = variant.Create(page) as SymbolReference;
|
|
36
|
+
if (reference == null)
|
|
37
|
+
{
|
|
38
|
+
throw new HostException("NOT_SYMBOL", "插入出来的对象不是 SymbolReference。");
|
|
39
|
+
}
|
|
40
|
+
reference.Location = at;
|
|
41
|
+
if (!string.IsNullOrEmpty(deviceTag))
|
|
42
|
+
{
|
|
43
|
+
// Name 在 Function 上,不在 SymbolReference 上。
|
|
44
|
+
Function function = reference as Function;
|
|
45
|
+
if (function != null) function.Name = deviceTag;
|
|
46
|
+
else result.Set("nameWarning", "对象不是 Function,设备标识未写入。");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 符号自身占多大:用它的包围盒判断。
|
|
50
|
+
try
|
|
51
|
+
{
|
|
52
|
+
PointD[] box = reference.GetBoundingBox();
|
|
53
|
+
if (box != null && box.Length >= 2)
|
|
54
|
+
{
|
|
55
|
+
JsonValue min = JsonValue.NewArray();
|
|
56
|
+
min.Add(JsonValue.NewNumber(box[0].X));
|
|
57
|
+
min.Add(JsonValue.NewNumber(box[0].Y));
|
|
58
|
+
JsonValue max = JsonValue.NewArray();
|
|
59
|
+
max.Add(JsonValue.NewNumber(box[1].X));
|
|
60
|
+
max.Add(JsonValue.NewNumber(box[1].Y));
|
|
61
|
+
result.Set("symbolBoxMin", min);
|
|
62
|
+
result.Set("symbolBoxMax", max);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (Exception ex) { result.Set("symbolBoxError", ex.Message); }
|
|
66
|
+
|
|
67
|
+
PropertyPlacement tag = new PropertyPlacement();
|
|
68
|
+
tag.Create(reference, Properties.Function.FUNC_DEVICETAG_MAINNAME);
|
|
69
|
+
result.Set("locationAfterCreate", PointJson(tag.Location));
|
|
70
|
+
|
|
71
|
+
try
|
|
72
|
+
{
|
|
73
|
+
tag.Location = tagAt;
|
|
74
|
+
result.Set("setTo", Context.PointJson(tagAt));
|
|
75
|
+
}
|
|
76
|
+
catch (Exception ex)
|
|
77
|
+
{
|
|
78
|
+
result.Set("setLocationError", ex.Message);
|
|
79
|
+
}
|
|
80
|
+
result.Set("locationAfterSet", PointJson(tag.Location));
|
|
81
|
+
|
|
82
|
+
try { result.Set("displayString", tag.GetDisplayString()); }
|
|
83
|
+
catch (Exception ex) { result.Set("displayError", ex.Message); }
|
|
84
|
+
|
|
85
|
+
try
|
|
86
|
+
{
|
|
87
|
+
PointD[] box = tag.GetBoundingBox();
|
|
88
|
+
if (box != null && box.Length >= 2)
|
|
89
|
+
{
|
|
90
|
+
result.Set("tagBoxMin", PointJson(box[0]));
|
|
91
|
+
result.Set("tagBoxMax", PointJson(box[1]));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (Exception ex) { result.Set("tagBoxError", ex.Message); }
|
|
95
|
+
|
|
96
|
+
result.Set("inserted", true);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private static JsonValue PointJson(PointD p)
|
|
101
|
+
{
|
|
102
|
+
JsonValue a = JsonValue.NewArray();
|
|
103
|
+
a.Add(JsonValue.NewNumber(p.X));
|
|
104
|
+
a.Add(JsonValue.NewNumber(p.Y));
|
|
105
|
+
return a;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|