diff --git a/tests/TestAcad2025/GlobalUsings.cs b/tests/TestAcad2025/GlobalUsings.cs index 045196f703ea51e14af47638509ed97287167b95..3d6e42a63594990c5db5a2dd8264cf9afde4401f 100644 --- a/tests/TestAcad2025/GlobalUsings.cs +++ b/tests/TestAcad2025/GlobalUsings.cs @@ -1,4 +1,4 @@ -/// 系统引用 +// 系统引用 global using System; global using System.Collections; global using System.Collections.Generic; @@ -17,7 +17,7 @@ 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; @@ -43,8 +43,8 @@ global using Cad_ErrorStatus = Autodesk.AutoCAD.Runtime.ErrorStatus; -/// ifoxcad +// ifoxcad global using IFoxCAD.Cad; global using IFoxCAD.Basal; -global using Test; +global using IFoxTest; diff --git a/tests/TestGcad2025/GlobalUsings.cs b/tests/TestGcad2025/GlobalUsings.cs index ba5075dbad4d0174cb7eb53620c6316d8d11ba1a..047cbc9e131bc33e89b4e059795af6fbaa73737f 100644 --- a/tests/TestGcad2025/GlobalUsings.cs +++ b/tests/TestGcad2025/GlobalUsings.cs @@ -1,4 +1,4 @@ -/// 系统引用 +// 系统引用 global using System; global using System.Collections; global using System.Collections.Generic; @@ -42,8 +42,8 @@ global using Cad_ErrorStatus = Gssoft.Gscad.Runtime.ErrorStatus; -/// ifoxcad +// ifoxcad global using IFoxCAD.Cad; global using IFoxCAD.Basal; -global using Test; \ No newline at end of file +global using IFoxTest; \ No newline at end of file diff --git a/tests/TestShared/TestAddEntity.cs b/tests/TestShared/TestAddEntity.cs index 123ba77b7c46ef0d7960697ec7a8d38925a32628..34a665ec2880a31ab5e8d03d5b7b6a00dec17410 100644 --- a/tests/TestShared/TestAddEntity.cs +++ b/tests/TestShared/TestAddEntity.cs @@ -1,19 +1,7 @@ -namespace Test; +namespace IFoxTest; public partial class Test { - - - - - - - - - - - - [CommandMethod(nameof(Test_Rec))] public void Test_Rec() { @@ -29,46 +17,57 @@ public void Test_Rec() var p13 = p3 - p1; var p24 = p4 - p2; - const double pi90 = Math.PI / 2; pi90.Print(); - Tools.TestTimes(1000000, "对角线", () => { - var result = false; - if (Math.Abs(p13.Length - p24.Length) <= 1e8) + Tools.TestTimes( + 1000000, + "对角线", + () => { - result = p41.IsParallelTo(p12); + var result = false; + if (Math.Abs(p13.Length - p24.Length) <= 1e8) + { + result = p41.IsParallelTo(p12); + } } - }); + ); #pragma warning disable CS0219 // 变量已被赋值,但从未使用过它的值 - Tools.TestTimes(1000000, "三次点乘", () => { - bool result = Math.Abs(p12.DotProduct(p23)) < 1e8 && - Math.Abs(p23.DotProduct(p34)) < 1e8 && - Math.Abs(p34.DotProduct(p41)) < 1e8; - }); + Tools.TestTimes( + 1000000, + "三次点乘", + () => + { + bool result = + Math.Abs(p12.DotProduct(p23)) < 1e8 + && Math.Abs(p23.DotProduct(p34)) < 1e8 + && Math.Abs(p34.DotProduct(p41)) < 1e8; + } + ); - Tools.TestTimes(1000000, "三次垂直", () => { - bool result = p12.IsParallelTo(p23) && - p23.IsParallelTo(p34) && - p34.IsParallelTo(p41); - }); + Tools.TestTimes( + 1000000, + "三次垂直", + () => + { + bool result = + p12.IsParallelTo(p23) && p23.IsParallelTo(p34) && p34.IsParallelTo(p41); + } + ); #pragma warning restore CS0219 // 变量已被赋值,但从未使用过它的值 } - - - [CommandMethod(nameof(Test_EntRoration))] public void Test_EntRoration() { - var line = new Line(new(0, 0, 0), new(100, 0, 0)); + var line = new Line(new Point3d(0, 0, 0), new Point3d(100, 0, 0)); using DBTrans tr = new(); tr.CurrentSpace.AddEntity(line); var line2 = (Line)line.Clone(); tr.CurrentSpace.AddEntity(line2); - line2.Rotation(new(100, 0, 0), Math.PI / 2); + line2.Rotation(new Point3d(100, 0, 0), Math.PI / 2); } [CommandMethod(nameof(Test_TypeSpeed))] @@ -76,34 +75,45 @@ public void Test_TypeSpeed() { var line = new Line(); var line1 = line as Entity; - Tools.TestTimes(100000, "is 匹配:", () => { - var t = line1 is Line; - }); - Tools.TestTimes(100000, "name 匹配:", () => { - // var t = line.GetType().Name; - var tt = line1.GetType().Name == nameof(Line); - }); - Tools.TestTimes(100000, "dxfname 匹配:", () => { - // var t = line.GetType().Name; - var tt = line1.GetRXClass().DxfName == nameof(Line); - }); + Tools.TestTimes( + 100000, + "is 匹配:", + () => + { + var t = line1 is Line; + } + ); + Tools.TestTimes( + 100000, + "name 匹配:", + () => + { + // var t = line.GetType().Name; + var tt = line1.GetType().Name == nameof(Line); + } + ); + Tools.TestTimes( + 100000, + "dxfname 匹配:", + () => + { + // var t = line.GetType().Name; + var tt = line1.GetRXClass().DxfName == nameof(Line); + } + ); } - [CommandMethod(nameof(Test_sleeptrans))] - public static void Test_sleeptrans() + [CommandMethod(nameof(Test_SleepTrans))] + public static void Test_SleepTrans() { using var tr = new DBTrans(); for (int i = 0; i < 100; i++) { var cir = CircleEx.CreateCircle(new Point3d(i, i, 0), 0.5); - if (cir is null) - { - return; - } cir.ColorIndex = i; tr.CurrentSpace.AddEntity(cir); tr.Editor?.Redraw(cir); - System.Threading.Thread.Sleep(10); + Thread.Sleep(10); } } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestBlkVisibility.cs b/tests/TestShared/TestBlkVisibility.cs index 68772fee51465b877c01bd5a9d074efa283a0344..4ea69d483a62b1dbfcf9056b5900aa2ebfc19f07 100644 --- a/tests/TestShared/TestBlkVisibility.cs +++ b/tests/TestShared/TestBlkVisibility.cs @@ -4,8 +4,8 @@ namespace TestAcad2025; public static class TestBlkVisibility { - [CommandMethod(nameof(TestBlkVisibility))] - public static void Main() + [CommandMethod(nameof(Test_BlkVisibility))] + public static void Test_BlkVisibility() { var r1 = Env.Editor.GetEntity("\n选择块参照"); if (r1.Status != PromptStatus.OK) @@ -15,6 +15,7 @@ public static void Main() return; var info = brf.GetVisibilityInfo(); MessageBox.Show( - $"块{brf.Name}的可见性名字:{info.PropertyName},参数:{string.Join(", ", info.AllowedValues)}。是否可见?{info.Has}"); + $"块{brf.Name}的可见性名字:{info.PropertyName},参数:{string.Join(", ", info.AllowedValues)}。是否可见?{info.Has}" + ); } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestBlock.cs b/tests/TestShared/TestBlock.cs index 918dca2d7ae0c19fc18c9111adc921e13aec0b2f..c523896889b2ee7aef88c3345a5ea83275765216 100644 --- a/tests/TestShared/TestBlock.cs +++ b/tests/TestShared/TestBlock.cs @@ -1,5 +1,4 @@ - -namespace Test; +namespace IFoxTest; public class TestBlock { @@ -18,8 +17,8 @@ public void Test_Refedit() } // 0x01 非在位编辑状态: 先选择块参照,然后在位编辑 // 0x02 在位编辑状态: 关闭并保存 - if (Env.GetVar("RefEditName").ToString() == "")//显示正在编辑的参照名称 - Env.Editor.RunLisp("(command \"_.refedit\")");//直接点选可以有嵌套层次 + if (Env.GetVar("RefEditName").ToString() == "") //显示正在编辑的参照名称 + Env.Editor.RunLisp("(command \"_.refedit\")"); //直接点选可以有嵌套层次 else Env.Editor.RunLisp("(command \"_.refclose\" \"s\")"); } @@ -34,7 +33,7 @@ public void Test_GetBoundingBoxEx() foreach (var item in ents) { var box = item?.GetBoundingBoxEx(); - Env.Print("min:" + box?.BottomLeft + ";max" + box?.TopRight); + ("min:" + box?.BottomLeft + ";max" + box?.TopRight).Print(); if (box != null) tr.CurrentSpace.AddEntity(new Line(box.Value.BottomLeft, box.Value.TopRight)); } @@ -46,7 +45,8 @@ 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", + tr.BlockTable.Add( + "test", btr => { btr.Origin = new Point3d(0, 0, 0); @@ -55,24 +55,36 @@ public void Test_BlockDef() 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 }; + 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 }; } ); // 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 }; - }); + 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 }; + } + ); } // 后台块定义 @@ -81,7 +93,8 @@ 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", + tr.BlockTable.Add( + "test", btr => { btr.Origin = new Point3d(0, 0, 0); @@ -92,30 +105,40 @@ public void Test_BlockDefbehind() }, () => // 属性定义 { - 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 }; + 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 }; } ); // 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); + 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 new List { line, acText }; + } + ); tr.Database.SaveDwgFile(); } - - // 修改块定义 [CommandMethod(nameof(Test_BlockDefChange))] public void Test_BlockDefChange() @@ -132,27 +155,29 @@ public void Test_BlockDefChange() // }); - - tr.BlockTable.Change("test", btr => - { - foreach (var id in btr) + tr.BlockTable.Change( + "test", + btr => { - var ent = tr.GetObject(id); - using (ent!.ForWrite()) + foreach (var id in btr) { - switch (ent) + var ent = tr.GetObject(id); + using (ent!.ForWrite()) { - case Dimension dBText: - dBText.DimensionText = "234"; - dBText.RecomputeDimensionBlock(true); - break; - case Hatch hatch: - hatch.ColorIndex = 0; - break; + switch (ent) + { + case Dimension dBText: + dBText.DimensionText = "234"; + dBText.RecomputeDimensionBlock(true); + break; + case Hatch hatch: + hatch.ColorIndex = 0; + break; + } } } } - }); + ); tr.Editor?.Regen(); } @@ -162,11 +187,22 @@ public void Test_InsertBlockDef() using DBTrans tr = new(); var line1 = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); var line2 = new Line(new Point3d(0, 0, 0), new Point3d(-1, 1, 0)); - var att1 = new AttributeDefinition() { Position = new Point3d(10, 10, 0), Tag = "tagTest1", Height = 1, TextString = "valueTest1" }; - var att2 = new AttributeDefinition() { Position = new Point3d(10, 12, 0), Tag = "tagTest2", Height = 1, TextString = "valueTest2" }; + var att1 = new AttributeDefinition() + { + Position = new Point3d(10, 10, 0), + Tag = "tagTest1", + Height = 1, + TextString = "valueTest1", + }; + var att2 = new AttributeDefinition() + { + Position = new Point3d(10, 12, 0), + Tag = "tagTest2", + Height = 1, + TextString = "valueTest2", + }; tr.BlockTable.Add("test1", line1, line2, att1, att2); - List ents = []; var line5 = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); var line6 = new Line(new Point3d(0, 0, 0), new Point3d(-1, 1, 0)); @@ -174,29 +210,36 @@ public void Test_InsertBlockDef() ents.Add(line6); tr.BlockTable.Add("test44", ents); - var line3 = new Line(new Point3d(5, 5, 0), new Point3d(6, 6, 0)); 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 }); + 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.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"); // 测试插入不存在的块定义 // tr.CurrentSpace.InsertBlock(new Point3d(0, 0, 0), "test1", new Scale3d(2)); // 测试放大2倍 // tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test1", new Scale3d(2), Math.PI / 4); // 测试放大2倍,旋转45度 - var def1 = new Dictionary - { - { "tagTest1", "1" }, - { "tagTest2", "2" } - }; + var def1 = new Dictionary { { "tagTest1", "1" }, { "tagTest2", "2" } }; tr.CurrentSpace.InsertBlock(new Point3d(0, 0, 0), "test1", atts: def1); - var def2 = new Dictionary - { - { "tagTest3", "1" }, - { "tagTest4", "" } - }; + var def2 = new Dictionary { { "tagTest3", "1" }, { "tagTest4", "" } }; tr.CurrentSpace.InsertBlock(new Point3d(10, 10, 0), "test2", atts: def2); tr.CurrentSpace.InsertBlock(new Point3d(20, 20, 0), "test2"); tr.CurrentSpace.InsertBlock(new Point3d(-10, 0, 0), "test44"); @@ -205,28 +248,34 @@ public void Test_InsertBlockDef() [CommandMethod(nameof(Test_InsertBlockWithDoubleDatabase))] public void Test_InsertBlockWithDoubleDatabase() { - using var tr = new DBTrans(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.dwg")); + using var tr = new DBTrans( + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.dwg") + ); using var trans = new DBTrans(); - tr.BlockTable.Add("test456", + tr.BlockTable.Add( + "test456", btr => { - btr.Origin = new(0, 0, 0); + btr.Origin = new Point3d(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); + var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + var actext = DBTextEx.CreateDBText( + Point3d.Origin, + "123", + 2.5, + database: tr.Database + ); return new List { line, actext }; - - }); + } + ); tr.CurrentSpace.InsertBlock(Point3d.Origin, "test456"); tr.Database.SaveDwgFile(); } - - [CommandMethod(nameof(Test_AddAttsDef))] public void Test_AddAttsDef() { @@ -235,9 +284,21 @@ public void Test_AddAttsDef() var btf = tr.GetObject(blockid); if (btf is null) return; - var att1 = new AttributeDefinition() { Position = new Point3d(20, 20, 0), Tag = "addtagTest1", Height = 1, TextString = "valueTest1" }; - var att2 = new AttributeDefinition() { Position = new Point3d(10, 12, 0), Tag = "tagTest2", Height = 1, TextString = "valueTest2" }; - tr.BlockTable.AddAttsToBlocks(btf.BlockTableRecord, new() { att1, att2 }); + var att1 = new AttributeDefinition() + { + Position = new Point3d(20, 20, 0), + Tag = "addtagTest1", + Height = 1, + TextString = "valueTest1", + }; + var att2 = new AttributeDefinition() + { + Position = new Point3d(10, 12, 0), + Tag = "tagTest2", + Height = 1, + TextString = "valueTest2", + }; + tr.BlockTable.AddAttsToBlocks(btf.BlockTableRecord, new List { att1, att2 }); } [CommandMethod(nameof(Test_BlockNullBug))] @@ -265,11 +326,11 @@ public void Test_BlockFile() [CommandMethod(nameof(Test_BlockFiledxf))] public void Test_BlockFiledxf() { - string [] files; - var folder= new System.Windows.Forms.FolderBrowserDialog(); + string[] files; + var folder = new System.Windows.Forms.FolderBrowserDialog(); if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK) { - files = Directory.GetFiles(folder.SelectedPath,"*.dxf",SearchOption.AllDirectories); + files = Directory.GetFiles(folder.SelectedPath, "*.dxf", SearchOption.AllDirectories); using DBTrans tr = new(); foreach (var item in files) { @@ -280,66 +341,71 @@ public void Test_BlockFiledxf() tr.CurrentSpace.InsertBlock(pt.Value, id); Env.Editor.Redraw(); } - } - } - - } - + [CommandMethod("Test_CreateMTextAttributeBlock")] public void Test_CreateMTextAttributeBlock() { - using var tr = new DBTrans(); - tr.BlockTable.Add("MTextAttributeBlock",btr => - { - btr.Origin = Point3d.Origin; - // 创建一个多行文字作为块的一部分 - var mtext = new MText(); - mtext.Contents = "默认多行文字内容\n第二行内容\n第三行内容"; - mtext.Location = new Point3d(0, 0, 0); - mtext.Width = 200; // 多行文字宽度 - mtext.Height = 2.5; // 文字高度 - btr.AddEntity(mtext); - - - // 创建属性定义 - var attrDef = new AttributeDefinition(); - attrDef.Position = new Point3d(0, -50, 0); // 位置在多行文字下方 - attrDef.Prompt = "请输入属性值"; - attrDef.Tag = "ATTR_TAG"; - attrDef.TextString = "默认属性值"; - attrDef.Height = 2.5; - attrDef.Justify = AttachmentPoint.MiddleCenter; // 居中对齐 - - // 设置为多行属性 - attrDef.SetMTextAttribute(att => att.Width = 100); - btr.AddEntity(attrDef); - }); + tr.BlockTable.Add( + "MTextAttributeBlock", + btr => + { + btr.Origin = Point3d.Origin; + // 创建一个多行文字作为块的一部分 + var mtext = new MText(); + mtext.Contents = "默认多行文字内容\n第二行内容\n第三行内容"; + mtext.Location = new Point3d(0, 0, 0); + mtext.Width = 200; // 多行文字宽度 + mtext.Height = 2.5; // 文字高度 + btr.AddEntity(mtext); + + // 创建属性定义 + var attrDef = new AttributeDefinition(); + attrDef.Position = new Point3d(0, -50, 0); // 位置在多行文字下方 + attrDef.Prompt = "请输入属性值"; + attrDef.Tag = "ATTR_TAG"; + attrDef.TextString = "默认属性值"; + attrDef.Height = 2.5; + attrDef.Justify = AttachmentPoint.MiddleCenter; // 居中对齐 + + // 设置为多行属性 + attrDef.SetMTextAttribute(att => att.Width = 100); + btr.AddEntity(attrDef); + } + ); tr.CurrentSpace.InsertBlock(Point3d.Origin, "MTextAttributeBlock"); - - } - [CommandMethod(nameof(Test_ClipBlock))] public void Test_ClipBlock() { using DBTrans tr = new(); - tr.BlockTable.Add("test1", btr => - { - btr.Origin = new Point3d(0, 0, 0); - btr.AddEntity(new Line(new Point3d(0, 0, 0), new Point3d(10, 10, 0)), - new Line(new Point3d(10, 10, 0), new Point3d(10, 0, 0))); - }); + tr.BlockTable.Add( + "test1", + btr => + { + btr.Origin = new Point3d(0, 0, 0); + btr.AddEntity( + new Line(new Point3d(0, 0, 0), new Point3d(10, 10, 0)), + new Line(new Point3d(10, 10, 0), new Point3d(10, 0, 0)) + ); + } + ); // tr.BlockTable.Add("hah"); var id = tr.CurrentSpace.InsertBlock(new Point3d(0, 0, 0), "test1"); var brf1 = tr.GetObject(id)!; - var pts = new List { new Point3d(3, 3, 0), new Point3d(7, 3, 0), new Point3d(7, 7, 0), new Point3d(3, 7, 0) }; + var pts = new List + { + new Point3d(3, 3, 0), + new Point3d(7, 3, 0), + new Point3d(7, 7, 0), + new Point3d(3, 7, 0), + }; brf1.XClip(pts); var id1 = tr.CurrentSpace.InsertBlock(new Point3d(20, 20, 0), "test1"); @@ -347,22 +413,25 @@ public void Test_ClipBlock() brf2?.XClip(new Point3d(13, 13, 0), new Point3d(17, 17, 0)); } - [CommandMethod(nameof(Test_ClipBlock1))] public void Test_ClipBlock1() { using DBTrans tr = new(); var ent = Env.Editor.GetEntity("pick block"); - if (ent.Status != PromptStatus.OK) return; + if (ent.Status != PromptStatus.OK) + return; var brf1 = tr.GetObject(ent.ObjectId)!; - var pts = new List { new Point3d(3, 3, 0), new Point3d(7, 3, 0), new Point3d(7, 7, 0), new Point3d(3, 7, 0) }; + var pts = new List + { + new Point3d(3, 3, 0), + new Point3d(7, 3, 0), + new Point3d(7, 7, 0), + new Point3d(3, 7, 0), + }; brf1.XClip(pts); - } - - // 给用户的测试程序,不知道对错 [CommandMethod(nameof(Test_Block_ej))] public void Test_Block_ej() @@ -386,13 +455,16 @@ public void Test_Block_ej() string fullFileName = @"C:\Users\vic\Desktop\001.dwg"; var blockdef = tr.BlockTable.GetBlockFrom(fullFileName, false); - tr.Database.Clayer = tr.LayerTable["0"];// 当前图层切换为0图层 - tr.LayerTable.Change(tr.Database.Clayer, ltr => - { - ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 2); // ColorMethod.ByAci可以让我们使用AutoCAD ACI颜色索引……这里为2(表示黄色) - }); + tr.Database.Clayer = tr.LayerTable["0"]; // 当前图层切换为0图层 + tr.LayerTable.Change( + tr.Database.Clayer, + ltr => + { + ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 2); // ColorMethod.ByAci可以让我们使用AutoCAD ACI颜色索引……这里为2(表示黄色) + } + ); - var id = tr.ModelSpace.InsertBlock(Point3d.Origin, blockdef);// 插入块参照 + var id = tr.ModelSpace.InsertBlock(Point3d.Origin, blockdef); // 插入块参照 var brf = tr.GetObject(id); brf?.Draw(); } @@ -413,45 +485,48 @@ public void Test_Block_ej() var btr = tr2.BlockTable[brf2.Name]; - tr2.BlockTable.Change(btr, ltr => - { - foreach (ObjectId oid in ltr) + tr2.BlockTable.Change( + btr, + ltr => { - var ent = tr2.GetObject(oid); - if (ent is MText mText) + foreach (ObjectId oid in ltr) { - using (ent.ForWrite()) - switch (mText.Text) - { - case "$$A": - mText.Contents = "hahaha"; - break; - case "$$B": - break; - default: - break; - } - } - else if (ent is DBText dBText) - { - using (ent.ForWrite()) - dBText.TextString = "haha"; - } - else if (ent is Dimension dimension) - { - using (ent.ForWrite()) - switch (dimension.DimensionText) - { - case "$$pipeLen": - dimension.DimensionText = "350"; - dimension.RecomputeDimensionBlock(true); - break; - default: - break; - } + var ent = tr2.GetObject(oid); + if (ent is MText mText) + { + using (ent.ForWrite()) + switch (mText.Text) + { + case "$$A": + mText.Contents = "hahaha"; + break; + case "$$B": + break; + default: + break; + } + } + else if (ent is DBText dBText) + { + using (ent.ForWrite()) + dBText.TextString = "haha"; + } + else if (ent is Dimension dimension) + { + using (ent.ForWrite()) + switch (dimension.DimensionText) + { + case "$$pipeLen": + dimension.DimensionText = "350"; + dimension.RecomputeDimensionBlock(true); + break; + default: + break; + } + } } } - }); + ); tr2.Editor?.Regen(); } @@ -459,10 +534,10 @@ public void Test_Block_ej() public void Test_QuickBlockDef2() { // Database db = HostApplicationServices.WorkingDatabase; - Editor ed = Acap.DocumentManager.MdiActiveDocument.Editor; + Editor ed = Acaop.DocumentManager.MdiActiveDocument.Editor; PromptSelectionOptions promptOpt = new() { - MessageForAdding = "请选择需要快速制作块的对象" + MessageForAdding = "请选择需要快速制作块的对象", }; string blockName = "W_BLOCK_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"); // var rss = ed.GetSelection(promptOpt); @@ -512,8 +587,7 @@ public void Test_QuickBlockDef2() // Acap.ShowAlertDialog(Environment.NewLine + "块名重复,程序退出!"); // return; // } - ents.ForEach(ent => - ent?.ForWrite(e => e?.TransformBy(matrix))); + ents.ForEach(ent => ent?.ForWrite(e => e?.TransformBy(matrix))); // var newents = ents.Select(ent => // { // var maping = new IdMapping(); @@ -544,14 +618,14 @@ public void Test_QuickBlockDef2() [CommandMethod(nameof(Test_QuickBlockDef1))] public void Test_QuickBlockDef1() { - var dm = Acap.DocumentManager; + var dm = Acaop.DocumentManager; var doc = dm.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; PromptSelectionOptions promptOpt = new() { - MessageForAdding = "请选择需要快速制作块的对象" + MessageForAdding = "请选择需要快速制作块的对象", }; string blockName = "W_BLOCK_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"); var rss = Env.Editor.GetSelection(promptOpt); @@ -561,10 +635,7 @@ public void Test_QuickBlockDef1() using var tr = db.TransactionManager.StartTransaction(); var ids = rss.Value.GetObjectIds(); var bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; - var btr = new BlockTableRecord - { - Name = blockName - }; + var btr = new BlockTableRecord { Name = blockName }; foreach (var item in ids) { var ent = tr.GetObject(item, OpenMode.ForRead) as Entity; @@ -582,10 +653,7 @@ public void Test_QuickBlockDef1() // { // var bt = tr1.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; var btr1 = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; - var brf = new BlockReference(Point3d.Origin, bt[blockName]) - { - ScaleFactors = default - }; + var brf = new BlockReference(Point3d.Origin, bt[blockName]) { ScaleFactors = default }; btr1!.AppendEntity(brf); tr.AddNewlyCreatedDBObject(brf, true); btr1.DowngradeOpen(); @@ -597,35 +665,28 @@ public void Test_QuickBlockDef1() void Wblock() { var curdb = HostApplicationServices.WorkingDatabase; - PromptSelectionOptions opts = new() - { - MessageForAdding = "选择对象" - }; + PromptSelectionOptions opts = new() { MessageForAdding = "选择对象" }; var ss = Env.Editor.GetSelection(opts).Value; using ObjectIdCollection ids = new(ss.GetObjectIds()); var db = curdb.Wblock(ids, Point3d.Origin); db.SaveAs(@"c:\test.dwg", DwgVersion.Current); } + [CommandMethod(nameof(ChangeDynameicBlock))] public void ChangeDynameicBlock() { - var pro = new Dictionary - { - { "haha", 1 } - }; + var pro = new Dictionary { { "haha", 1 } }; var blockid = Env.Editor.GetEntity("选择个块").ObjectId; using DBTrans tr = new(); var brf = tr.GetObject(blockid)!; brf.ChangeBlockProperty(pro); // 这是第一个函数的用法 } + [CommandMethod(nameof(ChangeBlockProperty))] public void ChangeBlockProperty() { - Dictionary? pro = new() - { - { "haha", "1" } - }; + Dictionary? pro = new() { { "haha", "1" } }; var blockid = Env.Editor.GetEntity("选择个块").ObjectId; using DBTrans tr = new(); var brf = tr.GetObject(blockid)!; @@ -645,16 +706,18 @@ public void Test_Back() } using DBTrans tr = new(dwg); - tr.ModelSpace.GetEntities().ForEach(ent => - { - ent.ForWrite(e => e.ColorIndex = 3); - }); + tr.ModelSpace.GetEntities() + .ForEach(ent => + { + ent.ForWrite(e => e.ColorIndex = 3); + }); tr.Database.SaveAs(dwg, DwgVersion.Current); - tr.ModelSpace.GetEntities().ForEach(ent => - { - ent.ForWrite(e => e.ColorIndex = 4); - }); + tr.ModelSpace.GetEntities() + .ForEach(ent => + { + ent.ForWrite(e => e.ColorIndex = 4); + }); tr.Database.SaveAs(dwg, DwgVersion.Current); } @@ -681,15 +744,12 @@ public void Test_ExplodeBlock() } } - - public static class Blocks { - [CommandMethod("TestExplodeToOwnerSpace3")] public static void TestExplodeToOwnerSpace3_Method() { - Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; + Editor ed = Acaop.DocumentManager.MdiActiveDocument.Editor; try { PromptEntityOptions prEntOpt = new PromptEntityOptions("\nSelect an INSERT:"); @@ -719,7 +779,7 @@ public static void ExplodeToOwnerSpace2(ObjectId id, bool erase = true) public static void ExplodeToOwnerSpace2(this BlockReference br) { - ExplodeToOwnerSpace3(br); + br.ExplodeToOwnerSpace3(); } public static ObjectIdCollection ExplodeToOwnerSpace3(ObjectId id, bool erase = true) @@ -744,6 +804,7 @@ public static ObjectIdCollection ExplodeToOwnerSpace3(ObjectId id, bool erase = } private static ObjectIdCollection idsAdded = []; + public static ObjectIdCollection ExplodeToOwnerSpace3(this BlockReference br) { idsAdded = new ObjectIdCollection(); @@ -754,11 +815,17 @@ public static ObjectIdCollection ExplodeToOwnerSpace3(this BlockReference br) return idsAdded; } + // 不能用于非等比 - public static void LoopThroughInsertAndAddEntity2n3(Matrix3d mat, BlockReference br, BlockTableRecord space) + public static void LoopThroughInsertAndAddEntity2n3( + Matrix3d mat, + BlockReference br, + BlockTableRecord space + ) { Transaction tr = space.Database.TransactionManager.TopTransaction; - BlockTableRecord btr = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead); + BlockTableRecord btr = (BlockTableRecord) + tr.GetObject(br.BlockTableRecord, OpenMode.ForRead); foreach (ObjectId id in btr) { @@ -779,10 +846,8 @@ public static void LoopThroughInsertAndAddEntity2n3(Matrix3d mat, BlockReference } } } - } - public class BlockImportClass { [CommandMethod(nameof(Test_Cbll))] @@ -792,15 +857,17 @@ public void Test_Cbll() using DBTrans tr = new(); using DBTrans tr1 = new(filename); // tr.BlockTable.GetBlockFrom(filename, true); - string blkdefname = SymbolUtilityServices.RepairSymbolName(SymbolUtilityServices.GetSymbolNameFromPathName(filename, "dwg"), false); + string blkdefname = SymbolUtilityServices.RepairSymbolName( + SymbolUtilityServices.GetSymbolNameFromPathName(filename, "dwg"), + false + ); tr.Database.Insert(blkdefname, tr1.Database, false); // 插入了块定义,未插入块参照 } - [CommandMethod(nameof(Test_CombineBlocksIntoLibrary))] public void Test_CombineBlocksIntoLibrary() { - Document doc = Acap.DocumentManager.MdiActiveDocument; + Document doc = Acaop.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database destDb = doc.Database; @@ -815,28 +882,25 @@ public void Test_CombineBlocksIntoLibrary() return; } string[] fileNames = Directory.GetFiles(pathName, "*.dwg"); - int imported = 0, failed = 0; + int imported = 0, + failed = 0; foreach (string fileName in fileNames) { - if (fileName.EndsWith(".dwg", - StringComparison.InvariantCultureIgnoreCase)) + if (fileName.EndsWith(".dwg", StringComparison.InvariantCultureIgnoreCase)) { // Catch exceptions at the file level to allow skipping try { // Suggestion from Thorsten Meinecke... - string destName = - SymbolUtilityServices.GetSymbolNameFromPathName( - fileName, "dwg" - ); + string destName = SymbolUtilityServices.GetSymbolNameFromPathName( + fileName, + "dwg" + ); // And from Dan Glassman... - destName = - SymbolUtilityServices.RepairSymbolName( - destName, false - ); + destName = SymbolUtilityServices.RepairSymbolName(destName, false); // Create a source database to load the DWG into @@ -849,26 +913,18 @@ public void Test_CombineBlocksIntoLibrary() // Insert it into the destination database as // a named block definition - ObjectId btrId = destDb.Insert( - destName, - db, - false - ); + ObjectId btrId = destDb.Insert(destName, db, false); if (isAnno) { // If an annotative block, open the resultant BTR // and set its annotative definition status - Transaction tr = - destDb.TransactionManager.StartTransaction(); + Transaction tr = destDb.TransactionManager.StartTransaction(); using (tr) { - BlockTableRecord btr = - (BlockTableRecord)tr.GetObject( - btrId, - OpenMode.ForWrite - ); + BlockTableRecord btr = (BlockTableRecord) + tr.GetObject(btrId, OpenMode.ForWrite); btr.Annotative = AnnotativeStates.True; tr.Commit(); } @@ -882,8 +938,9 @@ public void Test_CombineBlocksIntoLibrary() catch (System.Exception ex) { ed.WriteMessage( - "\nProblem importing \"{0}\": {1} - file skipped.", - fileName, ex.Message + "\nProblem importing \"{0}\": {1} - file skipped.", + fileName, + ex.Message ); failed++; } @@ -891,12 +948,11 @@ public void Test_CombineBlocksIntoLibrary() } ed.WriteMessage( - "\nImported block definitions from {0} files{1} in " + - "\"{2}\" into the current drawing.", - imported, - failed > 0 ? " (" + failed + " failed)" : "", - pathName + "\nImported block definitions from {0} files{1} in " + + "\"{2}\" into the current drawing.", + imported, + failed > 0 ? " (" + failed + " failed)" : "", + pathName ); } - -} \ No newline at end of file +} diff --git a/tests/TestShared/TestBubbleWindow.cs b/tests/TestShared/TestBubbleWindow.cs index 2edae8cb3483bfccb820dadd29dc12ecbd1ef2cd..3b4309871dcbe1e582f6cb94557948db11a8da48 100644 --- a/tests/TestShared/TestBubbleWindow.cs +++ b/tests/TestShared/TestBubbleWindow.cs @@ -2,9 +2,9 @@ public static class TestBubbleWindow { - [CommandMethod(nameof(TestBubbleWindow))] - public static void Run() + [CommandMethod(nameof(Test_BubbleWindow))] + public static void Test_BubbleWindow() { IFoxUtils.ShowBubbleWindow(5, "测试", "测试"); } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestCadFilePath.cs b/tests/TestShared/TestCadFilePath.cs index c0354d53598e2c502242888a31cdf9c84e6c5075..cf89ba487b62c1bd92272ab0dda843c5e3da4aa3 100644 --- a/tests/TestShared/TestCadFilePath.cs +++ b/tests/TestShared/TestCadFilePath.cs @@ -1,5 +1,5 @@  -namespace Test; +namespace IFoxTest; public class TestCadFilePath { @@ -20,7 +20,7 @@ public void TestCadFilePathfun() const string name = "ACAD"; var str = acadkey?.GetValue(name)?.ToString(); if (str == null || str.Contains("nihao")) continue; - Env.Print(str); + str.Print(); acadkey?.SetValue(name, $@"{str}\nihao;", RegistryValueKind.String); } } diff --git a/tests/TestShared/TestConvexHull.cs b/tests/TestShared/TestConvexHull.cs index 46cac38d38a6730a3e43e874dc63821e6bb1c3f8..84cc2e2face2fa9cc49803d47859236de9dc66f4 100644 --- a/tests/TestShared/TestConvexHull.cs +++ b/tests/TestShared/TestConvexHull.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestConvexHull { @@ -56,9 +56,9 @@ public void Test_ConvexHull() { // var area3 = vec2.DotProduct(vec1); // var area4 = vec1.DotProduct(vec2); - var area5 = GeometryEx.GetArea(new List { new Point2d(0, 0), new Point2d(1, 1), new Point2d(-1, 1) }); + var area5 = new List { new Point2d(0, 0), new Point2d(1, 1), new Point2d(-1, 1) }.GetArea(); - var area6 = GeometryEx.GetArea(new List { new Point2d(0, 0), new Point2d(-1, 1), new Point2d(1, 1) }); + var area6 = new List { new Point2d(0, 0), new Point2d(-1, 1), new Point2d(1, 1) }.GetArea(); // Env.Editor.WriteMessage($"vec1 的法向量= {vec3} \n"); // Env.Editor.WriteMessage($"vec2 的法向量= {vec4} \n"); diff --git a/tests/TestShared/TestCurve.cs b/tests/TestShared/TestCurve.cs index fd75698f2af5472409a2139940e55ee400d0e113..5cc09cd9920912fe7b5bf0d6ec9d90c987802c94 100644 --- a/tests/TestShared/TestCurve.cs +++ b/tests/TestShared/TestCurve.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestGraph { @@ -16,9 +16,9 @@ public void Test_PointInDict() { pt2, 2 }, { pt3, 3 }, { pt4, 4 }, - { pt5, 5 } + { pt5, 5 }, }; - Env.Print(dict[pt1]); + dict[pt1].Print(); } #if false @@ -81,24 +81,21 @@ public void Test_Graphspeed() #endif } - - public partial class TestCurve { [CommandMethod(nameof(Test_CurveExtend))] public void Test_CurveExtend() { - using var tr = new DBTrans(); + using var tr = new DBTrans(); var ent = Env.Editor.GetEntity("pick curve").ObjectId.GetObject(); if (ent is Curve curve) curve.ForWrite(e => e.Extend(e.EndParam + 1)); - } - private Arc ToArc1(CircularArc2d a2d) { - double startangle, endangle; + double startangle, + endangle; double refangle = a2d.ReferenceVector.Angle; if (a2d.IsClockWise) @@ -112,16 +109,15 @@ private Arc ToArc1(CircularArc2d a2d) endangle = a2d.EndAngle + refangle; } - return - new Arc( - new Point3d(new Plane(), a2d.Center), - Vector3d.ZAxis, - a2d.Radius, - startangle, - endangle); + return new Arc( + new Point3d(new Plane(), a2d.Center), + Vector3d.ZAxis, + a2d.Radius, + startangle, + endangle + ); } - #if false [CommandMethod(nameof(Test_Curve_ToArc))] public void Test_Curve_ToArc() @@ -258,7 +254,6 @@ public void Test_Curve_ToArc() #endif } - public partial class TestCurve { [CommandMethod(nameof(Test_BreakCurve))] @@ -268,7 +263,7 @@ public void Test_BreakCurve() var ents = Env.Editor.SSGet()?.Value.GetEntities(); if (ents is null) return; - var tt = CurveEx.BreakCurve(ents.ToList()!); + var tt = ents.ToList()!.BreakCurve(); tt.ForEach(t => t.ForWrite(e => e.ColorIndex = 1)); tr.CurrentSpace.AddEntity(tt); } @@ -277,9 +272,11 @@ public void Test_BreakCurve() public void Test_CurveCurveIntersector3d() { using DBTrans tr = new(); - var ents = Env.Editor.SSGet()? - .Value.GetEntities() - .Select(e => e?.ToCompositeCurve3d()).ToList(); + var ents = Env + .Editor.SSGet() + ?.Value.GetEntities() + .Select(e => e?.ToCompositeCurve3d()) + .ToList(); if (ents == null) return; @@ -297,11 +294,11 @@ public void Test_CurveCurveIntersector3d() cci3d.Set(gc1, gc2, int1, int2, Vector3d.ZAxis); var d = cci3d.OverlapCount(); var a = cci3d.GetIntersectionRanges(); - Env.Print($"{a[0].LowerBound}-{a[0].UpperBound} and {a[1].LowerBound}-{a[1].UpperBound}"); + $"{a[0].LowerBound}-{a[0].UpperBound} and {a[1].LowerBound}-{a[1].UpperBound}".Print(); for (int m = 0; m < d; m++) { var b = cci3d.GetOverlapRanges(m); - Env.Print($"{b[0].LowerBound}-{b[0].UpperBound} and {b[1].LowerBound}-{b[1].UpperBound}"); + $"{b[0].LowerBound}-{b[0].UpperBound} and {b[1].LowerBound}-{b[1].UpperBound}".Print(); } for (int k = 0; k < cci3d.NumberOfIntersectionPoints; k++) @@ -313,7 +310,7 @@ public void Test_CurveCurveIntersector3d() // var e = cci3d.OverlapDirection(); var pt = cci3d.GetIntersectionParameters(k); var pts = cci3d.GetIntersectionPoint(k); - Env.Print(pts); + pts.Print(); } } } @@ -321,4 +318,4 @@ public void Test_CurveCurveIntersector3d() // tt.ForEach(t => t.ForWrite(e => e.ColorIndex = 1)); // tr.CurrentSpace.AddEntity(tt); } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestDBTrans.cs b/tests/TestShared/TestDBTrans.cs index 41eb67d81a467ecaa1183c6e1868921d79890b9a..07d2db3feea5c69e40efbca5b03fb41bb9c6d2fe 100644 --- a/tests/TestShared/TestDBTrans.cs +++ b/tests/TestShared/TestDBTrans.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestTrans { @@ -33,10 +33,7 @@ private static Document Getdoc() var doc = Acaop.DocumentManager.MdiActiveDocument; return doc; } - - - - + [CommandMethod(nameof(CmdTest_DBTransActiveOpenDwg), CommandFlags.Session)] public static void CmdTest_DBTransActiveOpenDwg() { @@ -49,11 +46,14 @@ public static void CmdTest_ForEachDemo() using DBTrans tr = new(); // 泛型扩展(用变量名来使用它) - tr.BlockTable.ForEach(action: (id) => { - //Debugger.Break();// 为什么cad工程不能断点进入呢? - id.Print(); - Console.WriteLine(id); - }); + tr.BlockTable.ForEach( + action: (id) => + { + //Debugger.Break();// 为什么cad工程不能断点进入呢? + id.Print(); + Console.WriteLine(id); + } + ); //tr.BlockTable.ForEach(asdad); //void asdad(object id) @@ -61,41 +61,59 @@ public static void CmdTest_ForEachDemo() // id.Print(); //} - tr.BlockTable.ForEach(action: (id) => { - id.Print(); - }); - tr.BlockTable.ForEach(action: (id, state, index) => { - id.Print(); - }); + tr.BlockTable.ForEach( + action: (id) => + { + id.Print(); + } + ); + tr.BlockTable.ForEach( + action: (id, state, index) => + { + id.Print(); + } + ); // 符号表扩展(会顶替泛型扩展) - tr.BlockTable.ForEach((btr) => { // 预处理设置不进入ForEach函数体内 - btr.Print();// 此处可以设置断点 - }, OpenMode.ForRead, checkIdOk: true); - tr.BlockTable.ForEach((btr, state) => {// 预处理设置不进入ForEach函数体内 - btr.Print();// 此处可以设置断点 - }, OpenMode.ForRead, checkIdOk: true); - tr.BlockTable.ForEach((btr, state, index) => { // 预处理设置不进入ForEach函数体内 - btr.Print();// 此处可以设置断点 - }, OpenMode.ForRead, checkIdOk: true); + tr.BlockTable.ForEach( + (btr) => + { // 预处理设置不进入ForEach函数体内 + btr.Print(); // 此处可以设置断点 + } + ); + tr.BlockTable.ForEach( + (btr, state) => + { // 预处理设置不进入ForEach函数体内 + btr.Print(); // 此处可以设置断点 + } + ); + tr.BlockTable.ForEach( + (btr, state, index) => + { // 预处理设置不进入ForEach函数体内 + btr.Print(); // 此处可以设置断点 + } + ); // 修改:此处有缺陷:cad08会获取已经删除的块表记录,需要检查id.IsOk(),用ForEach代替 // tr.BlockTable.Change("块表记录", btr => { // }); // 修改:此处无缺陷 - tr.BlockTable.Change(tr.ModelSpace.ObjectId, modelSpace => { // 特性设置不进入函数体内 - var ents = modelSpace.GetEntities(); // 此处不会检查id.IsOk() - - modelSpace.ForEach(id => { // 利用遍历检查id.IsOk() - if (id.IsOk()) - id.Print(); - }); - }); + tr.BlockTable.Change( + tr.ModelSpace.ObjectId, + modelSpace => + { // 特性设置不进入函数体内 + var ents = modelSpace.GetEntities(); // 此处不会检查id.IsOk() + + modelSpace.ForEach(id => + { // 利用遍历检查id.IsOk() + if (id.IsOk()) + id.Print(); + }); + } + ); } - - // 后台:不存在路径的dwg会在桌面进行临时保存 [CommandMethod(nameof(FileNotExist))] public void FileNotExist() @@ -123,7 +141,6 @@ public void FileNotExist3() tr2.Database.SaveFile(saveAsFile: "D:\\"); } - [CommandMethod(nameof(Test_SaveDwgFile))] public void Test_SaveDwgFile() { @@ -134,6 +151,7 @@ public void Test_SaveDwgFile() // tr.Database.SaveAs(filename,DwgVersion.Current); tr.Database.SaveDwgFile(); } + [CommandMethod(nameof(Test_DBTransAbort))] public void Test_DBTransAbort() { @@ -165,7 +183,6 @@ public void Test_DBTransAbort() // tr.ModelSpace.AddCircle(new Point3d(0, 0, 0), 20); // } - [CommandMethod(nameof(Test_TopTransaction))] public void Test_TopTransaction() { @@ -176,28 +193,25 @@ public void Test_TopTransaction() using DBTrans tr2 = new(); var tr3 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; var tr6 = Acaop.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction; - Env.Print(tr2.Transaction == tr3); - Env.Print(tr3 == tr6); + (tr2.Transaction == tr3).Print(); + (tr3 == tr6).Print(); using DBTrans tr4 = new(); var tr5 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; var tr7 = Acaop.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction; - Env.Print(tr4.Transaction == tr5); - Env.Print(tr5 == tr7); + (tr4.Transaction == tr5).Print(); + (tr5 == tr7).Print(); var trm = HostApplicationServices.WorkingDatabase.TransactionManager; - } [CommandMethod(nameof(Test_DBTrans_BlockCount))] public void Test_DBTrans_BlockCount() { using var tr = new DBTrans(); - var i = tr.CurrentSpace - .GetEntities() + var i = tr + .CurrentSpace.GetEntities() .Where(ent => ent.GetBlockName() == "自定义块"); - + var block = i.ToList()[0]; - Env.Print(i.Count()); + i.Count().Print(); } - - -} \ No newline at end of file +} diff --git a/tests/TestShared/TestDBobject.cs b/tests/TestShared/TestDBobject.cs index f0cb142afe65c59161842eedc5ccfd0415047840..c1ac402f9c841e43de29f5b13f303b4dcaaab8c2 100644 --- a/tests/TestShared/TestDBobject.cs +++ b/tests/TestShared/TestDBobject.cs @@ -1,27 +1,25 @@ - - -namespace TestShared +namespace TestShared { - public static class TestDBobject + public static class TestDbObject { - [CommandMethod(nameof(TestForWrite))] - public static void TestForWrite() + [CommandMethod(nameof(Test_ForWrite))] + public static void Test_ForWrite() { using var tr = new DBTrans(); var ent = Env.Editor.GetEntity("\npick entity"); - if (ent.Status is not PromptStatus.OK) return; - var entid = ent.ObjectId.GetObject()!; - Tools.TestTimes3(100000, "using:", i => { - using (entid.ForWrite()) + if (ent.Status is not PromptStatus.OK) + return; + var entId = ent.ObjectId.GetObject()!; + Tools.TestTimes3( + 100000, + "using:", + i => { - entid.ColorIndex = i % 7; + using (entId.ForWrite()) + entId.ColorIndex = i % 7; } - }); - Tools.TestTimes3(100000, "action:", i => { - entid.ForWrite(e => { - e.ColorIndex = i % 7; - }); - }); + ); + Tools.TestTimes3(100000, "action:", i => entId.ForWrite(e => e.ColorIndex = i % 7)); } } } diff --git a/tests/TestShared/TestDwgFilerEx.cs b/tests/TestShared/TestDwgFilerEx.cs index 32a5f78a16bb4f32b3ca077c9995737cda62f62b..34258fee13f5b267b8b831541e703d18811a16bb 100644 --- a/tests/TestShared/TestDwgFilerEx.cs +++ b/tests/TestShared/TestDwgFilerEx.cs @@ -1,5 +1,5 @@ #if acad -namespace Test; +namespace IFoxTest; public class CmdTestDwgFilerEx { @@ -21,7 +21,7 @@ public static void CmdTest_DwgFilerEx() { objectId.ObjectClass.DxfName.Print(); } - + // ed.WriteMessage(Environment.NewLine + dwgFiler.ToString()); } } @@ -59,92 +59,92 @@ public static void CmdTest_DwgFilerEx() // } // } -// [CommandMethod(nameof(CmdTest_TextOut))] -// public static void CmdTest_TextOut() -// { -// var dm = Acap.DocumentManager; -// var doc = dm.MdiActiveDocument; -// var db = doc.Database; -// var ed = doc.Editor; -// -// #if true -// var peo1 = new PromptEntityOptions(Environment.NewLine + "点选源TCH_WIREDIM2:") -// { -// AllowObjectOnLockedLayer = false, -// AllowNone = false -// }; -// var gt1 = ed.GetEntity(peo1); -// if (gt1.Status != PromptStatus.OK) -// return; -// #else -// var peo2 = new PromptEntityOptions(Environment.NewLine + "点选目标TCH_WIREDIM2:") -// { -// AllowObjectOnLockedLayer = false, -// AllowNone = false -// }; -// var gt2 = ed.GetEntity(peo2); -// if (gt2.Status != PromptStatus.OK) -// return; -// #endif -// -// using DBTrans tr = new(); -// var dwgFilerEx = new DwgFilerEx(); -// var bText = tr.GetObject(gt1.ObjectId, OpenMode.ForRead); -// if (bText is null) -// return; -// -// // DwgFilerEx.StringList[0] = "1@2@3@4@5@6@7@"; -// // 复制 TCH_WIREDIM2 不行,TEXT 也不行,直接崩溃。line等线就没事 -// bText.DwgOut(dwgFilerEx.DwgFiler); -// -// int testNum = 1 | 2 | 4 | 8; -// -// if ((testNum & 1) == 1) -// { -// // 错误,原地克隆也是不行的,它会生成在了模型中. -// var sIds = new List -// { -// bText.ObjectId -// }; -// // 克隆到目标块表内 -// using ObjectIdCollection bindIds = new(sIds.ToArray()); -// using IdMapping map = new(); -// -// tr.CurrentSpace.DeepCloneEx(bindIds, map); -// var newTexts = map.GetValues().GetObject(); -// newTexts.ForEach(nText => { -// if (nText == null) -// return; -// // 通过上面的克隆就已经在块表上面了.所以下面的设置也跟设置到已有图元上一样报错. -// nText.UpgradeOpen(); -// nText.DwgIn(dwgFilerEx); -// tr.CurrentSpace.AddEntity(nText); -// nText.DowngradeOpen(); -// }); -// } -// if ((testNum & 2) == 2) -// { -// // 出错 -// // 直接设置 -// bText.DwgIn(dwgFilerEx); -// } -// if ((testNum & 4) == 4) -// { -// // 出错 -// // 此时是内存中对象.... -// var nText = (DBText)bText.Clone(); -// nText.DwgIn(dwgFilerEx); -// tr.CurrentSpace.AddEntity(nText); -// } -// if ((testNum & 8) == 8) -// { -// // 新对象相当于克隆,是ok的 -// DBText nText = new(); -// nText.SetDatabaseDefaults(); -// nText.DwgIn(dwgFilerEx); -// tr.CurrentSpace.AddEntity(nText); -// } -// } + // [CommandMethod(nameof(CmdTest_TextOut))] + // public static void CmdTest_TextOut() + // { + // var dm = Acap.DocumentManager; + // var doc = dm.MdiActiveDocument; + // var db = doc.Database; + // var ed = doc.Editor; + // + // #if true + // var peo1 = new PromptEntityOptions(Environment.NewLine + "点选源TCH_WIREDIM2:") + // { + // AllowObjectOnLockedLayer = false, + // AllowNone = false + // }; + // var gt1 = ed.GetEntity(peo1); + // if (gt1.Status != PromptStatus.OK) + // return; + // #else + // var peo2 = new PromptEntityOptions(Environment.NewLine + "点选目标TCH_WIREDIM2:") + // { + // AllowObjectOnLockedLayer = false, + // AllowNone = false + // }; + // var gt2 = ed.GetEntity(peo2); + // if (gt2.Status != PromptStatus.OK) + // return; + // #endif + // + // using DBTrans tr = new(); + // var dwgFilerEx = new DwgFilerEx(); + // var bText = tr.GetObject(gt1.ObjectId, OpenMode.ForRead); + // if (bText is null) + // return; + // + // // DwgFilerEx.StringList[0] = "1@2@3@4@5@6@7@"; + // // 复制 TCH_WIREDIM2 不行,TEXT 也不行,直接崩溃。line等线就没事 + // bText.DwgOut(dwgFilerEx.DwgFiler); + // + // int testNum = 1 | 2 | 4 | 8; + // + // if ((testNum & 1) == 1) + // { + // // 错误,原地克隆也是不行的,它会生成在了模型中. + // var sIds = new List + // { + // bText.ObjectId + // }; + // // 克隆到目标块表内 + // using ObjectIdCollection bindIds = new(sIds.ToArray()); + // using IdMapping map = new(); + // + // tr.CurrentSpace.DeepCloneEx(bindIds, map); + // var newTexts = map.GetValues().GetObject(); + // newTexts.ForEach(nText => { + // if (nText == null) + // return; + // // 通过上面的克隆就已经在块表上面了.所以下面的设置也跟设置到已有图元上一样报错. + // nText.UpgradeOpen(); + // nText.DwgIn(dwgFilerEx); + // tr.CurrentSpace.AddEntity(nText); + // nText.DowngradeOpen(); + // }); + // } + // if ((testNum & 2) == 2) + // { + // // 出错 + // // 直接设置 + // bText.DwgIn(dwgFilerEx); + // } + // if ((testNum & 4) == 4) + // { + // // 出错 + // // 此时是内存中对象.... + // var nText = (DBText)bText.Clone(); + // nText.DwgIn(dwgFilerEx); + // tr.CurrentSpace.AddEntity(nText); + // } + // if ((testNum & 8) == 8) + // { + // // 新对象相当于克隆,是ok的 + // DBText nText = new(); + // nText.SetDatabaseDefaults(); + // nText.DwgIn(dwgFilerEx); + // tr.CurrentSpace.AddEntity(nText); + // } + // } } -#endif \ No newline at end of file +#endif diff --git a/tests/TestShared/TestDwgMark.cs b/tests/TestShared/TestDwgMark.cs index 5eea9499adf2d17f15f80749eb6b8af754b038d7..90cb0d57541cd726031866ba27182c8c955910a1 100644 --- a/tests/TestShared/TestDwgMark.cs +++ b/tests/TestShared/TestDwgMark.cs @@ -1,12 +1,13 @@ -namespace Test; +namespace IFoxTest; -using IFoxCAD.Cad; -public class TestDwgMark { - [CommandMethod(nameof(DwgMarktest))] - public void DwgMarktest() { +public class TestDwgMark +{ + [CommandMethod(nameof(Test_DwgMarktest))] + public void Test_DwgMarktest() + { FileInfo file = new FileInfo(@"D:\TEST\1.dwg"); DwgMark.AddMark(file, 0x4D); DwgMark.RemoveMark(file); - int A = DwgMark.GetMark(file); + int a = DwgMark.GetMark(file); } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestEditor.cs b/tests/TestShared/TestEditor.cs index 5f83345d9fa456752e52a55b975c6177a1c37b6a..af5dda772e30cea681dbe530a0ddb3c842d48877 100644 --- a/tests/TestShared/TestEditor.cs +++ b/tests/TestShared/TestEditor.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class Testeditor { @@ -16,7 +16,7 @@ public void Test_Editor() var res1 = EditorEx.GetLines(pts, true); var res2 = pts.Select(pt => new TypedValue((int)LispDataType.Point2d, pt)).ToList(); - Editor ed = Acap.DocumentManager.MdiActiveDocument.Editor; + Editor ed = Acaop.DocumentManager.MdiActiveDocument.Editor; var pt = ed.GetPoint("qudiam", new Point3d(0, 0, 0)); var d = ed.GetDouble("qudoule"); var i = ed.GetInteger("quint"); @@ -47,12 +47,12 @@ public void Test_ZoomExtents() [CommandMethod(nameof(Test_Zoom_1))] public void Test_Zoom_1() { - Env.Editor.Zoom(new(0, 0, 0),200,200); + Env.Editor.Zoom(new Point3d(0, 0, 0),200,200); } [CommandMethod(nameof(Test_Zoom_2))] public void Test_Zoom_2() { - Env.Editor.ZoomWindow(new Point3d(-100,-100,0),new(100,100,0)); + Env.Editor.ZoomWindow(new Point3d(-100,-100,0),new Point3d(100,100,0)); } [CommandMethod(nameof(Test_Ssget))] @@ -61,13 +61,13 @@ public void Test_Ssget() var keyword = new Dictionary { - { "D", ("你好", () => { Env.Print("this is c"); }) }, - { "B", ("hello", () => { Env.Print("this is b"); }) } + { "D", ("你好", () => { "this is c".Print(); }) }, + { "B", ("hello", () => { "this is b".Print(); }) } }; var ss = Env.Editor.SSGet(/*":S", */ messages: ("get", "del" ), keywords: keyword); - Env.Print(ss!); + ss!.Print(); } [CommandMethod(nameof(Test_ExportWMF), CommandFlags.Modal | CommandFlags.UsePickSet)] diff --git a/tests/TestShared/TestEntity/TestAddEntity.cs b/tests/TestShared/TestEntity/TestAddEntity.cs index 920e6e03772c73b068e522d4d2a27374ad5c76f6..53535255d40261687f2011d597bd4052861e33d2 100644 --- a/tests/TestShared/TestEntity/TestAddEntity.cs +++ b/tests/TestShared/TestEntity/TestAddEntity.cs @@ -1,14 +1,14 @@ -namespace Test; +namespace IFoxTest; public class TestAddEntity { -#region 直线 + #region 直线 [CommandMethod(nameof(Test_AddLinetoCurrentSpace))] public void Test_AddLinetoCurrentSpace() { using DBTrans tr = new(); // 开启事务 - Line line = new(new(0, 0, 0), new(1, 1, 0)); // 定义一个直线 + Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); // 定义一个直线 tr.CurrentSpace.AddEntity(line); // 将直线添加到当前空间 } @@ -17,7 +17,7 @@ public void Test_AddLinetoModelSpace() { using DBTrans tr = new(); // 开启事务 - Line line = new(new(0, 0, 0), new(1, 1, 0)); // 定义一个直线 + Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); // 定义一个直线 tr.ModelSpace.AddEntity(line); // 将直线添加到模型空间 } @@ -26,7 +26,7 @@ public void Test_AddLinetoPaperSpace() { using DBTrans tr = new(); // 开启事务 - Line line = new(new(0, 0, 0), new(1, 1, 0)); // 定义一个直线 + Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); // 定义一个直线 tr.PaperSpace.AddEntity(line); // 将直线添加到图纸空间 } @@ -54,45 +54,54 @@ public void Test_AddEntities() // c#12 新语法,集合表达式 tr.CurrentSpace.AddEntity([line1, line2, circle]); } -#endregion + #endregion -#region 圆 + #region 圆 [CommandMethod(nameof(Test_AddCircle))] public void Test_AddCircle() { - var cir = CircleEx.CreateCircle(Point3d.Origin, new(1,0,0)); // 两点创建圆 - var cir1 = CircleEx.CreateCircle(Point3d.Origin, new(1,1,0), new(2,0,0)); //三点创建圆 + var cir = CircleEx.CreateCircle(Point3d.Origin, new Point3d(1, 0, 0)); // 两点创建圆 + var cir1 = CircleEx.CreateCircle( + Point3d.Origin, + new Point3d(1, 1, 0), + new Point3d(2, 0, 0) + ); //三点创建圆 var cir2 = CircleEx.CreateCircle(Point3d.Origin, 5); // 圆心半径创建圆 using DBTrans tr = new(); tr.CurrentSpace.AddEntity(cir, cir2); - + // 由于三点不一定能成功创建一个圆,因此返回值是可空的,需要判空 if (cir1 is not null) { tr.CurrentSpace.AddEntity(cir1); } } -#endregion + #endregion -#region 圆弧 + #region 圆弧 [CommandMethod(nameof(Test_AddArc))] public void Test_AddArc() { using DBTrans tr = new(); - Arc arc1 = ArcEx.CreateArcSCE(new Point3d(2, 0, 0), new Point3d(0, 0, 0), new Point3d(0, 2, 0));// 起点,圆心,终点 - Arc arc2 = ArcEx.CreateArc(new Point3d(4, 0, 0), new Point3d(0, 0, 0), Math.PI / 2); // 起点,圆心,弧度 - Arc arc3 = ArcEx.CreateArc(new Point3d(1, 0, 0), new Point3d(0, 0, 0), new Point3d(0, 1, 0)); // 起点,圆上一点,终点 + Arc arc1 = ArcEx.CreateArcSCE( + new Point3d(2, 0, 0), + new Point3d(0, 0, 0), + new Point3d(0, 2, 0) + ); // 起点,圆心,终点 + Arc arc2 = ArcEx.CreateArc(new Point3d(4, 0, 0), new Point3d(0, 0, 0), Math.PI / 2); // 起点,圆心,弧度 + Arc arc3 = ArcEx.CreateArc( + new Point3d(1, 0, 0), + new Point3d(0, 0, 0), + new Point3d(0, 1, 0) + ); // 起点,圆上一点,终点 tr.CurrentSpace.AddEntity(arc1, arc2, arc3); } -#endregion - - - + #endregion -#region 多段线 + #region 多段线 [CommandMethod(nameof(Test_AddPolyline1))] public void Test_AddPolyline1() { @@ -115,13 +124,13 @@ public void Test_AddPolyline2() // 集合表达式 List<(Point3d, double, double, double)> pts = [ - (new Point3d(0,0,0),0,0,0), - (new Point3d(10,0,0),0,0,0), - (new Point3d(10,10,0),0,0,0), - (new Point3d(0,10,0),0,0,0), - (new Point3d(5,5,0),0,0,0) + (new Point3d(0, 0, 0), 0, 0, 0), + (new Point3d(10, 0, 0), 0, 0, 0), + (new Point3d(10, 10, 0), 0, 0, 0), + (new Point3d(0, 10, 0), 0, 0, 0), + (new Point3d(5, 5, 0), 0, 0, 0), ]; - + using DBTrans tr = new(); var pl = pts.CreatePolyline(); tr.CurrentSpace.AddEntity(pl); @@ -132,26 +141,19 @@ public void Test_AddPolyline3() { using var tr = new DBTrans(); - List pts = - [ - new(0, 0, 0), - new(0, 1, 0), - new(1, 1, 0), - new(1, 0, 0) - ]; - var pline = pts.CreatePolyline(); - tr.CurrentSpace.AddEntity(pline); + List pts = [new(0, 0, 0), new(0, 1, 0), new(1, 1, 0), new(1, 0, 0)]; + var pLine = pts.CreatePolyline(); + tr.CurrentSpace.AddEntity(pLine); // 可以通过委托,一次性的创建多段线并设置属性 - var pline1 = pts.CreatePolyline(p => + var pLine1 = pts.CreatePolyline(p => { p.Closed = true; p.ConstantWidth = 0.2; p.ColorIndex = 1; }); - tr.CurrentSpace.AddEntity(pline1); + tr.CurrentSpace.AddEntity(pLine1); } -#endregion - + #endregion } diff --git a/tests/TestShared/TestEnv.cs b/tests/TestShared/TestEnv.cs index a9540345540114bf291bdd76e79893630bd43507..a74380c1e5fd752023a71dddb3c25a1ce90e121e 100644 --- a/tests/TestShared/TestEnv.cs +++ b/tests/TestShared/TestEnv.cs @@ -1,38 +1,46 @@ -namespace Test; +namespace IFoxTest; -public class Testenv { +public class TestEnv +{ [CommandMethod(nameof(Test_Enum))] - public void Test_Enum() { + public void Test_Enum() + { SystemVariableManager.CmdEcho = true; } + [CommandMethod(nameof(Test_Enum1))] - public void Test_Enum1() { + public void Test_Enum1() + { SystemVariableManager.CmdEcho = false; } [CommandMethod(nameof(Test_Dimblk))] - public void Test_Dimblk() { + public void Test_Dimblk() + { Env.Dimblk = Env.DimblkType.Dot; - Env.Print(Env.Dimblk); - Env.Print(Env.GetDimblkId(Env.DimblkType.Dot)); + Env.Dimblk.Print(); + Env.GetDimblkId(Env.DimblkType.Dot).Print(); Env.Dimblk = Env.DimblkType.Default; - Env.Print(Env.Dimblk); - Env.Print(Env.GetDimblkId(Env.DimblkType.Default)); + Env.Dimblk.Print(); + Env.GetDimblkId(Env.DimblkType.Default).Print(); Env.Dimblk = Env.DimblkType.Oblique; - Env.Print(Env.Dimblk); - Env.Print(Env.GetDimblkId(Env.DimblkType.Oblique)); + Env.Dimblk.Print(); + Env.GetDimblkId(Env.DimblkType.Oblique).Print(); Env.Dimblk = Env.DimblkType.ArchTick; - Env.Print(Env.Dimblk); - Env.Print(Env.GetDimblkId(Env.DimblkType.ArchTick)); + Env.Dimblk.Print(); + Env.GetDimblkId(Env.DimblkType.ArchTick).Print(); } + [CommandMethod(nameof(Test_Dimblk1))] - public void Test_Dimblk1() { + public void Test_Dimblk1() + { var dim = Env.Dimblk; Env.Editor.WriteMessage(dim.ToString()); } [CommandMethod(nameof(Test_Osmode))] - public void Test_Osmode() { + public void Test_Osmode() + { // 设置osmode变量,多个值用逻辑或 Env.OSMode = Env.OSModeType.End | Env.OSModeType.Middle; // 也可以直接写数值,进行强转 @@ -45,8 +53,10 @@ public void Test_Osmode() { Env.OSMode ^= Env.OSModeType.Center; Env.Editor.WriteMessage(Env.OSMode.ToString()); } + [CommandMethod(nameof(Test_Osmode1))] - public void Test_Osmode1() { + public void Test_Osmode1() + { var dim = Env.OSMode; Env.Editor.WriteMessage(dim.ToString()); } @@ -60,17 +70,16 @@ public void Test_Cadver() 1.Print(); "1".Print(); } -#endif +#endif [CommandMethod(nameof(Test_GetVar))] - public void Test_GetVar() { + public void Test_GetVar() + { // test getvar var a = Env.GetVar("dbmod"); a.Print(); Env.SetVar("dbmod1", 1); } - - //[CommandMethod(nameof(Test_DwgVersion))] //public void TestDwgVersion() //{ @@ -80,19 +89,21 @@ public void Test_GetVar() { // ((DwgVersion)a).Print(); //} - #if !zcad // 通过此功能获取全部变量,尚不清楚此处如何设置,没有通过测试 [CommandMethod(nameof(Test_GetvarAll))] - public static void Test_GetvarAll() { - GetvarAll(); + public static void Test_GetvarAll() + { + GetVarAll(); } - public static Dictionary GetvarAll() { + public static Dictionary GetVarAll() + { var dict = new Dictionary(); var en = new SystemVariableEnumerator(); - while (en.MoveNext()) { - Console.WriteLine(en.Current.Name + "-----" + en.Current.Value);// Value会出现异常 + while (en.MoveNext()) + { + Console.WriteLine(en.Current.Name + "-----" + en.Current.Value); // Value会出现异常 dict.Add(en.Current.Name, en.Current.Value); } return dict; @@ -100,7 +111,8 @@ public static Dictionary GetvarAll() { #endif [CommandMethod(nameof(Test_GetEnv))] - public static void Test_GetEnv() { + public static void Test_GetEnv() + { var dir = Env.GetEnv("PrinterConfigDir"); Env.Printl("pc3打印机位置:" + dir); @@ -118,8 +130,10 @@ public static void Test_GetEnv() { Env.Printl($"getenv-osmode: {Env.GetEnv("osmode")}"); Env.Printl($"getvar-osmode: {Env.GetVar("osmode")}"); } + [CommandMethod(nameof(Test_AppendPath))] - public static void Test_AppendPath() { + public static void Test_AppendPath() + { Directory.Exists(@"C:\Folder4").Print(); Env.AppendSupportPath(@"C:\Folder4", @"C:\Folder5", @"C:\Folder6"); // Env.AppendTrustedPath(@"c:\a\x",@"c:\a\c"); @@ -127,11 +141,11 @@ public static void Test_AppendPath() { Env.GetEnv("ACAD").Print(); // Env.SetEnv("ACAD", @"C:\Folder1;"+Env.GetEnv("ACAD")); Env.GetEnv("ACAD").Contains(@"C:\Folder1").Print(); - } [CommandMethod(nameof(Test_RemovePath))] - public static void Test_RemovePath() { + public static void Test_RemovePath() + { // var acad = Acaop.TryGetSystemVariable("ACAD").ToString(); // acad.Print(); // Acaop.SetSystemVariable("ACAD", acad + @";c:\a\x"); @@ -141,19 +155,22 @@ public static void Test_RemovePath() { Env.GetEnv("ACAD").Print(); } - public static void AppendSupportPath(string path) { - + public static void AppendSupportPath(string path) + { string key = HostApplicationServices.Current.UserRegistryProductRootKey; // 计算机\HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R24.0\ACAD-4101:804 var ackey = Registry.CurrentUser.OpenSubKey($@"{key}\Profiles") ?? null; - if (ackey != null) { + if (ackey != null) + { var listkey = ackey.GetSubKeyNames(); - foreach (var item in listkey) { + foreach (var item in listkey) + { var acadkey = ackey.OpenSubKey($@"{item}\General", true); const string name = "ACAD"; var str = acadkey?.GetValue(name)?.ToString(); - if (str != null && !str.ToLower().Contains(path.ToLower())) { + if (str != null && !str.ToLower().Contains(path.ToLower())) + { acadkey?.SetValue(name, $@"{str}{path};"); } } @@ -161,6 +178,4 @@ public static void AppendSupportPath(string path) { ackey?.Close(); } - - -} \ No newline at end of file +} diff --git a/tests/TestShared/TestExtents.cs b/tests/TestShared/TestExtents.cs index 96c04db04ec8d7e080b1edf6ccd797b69afcc61e..ddc7a9da8865178d571ef211442ab56a010fb9a4 100644 --- a/tests/TestShared/TestExtents.cs +++ b/tests/TestShared/TestExtents.cs @@ -7,7 +7,7 @@ public void Test_BlockExtents() { using var tr = new DBTrans(); var ent = Env.Editor.GetEntity("pick the entity"); - if (ent.Status != PromptStatus.OK ) + if (ent.Status != PromptStatus.OK) { return; } @@ -16,20 +16,20 @@ public void Test_BlockExtents() if (block != null && block.Bounds.HasValue) { var extent = block.GeometricExtents; - List pts = [ + List pts = + [ extent.MinPoint, - new Point3d(extent.MinPoint.X,extent.MaxPoint.Y,0), + new Point3d(extent.MinPoint.X, extent.MaxPoint.Y, 0), extent.MaxPoint, - new Point3d(extent.MaxPoint.X,extent.MinPoint.Y,0), - + new Point3d(extent.MaxPoint.X, extent.MinPoint.Y, 0), ]; tr.CurrentSpace.AddEntity(pts.CreatePolyline(action: e => e.ColorIndex = 1)); - + if (block is BlockReference block1) { var extents = block1.GeometryExtentsBestFit(); - List pts1 = + List pts1 = [ extents.MinPoint, new Point3d(extents.MinPoint.X, extents.MaxPoint.Y, 0), @@ -40,35 +40,34 @@ public void Test_BlockExtents() var extents2 = block1.GetBoundingBoxEx(); tr.CurrentSpace.AddEntity(pts.CreatePolyline(action: e => e.ColorIndex = 3)); - + // 此处是计算块定义的包围盒,不是块参照的,所以一般情况下不需要使用。 var ext = new Extents3d(); ext.AddBlockExtents(block1.BlockTableRecord.GetObject()); tr.CurrentSpace.AddEntity(ext.CreatePolyline(action: e => e.ColorIndex = 4)); } - - } } - - [CommandMethod(nameof(Test_entextents))] - public void Test_entextents() + + [CommandMethod(nameof(Test_Extensions))] + public void Test_Extensions() { using var tr = new DBTrans(); - var a = Env.Editor.GetSelection().Value. - GetEntities(OpenMode.ForWrite); + var a = Env.Editor.GetSelection().Value.GetEntities(OpenMode.ForWrite); foreach (var e in a) { - var b = e.Bounds.HasValue; //获取是否有包围盒 + var b = e.Bounds.HasValue; //获取是否有包围盒 var name = e.ObjectId.ObjectClass.DxfName; - Env.Print($"{name}是否有包围盒-" + b); + ($"{name}是否有包围盒-" + b).Print(); if (b) { - tr.CurrentSpace.AddEntity(e.Bounds!.Value.CreatePolyline(action: e => - { - e.ColorIndex = 4; - e.Closed = true; - })); + tr.CurrentSpace.AddEntity( + e.Bounds!.Value.CreatePolyline(action: e => + { + e.ColorIndex = 4; + e.Closed = true; + }) + ); var ext = e.GetBoundingBoxEx(); if (ext.HasValue) { @@ -77,32 +76,30 @@ public void Test_entextents() { e.ColorIndex = 5; e.Closed = true; - })); + }) + ); } - + if (e is Curve spline) { var ge = spline.GetGeCurve(); var box = ge.BoundBlock; - List lst = + List lst = [ box.BasePoint, box.BasePoint + box.Direction1, box.BasePoint + box.Direction2, box.BasePoint + box.Direction3, ]; - tr.CurrentSpace.AddEntity(lst.CreatePolyline(action: e => - { - e.ColorIndex = 6; - e.Closed = true; - })); + tr.CurrentSpace.AddEntity( + lst.CreatePolyline(action: e => + { + e.ColorIndex = 6; + e.Closed = true; + }) + ); } - } - - - - } } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestFileDatabase.cs b/tests/TestShared/TestFileDatabase.cs index e5c58c326c09c5c083598fcbe1995940e2df70c0..c764af9d65cc28d63330c5ef8267466bf06fe3c9 100644 --- a/tests/TestShared/TestFileDatabase.cs +++ b/tests/TestShared/TestFileDatabase.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; /************************************************************** *作者:Leon @@ -12,17 +12,17 @@ public void Test_FileDatabaseInit() { try { - var fileName = @"C:\Users\Administrator\Desktop\合并详图测试BUG.dwg"; + const string fileName = @"C:\Users\Administrator\Desktop\合并详图测试BUG.dwg"; using DBTrans trans = new(fileName); - trans.ModelSpace.AddEntity(new Line(new(0, 0, 0), new(1000, 1000, 0))); + trans.ModelSpace.AddEntity(new Line(new Point3d(0, 0, 0), new Point3d(1000, 1000, 0))); if (trans.Document is not null && trans.Document.IsActive) trans.Document.SendStringToExecute("_qsave\n", false, true, true); else trans.Database.SaveAs(fileName, (DwgVersion)27); } - catch (System.Exception e) + catch (Exception e) { System.Windows.MessageBox.Show(e.Message); } } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestHatchinfo.cs b/tests/TestShared/TestHatchinfo.cs index e241dfba01184c80bb1a7470f8e9048f39c92296..1faa13e334f3e65563876be37d93512c4fa4143f 100644 --- a/tests/TestShared/TestHatchinfo.cs +++ b/tests/TestShared/TestHatchinfo.cs @@ -1,16 +1,17 @@ -namespace Test; +namespace IFoxTest; -public class TestHatchinfo +public class TestHatchInfoTest { - [CommandMethod(" TestHatchInfo")] + [CommandMethod(nameof(TestHatchInfo))] public void TestHatchInfo() { using var tr = new DBTrans(); - var sf = new SelectionFilter(new TypedValue[] { new TypedValue(0, "*line,circle,arc") }); + var sf = new SelectionFilter([new TypedValue(0, "*line,circle,arc")]); var ids = Env.Editor.SSGet(null, sf).Value?.GetObjectIds(); - if (ids == null || ids.Count() <= 0) return; - var hf = new HatchInfo(ids!, false, null, 1, 0).Mode2UserDefined(); + if (ids is not { Length: > 0 }) + return; + + var hf = new HatchInfo(ids, false).Mode2UserDefined(); hf.Build(tr.CurrentSpace); } } - diff --git a/tests/TestShared/TestId.cs b/tests/TestShared/TestId.cs index 57f19cf512f635112ceef6637b3c36250ee02df5..4ec9c509fc05f4b00b6ec98809d22587d42f915a 100644 --- a/tests/TestShared/TestId.cs +++ b/tests/TestShared/TestId.cs @@ -1,6 +1,6 @@ -namespace Test; +namespace IFoxTest; -public class Testid +public class TestId { [CommandMethod(nameof(Test_Id))] public void Test_Id() @@ -8,7 +8,7 @@ public void Test_Id() using DBTrans tr = new(); Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); tr.CurrentSpace.AddEntity(line); - tr.Dispose(); + // tr.Dispose(); var res = Env.Editor.GetEntity("\npick ent:"); if (res.Status == PromptStatus.OK) @@ -29,16 +29,18 @@ public void Test_Id() [CommandMethod(nameof(Test_MyCommand))] public void Test_MyCommand() { - using DBTrans dbtrans = new(Env.Document, true, false); + using DBTrans tr = new(Env.Document); using var trans = Env.Database.TransactionManager.StartTransaction(); var l1 = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 0)); - var blkred = trans.GetObject(Env.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; + var blkred = + trans.GetObject(Env.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; blkred?.AppendEntity(l1); trans.AddNewlyCreatedDBObject(l1, true); trans.Commit(); // dbtrans.Dispose(); } + [CommandMethod(nameof(Test_TextStyle))] public void Test_TextStyle() { @@ -51,12 +53,14 @@ public void Test_TextStyle() tr.TextStyleTable.Add("arial", FontTTF.Arial, 0.8); tr.TextStyleTable.Add("romas", FontTTF.Romans, 0.8); - - - tr.TextStyleTable.Add("daziti", ttr => { - ttr.FileName = "ascii.shx"; - ttr.BigFontFileName = "gbcbig.shx"; - }); + tr.TextStyleTable.Add( + "daziti", + ttr => + { + ttr.FileName = "ascii.shx"; + ttr.BigFontFileName = "gbcbig.shx"; + } + ); } [CommandMethod(nameof(Test_TextStyleChange))] @@ -64,9 +68,8 @@ public void Test_TextStyleChange() { using DBTrans tr = new(); - tr.TextStyleTable.AddWithChange("宋体1", "simfang.ttf", height: 5); tr.TextStyleTable.AddWithChange("仿宋体", "宋体.ttf"); tr.TextStyleTable.AddWithChange("fsgb2312", "Romans", "gbcbig"); } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestJig.cs b/tests/TestShared/TestJig.cs index 5bc95ea3fae75b5b9ae68ea99c2fd79ad52841fd..da75fe57e4094e21864cd379678e0db9d3474bed 100644 --- a/tests/TestShared/TestJig.cs +++ b/tests/TestShared/TestJig.cs @@ -1,8 +1,8 @@ -namespace Test; +namespace IFoxTest; using System.Windows.Forms; -public class Commands_Jig +public class CommandsJig { // 已在数据库的图元如何进入jig [CommandMethod(nameof(Test_Jig33))] @@ -17,7 +17,7 @@ public static void Test_Jig33() return; var oldSp = cir.StartPoint; JigEx? moveJig = null; - moveJig = new JigEx((mousePoint, drawEntitys) => { + moveJig = new JigEx((mousePoint, _) => { moveJig!.SetOptions(oldSp);// 回调过程中也可以修改基点 // cir.UpgradeOpen();// 已经提权了,所以这里不需要提权 cir.Move(cir.StartPoint, mousePoint); @@ -122,7 +122,7 @@ public void Test_Jig44() [CommandMethod(nameof(Test_MessageFilter))] public void Test_MessageFilter() { - var dm = Acap.DocumentManager; + var dm = Acaop.DocumentManager; var ed = dm.MdiActiveDocument.Editor; // Create and add our message filter @@ -171,7 +171,7 @@ public bool PreFilterMessage(ref Message m) [CommandMethod(nameof(Test_QuickText))] static public void Test_QuickText() { - var dm = Acap.DocumentManager; + var dm = Acaop.DocumentManager; var doc = dm.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; diff --git a/tests/TestShared/TestJigExTransient.cs b/tests/TestShared/TestJigExTransient.cs index 52eb3f4be1f074790dfdaf2fea4e84c8a5c3dfb7..a9ca4366fa4b486c0ae36ded94664cb620df1cd8 100644 --- a/tests/TestShared/TestJigExTransient.cs +++ b/tests/TestShared/TestJigExTransient.cs @@ -1,5 +1,4 @@ - -namespace Test; +namespace IFoxTest; public partial class Test { @@ -53,10 +52,7 @@ public void Test_JigExTransient() [CommandMethod(nameof(Test_JigExTransentDim))] public static void Test_JigExTransentDim() { - PromptPointOptions ppo = new("") - { - AppendKeywordsToMessage = false, - }; + PromptPointOptions ppo = new("") { AppendKeywordsToMessage = false }; List pts = new(); for (int i = 0; i < 3; i++) { @@ -70,7 +66,7 @@ public static void Test_JigExTransentDim() using DBTrans tr = new(); using RotatedDimension dimension = new(); - dimension.SetDatabaseDefaults();// cad16没有这个不显示 + dimension.SetDatabaseDefaults(); // cad16没有这个不显示 dimension.Rotation = 0; dimension.XLine1Point = pts[0]; dimension.XLine2Point = pts[1]; diff --git a/tests/TestShared/TestJson.cs b/tests/TestShared/TestJson.cs index 281e1b1bce4ee8e0a21e9aa11696d9f83b7ae2fd..4085aaed190396ca1183122b49357966c0519c75 100644 --- a/tests/TestShared/TestJson.cs +++ b/tests/TestShared/TestJson.cs @@ -12,16 +12,11 @@ public class TestJson [CommandMethod(nameof(JavaScriptSerializer))] public void JavaScriptSerializer() { - List RegisteredUsers = []; - RegisteredUsers.Add(0); - RegisteredUsers.Add(1); - RegisteredUsers.Add(2); - RegisteredUsers.Add(3); - - var serializedResult = System.Text.Json.JsonSerializer.Serialize(RegisteredUsers); - var deserializedResult = System.Text.Json.JsonSerializer.Deserialize>(serializedResult); + List registeredUsers = [0, 1, 2, 3]; - - + var serializedResult = System.Text.Json.JsonSerializer.Serialize(registeredUsers); + var deserializedResult = System.Text.Json.JsonSerializer.Deserialize>( + serializedResult + ); } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestLayer.cs b/tests/TestShared/TestLayer.cs index 62df5e1bf2723132947d5374c1f7b6d20389fbce..7effc76e644c60d082fcbd0afaa00fa90d046e7f 100644 --- a/tests/TestShared/TestLayer.cs +++ b/tests/TestShared/TestLayer.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestLayer { @@ -7,18 +7,25 @@ public void Test_LayerAdd0() { using DBTrans tr = new(); tr.LayerTable.Add("1"); - tr.LayerTable.Add("2", lt => { - lt.Color = Color.FromColorIndex(ColorMethod.ByColor, 1); - lt.LineWeight = LineWeight.LineWeight030; - }); + tr.LayerTable.Add( + "2", + lt => + { + lt.Color = Color.FromColorIndex(ColorMethod.ByColor, 1); + lt.LineWeight = LineWeight.LineWeight030; + } + ); tr.LayerTable.Remove("3"); tr.LayerTable.Delete("0"); - tr.LayerTable.Change("4", lt => { - lt.Color = Color.FromColorIndex(ColorMethod.ByColor, 2); - }); + tr.LayerTable.Change( + "4", + lt => + { + lt.Color = Color.FromColorIndex(ColorMethod.ByColor, 2); + } + ); } - // 添加图层 [CommandMethod(nameof(Test_LayerAdd1))] public void Test_LayerAdd1() @@ -35,20 +42,21 @@ public void Test_LayerAdd2() tr.LayerTable.Add("test2", 2); // tr.LayerTable["3"] = new LayerTableRecord(); } + // 删除图层 [CommandMethod(nameof(Test_LayerDel))] public void Test_LayerDel() { using DBTrans tr = new(); - tr.LayerTable.Remove("0"); // 删除图层 0 - tr.LayerTable.Remove("Defpoints");// 删除图层 Defpoints - tr.LayerTable.Remove("1"); // 删除不存在的图层 1 - tr.LayerTable.Remove("2"); // 删除有图元的图层 2 - tr.LayerTable.Remove("3"); // 删除图层 3 // 删除图层 3 + tr.LayerTable.Remove("0"); // 删除图层 0 + tr.LayerTable.Remove("Defpoints"); // 删除图层 Defpoints + tr.LayerTable.Remove("1"); // 删除不存在的图层 1 + tr.LayerTable.Remove("2"); // 删除有图元的图层 2 + tr.LayerTable.Remove("3"); // 删除图层 3 // 删除图层 3 tr.LayerTable.Remove("2"); // 测试是否能强制删除 } - + [CommandMethod(nameof(Test_PrintLayerName))] public void Test_PrintLayerName() { @@ -63,4 +71,4 @@ public void Test_PrintLayerName() break; } } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestLisp.cs b/tests/TestShared/TestLisp.cs index 4bd7b193b39beb6d5b61f31a5d4b7945ee7551f6..f94dce9f5566be5c1750f251b969478c42d5d4bc 100644 --- a/tests/TestShared/TestLisp.cs +++ b/tests/TestShared/TestLisp.cs @@ -1,10 +1,10 @@ -namespace Test; +namespace IFoxTest; public class TestLisp { // 定义lisp函数 - [LispFunction(nameof(LispTest_RunLisp))] - public static object LispTest_RunLisp(ResultBuffer rb) + [LispFunction(nameof(Test_RunLisp))] + public static object Test_RunLisp(ResultBuffer rb) { CmdTest_RunLisp(); return null!; @@ -67,7 +67,7 @@ public static void CmdTest_RunLisp() { // 测试方法1: (command "CmdTest_RunLisp1") // 测试方式2: (LispTest_RunLisp) - var dm = Acap.DocumentManager; + var dm = Acaop.DocumentManager; var doc = dm.MdiActiveDocument; var ed = doc.Editor; @@ -88,10 +88,8 @@ public static void CmdTest_RunLisp() if (flag == EditorEx.RunLispFlag.AdsQueueexpr) { // 同步 - Env.Editor.RunLisp("(setq a 10)(princ)", - EditorEx.RunLispFlag.AdsQueueexpr); - Env.Editor.RunLisp("(princ a)", - EditorEx.RunLispFlag.AdsQueueexpr);// 成功输出 + Env.Editor.RunLisp("(setq a 10)(princ)"); + Env.Editor.RunLisp("(princ a)");// 成功输出 } else if (flag == EditorEx.RunLispFlag.AcedEvaluateLisp) { @@ -115,8 +113,7 @@ public static void CmdTest_RunLisp() var str = "(setq c 40)(princ)"; Env.Editor.RunLisp(str, EditorEx.RunLispFlag.SendStringToExecute); // 异步,后发送 - Env.Editor.RunLisp("(princ c)", - EditorEx.RunLispFlag.AdsQueueexpr); // 同步,先发送了,输出是null + Env.Editor.RunLisp("(princ c)"); // 同步,先发送了,输出是null } } } \ No newline at end of file diff --git a/tests/TestShared/TestLoop.cs b/tests/TestShared/TestLoop.cs index 438253ae5a8b7e03c3a0660e9d31409db966afb8..b09f0065d931c117e1d3af75d024f56a159735c7 100644 --- a/tests/TestShared/TestLoop.cs +++ b/tests/TestShared/TestLoop.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestLoop { [CommandMethod(nameof(Test_LoopList))] @@ -14,12 +14,12 @@ public void Test_LoopList() 5 }; - Env.Print(loop); + loop.Print(); loop.SetFirst(loop.Last!); - Env.Print(loop); - Env.Print(loop.Min()); + loop.Print(); + loop.Min().Print(); loop.SetFirst(new LoopListNode(loop.Min(), loop)); - Env.Print(loop); + loop.Print(); } } \ No newline at end of file diff --git a/tests/TestShared/TestMarshal.cs b/tests/TestShared/TestMarshal.cs index 80398e2910a1312defdfbd13c97c6b5cf2c834b1..93c588e27e98dfb22c1babd74f7c55a7a0127a64 100644 --- a/tests/TestShared/TestMarshal.cs +++ b/tests/TestShared/TestMarshal.cs @@ -70,7 +70,7 @@ public void Test_ImplicitPoint3D() [CommandMethod(nameof(Test_Marshal))] public void Test_Marshal() { - var dm = Acap.DocumentManager; + var dm = Acaop.DocumentManager; var doc = dm.MdiActiveDocument; var ed = doc.Editor; // 0x01 如何修改Point3d内容? diff --git a/tests/TestShared/TestMirrorFile.cs b/tests/TestShared/TestMirrorFile.cs index 76ac0337f5b8d657fbe37014ed74e07d24699c46..b45d15b646dfb7ba9ff49b2b99418205659b011c 100644 --- a/tests/TestShared/TestMirrorFile.cs +++ b/tests/TestShared/TestMirrorFile.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class MirrorFile { @@ -14,22 +14,25 @@ public static void CmdTest_MirrorFile() { var yaxis = new Point3d(0, 1, 0); using DBTrans tr = new(file, fileOpenMode: FileOpenMode.OpenForReadAndReadShare); - tr.BlockTable.Change(tr.ModelSpace.ObjectId, modelSpace => { - modelSpace.ForEach(entId => { - var dbText = tr.GetObject(entId, OpenMode.ForRead)!; - if (dbText is null) - return; + tr.BlockTable.Change( + tr.ModelSpace.ObjectId, + modelSpace => + { + modelSpace.ForEach(entId => + { + var dbText = tr.GetObject(entId)!; - dbText.UpgradeOpen(); - var pos = dbText.Position; - // text.Move(pos, Point3d.Origin); - // Y轴 - dbText.Mirror(Point3d.Origin, yaxis); - // text.Move(Point3d.Origin, pos); - dbText.DowngradeOpen(); - }); - }); - var ver = (DwgVersion)27;/*AC1021 AutoCAD 2007/2008/2009.*/ + dbText.UpgradeOpen(); + var pos = dbText.Position; + // text.Move(pos, Point3d.Origin); + // Y轴 + dbText.Mirror(Point3d.Origin, yaxis); + // text.Move(Point3d.Origin, pos); + dbText.DowngradeOpen(); + }); + } + ); + var ver = (DwgVersion)27; /*AC1021 AutoCAD 2007/2008/2009.*/ tr.Database.SaveAs(fileSave, ver); } @@ -42,32 +45,41 @@ public static void CmdTest_MirrorFile2() { using DBTrans tr = new(file); - tr.Task(() => { + tr.Task(() => + { var yaxis = new Point3d(0, 1, 0); - tr.BlockTable.Change(tr.ModelSpace.ObjectId, modelSpace => { - modelSpace.ForEach(entId => { - var entity = tr.GetObject(entId, OpenMode.ForWrite)!; - if (entity is DBText dbText) + tr.BlockTable.Change( + tr.ModelSpace.ObjectId, + modelSpace => + { + modelSpace.ForEach(entId => { - dbText.Mirror(Point3d.Origin, yaxis); - dbText.IsMirroredInX = true; // 这句将导致文字偏移 + var entity = tr.GetObject(entId, OpenMode.ForWrite)!; + if (entity is DBText dbText) + { + dbText.Mirror(Point3d.Origin, yaxis); + dbText.IsMirroredInX = true; // 这句将导致文字偏移 - // 指定文字的垂直对齐方式 - if (dbText.VerticalMode == TextVerticalMode.TextBase) - dbText.VerticalMode = TextVerticalMode.TextBottom; + // 指定文字的垂直对齐方式 + if (dbText.VerticalMode == TextVerticalMode.TextBase) + dbText.VerticalMode = TextVerticalMode.TextBottom; - // 指定文字的水平对齐方式 - dbText.HorizontalMode = dbText.HorizontalMode switch - { - TextHorizontalMode.TextLeft => TextHorizontalMode.TextRight, - TextHorizontalMode.TextRight => TextHorizontalMode.TextLeft, - _ => dbText.HorizontalMode - }; - dbText.AdjustAlignment(tr.Database); - } - }); - }); + // 指定文字的水平对齐方式 + dbText.HorizontalMode = dbText.HorizontalMode switch + { + TextHorizontalMode.TextLeft => TextHorizontalMode.TextRight, + TextHorizontalMode.TextRight => TextHorizontalMode.TextLeft, + _ => dbText.HorizontalMode, + }; + dbText.AdjustAlignment(tr.Database); + } + }); + } + ); }); - tr.Database.SaveAs(fileSave, (DwgVersion)27 /*AC1021 AutoCAD 2007/2008/2009.*/); + tr.Database.SaveAs( + fileSave, + (DwgVersion)27 /*AC1021 AutoCAD 2007/2008/2009.*/ + ); } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestPoint.cs b/tests/TestShared/TestPoint.cs index b69afeaec8a2e1a781ed669b371fee360d94c7e9..a4c7d386a884e411ae8706f3ddb7e21896405e4c 100644 --- a/tests/TestShared/TestPoint.cs +++ b/tests/TestShared/TestPoint.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestPoint { #if false @@ -22,10 +22,10 @@ public void Test_Endtoend() { var pts = new Point2dCollection { - new(0, 0), - new(0, 1), - new(1, 1), - new(1, 0) + new Point2d(0, 0), + new Point2d(0, 1), + new Point2d(1, 1), + new Point2d(1, 0) }; @@ -42,10 +42,10 @@ public void Test_Endtoend() Env.Printl("--------"); var ptss = new Point3dCollection { - new(0, 0,0), - new(0, 1,0), - new(1, 1,0), - new(1, 0,0) + new Point3d(0, 0,0), + new Point3d(0, 1,0), + new Point3d(1, 1,0), + new Point3d(1, 0,0) }; foreach (Point3d pt in ptss) @@ -108,44 +108,44 @@ public void Test_PtGethash() [CommandMethod(nameof(Test_Point3dHash))] public void Test_Point3dHash() { - Env.Print($"4位小数的hash:{new Point3d(0.0_001, 0.0_002, 0.0).GetHashCode()}"); - Env.Print($"5位小数的hash:{new Point3d(0.00_001, 0.00_002, 0.0).GetHashCode()}"); - Env.Print($"6位小数的hash:{new Point3d(0.000_001, 0.000_002, 0.0).GetHashCode()}"); - Env.Print($"7位小数的hash:{new Point3d(0.000_0_001, 0.000_0_002, 0.0).GetHashCode()}"); - Env.Print($"8位小数的hash:{new Point3d(0.000_00_001, 0.000_00_002, 0.0).GetHashCode()}"); - Env.Print($"9位小数的hash:{new Point3d(0.000_000_001, 0.000_000_002, 0.0).GetHashCode()}"); - Env.Print($"10位小数的hash:{new Point3d(0.000_000_0001, 0.000_000_0002, 0.0).GetHashCode()}"); - Env.Print($"10位小数的hash:{new Point3d(0.000_000_0001, 0.000_000_0001, 0.0).GetHashCode()}"); + $"4位小数的hash:{new Point3d(0.0_001, 0.0_002, 0.0).GetHashCode()}".Print(); + $"5位小数的hash:{new Point3d(0.00_001, 0.00_002, 0.0).GetHashCode()}".Print(); + $"6位小数的hash:{new Point3d(0.000_001, 0.000_002, 0.0).GetHashCode()}".Print(); + $"7位小数的hash:{new Point3d(0.000_0_001, 0.000_0_002, 0.0).GetHashCode()}".Print(); + $"8位小数的hash:{new Point3d(0.000_00_001, 0.000_00_002, 0.0).GetHashCode()}".Print(); + $"9位小数的hash:{new Point3d(0.000_000_001, 0.000_000_002, 0.0).GetHashCode()}".Print(); + $"10位小数的hash:{new Point3d(0.000_000_0001, 0.000_000_0002, 0.0).GetHashCode()}".Print(); + $"10位小数的hash:{new Point3d(0.000_000_0001, 0.000_000_0001, 0.0).GetHashCode()}".Print(); - Env.Print($"11位小数的hash:{new Point3d(0.000_000_000_01, 0.000_000_000_02, 0.0).GetHashCode()}"); - Env.Print($"11位小数的hash:{new Point3d(0.000_000_000_01, 0.000_000_000_01, 0.0).GetHashCode()}"); + $"11位小数的hash:{new Point3d(0.000_000_000_01, 0.000_000_000_02, 0.0).GetHashCode()}".Print(); + $"11位小数的hash:{new Point3d(0.000_000_000_01, 0.000_000_000_01, 0.0).GetHashCode()}".Print(); - Env.Print($"12位小数的hash:{new Point3d(0.000_000_000_001, 0.000_000_000_002, 0.0).GetHashCode()}"); - Env.Print($"12位小数的hash:{new Point3d(0.000_000_000_001, 0.000_000_000_001, 0.0).GetHashCode()}"); + $"12位小数的hash:{new Point3d(0.000_000_000_001, 0.000_000_000_002, 0.0).GetHashCode()}".Print(); + $"12位小数的hash:{new Point3d(0.000_000_000_001, 0.000_000_000_001, 0.0).GetHashCode()}".Print(); - Env.Print($"13位小数的hash:{new Point3d(0.000_000_000_0001, 0.000_000_000_0002, 0.0).GetHashCode()}"); - Env.Print($"13位小数的hash:{new Point3d(0.000_000_000_0001, 0.000_000_000_0001, 0.0).GetHashCode()}"); + $"13位小数的hash:{new Point3d(0.000_000_000_0001, 0.000_000_000_0002, 0.0).GetHashCode()}".Print(); + $"13位小数的hash:{new Point3d(0.000_000_000_0001, 0.000_000_000_0001, 0.0).GetHashCode()}".Print(); - Env.Print($"14位小数的hash:{new Point3d(0.000_000_000_000_01, 0.000_000_000_000_02, 0.0).GetHashCode()}"); - Env.Print($"14位小数的hash:{new Point3d(0.000_000_000_000_01, 0.000_000_000_000_01, 0.0).GetHashCode()}"); + $"14位小数的hash:{new Point3d(0.000_000_000_000_01, 0.000_000_000_000_02, 0.0).GetHashCode()}".Print(); + $"14位小数的hash:{new Point3d(0.000_000_000_000_01, 0.000_000_000_000_01, 0.0).GetHashCode()}".Print(); - Env.Print($"15位小数的hash:{new Point3d(0.000_000_000_000_001, 0.000_000_000_000_002, 0.0).GetHashCode()}"); - Env.Print($"15位小数的hash:{new Point3d(0.000_000_000_000_001, 0.000_000_000_000_001, 0.0).GetHashCode()}"); + $"15位小数的hash:{new Point3d(0.000_000_000_000_001, 0.000_000_000_000_002, 0.0).GetHashCode()}".Print(); + $"15位小数的hash:{new Point3d(0.000_000_000_000_001, 0.000_000_000_000_001, 0.0).GetHashCode()}".Print(); - Env.Print($"16位小数的hash:{new Point3d(0.000_000_000_000_000_1, 0.000_000_000_000_000_2, 0.0).GetHashCode()}"); - Env.Print($"16位小数的hash:{new Point3d(0.000_000_000_000_000_1, 0.000_000_000_000_000_1, 0.0).GetHashCode()}"); + $"16位小数的hash:{new Point3d(0.000_000_000_000_000_1, 0.000_000_000_000_000_2, 0.0).GetHashCode()}".Print(); + $"16位小数的hash:{new Point3d(0.000_000_000_000_000_1, 0.000_000_000_000_000_1, 0.0).GetHashCode()}".Print(); - Env.Print($"17位小数的hash:{new Point3d(0.000_000_000_000_000_01, 0.000_000_000_000_000_02, 0.0).GetHashCode()}"); - Env.Print($"17位小数的hash:{new Point3d(0.000_000_000_000_000_01, 0.000_000_000_000_000_01, 0.0).GetHashCode()}"); + $"17位小数的hash:{new Point3d(0.000_000_000_000_000_01, 0.000_000_000_000_000_02, 0.0).GetHashCode()}".Print(); + $"17位小数的hash:{new Point3d(0.000_000_000_000_000_01, 0.000_000_000_000_000_01, 0.0).GetHashCode()}".Print(); - Env.Print($"18位小数的hash:{new Point3d(0.000_000_000_000_000_001, 0.000_000_000_000_000_002, 0.0).GetHashCode()}"); - Env.Print($"18位小数的hash:{new Point3d(0.000_000_000_000_000_001, 0.000_000_000_000_000_001, 0.0).GetHashCode()}"); + $"18位小数的hash:{new Point3d(0.000_000_000_000_000_001, 0.000_000_000_000_000_002, 0.0).GetHashCode()}".Print(); + $"18位小数的hash:{new Point3d(0.000_000_000_000_000_001, 0.000_000_000_000_000_001, 0.0).GetHashCode()}".Print(); - Env.Print($"19位小数的hash:{new Point3d(0.000_000_000_000_000_000_1, 0.000_000_000_000_000_000_2, 0.0).GetHashCode()}"); - Env.Print($"19位小数的hash:{new Point3d(0.000_000_000_000_000_000_1, 0.000_000_000_000_000_000_1, 0.0).GetHashCode()}"); + $"19位小数的hash:{new Point3d(0.000_000_000_000_000_000_1, 0.000_000_000_000_000_000_2, 0.0).GetHashCode()}".Print(); + $"19位小数的hash:{new Point3d(0.000_000_000_000_000_000_1, 0.000_000_000_000_000_000_1, 0.0).GetHashCode()}".Print(); - Env.Print($"20位小数的hash:{new Point3d(0.000_000_000_000_000_000_01, 0.000_000_000_000_000_000_02, 0.0).GetHashCode()}"); - Env.Print($"20位小数的hash:{new Point3d(0.000_000_000_000_000_000_01, 0.000_000_000_000_000_000_01, 0.0).GetHashCode()}"); + $"20位小数的hash:{new Point3d(0.000_000_000_000_000_000_01, 0.000_000_000_000_000_000_02, 0.0).GetHashCode()}".Print(); + $"20位小数的hash:{new Point3d(0.000_000_000_000_000_000_01, 0.000_000_000_000_000_000_01, 0.0).GetHashCode()}".Print(); } [CommandMethod(nameof(Test_ListEqualspeed))] diff --git a/tests/TestShared/TestPointEx.cs b/tests/TestShared/TestPointEx.cs index 39ec186514fdec152ece92e8a84e23f52067743d..f28f61972a7543898ed346bd81d8442fc2ab3d7e 100644 --- a/tests/TestShared/TestPointEx.cs +++ b/tests/TestShared/TestPointEx.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestPointEx { diff --git a/tests/TestShared/TestPointOnRegion.cs b/tests/TestShared/TestPointOnRegion.cs index 62996a70d0b3672950126ea3be1c8e5371df844d..ff86085a67c02ad31788e122c137cf8dfd16f2b6 100644 --- a/tests/TestShared/TestPointOnRegion.cs +++ b/tests/TestShared/TestPointOnRegion.cs @@ -2,8 +2,8 @@ public static class TestPointOnRegion { - [CommandMethod(nameof(TestPointOnRegionCommand))] - public static void TestPointOnRegionCommand() + [CommandMethod(nameof(Test_PointOnRegionCommand))] + public static void Test_PointOnRegionCommand() { var r1 = Env.Editor.GetEntity("\n选择多段线"); if (r1.Status != PromptStatus.OK) @@ -21,4 +21,4 @@ public static void TestPointOnRegionCommand() stretchPoints.PointOnRegion(pt).Print(); } } -} \ No newline at end of file +} diff --git a/tests/TestShared/TestQuadTree.cs b/tests/TestShared/TestQuadTree.cs index 140d73c437cfebefb19f735a2981567ab9078883..5d80e7fd46e294b24c4940a3f27fb7d489585ab2 100644 --- a/tests/TestShared/TestQuadTree.cs +++ b/tests/TestShared/TestQuadTree.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; /* * 这里属于用户调用例子, @@ -8,33 +8,35 @@ public class CadEntity : QuadEntity { public ObjectId ObjectId; + // 这里加入其他字段 - public List? Link;// 碰撞链 + public List? Link; // 碰撞链 public System.Drawing.Color Color; public double Angle; - public CadEntity(ObjectId objectId, Rect box) : base(box) + + public CadEntity(ObjectId objectId, Rect box) + : base(box) { ObjectId = objectId; } + public int CompareTo(CadEntity? other) { if (other == null) return -1; return GetHashCode() ^ other.GetHashCode(); } + public override int GetHashCode() { return (base.GetHashCode(), ObjectId.GetHashCode()).GetHashCode(); } } - - - - public partial class TestQuadTree { QuadTree? _quadTreeRoot; + #region 四叉树创建并加入 [CommandMethod(nameof(Test_QuadTree))] public void Test_QuadTree() @@ -71,12 +73,12 @@ public void Test_QuadTree() // 数据库边界 var pl = dbExt.ToPoints(); var databaseBoundary = new List<(Point3d, double, double, double)> - { - (new Point3d(pl[0].X,pl[0].Y,0),0,0,0), - (new Point3d(pl[1].X,pl[1].Y,0),0,0,0), - (new Point3d(pl[2].X,pl[2].Y,0),0,0,0), - (new Point3d(pl[3].X,pl[3].Y,0),0,0,0), - }; + { + (new Point3d(pl[0].X, pl[0].Y, 0), 0, 0, 0), + (new Point3d(pl[1].X, pl[1].Y, 0), 0, 0, 0), + (new Point3d(pl[2].X, pl[2].Y, 0), 0, 0, 0), + (new Point3d(pl[3].X, pl[3].Y, 0), 0, 0, 0), + }; tr.CurrentSpace.AddEntity(databaseBoundary.CreatePolyline(action: e => e.Closed = true)); // 生成多少个图元,导致cad会令undo出错(八叉树深度过大 treemax) @@ -84,38 +86,50 @@ public void Test_QuadTree() int maximumItems = 1000; // 随机图元生成 - List ces = new(); // 用于随机获取图元 - Tools.TestTimes(1, "画圆消耗时间:", () => { - // 生成外边界和随机圆形 - var grc = GenerateRandomCircle(maximumItems, dbExt); - foreach (var ent in grc) + List ces = new(); // 用于随机获取图元 + Tools.TestTimes( + 1, + "画圆消耗时间:", + () => { - // 初始化图元颜色 - ent!.ColorIndex = 1; // Color.FromRgb(0, 0, 0);// 黑色 - var edge = ent.GeometricExtents; - // 四叉树数据 - var entRect = new Rect(edge.MinPoint.X, edge.MinPoint.Y, edge.MaxPoint.X, edge.MaxPoint.Y); - var entId = tr.CurrentSpace.AddEntity(ent); - - var ce = new CadEntity(entId, entRect) + // 生成外边界和随机圆形 + var grc = GenerateRandomCircle(maximumItems, dbExt); + foreach (var ent in grc) { - Color = RandomEx.NextColor() - }; - ces.Add(ce); - /*加入随机点*/ - var p = edge.MinPoint + new Vector3d(10, 10, 0); - entRect = new Rect(p.Point2d(), p.Point2d()); - entId = tr.CurrentSpace.AddEntity(new DBPoint(p)); - var dbPointCe = new CadEntity(entId, entRect); - ces.Add(dbPointCe); + // 初始化图元颜色 + ent!.ColorIndex = 1; // Color.FromRgb(0, 0, 0);// 黑色 + var edge = ent.GeometricExtents; + // 四叉树数据 + var entRect = new Rect( + edge.MinPoint.X, + edge.MinPoint.Y, + edge.MaxPoint.X, + edge.MaxPoint.Y + ); + var entId = tr.CurrentSpace.AddEntity(ent); + + var ce = new CadEntity(entId, entRect) { Color = RandomEx.NextColor() }; + ces.Add(ce); + /*加入随机点*/ + var p = edge.MinPoint + new Vector3d(10, 10, 0); + entRect = new Rect(p.Point2d(), p.Point2d()); + entId = tr.CurrentSpace.AddEntity(new DBPoint(p)); + var dbPointCe = new CadEntity(entId, entRect); + ces.Add(dbPointCe); + } } - });// 30万图元±3秒.cad2021 + ); // 30万图元±3秒.cad2021 // 测试只加入四叉树的时间 - Tools.TestTimes(1, "插入四叉树时间:", () => { - for (int i = 0; i < ces.Count; i++) - _quadTreeRoot.Insert(ces[i]); - });// 30万图元±0.7秒.cad2021 + Tools.TestTimes( + 1, + "插入四叉树时间:", + () => + { + for (int i = 0; i < ces.Count; i++) + _quadTreeRoot.Insert(ces[i]); + } + ); // 30万图元±0.7秒.cad2021 tr.Editor?.WriteMessage($"\n加入图元数量:{maximumItems}"); } @@ -173,20 +187,26 @@ public void CmdTest_QuadTree20() List ss = []; int entnum = 0; - var time1 = Timer.RunTime(() => { - db.Action(tr => { - db.TraverseBlockTable(tr, btRec => { - if (!btRec.IsLayout)// 布局跳过 - return false; - - foreach (var item in btRec) + var time1 = Timer.RunTime(() => + { + db.Action(tr => + { + db.TraverseBlockTable( + tr, + btRec => { - // var ent = item.ToEntity(tr); - ss.Add(item); - ++entnum;// 图元数量:100000, 遍历全图时间:0.216秒 CmdTest_QuadTree2 + if (!btRec.IsLayout) // 布局跳过 + return false; + + foreach (var item in btRec) + { + // var ent = item.ToEntity(tr); + ss.Add(item); + ++entnum; // 图元数量:100000, 遍历全图时间:0.216秒 CmdTest_QuadTree2 + } + return false; } - return false; - }); + ); }); }); ed.WriteMessage($"\n图元数量:{entnum}, 遍历全图时间:{time1 / 1000.0}秒"); @@ -214,7 +234,10 @@ void AddQuadTreeRoot(Database db, Editor ed, List ss) } else { - dbExt = new Rect(dbExtent.Value.MinPoint.Point2d(), dbExtent.Value.MaxPoint.Point2d()); + dbExt = new Rect( + dbExtent.Value.MinPoint.Point2d(), + dbExtent.Value.MaxPoint.Point2d() + ); } _quadTreeRoot = new(dbExt); } @@ -229,24 +252,24 @@ void AddQuadTreeRoot(Database db, Editor ed, List ss) */ List ces = new(); - db.Action(tr => { - ss.ForEach(entId => { + db.Action(tr => + { + ss.ForEach(entId => + { var ent = entId.ToEntity(tr); if (ent is null) return; var edge = new EdgeEntity(ent); // 四叉树数据 - var ce = new CadEntity(entId, edge.Edge) - { - Color = Utility.RandomColor - }; + var ce = new CadEntity(entId, edge.Edge) { Color = Utility.RandomColor }; ces.Add(ce); edge.Dispose(); }); }); - var time2 = Timer.RunTime(() => { + var time2 = Timer.RunTime(() => + { _quadTreeRoot.Insert(ces); }); ed.WriteMessage($"\n图元数量:{ces.Count}, 加入四叉树时间:{time2 / 1000.0}秒"); @@ -301,27 +324,31 @@ public void CmdTest_CreateNodesRect() // 报错: 0x6B00500A (msvcr80.dll)处(位于 acad.exe 中)引发的异常: 0xC0000005: 写入位置 0xFFE00000 时发生访问冲突。 // 画出所有的四叉树节点边界,因为事务放在外面引起 List nodeRects = []; - _quadTreeRoot.ForEach(node => { + _quadTreeRoot.ForEach(node => + { nodeRects.Add(node); return false; }); List rectIds = []; - foreach (var item in nodeRects)// Count = 97341 当数量接近这个量级 + foreach (var item in nodeRects) // Count = 97341 当数量接近这个量级 { - db.Action(tr => { + db.Action(tr => + { var pts = item.ToPoints(); var rec = EntityAdd.AddPolyLineToEntity(pts.ToPoint2d()); rec.ColorIndex = 250; rectIds.Add(tr.AddEntityToMsPs(db, rec)); }); } - db.Action(tr => { + db.Action(tr => + { db.CoverGroup(tr, rectIds); }); // 获取四叉树深度 int dep = 0; - _quadTreeRoot.ForEach(node => { + _quadTreeRoot.ForEach(node => + { dep = dep > node.Depth ? dep : node.Depth; return false; }); @@ -365,7 +392,8 @@ void Ssget(QuadTreeSelectMode mode) // 仿选择集 var ces = _quadTreeRoot.Query(rect, mode); - ces.ForEach(item => { + ces.ForEach(item => + { var ent = tr.GetObject(item.ObjectId, OpenMode.ForWrite); ent!.Color = Color.FromColor(item.Color); ent.DowngradeOpen(); @@ -386,16 +414,18 @@ void Ssget(QuadTreeSelectMode mode) return null; var optionsB = new PromptCornerOptions(Environment.NewLine + "输入矩形角点2:", pprA.Value) { - UseDashedLine = true,// 使用虚线 - AllowNone = true,// 回车 + UseDashedLine = true, // 使用虚线 + AllowNone = true, // 回车 }; var pprB = ed.GetCorner(optionsB); if (pprB.Status != PromptStatus.OK) return null!; - return new Rect(new Point2d(pprA.Value.X, pprA.Value.Y), - new Point2d(pprB.Value.X, pprB.Value.Y), - true); + return new Rect( + new Point2d(pprA.Value.X, pprA.Value.Y), + new Point2d(pprB.Value.X, pprB.Value.Y), + true + ); } #endregion } @@ -454,4 +484,4 @@ void Ssget(QuadTreeSelectMode mode) // } // }); // } -// } \ No newline at end of file +// } diff --git a/tests/TestShared/TestSelectfilter.cs b/tests/TestShared/TestSelectfilter.cs index 8cdb2cc9f9b188067c7aef6f8255e3379cc9a7c7..88a53d9b5ab6b591f5e0718b831400a60cb17554 100644 --- a/tests/TestShared/TestSelectfilter.cs +++ b/tests/TestShared/TestSelectfilter.cs @@ -1,19 +1,22 @@ -namespace Test; +namespace IFoxTest; -public class Testselectfilter { +public class TestSelectFilter +{ [CommandMethod(nameof(Test_Filter))] - public void Test_Filter() { + public void Test_Filter() + { var p = new Point3d(10, 10, 0); - var f = OpFilter.Build( - e => !(e.Dxf(0) == "line" & e.Dxf(8) == "0") - | e.Dxf(0) != "circle" & e.Dxf(8) == "2" & e.Dxf(10) >= p); - - - var f2 = OpFilter.Build( - e => e.Or( - !e.And(e.Dxf(0) == "line", e.Dxf(8) == "0"), - e.And(e.Dxf(0) != "circle", e.Dxf(8) == "2", - e.Dxf(10) <= new Point3d(10, 10, 0)))); + var f = OpFilter.Build(e => + !(e.Dxf(0) == "line" & e.Dxf(8) == "0") + | e.Dxf(0) != "circle" & e.Dxf(8) == "2" & e.Dxf(10) >= p + ); + + var f2 = OpFilter.Build(e => + e.Or( + !e.And(e.Dxf(0) == "line", e.Dxf(8) == "0"), + e.And(e.Dxf(0) != "circle", e.Dxf(8) == "2", e.Dxf(10) <= new Point3d(10, 10, 0)) + ) + ); SelectionFilter f3 = f; SelectionFilter f4 = f2; @@ -22,30 +25,34 @@ public void Test_Filter() { } [CommandMethod(nameof(Test_Selectanpoint))] - public void Test_Selectanpoint() { + public void Test_Selectanpoint() + { var sel2 = Env.Editor.SelectAtPoint(new Point3d(0, 0, 0)); Env.Editor.WriteMessage(""); } } -public class TestSelectObjectType { +public class TestSelectObjectType +{ [CommandMethod(nameof(Test_Select_type))] - public void Test_Select_type() { + public void Test_Select_type() + { var sel = Env.Editor.SSGet(); - if (sel.Status != PromptStatus.OK) return; + if (sel.Status != PromptStatus.OK) + return; var ids = sel.Value.GetObjectIds(); - foreach (var item in ids) { + foreach (var item in ids) + { item.Print(); } var dxfName = RXObject.GetClass(typeof(Dimension)).DxfName; dxfName.Print(); var idss = sel.Value.GetObjectIds(); - foreach (var item in idss) { + foreach (var item in idss) + { item.Print(); item.ObjectClass.DxfName.Print(); } - } - -} \ No newline at end of file +} diff --git a/tests/TestShared/TestSingleKeyWordHook.cs b/tests/TestShared/TestSingleKeyWordHook.cs index 73fe216cf7e19ba408589117d8f99a58290527bb..7cbbbb6d2eb2bc7efd9cbed74639033d078c2570 100644 --- a/tests/TestShared/TestSingleKeyWordHook.cs +++ b/tests/TestShared/TestSingleKeyWordHook.cs @@ -1,8 +1,8 @@ -namespace TestShared; +namespace IFoxTest; public static class TestSingleKeyWordHook { - [CommandMethod(nameof(TestSingleKeyWordHookDemo))] - public static void TestSingleKeyWordHookDemo() + [CommandMethod(nameof(Test_SingleKeyWordHookDemo))] + public static void Test_SingleKeyWordHookDemo() { var line1 = new Line(Point3d.Origin, new Point3d(100, 100, 0)); line1.SetDatabaseDefaults(); diff --git a/tests/TestShared/TestText.cs b/tests/TestShared/TestText.cs index b25dab69dab226d5dbcbc7708afb9c7bb8240209..b9eb374827984ba10a5feb0f8550dfa8139d3342 100644 --- a/tests/TestShared/TestText.cs +++ b/tests/TestShared/TestText.cs @@ -1,49 +1,73 @@ - -namespace TestShared; +namespace TestShared; public class TestText { - [CommandMethod(nameof(TestDBText))] public void TestDBText() { using var tr = new DBTrans(); - tr.CurrentSpace.AddEntity(DBTextEx.CreateDBText(new(-1, -1, 0), "123", 2.5, action:t=> t.ColorIndex = 1)); + tr.CurrentSpace.AddEntity( + DBTextEx.CreateDBText(new Point3d(-1, -1, 0), "123", 2.5, action: t => t.ColorIndex = 1) + ); - tr.CurrentSpace.AddEntity(DBTextEx.CreateDBText(new(-1, -1, 0), "123", 2.5, action: t => { - t.Justify = AttachmentPoint.BaseCenter; - t.AlignmentPoint = new(1, 1, 0); - t.ColorIndex = 2; - })); + tr.CurrentSpace.AddEntity( + DBTextEx.CreateDBText( + new Point3d(-1, -1, 0), + "123", + 2.5, + action: t => + { + t.Justify = AttachmentPoint.BaseCenter; + t.AlignmentPoint = new Point3d(1, 1, 0); + t.ColorIndex = 2; + } + ) + ); } [CommandMethod(nameof(TestBackDBText))] public void TestBackDBText() { using var tr = new DBTrans(@"C:\Users\vic\Desktop\test.dwg"); - tr.CurrentSpace.AddEntity(DBTextEx.CreateDBText(new(-1, -1, 0), "123", 2.5, action: t => t.ColorIndex = 1)); + tr.CurrentSpace.AddEntity( + DBTextEx.CreateDBText(new Point3d(-1, -1, 0), "123", 2.5, action: t => t.ColorIndex = 1) + ); - tr.CurrentSpace.AddEntity(DBTextEx.CreateDBText(new(-1, -1, 0), "123", 2.5, action: t => - { - t.Justify = AttachmentPoint.BaseCenter; - t.AlignmentPoint = new(1, 1, 0); - t.ColorIndex = 2; - })); + tr.CurrentSpace.AddEntity( + DBTextEx.CreateDBText( + new Point3d(-1, -1, 0), + "123", + 2.5, + action: t => + { + t.Justify = AttachmentPoint.BaseCenter; + t.AlignmentPoint = new Point3d(1, 1, 0); + t.ColorIndex = 2; + } + ) + ); tr.Database.SaveDwgFile(); } - - [CommandMethod(nameof(TestMText))] public void TestMText() { using var tr = new DBTrans(); - tr.CurrentSpace.AddEntity(MTextEx.CreateMText(new(5, 5, 0), "123", 2.5, action: t => t.ColorIndex = 1)); + tr.CurrentSpace.AddEntity( + MTextEx.CreateMText(new Point3d(5, 5, 0), "123", 2.5, action: t => t.ColorIndex = 1) + ); - tr.CurrentSpace.AddEntity(MTextEx.CreateMText(new(5, 5, 0), "123", 2.5, action: t => { - t.Attachment = AttachmentPoint.TopCenter; - t.ColorIndex = 2; - })); + tr.CurrentSpace.AddEntity( + MTextEx.CreateMText( + new Point3d(5, 5, 0), + "123", + 2.5, + action: t => + { + t.Attachment = AttachmentPoint.TopCenter; + t.ColorIndex = 2; + } + ) + ); } - } diff --git a/tests/TestShared/TestXdata.cs b/tests/TestShared/TestXdata.cs index a0c10afdeafa950b4893b6ef0445bfb9baa7fb32..e0f4b3e927094fc138b7536b564c18333c30937f 100644 --- a/tests/TestShared/TestXdata.cs +++ b/tests/TestShared/TestXdata.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public class TestXdata { @@ -38,7 +38,7 @@ public void Test_AddXdata() } }; - var line1 = new Line(new(0, 0, 0), new(2, 0, 0)); + var line1 = new Line(new Point3d(0, 0, 0), new Point3d(2, 0, 0)); line1.XData = new XDataList() { { DxfCode.ExtendedDataRegAppName, "myapp1" }, // 可以用dxfcode和int表示组码 diff --git a/tests/TestShared/TestXrefEx.cs b/tests/TestShared/TestXrefEx.cs index 7fa7f3e8b7ae0542f611061f082e48ac44c44130..3fc944d8f4e89868b8dcbdb43219eb58552a53b2 100644 --- a/tests/TestShared/TestXrefEx.cs +++ b/tests/TestShared/TestXrefEx.cs @@ -1,14 +1,16 @@ -namespace Test; +namespace IFoxTest; -public class TestCmd_BindXrefs +public class TestCmdBindXrefs { //后台绑定 [CommandMethod(nameof(Test_Bind1))] public static void Test_Bind1() { - string fileName = @"D:\Test.dwg"; - using var tr = new DBTrans(fileName, - fileOpenMode: FileOpenMode.OpenForReadAndAllShare/*后台绑定特别注意*/); + const string fileName = @"D:\Test.dwg"; + using var tr = new DBTrans( + fileName, + fileOpenMode: FileOpenMode.OpenForReadAndAllShare /*后台绑定特别注意*/ + ); tr.XrefFactory(XrefModes.Bind); tr.Database.SaveDwgFile(); } @@ -21,4 +23,4 @@ public static void Test_Bind2() tr.XrefFactory(XrefModes.Bind); tr.Database.SaveDwgFile(); } -} \ No newline at end of file +} diff --git a/tests/TestShared/Timer.cs b/tests/TestShared/Timer.cs index 6bd03f1efb38e28c6da60571626f24edcdbafb56..95ebce9a715042ed0bb1eb18594bf69e36afe691 100644 --- a/tests/TestShared/Timer.cs +++ b/tests/TestShared/Timer.cs @@ -1,6 +1,4 @@ - - -namespace Test; +namespace IFoxTest; /* // 测试例子,同时验证两个计时器 @@ -28,14 +26,17 @@ public enum TimeEnum /// 秒 /// Second, + /// /// 毫秒 /// Millisecond, + /// /// 微秒 /// Microsecond, + /// /// 纳秒 /// @@ -56,8 +57,10 @@ public enum TimeEnum [DllImport("Kernel32.dll")] private static extern bool QueryPerformanceFrequency(out long lpFrequency); - private long _startTime, _stopTime; + private long _startTime, + _stopTime; private readonly long _freq; + /// /// 构造函数 /// @@ -99,22 +102,24 @@ public void Stop() /// 毫秒 /// public double Millisecond => Second * 1000.0; + /// /// 微秒 /// public double Microsecond => Second * 1000000.0; + /// /// 纳秒 /// public double Nanosecond => Second * 1000000000.0; + /// /// 计算执行委托的时间 /// /// 要执行的委托 /// 时间单位 /// 执行委托的时间 - public static double RunTime(Action action, - TimeEnum timeEnum = TimeEnum.Millisecond) + public static double RunTime(Action action, TimeEnum timeEnum = TimeEnum.Millisecond) { var nanoSecond = new Timer(); nanoSecond.Start(); @@ -127,7 +132,7 @@ public static double RunTime(Action action, TimeEnum.Millisecond => nanoSecond.Millisecond, TimeEnum.Microsecond => nanoSecond.Microsecond, TimeEnum.Nanosecond => nanoSecond.Nanosecond, - _ => 0.0 + _ => 0.0, }; //string timeNameZn = ""; //switch (timeEnum) @@ -147,4 +152,4 @@ public static double RunTime(Action action, //} return time; } -} \ No newline at end of file +} diff --git a/tests/TestShared/Tools.cs b/tests/TestShared/Tools.cs index 4a9eefa144f623f27836936913f7ae06894632bd..999cfda80fd76d054a7f064c5f5e6dc856d768a5 100644 --- a/tests/TestShared/Tools.cs +++ b/tests/TestShared/Tools.cs @@ -1,4 +1,4 @@ -namespace Test; +namespace IFoxTest; public static class Tools { diff --git a/tests/TestZcad2025/GlobalUsings.cs b/tests/TestZcad2025/GlobalUsings.cs index 2c24797f6c0cde2a403ff8c6672248a0cb46058e..c06316394c8ca88bd037f54d3bc246f2b8d6efa4 100644 --- a/tests/TestZcad2025/GlobalUsings.cs +++ b/tests/TestZcad2025/GlobalUsings.cs @@ -1,4 +1,4 @@ -/// 系统引用 +// 系统引用 global using System; global using System.Collections; global using System.Collections.Generic; @@ -42,8 +42,8 @@ global using Cad_ErrorStatus = ZwSoft.ZwCAD.Runtime.ErrorStatus; -/// ifoxcad +// ifoxcad global using IFoxCAD.Cad; global using IFoxCAD.Basal; -global using Test; \ No newline at end of file +global using IFoxTest; \ No newline at end of file