feat: implement CAD template drawing service for opening templates and removing specific parameter annotations.

This commit is contained in:
sladro 2026-02-27 14:39:53 +08:00
parent 09ab4cff9e
commit 2230e554f9
4 changed files with 88 additions and 8 deletions

View File

@ -454,6 +454,16 @@ namespace CadParamPluging.Cad
return new NoteApplyResult { Applied = false, Message = "未找到目标空间,跳过附注替换。" };
}
Func<string, string> getValueW = (k) =>
{
var val = bag.GetString(k);
if (k != null && (k.StartsWith("Hardness", StringComparison.OrdinalIgnoreCase) || k.StartsWith("MarkingContent", StringComparison.OrdinalIgnoreCase)))
{
if (bag.GetString(k + "_ShowInNote") == "0") return "__SKIP_NOTE__";
}
return val;
};
// 1. 优先查找已经标记过的 Note Entity (重生成场景)
foreach (ObjectId id in space)
{
@ -462,7 +472,7 @@ namespace CadParamPluging.Cad
{
// 找到了之前的附注,使用存储的模板重新渲染
var effectiveStored = NoteTemplateEngine.BuildEffectiveValueKeyBindings(schema.NoteBindings);
var renderedStored = NoteTemplateEngine.Render(storedTemplate, effectiveStored, bag.GetString);
var renderedStored = NoteTemplateEngine.Render(storedTemplate, effectiveStored, getValueW);
ApplyNoteTextToObject(tr, id, "ExistingTaggedNote", renderedStored, null);
@ -517,7 +527,7 @@ namespace CadParamPluging.Cad
var insertPoint = new Point3d(insertX, insertY, 0);
var effectiveForCreation = NoteTemplateEngine.BuildEffectiveValueKeyBindings(schema.NoteBindings);
var renderedForCreation = NoteTemplateEngine.Render(schema.NoteTemplateText, effectiveForCreation, bag.GetString);
var renderedForCreation = NoteTemplateEngine.Render(schema.NoteTemplateText, effectiveForCreation, getValueW);
var mt = new MText();
mt.Contents = ToMTextContents(renderedForCreation);
@ -671,7 +681,7 @@ namespace CadParamPluging.Cad
}
var effective = NoteTemplateEngine.BuildEffectiveValueKeyBindings(schema.NoteBindings);
var rendered = NoteTemplateEngine.Render(templateText, effective, bag.GetString);
var rendered = NoteTemplateEngine.Render(templateText, effective, getValueW);
best.Apply(rendered);
if (!best.TargetId.IsNull)

View File

@ -242,11 +242,14 @@ namespace CadParamPluging.Common
if (map.TryGetValue(currentIdx, out var key) && getValue != null)
{
var val = getValue(key);
// Check for strict "空"
if (string.Equals(val, "空", StringComparison.OrdinalIgnoreCase))
if (string.Equals(val, "__SKIP_NOTE__", StringComparison.OrdinalIgnoreCase))
{
shouldSkip = true;
}
else if (string.Equals(val, "空", StringComparison.OrdinalIgnoreCase))
{
// Exception: MarkingContent (标刻内容) should NOT cause line skip
if (!string.Equals(key, "MarkingContent", StringComparison.OrdinalIgnoreCase))
if (key == null || !key.StartsWith("MarkingContent", StringComparison.OrdinalIgnoreCase))
{
shouldSkip = true;
}

View File

@ -426,8 +426,45 @@ namespace CadParamPluging.UI
_toolTip.SetToolTip(ctrl, extraToolTip);
}
Control finalCtrl = ctrl;
if (string.Equals(def.Key, "Hardness", StringComparison.OrdinalIgnoreCase) ||
string.Equals(def.Key, "MarkingContent", StringComparison.OrdinalIgnoreCase))
{
var flow = new FlowLayoutPanel
{
AutoSize = true,
FlowDirection = FlowDirection.LeftToRight,
WrapContents = false,
Margin = new Padding(0)
};
bool isChecked = true;
if (_loadedDefaults != null)
{
var showVal = _loadedDefaults.GetString(controlKey + "_ShowInNote");
if (showVal != null)
{
isChecked = showVal == "1" || showVal.Equals("true", StringComparison.OrdinalIgnoreCase);
}
}
var chk = new CheckBox
{
Text = "显示在附注中",
AutoSize = true,
Checked = isChecked,
Margin = new Padding(10, 3, 0, 0)
};
_controlsByKey[controlKey + "_ShowInNote"] = chk;
chk.CheckedChanged += (_, __) => UpdateNotePreviews();
flow.Controls.Add(ctrl);
flow.Controls.Add(chk);
finalCtrl = flow;
}
_grid.Controls.Add(lbl, 0, rowIdx);
_grid.Controls.Add(ctrl, 1, rowIdx);
_grid.Controls.Add(finalCtrl, 1, rowIdx);
_controlsByKey[controlKey] = ctrl;
_defsByControlKey[controlKey] = def;
@ -617,7 +654,19 @@ namespace CadParamPluging.UI
var tempBag = CollectBagFromUi();
var effective = NoteTemplateEngine.BuildEffectiveValueKeyBindings(_schema.NoteBindings);
_rtbNoteRendered.Text = NoteTemplateEngine.Render(noteTemplate, effective, tempBag.GetString);
Func<string, string> getValueW = (k) =>
{
var val = tempBag.GetString(k);
if (k != null && (k.StartsWith("Hardness", StringComparison.OrdinalIgnoreCase) || k.StartsWith("MarkingContent", StringComparison.OrdinalIgnoreCase)))
{
if (tempBag.GetString(k + "_ShowInNote") == "0") return "__SKIP_NOTE__";
}
return val;
};
_rtbNoteNumbered.Text = NoteTemplateEngine.BuildNumberedPreviewText(noteTemplate);
_rtbNoteRendered.Text = NoteTemplateEngine.Render(noteTemplate, effective, getValueW);
}
private ParamBag CollectBagFromUi()
@ -630,6 +679,15 @@ namespace CadParamPluging.UI
continue;
}
if (key.EndsWith("_ShowInNote", StringComparison.OrdinalIgnoreCase))
{
if (ctrl is CheckBox chk)
{
bag.Set(key, chk.Checked ? "1" : "0");
}
continue;
}
if (!_defsByControlKey.TryGetValue(key, out var def) || def == null)
{
continue;
@ -813,6 +871,15 @@ namespace CadParamPluging.UI
continue;
}
if (key.EndsWith("_ShowInNote", StringComparison.OrdinalIgnoreCase))
{
if (ctrl is CheckBox chk)
{
bag.Set(key, chk.Checked ? "1" : "0");
}
continue;
}
if (!_defsByControlKey.TryGetValue(key, out var def) || def == null)
{
continue;

BIN
runtest.cs Normal file

Binary file not shown.