更新图纸生成逻辑,在模板里直接生成,而不是新建文件
This commit is contained in:
parent
b69cca21ac
commit
257cef976c
@ -36,11 +36,26 @@ namespace CadParamPluging.Cad
|
||||
"尺寸标注", "标注", "DIM", "DIMENSION", "DIMENSIONS"
|
||||
};
|
||||
|
||||
public static Document CreateDocumentFromTemplate(TemplateInfo template)
|
||||
public static Document OpenTemplateDrawing(TemplateInfo template)
|
||||
{
|
||||
var doc = Application.DocumentManager.Add(template.FilePath);
|
||||
Application.DocumentManager.MdiActiveDocument = doc;
|
||||
return doc;
|
||||
if (template == null || string.IsNullOrWhiteSpace(template.FilePath))
|
||||
{
|
||||
throw new ArgumentException("Template path is invalid");
|
||||
}
|
||||
|
||||
var docMgr = Application.DocumentManager;
|
||||
foreach (Document doc in docMgr)
|
||||
{
|
||||
if (string.Equals(doc.Name, template.FilePath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
docMgr.MdiActiveDocument = doc;
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
|
||||
var newDoc = docMgr.Open(template.FilePath, false);
|
||||
docMgr.MdiActiveDocument = newDoc;
|
||||
return newDoc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -859,6 +874,7 @@ namespace CadParamPluging.Cad
|
||||
public int OuterFrameErased { get; set; }
|
||||
public Point3d OriginalCenter { get; set; }
|
||||
public Extents3d? OriginalExtents { get; set; }
|
||||
public Extents3d? WhiteFrameExtents { get; set; }
|
||||
}
|
||||
|
||||
private static readonly Regex DimensionPlaceholderRegex = new Regex(
|
||||
@ -892,6 +908,9 @@ namespace CadParamPluging.Cad
|
||||
|
||||
var layoutExtents = ComputeLayoutExtents(allEntities);
|
||||
var caxaExtents = ComputeCaxaLayerExtents(tr, allEntities);
|
||||
// Calculate white frame extents
|
||||
var whiteFrameExtents = ComputeWhiteFrameExtentsFromEntities(tr, allEntities) ?? ComputeLayoutExtents(allEntities);
|
||||
result.WhiteFrameExtents = whiteFrameExtents;
|
||||
|
||||
if (caxaExtents.HasValue)
|
||||
{
|
||||
@ -901,6 +920,17 @@ namespace CadParamPluging.Cad
|
||||
(caxaExtents.Value.MinPoint.Y + caxaExtents.Value.MaxPoint.Y) / 2,
|
||||
0);
|
||||
}
|
||||
else if (whiteFrameExtents.HasValue)
|
||||
{
|
||||
// Fallback to center of the upper half of the white frame if no CAXA layer found
|
||||
var frame = whiteFrameExtents.Value;
|
||||
var centerX = (frame.MinPoint.X + frame.MaxPoint.X) / 2.0;
|
||||
var height = frame.MaxPoint.Y - frame.MinPoint.Y;
|
||||
// Default to 70% height (center of upper area approximately) or just center?
|
||||
// User said "upper half center". Top half is [0.5, 1.0], center is 0.75.
|
||||
var centerY = frame.MinPoint.Y + height * 0.75;
|
||||
result.OriginalCenter = new Point3d(centerX, centerY, 0);
|
||||
}
|
||||
|
||||
// 使用CAXA图层范围作为图形区域,用于判断右上角
|
||||
var graphicExtents = caxaExtents ?? layoutExtents;
|
||||
|
||||
@ -265,6 +265,17 @@ namespace CadParamPluging.UI
|
||||
// Here we just list them.
|
||||
items.Add(item);
|
||||
}
|
||||
|
||||
// Fallback: if no layouts/model candidates found, add the file as a generic "Model Space" entry
|
||||
if (layouts.Count == 0 && models.Count == 0)
|
||||
{
|
||||
items.Add(new TemplateSelectionItem(new TemplateInfo
|
||||
{
|
||||
Name = Path.GetFileName(cadPath),
|
||||
FilePath = cadPath,
|
||||
LayoutName = null // Default to Model space
|
||||
}));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -567,7 +578,7 @@ namespace CadParamPluging.UI
|
||||
|
||||
DomainFacade.ValidateParameters(tplParams, drawingParams);
|
||||
|
||||
var doc = TemplateDrawingService.CreateDocumentFromTemplate(_selectedTemplate);
|
||||
var doc = TemplateDrawingService.OpenTemplateDrawing(_selectedTemplate);
|
||||
|
||||
if (_selectedModelWindow.HasValue)
|
||||
{
|
||||
@ -624,7 +635,23 @@ namespace CadParamPluging.UI
|
||||
}
|
||||
|
||||
var scaleFactor = ParseScaleFactor(bag.GetString("DrawingScale"));
|
||||
|
||||
|
||||
if (removeResult.WhiteFrameExtents.HasValue && removeResult.CaxaLayerErased == 0)
|
||||
{
|
||||
AppendLog($"未检测到CAXA层,已切换至白框定位: {removeResult.OriginalCenter}");
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendLog($"原图中心点: {removeResult.OriginalCenter}");
|
||||
}
|
||||
AppendLog($"绘图参数: Type={tplParams.ProjectType}, Size={tplParams.SheetSize}, Scale={tplParams.Scale}, Method={tplParams.DrawingType}");
|
||||
|
||||
// Dubug: Dump bag keys
|
||||
var bagKeys = bag.GetKeys(); // Assuming GetKeys exists? If not, skip or use reflection?
|
||||
// ParamBag implementation is simple dictionary usually.
|
||||
// Let's just log specific keys we suspect.
|
||||
AppendLog($"Bag Keys check: OD1={bag.GetDoubleOrNull("OuterDiameter1")}, H1={bag.GetDoubleOrNull("Height1")}");
|
||||
|
||||
// 根据模板参数绘制半剖视图,居中放置于原图纸位置
|
||||
// 使用特征驱动模式:根据参数存在性动态绘制对应特征
|
||||
HalfSectionDrawer.Draw(
|
||||
@ -637,6 +664,9 @@ namespace CadParamPluging.UI
|
||||
removeResult.OriginalCenter, // 原图纸中心点
|
||||
scaleFactor // 缩放比例
|
||||
);
|
||||
|
||||
// Force Zoom Extents to ensure visibility
|
||||
try { doc.SendStringToExecute("._ZOOM _E ", true, false, false); } catch { }
|
||||
|
||||
// 更新标题栏中的比例属性
|
||||
var scaleUpdated = TemplateDrawingService.UpdateScaleAttribute(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user