From 6f98f43ed0cc1f962c3acbc03e8602f4c0151520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= <Александр@DESKTOP-F3LNMFA> Date: Sun, 4 Dec 2022 20:57:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D1=8C=D1=82?= =?UTF-8?q?=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AcadToSMath.sln | 25 +++ AcadToSMath/AcadToSMath.cs | 269 +++++++++++++++++++++++++ AcadToSMath/AcadToSMath.csproj | 132 ++++++++++++ AcadToSMath/Properties/AssemblyInfo.cs | 36 ++++ AcadToSMath/Utilites.cs | 140 +++++++++++++ 5 files changed, 602 insertions(+) create mode 100644 AcadToSMath.sln create mode 100644 AcadToSMath/AcadToSMath.cs create mode 100644 AcadToSMath/AcadToSMath.csproj create mode 100644 AcadToSMath/Properties/AssemblyInfo.cs create mode 100644 AcadToSMath/Utilites.cs diff --git a/AcadToSMath.sln b/AcadToSMath.sln new file mode 100644 index 0000000..34bbb57 --- /dev/null +++ b/AcadToSMath.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33122.133 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AcadToSMath", "AcadToSMath\AcadToSMath.csproj", "{86AF75BC-5BAE-45AC-BA9E-E80940DA6060}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {86AF75BC-5BAE-45AC-BA9E-E80940DA6060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86AF75BC-5BAE-45AC-BA9E-E80940DA6060}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86AF75BC-5BAE-45AC-BA9E-E80940DA6060}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86AF75BC-5BAE-45AC-BA9E-E80940DA6060}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4946AE36-DA80-49A2-AE86-D30861BA4834} + EndGlobalSection +EndGlobal diff --git a/AcadToSMath/AcadToSMath.cs b/AcadToSMath/AcadToSMath.cs new file mode 100644 index 0000000..158b5e4 --- /dev/null +++ b/AcadToSMath/AcadToSMath.cs @@ -0,0 +1,269 @@ +using Autodesk.AutoCAD.Interop; +using Autodesk.AutoCAD.Interop.Common; + +using SMath.Manager; +using SMath.Math; +using SMath.Math.Numeric; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace AcadToSMath +{ + public class AcadToSMath : IPluginHandleEvaluation, IPluginLowLevelEvaluationFast + { + AssemblyInfo[] asseblyInfos; + + public void Dispose() + { + } + + public TermInfo[] GetTermsHandled(SessionProfile sessionProfile) + { + //functions definitions + return new TermInfo[] + { + new TermInfo("GetAcPlines", TermType.Function, + "(1:слой, 2:масштаб единиц чертежа, 3:замкнуть полилинии) - " + + "Получает вершины полилиний из ативного документа AutoCAD, возвращает массив с координатами вершин полилиний.", + FunctionSections.Files, true, + new ArgumentInfo(ArgumentSections.String, true), + new ArgumentInfo(ArgumentSections.RealNumber, true), + new ArgumentInfo(ArgumentSections.RealNumber, true)), + + new TermInfo("GetAcCircles", TermType.Function, + "(1:слой, 2:масштаб единиц чертежа) - " + + "Получает вершины полилиний из ативного документа AutoCAD, возвращает массив с координатами вершин полилиний.", + FunctionSections.Files, true, + new ArgumentInfo(ArgumentSections.String, true), + new ArgumentInfo(ArgumentSections.RealNumber, true)), + + }; + } + + public void Initialize() + { + asseblyInfos = new AssemblyInfo[] { new AssemblyInfo("SMath Studio", new Version(0, 99), new Guid("86af75bc-5bae-45ac-ba9e-e80940da6060")) }; + + AppDomain currentDomain = AppDomain.CurrentDomain; + currentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); + + System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + { + System.Reflection.Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies(); + for (int i = 0; i < asms.Length; ++i) + { + if (asms[i].FullName == args.Name) + return asms[i]; + } + return null; + } + } + + + public bool TryEvaluateExpression(Entry value, Store context, out Entry result) + { + //GetAcPlines + if (value.Type == TermType.Function && value.Text == "GetAcPlines") + { + List answer = new List(); + + string lay = "#"; + double scale = 1; + int isClose = 0; + if (TermsConverter.DecodeText(value.Items[0].Text).Trim('"') != "#") lay = TermsConverter.DecodeText(value.Items[0].Text).Trim('"'); + if(TermsConverter.DecodeText(value.Items[1].Text).Trim('"')!="#") scale = Utilites.Entry2Double(value.Items[1], context); + if(TermsConverter.DecodeText(value.Items[2].Text).Trim('"')!="#") isClose = Utilites.Entry2Int(value.Items[2], context); + + + const string progID = "AutoCAD.Application"; + AcadApplication acApp = null; + + try + { + acApp = (AcadApplication)Marshal.GetActiveObject(progID); + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"AutoCAD не запущен\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + if (acApp != null) + { + // By the time this is reached AutoCAD is fully + // functional and can be interacted with through code + acApp.Visible = true; + AcadModelSpace ms = null; + try + { + ms = acApp.ActiveDocument.ModelSpace; + List polylines = new List(); + List points = new List(); + List circles = new List(); + List textes = new List(); + if (lay == "#") + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbPolyline") polylines.Add(ms.Item(i) as AcadLWPolyline); + } + } + else + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbPolyline" && ms.Item(i).Layer == lay) polylines.Add(ms.Item(i) as AcadLWPolyline); + } + } + if (polylines.Count==0) + { + answer.AddRange(TermsConverter.ToTerms("\"Документ не содержит ни одной полилинии на заданном слое\"")); + result = Entry.Create(answer.ToArray()); + return true; + } + else + { + int plc = polylines.Count; + for (int i = 0; i < plc; i++) + { + AcadLWPolyline pline = polylines[i]; + double[] crds = (double[])polylines[i].Coordinates; + int crdsc = crds.Length/2; + //List crd = new List(crdsc); + foreach (double item in crds) answer.AddRange(new TNumber(item*scale).obj.ToTerms()); + if (isClose == 1) + { + answer.AddRange(new TNumber(crds[0] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(crds[1] * scale).obj.ToTerms()); + answer.AddRange(TermsConverter.ToTerms((crdsc+1).ToString())); + answer.AddRange(TermsConverter.ToTerms(2.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 4 + crdsc * 2)); + } + else + { + answer.AddRange(TermsConverter.ToTerms(crdsc.ToString())); + answer.AddRange(TermsConverter.ToTerms(2.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + crdsc * 2)); + } + } + + if (plc >1) + { + answer.AddRange(TermsConverter.ToTerms(1.ToString())); + answer.AddRange(TermsConverter.ToTerms(plc.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + plc)); + } + + result = Entry.Create(answer.ToArray()); + return true; + } + + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"Нет ни одного открытого документа AutoCAD\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + } + + //GetAcCircles + if (value.Type == TermType.Function && value.Text == "GetAcCircles") + { + List answer = new List(); + + string lay = "#"; + double scale = 1; + if (TermsConverter.DecodeText(value.Items[0].Text).Trim('"') != "#") lay = TermsConverter.DecodeText(value.Items[0].Text).Trim('"'); + if (TermsConverter.DecodeText(value.Items[1].Text).Trim('"') != "#") scale = Utilites.Entry2Double(value.Items[1], context); + + + const string progID = "AutoCAD.Application"; + AcadApplication acApp = null; + + try + { + acApp = (AcadApplication)Marshal.GetActiveObject(progID); + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"AutoCAD не запущен\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + if (acApp != null) + { + // By the time this is reached AutoCAD is fully + // functional and can be interacted with through code + acApp.Visible = true; + AcadModelSpace ms = null; + try + { + ms = acApp.ActiveDocument.ModelSpace; + List circles = new List(); + if (lay == "#") + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbCircle") circles.Add(ms.Item(i) as AcadCircle); + } + } + else + { + for (int i = 0; i < ms.Count; i++) + { + if (ms.Item(i).ObjectName == "AcDbCircle" && ms.Item(i).Layer == lay) circles.Add(ms.Item(i) as AcadCircle); + } + } + if (circles.Count == 0) + { + answer.AddRange(TermsConverter.ToTerms("\"Документ не содержит ни одной окружности на заданном слое\"")); + result = Entry.Create(answer.ToArray()); + return true; + } + else + { + int cc = circles.Count; + for (int i = 0; i < cc; i++) + { + AcadCircle c = circles[i]; + double[]cen= (double[])c.Center; + answer.AddRange(new TNumber(cen[0] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(cen[1] * scale).obj.ToTerms()); + answer.AddRange(new TNumber(c.Area * scale * scale).obj.ToTerms()); + answer.AddRange(new TNumber(c.Radius * scale * 2).obj.ToTerms()); + } + answer.AddRange(TermsConverter.ToTerms(cc.ToString())); + answer.AddRange(TermsConverter.ToTerms(4.ToString())); + answer.Add(new Term(Functions.Mat, TermType.Function, 2 + cc * 4)); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + catch + { + answer.AddRange(TermsConverter.ToTerms("\"Нет ни одного открытого документа AutoCAD\"")); + + result = Entry.Create(answer.ToArray()); + return true; + } + } + } + + + result = null; + return false; + } + + } +} diff --git a/AcadToSMath/AcadToSMath.csproj b/AcadToSMath/AcadToSMath.csproj new file mode 100644 index 0000000..7a477df --- /dev/null +++ b/AcadToSMath/AcadToSMath.csproj @@ -0,0 +1,132 @@ + + + + + Debug + AnyCPU + {86AF75BC-5BAE-45AC-BA9E-E80940DA6060} + Library + Properties + AcadToSMath + AcadToSMath + v4.6 + 512 + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\Main\SMathStudio\canvas\bin\Debug + + C:\Program Files (x86)\SMath Studio + + + C:\Program Files (x86)\SMathStudio + + + + ..\..\..\..\..\..\Program Files\Autodesk\AutoCAD 2020\Autodesk.AutoCAD.Interop.dll + False + + + ..\..\..\..\..\..\Program Files\Autodesk\AutoCAD 2020\Autodesk.AutoCAD.Interop.Common.dll + False + + + ..\..\..\Документы\C#\netDxf.dll + + + ..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Controls.dll + False + + + ..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Drawing.dll + False + + + ..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Environment.dll + False + + + ..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Manager.dll + False + + + ..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Math.Numeric.dll + False + + + ..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Math.Symbolic.dll + False + + + + + + + + + + + + + + + + + + + {00020430-0000-0000-C000-000000000046} + 2 + 0 + 0 + primary + False + True + + + + + + + + + + + + + %(ProgramInfo.Version) + config.$(ProgramVersion.Replace(".", "_")).ini + + $(SMathDir)\extensions\plugins\$(ProjectGuid.TrimStart("{").TrimEnd("}")) + + $(APPDATA)\SMath\extensions\plugins\$(ProjectGuid.TrimStart("{").TrimEnd("}")) + + + + + + + + + + + + + \ No newline at end of file diff --git a/AcadToSMath/Properties/AssemblyInfo.cs b/AcadToSMath/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1d83df5 --- /dev/null +++ b/AcadToSMath/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанные со сборкой. +[assembly: AssemblyTitle("AcadToSMath")] +[assembly: AssemblyDescription("Definition of the section property to be used in the structural analysis")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Aleksandr Ponomarev(https://t.me/smathru)")] +[assembly: AssemblyProduct("AcadToSMath")] +[assembly: AssemblyCopyright("Copyright © 2020 SMathStudio")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// COM, задайте атрибуту ComVisible значение TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("86af75bc-5bae-45ac-ba9e-e80940da6060")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Редакция +// +// Можно задать все значения или принять номера сборки и редакции по умолчанию +// используя "*", как показано ниже: +[assembly: AssemblyVersion("1.0.*")] +// [assembly: AssemblyVersion("1.0.0.0")] +// [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AcadToSMath/Utilites.cs b/AcadToSMath/Utilites.cs new file mode 100644 index 0000000..78e1c16 --- /dev/null +++ b/AcadToSMath/Utilites.cs @@ -0,0 +1,140 @@ +using SMath.Manager; + +using SMath.Math.Numeric; +using System; +using System.Collections.Generic; +using SMath.Math; +using System.IO; + +namespace AcadToSMath +{ + static class Utilites + { + public static string _exePath = System.Reflection.Assembly.GetEntryAssembly().Location; + public static string _exeDirectory = GlobalProfile.ApplicationPath; + public static string _exeFileName = Path.GetFileName(_exePath); + + public static string CurrentPath(string StoreFileName) + { + if (String.IsNullOrEmpty(StoreFileName)) + return Environment.GetFolderPath(Environment.SpecialFolder.Personal); + + if (!StoreFileName.Contains(Path.DirectorySeparatorChar.ToString())) + return Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); + + return Path.GetDirectoryName(StoreFileName); + } + + static public List BlueScale { get; } = new List() {"\"#08306B\"", + "\"#08519C\"", + "\"#2171B5\"", + "\"#4292C6\"", + "\"#6BAED6\"", + "\"#9ECAE1\"", + "\"#C6DBEF\"", + "\"#DEEBF7\"", + "\"#F7FBFF\""}; + static public List RedScale { get; } = new List() {"\"#800026\"", + "\"#BD0026\"", + "\"#E31A1C\"", + "\"#FC4E2A\"", + "\"#FD8D3C\"", + "\"#FEB24C\"", + "\"#FED976\"", + "\"#FFEDA0\"", + "\"#FFFFCC\""}; + + internal static double[] EntryVec2Arr(Entry vector, Store store) + { + TNumber num = Computation.NumericCalculation(vector, store); + TMatrix matrix = (TMatrix)num.obj; + double[] res = new double[matrix.Length()]; + //for (int i = 0; i < matrix.unit.Length; i++) + //{ + // res[i] = matrix.unit[i, 0].obj.ToDouble(); + //} + + string source = matrix.ToString(15, 15, FractionsType.Decimal, false); + source = source.Trim(new char[] { 'm', 'a', 't', '(', ')' }); + source = source.Replace("*10^{", "E"); + source = source.Replace("}", ""); + string[] src = source.Split(','); + + int n = matrix.Length(); + for (int i = 0; i < n; i++) + { + //if (src[i].IndexOf('^') >= 0) res[i] = 0; + res[i] = Convert.ToDouble(src[i]); + } + return res; + } + + internal static double[,] EntryMat2Arr(Entry mat, Store store) + { + TNumber num = Computation.NumericCalculation(mat, store); + TMatrix matrix = (TMatrix)num.obj; + double[,] res = new double[matrix.unit.GetLength(0), matrix.unit.GetLength(1)]; + for (int i = 0; i < matrix.unit.GetLength(0); i++) + { + for (int j = 0; j < matrix.unit.GetLength(1); j++) + { + res[i, j] = matrix.unit[i, j].obj.ToDouble(); + } + } + return res; + } + + internal static double Entry2Double(Entry prime, Store store) + { + TNumber num = Computation.NumericCalculation(prime, store); + return num.obj.ToDouble(); + } + + internal static int Entry2Int(Entry prime, Store store) + { + TNumber num = Computation.NumericCalculation(prime, store); + return (int)num.obj.ToDouble(); + } + + internal static List SelectColors(List values) + { + List source = new List(values); + source.Sort(); + double start = source[0]; + double end = source[source.Count - 1]; + double stepCold = start/ 9; + double stepHot = end / 9; + double[] cold = new double[10]; + double[] hot = new double[10]; + cold[0] = start; + hot[0] = end; + for (int i = 1; i < 9; i++) + { + cold[i] = start - i * stepCold; + hot[i] = end - i * stepHot; + } + cold[9] = 0; + hot[9] = 0; + + List res = new List(); + foreach (double item in values) + { + for (int i = 0; i < 9; i++) + { + if (item >= cold[i] && item <= cold[i + 1]) + { + res.Add(BlueScale[i]); + break; + } + else if (item <= hot[i] && item >= hot[i + 1]) + { + res.Add(RedScale[i]); + break; + } + } + } + + return res; + } + } +}