From 4529b72fabd9e17b2ae00437daa426cdb988835d Mon Sep 17 00:00:00 2001 From: vicwjb Date: Fri, 6 Dec 2024 16:13:00 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20GetBlockFrom=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96dxf?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=9D=97=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/SymbolTableEx.cs | 16 ++++++++++++++-- src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj | 2 +- src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj | 2 +- tests/TestAcad2025/GlobalUsings.cs | 19 +++++-------------- tests/TestAcad2025/TestAcad2025.csproj | 9 +++------ tests/TestShared/TestBlock.cs | 1 + tests/TestZcad2025/GlobalUsings.cs | 18 +++++------------- tests/TestZcad2025/TestZcad2025.csproj | 2 +- 8 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/CADShared/ExtensionMethod/SymbolTableEx.cs b/src/CADShared/ExtensionMethod/SymbolTableEx.cs index f780fd6..331ca9e 100644 --- a/src/CADShared/ExtensionMethod/SymbolTableEx.cs +++ b/src/CADShared/ExtensionMethod/SymbolTableEx.cs @@ -189,7 +189,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 +216,19 @@ public static ObjectId GetBlockFrom(this SymbolTable none - false + True bin\Release\IFoxCAD.AutoCad.xml diff --git a/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj b/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj index 4b659be..ab5ac5b 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 diff --git a/tests/TestAcad2025/GlobalUsings.cs b/tests/TestAcad2025/GlobalUsings.cs index 045196f..18445b0 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 126352d..d0576b0 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 20baa82..e93c30d 100644 --- a/tests/TestShared/TestBlock.cs +++ b/tests/TestShared/TestBlock.cs @@ -273,6 +273,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) diff --git a/tests/TestZcad2025/GlobalUsings.cs b/tests/TestZcad2025/GlobalUsings.cs index 2c24797..e820a0e 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 89cf1ba..9670435 100644 --- a/tests/TestZcad2025/TestZcad2025.csproj +++ b/tests/TestZcad2025/TestZcad2025.csproj @@ -1,4 +1,4 @@ - + preview enable -- Gitee From 8cc1e6fc937cedac4bebf17b97defdb992844632 Mon Sep 17 00:00:00 2001 From: vicwjb Date: Sat, 7 Dec 2024 23:35:20 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=B0=86enum=E7=A7=BB=E8=87=B3=E7=B1=BB?= =?UTF-8?q?=E5=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CADShared/ExtensionMethod/EditorEx.cs | 46 ++++++++++++----------- tests/TestShared/TestLisp.cs | 24 ++++++------ 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/CADShared/ExtensionMethod/EditorEx.cs b/src/CADShared/ExtensionMethod/EditorEx.cs index 9d2f6c8..c73b269 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/tests/TestShared/TestLisp.cs b/tests/TestShared/TestLisp.cs index 4bd7b19..2485c37 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 -- Gitee From ff65729e1411c41b9eb2badafa85e175893b7305 Mon Sep 17 00:00:00 2001 From: vicwjb Date: Sun, 15 Dec 2024 22:51:46 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9D=97=E5=AE=9A=E4=B9=89=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/SymbolTableEx.cs | 38 ++----- tests/TestShared/TestBlock.cs | 99 +++++++++---------- 2 files changed, 55 insertions(+), 82 deletions(-) diff --git a/src/CADShared/ExtensionMethod/SymbolTableEx.cs b/src/CADShared/ExtensionMethod/SymbolTableEx.cs index 331ca9e..c9e4af7 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); } /// diff --git a/tests/TestShared/TestBlock.cs b/tests/TestShared/TestBlock.cs index e93c30d..5a016ac 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(); @@ -460,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 = []; -- Gitee From 3937270645b98fe60ab21740fc45e3680d732d0b Mon Sep 17 00:00:00 2001 From: vicwjb Date: Sun, 15 Dec 2024 23:02:10 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E7=AC=A6=E5=8F=B7=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E7=BC=96=E8=AF=91=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=E4=B8=8Eifox=E7=9A=84=E6=BA=90=E7=A0=81=E4=B8=8D=E7=AC=A6?= =?UTF-8?q?=E6=97=B6=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CADShared/Algorithms/QuadTree/Rect.cs | 2 +- src/CADShared/Basal/Nullable/ArgumentNullEx.cs | 2 +- .../Basal/Nullable/CallerArgumentExpressionAttribute.cs | 2 +- src/CADShared/Basal/Win/WindowsAPI.cs | 2 +- src/CADShared/ExtensionMethod/Entity/BlockReferenceEx.cs | 2 +- src/CADShared/ExtensionMethod/Entity/CurveEx.cs | 2 +- src/CADShared/ExtensionMethod/Geomerty/PointEx.cs | 2 +- src/CADShared/ExtensionMethod/Hatch/HatchConverter.cs | 2 +- src/CADShared/ExtensionMethod/Hatch/HatchInfo.cs | 2 +- src/CADShared/ExtensionMethod/Jig/JigEx.cs | 2 +- src/CADShared/ExtensionMethod/SelectionSetEx.cs | 2 +- src/CADShared/ExtensionMethod/SymbolTableRecordEx.cs | 2 +- src/CADShared/ExtensionMethod/XrefEx.cs | 2 +- src/CADShared/Initialize/AutoRegAssem.cs | 2 +- src/CADShared/Initialize/MethodInfoHelper.cs | 2 +- src/CADShared/Runtime/DBTrans.cs | 2 +- src/CADShared/Runtime/Env.cs | 2 +- src/CADShared/Runtime/SymbolTable.cs | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/CADShared/Algorithms/QuadTree/Rect.cs b/src/CADShared/Algorithms/QuadTree/Rect.cs index 1366442..2dba294 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 7fb7763..517cd14 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 e6f5660..505d5ee 100644 --- a/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs +++ b/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs @@ -1,5 +1,5 @@  -#if a2024 || zcad +#if !NET8_0_OR_GREATER namespace System.Runtime.CompilerServices; /// /// 指示参数将为另一个参数传递的表达式捕获为字符串。 diff --git a/src/CADShared/Basal/Win/WindowsAPI.cs b/src/CADShared/Basal/Win/WindowsAPI.cs index 5125d47..5b12ae2 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/Entity/BlockReferenceEx.cs b/src/CADShared/ExtensionMethod/Entity/BlockReferenceEx.cs index 39ad840..92b4032 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 14a5113..0df06cd 100644 --- a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs +++ b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs @@ -1,6 +1,6 @@ // ReSharper disable ForCanBeConvertedToForeach -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/Geomerty/PointEx.cs b/src/CADShared/ExtensionMethod/Geomerty/PointEx.cs index f920a3c..2a89e17 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 fe79a62..eb17ddd 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 f836615..b1d7576 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 c985110..d0a79c8 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 3d152fb..61c9f03 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/SymbolTableRecordEx.cs b/src/CADShared/ExtensionMethod/SymbolTableRecordEx.cs index 4aa3a5a..1c2c1ab 100644 --- a/src/CADShared/ExtensionMethod/SymbolTableRecordEx.cs +++ b/src/CADShared/ExtensionMethod/SymbolTableRecordEx.cs @@ -1,5 +1,5 @@  -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/ExtensionMethod/XrefEx.cs b/src/CADShared/ExtensionMethod/XrefEx.cs index 39f7889..3722c6f 100644 --- a/src/CADShared/ExtensionMethod/XrefEx.cs +++ b/src/CADShared/ExtensionMethod/XrefEx.cs @@ -1,6 +1,6 @@ // ReSharper disable ForCanBeConvertedToForeach -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/Initialize/AutoRegAssem.cs b/src/CADShared/Initialize/AutoRegAssem.cs index eeecf3c..8bd70dc 100644 --- a/src/CADShared/Initialize/AutoRegAssem.cs +++ b/src/CADShared/Initialize/AutoRegAssem.cs @@ -1,4 +1,4 @@ -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/Initialize/MethodInfoHelper.cs b/src/CADShared/Initialize/MethodInfoHelper.cs index 79bede7..b671885 100644 --- a/src/CADShared/Initialize/MethodInfoHelper.cs +++ b/src/CADShared/Initialize/MethodInfoHelper.cs @@ -1,4 +1,4 @@ -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/Runtime/DBTrans.cs b/src/CADShared/Runtime/DBTrans.cs index a1a4cb4..dd8766b 100644 --- a/src/CADShared/Runtime/DBTrans.cs +++ b/src/CADShared/Runtime/DBTrans.cs @@ -1,5 +1,5 @@ namespace IFoxCAD.Cad; -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif using System.Diagnostics; diff --git a/src/CADShared/Runtime/Env.cs b/src/CADShared/Runtime/Env.cs index 3f88e36..726a384 100644 --- a/src/CADShared/Runtime/Env.cs +++ b/src/CADShared/Runtime/Env.cs @@ -1,5 +1,5 @@ using System.Security; -#if a2024 || zcad +#if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif diff --git a/src/CADShared/Runtime/SymbolTable.cs b/src/CADShared/Runtime/SymbolTable.cs index ad73274..c6c9422 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 -- Gitee From d6871c881ea14fd7911cb57d079423826899179a Mon Sep 17 00:00:00 2001 From: vicwjb Date: Sun, 22 Dec 2024 00:39:30 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Melkman=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E6=B1=82=E7=AE=80=E5=8D=95=E5=A4=9A=E8=BE=B9=E5=BD=A2=E5=87=B8?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/Geomerty/GeometryEx.cs | 56 +++++++++++++++++++ tests/TestShared/TestConvexHull.cs | 16 ++++++ 2 files changed, 72 insertions(+) diff --git a/src/CADShared/ExtensionMethod/Geomerty/GeometryEx.cs b/src/CADShared/ExtensionMethod/Geomerty/GeometryEx.cs index 5672631..1f0af2d 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/tests/TestShared/TestConvexHull.cs b/tests/TestShared/TestConvexHull.cs index 03692ae..c7bbafb 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 -- Gitee From 04e2cfd5211a8a98b9b91ecdec0aaa47951453b6 Mon Sep 17 00:00:00 2001 From: vicwjb Date: Tue, 24 Dec 2024 16:37:39 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=A4=E7=82=B9?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E5=87=BD=E6=95=B0=E5=92=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95;=E5=88=A9=E7=94=A8PolySharp=E6=9B=BF=E6=8D=A2IndexRan?= =?UTF-8?q?ge=E5=92=8CNullable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CallerArgumentExpressionAttribute.cs | 5 +- .../ExtensionMethod/Entity/CurveEx.cs | 67 +++++++++++++++ src/CADShared/Runtime/Env.cs | 15 +++- src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj | 10 ++- src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj | 10 ++- tests/TestShared/TestCurve.cs | 82 +++++++++++++++++++ 6 files changed, 181 insertions(+), 8 deletions(-) diff --git a/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs b/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs index 505d5ee..35ca533 100644 --- a/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs +++ b/src/CADShared/Basal/Nullable/CallerArgumentExpressionAttribute.cs @@ -1,4 +1,6 @@ - +#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/ExtensionMethod/Entity/CurveEx.cs b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs index 0df06cd..7b796c6 100644 --- a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs +++ b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs @@ -6,6 +6,42 @@ namespace IFoxCAD.Cad; + +/// +/// 交点类型 +/// +public enum IntersectorType +{ + /// + /// 切点 + /// + Tangential, + /// + /// 交叉点 + /// + Transversal +} + + +/// +/// +/// +/// +/// +public record OverlapInformation(Interval[] OverlapRanges, bool OverlapDirection); + + +/// +/// +/// +/// +/// +/// +public record IntersectorInformation( + PointOnCurve3d PointOnCurve, + IntersectorType IntersectorType, + OverlapInformation? OverlapInformation); + /// /// 实体类曲线扩展类 /// @@ -35,6 +71,37 @@ public static IEnumerable GetSplitCurves(this Curve curve, IEnumerable(); }*/ + + + + + /// + /// 获取两个曲线的z平面的交点坐标 + /// + /// 第一条曲线 + /// 第二条曲线 + /// 容差 + /// 交点列表 + public static IEnumerable GetIntersectorPoints(this Curve curve, Curve endCurve, Tolerance? tolerance = null) + { + var points = new List(); + var cur1 = curve.GetGeCurve(); + var cur2 = endCurve.GetGeCurve(); + tolerance ??= new Tolerance(0.001,0.001); + var cci3d = new CurveCurveIntersector3d(cur1, cur2, Vector3d.ZAxis, tolerance.Value); + for (var i = 0; i < cci3d.NumberOfIntersectionPoints; i++) + { + points.Add(cci3d.GetIntersectionPoint(i)); + } + return points; + } + + + + + + + /// /// 获取分割曲线集合 /// diff --git a/src/CADShared/Runtime/Env.cs b/src/CADShared/Runtime/Env.cs index 726a384..6d3d704 100644 --- a/src/CADShared/Runtime/Env.cs +++ b/src/CADShared/Runtime/Env.cs @@ -679,8 +679,21 @@ public static void RemoveTrustedPath(params string[] folders) /// 要打印的对象 public static T Print(this T obj) { + string? str; // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract - Document?.Editor.WriteMessage(obj is null ? "null\n" : $"{obj}\n"); + if (obj is IEnumerable lst) + { + str = string.Join(",", lst); + } + else if (obj is Array strObj) + { + str = string.Join(",", strObj.Cast()); + } + else + { + str = obj?.ToString(); + } + Document?.Editor.WriteMessage(obj is null ? "null\n" : $"{str}\n"); return obj; } diff --git a/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj b/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj index bdc6670..388b694 100644 --- a/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj +++ b/src/IFoxCAD.AutoCad/IFoxCAD.AutoCad.csproj @@ -45,10 +45,14 @@ - - + + + + + + all - runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers diff --git a/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj b/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj index ab5ac5b..2bb2e11 100644 --- a/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj +++ b/src/IFoxCAD.ZwCad/IFoxCAD.ZwCad.csproj @@ -37,10 +37,14 @@ - - + + + + + + all - runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers diff --git a/tests/TestShared/TestCurve.cs b/tests/TestShared/TestCurve.cs index fd75698..319761e 100644 --- a/tests/TestShared/TestCurve.cs +++ b/tests/TestShared/TestCurve.cs @@ -273,6 +273,88 @@ 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!.GetIntersectorPoints(ent2curve!, tol); + 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); + // + 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("输出GetOverlapRanges:"); + // cci3d.GetOverlapRanges(i).Print(); + // + Env.Printl("输出OverlapCount:"); + cci3d.OverlapCount().Print(); + // + // Env.Printl("输出OverlapDirection:"); + // cci3d.OverlapDirection().Print(); + // + // Env.Printl("输出IsTangential:"); + // cci3d.IsTangential(i).Print(); + // + // Env.Printl("输出IsTransversal:"); + // cci3d.IsTransversal(i).Print(); + + + + + } + + + + + } + [CommandMethod(nameof(Test_CurveCurveIntersector3d))] public void Test_CurveCurveIntersector3d() { -- Gitee From 476fee48143266eeef4a127be645c28565538542 Mon Sep 17 00:00:00 2001 From: vicwjb Date: Wed, 25 Dec 2024 16:46:02 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B1=82=E4=BA=A4?= =?UTF-8?q?=E7=82=B9=E4=BF=A1=E6=81=AF=E5=87=BD=E6=95=B0=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96print=E5=87=BD=E6=95=B0=E5=8F=AF=E4=BB=A5=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E9=9B=86=E5=90=88=E7=9A=84=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/Entity/CurveEx.cs | 55 +++++++++-- src/CADShared/Runtime/Env.cs | 94 +++++++++++++++---- src/IFoxCAD.AutoCad/GlobalUsings.cs | 2 +- src/IFoxCAD.ZwCad/GlobalUsings.cs | 2 +- tests/TestShared/TestCurve.cs | 92 ++++++++++++++---- 5 files changed, 201 insertions(+), 44 deletions(-) diff --git a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs index 7b796c6..092fc6b 100644 --- a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs +++ b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs @@ -10,7 +10,7 @@ namespace IFoxCAD.Cad; /// /// 交点类型 /// -public enum IntersectorType +public enum IntersectionType { /// /// 切点 @@ -35,12 +35,14 @@ public record OverlapInformation(Interval[] OverlapRanges, bool OverlapDirection /// /// /// -/// +/// +/// /// -public record IntersectorInformation( +public record IntersectionInformation( PointOnCurve3d PointOnCurve, - IntersectorType IntersectorType, - OverlapInformation? OverlapInformation); + IntersectionType IntersectionType, + int OverlapCount, + OverlapInformation[] OverlapInformation); /// /// 实体类曲线扩展类 @@ -82,7 +84,7 @@ public static IEnumerable GetSplitCurves(this Curve curve, IEnumerable第二条曲线 /// 容差 /// 交点列表 - public static IEnumerable GetIntersectorPoints(this Curve curve, Curve endCurve, Tolerance? tolerance = null) + public static IEnumerable GetIntersectionPoints(this Curve curve, Curve endCurve, Tolerance? tolerance = null) { var points = new List(); var cur1 = curve.GetGeCurve(); @@ -96,8 +98,45 @@ public static IEnumerable GetIntersectorPoints(this Curve curve, Curve 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/Runtime/Env.cs b/src/CADShared/Runtime/Env.cs index 6d3d704..69f4cfb 100644 --- a/src/CADShared/Runtime/Env.cs +++ b/src/CADShared/Runtime/Env.cs @@ -1,4 +1,3 @@ -using System.Security; #if !NET8_0_OR_GREATER using ArgumentNullException = IFoxCAD.Basal.ArgumentNullEx; #endif @@ -679,21 +678,8 @@ public static void RemoveTrustedPath(params string[] folders) /// 要打印的对象 public static T Print(this T obj) { - string? str; - // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract - if (obj is IEnumerable lst) - { - str = string.Join(",", lst); - } - else if (obj is Array strObj) - { - str = string.Join(",", strObj.Cast()); - } - else - { - str = obj?.ToString(); - } - Document?.Editor.WriteMessage(obj is null ? "null\n" : $"{str}\n"); + var str = DataFormatter.FormatObject(obj); + Document.Editor.WriteMessage(obj is null ? "null\n" : $"{str}\n"); return obj; } @@ -703,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"); } /// @@ -897,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/IFoxCAD.AutoCad/GlobalUsings.cs b/src/IFoxCAD.AutoCad/GlobalUsings.cs index 67dcfff..ea59926 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.ZwCad/GlobalUsings.cs b/src/IFoxCAD.ZwCad/GlobalUsings.cs index a3365f5..b428d55 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/tests/TestShared/TestCurve.cs b/tests/TestShared/TestCurve.cs index 319761e..38b9a0f 100644 --- a/tests/TestShared/TestCurve.cs +++ b/tests/TestShared/TestCurve.cs @@ -291,7 +291,7 @@ public static void Test_CurveIntersector() j /= 10; Tolerance tol = new(j, j); Env.Printl($"精度为 {j}"); - var pts = ent1curve!.GetIntersectorPoints(ent2curve!, tol); + var pts = ent1curve!.GetIntersectionPoints(ent2curve!, tol); foreach (var point3d in pts) { point3d.Print(); @@ -319,6 +319,25 @@ public static void Test_CurveIntersectorInfo() // 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:"); @@ -329,21 +348,16 @@ public static void Test_CurveIntersectorInfo() // Env.Printl("输出GetIntersectionRanges:"); cci3d.GetIntersectionRanges().Print(); - // - // Env.Printl("输出GetOverlapRanges:"); - // cci3d.GetOverlapRanges(i).Print(); - // - Env.Printl("输出OverlapCount:"); - cci3d.OverlapCount().Print(); - // - // Env.Printl("输出OverlapDirection:"); - // cci3d.OverlapDirection().Print(); - // - // Env.Printl("输出IsTangential:"); - // cci3d.IsTangential(i).Print(); - // - // Env.Printl("输出IsTransversal:"); - // cci3d.IsTransversal(i).Print(); + + + + + + Env.Printl("输出IsTangential:"); + cci3d.IsTangential(i).Print(); + + Env.Printl("输出IsTransversal:"); + cci3d.IsTransversal(i).Print(); @@ -355,6 +369,52 @@ public static void Test_CurveIntersectorInfo() } + [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!); + inters.Print(); + + 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() { -- Gitee From 30470bb3e577068bb51c3dba5266b0d89b2785ab Mon Sep 17 00:00:00 2001 From: vicwjb Date: Thu, 26 Dec 2024 15:56:53 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=A4=E7=82=B9?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E5=B9=B3=E9=9D=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/Entity/CurveEx.cs | 18 ++++++++++-------- tests/TestShared/TestCurve.cs | 3 +-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs index 092fc6b..cb67f29 100644 --- a/src/CADShared/ExtensionMethod/Entity/CurveEx.cs +++ b/src/CADShared/ExtensionMethod/Entity/CurveEx.cs @@ -82,15 +82,17 @@ public static IEnumerable GetSplitCurves(this Curve curve, IEnumerable /// 第一条曲线 /// 第二条曲线 + /// 交点平面 /// 容差 /// 交点列表 - public static IEnumerable GetIntersectionPoints(this Curve curve, Curve endCurve, Tolerance? tolerance = null) + 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); - var cci3d = new CurveCurveIntersector3d(cur1, cur2, Vector3d.ZAxis, tolerance.Value); + 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)); @@ -99,13 +101,13 @@ public static IEnumerable GetIntersectionPoints(this Curve curve, Curve } /// - /// + /// 获取交点信息 /// - /// - /// - /// - /// - /// + /// 第一条曲线 + /// 第二条曲线 + /// 交点平面 + /// 容差 + /// 交点信息集合 public static IEnumerable GetIntersectionInformation(this Curve curve, Curve endCurve, Vector3d? normal = null, Tolerance? tolerance = null) diff --git a/tests/TestShared/TestCurve.cs b/tests/TestShared/TestCurve.cs index 38b9a0f..2f8444e 100644 --- a/tests/TestShared/TestCurve.cs +++ b/tests/TestShared/TestCurve.cs @@ -291,7 +291,7 @@ public static void Test_CurveIntersector() j /= 10; Tolerance tol = new(j, j); Env.Printl($"精度为 {j}"); - var pts = ent1curve!.GetIntersectionPoints(ent2curve!, tol); + var pts = ent1curve!.GetIntersectionPoints(ent2curve!); foreach (var point3d in pts) { point3d.Print(); @@ -383,7 +383,6 @@ public static void Test_CurveInters() var ent2curve = ent2.ObjectId.GetObject(); Env.Printl("开始:"); var inters = ent1curve!.GetIntersectionInformation(ent2curve!); - inters.Print(); foreach (var intersectionInformation in inters) { -- Gitee