diff --git a/.gitignore b/.gitignore
index e71f827043efaf37d1b52c53598bdb0b1942ea3d..f1bc78188b045f13fc80427f02bb1c6a940b549d 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/ExtensionMethod/EditorEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs
index 66e3ef78b6bcb86d1b4668993a7a2a270bedef05..e0c4628fc777364eb1e0bf0f39a9a84d9ccb423b 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)
{
@@ -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 fc0fbafebdb2cd4a0cebb775ca170be205af787c..acec0262fc2e66b641aa5dfc523b9b8e24715ab8 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/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs
index 84b57f7d19dabd27ce64af2a8329fa176dec7526..2865e785de69e0986bf7e9f044dc7557e9cca0cd 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/src/IFoxCAD.Cad/Runtime/Env.cs b/src/IFoxCAD.Cad/Runtime/Env.cs
index 4b5beda3a5aa9c71c92b1bfea5cfdc735b50258b..b639c4a8bf88c42a8f52212c9cbef2b99899daae 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;
}
diff --git a/tests/Test/testeditor.cs b/tests/Test/testeditor.cs
index 9c71a9a7a499202a17b3b9010ce3d7649a340ab4..d2cfb35888c0563087e07ee4863afca379f084b3 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, CoordinateSystemCode.Dcs, CoordinateSystemCode.Ucs);
+ ed.WriteMessage(p.ToString());
+ }
}