From 8aac174705f0ef148491f66edab40d4d1b568a21 Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Thu, 1 Jul 2021 11:31:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9D=97=E8=A1=A8Add=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=EF=BC=8C=E9=87=8D=E5=86=99=E5=9D=97=E8=A1=A8Add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/SymbolTableEx.cs | 62 +++++++++++-------- src/IFoxCAD.Cad/Runtime/SymbolTable.cs | 1 - tests/DBTrans.test/Test.cs | 45 +++++++++----- 3 files changed, 65 insertions(+), 43 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs index f777147..a154533 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs @@ -71,7 +71,7 @@ public static ObjectId Rename(this SymbolTable tab /// 成功返回 ,失败返回 public static bool Delete(this SymbolTable table, string name) { - if (name == "0" || name == "Defpoints" || !table.Has(name) ||table[name] == DBTrans.Top.Database.Clayer) + if (name == "0" || name == "Defpoints" || !table.Has(name) || table[name] == DBTrans.Top.Database.Clayer) { return false; } @@ -95,38 +95,50 @@ public static bool Delete(this SymbolTable table, /// /// 块表 /// 块名 - /// 图元 - /// 属性定义 + /// 对所添加块表的委托n + /// 添加图元的委托 + /// 添加属性定义的委托 /// 块定义id /// TODO: 需要测试匿名块等特殊的块是否能定义 - public static ObjectId Add(this SymbolTable table, string name, Action action = null, Func < IEnumerable> ents = null, Func> attdef = null) + public static ObjectId Add(this SymbolTable table, string name, Action action = null, Func> ents = null, Func> attdef = null) { return table.Add(name, btr => { action?.Invoke(btr); - btr.AddEntity(ents?.Invoke()); - //ents.Invoke().ForEach(ent => btr.AppendEntity(ent)); - btr.AddEntity(attdef?.Invoke()); - + if (ents is not null) + { + btr.AddEntity(ents?.Invoke()); + } + if (attdef is not null) + { + btr.AddEntity(attdef?.Invoke()); + } }); - //var id = table.Add(name, action); - - //table.Change(id, btr => - //{ - // if (ents is not null) - // { - // btr.AddEntity(ents?.Invoke()); - // //ents.Invoke().ForEach(ent => btr.AppendEntity(ent)); - // } - // if (attdef is not null) - // { - // btr.AddEntity(attdef?.Invoke()); - // } - //}); - //return id; + } + /// + /// 添加块定义 + /// + /// 块表 + /// 块名 + /// 图元 + /// 属性定义 + /// + public static ObjectId Add(this SymbolTable table, string name, IEnumerable ents = null, IEnumerable attdef = null) + { + return table.Add(name, null, () => { return ents; }, () => { return attdef; }); } - + /// + /// 添加块定义 + /// + /// 块表 + /// 块名 + /// 图元 + /// + public static ObjectId Add(this SymbolTable table, string name, params Entity[] ents) + { + return table.Add(name, null, () => { return ents; }); + } /// /// 从文件中获取块定义 @@ -158,7 +170,7 @@ public static ObjectId GetBlockFrom(this SymbolTable /// 从文件中获取块定义 diff --git a/src/IFoxCAD.Cad/Runtime/SymbolTable.cs b/src/IFoxCAD.Cad/Runtime/SymbolTable.cs index e135ab7..aa30c2c 100644 --- a/src/IFoxCAD.Cad/Runtime/SymbolTable.cs +++ b/src/IFoxCAD.Cad/Runtime/SymbolTable.cs @@ -114,7 +114,6 @@ public ObjectId Add(string name, Action action = null) Name = name }; id = Add(record); - record = GetRecord(id); using (record.ForWrite()) { action?.Invoke(record); diff --git a/tests/DBTrans.test/Test.cs b/tests/DBTrans.test/Test.cs index c7e8e47..6bb53aa 100644 --- a/tests/DBTrans.test/Test.cs +++ b/tests/DBTrans.test/Test.cs @@ -197,7 +197,7 @@ public void BlockDef() using var tr = new DBTrans(); //var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); tr.BlockTable.Add("test", - btr => + btr => { btr.Origin = new Point3d(0, 0, 0); }, @@ -237,23 +237,34 @@ public void BlockDefChange() public void InsertBlockDef() { using var tr = new DBTrans(); - //var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); - //tr.InsertBlock(new Point3d(4, 4, 0), "test1"); //测试插入不存在的块定义 - //tr.InsertBlock(new Point3d(4, 4, 0), "test"); // 测试默认 - //tr.InsertBlock(new Point3d(0, 0, 0),"test", new Scale3d(2)); // 测试放大2倍 - //tr.InsertBlock(new Point3d(4, 4, 0), "test", new Scale3d(2), Math.PI / 4); // 测试放大2倍,旋转45度 - - tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test1"); //测试插入不存在的块定义 - tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test"); // 测试默认 - tr.CurrentSpace.InsertBlock(new Point3d(0, 0, 0), "test", new Scale3d(2)); // 测试放大2倍 - tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test", new Scale3d(2), Math.PI / 4); // 测试放大2倍,旋转45度 - - var def = new Dictionary + 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" }; + tr.BlockTable.Add("test1", line1, line2, att1, att2); + 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 }); + //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" } + }; + tr.CurrentSpace.InsertBlock(new Point3d(0, 0, 0), "test1", atts: def1); + var def2 = new Dictionary { - { "start", "1" }, - { "end", "2" } + { "tagTest3", "1" }, + { "tagTest4", "" } }; - tr.CurrentSpace.InsertBlock(new Point3d(4, 4, 0), "test", atts: def); + tr.CurrentSpace.InsertBlock(new Point3d(10,10, 0), "test2", atts: def2); } @@ -261,7 +272,7 @@ public void InsertBlockDef() public void TestClipBlock() { using var tr = new DBTrans(); - tr.BlockTable.Add("test1", + tr.BlockTable.Add("test1", btr => { btr.Origin = new Point3d(0, 0, 0); -- Gitee From 97ef1d3aea4dfb4789196681a1f187f24a9dea68 Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Thu, 1 Jul 2021 11:39:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs index a154533..bbeba00 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs @@ -133,7 +133,7 @@ public static ObjectId Add(this SymbolTable table, /// /// 块表 /// 块名 - /// 图元 + /// 图元(包括属性) /// public static ObjectId Add(this SymbolTable table, string name, params Entity[] ents) { -- Gitee