diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/ObjectIdEx.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/ObjectIdEx.cs index f5ebcb665ca07a919d834d1d115c9d47a369b397..2e74dd244b6643d9b33d9fae1eb80db18d1c7a75 100644 --- a/src/CAD/IFox.CAD.Shared/ExtensionMethod/ObjectIdEx.cs +++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/ObjectIdEx.cs @@ -1,4 +1,5 @@ using System.Data.Common; +using System.Text.RegularExpressions; namespace IFoxCAD.Cad; @@ -50,14 +51,41 @@ public static T GetObject(this ObjectId id, /// /// 对象类型 /// 对象id集合 + /// 精确匹配 /// 对象id集合 - public static IEnumerable OfType(this IEnumerable ids) where T : DBObject + public static IEnumerable OfType(this IEnumerable ids,bool exactMatch =false) where T : DBObject { - string dxfName = RXClass.GetClass(typeof(T)).DxfName; - return ids.Where(id => id.ObjectClass.DxfName == dxfName); + var rxc = RXClass.GetClass(typeof(T)); + if (exactMatch) + { + var dxfName = rxc.DxfName; + return ids.Where(id => id.ObjectClass.DxfName == dxfName); + } + else + { + return ids.Where(id => id.ObjectClass.IsDerivedFrom(rxc)); + } } #endregion GetObject + /// + /// 根据对象句柄字符串获取对象Id + /// + /// 数据库 + /// 句柄字符串 + /// 对象的ObjectId + public static ObjectId GetObjectId(this Database db, string handleString) + { + if (long.TryParse(handleString, System.Globalization.NumberStyles.HexNumber, null, out long l)) + { + var hanle = new Handle(l); + if (db.TryGetObjectId(hanle, out ObjectId id)) + { + return id; + } + } + return ObjectId.Null; + } /// /// id是否有效,未被删除 diff --git a/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs b/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs index 2cfa8d2f43f04da02676f071f7da0ed58d4675aa..e05963341666303e10b3684500b9477ada78ca14 100644 --- a/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs +++ b/src/CAD/IFox.CAD.Shared/ExtensionMethod/PointEx.cs @@ -56,12 +56,21 @@ public static double GetAngle(this Point2d startPoint, Point2d endPoint) /// /// /// - public static Point2d GetCenter(this Point2d a, Point2d b) + public static Point2d GetMidPointTo(this Point2d a, Point2d b) { // (p1 + p2) / 2; // 溢出风险 return new Point2d(a.X * 0.5 + b.X * 0.5, a.Y * 0.5 + b.Y * 0.5); } + /// + /// Z值归零 + /// + /// 点 + /// 新点 + internal static Point3d Z20(this Point3d point) + { + return new Point3d(point.X, point.Y, 0); + } /// http://www.lee-mac.com/bulgeconversion.html /// diff --git "a/src/CAD/IFox.CAD.Shared/ExtensionMethod/\346\226\260\345\273\272\345\241\253\345\205\205/HatchConverter.cs" "b/src/CAD/IFox.CAD.Shared/ExtensionMethod/\346\226\260\345\273\272\345\241\253\345\205\205/HatchConverter.cs" index 34a16046d5a068fd14d59cdf62401c68a80a1974..688bf78aeaf8edc2e8354bc2aeebcba47c40b441 100644 --- "a/src/CAD/IFox.CAD.Shared/ExtensionMethod/\346\226\260\345\273\272\345\241\253\345\205\205/HatchConverter.cs" +++ "b/src/CAD/IFox.CAD.Shared/ExtensionMethod/\346\226\260\345\273\272\345\241\253\345\205\205/HatchConverter.cs" @@ -25,7 +25,7 @@ class CircleData /// 对称点2 public CircleData(PointV symmetryAxisPoint1, PointV symmetryAxisPoint2) { - Center = symmetryAxisPoint1.GetCenter(symmetryAxisPoint2); + Center = PointEx.GetMidPointTo(symmetryAxisPoint1, symmetryAxisPoint2); Radius = symmetryAxisPoint1.GetDistanceTo(symmetryAxisPoint2) * 0.5; } }