增加查找线工具

This commit is contained in:
liu.wenjie
2019-08-04 21:51:40 +08:00
committed by liu.wenjie
parent 61de0d1236
commit 9d8944dcc3
256 changed files with 719371 additions and 778 deletions

Binary file not shown.

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{4D539EB2-E847-4D42-B6FA-03B2546DAFD7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VisionJobFactory</RootNamespace>
<AssemblyName>VisionJobFactory</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<ItemGroup>
<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="VisionToolFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VisionToolList.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommonMethods\CommonHelper.csproj">
<Project>{1C8D0DDC-2086-48A9-9586-F2B643E2FC54}</Project>
<Name>CommonHelper</Name>
</ProjectReference>
<ProjectReference Include="..\FindLine\FindLineTool.csproj">
<Project>{C3BB2B1C-ED0C-4879-A6D3-D86342C5086E}</Project>
<Name>FindLineTool</Name>
</ProjectReference>
<ProjectReference Include="..\HalconTool\HalconTool.csproj">
<Project>{F5669FB7-77EC-44B9-898B-6D575B7D26EA}</Project>
<Name>HalconTool</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using CommonMethods;
namespace VisionJobFactory
{
public class VisionToolFactory
{
private static Dictionary<ToolType, Type> animalTypeDic = new Dictionary<ToolType, Type>();
public static void InitVisionToolTypeDic()
{
animalTypeDic.Clear();
//读取所有带有VisionToolAttribute的类
var classEnumerator = new ClassEnumerator(typeof(VisionToolAttribute), null, typeof(VisionToolAttribute).Assembly);
var em = classEnumerator.Results.GetEnumerator();
while (em.MoveNext())
{
var classType = em.Current;
var atts = classType.GetCustomAttributes(typeof(VisionToolAttribute), true);
if (atts.Length > 0)
{
var att = atts[0] as VisionToolAttribute;
if (null != att)
{
animalTypeDic.Add(att.ToolType, classType);
}
}
}
}
public static IToolInfo CreateToolVision(ToolType animalType, string toolName)
{
if (animalTypeDic.ContainsKey(animalType))
{
return (IToolInfo)Activator.CreateInstance(animalTypeDic[animalType], new object[] { toolName });
}
return null;
}
public static IToolInfo CreateToolVision(ToolType animalType)
{
if (animalTypeDic.ContainsKey(animalType))
{
return (IToolInfo)Activator.CreateInstance(animalTypeDic[animalType]);
}
return null;
}
}
//自定义Attribute
public sealed class VisionToolAttribute : Attribute
{
public ToolType ToolType { get; private set; }
public VisionToolAttribute(ToolType toolType)
{
ToolType = toolType;
}
}
//根据Attribute提取类
public class ClassEnumerator
{
protected List<Type> results = new List<Type>();
public List<Type> Results
{
get
{
return results;
}
}
private Type AttributeType;
private Type InterfaceType;
public ClassEnumerator(Type InAttributeType, Type InInterfaceType, Assembly InAssembly, bool bIgnoreAbstract = true, bool bInheritAttribute = false, bool bShouldCrossAssembly = false)
{
AttributeType = InAttributeType;
InterfaceType = InInterfaceType;
try
{
if (bShouldCrossAssembly)
{
Assembly[] Assemblys = AppDomain.CurrentDomain.GetAssemblies();
if (Assemblys != null)
{
for (int i = 0, len = Assemblys.Length; i < len; i++)
{
CheckInAssembly(Assemblys[i], bIgnoreAbstract, bInheritAttribute);
}
}
}
else
{
CheckInAssembly(InAssembly, bIgnoreAbstract, bInheritAttribute);
}
}
catch (Exception e)
{
Debug.WriteLine("Error in enumerate classes: " + e.Message);
}
}
private void CheckInAssembly(Assembly InAssembly, bool bInIgnoreAbstract, bool bInInheritAttribute)
{
Type[] types = InAssembly.GetTypes();
if (null == types)
{
return;
}
for (int i = 0, len = types.Length; i < len; i++)
{
var type = types[i];
if (InterfaceType == null || InterfaceType.IsAssignableFrom(type))
{
if (!bInIgnoreAbstract || (bInIgnoreAbstract && !type.IsAbstract))
{
if (type.GetCustomAttributes(AttributeType, bInInheritAttribute).Length > 0)
{
results.Add(type);
}
}
}
}
}
}
}

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommonMethods;
using FindLineTool;
using HalconTool;
namespace VisionJobFactory
{
[VisionToolAttribute(ToolType.HalconTool)]
public class HalconToolInterface : IToolInfo
{
// 必添加输出项
ToolIO outputImage = new ToolIO("OutputImage", null, DataType.Image);
/// <summary>
/// 获取工具的所有信息
/// </summary>
/// <param name="生成的工具名称"></param>
public HalconToolInterface(string toolName)
{
enable = true;
toolType = ToolType.HalconTool;
this.toolName = toolName;
tool = new HalconTool.HalconTool();
FormTool = null;
FormToolName = "HalconTool.FormHalconTool";
toolInput = new List<ToolIO>();
toolOutput = new List<ToolIO>() { outputImage };
}
/// <summary>
/// 只获取选择工具的描述信息
/// </summary>
public HalconToolInterface()
{
toolDescription = "Halcon采集图像接口,可直接连接网口、USB等相机";
}
}
[VisionToolAttribute(ToolType.FindLine)]
public class FindLineToolInterface : IToolInfo
{
ToolIO inputImage = new ToolIO("InputImage", null, DataType.Image);
ToolIO outputXld = new ToolIO("outputXld", null, DataType.Line);
ToolIO startPointRow = new ToolIO("StartPointRow", null, DataType.Point);
ToolIO startPointColumn = new ToolIO("StartPointRow", null, DataType.Point);
ToolIO endPointRow = new ToolIO("EndPointRow", null, DataType.Point);
ToolIO endPointColumn = new ToolIO("EndPointColumn", null, DataType.Point);
public FindLineToolInterface(string toolName)
{
enable = true;
toolType = ToolType.FindLine;
this.toolName = toolName;
tool = new FindLine();
FormToolName = "FindLineTool.FormFindLine";
FormTool = null;
toolInput = new List<ToolIO>() { inputImage };
toolOutput = new List<ToolIO>() { outputXld, startPointRow, startPointColumn, endPointRow, endPointColumn };
}
/// <summary>
/// 只获取选择工具的描述信息
/// </summary>
public FindLineToolInterface()
{
toolDescription = "找线工具";
}
}
[VisionToolAttribute(ToolType.BlobAnalyse)]
public class BlobAnalyseToolInterface : IToolInfo
{
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\VisionJobFactory.dll
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\VisionJobFactory.pdb
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\CommonMethods.dll
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\FindLineTool.dll
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\HalconTool.dll
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\halcondotnet.dll
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\ToolBase.dll
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\DataStruct.dll
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\HalconWindow.exe
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\CommonMethods.pdb
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\FindLineTool.pdb
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\HalconTool.pdb
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\halcondotnet.xml
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\ToolBase.pdb
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\DataStruct.pdb
F:\VSCode\VisionEditTest\VisionJobFactory\bin\Debug\HalconWindow.pdb
F:\VSCode\VisionEditTest\VisionJobFactory\obj\Debug\VisionJobFactory.csprojResolveAssemblyReference.cache
F:\VSCode\VisionEditTest\VisionJobFactory\obj\Debug\VisionJobFactory.dll
F:\VSCode\VisionEditTest\VisionJobFactory\obj\Debug\VisionJobFactory.pdb

Binary file not shown.

Binary file not shown.