From c54bdebe5915e6aaab31dcf7fb0fe9c637ad8377 Mon Sep 17 00:00:00 2001
From: 230238001 <15151850021@126.com>
Date: Sat, 2 May 2026 10:18:00 +0800
Subject: [PATCH] Initial commit: UserStringProperty Rhino plugin
- Rhino 8 C# plugin for managing Block UserString properties
- XML template import with merge modes
- WinForms UI for property editing
- .NET Framework 4.8
---
.gitignore | 25 +
CHANGELOG.md | 27 +
CLAUDE.md | 17 +
CONTRIBUTING.md | 31 ++
LICENSE | 21 +
PLAN.md | 14 +
README.md | 122 +++++
.../Commands/CmdUserstringProperty.cs | 43 ++
UserStringProperty/Core/TemplateManager.cs | 296 ++++++++++
UserStringProperty/Core/XmlPropertyConfig.cs | 124 +++++
.../Resources/EmbeddedTemplates.cs | 130 +++++
UserStringProperty/UI/MainDialog.cs | 517 ++++++++++++++++++
UserStringProperty/UI/XmlImportDialog.cs | 227 ++++++++
UserStringProperty/UserStringProperty.cs | 32 ++
UserStringProperty/UserStringProperty.csproj | 52 ++
15 files changed, 1678 insertions(+)
create mode 100644 .gitignore
create mode 100644 CHANGELOG.md
create mode 100644 CLAUDE.md
create mode 100644 CONTRIBUTING.md
create mode 100644 LICENSE
create mode 100644 PLAN.md
create mode 100644 README.md
create mode 100644 UserStringProperty/Commands/CmdUserstringProperty.cs
create mode 100644 UserStringProperty/Core/TemplateManager.cs
create mode 100644 UserStringProperty/Core/XmlPropertyConfig.cs
create mode 100644 UserStringProperty/Resources/EmbeddedTemplates.cs
create mode 100644 UserStringProperty/UI/MainDialog.cs
create mode 100644 UserStringProperty/UI/XmlImportDialog.cs
create mode 100644 UserStringProperty/UserStringProperty.cs
create mode 100644 UserStringProperty/UserStringProperty.csproj
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ac5c433
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,25 @@
+# Build results
+
+bin/
+obj/
+
+# Visual Studio
+.vs/
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# Rider
+.idea/
+
+# VS Code
+.code/
+
+# Rhino plugin output (should be .rhp, not tracked)
+*.rhp
+*.dll
+
+# OS
+Thumbs.db
+.DS_Store
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..d3ac87d
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,27 @@
+# 更新日志
+
+所有重要版本更新会记录在此文件。
+
+## [0.1.0] - 2026-05-01
+
+### 新增
+- 项目骨架创建(插件主类、命令入口)
+- XML 配置文件解析器
+- 动态表单 UI:根据 XML 生成 TextBox / ComboBox 控件
+- 支持 string 类型字段(TextBox)
+- 支持 list 类型字段(ComboBox 下拉选择)
+- 多 XML 模板支持:可同时加载多个 XML 文件
+- 四种导入合并模式:追加、替代、合并更新、智能合并
+- `XmlImportDialog`:导入时弹出模式选择对话框
+- 模板持久化:Rhino 重启后自动恢复已加载的模板
+- `TemplateManager`:管理模板生命周期和 index 文件
+- 默认 XML 模板内嵌在 DLL 中,首次启动自动提取
+- 命令名:`UserstringProperty`
+
+### 功能
+- 选择 Block 后弹出属性编辑窗口
+- 属性保存到 Rhino Block 的 UserString(键值对存储)
+- 分隔标题自动识别(属性名含 `---` 时显示为分组标题)
+
+### 文档
+- README、LICENSE、.gitignore、CONTRIBUTING、CHANGELOG
\ No newline at end of file
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 0000000..95c8394
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,17 @@
+> 本文件仅保留高优先级、易混淆、跨会话必须一致的约束。
+> 本文件必须极精简,占用大模型注意力视为失效。
+
+## 项目一句话
+
+Rhino 8 C# 插件(.rhp),管理 Block 的 UserString 属性,支持 XML 模板导入。
+
+## 自动化约定
+
+- 禁止自行 commit / push git,用户下达指令再执行
+- 完成任务后清理临时文件
+
+## 文档入口
+
+- PLAN.md:待办事项
+- CHANGELOG.md:版本记录
+- CLAUDE.md:仅包含本文件(不要混入项目说明)
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..8c29a26
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,31 @@
+# 贡献指南
+
+欢迎提交 Issue 和 Pull Request!
+
+## 如何贡献
+
+### 报告问题
+
+发现 Bug 或有新功能想法?请先搜索 [Issues](https://gitea.com/user/project/issues) 确保不是重复提交,然后按以下格式描述:
+
+- **问题描述**:清晰说明问题或建议
+- **复现步骤**:如果是 Bug,列出具体步骤
+- **环境信息**:Rhino 版本、操作系统、.NET SDK 版本
+
+### 提交代码
+
+1. Fork 本项目
+2. 创建分支 (`git checkout -b feature/your-feature`)
+3. 确保代码符合项目风格,编译通过
+4. 提交时请写清楚改动内容和原因
+5. Push 到你的 Fork,发起 Pull Request
+
+### 代码规范
+
+- C# 代码遵循 [C# Coding Conventions](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions)
+- 公共方法需有 XML 注释
+- 新功能请附带测试或更新文档
+
+## 问题解答
+
+如有问题可以在 [Discussions](https://gitea.com/user/project/discussions) 中讨论。
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9d6dd3b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
\ No newline at end of file
diff --git a/PLAN.md b/PLAN.md
new file mode 100644
index 0000000..1e257f3
--- /dev/null
+++ b/PLAN.md
@@ -0,0 +1,14 @@
+# 待办事项
+
+## 插件开发
+
+- [ ] 为插件生成真实的 GUID 并配置到项目中
+ - 生成唯一的 GUID(不含全零值)
+ - 将 GUID 配置到 AssemblyInfo 或 csproj 中
+ - 确保插件在 Rhino 插件管理器中正确注册
+
+- [ ] 修复"重置模板"按钮的 bug
+ - 当前实现有 bug,需要排查并修复
+
+- [ ] 简化"导入 XML"的判断逻辑
+ - 当前分两段判断过于繁琐,合并为一段
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..dca8cf6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,122 @@
+# UserStringProperty
+
+Rhino 插件,用于根据用户自定义 XML 配置,给 Block 实例附加构件属性(UserString)。
+
+## 功能
+
+- 根据 XML 配置文件动态生成属性编辑界面
+- 支持 `string` 类型字段(TextBox)和 `list` 类型字段(ComboBox)
+- 自动保存到 Rhino Block 的 UserString
+- 支持多个 XML 模板同时加载、合并
+- 模板自动持久化,Rhino 重启后自动恢复
+- 导入时提供四种合并模式(追加、替代、合并更新、智能合并)
+
+## 安装
+
+### 编译
+
+```bash
+cd UserStringProperty
+dotnet build
+```
+
+输出:`UserStringProperty/bin/UserStringProperty.dll`
+
+### 加载到 Rhino
+
+1. 将 `bin/UserStringProperty.dll` 重命名为 `UserStringProperty.rhp`
+2. Rhino → `Options` → `Plug-ins` → `Install` → 选择 `.rhp` 文件
+
+### 使用
+
+1. 在 Rhino 中输入命令:`UserstringProperty`
+2. 选择要编辑的 Block 实例
+3. 默认模板首次启动自动加载;点 **加载XML** 导入自定义模板
+4. 在下拉框中选择属性集,编辑各字段值
+5. 点击 **保存**
+
+## 模板导入模式
+
+加载 XML 时,如果已有模板,会弹出对话框让选择导入模式:
+
+| 模式 | 说明 |
+|------|------|
+| 添加为新属性集 | 追加到现有列表末尾 |
+| 完全替代现有模板 | 清空所有现有属性集 |
+| 合并更新 | 同名属性集覆盖,其他保留 |
+| 智能合并 | 同名覆盖,同时追加新属性集 |
+
+## XML 配置格式
+
+插件根据 XML 动态生成 UI。示例参见 `Component_Property_base.xml` 和 `Component_Property_carbon.xml`。
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+### 字段类型
+
+| type | 控件 | 说明 |
+|------|------|------|
+| `string` | TextBox | 自由文本输入 |
+| `list` | ComboBox | 下拉选项(通过 `