添加项目文件。
This commit is contained in:
parent
5ae1cfe95e
commit
2e7995590b
|
@ -0,0 +1,79 @@
|
|||
|
||||
using Laservall.Solidworks.Extension;
|
||||
using Laservall.Solidworks.Pane;
|
||||
using Laservall.Solidworks.Pane.WPF;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xarial.XCad.Base.Attributes;
|
||||
using Xarial.XCad.Documents;
|
||||
using Xarial.XCad.SolidWorks.UI.PropertyPage;
|
||||
using Xarial.XCad.UI;
|
||||
using Xarial.XCad.UI.Commands;
|
||||
using Xarial.XCad.UI.PropertyPage.Enums;
|
||||
using Xarial.XCad.UI.TaskPane;
|
||||
using Xarial.XCad.UI.TaskPane.Attributes;
|
||||
using Xarial.XCad.UI.TaskPane.Enums;
|
||||
|
||||
namespace Laservall.Solidworks
|
||||
{
|
||||
[System.Runtime.InteropServices.ComVisible(true)]
|
||||
public class AddinEntry : Xarial.XCad.SolidWorks.SwAddInEx
|
||||
{
|
||||
private IXTaskPane<PartPropPaneUserControl> m_TaskPane;
|
||||
public override void OnConnect()
|
||||
{
|
||||
// 初始化DLL加载器
|
||||
AppDomainDllLoader.SetLaoder();
|
||||
// 初始化WPF应用程序
|
||||
WPFApplicationExt.InitApplication();
|
||||
//var taskPane = this.CreateTaskPane<TestUserControl>();
|
||||
var cmdTaskPane = this.CreateTaskPane<PartPropPaneUserControl>(new TaskPaneSpec
|
||||
{
|
||||
Title = "Laservall 自定义属性卡",
|
||||
Tooltip = "Laservall 自定义属性卡"
|
||||
});
|
||||
//cmdTaskPane.
|
||||
cmdTaskPane.Control.pane = cmdTaskPane;
|
||||
|
||||
m_TaskPane = cmdTaskPane;
|
||||
|
||||
this.Application.Documents.DocumentActivated += OnDocumentActivated;
|
||||
|
||||
if (this.Application.Documents.Active != null)
|
||||
{
|
||||
SubscribeToSelectionEvents(this.Application.Documents.Active);
|
||||
}
|
||||
}
|
||||
private void OnDocumentActivated(IXDocument doc)
|
||||
{
|
||||
SubscribeToSelectionEvents(doc);
|
||||
}
|
||||
|
||||
private void SubscribeToSelectionEvents(IXDocument doc)
|
||||
{
|
||||
doc.Selections.NewSelection += Selections_NewSelection;
|
||||
}
|
||||
|
||||
private void Selections_NewSelection(IXDocument doc, Xarial.XCad.IXSelObject selObject)
|
||||
{
|
||||
m_TaskPane.Control.OnSelectChange(doc, selObject);
|
||||
}
|
||||
|
||||
|
||||
public override void OnDisconnect()
|
||||
{
|
||||
base.OnDisconnect();
|
||||
|
||||
//AppDomainDllLoader.
|
||||
}
|
||||
private void OnTaskPaneButtonClick(TaskPaneButtonSpec spec)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Laservall.Solidworks
|
||||
{
|
||||
public class AppDomainDllLoader
|
||||
{
|
||||
public static bool isLoaded = false;
|
||||
public static void SetLaoder()
|
||||
{
|
||||
if (isLoaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// 接管DLL加载,解决依赖问题
|
||||
// 插件被加载时,AppContext.BaseDirectory 会指向Eplan的安装目录,导致一部分依赖的DLL在加载时找不到
|
||||
// 接管之后,从两个目录都查找一次
|
||||
//throw new NotImplementedException();
|
||||
try
|
||||
{
|
||||
// 防止重复加载 先卸载事件
|
||||
AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolveHandle;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.TraceError(ex.Message);
|
||||
}
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandle;
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
public static Assembly AssemblyResolveHandle(object sender, ResolveEventArgs args)
|
||||
{
|
||||
var assemblyName = new AssemblyName(args.Name);
|
||||
|
||||
// 判断是否已经被加载
|
||||
var loadedAssembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.FirstOrDefault(a => a.FullName == assemblyName.FullName);
|
||||
if (loadedAssembly != null)
|
||||
{
|
||||
Debug.WriteLine($"DLL is loaded -> {loadedAssembly.FullName}");
|
||||
return loadedAssembly;
|
||||
}
|
||||
|
||||
// 从当前路径下加载
|
||||
var path = Path.Combine(AppContext.BaseDirectory, $"{assemblyName.Name}.dll");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
Debug.WriteLine($"Load dll for path -> {path}");
|
||||
|
||||
return Assembly.LoadFile(path);
|
||||
}
|
||||
var envPath = System.Environment.CurrentDirectory;
|
||||
// 从插件路径中加载依赖
|
||||
path = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(AppDomainDllLoader)).Location), $"{assemblyName.Name}.dll");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
//MessageBox.Show($"Load dll for self path -> {path}");
|
||||
Debug.WriteLine($"Load dll for self path -> {path}");
|
||||
return Assembly.LoadFile(path);
|
||||
}
|
||||
//MessageBox.Show(path);
|
||||
Debug.WriteLine($"File not load! -> {path}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
using HandyControl.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Laservall.Solidworks.Common
|
||||
{
|
||||
public class ComboxPropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
{
|
||||
var comboBox = new ComboBox();
|
||||
comboBox.ItemsSource = new List<string> { "A", "B", "C" };
|
||||
comboBox.SelectedItem = propertyItem.Value?.ToString();
|
||||
comboBox.SelectionChanged += (s, e) =>
|
||||
{
|
||||
propertyItem.Value = comboBox.SelectedItem;
|
||||
};
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
public override DependencyProperty GetDependencyProperty()
|
||||
{
|
||||
return ComboBox.SelectedItemProperty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
using Laservall.Solidworks.Model;
|
||||
using SolidWorks.Interop.sldworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Shapes;
|
||||
using Xarial.XCad.Documents;
|
||||
using Xarial.XCad.SolidWorks.Documents;
|
||||
|
||||
namespace Laservall.Solidworks.Extension
|
||||
{
|
||||
public static class SWDocReader
|
||||
{
|
||||
public static void ReadDocProperties(IModelDoc2 doc,PartPropModel partPropModel)
|
||||
{
|
||||
if (doc != null)
|
||||
{
|
||||
partPropModel.GetType().GetProperties().ToList().ForEach(p =>
|
||||
{
|
||||
// Get DisplayName attribute
|
||||
p.CustomAttributes.ToList().ForEach(attr =>
|
||||
{
|
||||
if (attr.AttributeType == typeof(System.ComponentModel.DisplayNameAttribute))
|
||||
{
|
||||
var displayName = attr.ConstructorArguments[0].Value.ToString();
|
||||
// Get custom property value by display name
|
||||
var val2 = GetDocProperty(doc, displayName);
|
||||
if (val2 != null)
|
||||
{
|
||||
// 判断属性类型
|
||||
switch (p.PropertyType.Name)
|
||||
{
|
||||
case "Double":
|
||||
if (double.TryParse(val2, out double d))
|
||||
{
|
||||
p.SetValue(partPropModel, d);
|
||||
}
|
||||
break;
|
||||
case "Int32":
|
||||
if (int.TryParse(val2, out int i))
|
||||
{
|
||||
p.SetValue(partPropModel, i);
|
||||
}
|
||||
break;
|
||||
case "Boolean":
|
||||
if (bool.TryParse(val2, out bool b))
|
||||
{
|
||||
p.SetValue(partPropModel, b);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
p.SetValue(partPropModel, val2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//var val = partComponent.Component.CustomPropertyManager[p.Name];
|
||||
//if (val != null)
|
||||
//{
|
||||
// p.SetValue(partPropModel, val);
|
||||
//}
|
||||
});
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取当前激活配置的自定义属性
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="propertyName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDocProperty(IModelDoc2 model , string propertyName)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return "未打开任何文档";
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelDocExtension swModelDocExt = default(ModelDocExtension);
|
||||
CustomPropertyManager swCustProp = default(CustomPropertyManager);
|
||||
string val = "";
|
||||
string valout = "";
|
||||
int status;
|
||||
|
||||
//swModel = (ModelDoc2)swApp.ActiveDoc;
|
||||
swModelDocExt = model.Extension;
|
||||
|
||||
// Get the custom property data
|
||||
swCustProp = swModelDocExt.get_CustomPropertyManager("");
|
||||
//status = swCustProp.Get4(propertyName, false, out val, out valout);
|
||||
status = swCustProp.Get6(propertyName, false, out val,out valout,out bool wasResolved,out bool _);
|
||||
Debug.Print("Value: " + val);
|
||||
Debug.Print("Evaluated value: " + valout);
|
||||
//Debug.Print("Up-to-date data: " + status);
|
||||
if (wasResolved)
|
||||
{
|
||||
return valout;
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Laservall.Solidworks.Extension
|
||||
{
|
||||
public static class WPFApplicationExt
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置主窗口
|
||||
/// </summary>
|
||||
/// <param name="application"></param>
|
||||
/// <param name="window"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
//public static void SetMainWindow(this Application application, Window window)
|
||||
//{
|
||||
// if (application == null)
|
||||
// {
|
||||
// throw new ArgumentNullException(nameof(application));
|
||||
// }
|
||||
// if (window == null)
|
||||
// {
|
||||
// throw new ArgumentNullException(nameof(window));
|
||||
// }
|
||||
// application.MainWindow = window;
|
||||
//}
|
||||
/// <summary>
|
||||
/// 初始化应用程序,修复在某些情况下,引用第三方UI控件库的时候出现的异常与卡顿
|
||||
/// </summary>
|
||||
public static void InitApplication()
|
||||
{
|
||||
if (Application.Current == null)
|
||||
{
|
||||
new System.Windows.Application
|
||||
{
|
||||
ShutdownMode = ShutdownMode.OnExplicitShutdown,
|
||||
Resources = new ResourceDictionary
|
||||
{
|
||||
Source = new Uri("pack://application:,,,/Laservall.Solidworks;component/Themes/Theme.xaml")
|
||||
},
|
||||
};
|
||||
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Show($"{sender.GetType()}: {e.Exception.Message}");
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
<?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>{A8B83CC2-1DC4-478D-8956-B5357CDC336A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Laservall.Solidworks</RootNamespace>
|
||||
<AssemblyName>Laservall.Solidworks</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>False</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<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>
|
||||
</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="HandyControl, Version=3.5.1.0, Culture=neutral, PublicKeyToken=45be8712787a1e5b, processorArchitecture=MSIL">
|
||||
<HintPath>packages\HandyControl.3.5.1\lib\net481\HandyControl.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="SolidWorks.Interop.sldworks, Version=33.0.0.5050, Culture=neutral, PublicKeyToken=7c4797c3e4eeac03, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Xarial.XCad.SolidWorks.0.8.2\lib\net461\SolidWorks.Interop.sldworks.dll</HintPath>
|
||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="SolidWorks.Interop.swconst, Version=33.0.0.5050, Culture=neutral, PublicKeyToken=19f43e188e4269d8, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Xarial.XCad.SolidWorks.0.8.2\lib\net461\SolidWorks.Interop.swconst.dll</HintPath>
|
||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="SolidWorks.Interop.swpublished, Version=33.0.0.5050, Culture=neutral, PublicKeyToken=89a97bdc5284e6d8, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Xarial.XCad.SolidWorks.0.8.2\lib\net461\SolidWorks.Interop.swpublished.dll</HintPath>
|
||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<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="WindowsBase" />
|
||||
<Reference Include="WindowsFormsIntegration" />
|
||||
<Reference Include="Xarial.XCad, Version=0.8.2.5232, Culture=neutral, PublicKeyToken=60dcaf351d4060db, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Xarial.XCad.0.8.2\lib\net461\Xarial.XCad.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xarial.XCad.SolidWorks, Version=0.8.2.5232, Culture=neutral, PublicKeyToken=60dcaf351d4060db, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Xarial.XCad.SolidWorks.0.8.2\lib\net461\Xarial.XCad.SolidWorks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xarial.XCad.Toolkit, Version=0.8.2.5232, Culture=neutral, PublicKeyToken=60dcaf351d4060db, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Xarial.XCad.Toolkit.0.8.2\lib\net461\Xarial.XCad.Toolkit.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AddinEntry.cs" />
|
||||
<Compile Include="AppDomainDllLoader.cs" />
|
||||
<Compile Include="Common\ComboxPropertyEditor.cs" />
|
||||
<Compile Include="Extension\SWDocReader.cs" />
|
||||
<Compile Include="Extension\WPFApplicationExt.cs" />
|
||||
<Compile Include="Model\PartPropModel.cs" />
|
||||
<Compile Include="Pane\PartPropPaneUserControl.xaml.cs">
|
||||
<DependentUpon>PartPropPaneUserControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pane\WPF\TestUserControl.xaml.cs">
|
||||
<DependentUpon>TestUserControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Pane\PartPropPaneUserControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Pane\WPF\TestUserControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Themes\Theme.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="packages\Xarial.XCad.SolidWorks.0.8.2\build\Xarial.XCad.SolidWorks.targets" Condition="Exists('packages\Xarial.XCad.SolidWorks.0.8.2\build\Xarial.XCad.SolidWorks.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('packages\Xarial.XCad.SolidWorks.0.8.2\build\Xarial.XCad.SolidWorks.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Xarial.XCad.SolidWorks.0.8.2\build\Xarial.XCad.SolidWorks.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,3 @@
|
|||
<Solution>
|
||||
<Project Path="Laservall.Solidworks.csproj" Id="a8b83cc2-1dc4-478d-8956-b5357cdc336a" />
|
||||
</Solution>
|
|
@ -0,0 +1,210 @@
|
|||
using HandyControl.Controls;
|
||||
using Laservall.Solidworks.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Laservall.Solidworks.Model
|
||||
{
|
||||
public class PartPropModel : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private string _drawNo;
|
||||
[Category("设计")]
|
||||
[DisplayName("图号")]
|
||||
public string DrawNo
|
||||
{
|
||||
get => _drawNo;
|
||||
set
|
||||
{
|
||||
if (_drawNo == value) return;
|
||||
_drawNo = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _docNumber;
|
||||
[Category("设计")]
|
||||
[DisplayName("文档编码")]
|
||||
public string DocNumber
|
||||
{
|
||||
get => _docNumber;
|
||||
set
|
||||
{
|
||||
if (_docNumber == value) return;
|
||||
_docNumber = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _partName;
|
||||
[Category("设计")]
|
||||
[DisplayName("零件名称")]
|
||||
public string PartName
|
||||
{
|
||||
get => _partName;
|
||||
set
|
||||
{
|
||||
if (_partName == value) return;
|
||||
_partName = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _designer;
|
||||
[Category("设计")]
|
||||
[DisplayName("设计")]
|
||||
public string Designer
|
||||
{
|
||||
get => _designer;
|
||||
set
|
||||
{
|
||||
if (_designer == value) return;
|
||||
_designer = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _partProp;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("属性")]
|
||||
public string PartProp
|
||||
{
|
||||
get => _partProp;
|
||||
set
|
||||
{
|
||||
if (_partProp == value) return;
|
||||
_partProp = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _material;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("材质")]
|
||||
[Editor(typeof(ComboxPropertyEditor), typeof(ComboxPropertyEditor))]
|
||||
public string Material
|
||||
{
|
||||
get => _material;
|
||||
set
|
||||
{
|
||||
if (_material == value) return;
|
||||
_material = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _classNo;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("分类")]
|
||||
[Editor(typeof(ComboxPropertyEditor), typeof(ComboxPropertyEditor))]
|
||||
public string ClassNo
|
||||
{
|
||||
get => _classNo;
|
||||
set
|
||||
{
|
||||
if (_classNo == value) return;
|
||||
_classNo = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _surfaceTreatment;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("表面处理")]
|
||||
[Editor(typeof(ComboxPropertyEditor), typeof(ComboxPropertyEditor))]
|
||||
public string SurfaceTreatment
|
||||
{
|
||||
get => _surfaceTreatment;
|
||||
set
|
||||
{
|
||||
if (_surfaceTreatment == value) return;
|
||||
_surfaceTreatment = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _brand;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("品牌")]
|
||||
[Editor(typeof(ComboxPropertyEditor), typeof(ComboxPropertyEditor))]
|
||||
public string Brand
|
||||
{
|
||||
get => _brand;
|
||||
set
|
||||
{
|
||||
if (_brand == value) return;
|
||||
_brand = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _unit;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("单位")]
|
||||
[Editor(typeof(ComboxPropertyEditor), typeof(ComboxPropertyEditor))]
|
||||
public string Unit
|
||||
{
|
||||
get => _unit;
|
||||
set
|
||||
{
|
||||
if (_unit == value) return;
|
||||
_unit = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _purCheck;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("采购检验")]
|
||||
public bool PurCheck
|
||||
{
|
||||
get => _purCheck;
|
||||
set
|
||||
{
|
||||
if (_purCheck == value) return;
|
||||
_purCheck = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private double _wight;
|
||||
[Category("零件属性")]
|
||||
[DisplayName("重量")]
|
||||
public double Wight
|
||||
{
|
||||
get => _wight;
|
||||
set
|
||||
{
|
||||
if (_wight == value) return;
|
||||
_wight = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _remark;
|
||||
[Category("杂项")]
|
||||
[DisplayName("备注")]
|
||||
public string Remark
|
||||
{
|
||||
get => _remark;
|
||||
set
|
||||
{
|
||||
if (_remark == value) return;
|
||||
_remark = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<UserControl x:Class="Laservall.Solidworks.Pane.PartPropPaneUserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Laservall.Solidworks.Pane"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
d:DesignHeight="500" d:DesignWidth="300"
|
||||
mc:Ignorable="d" >
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Laservall.Solidworks;component/Themes/Theme.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="20"/>
|
||||
</Grid.RowDefinitions>
|
||||
<hc:ButtonGroup Grid.Row="0" VerticalAlignment="Center" Margin="10,5">
|
||||
<Button FontSize="14" Content="保存" Background="#81C784"/>
|
||||
<Button FontSize="14" Content="重置" Background="#E57373" />
|
||||
</hc:ButtonGroup>
|
||||
<hc:PropertyGrid Background="Transparent"
|
||||
FontSize="14"
|
||||
Grid.Row="1"
|
||||
SelectedObject="{Binding PartPropModel}"/>
|
||||
<TextBlock Grid.Row="2"
|
||||
x:Name="VersionText"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Text="1.0.0.1"/>
|
||||
</Grid>
|
||||
</UserControl>
|
|
@ -0,0 +1,81 @@
|
|||
using Laservall.Solidworks.Extension;
|
||||
using Laservall.Solidworks.Model;
|
||||
using Laservall.Solidworks.Pane.WPF;
|
||||
using SolidWorks.Interop.sldworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Xarial.XCad;
|
||||
using Xarial.XCad.Documents;
|
||||
using Xarial.XCad.Features;
|
||||
using Xarial.XCad.SolidWorks.Documents;
|
||||
using Xarial.XCad.SolidWorks.UI;
|
||||
|
||||
namespace Laservall.Solidworks.Pane
|
||||
{
|
||||
/// <summary>
|
||||
/// PartPropPaneUserControl.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class PartPropPaneUserControl : UserControl
|
||||
{
|
||||
public ISwTaskPane<PartPropPaneUserControl> pane;
|
||||
|
||||
public PartPropModel PartPropModel { get; set; } = new PartPropModel();
|
||||
public PartPropPaneUserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = this;
|
||||
VersionText.Text = $"Ver.{Assembly.GetExecutingAssembly().GetName().Version}";
|
||||
}
|
||||
|
||||
public void OnSelectChange(IXDocument doc, IXSelObject xSelObject)
|
||||
{
|
||||
if (xSelObject.OwnerDocument is IXDocument)
|
||||
{
|
||||
if(xSelObject is ISwPartComponent partComponent)
|
||||
{
|
||||
SWDocReader.ReadDocProperties((IModelDoc2)partComponent.Component.GetModelDoc(), PartPropModel);
|
||||
}
|
||||
else if(xSelObject is IXFeature feature)
|
||||
{
|
||||
if(feature.Component is ISwComponent swPartComponent)
|
||||
{
|
||||
var doc2 = swPartComponent.Component.GetModelDoc() as IModelDoc2;
|
||||
if(doc2 != null)
|
||||
{
|
||||
SWDocReader.ReadDocProperties(doc2, PartPropModel);
|
||||
}
|
||||
}
|
||||
else if(feature.OwnerDocument != null)
|
||||
{
|
||||
var doc2 = (feature.OwnerDocument as ISwDocument).Model;
|
||||
if (doc2 != null)
|
||||
{
|
||||
SWDocReader.ReadDocProperties(doc2, PartPropModel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if(xSelObject.OwnerDocument is ISwPart)
|
||||
{
|
||||
//xSelObject.OwnerDocument.Properties
|
||||
}
|
||||
Debug.WriteLine($"OnSelectChange: {xSelObject.GetType()}");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<UserControl x:Class="Laservall.Solidworks.Pane.WPF.TestUserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Laservall.Solidworks.Pane.WPF"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="500" d:DesignWidth="300">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Laservall.Solidworks;component/Themes/Theme.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="20"/>
|
||||
</Grid.RowDefinitions>
|
||||
<hc:ButtonGroup Grid.Row="0" VerticalAlignment="Center" Margin="10,5">
|
||||
<Button FontSize="14" Content="保存" Background="#81C784"/>
|
||||
<Button FontSize="14" Content="重置" Background="#E57373" />
|
||||
</hc:ButtonGroup>
|
||||
<hc:PropertyGrid Background="Transparent" FontSize="14" Grid.Row="1" SelectedObject="{Binding partPropModel}"/>
|
||||
<TextBlock Grid.Row="2" x:Name="VersionText" VerticalAlignment="Center" HorizontalAlignment="Center" Text="1.0.0.1"/>
|
||||
</Grid>
|
||||
</UserControl>
|
|
@ -0,0 +1,53 @@
|
|||
using Laservall.Solidworks.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Xarial.XCad;
|
||||
using Xarial.XCad.Documents;
|
||||
using Xarial.XCad.SolidWorks.Documents;
|
||||
using Xarial.XCad.SolidWorks.UI;
|
||||
|
||||
namespace Laservall.Solidworks.Pane.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// TestUserControl.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
[DisplayName("Laservall 自定义属性卡")]
|
||||
public partial class TestUserControl : UserControl
|
||||
{
|
||||
public ISwTaskPane<TestUserControl> pane;
|
||||
|
||||
public PartPropModel partPropModel { get; set; }
|
||||
public TestUserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
partPropModel = new PartPropModel();
|
||||
DataContext = this;
|
||||
VersionText.Text = $"Ver.{Assembly.GetExecutingAssembly().GetName().Version}";
|
||||
}
|
||||
|
||||
public void OnSelectChange(IXDocument doc, IXSelObject xSelObject)
|
||||
{
|
||||
if (xSelObject is ISwPartComponent doc2)
|
||||
{
|
||||
Debug.WriteLine(doc2.Name);
|
||||
}
|
||||
Debug.WriteLine($"OnSelectChange: {xSelObject.GetType()}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Laservall.Solidworks")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Laservall China Co., Ltd")]
|
||||
[assembly: AssemblyProduct("Laservall.Solidworks")]
|
||||
[assembly: AssemblyCopyright("Copyright © Laservall China Co., Ltd 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(true)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("a8b83cc2-1dc4-478d-8956-b5357cdc336a")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
[assembly: AssemblyVersion("0.0.*")]
|
||||
[assembly: AssemblyFileVersion("0.0.*")]
|
|
@ -0,0 +1,9 @@
|
|||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<Style BasedOn="{StaticResource DataGridBaseStyle}" TargetType="DataGrid">
|
||||
<Setter Property="RowHeight" Value="NaN" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="HandyControl" version="3.5.1" targetFramework="net481" />
|
||||
<package id="Xarial.XCad" version="0.8.2" targetFramework="net472" />
|
||||
<package id="Xarial.XCad.SolidWorks" version="0.8.2" targetFramework="net472" />
|
||||
<package id="Xarial.XCad.Toolkit" version="0.8.2" targetFramework="net472" />
|
||||
</packages>
|
Loading…
Reference in New Issue