From 9194dc041cd4b20832f7f36ba1c45c87bdcb0c37 Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sat, 5 Jun 2021 17:03:47 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=A2=9E=E4=BF=AE=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/CollectionEx.cs | 2 +- src/IFoxCAD.Cad/ResultData/LispDottedPair.cs | 5 ++++- src/IFoxCAD.Cad/ResultData/LispList.cs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs index a2d32d9..4e54ccb 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs @@ -56,7 +56,7 @@ public static Point2dCollection ToCollection(this IEnumerable pts) } /// - /// 三维点迭代器转换为二维点集合 + /// 三维点迭代器转换为三维点集合 /// /// 三维点迭代器 /// 三维点集合 diff --git a/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs b/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs index 94bebfa..9acad02 100644 --- a/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs +++ b/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs @@ -10,6 +10,7 @@ namespace IFoxCAD.Cad /// public class LispDottedPair : LispList { + #region 构造函数 /// /// 默认无参构造函数 /// @@ -34,6 +35,8 @@ public LispDottedPair(TypedValue left, TypedValue right) Add(left); Add(right); } + #endregion + /// /// 点对表的值 /// @@ -63,7 +66,7 @@ public override List Value /// /// TypedValueList 实例 public static implicit operator ResultBuffer(LispDottedPair values) => new(values.Value.ToArray()); - + #endregion } } \ No newline at end of file diff --git a/src/IFoxCAD.Cad/ResultData/LispList.cs b/src/IFoxCAD.Cad/ResultData/LispList.cs index fba1f47..8f87c2f 100644 --- a/src/IFoxCAD.Cad/ResultData/LispList.cs +++ b/src/IFoxCAD.Cad/ResultData/LispList.cs @@ -14,6 +14,7 @@ namespace IFoxCAD.Cad /// public class LispList : TypedValueList { + #region 构造函数 /// /// 默认构造函数 /// @@ -24,7 +25,7 @@ public LispList() { } /// /// TypedValue 迭代器 public LispList(IEnumerable values) : base(values) { } - + #endregion /// /// lisp 列表的值 /// -- Gitee From ff7b77cde155bfcc7044cedf2bb9784cd5aa8d4f Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sat, 5 Jun 2021 18:54:24 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E7=B3=BB=E7=B1=BB=E5=9E=8B=E6=9E=9A=E4=B8=BE=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/CoordinatesystemCode.cs | 34 +++++++++++++++++++ src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs | 5 --- src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs | 26 -------------- 3 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 src/IFoxCAD.Cad/ExtensionMethod/CoordinatesystemCode.cs diff --git a/src/IFoxCAD.Cad/ExtensionMethod/CoordinatesystemCode.cs b/src/IFoxCAD.Cad/ExtensionMethod/CoordinatesystemCode.cs new file mode 100644 index 0000000..f839bd4 --- /dev/null +++ b/src/IFoxCAD.Cad/ExtensionMethod/CoordinatesystemCode.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace IFoxCAD.Cad +{ + /// + /// 坐标系类型枚举 + /// + public enum CoordinateSystemCode + { + /// + /// 世界坐标系 + /// + Wcs = 0, + + /// + /// 用户坐标系 + /// + Ucs, + + /// + /// 模型空间坐标系 + /// + MDcs, + + /// + /// 图纸空间坐标系 + /// + PDcs + } + +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs index 6a2a4f3..e612b27 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs @@ -39,10 +39,6 @@ public static void ChangeXData(this DBObject obj, string appName, DxfCode dxfCod } #endregion - - - - #region 读写模式切换 /// @@ -121,6 +117,5 @@ public void Dispose() #endregion IDisposable 成员 } #endregion - } } diff --git a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs index 5f86426..3320bbd 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs @@ -10,32 +10,6 @@ namespace IFoxCAD.Cad { - /// - /// 坐标系类型枚举 - /// - public enum CoordinateSystemCode - { - /// - /// 世界坐标系 - /// - Wcs = 0, - - /// - /// 用户坐标系 - /// - Ucs, - - /// - /// 模型空间坐标系 - /// - MDcs, - - /// - /// 图纸空间坐标系 - /// - PDcs - } - /// /// 命令行扩展类 /// -- Gitee From 584c3de23f9daeb443b824b565717b1ae95378f0 Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sat, 5 Jun 2021 23:59:39 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=A2=9E=E4=BF=AE=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/EditorEx.cs | 72 ++++++++++----------- src/IFoxCAD.Cad/ExtensionMethod/EntityEx.cs | 6 +- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs index 3320bbd..1a7f7a3 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs @@ -309,7 +309,7 @@ public static void DrawCircle(this Editor editor, Point2d pnt, short colorIndex, /// /// 获取UCS到WCS的矩阵 /// - /// 编辑器对象 + /// 命令行对象 /// 变换矩阵 public static Matrix3d GetMatrixFromUcsToWcs(this Editor editor) { @@ -319,7 +319,7 @@ public static Matrix3d GetMatrixFromUcsToWcs(this Editor editor) /// /// 获取WCS到UCS的矩阵 /// - /// 编辑器对象 + /// 命令行对象 /// 变换矩阵 public static Matrix3d GetMatrixFromWcsToUcs(this Editor editor) { @@ -329,7 +329,7 @@ public static Matrix3d GetMatrixFromWcsToUcs(this Editor editor) /// /// 获取MDCS(模型空间)到WCS的矩阵 /// - /// 编辑器对象 + /// 命令行对象 /// 变换矩阵 public static Matrix3d GetMatrixFromMDcsToWcs(this Editor editor) { @@ -343,7 +343,7 @@ public static Matrix3d GetMatrixFromMDcsToWcs(this Editor editor) /// /// 获取WCS到MDCS(模型空间)的矩阵 /// - /// 编辑器对象 + /// 命令行对象 /// 变换矩阵 public static Matrix3d GetMatrixFromWcsToMDcs(this Editor editor) { @@ -353,7 +353,7 @@ public static Matrix3d GetMatrixFromWcsToMDcs(this Editor editor) /// /// 获取MDCS(模型空间)到PDCS(图纸空间)的矩阵 /// - /// 编辑器对象 + /// 命令行对象 /// 变换矩阵 public static Matrix3d GetMatrixFromMDcsToPDcs(this Editor editor) { @@ -390,7 +390,7 @@ public static Matrix3d GetMatrixFromMDcsToPDcs(this Editor editor) /// /// 获取PDCS(图纸空间)到MDCS(模型空间)的矩阵 /// - /// 编辑器对象 + /// 命令行对象 /// 变换矩阵 public static Matrix3d GetMatrixFromPDcsToMDcs(this Editor editor) { @@ -400,7 +400,7 @@ public static Matrix3d GetMatrixFromPDcsToMDcs(this Editor editor) /// /// 获取变换矩阵 /// - /// 编辑器对象 + /// 命令行对象 /// 源坐标系 /// 目标坐标系 /// 变换矩阵 @@ -487,14 +487,14 @@ public static Matrix3d GetMatrix(this Editor editor, CoordinateSystemCode from, #endif } -#endregion Matrix + #endregion Matrix -#region Zoom + #region Zoom /// /// 缩放窗口范围 /// - /// 编辑器对象 + /// 命令行对象 /// 窗口左下点 /// 窗口右上点 public static void ZoomWindow(this Editor ed, Point3d minPoint, Point3d maxPoint) @@ -540,7 +540,7 @@ public static void ZoomWindow(this Editor ed, Point3d minPoint, Point3d maxPoint /// /// 缩放窗口范围 /// - /// 编辑器对象 + /// 命令行对象 /// 窗口范围点 public static void ZoomWindow(this Editor ed, Extents3d ext) { @@ -548,12 +548,12 @@ public static void ZoomWindow(this Editor ed, Extents3d ext) } /// - /// Zooms the scaled. + /// 缩放比例 /// - /// The ed. - /// The cen pt. - /// The width. - /// The height. + /// 命令行对象 + /// 中心点 + /// 窗口宽 + /// 窗口高 public static void Zoom(this Editor ed, Point3d CenPt, double width, double height) { using ViewTableRecord view = ed.GetCurrentView(); @@ -564,12 +564,12 @@ public static void Zoom(this Editor ed, Point3d CenPt, double width, double heig } /// - /// 视图的窗口缩放 + ///缩放窗口范围 /// - /// The ed. + /// 命令行对象 /// 第一点 /// 对角点 - /// + /// 偏移距离 public static void ZoomWindow(this Editor ed, Point3d lpt, Point3d rpt, double offsetDist = 0.00) { Extents3d extents = new(); @@ -584,7 +584,7 @@ public static void ZoomWindow(this Editor ed, Point3d lpt, Point3d rpt, double o /// /// 动态缩放 /// - /// 编辑器对象 + /// 命令行对象 /// 偏移距离 public static void ZoomExtents(this Editor ed, double offsetDist = 0.00) { @@ -596,7 +596,7 @@ public static void ZoomExtents(this Editor ed, double offsetDist = 0.00) /// /// 根据实体对象的范围显示视图 /// - /// + /// 命令行对象 /// Entity对象 /// 偏移距离 public static void ZoomObject(this Editor ed, Entity ent, double offsetDist = 0.00) @@ -605,16 +605,16 @@ public static void ZoomObject(this Editor ed, Entity ent, double offsetDist = 0. ed.ZoomWindow(ext.MinPoint, ext.MinPoint, offsetDist); } -#endregion Zoom + #endregion Zoom -#region Get交互类 + #region Get交互类 /// /// 获取Point /// - /// - /// - /// + /// 命令行对象 + /// 提示信息 + /// 提示使用的基点 /// public static PromptPointResult GetPoint(this Editor ed, string Message, Point3d BasePoint) { @@ -629,8 +629,8 @@ public static PromptPointResult GetPoint(this Editor ed, string Message, Point3d /// /// 获取double值 /// - /// - /// 显示信息 + /// 命令行对象 + /// 提示信息 /// double默认值 /// public static PromptDoubleResult GetDouble(this Editor ed, string Message, double DefaultValue = 1.0) @@ -645,8 +645,8 @@ public static PromptDoubleResult GetDouble(this Editor ed, string Message, doubl /// /// 获取int值 /// - /// - /// 显示信息 + /// 命令行对象 + /// 提示信息 /// double默认值 /// public static PromptIntegerResult GetInteger(this Editor ed, string Message, int DefaultValue = 1) @@ -661,9 +661,9 @@ public static PromptIntegerResult GetInteger(this Editor ed, string Message, int /// /// 获取string值 /// - /// - /// - /// + /// 命令行对象 + /// 提示信息 + /// string默认值 /// public static PromptResult GetString(this Editor ed, string Message, string DefaultValue = "") { @@ -674,9 +674,9 @@ public static PromptResult GetString(this Editor ed, string Message, string Defa return ed.GetString(strOp); } -#endregion Get交互类 + #endregion Get交互类 -#region 执行lisp + #region 执行lisp [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, @@ -710,6 +710,6 @@ public static ResultBuffer RunLisp(this Editor ed, string arg) return null; } -#endregion 执行lisp + #endregion 执行lisp } } \ No newline at end of file diff --git a/src/IFoxCAD.Cad/ExtensionMethod/EntityEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/EntityEx.cs index 7d0c8d7..38efca4 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/EntityEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/EntityEx.cs @@ -181,7 +181,8 @@ public static Extents3d GetExtents(this IEnumerable ents) } #endregion - #region 多行文字 + #region 单行文字 + /// /// 更正单行文字的镜像属性 /// @@ -194,6 +195,9 @@ public static void ValidateMirror(this DBText txt) txt.IsMirroredInY = false; } } + #endregion + + #region 多行文字 /// /// 炸散多行文字 -- Gitee From 960555628fe7649cb2526bfb859be75234aa9bf5 Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sun, 6 Jun 2021 00:03:01 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs | 85 ++++++++++--------- tests/DBTrans.test/testConvexHull.cs | 19 ++++- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs index 93742f0..d9be6e9 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs @@ -246,15 +246,25 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, } /// - /// 获取三点的面积 + /// 获取两个向量的叉积(|vecBase|×|vec|×sin(a)) /// - /// 基准点 - /// 第一点 - /// 第二点 - /// 三点围成的三角形的面积 - public static double GetArea(Point2d ptBase, Point2d pt1, Point2d pt2) + /// 基向量 + /// 向量 + /// 叉积 + public static double CrossProduct(this Vector2d vecBase, Vector2d vec) + { + return vec.DotProduct(vecBase.GetPerpendicularVector()); + } + + /// + /// 判断两个向量是否左转 + /// + /// 基向量 + /// 向量 + /// 左转/逆时针返回 ,反之返回 + public static bool IsClockWise(Vector2d vecBase, Vector2d vec) { - return (pt2 - ptBase).DotProduct((pt1 - ptBase).GetPerpendicularVector()); + return vecBase.CrossProduct(vec) <= 0; } /// @@ -266,39 +276,29 @@ public static double GetArea(Point2d ptBase, Point2d pt1, Point2d pt2) /// 左转/逆时针或者三点共线返回 ,反之返回 public static bool IsClockWise(Point2d ptBase, Point2d pt1, Point2d pt2) { - return GetArea(ptBase, pt1, pt2) <= 0; - } - - /// - /// 获取两个向量的点积 - /// - /// 基向量 - /// 向量 - /// 点积 - public static double GetArea(Vector2d vecBase, Vector2d vec) - { - return vec.DotProduct(vecBase.GetPerpendicularVector()); + return IsClockWise((pt1 - ptBase), (pt2 - ptBase)); } /// - /// 判断两个向量是否左转 + /// 获取三点的面积 /// - /// 基向量 - /// 向量 - /// 左转/逆时针返回 ,反之返回 - public static bool IsClockWise(Vector2d vecBase, Vector2d vec) + /// 基准点 + /// 第一点 + /// 第二点 + /// 三点围成的三角形的面积 + public static double GetArea(Point2d ptBase, Point2d pt1, Point2d pt2) { - return GetArea(vecBase, vec) <= 0; + return Math.Abs((pt1 - ptBase).CrossProduct(pt2 - ptBase)) / 2;//求三角形面积需加绝对值除2 } - #region PointList /// /// 获取点集的面积 /// /// 点集 + /// 是否恒为正数 /// 面积 - public static double GetArea(this IEnumerable pnts) + public static double GetArea(this IEnumerable pnts, bool positive = true) { IEnumerator itor = pnts.GetEnumerator(); if (!itor.MoveNext()) @@ -316,7 +316,8 @@ public static double GetArea(this IEnumerable pnts) } area = (area + (p2.X * start.Y - start.X * p2.Y)) / 2.0; - return area; + + return positive ? Math.Abs(area) : area; } /// @@ -324,17 +325,17 @@ public static double GetArea(this IEnumerable pnts) /// /// 点集 /// 面积 - public static double GetArea(this IList vertices) - { - double sum = 0.0; - for (int i = 0; i < vertices.Count; i++) - { - Point2d v1 = vertices[i]; - Point2d v2 = vertices[(i + 1) % vertices.Count]; - sum += (v1.X * v2.Y - v2.X * v1.Y); - } - return sum / 2; - } + //public static double GetArea(this IList vertices) + //{ + // double sum = 0.0; + // for (int i = 0; i < vertices.Count; i++) + // { + // Point2d v1 = vertices[i]; + // Point2d v2 = vertices[(i + 1) % vertices.Count]; + // sum += (v1.X * v2.Y - v2.X * v1.Y); + // } + // return sum / 2; + //} /// /// 判断点集的点是否为左转/逆时针 @@ -343,7 +344,7 @@ public static double GetArea(this IList vertices) /// 左转/逆时针返回 ,反之返回 public static bool IsClockWise(this IEnumerable pnts) { - return pnts.GetArea() <= 0; + return pnts.GetArea(false) <= 0; } /// @@ -434,7 +435,7 @@ public static List ConvexHull(this List points) points.Sort((a, b) => a.X == b.X ? a.Y.CompareTo(b.Y) : a.X.CompareTo(b.X)); - // Build lower hull + // 建立下凸包 for (int i = 0; i < n; ++i) { while (k >= 2 && IsClockWise(H[k - 2], H[k - 1], points[i])) @@ -442,7 +443,7 @@ public static List ConvexHull(this List points) H[k++] = points[i]; } - // Build upper hull + // 建立上凸包 for (int i = n - 2, t = k + 1; i >= 0; i--) { while (k >= t && IsClockWise(H[k - 2], H[k - 1], points[i])) diff --git a/tests/DBTrans.test/testConvexHull.cs b/tests/DBTrans.test/testConvexHull.cs index 2765b45..8165e14 100644 --- a/tests/DBTrans.test/testConvexHull.cs +++ b/tests/DBTrans.test/testConvexHull.cs @@ -32,7 +32,7 @@ public void testch() // { // flag = false; // } - + //} //var ptt = ConvexHull.GetConvexHull(pts); @@ -52,9 +52,24 @@ public void testch() //tr.CurrentSpace.AddEntity(pl); var a1 = GeometryEx.GetArea(new Point2d(0, 0), new Point2d(1, 0), new Point2d(1, 1)); + var a2 = GeometryEx.GetArea(new Point2d(0, 0), new Point2d(-1, 0), new Point2d(-1, 1)); //var a2 = ConvexHull.cross(new Point3d(0, 0, 0), new Point3d(1, 0, 0), new Point3d(1, 1, 0)); - tr.Editor.WriteMessage(a1.ToString()); + tr.Editor.WriteMessage((a1 == 0.5).ToString() + "\n"); + tr.Editor.WriteMessage((a2 == 0.5).ToString() + "\n"); //tr.Editor.WriteMessage(a2.ToString()); + List vertices1 = new(); + vertices1.Add(new Point2d(0, 0)); + vertices1.Add(new Point2d(1, 0)); + vertices1.Add(new Point2d(1, 1)); + vertices1.Add(new Point2d(0, 1)); + List vertices2 = new(); + vertices2.Add(new Point2d(0, 0)); + vertices2.Add(new Point2d(-1, 0)); + vertices2.Add(new Point2d(-1, 1)); + vertices2.Add(new Point2d(0, 1)); + tr.Editor.WriteMessage(vertices1.GetArea().ToString() + "\n"); + tr.Editor.WriteMessage(vertices2.GetArea().ToString() + "\n"); + tr.Editor.WriteMessage(vertices2.GetArea(false).ToString() + "\n"); } } } -- Gitee From ddc2093c1e677202f0fe6f7f6a68ab38101efbab Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sun, 6 Jun 2021 00:07:12 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/.gitignore b/.gitignore index 3e8a155..faf8762 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## Visual StudioʱļɽVisualStudioòɵļ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files +# ûضļ *.rsuser *.suo *.user @@ -11,9 +13,12 @@ *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) +# ûضļ (MonoDevelop/Xamarin Studio) *.userprefs # Build results +# Build +# ﷨[abc]ƥκһڷеַҪôƥһ aҪôƥһ bҪôƥһ c *.[oa]Git .o .a βļ [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ @@ -28,27 +33,34 @@ bld/ [Ll]og/ # Visual Studio 2015/2017 cache/options directory +# Visual Studio 2015/2017 /ѡ Ŀ¼ .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot +# wwwrootдĿ̬ļȡע #wwwroot/ # Visual Studio 2017 auto generated files +# Visual Studio 2017Զɵļ Generated\ Files/ # MSTest test Results +# MSTestԽ [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* # NUNIT +# NUnit JUnit .NET 棬֧ .NET ԣȫʹ C# дȫúܶ߼ .NET ԣ綨Լصķ书ܡ *.VisualState.xml TestResult.xml # Build Results of an ATL Project +# ATLĿɽ [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c # Benchmark Results +# Benchmark BenchmarkDotNet.Artifacts/ # .NET Core @@ -57,9 +69,11 @@ project.fragment.lock.json artifacts/ # StyleCop +# ⹤ StyleCopReport.xml # Files built by Visual Studio +# Visual Studio builtļ *_i.c *_p.c *_h.h @@ -89,9 +103,11 @@ StyleCopReport.xml *.scc # Chutzpah Test files +# Chutzpahļ _Chutzpah* # Visual C++ cache files +# Visual C++ ļ ipch/ *.aps *.ncb @@ -103,18 +119,23 @@ ipch/ *.VC.VC.opendb # Visual Studio profiler +# Ӧóܷ *.psess *.vsp *.vspx *.sap # Visual Studio Trace Files +# Visual Studio ļ *.e2e # TFS 2012 Local Workspace +# TFS 2012 ع $tf/ # Guidance Automation Toolkit +# ׹ּڼ򻯽õĴ뼯ɵӦóḶ́ʹܹʦִֶܽͨеһϵпԶ +# ʹô˹ߣȷظԵġ׳ĿԺһµķʽɣʱ䡣 *.gpState # ReSharper is a .NET coding add-in @@ -152,9 +173,11 @@ AutoTest.Net/ .sass-cache/ # Installshield output folder +# Installshield ļ [Ee]xpress/ # DocProject is a documentation generator add-in +# DocProject һĵӳ DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC @@ -172,23 +195,32 @@ publish/ *.azurePubxml # Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted +# ע⣺Ҫǩwebãһעͣ +# ݿַпܵ룩δܵ *.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to # checkin your Azure Web App publish settings, but sensitive information contained # in these scripts will be unencrypted +# Microsoft Azure Web Appá +# ǩAzure Web AppãһעͣЩűаϢ PublishScripts/ # NuGet Packages +# NuGet *.nupkg # The packages folder can be ignored because of Package Restore +# Package RestoreļпԺ **/[Pp]ackages/* # except build/, which is used as an MSBuild target. +# build/MSBuildĿꡣ !**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed +# ҪʱȡעͣͨҪʱע #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files +# NuGet v3project.jsonļɸɺԵļ *.nuget.props *.nuget.targets @@ -201,6 +233,7 @@ ecf/ rcf/ # Windows Store app package directories and files +# WindowsӦ̵ӦóĿ¼ļ AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml @@ -208,12 +241,16 @@ _pkginfo.txt *.appx # Visual Studio cache files +# Visual Studioļ # files ending in .cache can be ignored +# Ժ.cacheβļ *.[Cc]ache # but keep track of directories ending in .cache +# Ҫ.cacheβĿ¼ !?*.[Cc]ache/ # Others +# ClientBin/ ~$* *~ @@ -225,13 +262,16 @@ ClientBin/ orleans.codegen.cs # Including strong name files can present a security risk +# ǿļܻȫ # (https://github.com/github/gitignore/pull/2483#issue-259490424) #*.snk # Since there are multiple workflows, uncomment next line to ignore bower_components +#жȡעһԺbower_components # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) #bower_components/ # ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true +#ASP.NETĬãbowerĿ¼Ϊwwwroot/lib/bower restoreΪtrue **/wwwroot/lib/ # RIA/Silverlight projects @@ -240,6 +280,7 @@ Generated_Code/ # Backup & report files from converting an old project file # to a newer Visual Studio version. Backup files are not needed, # because we have git ;-) +#ĿļתΪµVisual Studio汾ıݺͱļҪļΪgit _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML @@ -253,6 +294,7 @@ ServiceFabricBackup/ *.ndf # Business Intelligence projects +# ҵĿ *.rdl.data *.bim.layout *.bim_*.settings @@ -262,22 +304,28 @@ ServiceFabricBackup/ FakesAssemblies/ # GhostDoc plugin setting file +# GhostDocļ *.GhostDoc.xml # Node.js Tools for Visual Studio +# Visual StudioNode.js .ntvs_analysis.dat node_modules/ # Visual Studio 6 build log +# Visual Studio 6־ *.plg # Visual Studio 6 workspace options file +# Visual Studio 6ѡļ *.opt # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +# Visual Studio 6ԶɵĹļ򿪵ļȣ *.vbw # Visual Studio LightSwitch build output +# Visual Studio LightSwitch **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/ModelManifest.xml @@ -286,6 +334,7 @@ node_modules/ _Pvt_Extensions # Paket dependency manager +# Paketϵ .paket/paket.exe paket-files/ @@ -304,6 +353,7 @@ __pycache__/ *.pyc # Cake - Uncomment if you are using it +# Cake-ʹȡע # tools/** # !tools/packages.config @@ -311,8 +361,10 @@ __pycache__/ *.tss # Telerik's JustMock configuration file +# TelerikJustMockļ *.jmconfig +# BizTalk build output # BizTalk build output *.btp.cs *.btm.cs @@ -320,22 +372,29 @@ __pycache__/ *.xsd.cs # OpenCover UI analysis results +# OpenCover UI OpenCover/ # Azure Stream Analytics local run output +# Azure ASALocalRun/ # MSBuild Binary and Structured Log +# MSBuildƺͽṹ־ *.binlog # NVidia Nsight GPU debugger configuration file +# NVidia Nsight GPUļ *.nvuser # MFractors (Xamarin productivity tool) working folder +# MFractorsXamarinߣļ .mfractor/ # Local History for Visual Studio +# Visual Studio ıʷ¼ .localhistory/ # BeatPulse healthcheck temp database +# BeatPulse healthcheck ʱݿ healthchecksdb -- Gitee From d638a4eb2e697101bbcdd723b7e4fb19fc84414f Mon Sep 17 00:00:00 2001 From: xk <9063830+giteezxk@user.noreply.gitee.com> Date: Sun, 6 Jun 2021 01:17:33 +0800 Subject: [PATCH 06/10] update README.md. --- README.md | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 275c9ef..dbf6dc6 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,80 @@ #### 使用说明 -1. xxxx -2. xxxx -3. xxxx +1. 快速入门 + + - 打开vs,新建一个standard类型的类库项目,修改项目文件里的`netcore2.0`为`NET45`。其中的net45,可以改为net40以上的任何版本(net40、net45、net46、net47)。同时可以指定多版本。具体的详细的教程见 [VS通过添加不同引用库,建立多条件编译]( https://www.yuque.com/vicwjb/zqpcd0/ufbwyl)。 + - 右键项目文件,选择管理nuget程序包。 + - 在nuget程序里搜索**ifoxcad**,直接选择最新的版本,然后点击安装,nuget会自动安装ifoxcad依赖的库。 + - 添加引用 + + ```c# + using Autodesk.AutoCAD.ApplicationServices; + using Autodesk.AutoCAD.EditorInput; + using Autodesk.AutoCAD.Runtime; + using Autodesk.AutoCAD.Geometry; + using Autodesk.AutoCAD.DatabaseServices; + using IFoxCAD.Cad; + ``` + + - 添加代码 + + ```c# + [CommandMethod("hello")] + public void Hello() + { + using (DBTrans tr = new DBTrans()) + { + Line line1 = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + tr.CurrentSpace.AddEntity(line1); + } + } + ``` + + + 这段代码就是在cad的当前空间内添加了一条直线。 + +- F6生成,然后打开cad,netload命令将刚刚生成的dll加载。 + - 运行hello命令,然后缩放一下视图,现在一条直线和一个圆已经显示在屏幕上了。 + +2. 事务管理器用法 + +3. 选择集过滤器用法 + +4. 符号表用法 + +5. WPF支持 + +6. 天秀的自动加载与初始化 + + 为了将程序集的初始化和通过写注册表的方式实现自动加载统一设置,减少每次重复的工作量,内裤提供了`AutoRegAssem`抽象类来完成此功能,只要在需要初始化的类继承`AutoRegAssem`类,然后实现`Initialize()` 和`Terminate()`两个函数就可以了。特别强调的是,一个程序集里只能有一个类继承,不管是不是同一个命名空间。 + + ```c# + public class Test : AutoRegAssem //继承 + { + public override void Initialize() //实现接口函数 + { + throw new NotImplementedException(); + } + public override void Terminate() //实现接口函数 + { + throw new NotImplementedException(); + } + } + ``` + +7. 天秀的打开模式提权 + + 由于cad的对象是有打开模式,是否可写等等,为了安全起见,在处理对象时,一般是用读模式打开,然后需要写数据的时候在提权为写模式,然后在降级到读模式,但是这个过程中,很容易漏掉某些步骤,然后cad崩溃。为了处理这些情况,内裤提供了提权类来保证读写模式的有序转换。 + + ```c# + using(line.ForWrite()) //开启对象写模式提权事务 + { + //处理代码 + } //关闭事务自动处理读写模式 + ``` + +8. 未完待续。。。。 #### 参与贡献 -- Gitee From 213ff4def3f6bad45332b0c2d71937895fdcbd2a Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sun, 6 Jun 2021 01:32:09 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E9=87=8D=E8=BD=BDAddEntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/SymbolTableRecordEx.cs | 14 ++++++- tests/DBTrans.test/Test.cs | 40 ++++++++++--------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs index e3d9bf1..794dd64 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs @@ -57,6 +57,16 @@ public static List AddEntity(this BlockTableRecord btr, IEnumerable .ToList(); } } + /// + /// 添加多个实体 + /// + /// + /// + /// + public static List AddEntity(this BlockTableRecord btr, params Entity[] ents) + { + return btr.AddEntity(ents, null); + } #endregion #region 添加图元 @@ -123,7 +133,7 @@ public static ObjectId DrawCircle(this BlockTableRecord btr, Point3d p0, Point3d var dy2 = p2.Y - p0.Y; var d = dx1 * dy2 - dx2 * dy1; - + if (d != 0.0) { var d2 = d * 2; @@ -169,7 +179,7 @@ public static ObjectId DrawPline(this BlockTableRecord btr, List pts, L /// 圆弧属性设置委托 /// 事务管理器 /// 圆弧id - public static ObjectId DrawArc(this BlockTableRecord btr, Point3d startPoint, Point3d pointOnArc, Point3d endPoint, Action action = default, Transaction trans = default) + public static ObjectId DrawArc(this BlockTableRecord btr, Point3d startPoint, Point3d pointOnArc, Point3d endPoint, Action action = default, Transaction trans = default) { var arc = new CircularArc3d(startPoint, pointOnArc, endPoint); diff --git a/tests/DBTrans.test/Test.cs b/tests/DBTrans.test/Test.cs index d7e0d72..0dac766 100644 --- a/tests/DBTrans.test/Test.cs +++ b/tests/DBTrans.test/Test.cs @@ -97,7 +97,7 @@ public void Layertest() public void Layertest1() { using var tr = new DBTrans(); - tr.LayerTable.Add("test1", Color.FromColorIndex(ColorMethod.ByColor,1)); + tr.LayerTable.Add("test1", Color.FromColorIndex(ColorMethod.ByColor, 1)); } //添加图层 @@ -121,7 +121,7 @@ public void LayerDel() tr.LayerTable.Remove("2"); //测试是否能强制删除 } - + //添加直线 [CommandMethod("linedemo1")] public void AddLine1() @@ -141,8 +141,12 @@ public void AddLine1() // { // line. // }); - Line line = new(new Point3d(0,0,0),new Point3d(1,1,0)); - tr.CurrentSpace.AddEntity(line); + Line line1 = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + Line line2 = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + Line line3 = new(new Point3d(1, 1, 0), new Point3d(3, 3, 0)); + Circle circle = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 10); + tr.CurrentSpace.AddEntity(line1); + tr.CurrentSpace.AddEntity(line2, line3, circle); } //增加多段线1 @@ -151,11 +155,11 @@ public void AddPolyline1() { using var tr = new DBTrans(); Polyline pl = new Polyline(); - pl.AddVertexAt(0, new Point2d(0,0), 0, 0, 0); - pl.AddVertexAt(1, new Point2d(10,10), 0, 0, 0); - pl.AddVertexAt(2, new Point2d(20,20), 0, 0, 0); - pl.AddVertexAt(3, new Point2d(30,30), 0, 0, 0); - pl.AddVertexAt(4, new Point2d(40,40), 0, 0, 0); + pl.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0); + pl.AddVertexAt(1, new Point2d(10, 10), 0, 0, 0); + pl.AddVertexAt(2, new Point2d(20, 20), 0, 0, 0); + pl.AddVertexAt(3, new Point2d(30, 30), 0, 0, 0); + pl.AddVertexAt(4, new Point2d(40, 40), 0, 0, 0); pl.Closed = true; pl.Color = Color.FromColorIndex(ColorMethod.ByColor, 6); tr.CurrentSpace.AddEntity(pl); @@ -167,10 +171,10 @@ 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", + tr.BlockTable.Add("test", () => //图元 { - return new List { new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0))}; + return new List { new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)) }; }, () => //属性定义 { @@ -193,7 +197,7 @@ public void BlockDefChange() btr.GetEntities() .ToList() .ForEach(e => e.Flush()); //刷新块显示 - + }); tr.Editor.Regen(); } @@ -227,14 +231,14 @@ public void AddXdata() { using var tr = new DBTrans(); var appname = "myapp"; - + tr.RegAppTable.Add(appname); // add函数会默认的在存在这个名字的时候返回这个名字的regapp的id,不存在就新建 - + var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); - line.XData = new XDataList() - { + line.XData = new XDataList() + { { DxfCode.ExtendedDataRegAppName, appname }, //可以用dxfcode和int表示组码 { DxfCode.ExtendedDataAsciiString, "hahhahah" }, {1070, 12 } @@ -279,7 +283,7 @@ public void Changexdata() { DxfCode.ExtendedDataLayerName, "0"} }; } - + //tr.AddEntity(data); ed.WriteMessage(data.XData.ToString()); @@ -345,7 +349,7 @@ public void cbll() //tr.BlockTable.GetBlockFrom(filename, true); string blkdefname = SymbolUtilityServices.RepairSymbolName(SymbolUtilityServices.GetSymbolNameFromPathName(filename, "dwg"), false); tr.Database.Insert(blkdefname, tr1.Database, false); //插入了块定义,未插入块参照 - + } -- Gitee From 1b5417fb0431f05362a73914768c1803cb4e612c Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sun, 6 Jun 2021 21:42:45 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9E=E4=BD=93DrawX?= =?UTF-8?q?XX=E6=94=B9=E4=B8=BAAddXXX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionMethod/SymbolTableRecordEx.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs index 794dd64..37571fa 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs @@ -79,7 +79,7 @@ public static List AddEntity(this BlockTableRecord btr, params Entity[ /// 图元属性设置委托 /// 事务管理器 /// 图元id - private static ObjectId DrawEnt(this BlockTableRecord btr, T ent, Action action, Transaction trans) where T : Entity + private static ObjectId AddEnt(this BlockTableRecord btr, T ent, Action action, Transaction trans) where T : Entity { trans ??= DBTrans.Top.Trans; action?.Invoke(ent); @@ -95,10 +95,10 @@ private static ObjectId DrawEnt(this BlockTableRecord btr, T ent, Action a /// 绘图空间 /// 直线属性设置委托 /// 直线的id - public static ObjectId DrawLine(this BlockTableRecord btr, Point3d start, Point3d end, Action action = default, Transaction trans = default) + public static ObjectId AddLine(this BlockTableRecord btr, Point3d start, Point3d end, Action action = default, Transaction trans = default) { var line = new Line(start, end); - return btr.DrawEnt(line, action, trans); + return btr.AddEnt(line, action, trans); } /// /// 在指定绘图空间X-Y平面添加圆 @@ -109,10 +109,10 @@ public static ObjectId DrawLine(this BlockTableRecord btr, Point3d start, Point3 /// 圆属性设置委托 /// 事务管理器 /// 圆的id - public static ObjectId DrawCircle(this BlockTableRecord btr, Point3d center, double radius, Action action = default, Transaction trans = default) + public static ObjectId AddCircle(this BlockTableRecord btr, Point3d center, double radius, Action action = default, Transaction trans = default) { var circle = new Circle(center, Vector3d.ZAxis, radius); - return btr.DrawEnt(circle, action, trans); + return btr.AddEnt(circle, action, trans); } /// @@ -125,7 +125,7 @@ public static ObjectId DrawCircle(this BlockTableRecord btr, Point3d center, dou /// 圆属性设置委托 /// 事务管理器 /// 三点有外接圆则返回圆的id,否则返回ObjectId.Null - public static ObjectId DrawCircle(this BlockTableRecord btr, Point3d p0, Point3d p1, Point3d p2, Action action = default, Transaction trans = default) + public static ObjectId AddCircle(this BlockTableRecord btr, Point3d p0, Point3d p1, Point3d p2, Action action = default, Transaction trans = default) { var dx1 = p1.X - p0.X; var dy1 = p1.Y - p0.Y; @@ -141,7 +141,7 @@ public static ObjectId DrawCircle(this BlockTableRecord btr, Point3d p0, Point3d var c2 = (p0.X + p2.X) * dx2 + (p0.Y + p2.Y) * dy2; var ce = new Point3d((c1 * dy2 - c2 * dy1) / d2, (c2 * dx1 - c1 * dx2) / d2, 0); var circle = new Circle(ce, Vector3d.ZAxis, p0.DistanceTo(ce)); - return btr.DrawEnt(circle, action, trans); + return btr.AddEnt(circle, action, trans); } return ObjectId.Null; } @@ -156,7 +156,7 @@ public static ObjectId DrawCircle(this BlockTableRecord btr, Point3d p0, Point3d /// 轻多段线属性设置委托 /// 事务管理器 /// 轻多段线 - public static ObjectId DrawPline(this BlockTableRecord btr, List pts, List bulges = default, List startWidths = default, List endWidths = default, Action action = default, Transaction trans = default) + public static ObjectId AddPline(this BlockTableRecord btr, List pts, List bulges = default, List startWidths = default, List endWidths = default, Action action = default, Transaction trans = default) { bulges ??= new List(new double[pts.Count]); startWidths ??= new List(new double[pts.Count]); @@ -166,7 +166,7 @@ public static ObjectId DrawPline(this BlockTableRecord btr, List pts, L { pl.AddVertexAt(i, pts[i].Point2d(), bulges[i], startWidths[i], endWidths[i]); } - return btr.DrawEnt(pl, action, trans); + return btr.AddEnt(pl, action, trans); } /// @@ -179,14 +179,14 @@ public static ObjectId DrawPline(this BlockTableRecord btr, List pts, L /// 圆弧属性设置委托 /// 事务管理器 /// 圆弧id - public static ObjectId DrawArc(this BlockTableRecord btr, Point3d startPoint, Point3d pointOnArc, Point3d endPoint, Action action = default, Transaction trans = default) + public static ObjectId AddArc(this BlockTableRecord btr, Point3d startPoint, Point3d pointOnArc, Point3d endPoint, Action action = default, Transaction trans = default) { var arc = new CircularArc3d(startPoint, pointOnArc, endPoint); #if ac2009 - return btr.DrawEnt(arc.ToArc(), action, trans); + return btr.AddEnt(arc.ToArc(), action, trans); #elif ac2013 - return btr.DrawEnt(Curve.CreateFromGeCurve(arc) as Arc, action, trans); + return btr.AddEnt(Curve.CreateFromGeCurve(arc) as Arc, action, trans); #endif } #endregion -- Gitee From c38b91652da6a7be63fa3608fedd936b5e00fc99 Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Sun, 6 Jun 2021 22:35:47 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9E=E4=BD=93DrawX?= =?UTF-8?q?XX=E6=94=B9=E4=B8=BAAddXXX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs | 4 ++-- tests/DBTrans.test/Test.cs | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs index 37571fa..b3b9890 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs @@ -257,7 +257,7 @@ public static DrawOrderTable GetDrawOrderTable(this BlockTableRecord btr, Transa /// /// 插入点 /// 块名 - /// 块插入比例,默认为0 + /// 块插入比例,默认为1 /// 块插入旋转角(弧度),默认为0 /// 属性字典{Tag,Value},默认为null /// 块参照对象id @@ -280,7 +280,7 @@ public static ObjectId InsertBlock(this BlockTableRecord blockTableRecord, Point /// /// 插入点 /// 块定义id - /// 块插入比例,默认为0 + /// 块插入比例,默认为1 /// 块插入旋转角(弧度),默认为0 /// 属性字典{Tag,Value},默认为null /// 块参照对象id diff --git a/tests/DBTrans.test/Test.cs b/tests/DBTrans.test/Test.cs index 0dac766..ae6e9b8 100644 --- a/tests/DBTrans.test/Test.cs +++ b/tests/DBTrans.test/Test.cs @@ -69,7 +69,7 @@ public void Addent() public void drawarc() { using var tr = new DBTrans(); - tr.CurrentSpace.DrawArc(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 0, 0)); + tr.CurrentSpace.AddArc(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 0, 0)); } [CommandMethod("layertest")] @@ -183,6 +183,8 @@ public void BlockDef() return new List { id1, id2 }; } ); + ObjectId objectId = tr.BlockTable.Add("a");//新建块 + objectId.GetObject().AddEntity();//测试添加空实体 } //修改块定义 [CommandMethod("blockdefchange")] -- Gitee From 8b8d7f75108503d1a9c4c5fe9f975a1892a051f0 Mon Sep 17 00:00:00 2001 From: giteezxk <9063830+giteezxk@user.noreply.gitee.com> Date: Mon, 7 Jun 2021 21:49:53 +0800 Subject: [PATCH 10/10] =?UTF-8?q?Revert=20"=E4=BC=98=E5=8C=96=E5=9B=BE?= =?UTF-8?q?=E5=BD=A2=E6=89=A9=E5=B1=95=E7=B1=BB"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 960555628fe7649cb2526bfb859be75234aa9bf5. --- src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs | 85 +++++++++---------- tests/DBTrans.test/testConvexHull.cs | 19 +---- 2 files changed, 44 insertions(+), 60 deletions(-) diff --git a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs index d9be6e9..93742f0 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs @@ -246,25 +246,15 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, } /// - /// 获取两个向量的叉积(|vecBase|×|vec|×sin(a)) - /// - /// 基向量 - /// 向量 - /// 叉积 - public static double CrossProduct(this Vector2d vecBase, Vector2d vec) - { - return vec.DotProduct(vecBase.GetPerpendicularVector()); - } - - /// - /// 判断两个向量是否左转 + /// 获取三点的面积 /// - /// 基向量 - /// 向量 - /// 左转/逆时针返回 ,反之返回 - public static bool IsClockWise(Vector2d vecBase, Vector2d vec) + /// 基准点 + /// 第一点 + /// 第二点 + /// 三点围成的三角形的面积 + public static double GetArea(Point2d ptBase, Point2d pt1, Point2d pt2) { - return vecBase.CrossProduct(vec) <= 0; + return (pt2 - ptBase).DotProduct((pt1 - ptBase).GetPerpendicularVector()); } /// @@ -276,29 +266,39 @@ public static bool IsClockWise(Vector2d vecBase, Vector2d vec) /// 左转/逆时针或者三点共线返回 ,反之返回 public static bool IsClockWise(Point2d ptBase, Point2d pt1, Point2d pt2) { - return IsClockWise((pt1 - ptBase), (pt2 - ptBase)); + return GetArea(ptBase, pt1, pt2) <= 0; } /// - /// 获取三点的面积 + /// 获取两个向量的点积 /// - /// 基准点 - /// 第一点 - /// 第二点 - /// 三点围成的三角形的面积 - public static double GetArea(Point2d ptBase, Point2d pt1, Point2d pt2) + /// 基向量 + /// 向量 + /// 点积 + public static double GetArea(Vector2d vecBase, Vector2d vec) + { + return vec.DotProduct(vecBase.GetPerpendicularVector()); + } + + /// + /// 判断两个向量是否左转 + /// + /// 基向量 + /// 向量 + /// 左转/逆时针返回 ,反之返回 + public static bool IsClockWise(Vector2d vecBase, Vector2d vec) { - return Math.Abs((pt1 - ptBase).CrossProduct(pt2 - ptBase)) / 2;//求三角形面积需加绝对值除2 + return GetArea(vecBase, vec) <= 0; } + #region PointList /// /// 获取点集的面积 /// /// 点集 - /// 是否恒为正数 /// 面积 - public static double GetArea(this IEnumerable pnts, bool positive = true) + public static double GetArea(this IEnumerable pnts) { IEnumerator itor = pnts.GetEnumerator(); if (!itor.MoveNext()) @@ -316,8 +316,7 @@ public static double GetArea(this IEnumerable pnts, bool positive = tru } area = (area + (p2.X * start.Y - start.X * p2.Y)) / 2.0; - - return positive ? Math.Abs(area) : area; + return area; } /// @@ -325,17 +324,17 @@ public static double GetArea(this IEnumerable pnts, bool positive = tru /// /// 点集 /// 面积 - //public static double GetArea(this IList vertices) - //{ - // double sum = 0.0; - // for (int i = 0; i < vertices.Count; i++) - // { - // Point2d v1 = vertices[i]; - // Point2d v2 = vertices[(i + 1) % vertices.Count]; - // sum += (v1.X * v2.Y - v2.X * v1.Y); - // } - // return sum / 2; - //} + public static double GetArea(this IList vertices) + { + double sum = 0.0; + for (int i = 0; i < vertices.Count; i++) + { + Point2d v1 = vertices[i]; + Point2d v2 = vertices[(i + 1) % vertices.Count]; + sum += (v1.X * v2.Y - v2.X * v1.Y); + } + return sum / 2; + } /// /// 判断点集的点是否为左转/逆时针 @@ -344,7 +343,7 @@ public static double GetArea(this IEnumerable pnts, bool positive = tru /// 左转/逆时针返回 ,反之返回 public static bool IsClockWise(this IEnumerable pnts) { - return pnts.GetArea(false) <= 0; + return pnts.GetArea() <= 0; } /// @@ -435,7 +434,7 @@ public static List ConvexHull(this List points) points.Sort((a, b) => a.X == b.X ? a.Y.CompareTo(b.Y) : a.X.CompareTo(b.X)); - // 建立下凸包 + // Build lower hull for (int i = 0; i < n; ++i) { while (k >= 2 && IsClockWise(H[k - 2], H[k - 1], points[i])) @@ -443,7 +442,7 @@ public static List ConvexHull(this List points) H[k++] = points[i]; } - // 建立上凸包 + // Build upper hull for (int i = n - 2, t = k + 1; i >= 0; i--) { while (k >= t && IsClockWise(H[k - 2], H[k - 1], points[i])) diff --git a/tests/DBTrans.test/testConvexHull.cs b/tests/DBTrans.test/testConvexHull.cs index 8165e14..2765b45 100644 --- a/tests/DBTrans.test/testConvexHull.cs +++ b/tests/DBTrans.test/testConvexHull.cs @@ -32,7 +32,7 @@ public void testch() // { // flag = false; // } - + //} //var ptt = ConvexHull.GetConvexHull(pts); @@ -52,24 +52,9 @@ public void testch() //tr.CurrentSpace.AddEntity(pl); var a1 = GeometryEx.GetArea(new Point2d(0, 0), new Point2d(1, 0), new Point2d(1, 1)); - var a2 = GeometryEx.GetArea(new Point2d(0, 0), new Point2d(-1, 0), new Point2d(-1, 1)); //var a2 = ConvexHull.cross(new Point3d(0, 0, 0), new Point3d(1, 0, 0), new Point3d(1, 1, 0)); - tr.Editor.WriteMessage((a1 == 0.5).ToString() + "\n"); - tr.Editor.WriteMessage((a2 == 0.5).ToString() + "\n"); + tr.Editor.WriteMessage(a1.ToString()); //tr.Editor.WriteMessage(a2.ToString()); - List vertices1 = new(); - vertices1.Add(new Point2d(0, 0)); - vertices1.Add(new Point2d(1, 0)); - vertices1.Add(new Point2d(1, 1)); - vertices1.Add(new Point2d(0, 1)); - List vertices2 = new(); - vertices2.Add(new Point2d(0, 0)); - vertices2.Add(new Point2d(-1, 0)); - vertices2.Add(new Point2d(-1, 1)); - vertices2.Add(new Point2d(0, 1)); - tr.Editor.WriteMessage(vertices1.GetArea().ToString() + "\n"); - tr.Editor.WriteMessage(vertices2.GetArea().ToString() + "\n"); - tr.Editor.WriteMessage(vertices2.GetArea(false).ToString() + "\n"); } } } -- Gitee