diff --git a/src/CADShared/Algorithms/QuadTree/Rect.cs b/src/CADShared/Algorithms/QuadTree/Rect.cs index 1366442ee833adbd4aa9f6b84572abaa17637089..2dba294c003b36250a2a3f6c46cde5b6b6bbf99f 100644 --- a/src/CADShared/Algorithms/QuadTree/Rect.cs +++ b/src/CADShared/Algorithms/QuadTree/Rect.cs @@ -1,6 +1,6 @@ using System.Diagnostics; using System.Runtime.CompilerServices; -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif namespace IFoxCAD.Cad; diff --git a/src/CADShared/Basal/Nullable/ArgumentNullEx.cs b/src/CADShared/Basal/Nullable/ArgumentNullEx.cs index 7fb7763d155fe169740d82758ebdd19763ac4f61..517cd14c8a7658d4c277fa82539de35f42b15ba3 100644 --- a/src/CADShared/Basal/Nullable/ArgumentNullEx.cs +++ b/src/CADShared/Basal/Nullable/ArgumentNullEx.cs @@ -1,5 +1,5 @@  -#if a2024 || zcad +#if !NET8_0_OR_GREATER namespace IFoxCAD.Basal; /// diff --git a/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs b/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs index e6f566041731582fb5e2e0544ff199d4024257b3..35ca5337385539bc2aa0aedab5bc3b8933970781 100644 --- a/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs +++ b/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs @@ -1,5 +1,7 @@ - -#if a2024 || zcad +#if false + + +#if !NET8_0_OR_GREATER namespace System.Runtime.CompilerServices; /// /// 指示参数将为另一个参数传递的表达式捕获为字符串。 @@ -22,4 +24,5 @@ public CallerArgumentExpressionAttribute(string parameterName) // ReSharper disable once UnusedAutoPropertyAccessor.Global public string ParameterName { get; } } +#endif #endif \ No newline at end of file diff --git a/src/CADShared/Basal/Win/WindowsAPI.cs b/src/CADShared/Basal/Win/WindowsAPI.cs index 5125d471e94c218224c4df83e8c5517ef2be4700..5b12ae2cc22560fc476fb352a8a9a4eddb6c1593 100644 --- a/src/CADShared/Basal/Win/WindowsAPI.cs +++ b/src/CADShared/Basal/Win/WindowsAPI.cs @@ -1,6 +1,6 @@ #pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释 #define Marshal -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif namespace IFoxCAD.Basal; diff --git a/src/CADShared/ExtensionMethod/EditorEx.cs b/src/CADShared/ExtensionMethod/EditorEx.cs index 9d2f6c8e1b844bfc81f64ac1668c06ab7de5d301..c73b269415a183a4b16399451f28a264cf82760d 100644 --- a/src/CADShared/ExtensionMethod/EditorEx.cs +++ b/src/CADShared/ExtensionMethod/EditorEx.cs @@ -2,6 +2,30 @@ namespace IFoxCAD.Cad; +/// +/// 执行lisp的方式枚举 +/// +[Flags] +public enum RunLispFlag : byte +{ + /// + /// AdsQueueexpr + /// + AdsQueueexpr = 1, + + /// + /// AcedEvaluateLisp + /// + AcedEvaluateLisp = 2, + + /// + /// SendStringToExecute + /// + SendStringToExecute = 4, +} + + + /// /// 命令行扩展类 /// @@ -1002,27 +1026,7 @@ public static PromptResult GetString(this Editor ed, string Message, string Defa EntryPoint = "ads_queueexpr")] static extern int Ads_queueexpr(string strExpr); - /// - /// 执行lisp的方式枚举 - /// - [Flags] - public enum RunLispFlag : byte - { - /// - /// AdsQueueexpr - /// - AdsQueueexpr = 1, - - /// - /// AcedEvaluateLisp - /// - AcedEvaluateLisp = 2, - - /// - /// SendStringToExecute - /// - SendStringToExecute = 4, - } + /* * 测试命令: diff --git a/src/CADShared/ExtensionMethod/Entity/BlockReferenceEx.cs b/src/CADShared/ExtensionMethod/Entity/BlockReferenceEx.cs index 39ad840c361bb10b9628b76c61b3ea5e73c11c36..92b4032db87449c49584281d22bba159a1a216fe 100644 --- a/src/CADShared/ExtensionMethod/Entity/BlockReferenceEx.cs +++ b/src/CADShared/ExtensionMethod/Entity/BlockReferenceEx.cs @@ -1,4 +1,4 @@ -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs index 14a51130884167c72f1099ce11dd0396dc90a847..cb67f292386cd8fae55cb3807802465fb5c81984 100644 --- a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs +++ b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs @@ -1,11 +1,49 @@ // ReSharper disable ForCanBeConvertedToForeach -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif namespace IFoxCAD.Cad; + +/// +/// 交点类型 +/// +public enum IntersectionType +{ + /// + /// 切点 + /// + Tangential, + /// + /// 交叉点 + /// + Transversal +} + + +/// +/// +/// +/// +/// +public record OverlapInformation(Interval[] OverlapRanges, bool OverlapDirection); + + +/// +/// +/// +/// +/// +/// +/// +public record IntersectionInformation( + PointOnCurve3d PointOnCurve, + IntersectionType IntersectionType, + int OverlapCount, + OverlapInformation[] OverlapInformation); + /// /// 实体类曲线扩展类 /// @@ -35,6 +73,76 @@ public static IEnumerable GetSplitCurves(this Curve curve, IEnumerable(); }*/ + + + + + /// + /// 获取两个曲线的z平面的交点坐标 + /// + /// 第一条曲线 + /// 第二条曲线 + /// 交点平面 + /// 容差 + /// 交点列表 + public static IEnumerable GetIntersectionPoints(this Curve curve, Curve endCurve, Vector3d? normal = null, Tolerance? tolerance = null) + { + var points = new List(); + var cur1 = curve.GetGeCurve(); + var cur2 = endCurve.GetGeCurve(); + tolerance ??= new Tolerance(0.001,0.001); + normal ??= Vector3d.ZAxis; + var cci3d = new CurveCurveIntersector3d(cur1, cur2, normal.Value, tolerance.Value); + for (var i = 0; i < cci3d.NumberOfIntersectionPoints; i++) + { + points.Add(cci3d.GetIntersectionPoint(i)); + } + return points; + } + + /// + /// 获取交点信息 + /// + /// 第一条曲线 + /// 第二条曲线 + /// 交点平面 + /// 容差 + /// 交点信息集合 + + public static IEnumerable GetIntersectionInformation(this Curve curve, Curve endCurve, + Vector3d? normal = null, Tolerance? tolerance = null) + { + normal ??= Vector3d.ZAxis; + tolerance ??= new Tolerance(0.001,0.001); + var cur1 = curve.GetGeCurve(); + var cur2 = endCurve.GetGeCurve(); + + var cci3d = new CurveCurveIntersector3d(cur1, cur2, normal.Value, tolerance.Value); + var overlaps = cci3d.OverlapCount(); + var overlapInformation = new OverlapInformation[overlaps]; + if (overlaps > 0) + { + for (var i = 0; i < overlaps; i++) + { + var range = cci3d.GetOverlapRanges(i); + var dir = cci3d.OverlapDirection(); + overlapInformation[i] = new OverlapInformation(range, dir); + } + } + var inters = new IntersectionInformation[cci3d.NumberOfIntersectionPoints]; + for (var i = 0; i < cci3d.NumberOfIntersectionPoints; i++) + { + inters[i] = new IntersectionInformation(cci3d.GetPointOnCurve1(i), + cci3d.IsTangential(i) ? IntersectionType.Tangential : IntersectionType.Transversal, + overlaps, overlapInformation); + } + return inters; + + } + + + + /// /// 获取分割曲线集合 /// diff --git a/src/CADShared/ExtensionMethod/Geomerty/GeometryEx.cs b/src/CADShared/ExtensionMethod/Geomerty/GeometryEx.cs index 56726314cc88b859c6c6a0f7f02799f66b657ef3..1f0af2dcbb5e3427d963d223591fd25e978969a2 100644 --- a/src/CADShared/ExtensionMethod/Geomerty/GeometryEx.cs +++ b/src/CADShared/ExtensionMethod/Geomerty/GeometryEx.cs @@ -486,7 +486,63 @@ public static List ConvexHull(this List points) return H.Take(k - 1).ToList(); } + /// + /// 判断三个点是否左转 + /// + /// 第一点 + /// 第二点 + /// 第三点 + /// 左转返回 true,否则返回 false + public static bool IsClockWise(Point3d p1, Point3d p2, Point3d p3) + { + return ((p2.X - p1.X) * (p3.Y - p2.Y) - (p2.Y - p1.Y) * (p3.X - p2.X)) > 0; + + } + /// + /// Melkman算法求简单多边形凸包 + /// + /// 多边形端点列表 + /// 凸包端点列表 + public static List ConvexHull_Melkman(this List points) + { + if (points.Count <= 3) + { + return points; + } + + var deque = new LinkedList(); + if (IsClockWise(points[0], points[1], points[2])) + { + deque.AddLast(points[0]); + deque.AddLast(points[1]); + deque.AddLast(points[2]); + } + else + { + deque.AddLast(points[0]); + deque.AddLast(points[2]); + deque.AddLast(points[1]); + } + + foreach (var p in points.Skip(3)) + { + while (deque.Count > 1 && !IsClockWise(deque.Last!.Previous!.Value, deque.Last.Value, p)) + { + deque.RemoveLast(); + } + + while (deque.Count > 1 && !IsClockWise(p, deque.First!.Value, deque.First.Next!.Value)) + { + deque.RemoveFirst(); + } + deque.AddLast(p); + + } + return [.. deque]; + } + + #endregion PointList #endregion Point&Circle diff --git a/src/CADShared/ExtensionMethod/Geomerty/PointEx.cs b/src/CADShared/ExtensionMethod/Geomerty/PointEx.cs index f920a3cd0bf8aca0f3b82e8d8dd72a22119175e3..2a89e17409135e7fa89f6dd7e496cb484bc62bc5 100644 --- a/src/CADShared/ExtensionMethod/Geomerty/PointEx.cs +++ b/src/CADShared/ExtensionMethod/Geomerty/PointEx.cs @@ -1,4 +1,4 @@ -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/Hatch/HatchConverter.cs b/src/CADShared/ExtensionMethod/Hatch/HatchConverter.cs index fe79a623bd4dda12f333b6cbab53c6ad20401976..eb17ddd55da15c25aecacec9eeab4502c262698c 100644 --- a/src/CADShared/ExtensionMethod/Hatch/HatchConverter.cs +++ b/src/CADShared/ExtensionMethod/Hatch/HatchConverter.cs @@ -1,7 +1,7 @@ // ReSharper disable CompareOfFloatsByEqualityOperator // ReSharper disable ForCanBeConvertedToForeach -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/Hatch/HatchInfo.cs b/src/CADShared/ExtensionMethod/Hatch/HatchInfo.cs index f836615f30fabe9e69cd6f853899ebb89f4e6bad..b1d7576cbe63ed2f306658220b6b3707c7b6e4d2 100644 --- a/src/CADShared/ExtensionMethod/Hatch/HatchInfo.cs +++ b/src/CADShared/ExtensionMethod/Hatch/HatchInfo.cs @@ -1,6 +1,6 @@  -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/Jig/JigEx.cs b/src/CADShared/ExtensionMethod/Jig/JigEx.cs index c98511007a083be3b9a5100c00636e61f53aecd5..d0a79c83efa76fe4bea1c32b943ae13445fb0d09 100644 --- a/src/CADShared/ExtensionMethod/Jig/JigEx.cs +++ b/src/CADShared/ExtensionMethod/Jig/JigEx.cs @@ -1,4 +1,4 @@ -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/SelectionSetEx.cs b/src/CADShared/ExtensionMethod/SelectionSetEx.cs index 3d152fb2bd7f2f7b965fc5be5c6a7d8e046b58bd..61c9f03a7999d255791f199d66365dd4fd725c60 100644 --- a/src/CADShared/ExtensionMethod/SelectionSetEx.cs +++ b/src/CADShared/ExtensionMethod/SelectionSetEx.cs @@ -1,4 +1,4 @@ -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/SymbolTableEx.cs b/src/CADShared/ExtensionMethod/SymbolTableEx.cs index f780fd663274b97e0b25bf8c6ef27b5f0be8751e..c9e4af7e1982dc56d468b0d82799d46d85140f4d 100644 --- a/src/CADShared/ExtensionMethod/SymbolTableEx.cs +++ b/src/CADShared/ExtensionMethod/SymbolTableEx.cs @@ -87,44 +87,18 @@ public static bool Delete(this SymbolTable table, /// 块名 /// 对所添加块表的委托n /// 添加图元的委托 - /// 添加属性定义的委托 /// 块定义id /// TODO: 需要测试匿名块等特殊的块是否能定义 - public static ObjectId Add(this SymbolTable table, string name, - Action? action = null, Func>? ents = null, - Func>? attDef = null) + public static ObjectId Add(this SymbolTable table, + string name, Func>? ents = null, + Action? action = null) { return table.Add(name, btr => { - action?.Invoke(btr); - var entsRes = ents?.Invoke(); if (entsRes is not null) btr.AddEntity(entsRes); - - var addDefRes = attDef?.Invoke(); - if (addDefRes is not null) - btr.AddEntity(addDefRes); - }); - } - - /// - /// 添加块定义 - /// - /// 块表 - /// 块名 - /// 图元 - /// 属性定义 - /// - public static ObjectId Add(this SymbolTable table, string name, - IEnumerable? ents = null, IEnumerable? attDef = null) - { - return table.Add(name, btr => - { - if (ents is not null) - btr.AddEntity(ents); - if (attDef is not null) - btr.AddEntity(attDef); + action?.Invoke(btr); }); } @@ -136,9 +110,9 @@ public static ObjectId Add(this SymbolTable table, /// 图元(包括属性) /// public static ObjectId Add(this SymbolTable table, string name, - params Entity[] ents) + params IEnumerable ents) { - return table.Add(name, null, () => ents); + return table.Add(name, () => ents); } /// @@ -189,7 +163,7 @@ public static void AddAttsToBlocks(this SymbolTable table, string fileName, bool over) { - var blkDefName = SymbolUtilityServices.GetSymbolNameFromPathName(fileName, "dwg"); + var blkDefName = SymbolUtilityServices.GetSymbolNameFromPathName(fileName, "dwg;dxf"); #if acad blkDefName = SymbolUtilityServices.RepairSymbolName(blkDefName, false); #endif @@ -216,7 +190,19 @@ public static ObjectId GetBlockFrom(this SymbolTable要打印的对象 public static T Print(this T obj) { - // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract - Document?.Editor.WriteMessage(obj is null ? "null\n" : $"{obj}\n"); + var str = DataFormatter.FormatObject(obj); + Document.Editor.WriteMessage(obj is null ? "null\n" : $"{str}\n"); return obj; } @@ -690,8 +689,7 @@ public static T Print(this T obj) /// 要打印的对象 public static void Printl(object message) { - // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract - Document?.Editor.WriteMessage($"{Environment.NewLine}{message}\n"); + Document.Editor.WriteMessage($"{Environment.NewLine}{DataFormatter.FormatObject(message)}\n"); } /// @@ -884,4 +882,77 @@ public static void DelayUpdateLayLockFade() } #endregion +} + +/// +/// 格式化打印类 +/// +public static class DataFormatter +{ + /// + /// 格式化对象函数 + /// + /// 对象 + /// 格式化后的字符串 + public static string FormatObject(object? obj) + { + // 检查是否为基础类型或者null + if (obj == null || obj.GetType().IsValueType || obj is string) + { + return FormatBasicType(obj); + } + // 检查是否为数组 + + if (obj.GetType().IsArray) + { + return FormatArray(obj as Array); + } + // 检查是否为实现了IEnumerable但未实现IEnumerable的类型(如非泛型集合) + + if (obj is IEnumerable and not IEnumerable) + { + return FormatNonGenericCollection(obj); + } + // 检查是否为实现了IEnumerable的泛型集合 + + if (obj is IEnumerable enumerable) + { + return FormatGenericCollection(enumerable.Cast()); + } + + // 未知类型 + return obj.ToString()!; + } + + private static string FormatBasicType(object? value) + { + return (value != null ? value.ToString() : "") ?? string.Empty; + } + + private static string FormatArray(Array? array) + { + var result = new StringBuilder(); + result.Append("{ "); + if (array != null) result.Append(string.Join(", ", array.Cast().Select(FormatObject))); + result.Append(" }"); + return result.ToString(); + } + + private static string FormatNonGenericCollection(object? collection) + { + var result = new StringBuilder(); + result.Append("{ "); + result.Append(string.Join(", ", ((IEnumerable)collection!).Cast().Select(FormatObject))); + result.Append(" }"); + return result.ToString(); + } + + private static string FormatGenericCollection(IEnumerable collection) + { + var result = new StringBuilder(); + result.Append("{ "); + result.Append(string.Join(", ", collection.Select(FormatObject))); + result.Append(" }"); + return result.ToString(); + } } \ No newline at end of file diff --git a/src/CADShared/Runtime/SymbolTable.cs b/src/CADShared/Runtime/SymbolTable.cs index ad73274b0ddd15dca062e4dafc790bae63d62eaa..c6c9422ebc5dd7275ee43a4de992704eabd39527 100644 --- a/src/CADShared/Runtime/SymbolTable.cs +++ b/src/CADShared/Runtime/SymbolTable.cs @@ -1,6 +1,6 @@ // ReSharper disable RedundantNameQualifier -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/IFoxCAD.AutoCad/GlobalUsings.cs b/src/IFoxCAD.AutoCad/GlobalUsings.cs index 67dcfff663047d2efb5ed03f2fb037777e1afd30..ea5992630844f7b497086550ba4267e837a808a0 100644 --- a/src/IFoxCAD.AutoCad/GlobalUsings.cs +++ b/src/IFoxCAD.AutoCad/GlobalUsings.cs @@ -45,7 +45,7 @@ global using System.Windows.Input; global using System.Globalization; global using System.Diagnostics; - +global using System.Security; // global using System.Windows.Data; global using System.Net; global using System.Diagnostics.CodeAnalysis; diff --git a/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj b/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj index d6c0b9157f825fe3f69ec7d634ca95d00450cfee..388b694d871bae3d440cbe382df5eef04033df7b 100644 --- a/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj +++ b/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj @@ -18,7 +18,7 @@ none - false + True bin\Release\IFoxCAD.AutoCad.xml @@ -45,10 +45,14 @@ - - + + + + + + all - runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers diff --git a/src/IFoxCAD.ZwCad/GlobalUsings.cs b/src/IFoxCAD.ZwCad/GlobalUsings.cs index a3365f56a2c6baa8b18683d5b5e54487f6ffbb4a..b428d552248fa916d621f59fc544ba71dfb28450 100644 --- a/src/IFoxCAD.ZwCad/GlobalUsings.cs +++ b/src/IFoxCAD.ZwCad/GlobalUsings.cs @@ -45,7 +45,7 @@ global using System.Windows.Input; global using System.Globalization; global using System.Diagnostics; - +global using System.Security; // global using System.Windows.Data; global using System.Net; global using System.Diagnostics.CodeAnalysis; diff --git a/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj b/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj index 4b659bef5716b847b13970b17f675cddffc5a990..2bb2e1190fd459eb2724dbb3d1c7b5dc33ce54c1 100644 --- a/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj +++ b/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj @@ -16,7 +16,7 @@ none - false + True bin\Release\IFoxCAD.ZwCad.xml @@ -37,10 +37,14 @@ - - + + + + + + all - runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers diff --git a/tests/TestAcad2025/GlobalUsings.cs b/tests/TestAcad2025/GlobalUsings.cs index 045196f703ea51e14af47638509ed97287167b95..18445b0beb6ffaaf5a7c0a05d46a18d6ba7675d4 100644 --- a/tests/TestAcad2025/GlobalUsings.cs +++ b/tests/TestAcad2025/GlobalUsings.cs @@ -1,48 +1,39 @@ -/// 系统引用 +// 系统引用 global using System; -global using System.Collections; global using System.Collections.Generic; global using System.IO; global using System.Linq; global using System.Text; -global using System.Reflection; -global using System.Text.RegularExpressions; global using Microsoft.Win32; global using System.ComponentModel; global using System.Runtime.InteropServices; -global using System.Collections.Specialized; global using System.Threading; -global using Exception = System.Exception; - global using Registry = Microsoft.Win32.Registry; -global using RegistryKey = Microsoft.Win32.RegistryKey; -/// autocad 引用 +// autocad 引用 global using Autodesk.AutoCAD.ApplicationServices; global using Autodesk.AutoCAD.EditorInput; global using Autodesk.AutoCAD.Colors; global using Autodesk.AutoCAD.DatabaseServices; global using Autodesk.AutoCAD.Geometry; global using Autodesk.AutoCAD.Runtime; +global using Autodesk.AutoCAD.GraphicsInterface; +global using Autodesk.AutoCAD.DatabaseServices.Filters; +global using Autodesk.AutoCAD; global using Acap = Autodesk.AutoCAD.ApplicationServices.Application; global using Acaop = Autodesk.AutoCAD.ApplicationServices.Core.Application; global using Acgi = Autodesk.AutoCAD.GraphicsInterface; -global using Autodesk.AutoCAD.DatabaseServices.Filters; -global using Autodesk.AutoCAD; - // jig命名空间会引起Viewport/Polyline等等重义,最好逐个引入 using Autodesk.AutoCAD.GraphicsInterface global using WorldDraw = Autodesk.AutoCAD.GraphicsInterface.WorldDraw; global using Manager = Autodesk.AutoCAD.GraphicsSystem.Manager; global using Group = Autodesk.AutoCAD.DatabaseServices.Group; global using Viewport = Autodesk.AutoCAD.DatabaseServices.Viewport; -global using Autodesk.AutoCAD.GraphicsInterface; global using Polyline = Autodesk.AutoCAD.DatabaseServices.Polyline; global using Cad_DwgFiler = Autodesk.AutoCAD.DatabaseServices.DwgFiler; global using Cad_DxfFiler = Autodesk.AutoCAD.DatabaseServices.DxfFiler; global using Cad_ErrorStatus = Autodesk.AutoCAD.Runtime.ErrorStatus; - /// ifoxcad global using IFoxCAD.Cad; global using IFoxCAD.Basal; diff --git a/tests/TestAcad2025/TestAcad2025.csproj b/tests/TestAcad2025/TestAcad2025.csproj index 126352d70dc681ed1b0df50713aad572978c0805..d0576b090d894bd056f819ac9073cf6cc308799b 100644 --- a/tests/TestAcad2025/TestAcad2025.csproj +++ b/tests/TestAcad2025/TestAcad2025.csproj @@ -35,13 +35,10 @@ - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/tests/TestShared/TestBlock.cs b/tests/TestShared/TestBlock.cs index 20baa825524e98a23c29a8e527db295beaa9513e..5a016acdd969cb5a9cbf76847237c83e12db6714 100644 --- a/tests/TestShared/TestBlock.cs +++ b/tests/TestShared/TestBlock.cs @@ -47,32 +47,40 @@ public void Test_BlockDef() using DBTrans tr = new(); // var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); tr.BlockTable.Add("test", - btr => - { - btr.Origin = new Point3d(0, 0, 0); - }, + () => // 图元 - new List { new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)) }, - () => // 属性定义 { + + var ents = new List { new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)) }; + var id1 = new AttributeDefinition() { Position = new Point3d(0, 0, 0), Tag = "start", Height = 0.2 }; var id2 = new AttributeDefinition() { Position = new Point3d(1, 1, 0), Tag = "end", Height = 0.2 }; - return new List { id1, id2 }; + return [..ents, id1, id2]; + }, + btr => + { + btr.Origin = new Point3d(0, 0, 0); } ); // ObjectId objectId = tr.BlockTable.Add("a");// 新建块 // objectId.GetObject().AddEntity();// 测试添加空实体 tr.BlockTable.Add("test1", - btr => - { - btr.Origin = new Point3d(0, 0, 0); - }, - () => - { - var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); - var acText = DBTextEx.CreateDBText(Point3d.Origin, "123", 2.5); - return new List { line, acText }; - }); + + () => + { + var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + var acText = DBTextEx.CreateDBText(Point3d.Origin, "123", 2.5); + return [line, acText] ; + }, + + btr => + { + btr.Origin = new Point3d(0, 0, 0); + } + + + ); + } // 后台块定义 @@ -82,34 +90,34 @@ public void Test_BlockDefbehind() using DBTrans tr = new(@"C:\Users\vic\Desktop\test.dwg"); // var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); tr.BlockTable.Add("test", - btr => - { - btr.Origin = new Point3d(0, 0, 0); - }, + () => // 图元 { - return new List { new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)) }; - }, - () => // 属性定义 - { + var ents = new List { new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)) }; + var id1 = new AttributeDefinition() { Position = new Point3d(0, 0, 0), Tag = "start", Height = 0.2 }; var id2 = new AttributeDefinition() { Position = new Point3d(1, 1, 0), Tag = "end", Height = 0.2 }; - return new List { id1, id2 }; + return [..ents, id1, id2]; + }, + btr => + { + btr.Origin = new Point3d(0, 0, 0); } ); // ObjectId objectId = tr.BlockTable.Add("a");// 新建块 // objectId.GetObject().AddEntity();// 测试添加空实体 tr.BlockTable.Add("test1", - btr => - { - btr.Origin = new Point3d(0, 0, 0); - }, + () => { var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); var acText = DBTextEx.CreateDBText(Point3d.Origin, "12345", 2.5); - return new List { line, acText }; + return [line, acText]; + }, + btr => + { + btr.Origin = new Point3d(0, 0, 0); }); tr.Database.SaveDwgFile(); } @@ -121,18 +129,6 @@ public void Test_BlockDefbehind() public void Test_BlockDefChange() { using DBTrans tr = new(); - // var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); - // tr.BlockTable.Change("test", btr => - // { - // btr.Origin = new Point3d(5, 5, 0); - // btr.AddEntity(new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 2)); - // btr.GetEntities() - // .ToList() - // .ForEach(e => e.Flush()); // 刷新块显示 - - // }); - - tr.BlockTable.Change("test", btr => { foreach (var id in btr) @@ -179,7 +175,8 @@ public void Test_InsertBlockDef() var line4 = new Line(new Point3d(5, 5, 0), new Point3d(-6, 6, 0)); var att3 = new AttributeDefinition() { Position = new Point3d(10, 14, 0), Tag = "tagTest3", Height = 1, TextString = "valueTest3" }; var att4 = new AttributeDefinition() { Position = new Point3d(10, 16, 0), Tag = "tagTest4", Height = 1, TextString = "valueTest4" }; - tr.BlockTable.Add("test2", new List { line3, line4 }, new List { att3, att4 }); + tr.BlockTable.Add("test2", [line3, line4, att3, att4]); + tr.BlockTable.Add("test23", line3,line4, att3, att4); // tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test1"); // 测试默认 // tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test2"); // tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test3"); // 测试插入不存在的块定义 @@ -209,17 +206,19 @@ public void Test_InsertBlockWithDoubleDatabase() using var trans = new DBTrans(); tr.BlockTable.Add("test456", - btr => - { - btr.Origin = new(0, 0, 0); - }, + () => { var line = new Line(new(0, 0, 0), new(1, 1, 0)); var actext = DBTextEx.CreateDBText(Point3d.Origin, "123", 2.5, database: tr.Database); - return new List { line, actext }; + return [line, actext]; + + }, + btr => + { + btr.Origin = new(0, 0, 0); }); tr.CurrentSpace.InsertBlock(Point3d.Origin, "test456"); tr.Database.SaveDwgFile(); @@ -273,6 +272,7 @@ public void Test_BlockFiledxf() using DBTrans tr = new(); foreach (var item in files) { + Env.Printl(item); var id = tr.BlockTable.GetBlockFrom(item, false); var pt = Env.Editor.GetPoint("pick pt"); if (pt.Status == PromptStatus.OK) @@ -459,7 +459,7 @@ public void Test_QuickBlockDef2() // ents = ents.OrderBy(x => x.Value).ToList(); var ents = rss.Value.GetEntities(); // ents.ForEach(ent => extents.AddExtents(ent.GeometricExtents)); - var extents = ents!.GetExtents(); + var extents = ents.GetExtents(); Point3d pt = extents.MinPoint; Matrix3d matrix = Matrix3d.Displacement(Point3d.Origin - pt); // List newEnts = []; diff --git a/tests/TestShared/TestConvexHull.cs b/tests/TestShared/TestConvexHull.cs index 03692ae5ffc3cceec783cd35c053079e7374ba03..c7bbafb169a703eab2c13dbacec0ee3989ffa3e2 100644 --- a/tests/TestShared/TestConvexHull.cs +++ b/tests/TestShared/TestConvexHull.cs @@ -73,4 +73,20 @@ public void Test_ConvexHull() Env.Editor.WriteMessage($"点集的有向面积:{area5} \n"); Env.Editor.WriteMessage($"点集的有向面积:{area6} \n"); } + + [CommandMethod(nameof(Test_ConvexHull_Melkman))] + public static void Test_ConvexHull_Melkman() + { + using var tr = new DBTrans(); + var ent = Env.Editor.GetEntity("选取多段线"); + if (ent.Status != PromptStatus.OK) return; + var pts = ent.ObjectId.GetObject()!.GetPoints(); + var ptss = pts.ConvexHull_Melkman(); + var pl = ptss.CreatePolyline(p => + { + p.Closed = true; + p.ColorIndex = 3; + }); + tr.CurrentSpace.AddEntity(pl); + } } \ No newline at end of file diff --git a/tests/TestShared/TestCurve.cs b/tests/TestShared/TestCurve.cs index fd75698f2af5472409a2139940e55ee400d0e113..2f8444e3d604a34cc3f54fa9a897638367a79990 100644 --- a/tests/TestShared/TestCurve.cs +++ b/tests/TestShared/TestCurve.cs @@ -273,6 +273,147 @@ public void Test_BreakCurve() tr.CurrentSpace.AddEntity(tt); } + [CommandMethod(nameof(Test_CurveIntersector))] + public static void Test_CurveIntersector() + { + using DBTrans tr = new(); + + var ent1 = Env.Editor.GetEntity("第一条曲线"); + if (ent1.Status != PromptStatus.OK) return; + var ent2 = Env.Editor.GetEntity("第二条曲线"); + if (ent2.Status != PromptStatus.OK) return; + + var ent1curve = ent1.ObjectId.GetObject(); + var ent2curve = ent2.ObjectId.GetObject(); + double j = 1; + for (int i = 0; i < 9; i++) + { + j /= 10; + Tolerance tol = new(j, j); + Env.Printl($"精度为 {j}"); + var pts = ent1curve!.GetIntersectionPoints(ent2curve!); + foreach (var point3d in pts) + { + point3d.Print(); + var cir = new Circle(point3d, Vector3d.ZAxis, 5); + cir.ColorIndex = i; + tr.CurrentSpace.AddEntity(cir); + } + } + + } + + [CommandMethod(nameof(Test_CurveIntersectorInfo))] + public static void Test_CurveIntersectorInfo() + { + using DBTrans tr = new(); + + var ent1 = Env.Editor.GetEntity("第一条曲线"); + if (ent1.Status != PromptStatus.OK) return; + var ent2 = Env.Editor.GetEntity("第二条曲线"); + if (ent2.Status != PromptStatus.OK) return; + Env.Printl("转换"); + var ent1curve = ent1.ObjectId.GetObject(); + var ent2curve = ent2.ObjectId.GetObject(); + Env.Printl("开始:"); + // + var cci3d = new CurveCurveIntersector3d(ent1curve!.GetGeCurve(), ent2curve!.GetGeCurve(), Vector3d.ZAxis); + // + + + // 如果不存在重叠,直接获取重叠区域cad会崩溃 + if (cci3d.OverlapCount() > 0) + { + Env.Printl("输出OverlapCount:"); + cci3d.OverlapCount().Print(); + for (var i = 0; i < cci3d.OverlapCount(); i++) + { + // 这里的参数为重叠的顺序号,而不是交点的顺序号 + Env.Printl("输出GetOverlapRanges:"); + cci3d.GetOverlapRanges(i).Print(); + // + Env.Printl("输出OverlapDirection:"); + cci3d.OverlapDirection().Print(); + } + + } + + for (var i = 0; i < cci3d.NumberOfIntersectionPoints; i++) + { + Env.Printl("输出GetIntersectionParameters:"); + cci3d.GetIntersectionParameters(i).Print(); + + Env.Printl("输出GetIntersectionPoint:"); + cci3d.GetIntersectionPoint(i).Print(); + // + Env.Printl("输出GetIntersectionRanges:"); + cci3d.GetIntersectionRanges().Print(); + + + + + + Env.Printl("输出IsTangential:"); + cci3d.IsTangential(i).Print(); + + Env.Printl("输出IsTransversal:"); + cci3d.IsTransversal(i).Print(); + + + + + } + + + + + } + + [CommandMethod(nameof(Test_CurveInters))] + public static void Test_CurveInters() + { + using DBTrans tr = new(); + + var ent1 = Env.Editor.GetEntity("第一条曲线"); + if (ent1.Status != PromptStatus.OK) return; + var ent2 = Env.Editor.GetEntity("第二条曲线"); + if (ent2.Status != PromptStatus.OK) return; + Env.Printl("转换"); + var ent1curve = ent1.ObjectId.GetObject(); + var ent2curve = ent2.ObjectId.GetObject(); + Env.Printl("开始:"); + var inters = ent1curve!.GetIntersectionInformation(ent2curve!); + + foreach (var intersectionInformation in inters) + { + Env.Printl("打印交点:"); + intersectionInformation.PointOnCurve.Point.Print(); + + Env.Printl("打印交点类型:"); + intersectionInformation.IntersectionType.Print(); + + Env.Printl("打印重叠数量:"); + intersectionInformation.OverlapCount.Print(); + foreach (var overlapInformation in intersectionInformation.OverlapInformation) + { + Env.Printl("打印重叠区间:"); + overlapInformation.OverlapRanges.Print(); + + Env.Printl("打印重叠方向:"); + overlapInformation.OverlapDirection.Print(); + } + + } + + + + } + + + + + + [CommandMethod(nameof(Test_CurveCurveIntersector3d))] public void Test_CurveCurveIntersector3d() { diff --git a/tests/TestShared/TestLisp.cs b/tests/TestShared/TestLisp.cs index 4bd7b193b39beb6d5b61f31a5d4b7945ee7551f6..2485c37a05b3f17b9311b3ae9fbd602883da4d73 100644 --- a/tests/TestShared/TestLisp.cs +++ b/tests/TestShared/TestLisp.cs @@ -72,7 +72,7 @@ public static void CmdTest_RunLisp() var ed = doc.Editor; var sb = new StringBuilder(); - foreach (var item in Enum.GetValues(typeof(EditorEx.RunLispFlag))) + foreach (var item in Enum.GetValues(typeof(RunLispFlag))) { sb.Append((byte)item); sb.Append(','); @@ -83,40 +83,40 @@ public static void CmdTest_RunLisp() if (ppr.Status != PromptStatus.OK) return; - var flag = (EditorEx.RunLispFlag)ppr.Value; + var flag = (RunLispFlag)ppr.Value; - if (flag == EditorEx.RunLispFlag.AdsQueueexpr) + if (flag == RunLispFlag.AdsQueueexpr) { // 同步 Env.Editor.RunLisp("(setq a 10)(princ)", - EditorEx.RunLispFlag.AdsQueueexpr); + RunLispFlag.AdsQueueexpr); Env.Editor.RunLisp("(princ a)", - EditorEx.RunLispFlag.AdsQueueexpr);// 成功输出 + RunLispFlag.AdsQueueexpr);// 成功输出 } - else if (flag == EditorEx.RunLispFlag.AcedEvaluateLisp) + else if (flag == RunLispFlag.AcedEvaluateLisp) { // 使用(command "CmdTest_RunLisp1")发送,然后 !b 查看变量,acad08是有值的,高版本是null var strlisp0 = "(setq b 20)"; var res0 = Env.Editor.RunLisp(strlisp0, - EditorEx.RunLispFlag.AcedEvaluateLisp); // 有lisp的返回值 + RunLispFlag.AcedEvaluateLisp); // 有lisp的返回值 var strlisp1 = "(defun f1( / )(princ \"aa\"))"; var res1 = Env.Editor.RunLisp(strlisp1, - EditorEx.RunLispFlag.AcedEvaluateLisp); // 有lisp的返回值 + RunLispFlag.AcedEvaluateLisp); // 有lisp的返回值 var strlisp2 = "(defun f2( / )(command \"line\"))"; var res2 = Env.Editor.RunLisp(strlisp2, - EditorEx.RunLispFlag.AcedEvaluateLisp); // 有lisp的返回值 + RunLispFlag.AcedEvaluateLisp); // 有lisp的返回值 } - else if (flag == EditorEx.RunLispFlag.SendStringToExecute) + else if (flag == RunLispFlag.SendStringToExecute) { // 测试异步 // (command "CmdTest_RunLisp1")和(LispTest_RunLisp)4都是异步 var str = "(setq c 40)(princ)"; Env.Editor.RunLisp(str, - EditorEx.RunLispFlag.SendStringToExecute); // 异步,后发送 + RunLispFlag.SendStringToExecute); // 异步,后发送 Env.Editor.RunLisp("(princ c)", - EditorEx.RunLispFlag.AdsQueueexpr); // 同步,先发送了,输出是null + RunLispFlag.AdsQueueexpr); // 同步,先发送了,输出是null } } } \ No newline at end of file diff --git a/tests/TestZcad2025/GlobalUsings.cs b/tests/TestZcad2025/GlobalUsings.cs index 2c24797f6c0cde2a403ff8c6672248a0cb46058e..e820a0eec23dcd5ebfaa9a15ea54333d11fdf326 100644 --- a/tests/TestZcad2025/GlobalUsings.cs +++ b/tests/TestZcad2025/GlobalUsings.cs @@ -1,22 +1,15 @@ -/// 系统引用 +// 系统引用 global using System; -global using System.Collections; global using System.Collections.Generic; global using System.IO; global using System.Linq; global using System.Text; -global using System.Reflection; -global using System.Text.RegularExpressions; global using Microsoft.Win32; global using System.ComponentModel; global using System.Runtime.InteropServices; -global using System.Collections.Specialized; global using System.Threading; global using System.Diagnostics; -global using Exception = System.Exception; -global using System.Runtime.CompilerServices; global using Registry = Microsoft.Win32.Registry; -global using RegistryKey = Microsoft.Win32.RegistryKey; // cad 引用 global using ZwSoft.ZwCAD.ApplicationServices; @@ -25,13 +18,13 @@ global using ZwSoft.ZwCAD.DatabaseServices; global using ZwSoft.ZwCAD.Geometry; global using ZwSoft.ZwCAD.Runtime; +global using ZwSoft.ZwCAD.GraphicsInterface; +global using ZwSoft.ZwCAD.DatabaseServices.Filters; global using Acap = ZwSoft.ZwCAD.ApplicationServices.Application; global using Acaop = ZwSoft.ZwCAD.ApplicationServices.Application; -global using AcException = ZwSoft.ZwCAD.Runtime.Exception; -global using ZwSoft.ZwCAD.DatabaseServices.Filters; global using Acgi = ZwSoft.ZwCAD.GraphicsInterface; + // jig命名空间会引起Viewport/Polyline等等重义,最好逐个引入 using ZwSoft.ZwCAD.GraphicsInterface -global using ZwSoft.ZwCAD.GraphicsInterface; global using WorldDraw = ZwSoft.ZwCAD.GraphicsInterface.WorldDraw; global using Manager = ZwSoft.ZwCAD.GraphicsSystem.Manager; global using Group = ZwSoft.ZwCAD.DatabaseServices.Group; @@ -41,8 +34,7 @@ global using Cad_DxfFiler = ZwSoft.ZwCAD.DatabaseServices.DxfFiler; global using Cad_ErrorStatus = ZwSoft.ZwCAD.Runtime.ErrorStatus; - -/// ifoxcad +// ifoxcad global using IFoxCAD.Cad; global using IFoxCAD.Basal; diff --git a/tests/TestZcad2025/TestZcad2025.csproj b/tests/TestZcad2025/TestZcad2025.csproj index 89cf1ba77f1ba02466d1bbf49e7be9c975a259b0..967043563deb8ee18a712d9f58eddedd74c4c649 100644 --- a/tests/TestZcad2025/TestZcad2025.csproj +++ b/tests/TestZcad2025/TestZcad2025.csproj @@ -1,4 +1,4 @@ - + preview enable