修改自动比例
This commit is contained in:
parent
2e2dc274cc
commit
6516de9937
@ -644,7 +644,80 @@ namespace CadParamPluging.UI
|
||||
{
|
||||
AppendLog($"原图中心点: {removeResult.OriginalCenter}");
|
||||
}
|
||||
AppendLog($"绘图参数: Type={tplParams.ProjectType}, Size={tplParams.SheetSize}, Scale={tplParams.Scale}, Method={tplParams.DrawingType}");
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// 智能比例建议 (Pre-calculation)
|
||||
// ---------------------------------------------------------
|
||||
if (removeResult.WhiteFrameExtents.HasValue)
|
||||
{
|
||||
var frame = removeResult.WhiteFrameExtents.Value;
|
||||
var frameWidth = frame.MaxPoint.X - frame.MinPoint.X;
|
||||
var frameHeight = frame.MaxPoint.Y - frame.MinPoint.Y;
|
||||
|
||||
// 1. 获取预估图形尺寸 (不含标注的纯几何尺寸 + 预留边距)
|
||||
var expectedSize = FeatureDrivenDrawer.CalculateExpectedSize(bag, tplParams.SheetSize);
|
||||
|
||||
if (expectedSize.IsValid)
|
||||
{
|
||||
var currentDrawW = expectedSize.Width * scaleFactor;
|
||||
var currentDrawH = expectedSize.Height * scaleFactor;
|
||||
|
||||
bool isOverflow = currentDrawW > frameWidth || currentDrawH > frameHeight;
|
||||
bool isTooSmall = currentDrawW < frameWidth * 0.3 && currentDrawH < frameHeight * 0.3;
|
||||
|
||||
if (isOverflow || isTooSmall)
|
||||
{
|
||||
// 计算建议比例 (目标填充率 65%)
|
||||
var ratioW = frameWidth / expectedSize.Width;
|
||||
var ratioH = frameHeight / expectedSize.Height;
|
||||
var targetScale = Math.Min(ratioW, ratioH) * 0.65;
|
||||
|
||||
// 格式化建议比例
|
||||
string suggestedScaleText;
|
||||
double newOneToN = 1.0 / targetScale;
|
||||
|
||||
// 简单的取整逻辑,优先凑整 1:1, 1:2, 1:5, 1:10 等
|
||||
if (targetScale >= 0.95)
|
||||
{
|
||||
suggestedScaleText = "1:1";
|
||||
targetScale = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 凑整到最近的 0.5 或 整数
|
||||
if (newOneToN < 10)
|
||||
{
|
||||
newOneToN = Math.Round(newOneToN * 2) / 2.0; // 凑整 0.5
|
||||
}
|
||||
else
|
||||
{
|
||||
newOneToN = Math.Round(newOneToN); // 凑整 1
|
||||
}
|
||||
suggestedScaleText = $"1:{newOneToN}";
|
||||
targetScale = 1.0 / newOneToN;
|
||||
}
|
||||
|
||||
var msg = isOverflow
|
||||
? $"当前比例 (1:{(1/scaleFactor):F1}) 会导致图形超出图纸边框。\n建议调整为 {suggestedScaleText}。\n\n是否应用建议比例?"
|
||||
: $"当前比例 (1:{(1/scaleFactor):F1}) 会导致图形过小(占比<30%)。\n建议调整为 {suggestedScaleText}。\n\n是否应用建议比例?";
|
||||
|
||||
var dialogResult = MessageBox.Show(this, msg, "自动比例建议", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
scaleFactor = targetScale;
|
||||
bag.Set("DrawingScale", suggestedScaleText); // 更新参数包中的比例字符串
|
||||
AppendLog($"[自动调整] 已应用建议比例: {suggestedScaleText}");
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendLog($"[自动调整] 用户忽略了比例建议,保持原比例。");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppendLog($"绘图参数: Type={tplParams.ProjectType}, Size={tplParams.SheetSize}, Scale={bag.GetString("DrawingScale")}, Method={tplParams.DrawingType}");
|
||||
|
||||
// Dubug: Dump bag keys
|
||||
var bagKeys = bag.GetKeys(); // Assuming GetKeys exists? If not, skip or use reflection?
|
||||
|
||||
Loading…
Reference in New Issue
Block a user