diff --git a/.gitattributes b/.gitattributes index 63a09c51f24efa84baaf488dc1eca57666b578a1..8bb03aa0a2589806c70bab18b29046a3874727f6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -############################################################################### +############################################################################### # Set default behavior to automatically normalize line endings. ############################################################################### * text=auto diff --git a/.gitignore b/.gitignore index faf876255f879578e1407606fc89f5473b4d3eee..25cc348b693a5371695ce78e78457f9815755384 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ -## Ignore Visual Studio temporary files, build results, and +## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. -## Visual StudioʱļɽVisualStudioòɵļ +## 忽略Visual Studio临时文件、生成结果和由VisualStudio常用插件生成的文件。 ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files -# ûضļ +# 用户特定文件 *.rsuser *.suo *.user @@ -13,12 +13,12 @@ *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) -# ûضļ (MonoDevelop/Xamarin Studio) +# 用户特定文件 (MonoDevelop/Xamarin Studio) *.userprefs # Build results -# Build -# ﷨[abc]ƥκһڷеַҪôƥһ aҪôƥһ bҪôƥһ c *.[oa]Git .o .a βļ +# Build 结果 +# 语法:[abc]匹配任何一个列在方括号中的字符(要么匹配一个 a,要么匹配一个 b,要么匹配一个 c)——如 *.[oa]表明Git忽略所有以 .o 或 .a 结尾的文件 [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ @@ -33,34 +33,34 @@ bld/ [Ll]og/ # Visual Studio 2015/2017 cache/options directory -# Visual Studio 2015/2017 /ѡ Ŀ¼ +# Visual Studio 2015/2017 缓存/选项 目录 .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot -# wwwrootдĿ̬ļȡע +# 如果您有在wwwroot中创建项目静态文件的任务,请取消注释 #wwwroot/ # Visual Studio 2017 auto generated files -# Visual Studio 2017Զɵļ +# Visual Studio 2017自动生成的文件 Generated\ Files/ # MSTest test Results -# MSTestԽ +# MSTest测试结果 [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* # NUNIT -# NUnit JUnit .NET 棬֧ .NET ԣȫʹ C# дȫúܶ߼ .NET ԣ綨Լصķ书ܡ +# NUnit 是 JUnit 的 .NET 版,支持所有 .NET 语言,完全使用 C# 编写,并进行完全重新设计以利用很多高级的 .NET 语言特性,例如定制属性以及其他相关的反射功能。 *.VisualState.xml TestResult.xml # Build Results of an ATL Project -# ATLĿɽ +# ATL项目的生成结果 [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c # Benchmark Results -# Benchmark +# Benchmark结果 BenchmarkDotNet.Artifacts/ # .NET Core @@ -69,11 +69,11 @@ project.fragment.lock.json artifacts/ # StyleCop -# ⹤ +# 代码检测工具 StyleCopReport.xml # Files built by Visual Studio -# Visual Studio builtļ +# Visual Studio built的文件 *_i.c *_p.c *_h.h @@ -103,11 +103,11 @@ StyleCopReport.xml *.scc # Chutzpah Test files -# Chutzpahļ +# Chutzpah测试文件 _Chutzpah* # Visual C++ cache files -# Visual C++ ļ +# Visual C++ 缓存文件 ipch/ *.aps *.ncb @@ -119,23 +119,23 @@ ipch/ *.VC.VC.opendb # Visual Studio profiler -# Ӧóܷ +# 应用程序性能分析工具 *.psess *.vsp *.vspx *.sap # Visual Studio Trace Files -# Visual Studio ļ +# Visual Studio 跟踪文件 *.e2e # TFS 2012 Local Workspace -# TFS 2012 ع +# TFS 2012 本地工作区 $tf/ # Guidance Automation Toolkit -# ׹ּڼ򻯽õĴ뼯ɵӦóḶ́ʹܹʦִֶܽͨеһϵпԶ -# ʹô˹ߣȷظԵġ׳ĿԺһµķʽɣʱ䡣 +# 这套工具旨在简化将可重用的代码集成到应用程序的过程,使架构师能将通常需手动执行的一系列开发工作自动化起来。 +# 使用此工具,还能确保重复性的、易出错的开发工作以合理、一致的方式完成,并能缩短软件开发时间。 *.gpState # ReSharper is a .NET coding add-in @@ -173,11 +173,11 @@ AutoTest.Net/ .sass-cache/ # Installshield output folder -# Installshield ļ +# Installshield 输出文件夹 [Ee]xpress/ # DocProject is a documentation generator add-in -# DocProject һĵӳ +# DocProject 是一个文档生成器外接程序 DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC @@ -195,32 +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ãһעͣ -# ݿַпܵ룩δܵ +# 注意:如果要签入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ãһעͣЩűаϢ +# Microsoft Azure Web App发布设置。 +# 如果您想签入Azure Web App发布设置,请在下一行添加注释,但这些脚本中包含的敏感信息将不加密 PublishScripts/ # NuGet Packages -# NuGet +# NuGet包 *.nupkg # The packages folder can be ignored because of Package Restore -# Package RestoreļпԺ +# 由于Package Restore,包文件夹可以忽略 **/[Pp]ackages/* # except build/, which is used as an MSBuild target. -# build/MSBuildĿꡣ +# 除了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 v3的project.json文件生成更多可忽略的文件 *.nuget.props *.nuget.targets @@ -233,7 +233,7 @@ ecf/ rcf/ # Windows Store app package directories and files -# WindowsӦ̵ӦóĿ¼ļ +# Windows应用商店应用程序包目录和文件 AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml @@ -241,16 +241,16 @@ _pkginfo.txt *.appx # Visual Studio cache files -# Visual Studioļ +# Visual Studio缓存文件 # files ending in .cache can be ignored -# Ժ.cacheβļ +# 可以忽略以.cache结尾的文件 *.[Cc]ache # but keep track of directories ending in .cache -# Ҫ.cacheβĿ¼ +# 但要跟踪以.cache结尾的目录 !?*.[Cc]ache/ # Others -# +# 其他 ClientBin/ ~$* *~ @@ -262,16 +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 +#由于有多个工作流,取消注释下一行以忽略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 +#ASP.NET核心默认设置:bower目录配置为wwwroot/lib/并且bower restore为true **/wwwroot/lib/ # RIA/Silverlight projects @@ -280,7 +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 +#将旧项目文件转换为新的Visual Studio版本的备份和报告文件。不需要备份文件,因为我们有git; _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML @@ -294,7 +294,7 @@ ServiceFabricBackup/ *.ndf # Business Intelligence projects -# ҵĿ +# 商业智能项目 *.rdl.data *.bim.layout *.bim_*.settings @@ -304,28 +304,28 @@ ServiceFabricBackup/ FakesAssemblies/ # GhostDoc plugin setting file -# GhostDocļ +# GhostDoc插件设置文件 *.GhostDoc.xml # Node.js Tools for Visual Studio -# Visual StudioNode.js +# 用于Visual Studio的Node.js工具 .ntvs_analysis.dat node_modules/ # Visual Studio 6 build log -# Visual Studio 6־ +# Visual Studio 6生成日志 *.plg # Visual Studio 6 workspace options file -# Visual Studio 6ѡļ +# Visual Studio 6工作区选项文件 *.opt # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -# Visual Studio 6ԶɵĹļ򿪵ļȣ +# Visual Studio 6自动生成的工作区文件(包含打开的文件等) *.vbw # Visual Studio LightSwitch build output -# Visual Studio LightSwitch +# Visual Studio LightSwitch生成输出 **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/ModelManifest.xml @@ -334,7 +334,7 @@ node_modules/ _Pvt_Extensions # Paket dependency manager -# Paketϵ +# Paket依赖关系管理器 .paket/paket.exe paket-files/ @@ -353,7 +353,7 @@ __pycache__/ *.pyc # Cake - Uncomment if you are using it -# Cake-ʹȡע +# Cake-如果你正在使用它,请取消注释 # tools/** # !tools/packages.config @@ -361,7 +361,7 @@ __pycache__/ *.tss # Telerik's JustMock configuration file -# TelerikJustMockļ +# Telerik的JustMock配置文件 *.jmconfig # BizTalk build output @@ -372,29 +372,29 @@ __pycache__/ *.xsd.cs # OpenCover UI analysis results -# OpenCover UI +# OpenCover UI分析结果 OpenCover/ # Azure Stream Analytics local run output -# Azure +# Azure流分析本地运行输出 ASALocalRun/ # MSBuild Binary and Structured Log -# MSBuildƺͽṹ־ +# MSBuild二进制和结构化日志 *.binlog # NVidia Nsight GPU debugger configuration file -# NVidia Nsight GPUļ +# NVidia Nsight GPU调试器配置文件 *.nvuser # MFractors (Xamarin productivity tool) working folder -# MFractorsXamarinߣļ +# MFractors(Xamarin生产力工具)工作文件夹 .mfractor/ # Local History for Visual Studio -# Visual Studio ıʷ¼ +# Visual Studio 的本地历史记录 .localhistory/ # BeatPulse healthcheck temp database -# BeatPulse healthcheck ʱݿ +# BeatPulse healthcheck 临时数据库 healthchecksdb diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 7c3d2c4742185f4b8d6f8b3319a78c74079f6822..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# IFoxCAD - -#### Description -基于.NET的Cad二次开发类库 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/src/IFoxCAD.Basal/IFoxCAD.Basal.csproj b/src/IFoxCAD.Basal/IFoxCAD.Basal.csproj index 93309690e7bda95e7b9ba2ef6ffe73f70bd33633..a15060de087c689ca44f7d79395d03ee0f9b51f8 100644 --- a/src/IFoxCAD.Basal/IFoxCAD.Basal.csproj +++ b/src/IFoxCAD.Basal/IFoxCAD.Basal.csproj @@ -1,36 +1,45 @@ - - - - net35;net40 - true - 0.1.1 - InspireFunction - xsfhlzh;vicwjb - 基于.NET的二次开发基本类库 - InspireFunction - https://gitee.com/inspirefunction/ifoxcad - https://gitee.com/inspirefunction/ifoxcad.git - git - IFoxCAD;C#;NET;Common;Basal - 增加在net35支持 - true - true - preview - true - LICENSE - true - - - - - - - - - True - - - + + + + preview + enable + + + 1.0.0.* + 1.0.0.0 + False + net35;net40 + 0.1.1 + + true + true + InspireFunction + xsfhlzh;vicwjb + 基于.NET的二次开发基本类库 + InspireFunction + git + https://gitee.com/inspirefunction/ifoxcad.git + + https://gitee.com/inspirefunction/ifoxcad + IFoxCAD;C#;NET;Common;Basal + 增加在net35支持 + true + true + + LICENSE + true + + + + + + + + + True + + + diff --git a/src/IFoxCAD.Basal/LinqEx.cs b/src/IFoxCAD.Basal/LinqEx.cs index b0454a46ea0146eaaf0e6a3a2ef595970e9300c3..7b20401d7ae4cc10c95f11e233f8005cf9c3c210 100644 --- a/src/IFoxCAD.Basal/LinqEx.cs +++ b/src/IFoxCAD.Basal/LinqEx.cs @@ -339,4 +339,4 @@ public static IOrderedEnumerable ThenBy(this IOrderedEnumerable s #endregion Order } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Basal/LoopList.cs b/src/IFoxCAD.Basal/LoopList.cs index 3d132c852b2876229eb0016ca9352ec98cf4cf9f..2c0b088b7d8bf0832360a373ebaa76d21db9fbd2 100644 --- a/src/IFoxCAD.Basal/LoopList.cs +++ b/src/IFoxCAD.Basal/LoopList.cs @@ -1,6 +1,8 @@ using System; +using System.Collections; using System.Collections.Generic; -using System.Linq; +using System.Text; + namespace IFoxCAD.Collections { /// @@ -9,88 +11,103 @@ namespace IFoxCAD.Collections /// public class LoopListNode { + #region 成员 /// /// 取值 /// - public T Value { get; set; } + public T Value; /// /// 上一个节点 /// - public LoopListNode Previous - { internal set; get; } + public LoopListNode? Previous { internal set; get; } /// /// 下一个节点 /// - public LoopListNode Next - { internal set; get; } + public LoopListNode? Next { internal set; get; } /// - ///环链表序列 + /// 环链表序列 /// - public LoopList List - { internal set; get; } + public LoopList? List { internal set; get; } + #endregion + #region 构造 /// /// 环链表节点构造函数 /// /// 节点值 - public LoopListNode(T value) + public LoopListNode(T value, LoopList ts) { Value = value; + List = ts; } + /// /// 获取当前节点的临近节点 /// /// 搜索方向标志,为向前搜索,为向后搜索 /// - public LoopListNode GetNext(bool forward) + public LoopListNode? GetNext(bool forward) { return forward ? Next : Previous; } + #endregion + #region 方法 + /// + /// 无效化成员 + /// + internal void Invalidate() + { + List = null; + Next = null; + Previous = null; + } + #endregion } /// /// 环链表 /// /// - public class LoopList : - IEnumerable, IFormattable + public class LoopList : IEnumerable, IFormattable { + #region 成员 /// - /// 默认构造函数 + /// 节点数 /// - public LoopList() - { } + public int Count { get; private set; } + /// - /// 环链表构造函数 + /// 首节点 /// - /// 节点迭代器 - public LoopList(IEnumerable values) - { - foreach (T value in values) - Add(value); - } + public LoopListNode? First { get; private set; } /// - /// 节点数 + /// 尾节点 /// - public int Count - { get; private set; } + public LoopListNode? Last => First?.Previous; + #endregion + #region 构造 /// - /// 首节点 + /// 默认构造函数 /// - public LoopListNode First - { get; private set; } + public LoopList() { } /// - /// 尾节点 + /// 环链表构造函数 /// - public LoopListNode Last + /// 节点迭代器 + public LoopList(IEnumerable values) { - get { return First?.Previous; } + var ge = values.GetEnumerator(); + while (ge.MoveNext()) + Add(ge.Current); } + + #endregion + #region 方法 /// /// 设置首节点 /// @@ -98,12 +115,11 @@ public LoopListNode Last /// public bool SetFirst(LoopListNode node) { - if (Contains(node)) - { - First = node; - return true; - } - return false; + if (!Contains(node)) + return false; + + First = node; + return true; } /// @@ -113,9 +129,57 @@ public bool SetFirst(LoopListNode node) /// 第二个节点 public void Swap(LoopListNode node1, LoopListNode node2) { - T value = node1.Value; - node1.Value = node2.Value; - node2.Value = value; +#if NET35 + var value = node1.Value; + node1.Value = node2.Value; + node2.Value = value; +#else + (node2.Value, node1.Value) = (node1.Value, node2.Value); +#endif + } + + /// + /// 链内翻转 + /// + public void Reverse() + { + var first = First; + if (first is null) + return; + var last = Last; + for (int i = 0; i < Count / 2; i++) + { + Swap(first!, last!); + first = first!.Next; + last = last!.Previous; + } + } + + /// + /// 清理 + /// + public void Clear() + { + //移除头部,表示链表再也无法遍历得到 + First = null; + Count = 0; + } + + /// + /// 从头遍历_非迭代器 + /// + /// + public void ForEach(Func, bool> action) + { + var node = First; + if (node is null) + return; + for (int i = 0; i < Count; i++) + { + if (action(node!)) + break; + node = node!.Next; + } } #region Contains @@ -126,8 +190,9 @@ public void Swap(LoopListNode node1, LoopListNode node2) /// public bool Contains(LoopListNode node) { - return node != null && node.List == this; + return node is not null && node.List == this; } + /// /// 是否包含值 /// @@ -135,45 +200,118 @@ public bool Contains(LoopListNode node) /// public bool Contains(T value) { - LoopListNode node = First; - if (node == null) + bool result = false; + ForEach(node => { + if (node.Value!.Equals(value)) + { + result = true; + return true; + } return false; + }); + return result; + } - for (int i = 0; i < Count; i++) + /// + /// 查找第一个出现的节点 + /// + /// + /// + public LoopListNode? Find(T value) + { + //LoopListNode result = null; + //ForEach(node => + //{ + // if (node.Value.Equals(t2)) + // { + // result = node; + // return true; + // } + // return false; + //}); + //return result; + + LoopListNode? node = First; + var c = EqualityComparer.Default; + if (node is not null) { - if (node.Value.Equals(value)) - return true; - node = node.Next; + if (value is not null) + { + do + { + if (c.Equals(node!.Value, value)) + return node; + node = node.Next; + } while (node != First); + } + else + { + do + { + if (node!.Value is null) + return node; + node = node.Next; + } while (node != First); + } } - - return false; + return null; } + /// - /// 获取节点 + /// 查找所有出现的节点 /// - /// + /// /// - public LoopListNode GetNode(Func func) + public IEnumerable>? Finds(T value) { - LoopListNode node = First; - if (node == null) + LoopListNode? node = First; + if (node is null) return null; - for (int i = 0; i < Count; i++) + List> result = new(); + var c = EqualityComparer.Default; + if (value is not null) { - if (func(node.Value)) + do { - return node; - } - node = node.Next; + if (c.Equals(node!.Value, value)) + result.Add(node); + node = node.Next; + } while (node != First); } - return null; + else + { + do + { + if (node!.Value is null) + result.Add(node); + node = node.Next; + } while (node != First); + } + return result; } - #endregion Contains + /// + /// 获取节点 + /// + /// + /// + public LoopListNode? GetNode(Func func) + { + LoopListNode? result = null; + ForEach(node => { + if (func(node.Value)) + { + result = node; + return true; + } + return false; + }); + return result; + } + #endregion #region Add - /// /// 在首节点之前插入节点,并设置新节点为首节点 /// @@ -181,22 +319,20 @@ public LoopListNode GetNode(Func func) /// public LoopListNode AddFirst(T value) { - LoopListNode node = new(value) - { - List = this - }; + var node = new LoopListNode(value, this); + if (Count == 0) { - First = node; + First = node; First.Previous = First.Next = node; } else { - LoopListNode last = Last; - First.Previous = last.Next = node; - node.Next = First; - node.Previous = last; - First = node; + LoopListNode last = Last!; + First!.Previous = last.Next = node; + node.Next = First; + node.Previous = last; + First = node; } Count++; return First; @@ -209,23 +345,46 @@ public LoopListNode AddFirst(T value) /// public LoopListNode Add(T value) { - LoopListNode node = new(value); - node.List = this; + var node = new LoopListNode(value, this); + if (Count == 0) { - First = node; + First = node; First.Previous = First.Next = node; } else { - LoopListNode last = First.Previous; + var last = First!.Previous!; First.Previous = last.Next = node; - node.Next = First; - node.Previous = last; + node.Next = First; + node.Previous = last; } Count++; - return Last; + return Last!; + } + + /// + /// 在尾节点之后插入节点,并设置新节点为尾节点_此函数仅为与LinkedList同名方法 + /// + /// + /// + public LoopListNode AddLast(T value) + { + return Add(value); + } + + + /// + /// 容器内容全部加入到末尾 + /// + /// + public void AddRange(IEnumerable list) + { + var ge = list.GetEnumerator(); + while (ge.MoveNext()) + Add(ge.Current); } + /// /// 前面增加节点 /// @@ -235,20 +394,17 @@ public LoopListNode Add(T value) public LoopListNode AddBefore(LoopListNode node, T value) { if (node == First) - { return AddFirst(value); - } - else - { - LoopListNode tnode = new(value); - node.Previous.Next = tnode; - tnode.Previous = node.Previous; - node.Previous = tnode; - tnode.Next = node; - Count++; - return tnode; - } + + var tnode = new LoopListNode(value, this); + node.Previous!.Next = tnode; + tnode.Previous = node.Previous; + node.Previous = tnode; + tnode.Next = node; + Count++; + return tnode; } + /// /// 后面增加节点 /// @@ -257,8 +413,8 @@ public LoopListNode AddBefore(LoopListNode node, T value) /// public LoopListNode AddAfter(LoopListNode node, T value) { - LoopListNode tnode = new(value); - node.Next.Previous = tnode; + var tnode = new LoopListNode(value, this); + node.Next!.Previous = tnode; tnode.Next = node.Next; node.Next = tnode; tnode.Previous = node; @@ -266,10 +422,8 @@ public LoopListNode AddAfter(LoopListNode node, T value) return tnode; } - #endregion Add - + #endregion #region Remove - /// /// 删除首节点 /// @@ -286,13 +440,12 @@ public bool RemoveFirst() break; default: - LoopListNode last = Last; - First = First.Next; - First.Previous = last; + LoopListNode last = Last!; + First = First!.Next; + First!.Previous = last; last.Next = First; break; } - Count--; return true; } @@ -312,9 +465,9 @@ public bool RemoveLast() break; default: - LoopListNode last = Last.Previous; + LoopListNode last = Last!.Previous!; last.Next = First; - First.Previous = last; + First!.Previous = last; break; } Count--; @@ -324,38 +477,56 @@ public bool RemoveLast() /// /// 删除节点 /// - /// + /// 指定节点 /// public bool Remove(LoopListNode node) { - if (Contains(node)) + if (!Contains(node)) + return false; + InternalRemove(node); + return true; + } + + /// + /// 删除节点 + /// + /// 将移除所有含有此值 + /// + public bool Remove(T value) + { + var lst = Finds(value); + if (lst is null) + return false; + + var ge = lst!.GetEnumerator(); + while (ge.MoveNext()) + InternalRemove(ge.Current); + return true; + } + + /// + /// 删除节点_内部调用 + /// + /// 此值肯定存在当前链表 + /// + void InternalRemove(LoopListNode node) + { + if (Count == 1 || node == First) { - if (Count == 1) - { - First = null; - } - else - { - if (node == First) - { - RemoveFirst(); - } - else - { - node.Next.Previous = node.Previous; - node.Previous.Next = node.Next; - } - } - Count--; - return true; + RemoveFirst(); + } + else + { + node.Next!.Previous = node.Previous; + node.Previous!.Next = node.Next; } - return false; - } - #endregion Remove + node.Invalidate(); + Count--; + } + #endregion #region LinkTo - /// /// 链接两节点,并去除这两个节点间的所有节点 /// @@ -365,7 +536,7 @@ public void LinkTo(LoopListNode from, LoopListNode to) { if (from != to && Contains(from) && Contains(to)) { - LoopListNode node = from.Next; + LoopListNode node = from.Next!; bool isFirstChanged = false; int number = 0; @@ -374,7 +545,7 @@ public void LinkTo(LoopListNode from, LoopListNode to) if (node == First) isFirstChanged = true; - node = node.Next; + node = node.Next!; number++; } @@ -424,10 +595,9 @@ public void LinkTo(LoopListNode from, LoopListNode to, int number, bool is } } - #endregion LinkTo - - #region IEnumerable 成员 - + #endregion + #endregion + #region IEnumerable /// /// 获取节点的查询器 /// @@ -435,11 +605,11 @@ public void LinkTo(LoopListNode from, LoopListNode to, int number, bool is /// public IEnumerable> GetNodes(LoopListNode from) { - LoopListNode node = from; + var node = from; for (int i = 0; i < Count; i++) { - yield return node; - node = node.Next; + yield return node!; + node = node!.Next; } } @@ -449,11 +619,11 @@ public IEnumerable> GetNodes(LoopListNode from) /// public IEnumerable> GetNodes() { - LoopListNode node = First; + LoopListNode node = First!; for (int i = 0; i < Count; i++) { - yield return node; - node = node.Next; + yield return node!; + node = node.Next!; } } @@ -463,50 +633,73 @@ public IEnumerable> GetNodes() /// public IEnumerator GetEnumerator() { - LoopListNode node = First; + LoopListNode node = First!; for (int i = 0; i < Count; i++) { - yield return node.Value; - node = node.Next; + yield return node!.Value; + node = node.Next!; } } - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #region IEnumerable 成员 + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + #endregion IEnumerable 成员 + #endregion + #region IFormattable + /// + /// 转换为字符串_格式化实现 + /// + /// + /// + /// + string IFormattable.ToString(string? format, IFormatProvider? formatProvider) { - return GetEnumerator(); + return ToString(format, formatProvider); } - #endregion IEnumerable 成员 - - #endregion IEnumerable 成员 - - #region IFormattable 成员 /// - /// 转换为字符串 + /// 转换为字符串_无参调用 /// /// public override string ToString() { - string s = "( "; - foreach (T value in this) - { - s += value.ToString() + " "; - } - return s + ")"; + return ToString(null, null); } - string IFormattable.ToString(string format, IFormatProvider formatProvider) + /// + /// 转换为字符串_有参调用 + /// + /// + public string ToString(string? format, IFormatProvider? formatProvider = null) { - return ToString(); + var s = new StringBuilder(); + s.Append($"Count = {Count};"); + if (format is null) + { + s.Append("{ "); + foreach (T value in this) + s.Append($"{value} "); + s.Append(" }"); + } + return s.ToString(); } - - #endregion IFormattable 成员 + #endregion + #region ICloneable + /* 山人说无法分辨ICloneable接口是深浅克隆,因此不要在泛型模板实现克隆函数,让用户自己来 + * 因此约定了:CopyTo(T,index)是深克隆;MemberwiseClone()是浅克隆; + * public object Clone() + * { + * var lst = new LoopList>(); + * ForEach(node => { + * lst.Add(node); + * return false; + * }); + * return lst; + * } + */ + #endregion } -} +} \ No newline at end of file diff --git a/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs index 8fb683a44748363c48b214c8de515dfe219d1536..406a33d12f9941064ff3b94050d89d43f7cee758 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/CollectionEx.cs @@ -2,6 +2,7 @@ using Autodesk.AutoCAD.Geometry; using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; namespace IFoxCAD.Cad @@ -75,6 +76,27 @@ public static List ToList(this ObjectIdCollection ids) return ids.Cast().ToList(); } + public static List ToList(this StringCollection strs) + { + return strs.Cast().ToList(); + } + + /* Cast不进行过滤,而是直接强转 + var s = new System.Collections.ArrayList(); + s.Add("1"); + s.Add("a"); + s.Add(5666); + + var aaa = s.Cast().ToList(); + System.InvalidCastException: 指定的转换无效。 + + List..ctor(IEnumerable) + + System.Linq.Enumerable.ToList(IEnumerable) + + var aaa = s.Cast().ToList(); + System.InvalidCastException: 无法将类型为“System.Int32”的对象强制转换为类型“System.String”。 + + List..ctor(IEnumerable) + + System.Linq.Enumerable.ToList(IEnumerable) + */ /// /// 遍历集合的迭代器,执行action委托 @@ -84,11 +106,13 @@ public static List ToList(this ObjectIdCollection ids) /// 要运行的委托 public static void ForEach(this IEnumerable source, Action action) { + if (action is null) + throw new ArgumentNullException(nameof(action)); foreach (var element in source) - { - action?.Invoke(element); - } + action.Invoke(element); } + + /// /// 同时遍历集合索引和值的迭代器,执行action委托 /// @@ -97,14 +121,15 @@ public static void ForEach(this IEnumerable source, Action action) /// 要运行的委托 public static void ForEach(this IEnumerable source, Action action) { + if (action is null) + throw new ArgumentNullException(nameof(action)); int i = 0; foreach (var item in source) { - action?.Invoke(i, item); + action.Invoke(i, item); i++; } - } } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/Curve2dEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/Curve2dEx.cs index e5d794337fdcb257250e8e804372a545a9043d4e..7acb61ef150e60a0f2534da55463ef1a009f63df 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/Curve2dEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/Curve2dEx.cs @@ -18,7 +18,7 @@ public static class Curve2dEx /// Ge2d曲线 /// 曲线转换矩阵 /// Db曲线 - public static Curve ToCurve(this Curve2d curve, Matrix3d mat) + public static Curve? ToCurve(this Curve2d curve, Matrix3d mat) { return curve switch { @@ -183,7 +183,7 @@ public static Ellipse ToCurve(this EllipticalArc2d ea2d) /// 实体类构造线 public static Xline ToCurve(this Line2d line2d) { - Plane plane = new Plane(); + var plane = new Plane(); return new Xline { @@ -315,4 +315,4 @@ public static Spline ToCurve(this NurbCurve2d nc2d) #endregion NurbCurve2d } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/Curve3dEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/Curve3dEx.cs index d5ad9ae9241b3feb65c61f9e661660c1ccb5e2ad..9d477ba229cf25f59b650f57cff6acce72c22aaa 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/Curve3dEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/Curve3dEx.cs @@ -403,7 +403,7 @@ public static Curve ToCurve(this CircularArc3d ca3d) /// /// 三维解析类圆/弧 /// 实体圆 - public static Circle ToCircle(this CircularArc3d ca3d) => + public static Circle ToCircle(this CircularArc3d ca3d) => new Circle(ca3d.Center, ca3d.Normal, ca3d.Radius); /// @@ -564,4 +564,4 @@ public static Polyline3d ToCurve(this PolylineCurve3d pl3d) #endregion PolylineCurve3d } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/CurveEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/CurveEx.cs index fd3bf8362e3840362e3c1ebaf25f0b42d3623322..26fbd18847934908946aade03477b6d32b71d21b 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/CurveEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/CurveEx.cs @@ -58,20 +58,18 @@ private struct EdgeItem : IEquatable public EdgeItem(Edge edge, bool forward) { - Edge = edge; + Edge = edge; Forward = forward; } public CompositeCurve3d GetCurve() { - CompositeCurve3d cc3d = Edge.Curve; + var cc3d = Edge.Curve; if (Forward) - { return cc3d; - } else { - cc3d = cc3d.Clone() as CompositeCurve3d; + cc3d = (CompositeCurve3d)cc3d.Clone(); return cc3d.GetReverseParameterCurve() as CompositeCurve3d; } } @@ -89,13 +87,13 @@ public void FindRegion(List edges, List> regions) var edgeItem = this; region.Add(edgeItem); var edgeItem2 = this.GetNext(edges); - if (edgeItem2.Edge != null) + if (edgeItem2.Edge is not null) { bool hasList = false; foreach (var edgeList2 in regions) { var node = edgeList2.GetNode(e => e.Equals(edgeItem)); - if (node != null) + if (node is not null) { if (node.Next.Value.Equals(edgeItem2)) { @@ -106,7 +104,7 @@ public void FindRegion(List edges, List> regions) } if (!hasList) { - while (edgeItem2.Edge != null) + while (edgeItem2.Edge is not null) { if (edgeItem2.Edge == edgeItem.Edge) break; @@ -125,12 +123,12 @@ public EdgeItem GetNext(List edges) int next; if (Forward) { - vec = Edge.GetEndVector(); + vec = Edge.GetEndVector(); next = Edge.EndIndex; } else { - vec = Edge.GetStartVector(); + vec = Edge.GetStartVector(); next = Edge.StartIndex; } @@ -148,19 +146,19 @@ public EdgeItem GetNext(List edges) var angle2 = vec.GetAngleTo(vec3, Vector3d.ZAxis); if (angle2 < angle) { - vec2 = vec3; - angle = angle2; - item.Edge = edge; + vec2 = vec3; + angle = angle2; + item.Edge = edge; item.Forward = forward; } } else { - vec2 = vec3; - angle = vec.GetAngleTo(vec2, Vector3d.ZAxis); - item.Edge = edge; + vec2 = vec3; + angle = vec.GetAngleTo(vec2, Vector3d.ZAxis); + item.Edge = edge; item.Forward = forward; - hasNext = true; + hasNext = true; } } } @@ -226,7 +224,7 @@ public static List Topo(List curves) foreach (var curve in curves) { var cc3d = curve.ToCompositeCurve3d(); - if (cc3d != null) + if (cc3d is not null) { geCurves.Add(cc3d); paramss.Add(new List()); @@ -335,7 +333,7 @@ public static List Topo(List curves) if (nums[edge.StartIndex] == 1 && nums[edge.EndIndex] == 1) { nums[edge.StartIndex] = 0; - nums[edge.EndIndex] = 0; + nums[edge.EndIndex] = 0; } else { @@ -343,12 +341,12 @@ public static List Topo(List curves) if (nums[edge.StartIndex] == 1) { nums[edge.StartIndex] = 0; - nums[next = edge.EndIndex]--; + nums[next = edge.EndIndex]--; } else { nums[edge.EndIndex] = 0; - nums[next = edge.StartIndex]--; + nums[next = edge.StartIndex]--; } } } @@ -373,7 +371,7 @@ public static List Topo(List curves) var node = regions[i].First; var curve = node.Value.Edge.Curve; var node2 = regions[j].GetNode(e => e.Edge.Curve == curve); - if (eq = node2 != null) + if (eq = node2 is not null) { var b = node.Value.Forward; var b2 = node2.Value.Forward; @@ -421,7 +419,7 @@ public static List BreakCurve(List curves) foreach (var curve in curves) { var cc3d = curve.ToCompositeCurve3d(); - if (cc3d != null) + if (cc3d is not null) { geCurves.Add(cc3d); paramss.Add(new List()); @@ -459,7 +457,7 @@ public static List BreakCurve(List curves) foreach (CompositeCurve3d c3d in c3ds) { Curve c = c3d.ToCurve(); - if (c != null) + if (c is not null) { c.SetPropertiesFrom(curves[i]); newCurves.Add(c); @@ -483,7 +481,7 @@ public static List BreakCurve(List curves) /// 曲线 /// ge曲线 [Obsolete("请使用Cad自带的 GetGeCurve 函数!")] - public static Curve3d ToCurve3d(this Curve curve) + public static Curve3d? ToCurve3d(this Curve curve) { return curve switch { @@ -504,7 +502,7 @@ public static Curve3d ToCurve3d(this Curve curve) /// /// 曲线 /// 复合曲线 - public static CompositeCurve3d ToCompositeCurve3d(this Curve curve) + public static CompositeCurve3d? ToCompositeCurve3d(this Curve curve) { return curve switch { @@ -526,7 +524,7 @@ public static CompositeCurve3d ToCompositeCurve3d(this Curve curve) /// /// 曲线 /// Nurb曲线 - public static NurbCurve3d ToNurbCurve3d(this Curve curve) + public static NurbCurve3d? ToNurbCurve3d(this Curve curve) { return curve switch { @@ -644,7 +642,7 @@ public static EllipticalArc3d ToEllipticalArc3d(this Arc arc) public static NurbCurve3d ToNurbCurve3d(this Arc arc) { return new NurbCurve3d(ToEllipticalArc3d(arc)); - } + } #endregion Arc @@ -780,14 +778,11 @@ public static NurbCurve3d ToNurbCurve3d(this Polyline2d pl2d) /// 三维ge多段线 public static PolylineCurve3d ToPolylineCurve3d(this Polyline2d pl) { - Point3dCollection pnts = new Point3dCollection(); + var pnts = new Point3dCollection(); foreach (Vertex2d ver in pl) - { pnts.Add(ver.Position); - } return new PolylineCurve3d(pnts); } - #endregion Polyline2d #region Polyline3d @@ -888,11 +883,11 @@ public static NurbCurve3d ToNurbCurve3d(this Polyline pl) default: break; } - if (nc3d == null) + if (nc3d is null) { nc3d = nc3dtemp; } - else if (nc3dtemp != null) + else if (nc3dtemp is not null) { nc3d.JoinWith(nc3dtemp); } @@ -912,16 +907,16 @@ public static void ChamferAt(this Polyline polyline, int index, double radius, b if (index < 1 || index > polyline.NumberOfVertices - 2) throw new System.Exception("错误的索引号"); - if (polyline.GetSegmentType(index - 1) != SegmentType.Line || polyline.GetSegmentType(index) != SegmentType.Line) + if (polyline.GetSegmentType(index - 1) != SegmentType.Line || + polyline.GetSegmentType(index) != SegmentType.Line) throw new System.Exception("非直线段不能倒角"); //获取当前索引号的前后两段直线,并组合为Ge复合曲线 - Curve3d[] c3ds = - new Curve3d[] - { - polyline.GetLineSegmentAt(index - 1), - polyline.GetLineSegmentAt(index) - }; + var c3ds = new Curve3d[] + { + polyline.GetLineSegmentAt(index - 1), + polyline.GetLineSegmentAt(index) + }; var cc3d = new CompositeCurve3d(c3ds); //试倒直角 @@ -929,31 +924,26 @@ public static void ChamferAt(this Polyline polyline, int index, double radius, b //1、=3时倒角方向正确 //2、=2时倒角方向相反 //3、=0或为直线时失败 - c3ds = - cc3d.GetTrimmedOffset - ( - radius, - Vector3d.ZAxis, - OffsetCurveExtensionType.Chamfer - ); + c3ds = cc3d.GetTrimmedOffset + ( + radius, + Vector3d.ZAxis, + OffsetCurveExtensionType.Chamfer + ); - if (c3ds.Length > 0 && c3ds[0] is CompositeCurve3d) + if (c3ds.Length > 0 && c3ds[0] is CompositeCurve3d newcc3d) { - var newcc3d = c3ds[0] as CompositeCurve3d; c3ds = newcc3d.GetCurves(); if (c3ds.Length == 3) { - c3ds = - cc3d.GetTrimmedOffset - ( - -radius, - Vector3d.ZAxis, - OffsetCurveExtensionType.Chamfer - ); + c3ds = cc3d.GetTrimmedOffset + ( + -radius, + Vector3d.ZAxis, + OffsetCurveExtensionType.Chamfer + ); if (c3ds.Length == 0 || c3ds[0] is LineSegment3d) - { throw new System.Exception("倒角半径过大"); - } } else if (c3ds.Length == 2) { @@ -966,26 +956,22 @@ public static void ChamferAt(this Polyline polyline, int index, double radius, b } //GetTrimmedOffset会生成倒角+偏移,故先反方向倒角,再倒回 - c3ds = - cc3d.GetTrimmedOffset - ( - -radius, - Vector3d.ZAxis, - OffsetCurveExtensionType.Extend - ); - OffsetCurveExtensionType type = - isFillet ? - OffsetCurveExtensionType.Fillet : OffsetCurveExtensionType.Chamfer; - c3ds = - c3ds[0].GetTrimmedOffset - ( - radius, - Vector3d.ZAxis, - type - ); + c3ds = cc3d.GetTrimmedOffset + ( + -radius, + Vector3d.ZAxis, + OffsetCurveExtensionType.Extend + ); + var type = isFillet ? OffsetCurveExtensionType.Fillet : OffsetCurveExtensionType.Chamfer; + c3ds = c3ds[0].GetTrimmedOffset + ( + radius, + Vector3d.ZAxis, + type + ); //将结果Ge曲线转为Db曲线,并将相关的数值反映到原曲线 - Polyline plTemp = c3ds[0].ToCurve() as Polyline; + var plTemp = c3ds[0].ToCurve() as Polyline; polyline.RemoveVertexAt(index); polyline.AddVertexAt(index, plTemp.GetPoint2dAt(1), plTemp.GetBulgeAt(1), 0, 0); polyline.AddVertexAt(index + 1, plTemp.GetPoint2dAt(2), 0, 0, 0); @@ -995,4 +981,4 @@ public static void ChamferAt(this Polyline polyline, int index, double radius, b #endregion Curve } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/DBDictionaryEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/DBDictionaryEx.cs index dff4ff3b8749989511844ed12d66fc370a7c9943..d4fba82c7de97d5e167e894c7eaf93c8c89fe9ab 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/DBDictionaryEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/DBDictionaryEx.cs @@ -55,16 +55,16 @@ public static T GetAt(this DBDictionary dict, string key, Transaction trans = /// /// 对象类型 /// 字典 - /// 事务 + /// 事务 /// 键 /// 值 - public static void SetAt(this DBDictionary dict, string key, T obj, Transaction trans = null) where T : DBObject + public static void SetAt(this DBDictionary dict, string key, T obj, Transaction tr = null) where T : DBObject { - trans ??= DBTrans.Top.Transaction; + tr ??= DBTrans.Top.Transaction; using (dict.ForWrite()) { dict.SetAt(key, obj); - trans.AddNewlyCreatedDBObject(obj, true); + tr.AddNewlyCreatedDBObject(obj, true); } } @@ -79,7 +79,7 @@ public static void SetAt(this DBDictionary dict, string key, T obj, Transacti public static XRecordDataList GetXRecord(this DBDictionary dict, string key) { Xrecord rec = dict.GetAt(key); - if (rec != null) + if (rec is not null) return rec.Data; return null; } @@ -116,7 +116,7 @@ public static DBDictionary GetXDictionary(this DBObject obj, Transaction trans = id = obj.ExtensionDictionary; } - return id.GetObject(tr:trans); + return id.GetObject(tr: trans); } #region 数据表 @@ -158,8 +158,8 @@ public static DataTable CreateDataTable(Dictionary colTypes, o /// 数据 public static void SetValue(this DataCell cell, CellType type, object value) { - - + + switch (type) { case CellType.Bool: diff --git a/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs index eac264cd107be9cb8821f3b46db4a642d6d1f6ae..3052258082cd2fbae9c1967ffc11960aaaaf0fd1 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/DBObjectEx.cs @@ -75,7 +75,7 @@ public static void ChangeXData(this DBObject obj, string appName, DxfCode dxfCod break; if (data[i].TypeCode == (int)dxfCode) { - data[i] = new TypedValue((int)dxfCode,newvalue); + data[i] = new TypedValue((int)dxfCode, newvalue); } } } @@ -83,7 +83,7 @@ public static void ChangeXData(this DBObject obj, string appName, DxfCode dxfCod using (obj.ForWrite()) { obj.XData = data; - } + } } #endregion diff --git a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs index a396bbd2ce803c46153c0a7b9d0ec1a4195f4682..9745eb94f54dc93215ed169f318fa7aa234163ea 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs @@ -200,9 +200,9 @@ public static void WriteMessage(string format, params object[] args) /// 有,没有 public static bool HasEditor() { - return Application.DocumentManager.MdiActiveDocument != null + return Application.DocumentManager.MdiActiveDocument is not null && Application.DocumentManager.Count != 0 - && Application.DocumentManager.MdiActiveDocument.Editor != null; + && Application.DocumentManager.MdiActiveDocument.Editor is not null; }// /// @@ -516,7 +516,7 @@ public static Matrix3d GetMatrix(this Editor editor, CoordinateSystemCode from, (CoordinateSystemCode.MDcs, CoordinateSystemCode.Ucs) => editor.GetMatrixFromMDcsToWcs() * editor.GetMatrixFromWcsToUcs(), (CoordinateSystemCode.MDcs, CoordinateSystemCode.PDcs) => editor.GetMatrixFromMDcsToPDcs(), (CoordinateSystemCode.PDcs, CoordinateSystemCode.MDcs) => editor.GetMatrixFromPDcsToMDcs(), - (CoordinateSystemCode.PDcs, CoordinateSystemCode.Wcs or CoordinateSystemCode.Ucs) + (CoordinateSystemCode.PDcs, CoordinateSystemCode.Wcs or CoordinateSystemCode.Ucs) or (CoordinateSystemCode.Wcs or CoordinateSystemCode.Ucs, CoordinateSystemCode.PDcs) => throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.InvalidInput,"To be used only with DCS"), (_, _) => Matrix3d.Identity }; @@ -548,8 +548,8 @@ public static void ZoomWindow(this Editor ed, Point3d minPoint, Point3d maxPoint { for (int k = 0; k < 2; k++) { - int n = i * 4 + j * 2 + k; - pnts[n] = new Point3d(oldpnts[i][0], oldpnts[j][1], oldpnts[k][2]); + int n = i * 4 + j * 2 + k; + pnts[n] = new Point3d(oldpnts[i][0], oldpnts[j][1], oldpnts[k][2]); dpnts[n] = pnts[n].TransformBy(ed.GetMatrixFromWcsToMDcs()); } } @@ -624,7 +624,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) { - Database db = ed.Document.Database; + var db = ed.Document.Database; db.UpdateExt(true); ed.ZoomWindow(db.Extmax, db.Extmin, offsetDist); } @@ -638,7 +638,7 @@ public static void ZoomExtents(this Editor ed, double offsetDist = 0.00) public static void ZoomObject(this Editor ed, Entity ent, double offsetDist = 0.00) { Extents3d ext = ent.GeometricExtents; - ed.ZoomWindow(ext.MinPoint, ext.MinPoint, offsetDist); + ed.ZoomWindow(ext.MinPoint, ext.MaxPoint, offsetDist); } #endregion @@ -656,7 +656,7 @@ public static PromptPointResult GetPoint(this Editor ed, string Message, Point3d { PromptPointOptions ptOp = new(Message) { - BasePoint = BasePoint, + BasePoint = BasePoint, UseBasePoint = true }; return ed.GetPoint(ptOp); @@ -737,22 +737,16 @@ public static PromptResult GetString(this Editor ed, string Message, string Defa /// 缓冲结果,返回值 public static ResultBuffer RunLisp(this Editor ed, string arg) { - _ = AcedEvaluateLisp(arg, out IntPtr rb); - if (rb != IntPtr.Zero) + AcedEvaluateLisp(arg, out IntPtr rb); + try { - try - { - var rbb = DisposableWrapper.Create(typeof(ResultBuffer), rb, true) as ResultBuffer; - return rbb; - } - catch - { - return null; - } + if (rb != IntPtr.Zero) + return DisposableWrapper.Create(typeof(ResultBuffer), rb, true) as ResultBuffer; } + catch + { } return null; } - #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 795e9df2024f833b7c89955e2a4aab700bc607cc..c14b566ddf62a1276ea031540d9e814bc68eb7e9 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/EntityEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/EntityEx.cs @@ -225,8 +225,7 @@ public static string GetUnFormatString(this MText mt) List strs = new(); mt.ExplodeFragments( strs, - (f, o) => - { + (f, o) => { o.Add(f.Text); return MTextFragmentCallbackStatus.Continue; }); @@ -317,13 +316,13 @@ public static Circle CreateCircle(Point3d startPoint, Point3d endPoint) /// 三点法创建圆(失败则返回Null) /// /// 第一点 - /// 第二点 + /// 第二点 /// 第三点 /// - public static Circle CreateCircle(Point3d pt1, Point3d pt2, Point3d pt3) + public static Circle CreateCircle(Point3d pt1, Point3d PointV, Point3d pt3) { - //先判断三点是否共线,得到pt1点指向pt2、pt2点的矢量 - Vector3d va = pt1.GetVectorTo(pt2); + //先判断三点是否共线,得到pt1点指向PointV、PointV点的矢量 + Vector3d va = pt1.GetVectorTo(PointV); Vector3d vb = pt1.GetVectorTo(pt3); //如两矢量夹角为0或180度(π弧度),则三点共线. if (va.GetAngleTo(vb) == 0 | va.GetAngleTo(vb) == Math.PI) @@ -333,7 +332,7 @@ public static Circle CreateCircle(Point3d pt1, Point3d pt2, Point3d pt3) else { //创建一个几何类的圆弧对象 - CircularArc3d geArc = new(pt1, pt2, pt3); + CircularArc3d geArc = new(pt1, PointV, pt3); geArc.ToCircle(); return geArc.ToCircle(); } @@ -355,11 +354,11 @@ public static Circle CreateCircle(Point3d pt1, Point3d pt2, Point3d pt3) /// 裁剪多边形点表 public static void ClipBlockRef(this BlockReference bref, IEnumerable pt3ds) { - if (bref == null) + if (bref is null) { throw new ArgumentNullException(nameof(bref)); } - if (pt3ds == null) + if (pt3ds is null) { throw new ArgumentNullException(nameof(pt3ds)); } @@ -382,20 +381,20 @@ public static void ClipBlockRef(this BlockReference bref, IEnumerable p /// /// 块参照 /// 第一角点 - /// 第二角点 - public static void ClipBlockRef(this BlockReference bref, Point3d pt1, Point3d pt2) + /// 第二角点 + public static void ClipBlockRef(this BlockReference bref, Point3d pt1, Point3d PointV) { - if (bref == null) + if (bref is null) { throw new ArgumentNullException(nameof(bref)); } Matrix3d mat = bref.BlockTransform.Inverse(); pt1 = pt1.TransformBy(mat); - pt2 = pt2.TransformBy(mat); + PointV = PointV.TransformBy(mat); Point2dCollection pts = new() { - new Point2d(Math.Min(pt1.X, pt2.X), Math.Min(pt1.Y, pt2.Y)), - new Point2d(Math.Max(pt1.X, pt2.X), Math.Max(pt1.Y, pt2.Y)) + new Point2d(Math.Min(pt1.X, PointV.X), Math.Min(pt1.Y, PointV.Y)), + new Point2d(Math.Max(pt1.X, PointV.X), Math.Max(pt1.Y, PointV.Y)) }; SpatialFilterDefinition sfd = new(pts, Vector3d.ZAxis, 0.0, 0.0, 0.0, true); diff --git a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs index d2e337250ef78a1e85774125b76c01ee9cc83e65..8f2a7a1059f5d04c5d6c5145c914c1644791b629 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/GeometryEx.cs @@ -13,6 +13,10 @@ namespace IFoxCAD.Cad /// public static class GeometryEx { + public static double DistanceTo(this Point2d pt1, Point2d PointV) + { + return pt1.GetDistanceTo(PointV); + } #region Point&Circle @@ -50,12 +54,12 @@ public static PointOnRegionType PointOnRegion(this IEnumerable pts, Poi foreach (var node in ptlst.GetNodes()) { var pt1 = node.Value; - var pt2 = node.Next.Value; - if (pt.Y < pt1.Y && pt.Y < pt2.Y) + var PointV = node.Next.Value; + if (pt.Y < pt1.Y && pt.Y < PointV.Y) continue; - if (pt1.X < pt.X && pt2.X < pt.X) + if (pt1.X < pt.X && PointV.X < pt.X) continue; - Vector2d vec = pt2 - pt1; + Vector2d vec = PointV - pt1; double t = (pt.X - pt1.X) / vec.X; double y = t * vec.Y + pt1.Y; if (y < pt.Y && t >= 0 && t <= 1) @@ -102,12 +106,12 @@ public static PointOnRegionType PointOnRegion(this IEnumerable pts, Poi foreach (var node in ptlst.GetNodes()) { var pt1 = node.Value; - var pt2 = node.Next.Value; - if (pt.Y < pt1.Y && pt.Y < pt2.Y) + var PointV = node.Next.Value; + if (pt.Y < pt1.Y && pt.Y < PointV.Y) continue; - if (pt1.X < pt.X && pt2.X < pt.X) + if (pt1.X < pt.X && PointV.X < pt.X) continue; - Vector3d vec = pt2 - pt1; + Vector3d vec = PointV - pt1; double t = (pt.X - pt1.X) / vec.X; double y = t * vec.Y + pt1.Y; if (y < pt.Y && t >= 0 && t <= 1) @@ -122,17 +126,17 @@ public static PointOnRegionType PointOnRegion(this IEnumerable pts, Poi /// 按两点返回最小包围圆 /// /// 基准点 - /// 基准点 + /// 基准点 /// 输出圆上的点 /// 解析类圆对象 - public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, out LoopList ptlst) + public static CircularArc2d GetMinCircle(Point2d pt1, Point2d PointV, out LoopList ptlst) { - ptlst = new LoopList { pt1, pt2 }; + ptlst = new LoopList { pt1, PointV }; return new CircularArc2d ( - (pt1 + pt2.GetAsVector()) / 2, - pt1.GetDistanceTo(pt2) / 2 + (pt1 + PointV.GetAsVector()) / 2, + pt1.DistanceTo(PointV) / 2 ); } @@ -140,14 +144,13 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, out LoopList< /// 按三点返回最小包围圆 /// /// 基准点 - /// 基准点 + /// 基准点 /// 基准点 /// 输出圆上的点 /// 解析类圆对象 - public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, out LoopList ptlst) + public static CircularArc2d GetMinCircle(Point2d pt1, Point2d PointV, Point2d pt3, out LoopList ptlst) { - ptlst = - new LoopList { pt1, pt2, pt3 }; + ptlst = new LoopList { pt1, PointV, pt3 }; //遍历各点与下一点的向量长度,找到距离最大的两个点 double maxLength; @@ -155,7 +158,7 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, ptlst.GetNodes().FindByMax ( out maxLength, - node => node.Value.GetDistanceTo(node.Next.Value) + node => node.Value.DistanceTo(node.Next.Value) ); //以两点做最小包围圆 @@ -173,7 +176,7 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, //否则按三点做圆 ptlst.SetFirst(maxNode); - ca2d = new CircularArc2d(pt1, pt2, pt3); + ca2d = new CircularArc2d(pt1, PointV, pt3); ca2d.SetAngles(0, Math.PI * 2); return ca2d; } @@ -182,15 +185,15 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, /// 按四点返回最小包围圆 /// /// 基准点 - /// 基准点 + /// 基准点 /// 基准点 /// 基准点 /// 输出圆上的点 /// 解析类圆对象 - public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, Point2d pt4, out LoopList ptlst) + public static CircularArc2d GetMinCircle(Point2d pt1, Point2d PointV, Point2d pt3, Point2d pt4, out LoopList ptlst) { LoopList iniptlst = - new LoopList { pt1, pt2, pt3, pt4 }; + new LoopList { pt1, PointV, pt3, pt4 }; ptlst = null; CircularArc2d ca2d = null; @@ -207,9 +210,9 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, //如果另一点属于该圆,并且半径小于当前值就把它做为候选解 if (tca2d.IsIn(firstNode.Previous.Value)) { - if (ca2d == null || tca2d.Radius < ca2d.Radius) + if (ca2d is null || tca2d.Radius < ca2d.Radius) { - ca2d = tca2d; + ca2d = tca2d; ptlst = tptlst; } } @@ -224,22 +227,22 @@ public static CircularArc2d GetMinCircle(Point2d pt1, Point2d pt2, Point2d pt3, /// /// 基准点 /// 第一点 - /// 第二点 + /// 第二点 /// 三点围成的三角形的有向面积 - private static double CalArea(Point2d ptBase, Point2d pt1, Point2d pt2) + private static double CalArea(Point2d ptBase, Point2d pt1, Point2d PointV) { - return (pt2 - ptBase).DotProduct((pt1 - ptBase).GetPerpendicularVector()) / 2; + return (PointV - ptBase).DotProduct((pt1 - ptBase).GetPerpendicularVector()) / 2; } /// /// 计算三点围成的三角形的真实面积 /// /// 基准点 /// 第一点 - /// 第二点 + /// 第二点 /// 三点围成的三角形的真实面积 - public static double GetArea(this Point2d ptBase, Point2d pt1, Point2d pt2) + public static double GetArea(this Point2d ptBase, Point2d pt1, Point2d PointV) { - return Math.Abs(CalArea(ptBase, pt1, pt2)); + return Math.Abs(CalArea(ptBase, pt1, PointV)); } /// @@ -247,12 +250,12 @@ public static double GetArea(this Point2d ptBase, Point2d pt1, Point2d pt2) /// /// 基点 /// 第一点 - /// 第二点 + /// 第二点 /// OrientationType 类型值 - public static OrientationType IsClockWise(this Point2d ptBase, Point2d pt1, Point2d pt2) + public static OrientationType IsClockWise(this Point2d ptBase, Point2d pt1, Point2d PointV) { - return CalArea(ptBase, pt1, pt2) switch + return CalArea(ptBase, pt1, PointV) switch { > 0 => OrientationType.CounterClockWise, @@ -385,7 +388,7 @@ public static CircularArc2d GetMinCircle(this List pnts, out LoopList

