图纸生成位置解决了

This commit is contained in:
sladro 2025-12-18 11:43:16 +08:00
parent 0efa86309d
commit 83e774a029
2 changed files with 33 additions and 25 deletions

View File

@ -7,7 +7,7 @@ namespace CadParamPluging.Cad
{
public static class HalfSectionDrawer
{
public static void Draw(CadContext ctx, ParamBag bag, string deliveryStatus, string structuralFeature)
public static void Draw(CadContext ctx, ParamBag bag, string deliveryStatus, string structuralFeature, Point3d? center = null)
{
if (ctx == null)
{
@ -19,9 +19,11 @@ namespace CadParamPluging.Cad
throw new ArgumentNullException(nameof(bag));
}
var drawCenter = center ?? Point3d.Origin;
if (IsRing(structuralFeature))
{
DrawRing(ctx, bag, deliveryStatus);
DrawRing(ctx, bag, deliveryStatus, drawCenter);
}
else if (IsDisk(structuralFeature))
{
@ -71,7 +73,7 @@ namespace CadParamPluging.Cad
&& deliveryStatus.IndexOf("车加工", StringComparison.OrdinalIgnoreCase) >= 0;
}
private static void DrawRing(CadContext ctx, ParamBag bag, string deliveryStatus)
private static void DrawRing(CadContext ctx, ParamBag bag, string deliveryStatus, Point3d center)
{
var db = ctx.Database;
var tr = ctx.Transaction;
@ -87,16 +89,21 @@ namespace CadParamPluging.Cad
return;
}
// 计算偏移量,使图形居中于 center
// 图形原本以 (0,0) 为左端中心,宽度为 height需要偏移使其居中
double ox = center.X - height / 2.0;
double oy = center.Y;
// 绘制水平圆柱 (侧视图)
// 中心线 (X轴) - 已移除,以匹配参考图样式
// 1. 锻件外轮廓
double R = outerDia / 2.0;
var polyForging = new Polyline();
polyForging.AddVertexAt(0, new Point2d(0, -R), 0, 0, 0);
polyForging.AddVertexAt(1, new Point2d(height, -R), 0, 0, 0);
polyForging.AddVertexAt(2, new Point2d(height, R), 0, 0, 0);
polyForging.AddVertexAt(3, new Point2d(0, R), 0, 0, 0);
polyForging.AddVertexAt(0, new Point2d(ox + 0, oy - R), 0, 0, 0);
polyForging.AddVertexAt(1, new Point2d(ox + height, oy - R), 0, 0, 0);
polyForging.AddVertexAt(2, new Point2d(ox + height, oy + R), 0, 0, 0);
polyForging.AddVertexAt(3, new Point2d(ox + 0, oy + R), 0, 0, 0);
polyForging.Closed = true;
polyForging.ColorIndex = 7; // 白色
@ -109,30 +116,30 @@ namespace CadParamPluging.Cad
double r = innerDia / 2.0;
TryLoadLinetype(db, tr, "DASHED");
var lineHiddenTop = new Line(new Point3d(0, r, 0), new Point3d(height, r, 0));
var lineHiddenTop = new Line(new Point3d(ox + 0, oy + r, 0), new Point3d(ox + height, oy + r, 0));
lineHiddenTop.ColorIndex = 2; // 黄色
lineHiddenTop.Linetype = "DASHED";
btr.AppendEntity(lineHiddenTop);
tr.AddNewlyCreatedDBObject(lineHiddenTop, true);
var lineHiddenBot = new Line(new Point3d(0, -r, 0), new Point3d(height, -r, 0));
var lineHiddenBot = new Line(new Point3d(ox + 0, oy - r, 0), new Point3d(ox + height, oy - r, 0));
lineHiddenBot.ColorIndex = 2;
lineHiddenBot.Linetype = "DASHED";
btr.AppendEntity(lineHiddenBot);
tr.AddNewlyCreatedDBObject(lineHiddenBot, true);
// 内孔标注
AddLinearDim(db, tr, btr, new Point3d(0, r, 0), new Point3d(0, -r, 0),
new Point3d(height + 15, 0, 0), 90, $"%%c{innerDia}");
AddLinearDim(db, tr, btr, new Point3d(ox + 0, oy + r, 0), new Point3d(ox + 0, oy - r, 0),
new Point3d(ox + height + 15, oy, 0), 90, $"%%c{innerDia}");
}
// 外径标注
AddLinearDim(db, tr, btr, new Point3d(0, R, 0), new Point3d(0, -R, 0),
new Point3d(-15, 0, 0), 90, $"%%c{outerDia}");
AddLinearDim(db, tr, btr, new Point3d(ox + 0, oy + R, 0), new Point3d(ox + 0, oy - R, 0),
new Point3d(ox - 15, oy, 0), 90, $"%%c{outerDia}");
// 长度标注
AddLinearDim(db, tr, btr, new Point3d(0, -R, 0), new Point3d(height, -R, 0),
new Point3d(height / 2, -R - 15, 0), 0, $"{height}min");
AddLinearDim(db, tr, btr, new Point3d(ox + 0, oy - R, 0), new Point3d(ox + height, oy - R, 0),
new Point3d(ox + height / 2, oy - R - 15, 0), 0, $"{height}min");
// 4. 车加工零件 (填充)
if (IsMachined(deliveryStatus))
@ -148,10 +155,10 @@ namespace CadParamPluging.Cad
// 零件轮廓
var polyPart = new Polyline();
polyPart.AddVertexAt(0, new Point2d(offsetX, -Rp), 0, 0, 0);
polyPart.AddVertexAt(1, new Point2d(offsetX + heightPrime, -Rp), 0, 0, 0);
polyPart.AddVertexAt(2, new Point2d(offsetX + heightPrime, Rp), 0, 0, 0);
polyPart.AddVertexAt(3, new Point2d(offsetX, Rp), 0, 0, 0);
polyPart.AddVertexAt(0, new Point2d(ox + offsetX, oy - Rp), 0, 0, 0);
polyPart.AddVertexAt(1, new Point2d(ox + offsetX + heightPrime, oy - Rp), 0, 0, 0);
polyPart.AddVertexAt(2, new Point2d(ox + offsetX + heightPrime, oy + Rp), 0, 0, 0);
polyPart.AddVertexAt(3, new Point2d(ox + offsetX, oy + Rp), 0, 0, 0);
polyPart.Closed = true;
polyPart.ColorIndex = 7;
@ -185,11 +192,11 @@ namespace CadParamPluging.Cad
}
// 可以在这里添加零件尺寸标注
AddLinearDim(db, tr, btr, new Point3d(offsetX, Rp, 0), new Point3d(offsetX, -Rp, 0),
new Point3d(offsetX - 5, 0, 0), 90, $"%%c{outerDiaPrime}");
AddLinearDim(db, tr, btr, new Point3d(ox + offsetX, oy + Rp, 0), new Point3d(ox + offsetX, oy - Rp, 0),
new Point3d(ox + offsetX - 5, oy, 0), 90, $"%%c{outerDiaPrime}");
AddLinearDim(db, tr, btr, new Point3d(offsetX, -Rp, 0), new Point3d(offsetX + heightPrime, -Rp, 0),
new Point3d(offsetX + heightPrime / 2, -Rp - 10, 0), 0, $"{heightPrime}");
AddLinearDim(db, tr, btr, new Point3d(ox + offsetX, oy - Rp, 0), new Point3d(ox + offsetX + heightPrime, oy - Rp, 0),
new Point3d(ox + offsetX + heightPrime / 2, oy - Rp - 10, 0), 0, $"{heightPrime}");
}
}
}

View File

@ -616,12 +616,13 @@ namespace CadParamPluging.UI
var removeResult = TemplateDrawingService.RemoveTemplateOriginalDrawing(ctx);
AppendLog($"已删除原有图形: CAXA图层={removeResult.CaxaLayerErased}, 标注={removeResult.DimensionLayerErased}, 保留右上角={removeResult.DimensionLayerKept}");
// 根据模板参数绘制半剖视图
// 根据模板参数绘制半剖视图,居中放置于原图纸位置
HalfSectionDrawer.Draw(
ctx,
bag,
tplParams.ProjectType, // 交付状态
tplParams.SheetSize // 结构特征
tplParams.SheetSize, // 结构特征
removeResult.OriginalCenter // 原图纸中心点
);
ctx.Commit();