From 04b450392b36ee726227c934e06b79c5f690e4e4 Mon Sep 17 00:00:00 2001
From: Ps <376313736@qq.com>
Date: Sun, 4 Feb 2024 18:34:10 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96EntityBoundingInfo?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Entity/EntityBoundingInfo.cs | 121 +++++++-----------
1 file changed, 44 insertions(+), 77 deletions(-)
diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs
index 32562a8..be4b770 100644
--- a/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs
+++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/Entity/EntityBoundingInfo.cs
@@ -15,81 +15,17 @@ public static class EntityBoundingInfo
{
return new(ext);
}
-
- // 包围盒外扩
- //public static BoundingInfo? GetBoundingInfo(this Extents3d ext, double dist = 0)
- //{
- // var p1 = ext.MinPoint.Offset(-dist, -dist);
- // var p2 = ext.MaxPoint.Offset(dist, dist);
- // var e = new Extents3d(p1, p2);
- // return new(e);
- //}
-
- ///
- /// 获取实体包围盒
- ///
- /// 实体
- /// 包围盒
- static Extents3d? GetEntityBox(this Entity ent)
- {
- if (!ent.Bounds.HasValue)
- return null;
- //if (ent is BlockReference brf)
- // ext = brf.GeometryExtentsBestFit();
-
- if (ent is Spline spl)
- return spl.ToPolyline().GeometricExtents;
-
- else if (ent is MText mtext)
- return GetMTextBox(mtext);
-
- else if (ent is Table table)
- {
- if(table.IsNewObject)
- table.GenerateLayout();
-
- table.RecomputeTableBlock(true);
- return table.GeometricExtents;
- }
-
- else if (ent is Dimension dim)
- {
- if(dim.IsNewObject)
- dim.GenerateLayout(); // 新new的实体生成布局,即可获取包围盒
-
- dim.RecomputeDimensionBlock(true);
- return dim.GeometricExtents;
- }
- else
- return ent.GeometricExtents;
-
- }
-
///
/// 获取多行文本的正交包围盒
///
/// 多行文本
/// 包围盒
static Extents3d GetMTextBox(MText mText)
- {
- return mText.GetMTextBoxCorners().ToExtents3D();
- }
-
- ///
- /// 获取点集包围盒
- ///
- /// Point3d点集
- /// 包围盒
- static Extents3d ToExtents3D(this IEnumerable pts)
{
var ext = new Extents3d();
- foreach (Point3d pt in pts)
- {
- ext.AddPoint(pt);
- }
+ GetMTextBoxCorners(mText).ForEach(p=>ext.AddPoint(p));
return ext;
}
-
///
/// 获取块的包围盒
///
@@ -133,13 +69,15 @@ static void GetBlockBox(this Entity en, ref Extents3d ext, ref Matrix3d mat)
{
if (ext.IsEmptyExt())
{
- var e = ent1.GetEntityBox();
+ //var e = ent1.GetEntityBox();
+ var e = GetEntityBoxEx(ent1);
if (e.HasValue)
ext = e.Value;
}
else
{
- var e = ent1.GetEntityBox();
+ //var e = ent1.GetEntityBox();
+ var e = GetEntityBoxEx(ent1);
if (e.HasValue)
ext.AddExtents(e.Value);
}
@@ -147,7 +85,8 @@ static void GetBlockBox(this Entity en, ref Extents3d ext, ref Matrix3d mat)
}
else
{
- var e = en.GetEntityBox();
+ //var e = en.GetEntityBox();
+ var e = GetEntityBoxEx(en);
if (e.HasValue)
{
Extents3d entext = e.Value;
@@ -167,7 +106,7 @@ static void GetBlockBox(this Entity en, ref Extents3d ext, ref Matrix3d mat)
///
/// 多行文本
/// 最小包围盒4点坐标
- public static Point3d[] GetMTextBoxCorners(this MText mtext)
+ public static Point3d[] GetMTextBoxCorners(MText mtext)
{
double width = mtext.ActualWidth;
double height = mtext.ActualHeight;
@@ -233,16 +172,44 @@ public static Point3d[] GetMTextBoxCorners(this MText mtext)
/// 包围盒
public static Extents3d? GetEntityBoxEx(Entity ent)
{
- if (ent is BlockReference block)
+ Extents3d? ext = null;
+ switch (ent)
{
- Extents3d blockExt = default;
- var mat = Matrix3d.Identity;
- block!.GetBlockBox(ref blockExt, ref mat);
- if (blockExt.IsEmptyExt())
- return null;
- return blockExt;
+ case Spline spl:
+ ext = spl.ToPolyline().GeometricExtents;
+ break;
+ case MText mtext:
+ ext = GetMTextBox(mtext);
+ break;
+ case Table table:
+ if (table.IsNewObject)
+ table.GenerateLayout();
+ table.RecomputeTableBlock(true);
+ ext = table.GeometricExtents;
+ break;
+ case Dimension dim:
+ if (dim.IsNewObject)
+ dim.GenerateLayout(); // 新new的实体生成布局,即可获取包围盒
+ dim.RecomputeDimensionBlock(true);
+ ext = dim.GeometricExtents;
+ break;
+ case BlockReference block:
+ Extents3d blockExt = default;
+ var mat = Matrix3d.Identity;
+ block!.GetBlockBox(ref blockExt, ref mat);
+ if (!blockExt.IsEmptyExt())
+ ext = blockExt;
+ break;
+ default:
+ if (ent.Bounds.HasValue)
+ ext = ent.GeometricExtents;
+ break;
}
- return GetEntityBox(ent);
+ if (ext != null)
+ //实体不是点时,pass
+ if (ent is not DBPoint && ext.Value.MinPoint.IsEqualTo(ext.Value.MaxPoint))
+ return null;
+ return ext;
}
///
--
Gitee