ca2d.Center.GetDistanceTo(pnt)); + tpnts[3] = pnts.FindByMax(pnt => ca2d.Center.DistanceTo(pnt)); //如果最远点属于圆结束 while (!ca2d.IsIn(tpnts[3])) @@ -404,7 +407,7 @@ public static CircularArc2d GetMinCircle(this List pnts, out LoopList

ca2d.Center.GetDistanceTo(pnt)); + .FindByMax(pnt => ca2d.Center.DistanceTo(pnt)); } tpnts[0] = ptlst.First.Value; tpnts[1] = ptlst.First.Next.Value; @@ -413,7 +416,7 @@ public static CircularArc2d GetMinCircle(this List pnts, out LoopList

ca2d.Center.GetDistanceTo(pnt)); + tpnts[3] = pnts.FindByMax(pnt => ca2d.Center.DistanceTo(pnt)); } return ca2d; @@ -426,7 +429,7 @@ public static CircularArc2d GetMinCircle(this List pnts, out LoopList

凸包 public static List ConvexHull(this List points) { - if (points == null) + if (points is null) return null; if (points.Count <= 1) @@ -559,7 +562,7 @@ public static Vector3d Wcs2Dcs(this Vector3d vec, bool atPaperSpace) #endregion Ucs - + ///

/// 返回不等比例变换矩阵 /// @@ -620,16 +623,16 @@ public static Point3d Point3d(this Point2d pt) { return new Point3d(pt.X, pt.Y, 0); } - + /// /// 获取两个点之间的中点 /// /// 第一点 - /// 第二点 + /// 第二点 /// 返回两个点之间的中点 - public static Point3d GetMidPointTo(this Point3d pt1, Point3d pt2) + public static Point3d GetMidPointTo(this Point3d pt1, Point3d PointV) { - return new Point3d((pt1.X + pt2.X) * 0.5, (pt1.Y + pt2.Y) * 0.5, (pt1.Z + pt2.Z) * 0.5); + return new Point3d((pt1.X + PointV.X) * 0.5, (pt1.Y + PointV.Y) * 0.5, (pt1.Z + PointV.Z) * 0.5); } /// @@ -659,4 +662,4 @@ public static Point3d Polar(this Point3d pt, double ang, double len) return pt + Vector3d.XAxis.RotateBy(ang, Vector3d.ZAxis) * len; } } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/ObjectIdEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/ObjectIdEx.cs index fef501c2a0c3c73f7c3cb7160db321ced5cf05a6..2a89bd5232b8696a07379ef7a02e148effde0453 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/ObjectIdEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/ObjectIdEx.cs @@ -21,7 +21,8 @@ public static class ObjectIdEx /// 打开模式 /// 打开删除对象 /// 指定类型对象 - public static T GetObject(this ObjectId id, OpenMode mode = OpenMode.ForRead, bool openErased = false, Transaction tr = default) where T : DBObject + public static T GetObject(this ObjectId id, + OpenMode mode = OpenMode.ForRead, bool openErased = false, Transaction tr = default) where T : DBObject { tr ??= DBTrans.Top.Transaction; return tr.GetObject(id, mode, openErased) as T; @@ -36,11 +37,12 @@ public static T GetObject(this ObjectId id, OpenMode mode = OpenMode.ForRead, /// 打开模式 /// 打开删除对象 /// 指定类型对象集合 - public static IEnumerable GetObject(this IEnumerable ids, OpenMode mode = OpenMode.ForRead, bool openErased = false, Transaction tr = default) where T : DBObject + public static IEnumerable GetObject(this IEnumerable ids, + OpenMode mode = OpenMode.ForRead, bool openErased = false, Transaction tr = default) where T : DBObject { return ids.Select(id => id.GetObject(mode, openErased, tr)); } - + /// /// 返回符合类型的对象id /// @@ -50,11 +52,19 @@ public static IEnumerable GetObject(this IEnumerable ids, OpenMo public static IEnumerable OfType(this IEnumerable ids) where T : DBObject { string dxfName = RXClass.GetClass(typeof(T)).DxfName; - return - ids - .Where(id => id.ObjectClass.DxfName == dxfName); + return ids.Where(id => id.ObjectClass().DxfName == dxfName); + } + + //Acad08缺少 id.ObjectClass 如何补偿? + public static RXClass ObjectClass(this ObjectId id) + { +#if NET35 + return RXClass.GetClass(id.GetType()); +#else + return id.ObjectClass; +#endif } #endregion GetObject } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SelectionSetEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SelectionSetEx.cs index e8e91f5260f5b51b5e5046f797919b0f24c27a8c..9ede8886ff638c33bfa1cead1e4cb9a4c0b9816c 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SelectionSetEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SelectionSetEx.cs @@ -7,7 +7,7 @@ namespace IFoxCAD.Cad { - + /// /// 选择集扩展类 /// @@ -47,7 +47,7 @@ public static IEnumerable GetObjectIds(this SelectionSet ss) where return ss .GetObjectIds() - .Where(id => id.ObjectClass.DxfName == dxfName); + .Where(id => id.ObjectClass().DxfName == dxfName); } /// @@ -60,7 +60,7 @@ public static IEnumerable> GetObjectIdGroup(this Sel return ss .GetObjectIds() - .GroupBy(id => id.ObjectClass.DxfName); + .GroupBy(id => id.ObjectClass().DxfName); } #endregion @@ -74,14 +74,14 @@ public static IEnumerable> GetObjectIdGroup(this Sel /// 事务 /// 打开模式 /// 图元集合 - public static IEnumerable GetEntities(this SelectionSet ss, OpenMode openMode=OpenMode.ForRead, Transaction tr = default) where T : Entity + public static IEnumerable GetEntities(this SelectionSet ss, OpenMode openMode = OpenMode.ForRead, Transaction tr = default) where T : Entity { return ss .GetObjectIds() .Select(id => tr.GetObject(id, openMode) as T); } - + #endregion #region ForEach @@ -103,4 +103,4 @@ public static void ForEach(this SelectionSet ss, Action action, OpenMode o } #endregion } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs index 61fd058cdd8a6aa70d24a0ac96b281d20603abd2..327f8bae9fbc75d876a5522928444d9ecd953a46 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableEx.cs @@ -37,7 +37,7 @@ public static ObjectId Add(this SymbolTable table, /// 图层id public static ObjectId Add(this SymbolTable table, string name, int colorIndex) { - colorIndex %= 256;//防止输入的颜色超出256 + colorIndex %= 256; //防止输入的颜色超出256 colorIndex = Math.Abs(colorIndex);//防止负数 return table.Add(name, lt => lt.Color = Color.FromColorIndex(ColorMethod.ByColor, (short)colorIndex)); } @@ -51,8 +51,7 @@ public static ObjectId Rename(this SymbolTable tab { if (table.Has(Oldname)) { - table.Change(Oldname, ly => - { + table.Change(Oldname, ly => { ly.Name = NewName; } ); @@ -102,16 +101,15 @@ public static bool Delete(this SymbolTable table, /// TODO: 需要测试匿名块等特殊的块是否能定义 public static ObjectId Add(this SymbolTable table, string name, Action action = null, Func> ents = null, Func> attdef = null) { - return table.Add(name, btr => - { + return table.Add(name, btr => { action?.Invoke(btr); var entsres = ents?.Invoke(); - if (entsres != null) + if (entsres is not null) { btr.AddEntity(entsres); } var adddefres = attdef?.Invoke(); - if (adddefres != null) + if (adddefres is not null) { btr.AddEntity(adddefres); } @@ -216,10 +214,9 @@ public static ObjectId Add(this SymbolTable { return table.Add( name, - ltt => - { + ltt => { ltt.AsciiDescription = description; - ltt.PatternLength = length; //线型的总长度 + ltt.PatternLength = length; //线型的总长度 ltt.NumDashes = dash.Length; //组成线型的笔画数目 for (int i = 0; i < dash.Length; i++) { @@ -248,11 +245,10 @@ public static ObjectId Add(this SymbolTable - { - tstr.Name = textStyleName; + tstr => { + tstr.Name = textStyleName; tstr.FileName = font; - tstr.XScale = xscale; + tstr.XScale = xscale; }); } #endregion diff --git a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs index 4f73f651a31c6f9942f894256a9ed1e6cba974e7..c66b2e2bc1a7d21c3d2d5b31c0dc8b9ad7a8e120 100644 --- a/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs +++ b/src/IFoxCAD.Cad/ExtensionMethod/SymbolTableRecordEx.cs @@ -27,19 +27,19 @@ public static class SymbolTableRecordEx /// /// 块表记录 /// 实体 - /// 事务管理器 + /// 事务管理器 /// 对象 id - public static ObjectId AddEntity(this BlockTableRecord btr, Entity entity, Transaction trans = null) + public static ObjectId AddEntity(this BlockTableRecord btr, Entity entity, Transaction tr = null) { if (entity is null) - throw new ArgumentNullException(nameof(entity),"对象为 null"); + throw new ArgumentNullException(nameof(entity), "对象为 null"); ObjectId id; - trans ??= DBTrans.Top.Transaction; + tr ??= DBTrans.Top.Transaction; using (btr.ForWrite()) { id = btr.AppendEntity(entity); - trans.AddNewlyCreatedDBObject(entity, true); + tr.AddNewlyCreatedDBObject(entity, true); } return id; } @@ -52,20 +52,19 @@ public static ObjectId AddEntity(this BlockTableRecord btr, Entity entity, Trans /// 事务 /// 实体集合 /// 对象 id 列表 - public static IEnumerable AddEntity(this BlockTableRecord btr, IEnumerable ents, Transaction trans = null) where T : Entity + public static IEnumerable AddEntity(this BlockTableRecord btr, IEnumerable ents, Transaction tr = null) where T : Entity { - if (ents.Any(ent => ent is null)) + if (ents.Any(ent => ent is null)) throw new ArgumentNullException(nameof(ents), "实体集合内存在 null 对象"); - trans ??= DBTrans.Top.Transaction; + tr ??= DBTrans.Top.Transaction; using (btr.ForWrite()) { return ents .Select( - ent => - { + ent => { ObjectId id = btr.AppendEntity(ent); - trans.AddNewlyCreatedDBObject(ent, true); + tr.AddNewlyCreatedDBObject(ent, true); return id; }) .ToList(); @@ -180,13 +179,13 @@ public static ObjectId AddPline(this BlockTableRecord btr, List pts, Li /// 轻多段线id public static ObjectId AddPline(this BlockTableRecord btr, List<(Point3d pt, double bulge, double startWidth, double endWidth)> pts, Action action = default, Transaction trans = default) { - + Polyline pl = new(); pts.ForEach((i, vertex) => { pl.AddVertexAt(i, vertex.pt.Point2d(), vertex.bulge, vertex.startWidth, vertex.endWidth); }); - + return btr.AddEnt(pl, action, trans); } #endif @@ -238,7 +237,7 @@ public static IEnumerable GetObjectIds(this BlockTableRecord btr) w { string dxfName = RXClass.GetClass(typeof(T)).DxfName; return btr.Cast() - .Where(id => id.ObjectClass.DxfName == dxfName); + .Where(id => id.ObjectClass().DxfName == dxfName); } /// @@ -251,7 +250,7 @@ public static IEnumerable> GetObjectIds(this BlockTa return btr .Cast() - .GroupBy(id => id.ObjectClass.DxfName); + .GroupBy(id => id.ObjectClass().DxfName); } /// @@ -306,9 +305,9 @@ public static ObjectId InsertBlock(this BlockTableRecord blockTableRecord, Point ObjectId blockId, Scale3d scale = default, double rotation = default, - Dictionary atts = default, Transaction trans = null) + Dictionary atts = default, Transaction tr = null) { - trans ??= DBTrans.Top.Transaction; + tr ??= DBTrans.Top.Transaction; if (!DBTrans.Top.BlockTable.Has(blockId)) { DBTrans.Top.Editor.WriteMessage($"\n不存在名字为{DBTrans.Top.GetObject(blockId).Name}的块定义。"); @@ -335,12 +334,10 @@ public static ObjectId InsertBlock(this BlockTableRecord blockTableRecord, Point attref.Position = attdef.Position.TransformBy(blockref.BlockTransform); attref.AdjustAlignment(DBTrans.Top.Database); if (atts.ContainsKey(attdef.Tag)) - { attref.TextString = atts[attdef.Tag]; - } blockref.AttributeCollection.AppendAttribute(attref); - trans.AddNewlyCreatedDBObject(attref, true); + tr.AddNewlyCreatedDBObject(attref, true); } } } diff --git a/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj b/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj index b28ee58b429e2cd2281c19badfc9a57ab1a8cf8c..d742beff1450f6b92fbd4e51faae2c957d2ff76e 100644 --- a/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj +++ b/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj @@ -1,66 +1,66 @@ - + + + + preview + enable - - net35;net40 - true - 0.1.3 - InspireFunction - xsfhlzh;vicwjb - 基于.NET的Cad二次开发类库 - InspireFunction - https://gitee.com/inspirefunction/ifoxcad - https://gitee.com/inspirefunction/ifoxcad.git - git - IFoxCAD;CAD;AutoCad;C#;NET - Optimize and add multiple functions. - true - true - preview - true - LICENSE - true - + net35;net40 + true + 0.1.3 + InspireFunction + xsfhlzh;vicwjb + 基于.NET的Cad二次开发类库 + InspireFunction + https://gitee.com/inspirefunction/ifoxcad + https://gitee.com/inspirefunction/ifoxcad.git + git + IFoxCAD;CAD;AutoCad;C#;NET + Optimize and add multiple functions. + true + true + true + LICENSE + true + - - - runtime - - - - - runtime - - - + + + + + + runtime + + + - - DEBUG - - - $(Configuration);ac2009 - - - $(Configuration);ac2013 - - - - - - True - - - + + DEBUG + + + $(Configuration);ac2009 + + + $(Configuration);ac2013 + - - - - - - + + + True + + + - - - + + + + + + + + + + + diff --git a/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj.data b/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj.data index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5f282702bb03ef11d7184d19c80927b47f919764 100644 --- a/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj.data +++ b/src/IFoxCAD.Cad/IFoxCAD.Cad.csproj.data @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs b/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs index 9acad02506d333d587de5001043d5539416def51..0aa2f6932b5cf37336e437975f26cc9a23e82cb3 100644 --- a/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs +++ b/src/IFoxCAD.Cad/ResultData/LispDottedPair.cs @@ -69,4 +69,4 @@ public override List Value #endregion } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ResultData/LispList.cs b/src/IFoxCAD.Cad/ResultData/LispList.cs index 8f87c2f5f71c57e318917c573bb0a91930d09776..4742d382bb93d8ff6ede68fd28a53ce2be13bc02 100644 --- a/src/IFoxCAD.Cad/ResultData/LispList.cs +++ b/src/IFoxCAD.Cad/ResultData/LispList.cs @@ -199,4 +199,4 @@ public void Add(LispList value) public static implicit operator LispList(TypedValue[] values) => new(values); #endregion } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ResultData/TypedValueList.cs b/src/IFoxCAD.Cad/ResultData/TypedValueList.cs index c82d464e16cce2c4f7825b553b01fba4c81b06d4..2fccce51733e1b3dbb0bead12f8f4ecc2bff92d6 100644 --- a/src/IFoxCAD.Cad/ResultData/TypedValueList.cs +++ b/src/IFoxCAD.Cad/ResultData/TypedValueList.cs @@ -66,4 +66,4 @@ public override string ToString() } #endregion } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ResultData/XRecordDataList.cs b/src/IFoxCAD.Cad/ResultData/XRecordDataList.cs index 1aa23044b5b24bc54f2cba7fba52cdfb6e77b4b6..0364f9a299f8fbce54b6febbe9a9bb92c7efe180 100644 --- a/src/IFoxCAD.Cad/ResultData/XRecordDataList.cs +++ b/src/IFoxCAD.Cad/ResultData/XRecordDataList.cs @@ -62,4 +62,4 @@ public void Add(DxfCode code, object obj) public static implicit operator XRecordDataList(TypedValue[] values) => new(values); #endregion } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/ResultData/XdataList.cs b/src/IFoxCAD.Cad/ResultData/XdataList.cs index c31f53cefb2a12a294b9803025f5f2ada8b74637..e22ffe236e9135c82e9b21674828d7dd3ca189b9 100644 --- a/src/IFoxCAD.Cad/ResultData/XdataList.cs +++ b/src/IFoxCAD.Cad/ResultData/XdataList.cs @@ -16,7 +16,7 @@ public XDataList() } public XDataList(IEnumerable values) : base(values) { } - + #region 添加数据 /// /// 添加数据 @@ -68,4 +68,4 @@ public void Add(DxfCode code, object obj) public static implicit operator XDataList(TypedValue[] values) => new(values); #endregion } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/Runtime/AcadVersion.cs b/src/IFoxCAD.Cad/Runtime/AcadVersion.cs index 4e33b580e9b0625ac777f1108d3f06099ccb1be9..7be301f7b1cd9e0e047c838bc28da5668fa18047 100644 --- a/src/IFoxCAD.Cad/Runtime/AcadVersion.cs +++ b/src/IFoxCAD.Cad/Runtime/AcadVersion.cs @@ -51,7 +51,7 @@ public static List Versions { get { - if (_versions == null) + if (_versions is null) { string[] copys = Registry.LocalMachine @@ -91,7 +91,7 @@ public static List Versions /// cad版本号对象 public static AcadVersion FromApp(object app) { - if (app == null) + if (app is null) { throw new ArgumentNullException(nameof(app)); } @@ -127,4 +127,4 @@ public override string ToString() $"名称:{ProductName}\n版本号:{ProgId}\n注册表位置:{ProductRootKey}"; } } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/Runtime/AssemInfo.cs b/src/IFoxCAD.Cad/Runtime/AssemInfo.cs index 59748006adeb40909196f25b88e8df85d1e78414..62b70f89d46d16a10d3f1964034587aabbc613d9 100644 --- a/src/IFoxCAD.Cad/Runtime/AssemInfo.cs +++ b/src/IFoxCAD.Cad/Runtime/AssemInfo.cs @@ -33,4 +33,4 @@ public struct AssemInfo /// public string Description { get; set; } } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/Runtime/AutoRegAssem.cs b/src/IFoxCAD.Cad/Runtime/AutoRegAssem.cs index 0042dd2a6c811629db13c368d012276221a3a41e..111be639dcf9496623c36784e0942a556b6efdaf 100644 --- a/src/IFoxCAD.Cad/Runtime/AutoRegAssem.cs +++ b/src/IFoxCAD.Cad/Runtime/AutoRegAssem.cs @@ -26,7 +26,7 @@ public enum AssemLoadType /// /// 无效 /// - Disabled = 20 + Disabled = 20 } /// @@ -53,7 +53,7 @@ public abstract class AutoRegAssem : CadRuntime.IExtensionApplication /// 路径对象 public static DirectoryInfo GetDirectory(Assembly assem) { - if (assem == null) + if (assem is null) { throw new(nameof(assem)); } @@ -112,9 +112,9 @@ public void RegApp() appkey.Close(); } -#endregion RegApp + #endregion RegApp -#region IExtensionApplication 成员 + #region IExtensionApplication 成员 /// /// 初始化函数 @@ -126,6 +126,6 @@ public void RegApp() /// public abstract void Terminate(); -#endregion IExtensionApplication 成员 + #endregion IExtensionApplication 成员 } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/Runtime/DBTrans.cs b/src/IFoxCAD.Cad/Runtime/DBTrans.cs index 6de5a786c49965f4c038a63134c5dd2c4c47467f..9507f17a9be4e56cc213d4e89c956014ccfc39d1 100644 --- a/src/IFoxCAD.Cad/Runtime/DBTrans.cs +++ b/src/IFoxCAD.Cad/Runtime/DBTrans.cs @@ -1,14 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; - - -using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.ApplicationServices; -using Autodesk.AutoCAD.Geometry; using System.IO; namespace IFoxCAD.Cad @@ -81,7 +75,7 @@ public DBTrans(Document doc = null, bool commit = true, bool doclock = false) public DBTrans(Database database, bool commit = true) { Database = database; - Init(commit,false); + Init(commit, false); } /// /// 构造函数,打开文件,默认提交事务 @@ -93,7 +87,7 @@ public DBTrans(string fileName, bool commit = true) Database = new Database(false, true); Database.ReadDwgFile(fileName, FileShare.Read, true, null); Database.CloseInput(true); - Init(commit,false); + Init(commit, false); } /// /// 初始化事务及事务队列、提交模式 @@ -261,8 +255,6 @@ public ObjectId GetObjectId(string handleString) return Database.GetObjectId(false, hanle, 0); } - - #endregion @@ -284,7 +276,7 @@ public void Commit() { Abort(); } - + } protected virtual void Dispose(bool disposing) diff --git a/src/IFoxCAD.Cad/Runtime/Env.cs b/src/IFoxCAD.Cad/Runtime/Env.cs index 7df751e3607be17e3a222f7eeaaf194583209fd9..0d490e13225e4bcb308c46374af6e36f3c7a30e8 100644 --- a/src/IFoxCAD.Cad/Runtime/Env.cs +++ b/src/IFoxCAD.Cad/Runtime/Env.cs @@ -1,4 +1,4 @@ -using Autodesk.AutoCAD.ApplicationServices; +using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.GraphicsSystem; @@ -450,4 +450,4 @@ public static void SetEnv(string var, string? value) /// 要打印的对象 public static void Print(object message) => Editor.WriteMessage($"{message}\n"); } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/Runtime/SymbolTable.cs b/src/IFoxCAD.Cad/Runtime/SymbolTable.cs index 374ab580f4d0ef5b799a51292db877ef87a762d6..c319b5e63f33db768a10703f6ea5ce92658c5328 100644 --- a/src/IFoxCAD.Cad/Runtime/SymbolTable.cs +++ b/src/IFoxCAD.Cad/Runtime/SymbolTable.cs @@ -1,14 +1,14 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; -using System.Linq; +using System.Linq; using Autodesk.AutoCAD.DatabaseServices; namespace IFoxCAD.Cad { - public class SymbolTable : IEnumerable - where TTable : SymbolTable + public class SymbolTable : IEnumerable + where TTable : SymbolTable where TRecord : SymbolTableRecord, new() - { + { #region 程序集内部属性 /// /// 事务管理器 @@ -36,7 +36,7 @@ public class SymbolTable : IEnumerable /// 符号表id internal SymbolTable(DBTrans tr, ObjectId tableId) { - DTrans = tr; + DTrans = tr; CurrentSymbolTable = DTrans.GetObject(tableId); } @@ -50,7 +50,7 @@ internal SymbolTable(DBTrans tr, ObjectId tableId) /// 对象的id public ObjectId this[string key] { - get + get { if (Has(key)) { @@ -142,11 +142,11 @@ private static void Remove(TRecord record) public void Remove(string name) { TRecord record = GetRecord(name); - if (record != null) + if (record is not null) { Remove(record); } - + } /// /// 删除符号表记录 @@ -155,7 +155,7 @@ public void Remove(string name) public void Remove(ObjectId id) { TRecord record = GetRecord(id); - if (record != null) + if (record is not null) { Remove(record); } @@ -185,7 +185,7 @@ private static void Change(TRecord record, Action action) public void Change(string name, Action action) { var record = GetRecord(name); - if (record != null) + if (record is not null) { Change(record, action); } @@ -198,7 +198,7 @@ public void Change(string name, Action action) public void Change(ObjectId id, Action action) { var record = GetRecord(id); - if (record != null) + if (record is not null) { Change(record, action); } @@ -273,7 +273,7 @@ public ObjectId GetRecordFrom(SymbolTable table, string name, b { ObjectId id = table[name]; using IdMapping idm = new(); - using (ObjectIdCollection ids = new(){ id }) + using (ObjectIdCollection ids = new() { id }) { table.Database.WblockCloneObjects(ids, CurrentSymbolTable.Id, idm, DuplicateRecordCloning.Replace, false); } diff --git a/src/IFoxCAD.Cad/SelectionFilter/OpComp.cs b/src/IFoxCAD.Cad/SelectionFilter/OpComp.cs index 4e1fb165ca9f7cc3315419b3d7b5d448605e203a..567be46bcde51d274cdc9aa5639052ea25c165aa 100644 --- a/src/IFoxCAD.Cad/SelectionFilter/OpComp.cs +++ b/src/IFoxCAD.Cad/SelectionFilter/OpComp.cs @@ -80,4 +80,4 @@ public override IEnumerable GetValues() yield return Value; } } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/SelectionFilter/OpEqual.cs b/src/IFoxCAD.Cad/SelectionFilter/OpEqual.cs index dac84d529378e6af024a8e26411bdcfe76647200..76dc738e17acb486348d0fdaa120fbc866570a69 100644 --- a/src/IFoxCAD.Cad/SelectionFilter/OpEqual.cs +++ b/src/IFoxCAD.Cad/SelectionFilter/OpEqual.cs @@ -87,4 +87,4 @@ public void SetValue(int code, object value) Value = new TypedValue(code, value); } } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.Cad/SelectionFilter/OpFilter.cs b/src/IFoxCAD.Cad/SelectionFilter/OpFilter.cs index 23ef25bfb06fc09c2d5e509193a72cbf4996c202..cd7312924ff413312512f4fe17d40a85f9c080e8 100644 --- a/src/IFoxCAD.Cad/SelectionFilter/OpFilter.cs +++ b/src/IFoxCAD.Cad/SelectionFilter/OpFilter.cs @@ -339,4 +339,4 @@ private static Op GetCompOp(string content, Op left, object right) #endregion Operator } -} \ No newline at end of file +} diff --git a/src/IFoxCAD.WPF/DependencyObjectExtensions.cs b/src/IFoxCAD.WPF/DependencyObjectExtensions.cs index f45e2594df36f4a6a08495e5473a2bca1b7137c6..39cd18481df528ba561d59f8566623ed1f71941f 100644 --- a/src/IFoxCAD.WPF/DependencyObjectExtensions.cs +++ b/src/IFoxCAD.WPF/DependencyObjectExtensions.cs @@ -13,23 +13,25 @@ public static class DependencyObjectExtensions /// /// 子对象 /// 依赖属性 - public static DependencyObject GetParentObject(this DependencyObject child) + public static DependencyObject? GetParentObject(this DependencyObject child) { - if (child == null) return null; + if (child is null) + return null; if (child is ContentElement contentElement) { - DependencyObject parent = ContentOperations.GetParent(contentElement); - if (parent != null) return parent; + var parent = ContentOperations.GetParent(contentElement); + if (parent is not null) return parent; - FrameworkContentElement fce = contentElement as FrameworkContentElement; + var fce = contentElement as FrameworkContentElement; return fce?.Parent; } if (child is FrameworkElement frameworkElement) { - DependencyObject parent = frameworkElement.Parent; - if (parent != null) return parent; + var parent = frameworkElement.Parent; + if (parent is not null) + return parent; } return VisualTreeHelper.GetParent(child); diff --git a/src/IFoxCAD.WPF/EventBindingExtension.cs b/src/IFoxCAD.WPF/EventBindingExtension.cs index 67016772d6e1733ad33274ab12e54c8ca81746db..9298c074d468c0dc8db53d0dd06dee2b48585212 100644 --- a/src/IFoxCAD.WPF/EventBindingExtension.cs +++ b/src/IFoxCAD.WPF/EventBindingExtension.cs @@ -34,7 +34,7 @@ public class EventBindingExtension : MarkupExtension /// public override object ProvideValue(IServiceProvider serviceProvider) { - if (serviceProvider == null) + if (serviceProvider is null) { throw new ArgumentNullException(nameof(serviceProvider)); } @@ -49,7 +49,7 @@ public override object ProvideValue(IServiceProvider serviceProvider) } var memberInfo = targetProvider.TargetProperty as MemberInfo; - if (memberInfo == null) + if (memberInfo is null) { throw new InvalidOperationException(); } @@ -69,22 +69,22 @@ public override object ProvideValue(IServiceProvider serviceProvider) return CreateHandler(memberInfo, Command, targetObject.GetType()); } - + private Type GetEventHandlerType(MemberInfo memberInfo) { Type eventHandlerType = null; if (memberInfo is EventInfo) { - var info = memberInfo as EventInfo; - var eventInfo = info; + var info = memberInfo as EventInfo; + var eventInfo = info; eventHandlerType = eventInfo.EventHandlerType; } else if (memberInfo is MethodInfo) { - var info = memberInfo as MethodInfo; - var methodInfo = info; + var info = memberInfo as MethodInfo; + var methodInfo = info; ParameterInfo[] pars = methodInfo.GetParameters(); - eventHandlerType = pars[1].ParameterType; + eventHandlerType = pars[1].ParameterType; } return eventHandlerType; @@ -94,7 +94,7 @@ private object CreateHandler(MemberInfo memberInfo, string cmdName, Type targetT { Type eventHandlerType = GetEventHandlerType(memberInfo); - if (eventHandlerType == null) return null; + if (eventHandlerType is null) return null; var handlerInfo = eventHandlerType.GetMethod("Invoke"); var method = new DynamicMethod("", handlerInfo.ReturnType, @@ -108,7 +108,7 @@ private object CreateHandler(MemberInfo memberInfo, string cmdName, Type targetT gen.Emit(OpCodes.Ldarg, 0); gen.Emit(OpCodes.Ldarg, 1); gen.Emit(OpCodes.Ldstr, cmdName); - if (CommandParameter == null) + if (CommandParameter is null) { gen.Emit(OpCodes.Ldnull); } @@ -138,7 +138,7 @@ static void Handler(object sender, object args) public static void HandlerIntern(object sender, object args, string cmdName, string commandParameter) { var fe = sender as FrameworkElement; - if (fe != null) + if (fe is not null) { ICommand cmd = GetCommand(fe, cmdName); object commandParam = null; @@ -146,7 +146,7 @@ public static void HandlerIntern(object sender, object args, string cmdName, str { commandParam = GetCommandParameter(fe, args, commandParameter); } - if ((cmd != null) && cmd.CanExecute(commandParam)) + if ((cmd is not null) && cmd.CanExecute(commandParam)) { cmd.Execute(commandParam); } @@ -156,18 +156,15 @@ public static void HandlerIntern(object sender, object args, string cmdName, str internal static ICommand GetCommand(FrameworkElement target, string cmdName) { var vm = FindViewModel(target); - if (vm == null) return null; + if (vm is null) return null; var vmType = vm.GetType(); var cmdProp = vmType.GetProperty(cmdName); - if (cmdProp != null) - { + if (cmdProp is not null) return cmdProp.GetValue(vm) as ICommand; - } #if DEBUG throw new Exception("EventBinding path error: '" + cmdName + "' property not found on '" + vmType + "' 'DelegateCommand'"); #endif - return null; } @@ -191,28 +188,29 @@ internal static object GetCommandParameter(FrameworkElement target, object args, return ret; } - internal static ViewModelBase FindViewModel(FrameworkElement target) + internal static ViewModelBase? FindViewModel(FrameworkElement? target) { - if (target == null) return null; + if (target is null) + return null; - if (target.DataContext is ViewModelBase vm) return vm; + if (target.DataContext is ViewModelBase vm) + return vm; var parent = target.GetParentObject() as FrameworkElement; - return FindViewModel(parent); } internal static object FollowPropertyPath(object target, string path, Type valueType = null) { - if (target == null) throw new ArgumentNullException(nameof(target)); - if (path == null) throw new ArgumentNullException(nameof(path)); + if (target is null) throw new ArgumentNullException(nameof(target)); + if (path is null) throw new ArgumentNullException(nameof(path)); Type currentType = valueType ?? target.GetType(); foreach (string propertyName in path.Split('.')) { PropertyInfo property = currentType.GetProperty(propertyName); - if (property == null) throw new NullReferenceException("property"); + if (property is null) throw new NullReferenceException("property"); target = property.GetValue(target); currentType = property.PropertyType; diff --git a/src/IFoxCAD.WPF/IFoxCAD.WPF.csproj b/src/IFoxCAD.WPF/IFoxCAD.WPF.csproj index c23b00410ceda7d94e840ac6d26c7d2222396455..297d6ce71cbfb2a05448c90ca8e52dc126f9487c 100644 --- a/src/IFoxCAD.WPF/IFoxCAD.WPF.csproj +++ b/src/IFoxCAD.WPF/IFoxCAD.WPF.csproj @@ -1,38 +1,43 @@  - - net45 - true - true - true - true - 0.1.0 - xsfhlzh;vicwjb - InspireFunction - WPF的简单MVVM模式开发类库 - InspireFunction - LICENSE - https://gitee.com/inspirefunction/ifoxcad - https://gitee.com/inspirefunction/ifoxcad.git - IFoxCAD;C#;NET;WPF;MVVM - git - 基于NFOX类库的重构版本 - preview - + + + preview + enable - - DEBUG;TRACE - + + NET45;NET46;NET47;NET48; - - - + true + true + true + true + 0.1.0 + xsfhlzh;vicwjb + InspireFunction + WPF的简单MVVM模式开发类库 + InspireFunction + LICENSE + https://gitee.com/inspirefunction/ifoxcad + https://gitee.com/inspirefunction/ifoxcad.git + IFoxCAD;C#;NET;WPF;MVVM + git + 基于NFOX类库的重构版本 + - - - True - - - + + DEBUG;TRACE + + + + + + + + + True + + + diff --git a/src/IFoxCAD.WPF/RelayCommand.cs b/src/IFoxCAD.WPF/RelayCommand.cs index 338c5152964347fe864733e22722587c0f931810..cb4f118bc04b50f499cb82586bf5cbf4b6432824 100644 --- a/src/IFoxCAD.WPF/RelayCommand.cs +++ b/src/IFoxCAD.WPF/RelayCommand.cs @@ -30,7 +30,7 @@ public RelayCommand(Action execute):this(execute,null) /// execute public RelayCommand(Action execute,Func canExecute) { - _execute = execute ?? throw new ArgumentNullException(nameof(execute)); + _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } @@ -41,14 +41,14 @@ public event EventHandler CanExecuteChanged { add { - if (_canExecute != null) + if (_canExecute is not null) { CommandManager.RequerySuggested += value; } } remove { - if (_canExecute != null) + if (_canExecute is not null) { CommandManager.RequerySuggested -= value; } @@ -64,7 +64,7 @@ public event EventHandler CanExecuteChanged [DebuggerStepThrough] public bool CanExecute(object parameter) { - return _canExecute == null ? true : _canExecute(parameter); + return _canExecute is null ? true : _canExecute(parameter); } /// /// 定义在调用此命令时要调用的方法。 @@ -93,7 +93,7 @@ public RelayCommand(Action execute) : this(execute, (o)=>true) { } - + /// /// 初始化 类。 /// @@ -102,7 +102,7 @@ public RelayCommand(Action execute) : this(execute, (o)=>true) /// execute public RelayCommand(Action execute, Func canExecute) { - _execute = execute ?? throw new ArgumentNullException(nameof(execute)); + _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } /// @@ -112,14 +112,14 @@ public event EventHandler CanExecuteChanged { add { - if (_canExecute != null) + if (_canExecute is not null) { CommandManager.RequerySuggested += value; } } remove { - if (_canExecute != null) + if (_canExecute is not null) { CommandManager.RequerySuggested -= value; } @@ -134,7 +134,7 @@ public event EventHandler CanExecuteChanged /// public bool CanExecute(object parameter) { - if (_canExecute == null) + if (_canExecute is null) { return true; } @@ -146,7 +146,7 @@ public bool CanExecute(object parameter) /// 此命令使用的数据。 如果此命令不需要传递数据,则该对象可以设置为 。 public void Execute(object parameter) { - if (_execute != null && CanExecute(parameter)) + if (_execute is not null && CanExecute(parameter)) { _execute((T)parameter); } @@ -164,11 +164,11 @@ public class EventCommand : TriggerAction /// 要执行的动作参数, 如果动作为提供参数,就设置为null protected override void Invoke(object parameter) { - if (CommandParameter != null) + if (CommandParameter is not null) { parameter = CommandParameter; } - if (Command != null) + if (Command is not null) { Command.Execute(parameter); } diff --git a/tests/DBTrans.test/Test.cs b/tests/DBTrans.test/Test.cs deleted file mode 100644 index 99b283d8993cf44a95a5d36ce78c21d682e4e533..0000000000000000000000000000000000000000 --- a/tests/DBTrans.test/Test.cs +++ /dev/null @@ -1,628 +0,0 @@ -using Autodesk.AutoCAD.ApplicationServices; -using Autodesk.AutoCAD.Colors; -using Autodesk.AutoCAD.DatabaseServices; -using Autodesk.AutoCAD.EditorInput; -using Autodesk.AutoCAD.Geometry; -using Autodesk.AutoCAD.Runtime; - -using IFoxCAD.Cad; - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using test.wpf; - -namespace test; - -public class Test -{ - [CommandMethod("dbtest")] - public void Dbtest() - { - using var tr = new DBTrans(); - tr.Editor.WriteMessage("\n测试 Editor 属性是否工作!"); - tr.Editor.WriteMessage("\n----------开始测试--------------"); - tr.Editor.WriteMessage("\n测试document属性是否工作"); - if (tr.Document == Getdoc()) - { - tr.Editor.WriteMessage("\ndocument 正常"); - } - tr.Editor.WriteMessage("\n测试database属性是否工作"); - if (tr.Database == Getdb()) - { - tr.Editor.WriteMessage("\ndatabase 正常"); - } - - Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); - Circle circle = new(new Point3d(0, 0, 0), Vector3d.ZAxis, 2); - //var lienid = tr.AddEntity(line); - //var cirid = tr.AddEntity(circle); - //var linent = tr.GetObject(lienid); - //var lineent = tr.GetObject(cirid); - //var linee = tr.GetObject(cirid); //经测试,类型不匹配,返回null - //var dd = tr.GetObject(lienid); - //List ds = new() { linee, dd }; - } - - //add entity test - [CommandMethod("addent")] - public void Addent() - { - using var tr = new DBTrans(); - Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); - tr.CurrentSpace.AddEntity(line); - Line line1 = new(new Point3d(10, 10, 0), new Point3d(41, 1, 0)); - tr.ModelSpace.AddEntity(line1); - Line line2 = new(new Point3d(-10, 10, 0), new Point3d(41, 1, 0)); - tr.PaperSpace.AddEntity(line2); - } - - [CommandMethod("drawarc")] - public void drawarc() - { - using var tr = new DBTrans(); - Arc arc1 = EntityEx.CreateArcSCE(new Point3d(2, 0, 0), new Point3d(0, 0, 0), new Point3d(0, 2, 0));//起点,圆心,终点 - Arc arc2 = EntityEx.CreateArc(new Point3d(4, 0, 0), new Point3d(0, 0, 0), Math.PI / 2);//起点,圆心,弧度 - Arc arc3 = EntityEx.CreateArc(new Point3d(1, 0, 0), new Point3d(0, 0, 0), new Point3d(0, 1, 0));//起点,圆上一点,终点 - tr.CurrentSpace.AddEntity(arc1, arc2, arc3); - tr.CurrentSpace.AddArc(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 0, 0));//起点,圆上一点,终点 - } - - [CommandMethod("drawcircle")] - public void draCircle() - { - using var tr = new DBTrans(); - Circle circle1 = EntityEx.CreateCircle(new Point3d(0, 0, 0), new Point3d(1, 0, 0));//起点,终点 - Circle circle2 = EntityEx.CreateCircle(new Point3d(-2, 0, 0), new Point3d(2, 0, 0), new Point3d(0, 2, 0));//三点画圆,成功 - Circle circle3 = EntityEx.CreateCircle(new Point3d(-2, 0, 0), new Point3d(0, 0, 0), new Point3d(2, 0, 0));//起点,圆心,终点,失败 - tr.CurrentSpace.AddEntity(circle1, circle2); - if (circle3 is not null) - { - tr.CurrentSpace.AddEntity(circle3); - } - else - { - tr.Editor.WriteMessage("三点画圆失败"); - } - tr.CurrentSpace.AddEntity(circle3); - tr.CurrentSpace.AddCircle(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 0, 0));//三点画圆,成功 - tr.CurrentSpace.AddCircle(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 2, 0));//起点,圆上一点,终点(共线) - } - - [CommandMethod("layertest")] - public void Layertest() - { - using var tr = new DBTrans(); - tr.LayerTable.Add("1"); - 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); - }); - } - - - //添加图层 - [CommandMethod("layerAdd1")] - public void Layertest1() - { - using var tr = new DBTrans(); - tr.LayerTable.Add("test1", Color.FromColorIndex(ColorMethod.ByColor, 1)); - } - - //添加图层 - [CommandMethod("layerAdd2")] - public void Layertest2() - { - using var tr = new DBTrans(); - tr.LayerTable.Add("test2", 2); - //tr.LayerTable["3"] = new LayerTableRecord(); - } - //删除图层 - [CommandMethod("layerdel")] - public void LayerDel() - { - using var tr = new DBTrans(); - Env.Editor.WriteMessage(tr.LayerTable.Delete("0").ToString()); //删除图层 0 - Env.Editor.WriteMessage(tr.LayerTable.Delete("Defpoints").ToString());//删除图层 Defpoints - Env.Editor.WriteMessage(tr.LayerTable.Delete("1").ToString());//删除不存在的图层 1 - Env.Editor.WriteMessage(tr.LayerTable.Delete("2").ToString());//删除有图元的图层 2 - Env.Editor.WriteMessage(tr.LayerTable.Delete("3").ToString());//删除图层 3 - - tr.LayerTable.Remove("2"); //测试是否能强制删除 - } - - //添加直线 - [CommandMethod("linedemo1")] - public void AddLine1() - { - using var tr = new DBTrans(); - // tr.ModelSpace.AddEnt(line); - // tr.ModelSpace.AddEnts(line,circle); - - // tr.PaperSpace.AddEnt(line); - // tr.PaperSpace.AddEnts(line,circle); - - // tr.addent(btr,line); - // tr.addents(btr,line,circle); - - - // tr.BlockTable.Add(new BlockTableRecord(), line => - // { - // 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 - [CommandMethod("Pldemo1")] - 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.Closed = true; - pl.Color = Color.FromColorIndex(ColorMethod.ByColor, 6); - tr.CurrentSpace.AddEntity(pl); - } - - //增加多段线2 - [CommandMethod("pldemo2")] - public void Addpl2() - { - var pts = new List<(Point3d, double, double, double)> - { - (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 var tr = new DBTrans(); - tr.CurrentSpace.AddPline(pts); - } - - //块定义 - [CommandMethod("blockdef")] - 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.Origin = new Point3d(0, 0, 0); - }, - () => //图元 - { - return 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 }; - return new List { id1, id2 }; - } - ); - //ObjectId objectId = tr.BlockTable.Add("a");//新建块 - //objectId.GetObject().AddEntity();//测试添加空实体 - } - //修改块定义 - [CommandMethod("blockdefchange")] - public void BlockDefChange() - { - using var tr = new DBTrans(); - //var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); - tr.BlockTable.Change("test", btr => - { - btr.Origin = new Point3d(5, 5, 0); - btr.AddEntity(new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 2)); - btr.GetEntities() - .ToList() - .ForEach(e => e.Flush()); //刷新块显示 - - }); - tr.Editor.Regen(); - } - - [CommandMethod("insertblockdef")] - public void InsertBlockDef() - { - using var tr = new DBTrans(); - 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 ents = new List(); - 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)); - ents.Add(line5); - 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 }); - //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 - { - { "tagTest3", "1" }, - { "tagTest4", "" } - }; - tr.CurrentSpace.InsertBlock(new Point3d(10, 10, 0), "test2", atts: def2); - tr.CurrentSpace.InsertBlock(new Point3d(-10, 0, 0), "test44"); - } - - [CommandMethod("testblocknullbug")] - public void TestBlockNullBug() - { - using var tr = new DBTrans(); - - var ents = new List(); - 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)); - ents.Add(line5); - ents.Add(line6); - tr.BlockTable.Add("test44", ents); - tr.CurrentSpace.InsertBlock(new Point3d(0, 0, 0), "test44"); - } - - - [CommandMethod("testclip")] - public void TestClipBlock() - { - using var tr = new DBTrans(); - 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 bref = 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) }; - bref.ClipBlockRef(pts); - - var id1 = tr.CurrentSpace.InsertBlock(new Point3d(20, 20, 0), "test1"); - var bref1 = tr.GetObject(id); - - bref1.ClipBlockRef(new Point3d(13, 13, 0), new Point3d(17, 17, 0)); - } - - - - - // 测试扩展数据 - [CommandMethod("addxdata")] - public void AddXdata() - { - using var tr = new DBTrans(); - var appname = "myapp"; - - tr.RegAppTable.Add(appname); // add函数会默认的在存在这个名字的时候返回这个名字的regapp的id,不存在就新建 - tr.RegAppTable.Add("myapp2"); - - var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)) - { - XData = new XDataList() - { - { DxfCode.ExtendedDataRegAppName, appname }, //可以用dxfcode和int表示组码 - { DxfCode.ExtendedDataAsciiString, "hahhahah" }, - {1070, 12 }, - { DxfCode.ExtendedDataRegAppName, "myapp2" }, //可以用dxfcode和int表示组码 - { DxfCode.ExtendedDataAsciiString, "hahhahah" }, - {1070, 12 } - } - }; - - tr.CurrentSpace.AddEntity(line); - } - - [CommandMethod("getxdata")] - public void GetXdata() - { - var doc = Application.DocumentManager.MdiActiveDocument; - var ed = doc.Editor; - - var res = ed.GetEntity("\n select the entity:"); - if (res.Status == PromptStatus.OK) - { - using var tr = new DBTrans(); - var data = tr.GetObject(res.ObjectId).XData; - ed.WriteMessage(data.ToString()); - } - } - - [CommandMethod("changexdata")] - public void Changexdata() - { - var doc = Application.DocumentManager.MdiActiveDocument; - var ed = doc.Editor; - var appname = "myapp"; - var res = ed.GetEntity("\n select the entity:"); - if (res.Status == PromptStatus.OK) - { - using var tr = new DBTrans(); - var data = tr.GetObject(res.ObjectId); - data.ChangeXData(appname, DxfCode.ExtendedDataAsciiString, "change"); - - ed.WriteMessage(data.XData.ToString()); - } - } - [CommandMethod("removexdata")] - public void Removexdata() - { - var doc = Application.DocumentManager.MdiActiveDocument; - var ed = doc.Editor; - var appname = "myapp"; - var res = ed.GetEntity("\n select the entity:"); - if (res.Status == PromptStatus.OK) - { - using var tr = new DBTrans(); - var data = tr.GetObject(res.ObjectId); - data.RemoveXData(appname, DxfCode.ExtendedDataAsciiString); - - ed.WriteMessage(data.XData.ToString()); - } - } - - [CommandMethod("PrintLayerName")] - public void PrintLayerName() - { - using var tr = new DBTrans(); - foreach (var layerRecord in tr.LayerTable.GetRecords()) - { - tr.Editor.WriteMessage(layerRecord.Name); - } - - } - - - [CommandMethod("testwpf")] - public void TestWPf() - { - - var test = new TestView(); - Application.ShowModalWindow(test); - } - - [CommandMethod("testpt")] - public void TestPt() - { - //var pt = Env.Editor.GetPoint("pick pt:").Value; - //var pl = Env.Editor.GetEntity("pick pl").ObjectId; - var tr1 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; - using var tr2 = new DBTrans(); - var tr3 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; - var tr6 = Application.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction; - Env.Print(tr2.Transaction == tr3); - Env.Print(tr3 == tr6); - using var tr4 = new DBTrans(); - var tr5 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; - var tr7 = Application.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction; - Env.Print(tr4.Transaction == tr5); - Env.Print(tr5 == tr7); - var trm = HostApplicationServices.WorkingDatabase.TransactionManager; - //var ptt = tr.GetObject(pl).GetClosestPointTo(pt,false); - //var pt1 = new Point3d(0, 0.00000000000001, 0); - //var pt2 = new Point3d(0, 0.00001, 0); - //Env.Print(Tolerance.Global.EqualPoint); - //Env.Print(pt1.IsEqualTo(pt2).ToString()); - //Env.Print(pt1.IsEqualTo(pt2,new Tolerance(0.0,1e-6)).ToString()); - //Env.Print((pt1 == pt2).ToString()); - //Env.Print((pt1 != pt2).ToString()); - - - - } - - - public Database Getdb() - { - var db = Application.DocumentManager.MdiActiveDocument.Database; - return db; - } - - - public Document Getdoc() - { - var doc = Application.DocumentManager.MdiActiveDocument; - return doc; - } - - //public override void Initialize() - //{ - // Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nload...."); - //} - - //public override void Terminate() - //{ - // Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nunload...."); - //} -} - - -public class BlockImportClass -{ - - [CommandMethod("CBLL")] - public void cbll() - { - string filename = @"C:\Users\vic\Desktop\Drawing1.dwg"; - using var tr = new DBTrans(); - using var tr1 = new DBTrans(filename); - //tr.BlockTable.GetBlockFrom(filename, true); - string blkdefname = SymbolUtilityServices.RepairSymbolName(SymbolUtilityServices.GetSymbolNameFromPathName(filename, "dwg"), false); - tr.Database.Insert(blkdefname, tr1.Database, false); //插入了块定义,未插入块参照 - - } - - - [CommandMethod("CBL")] - public void CombineBlocksIntoLibrary() - { - Document doc = - Application.DocumentManager.MdiActiveDocument; - Editor ed = doc.Editor; - Database destDb = doc.Database; - - // Get name of folder from which to load and import blocks - - PromptResult pr = - ed.GetString("\nEnter the folder of source drawings: "); - - if (pr.Status != PromptStatus.OK) - return; - string pathName = pr.StringResult; - - // Check the folder exists - - if (!Directory.Exists(pathName)) - { - ed.WriteMessage( - "\nDirectory does not exist: {0}", pathName - ); - return; - } - - // Get the names of our DWG files in that folder - - string[] fileNames = Directory.GetFiles(pathName, "*.dwg"); - - // A counter for the files we've imported - - int imported = 0, failed = 0; - - // For each file in our list - - foreach (string fileName in fileNames) - { - // Double-check we have a DWG file (probably unnecessary) - - 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" - ); - - // And from Dan Glassman... - - destName = - SymbolUtilityServices.RepairSymbolName( - destName, false - ); - - // Create a source database to load the DWG into - - using (Database db = new Database(false, true)) - { - // Read the DWG into our side database - - db.ReadDwgFile(fileName, FileShare.Read, true, ""); - bool isAnno = db.AnnotativeDwg; - - // Insert it into the destination database as - // a named block definition - - 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(); - using (tr) - { - BlockTableRecord btr = - (BlockTableRecord)tr.GetObject( - btrId, - OpenMode.ForWrite - ); - btr.Annotative = AnnotativeStates.True; - tr.Commit(); - } - } - - // Print message and increment imported block counter - - ed.WriteMessage("\nImported from \"{0}\".", fileName); - imported++; - } - } - catch (System.Exception ex) - { - ed.WriteMessage( - "\nProblem importing \"{0}\": {1} - file skipped.", - fileName, ex.Message - ); - failed++; - } - } - } - - ed.WriteMessage( - "\nImported block definitions from {0} files{1} in " + - "\"{2}\" into the current drawing.", - imported, - failed > 0 ? " (" + failed + " failed)" : "", - pathName - ); - } -} - diff --git a/tests/DBTrans.test/Properties/launchSettings.json b/tests/Test/Properties/launchSettings.json similarity index 100% rename from tests/DBTrans.test/Properties/launchSettings.json rename to tests/Test/Properties/launchSettings.json diff --git a/tests/Test/Test.cs b/tests/Test/Test.cs new file mode 100644 index 0000000000000000000000000000000000000000..78746f425a65420f15520caa675c86540be4805f --- /dev/null +++ b/tests/Test/Test.cs @@ -0,0 +1,628 @@ +using Autodesk.AutoCAD.ApplicationServices; +using Autodesk.AutoCAD.Colors; +using Autodesk.AutoCAD.DatabaseServices; +using Autodesk.AutoCAD.EditorInput; +using Autodesk.AutoCAD.Geometry; +using Autodesk.AutoCAD.Runtime; + +using IFoxCAD.Cad; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +using test.wpf; + +namespace test +{ + public class Test + { + [CommandMethod("dbtest")] + public void Dbtest() + { + using var tr = new DBTrans(); + tr.Editor.WriteMessage("\n测试 Editor 属性是否工作!"); + tr.Editor.WriteMessage("\n----------开始测试--------------"); + tr.Editor.WriteMessage("\n测试document属性是否工作"); + if (tr.Document == Getdoc()) + { + tr.Editor.WriteMessage("\ndocument 正常"); + } + tr.Editor.WriteMessage("\n测试database属性是否工作"); + if (tr.Database == Getdb()) + { + tr.Editor.WriteMessage("\ndatabase 正常"); + } + + Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + Circle circle = new(new Point3d(0, 0, 0), Vector3d.ZAxis, 2); + //var lienid = tr.AddEntity(line); + //var cirid = tr.AddEntity(circle); + //var linent = tr.GetObject(lienid); + //var lineent = tr.GetObject(cirid); + //var linee = tr.GetObject(cirid); //经测试,类型不匹配,返回null + //var dd = tr.GetObject(lienid); + //List ds = new() { linee, dd }; + } + + //add entity test + [CommandMethod("addent")] + public void Addent() + { + using var tr = new DBTrans(); + Line line = new(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + tr.CurrentSpace.AddEntity(line); + Line line1 = new(new Point3d(10, 10, 0), new Point3d(41, 1, 0)); + tr.ModelSpace.AddEntity(line1); + Line line2 = new(new Point3d(-10, 10, 0), new Point3d(41, 1, 0)); + tr.PaperSpace.AddEntity(line2); + } + + [CommandMethod("drawarc")] + public void drawarc() + { + using var tr = new DBTrans(); + Arc arc1 = EntityEx.CreateArcSCE(new Point3d(2, 0, 0), new Point3d(0, 0, 0), new Point3d(0, 2, 0));//起点,圆心,终点 + Arc arc2 = EntityEx.CreateArc(new Point3d(4, 0, 0), new Point3d(0, 0, 0), Math.PI / 2); //起点,圆心,弧度 + Arc arc3 = EntityEx.CreateArc(new Point3d(1, 0, 0), new Point3d(0, 0, 0), new Point3d(0, 1, 0)); //起点,圆上一点,终点 + tr.CurrentSpace.AddEntity(arc1, arc2, arc3); + tr.CurrentSpace.AddArc(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 0, 0));//起点,圆上一点,终点 + } + + [CommandMethod("drawcircle")] + public void draCircle() + { + using var tr = new DBTrans(); + Circle circle1 = EntityEx.CreateCircle(new Point3d(0, 0, 0), new Point3d(1, 0, 0)); //起点,终点 + Circle circle2 = EntityEx.CreateCircle(new Point3d(-2, 0, 0), new Point3d(2, 0, 0), new Point3d(0, 2, 0));//三点画圆,成功 + Circle circle3 = EntityEx.CreateCircle(new Point3d(-2, 0, 0), new Point3d(0, 0, 0), new Point3d(2, 0, 0));//起点,圆心,终点,失败 + tr.CurrentSpace.AddEntity(circle1, circle2); + if (circle3 is not null) + tr.CurrentSpace.AddEntity(circle3); + else + { + tr.Editor.WriteMessage("三点画圆失败"); + return; + } + tr.CurrentSpace.AddEntity(circle3); + tr.CurrentSpace.AddCircle(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 0, 0));//三点画圆,成功 + tr.CurrentSpace.AddCircle(new Point3d(0, 0, 0), new Point3d(1, 1, 0), new Point3d(2, 2, 0));//起点,圆上一点,终点(共线) + } + + [CommandMethod("layertest")] + public void Layertest() + { + using var tr = new DBTrans(); + tr.LayerTable.Add("1"); + 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); + }); + } + + + //添加图层 + [CommandMethod("layerAdd1")] + public void Layertest1() + { + using var tr = new DBTrans(); + tr.LayerTable.Add("test1", Color.FromColorIndex(ColorMethod.ByColor, 1)); + } + + //添加图层 + [CommandMethod("layerAdd2")] + public void Layertest2() + { + using var tr = new DBTrans(); + tr.LayerTable.Add("test2", 2); + //tr.LayerTable["3"] = new LayerTableRecord(); + } + //删除图层 + [CommandMethod("layerdel")] + public void LayerDel() + { + using var tr = new DBTrans(); + Env.Editor.WriteMessage(tr.LayerTable.Delete("0").ToString()); //删除图层 0 + Env.Editor.WriteMessage(tr.LayerTable.Delete("Defpoints").ToString());//删除图层 Defpoints + Env.Editor.WriteMessage(tr.LayerTable.Delete("1").ToString()); //删除不存在的图层 1 + Env.Editor.WriteMessage(tr.LayerTable.Delete("2").ToString()); //删除有图元的图层 2 + Env.Editor.WriteMessage(tr.LayerTable.Delete("3").ToString()); //删除图层 3 + + tr.LayerTable.Remove("2"); //测试是否能强制删除 + } + + //添加直线 + [CommandMethod("linedemo1")] + public void AddLine1() + { + using var tr = new DBTrans(); + // tr.ModelSpace.AddEnt(line); + // tr.ModelSpace.AddEnts(line,circle); + + // tr.PaperSpace.AddEnt(line); + // tr.PaperSpace.AddEnts(line,circle); + + // tr.addent(btr,line); + // tr.addents(btr,line,circle); + + + // tr.BlockTable.Add(new BlockTableRecord(), line => + // { + // 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 + [CommandMethod("Pldemo1")] + 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.Closed = true; + pl.Color = Color.FromColorIndex(ColorMethod.ByColor, 6); + tr.CurrentSpace.AddEntity(pl); + } + + //增加多段线2 + [CommandMethod("pldemo2")] + public void Addpl2() + { + var pts = new List<(Point3d, double, double, double)> + { + (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 var tr = new DBTrans(); + tr.CurrentSpace.AddPline(pts); + } + + //块定义 + [CommandMethod("blockdef")] + 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.Origin = new Point3d(0, 0, 0); + }, + () => //图元 + { + return 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 }; + return new List { id1, id2 }; + } + ); + //ObjectId objectId = tr.BlockTable.Add("a");//新建块 + //objectId.GetObject().AddEntity();//测试添加空实体 + } + //修改块定义 + [CommandMethod("blockdefchange")] + public void BlockDefChange() + { + using var tr = new DBTrans(); + //var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)); + tr.BlockTable.Change("test", btr => + { + btr.Origin = new Point3d(5, 5, 0); + btr.AddEntity(new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 2)); + btr.GetEntities() + .ToList() + .ForEach(e => e.Flush()); //刷新块显示 + + }); + tr.Editor.Regen(); + } + + [CommandMethod("insertblockdef")] + public void InsertBlockDef() + { + using var tr = new DBTrans(); + 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 ents = new List(); + 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)); + ents.Add(line5); + 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 }); + //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 + { + { "tagTest3", "1" }, + { "tagTest4", "" } + }; + tr.CurrentSpace.InsertBlock(new Point3d(10, 10, 0), "test2", atts: def2); + tr.CurrentSpace.InsertBlock(new Point3d(-10, 0, 0), "test44"); + } + + [CommandMethod("testblocknullbug")] + public void TestBlockNullBug() + { + using var tr = new DBTrans(); + + var ents = new List(); + 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)); + ents.Add(line5); + ents.Add(line6); + tr.BlockTable.Add("test44", ents); + tr.CurrentSpace.InsertBlock(new Point3d(0, 0, 0), "test44"); + } + + + [CommandMethod("testclip")] + public void TestClipBlock() + { + using var tr = new DBTrans(); + 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 bref = 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) }; + bref.ClipBlockRef(pts); + + var id1 = tr.CurrentSpace.InsertBlock(new Point3d(20, 20, 0), "test1"); + var bref1 = tr.GetObject(id); + + bref1.ClipBlockRef(new Point3d(13, 13, 0), new Point3d(17, 17, 0)); + } + + + + + // 测试扩展数据 + [CommandMethod("addxdata")] + public void AddXdata() + { + using var tr = new DBTrans(); + var appname = "myapp"; + + tr.RegAppTable.Add(appname); // add函数会默认的在存在这个名字的时候返回这个名字的regapp的id,不存在就新建 + tr.RegAppTable.Add("myapp2"); + + var line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0)) + { + XData = new XDataList() + { + { DxfCode.ExtendedDataRegAppName, appname }, //可以用dxfcode和int表示组码 + { DxfCode.ExtendedDataAsciiString, "hahhahah" }, + {1070, 12 }, + { DxfCode.ExtendedDataRegAppName, "myapp2" }, //可以用dxfcode和int表示组码 + { DxfCode.ExtendedDataAsciiString, "hahhahah" }, + {1070, 12 } + } + }; + + tr.CurrentSpace.AddEntity(line); + } + + [CommandMethod("getxdata")] + public void GetXdata() + { + var doc = Application.DocumentManager.MdiActiveDocument; + var ed = doc.Editor; + + var res = ed.GetEntity("\n select the entity:"); + if (res.Status == PromptStatus.OK) + { + using var tr = new DBTrans(); + var data = tr.GetObject(res.ObjectId).XData; + ed.WriteMessage(data.ToString()); + } + } + + [CommandMethod("changexdata")] + public void Changexdata() + { + var doc = Application.DocumentManager.MdiActiveDocument; + var ed = doc.Editor; + var appname = "myapp"; + var res = ed.GetEntity("\n select the entity:"); + if (res.Status == PromptStatus.OK) + { + using var tr = new DBTrans(); + var data = tr.GetObject(res.ObjectId); + data.ChangeXData(appname, DxfCode.ExtendedDataAsciiString, "change"); + + ed.WriteMessage(data.XData.ToString()); + } + } + [CommandMethod("removexdata")] + public void Removexdata() + { + var doc = Application.DocumentManager.MdiActiveDocument; + var ed = doc.Editor; + var appname = "myapp"; + var res = ed.GetEntity("\n select the entity:"); + if (res.Status == PromptStatus.OK) + { + using var tr = new DBTrans(); + var data = tr.GetObject(res.ObjectId); + data.RemoveXData(appname, DxfCode.ExtendedDataAsciiString); + + ed.WriteMessage(data.XData.ToString()); + } + } + + [CommandMethod("PrintLayerName")] + public void PrintLayerName() + { + using var tr = new DBTrans(); + foreach (var layerRecord in tr.LayerTable.GetRecords()) + { + tr.Editor.WriteMessage(layerRecord.Name); + } + + } + + + [CommandMethod("testwpf")] + public void TestWPf() + { + + var test = new TestView(); + Application.ShowModalWindow(test); + } + + [CommandMethod("testpt")] + public void TestPt() + { + //var pt = Env.Editor.GetPoint("pick pt:").Value; + //var pl = Env.Editor.GetEntity("pick pl").ObjectId; + var tr1 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; + using var tr2 = new DBTrans(); + var tr3 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; + var tr6 = Application.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction; + Env.Print(tr2.Transaction == tr3); + Env.Print(tr3 == tr6); + using var tr4 = new DBTrans(); + var tr5 = HostApplicationServices.WorkingDatabase.TransactionManager.TopTransaction; + var tr7 = Application.DocumentManager.MdiActiveDocument.TransactionManager.TopTransaction; + Env.Print(tr4.Transaction == tr5); + Env.Print(tr5 == tr7); + var trm = HostApplicationServices.WorkingDatabase.TransactionManager; + //var ptt = tr.GetObject(pl).GetClosestPointTo(pt,false); + //var pt1 = new Point3d(0, 0.00000000000001, 0); + //var pt2 = new Point3d(0, 0.00001, 0); + //Env.Print(Tolerance.Global.EqualPoint); + //Env.Print(pt1.IsEqualTo(pt2).ToString()); + //Env.Print(pt1.IsEqualTo(pt2,new Tolerance(0.0,1e-6)).ToString()); + //Env.Print((pt1 == pt2).ToString()); + //Env.Print((pt1 != pt2).ToString()); + + + + } + + + public Database Getdb() + { + var db = Application.DocumentManager.MdiActiveDocument.Database; + return db; + } + + + public Document Getdoc() + { + var doc = Application.DocumentManager.MdiActiveDocument; + return doc; + } + + //public override void Initialize() + //{ + // Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nload...."); + //} + + //public override void Terminate() + //{ + // Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nunload...."); + //} + } + + + public class BlockImportClass + { + + [CommandMethod("CBLL")] + public void cbll() + { + string filename = @"C:\Users\vic\Desktop\Drawing1.dwg"; + using var tr = new DBTrans(); + using var tr1 = new DBTrans(filename); + //tr.BlockTable.GetBlockFrom(filename, true); + string blkdefname = SymbolUtilityServices.RepairSymbolName(SymbolUtilityServices.GetSymbolNameFromPathName(filename, "dwg"), false); + tr.Database.Insert(blkdefname, tr1.Database, false); //插入了块定义,未插入块参照 + + } + + + [CommandMethod("CBL")] + public void CombineBlocksIntoLibrary() + { + Document doc = + Application.DocumentManager.MdiActiveDocument; + Editor ed = doc.Editor; + Database destDb = doc.Database; + + // Get name of folder from which to load and import blocks + + PromptResult pr = + ed.GetString("\nEnter the folder of source drawings: "); + + if (pr.Status != PromptStatus.OK) + return; + string pathName = pr.StringResult; + + // Check the folder exists + + if (!Directory.Exists(pathName)) + { + ed.WriteMessage( + "\nDirectory does not exist: {0}", pathName + ); + return; + } + + // Get the names of our DWG files in that folder + + string[] fileNames = Directory.GetFiles(pathName, "*.dwg"); + + // A counter for the files we've imported + + int imported = 0, failed = 0; + + // For each file in our list + + foreach (string fileName in fileNames) + { + // Double-check we have a DWG file (probably unnecessary) + + 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" + ); + + // And from Dan Glassman... + + destName = + SymbolUtilityServices.RepairSymbolName( + destName, false + ); + + // Create a source database to load the DWG into + + using (Database db = new Database(false, true)) + { + // Read the DWG into our side database + + db.ReadDwgFile(fileName, FileShare.Read, true, ""); + bool isAnno = db.AnnotativeDwg; + + // Insert it into the destination database as + // a named block definition + + 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(); + using (tr) + { + BlockTableRecord btr = + (BlockTableRecord)tr.GetObject( + btrId, + OpenMode.ForWrite + ); + btr.Annotative = AnnotativeStates.True; + tr.Commit(); + } + } + + // Print message and increment imported block counter + + ed.WriteMessage("\nImported from \"{0}\".", fileName); + imported++; + } + } + catch (System.Exception ex) + { + ed.WriteMessage( + "\nProblem importing \"{0}\": {1} - file skipped.", + fileName, ex.Message + ); + failed++; + } + } + } + + ed.WriteMessage( + "\nImported block definitions from {0} files{1} in " + + "\"{2}\" into the current drawing.", + imported, + failed > 0 ? " (" + failed + " failed)" : "", + pathName + ); + } + } + +} diff --git a/tests/DBTrans.test/DBTrans.test.csproj b/tests/Test/Test.csproj similarity index 34% rename from tests/DBTrans.test/DBTrans.test.csproj rename to tests/Test/Test.csproj index a6f4773c0403d637c64c303f52227fafd9d66693..fa8ed348e5eafbc1dfb264f16990358413d02ba0 100644 --- a/tests/DBTrans.test/DBTrans.test.csproj +++ b/tests/Test/Test.csproj @@ -1,15 +1,37 @@  - net45 + + preview + enable + + + 1.0.0.* + 1.0.0.0 + False + git + + + NET45; true true - preview + + + + + + + + + + + + diff --git a/tests/DBTrans.test/testConvexHull.cs b/tests/Test/testConvexHull.cs similarity index 100% rename from tests/DBTrans.test/testConvexHull.cs rename to tests/Test/testConvexHull.cs diff --git a/tests/DBTrans.test/testeditor.cs b/tests/Test/testeditor.cs similarity index 100% rename from tests/DBTrans.test/testeditor.cs rename to tests/Test/testeditor.cs diff --git a/tests/DBTrans.test/testenv.cs b/tests/Test/testenv.cs similarity index 90% rename from tests/DBTrans.test/testenv.cs rename to tests/Test/testenv.cs index 274d5d84d8c6dbe7fac56649d76b853c305a2ca0..6cd7c9b76c9ae9af5986c862af2a7f55b88cb90d 100644 --- a/tests/DBTrans.test/testenv.cs +++ b/tests/Test/testenv.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using IFoxCAD.Cad; +using IFoxCAD.Cad; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; @@ -15,16 +10,12 @@ public class testenv [CommandMethod("testenum")] public void testenum() { - Env.CmdEcho = true; - } [CommandMethod("testenum1")] public void testenum1() { - Env.CmdEcho = false; - } [CommandMethod("testdimblk")] @@ -75,8 +66,6 @@ public void testzoom() { Env.Editor.ZoomObject(res.ObjectId.GetObject()); } - - } } } diff --git a/tests/DBTrans.test/testselectfilter.cs b/tests/Test/testselectfilter.cs similarity index 91% rename from tests/DBTrans.test/testselectfilter.cs rename to tests/Test/testselectfilter.cs index 1224a2f6d067d37ae82135deda537d4eddbcf7da..9b658eea29905e11aa70eff9eef5533f38fe71b7 100644 --- a/tests/DBTrans.test/testselectfilter.cs +++ b/tests/Test/testselectfilter.cs @@ -17,13 +17,13 @@ public class testselectfilter [CommandMethod("testfilter")] public void testfilter() { - + var p = new Point3d(10, 10, 0); var f = OpFilter.Bulid( - e =>!(e.Dxf(0) == "line" & e.Dxf(8) == "0") + e => !(e.Dxf(0) == "line" & e.Dxf(8) == "0") | e.Dxf(0) != "circle" & e.Dxf(8) == "2" & e.Dxf(10) >= p); - - + + var f2 = OpFilter.Bulid( e => e.Or( !e.And(e.Dxf(0) == "line", e.Dxf(8) == "0"), @@ -39,10 +39,7 @@ public void testfilter() [CommandMethod("testselectanpoint")] public void testselectanpoint() { - - var sel2 = Env.Editor.SelectAtPoint(new Point3d(0, 0, 0)); - Env.Editor.WriteMessage(""); } } diff --git a/tests/DBTrans.test/wpf/TestView.xaml b/tests/Test/wpf/TestView.xaml similarity index 100% rename from tests/DBTrans.test/wpf/TestView.xaml rename to tests/Test/wpf/TestView.xaml diff --git a/tests/DBTrans.test/wpf/TestView.xaml.cs b/tests/Test/wpf/TestView.xaml.cs similarity index 100% rename from tests/DBTrans.test/wpf/TestView.xaml.cs rename to tests/Test/wpf/TestView.xaml.cs diff --git a/tests/DBTrans.test/wpf/TestViewModel.cs b/tests/Test/wpf/TestViewModel.cs similarity index 100% rename from tests/DBTrans.test/wpf/TestViewModel.cs rename to tests/Test/wpf/TestViewModel.cs