Добавьте файлы проекта.

This commit is contained in:
Александр
2022-12-04 20:57:19 +03:00
parent 529b1dbd3d
commit 6f98f43ed0
5 changed files with 602 additions and 0 deletions

25
AcadToSMath.sln Normal file
View File

@@ -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

269
AcadToSMath/AcadToSMath.cs Normal file
View File

@@ -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<Term> answer = new List<Term>();
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<AcadLWPolyline> polylines = new List<AcadLWPolyline>();
List<AcadPoint> points = new List<AcadPoint>();
List<AcadCircle> circles = new List<AcadCircle>();
List<AcadText> textes = new List<AcadText>();
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<double[]> crd = new List<double[]>(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<Term> answer = new List<Term>();
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<AcadCircle> circles = new List<AcadCircle>();
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;
}
}
}

View File

@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{86AF75BC-5BAE-45AC-BA9E-E80940DA6060}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AcadToSMath</RootNamespace>
<AssemblyName>AcadToSMath</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>false</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<!-- Relase -> SMath Release Manager -->
<SMathDir Condition=" '$(SMathDir)' == '' AND '$(Configuration)' == 'Release' ">..\..\..\Main\SMathStudio\canvas\bin\Debug</SMathDir>
<!-- Debug -> development -->
<SMathDir Condition=" '$(SMathDir)' == '' AND '$(Configuration)' == 'Debug' ">C:\Program Files (x86)\SMath Studio</SMathDir>
</PropertyGroup>
<PropertyGroup>
<SMathDir Condition=" '$(SMathDir)' == '' ">C:\Program Files (x86)\SMathStudio</SMathDir>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autodesk.AutoCAD.Interop">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\AutoCAD 2020\Autodesk.AutoCAD.Interop.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Autodesk.AutoCAD.Interop.Common">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\AutoCAD 2020\Autodesk.AutoCAD.Interop.Common.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="netDxf">
<HintPath>..\..\..\Документы\C#\netDxf.dll</HintPath>
</Reference>
<Reference Include="SMath.Controls">
<HintPath>..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Controls.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Drawing">
<HintPath>..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Drawing.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Environment">
<HintPath>..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Environment.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Manager">
<HintPath>..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Manager.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Math.Numeric">
<HintPath>..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Math.Numeric.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Math.Symbolic">
<HintPath>..\..\..\..\..\..\Program Files (x86)\SMath Studio\SMath.Math.Symbolic.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AcadToSMath.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilites.cs" />
</ItemGroup>
<ItemGroup>
<COMReference Include="stdole">
<Guid>{00020430-0000-0000-C000-000000000046}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- copy anything from the build path to the SMath Studio extension path -->
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Debug' ">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="AssemblyInfo" />
</GetAssemblyIdentity>
<GetAssemblyIdentity AssemblyFiles="$(SMathDir)\SMath.Manager.dll">
<Output TaskParameter="Assemblies" ItemName="ProgramInfo" />
</GetAssemblyIdentity>
<PropertyGroup>
<ProgramVersion>%(ProgramInfo.Version)</ProgramVersion>
<ConfigFileName>config.$(ProgramVersion.Replace(".", "_")).ini</ConfigFileName>
<!-- SS portable -->
<PluginPath Condition=" Exists('$(SMathDir)\portable.version')">$(SMathDir)\extensions\plugins\$(ProjectGuid.TrimStart("{").TrimEnd("}"))</PluginPath>
<!-- SS from installer -->
<PluginPath Condition=" '$(PluginPath)' == ''">$(APPDATA)\SMath\extensions\plugins\$(ProjectGuid.TrimStart("{").TrimEnd("}"))</PluginPath>
</PropertyGroup>
<ItemGroup>
<BuildFiles Include="$(TargetDir)\*.*" />
<ConfigFileContent Include="%(AssemblyInfo.Version)" />
<!-- extension status (0: enabled; 2: disabled; 1: removed) -->
<ConfigFileContent Include="0" />
</ItemGroup>
<!-- uncomment line below to keep clean the extension directory -->
<!-- <RemoveDir Condition="'$(Configuration)' == 'Debug'"Directories="$(PluginPath)"/> -->
<Copy SourceFiles="@(BuildFiles)" DestinationFolder="$(PluginPath)\%(AssemblyInfo.Version)" ContinueOnError="false" />
<WriteLinesToFile File="$(PluginPath)\$(ConfigFileName)" Lines="@(ConfigFileContent)" Overwrite="true" />
</Target>
</Project>

View File

@@ -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")]

140
AcadToSMath/Utilites.cs Normal file
View File

@@ -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<string> BlueScale { get; } = new List<string>() {"\"#08306B\"",
"\"#08519C\"",
"\"#2171B5\"",
"\"#4292C6\"",
"\"#6BAED6\"",
"\"#9ECAE1\"",
"\"#C6DBEF\"",
"\"#DEEBF7\"",
"\"#F7FBFF\""};
static public List<string> RedScale { get; } = new List<string>() {"\"#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<string> SelectColors(List<double> values)
{
List<double> source = new List<double>(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<string> res = new List<string>();
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;
}
}
}