保留表格内的蓝色字
This commit is contained in:
parent
bfec5deb9f
commit
3bd6d7cd11
@ -1991,6 +1991,9 @@ namespace CadParamPluging.Cad
|
||||
// Calculate white frame extents
|
||||
var whiteFrameExtents = ComputeWhiteFrameExtentsFromEntities(tr, allEntities) ?? ComputeLayoutExtents(allEntities);
|
||||
result.WhiteFrameExtents = whiteFrameExtents;
|
||||
var titleBlockExtents = whiteFrameExtents.HasValue
|
||||
? ComputeTitleBlockExtentsFromEntities(tr, allEntities, whiteFrameExtents.Value)
|
||||
: (Extents3d?)null;
|
||||
|
||||
if (caxaExtents.HasValue)
|
||||
{
|
||||
@ -2045,6 +2048,11 @@ namespace CadParamPluging.Cad
|
||||
*/
|
||||
}
|
||||
|
||||
if (IsWithinTitleBlock(ent, titleBlockExtents))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsCaxaLayer(layerName))
|
||||
{
|
||||
var entForWrite = tr.GetObject(ent.ObjectId, OpenMode.ForWrite) as Entity;
|
||||
@ -2058,6 +2066,12 @@ namespace CadParamPluging.Cad
|
||||
|
||||
if (IsDimensionLayer(layerName) || IsDimensionEntity(ent))
|
||||
{
|
||||
if (IsWithinTitleBlock(ent, titleBlockExtents))
|
||||
{
|
||||
result.DimensionLayerKept++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 基于CAXA图形区域判断是否在右上角
|
||||
if (graphicExtents.HasValue && IsInTopRightCorner(ent, graphicExtents.Value, topRightThreshold))
|
||||
{
|
||||
@ -2244,6 +2258,10 @@ namespace CadParamPluging.Cad
|
||||
?? ComputeWhiteFrameExtentsFromEntities(tr, allEntities)
|
||||
?? ComputeLayoutExtents(allEntities);
|
||||
|
||||
var titleBlockExtents = targetExtents.HasValue
|
||||
? ComputeTitleBlockExtentsFromEntities(tr, allEntities, targetExtents.Value)
|
||||
: (Extents3d?)null;
|
||||
|
||||
var removed = 0;
|
||||
foreach (ObjectId id in ms)
|
||||
{
|
||||
@ -2258,6 +2276,11 @@ namespace CadParamPluging.Cad
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsWithinTitleBlock(ent, titleBlockExtents))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!IsWithin(ent, targetExtents))
|
||||
{
|
||||
continue;
|
||||
@ -2456,6 +2479,8 @@ namespace CadParamPluging.Cad
|
||||
return 0;
|
||||
}
|
||||
|
||||
var titleBlockExtents = ComputeTitleBlockExtentsFromEntities(tr, allEntities, whiteFrame.Value);
|
||||
|
||||
var frame = whiteFrame.Value;
|
||||
var height = frame.MaxPoint.Y - frame.MinPoint.Y;
|
||||
if (height <= 0)
|
||||
@ -2500,6 +2525,11 @@ namespace CadParamPluging.Cad
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsWithinTitleBlock(ent, titleBlockExtents))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryGetEntityCenterY(ent, out var centerY))
|
||||
{
|
||||
continue;
|
||||
@ -2998,6 +3028,129 @@ namespace CadParamPluging.Cad
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Extents3d? ComputeTitleBlockExtentsFromEntities(Transaction tr, IEnumerable<Entity> entities, Extents3d frame)
|
||||
{
|
||||
if (entities == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var w = frame.MaxPoint.X - frame.MinPoint.X;
|
||||
var h = frame.MaxPoint.Y - frame.MinPoint.Y;
|
||||
if (w <= 0 || h <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var searchMinX = frame.MinPoint.X + w * 0.25;
|
||||
var searchMaxX = frame.MaxPoint.X - 5.0;
|
||||
var searchMinY = frame.MinPoint.Y;
|
||||
var searchMaxY = frame.MinPoint.Y + h * 0.50;
|
||||
|
||||
var candidatesX = new List<double>();
|
||||
var candidatesY = new List<double>();
|
||||
|
||||
foreach (var ent in entities)
|
||||
{
|
||||
if (ent == null || ent.IsErased)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ent is Line ln)
|
||||
{
|
||||
if (Math.Abs(ln.StartPoint.X - ln.EndPoint.X) < 1.0
|
||||
&& ln.StartPoint.X > searchMinX && ln.StartPoint.X < searchMaxX
|
||||
&& Math.Max(ln.StartPoint.Y, ln.EndPoint.Y) > searchMinY
|
||||
&& Math.Min(ln.StartPoint.Y, ln.EndPoint.Y) < searchMaxY)
|
||||
{
|
||||
candidatesX.Add(ln.StartPoint.X);
|
||||
}
|
||||
|
||||
if (ln.StartPoint.X > frame.MaxPoint.X - Math.Min(200.0, w * 0.5)
|
||||
&& ln.EndPoint.X > frame.MaxPoint.X - Math.Min(200.0, w * 0.5)
|
||||
&& ln.StartPoint.Y > searchMinY && ln.StartPoint.Y < frame.MinPoint.Y + Math.Min(80.0, h * 0.40)
|
||||
&& Math.Abs(ln.StartPoint.Y - ln.EndPoint.Y) < 1.0)
|
||||
{
|
||||
candidatesY.Add(ln.StartPoint.Y);
|
||||
}
|
||||
}
|
||||
else if (ent is Polyline pl)
|
||||
{
|
||||
for (int i = 0; i < pl.NumberOfVertices; i++)
|
||||
{
|
||||
var pt = pl.GetPoint3dAt(i);
|
||||
if (pt.X > searchMinX && pt.X < searchMaxX && pt.Y > searchMinY && pt.Y < searchMaxY)
|
||||
{
|
||||
candidatesX.Add(pt.X);
|
||||
}
|
||||
if (pt.X > frame.MaxPoint.X - Math.Min(200.0, w * 0.5)
|
||||
&& pt.Y > searchMinY && pt.Y < frame.MinPoint.Y + Math.Min(80.0, h * 0.40))
|
||||
{
|
||||
candidatesY.Add(pt.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ent is BlockReference br)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ext = br.GeometricExtents;
|
||||
if (ext.MaxPoint.X > searchMinX && ext.MinPoint.X < searchMaxX
|
||||
&& ext.MaxPoint.Y > searchMinY && ext.MinPoint.Y < searchMaxY)
|
||||
{
|
||||
if (ext.MinPoint.X > searchMinX)
|
||||
{
|
||||
candidatesX.Add(ext.MinPoint.X);
|
||||
}
|
||||
if (ext.MaxPoint.Y < frame.MinPoint.Y + Math.Min(80.0, h * 0.40))
|
||||
{
|
||||
candidatesY.Add(ext.MaxPoint.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (candidatesY.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var tableTopY = candidatesY.Max();
|
||||
var boundaryX = candidatesX.Count > 0 ? candidatesX.Min() : (frame.MaxPoint.X - Math.Min(200.0, w * 0.5));
|
||||
|
||||
if (boundaryX >= frame.MaxPoint.X - 1.0 || tableTopY <= frame.MinPoint.Y + 1.0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Extents3d(
|
||||
new Point3d(boundaryX, frame.MinPoint.Y, 0),
|
||||
new Point3d(frame.MaxPoint.X, tableTopY, 0));
|
||||
}
|
||||
|
||||
private static bool IsWithinTitleBlock(Entity ent, Extents3d? titleBlock)
|
||||
{
|
||||
if (ent == null || !titleBlock.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Intersects(ent.GeometricExtents, titleBlock.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsInTopRightCorner(Entity ent, Extents3d layoutExtents, double threshold)
|
||||
{
|
||||
try
|
||||
|
||||
@ -267,14 +267,15 @@ namespace CadParamPluging.UI
|
||||
using (doc.LockDocument())
|
||||
using (var ctx = new CadContext(doc))
|
||||
{
|
||||
var removed = TemplateDrawingService.RemoveMatchParameterAnnotations(
|
||||
ctx,
|
||||
layoutName,
|
||||
isModelSpace);
|
||||
if (removed > 0)
|
||||
{
|
||||
AppendLog($"已移除模板匹配参数标注文本: {removed} 处");
|
||||
}
|
||||
// 用户要求保留模板配置文字,不执行移除操作
|
||||
// var removed = TemplateDrawingService.RemoveMatchParameterAnnotations(
|
||||
// ctx,
|
||||
// layoutName,
|
||||
// isModelSpace);
|
||||
// if (removed > 0)
|
||||
// {
|
||||
// AppendLog($"已移除模板匹配参数标注文本: {removed} 处");
|
||||
// }
|
||||
|
||||
var featureCategoryCount = TemplateDrawingService.ApplyFeatureCategory(
|
||||
ctx,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user