From e0ba92daedac8bbcf80b2602c41fcc96987998ae Mon Sep 17 00:00:00 2001 From: zewen han Date: Thu, 21 Apr 2022 16:25:45 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9D=97=E4=B8=AD?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E5=92=8C=E5=9B=BE=E7=BA=B8=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs | 45 ++++++++++++++++++++- src/IFoxCAD.Cad/ExtensionMethod/Enums.cs | 7 +++- tests/Test/testeditor.cs | 19 ++++++++- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs index 66e3ef7..71b8011 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs @@ -680,9 +680,50 @@ public static Matrix3d GetMatrix(this Editor editor, CoordinateSystemCode from, #endif } -#endregion + /// + /// 将点从一个WCS坐标系转换到UCS坐标系 + /// + /// 点 + /// 返回转化后的坐标 + public static Point3d WCS2UCS(this Point3d pt) + { + return pt.TransformBy(Env.Editor.CurrentUserCoordinateSystem.Inverse()); + } + + /// + /// 将点从一个UCS坐标系转换到WCS坐标系 + /// + /// 点 + /// 返回转化后的坐标 + public static Point3d UCS2WCS(this Point3d pt) + { + return pt.TransformBy(Env.Editor.CurrentUserCoordinateSystem); + } + /// + /// 某点在块内坐标系统和世界或者用户坐标系统的转换 + /// + /// 要变换的点 + /// 要变换的块 + /// 源坐标系 + /// 目标坐标系 + /// + public static Point3d TransNested(this Point3d pt, List btrList, CoordinateSystemCode from, CoordinateSystemCode to) + { + if (from == CoordinateSystemCode.Ucs) pt = pt.UCS2WCS(); + if (from == CoordinateSystemCode.Dcs) btrList.Reverse(); + if (from == CoordinateSystemCode.Dcs || to == CoordinateSystemCode.Dcs) + { + foreach (var btr in btrList) + { + Matrix3d geom = to == CoordinateSystemCode.Dcs ? btr.BlockTransform.Inverse() : btr.BlockTransform; + pt = pt.TransformBy(geom); + } + } + return to == CoordinateSystemCode.Ucs ? pt.WCS2UCS() : pt; + } + #endregion -#region 缩放 + #region 缩放 /// /// 缩放窗口范围 diff --git a/src/IFoxCAD.Cad/ExtensionMethod/Enums.cs b/src/IFoxCAD.Cad/ExtensionMethod/Enums.cs index fc0fbaf..acec026 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/Enums.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/Enums.cs @@ -23,7 +23,12 @@ public enum CoordinateSystemCode /// /// 图纸空间坐标系 /// - PDcs + PDcs, + + /// + /// 块空间坐标系 + /// + Dcs } /// diff --git a/tests/Test/testeditor.cs b/tests/Test/testeditor.cs index 9c71a9a..c418a76 100644 --- a/tests/Test/testeditor.cs +++ b/tests/Test/testeditor.cs @@ -51,10 +51,27 @@ public void testzoomextent() [CommandMethod("testssget")] public void testssget() { - var ss = + var ss = Env.Editor.SSGet(":S", messages: new string[2] { "get", "del" }, keywords: new string[2] { "A", "B" }); Env.Print(ss); } + /// + /// 测试块中坐标和图纸坐标转换 + /// + [CommandMethod("pointtest")] + public static void Testhot() + { + using var tr = new DBTrans(); + Editor ed = Env.Editor; + PromptEntityResult BLK = ed.GetEntity("\n请选择一个图元:"); + if (BLK.Status != PromptStatus.OK) return; + var blk = BLK.ObjectId.GetObject(); + List blklist = new List(); + if (blk == null) return; + blklist.Add(blk); + Point3d p = new Point3d(4454, -1321, 0.0).TransNested(blklist, CoordSystem.DCS, CoordSystem.UCS); + ed.WriteMessage(p.ToString()); + } } -- Gitee From 615927a649fc01cc7d07ddd6001390254037580b Mon Sep 17 00:00:00 2001 From: zewen han Date: Thu, 28 Apr 2022 14:27:33 +0800 Subject: [PATCH 2/4] 11 --- src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs | 23 +++++++++++++++++++ tests/Test/testeditor.cs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs index 84b57f7..2865e78 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs @@ -545,6 +545,29 @@ public static Vector3d Wcs2Dcs(this Vector3d vec, bool atPaperSpace) ); } + /// + /// 某点在块内坐标系统和世界或者用户坐标系统的转换 + /// + /// 要变换的点 + /// 要变换的块 + /// 源坐标系 + /// 目标坐标系 + /// + public static Point3d TransNested(this Point3d pt, List btrList, CoordinateSystemCode from, CoordinateSystemCode to) + { + if (from == CoordinateSystemCode.Ucs) pt = pt.Ucs2Wcs(); + if (from == CoordinateSystemCode.Dcs) btrList.Reverse(); + if (from == CoordinateSystemCode.Dcs || to == CoordinateSystemCode.Dcs) + { + foreach (var btr in btrList) + { + Matrix3d geom = to == CoordinateSystemCode.Dcs ? btr.BlockTransform.Inverse() : btr.BlockTransform; + pt = pt.TransformBy(geom); + } + } + return to == CoordinateSystemCode.Ucs ? pt.Wcs2Ucs() : pt; + } + #endregion Ucs diff --git a/tests/Test/testeditor.cs b/tests/Test/testeditor.cs index c418a76..d2cfb35 100644 --- a/tests/Test/testeditor.cs +++ b/tests/Test/testeditor.cs @@ -71,7 +71,7 @@ public static void Testhot() List blklist = new List(); if (blk == null) return; blklist.Add(blk); - Point3d p = new Point3d(4454, -1321, 0.0).TransNested(blklist, CoordSystem.DCS, CoordSystem.UCS); + Point3d p = new Point3d(4454, -1321, 0.0).TransNested(blklist, CoordinateSystemCode.Dcs, CoordinateSystemCode.Ucs); ed.WriteMessage(p.ToString()); } } -- Gitee From 4a7f646913ec97a42fb40e2267ea5bea99123aac Mon Sep 17 00:00:00 2001 From: zewen han Date: Fri, 6 May 2022 13:21:05 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Env=E5=A2=9E=E5=8A=A0newLINE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- src/IFoxCAD.Cad/Runtime/Env.cs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e71f827..f1bc781 100644 --- a/.gitignore +++ b/.gitignore @@ -404,4 +404,5 @@ healthchecksdb #vscode .ionide -.vscode \ No newline at end of file +.vscode +/src/IFoxCAD.Cad/Properties/launchSettings.json diff --git a/src/IFoxCAD.Cad/Runtime/Env.cs b/src/IFoxCAD.Cad/Runtime/Env.cs index 4b5beda..b639c4a 100644 --- a/src/IFoxCAD.Cad/Runtime/Env.cs +++ b/src/IFoxCAD.Cad/Runtime/Env.cs @@ -419,4 +419,9 @@ public static void SetEnv(string var, string? value) /// /// 要打印的对象 public static void Print(object message) => Editor.WriteMessage($"{message}\n"); + /// + /// 新行 + /// + /// + public static string NewLine() => Environment.NewLine; } -- Gitee From 0eb941b905e5fd441021e18eb096e5de38ba7019 Mon Sep 17 00:00:00 2001 From: zewen han Date: Mon, 30 May 2022 15:06:54 +0800 Subject: [PATCH 4/4] =?UTF-8?q?SSGET=20pso=20=E5=90=91=E5=A4=96=E6=9A=B4?= =?UTF-8?q?=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs index 71b8011..e0c4628 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs @@ -56,9 +56,9 @@ public static SelectionSet SelectByLineWeight(this Editor editor, LineWeight lin } - public static PromptSelectionResult? SSGet(this Editor editor, string? mode = null, SelectionFilter? filter = null, string[]? messages = null, string[]? keywords = null) + public static PromptSelectionResult? SSGet(this Editor editor, PromptSelectionOptions? promptSelectionOptions = null, string? mode = null, SelectionFilter? filter = null, string[]? messages = null, string[]? keywords = null) { - var pso = new PromptSelectionOptions(); + PromptSelectionOptions pso = promptSelectionOptions ?? new PromptSelectionOptions(); PromptSelectionResult? ss = null; if (mode is not null) { -- Gitee