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

This commit is contained in:
2020-07-25 00:44:03 +03:00
parent 35689eeee2
commit 52a3664365
5 changed files with 350 additions and 0 deletions

128
MatrixExtensions.cs Normal file
View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SMath.Manager;
using SMath.Math;
using SMath.Math.Numeric;
namespace MatrixExtensions
{
public class MatrixExtensions : IPluginHandleEvaluation, IPluginLowLevelEvaluationFast
{
AssemblyInfo[] asseblyInfos;
public void Initialize()
{
asseblyInfos = new AssemblyInfo[] { new AssemblyInfo("SMath Studio", new Version(0, 99), new Guid("a37cba83-b69c-4c71-9992-55ff666763bd")) };
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 TermInfo[] GetTermsHandled(SessionProfile sessionProfile)
{
//functions definitions
return new TermInfo[]
{
new TermInfo("listDistinct", TermType.Function,
"Возвращает вектор уникальных значений, содержащихся в ('матрица').",
FunctionSections.MatricesAndVectors, true,
new ArgumentInfo(ArgumentSections.Matrix)),
new TermInfo("listDistinct", TermType.Function,
"Возвращает вектор или вектор-строку уникальных значений, содержащихся в ('матрица'), а" +
" ('число') указывает на вид возвращаемого вектора: 0 - вектор; 1 - вектор-строка.",
FunctionSections.MatricesAndVectors, true,
new ArgumentInfo(ArgumentSections.Matrix), new ArgumentInfo(ArgumentSections.RealNumber)),
};
}
public bool TryEvaluateExpression(Entry value, Store context, out Entry result)
{
//listDistinct
if (value.Type == TermType.Function && value.ArgsCount == 1 && value.Text == "listDistinct")
{
Entry arg1 = Computation.Preprocessing(value.Items[0], context);
TNumber tmp = Computation.NumericCalculation(arg1, context);
List<string> vector = new List<string>(Utilites.EntryMatrix2ArrStr(tmp.obj));
vector.RemoveAt(vector.Count - 1);
vector.RemoveAt(vector.Count - 1);
List<string> distinct = vector.Distinct().ToList();
List<Term> answer = new List<Term>();
foreach (string item in distinct)
{
answer.AddRange(TermsConverter.ToTerms(item));
}
answer.AddRange(TermsConverter.ToTerms(distinct.Count.ToString()));
answer.AddRange(TermsConverter.ToTerms(1.ToString()));
answer.Add(new Term(Functions.Mat, TermType.Function, 2 + distinct.Count));
result = Entry.Create(answer.ToArray());
return true;
}
if (value.Type == TermType.Function && value.ArgsCount == 2 && value.Text == "listDistinct")
{
Entry arg1 = Computation.Preprocessing(value.Items[0], context);
Entry arg2 = Computation.Preprocessing(value.Items[1], context);
int dir = Utilites.Entry2Int(arg2);
TNumber tmp = Computation.NumericCalculation(arg1, context);
List<string> vector = new List<string>(Utilites.EntryMatrix2ArrStr(tmp.obj));
vector.RemoveAt(vector.Count - 1);
vector.RemoveAt(vector.Count - 1);
List<string> distinct = vector.Distinct().ToList();
//string res = "null";
List<Term> answer = new List<Term>();
foreach (string item in distinct)
{
answer.AddRange(TermsConverter.ToTerms(item));
}
if (dir==0)
{
answer.AddRange(TermsConverter.ToTerms(distinct.Count.ToString()));
answer.AddRange(TermsConverter.ToTerms(1.ToString()));
answer.Add(new Term(Functions.Mat, TermType.Function, 2 + distinct.Count));
}
else
{
answer.AddRange(TermsConverter.ToTerms(1.ToString()));
answer.AddRange(TermsConverter.ToTerms(distinct.Count.ToString()));
answer.Add(new Term(Functions.Mat, TermType.Function, 2 + distinct.Count));
}
result = Entry.Create(answer.ToArray());
return true;
}
result = null;
return false;
}
public void Dispose()
{
}
}
}

106
MatrixExtensions.csproj Normal file
View File

@@ -0,0 +1,106 @@
<?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>{6DD7D794-EB0C-4386-8FAF-64C1C9AEED27}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MatrixExtensions</RootNamespace>
<AssemblyName>MatrixExtensions</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AssemblyVersion>1.0.*</AssemblyVersion>
<Deterministic>false</Deterministic>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</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>
<Prefer32Bit>false</Prefer32Bit>
</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>
<Prefer32Bit>false</Prefer32Bit>
</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="System" />
<Reference Include="System.Core" />
<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" />
<Reference Include="SMath.Controls">
<HintPath>$(SMathDir)\SMath.Controls.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Manager">
<HintPath>$(SMathDir)\SMath.Manager.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Math.Numeric">
<HintPath>$(SMathDir)\SMath.Math.Numeric.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SMath.Math.Symbolic">
<HintPath>$(SMathDir)\SMath.Math.Symbolic.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MatrixExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilites.cs" />
</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>

25
MatrixExtensions.sln Normal file
View File

@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixExtensions", "MatrixExtensions.csproj", "{6DD7D794-EB0C-4386-8FAF-64C1C9AEED27}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6DD7D794-EB0C-4386-8FAF-64C1C9AEED27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DD7D794-EB0C-4386-8FAF-64C1C9AEED27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DD7D794-EB0C-4386-8FAF-64C1C9AEED27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DD7D794-EB0C-4386-8FAF-64C1C9AEED27}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FDF65821-5E33-4A1A-9519-311235CF2749}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Общие сведения об этой сборке предоставляются следующим набором
// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
// связанные со сборкой.
[assembly: AssemblyTitle("MatrixExtensions")]
[assembly: AssemblyDescription("Сustom functions for working with matrices")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Aleksandr Ponomarev")]
[assembly: AssemblyProduct("MatrixExtensions")]
[assembly: AssemblyCopyright("Copyright © 2020 SMathStudio")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
[assembly: ComVisible(false)]
// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
[assembly: Guid("6dd7d794-eb0c-4386-8faf-64c1c9aeed27")]
// Сведения о версии сборки состоят из указанных ниже четырех значений:
//
// Основной номер версии
// Дополнительный номер версии
// Номер сборки
// Редакция
//
// Можно задать все значения или принять номера сборки и редакции по умолчанию
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

55
Utilites.cs Normal file
View File

@@ -0,0 +1,55 @@
using SMath.Manager;
using SMath.Math.Numeric;
using System;
using System.Collections.Generic;
namespace MatrixExtensions
{
static class Utilites
{
internal static string[] EntryMatrix2ArrStr(Entry matrix)
{
string source = matrix.ToString();
source = source.Trim(new char[] { 'm', 'a', 't', '(', ')' });
return source.Split(',');
}
internal static string[] EntryMatrix2ArrStr(BaseEntry matrix)
{
string source = matrix.ToString();
source = source.Trim(new char[] { 'm', 'a', 't', '(', ')' });
return source.Split(',');
}
internal static double[] EntryVec2Arr(Entry vector)
{
string source = vector.ToString();
source = source.Trim(new char[] { 'm', 'a', 't', '(', ')' });
//source = source.Replace("{", "");
//source = source.Replace("}", "");
string[] src = source.Split(',');
int n = src.Length - 2;
double[] res = new double[n];
for (int i = 0; i < n; i++)
{
if (src[i].IndexOf('^') >= 0) res[i] = 0;
else res[i] = Convert.ToDouble(src[i]);
}
return res;
}
internal static double Entry2Double(Entry prime)
{
string source = prime.ToString();
return Convert.ToDouble(source);
}
internal static int Entry2Int(Entry prime)
{
string source = prime.ToString();
return Convert.ToInt32(source);
}
}
}