重构项目结构并添加新功能

将项目输出类型从 `Library` 更改为 `Exe`,并设置 `StartupObject` 为 `Sinvo.EplanHpD.Plugin.WPFUI.TestWindow`。删除了 `LectotypeWindow.xaml.cs` 的编译项,并添加了 `View\LectotypeWindow.xaml.cs`、`View\MainWindow.xaml.cs` 和 `View\CableLectotypeWindow.xaml.cs` 的编译项。添加了 `Utils\BaseAppExt.cs` 的编译项。

将 `MainWindow.xaml` 和 `TestWindow.xaml` 的页面项移动到 `View` 文件夹下,并添加了 `CableLectotypeWindow.xaml` 的页面项。在项目文件中添加了 `Common` 文件夹。在 `TestWindow.xaml.cs` 中添加了 `Main` 方法,并在其中显示 `CableLectotypeWindow`。

在 `Theme.xaml` 中添加了一个 `DataGrid` 的样式。添加了 `CableLectotypeWindow.xaml` 和 `CableLectotypeWindow.xaml.cs` 文件,定义了一个新的窗口。在 `LectotypeWindow.xaml` 中添加了一个按钮和 `DataGrid` 的上下文菜单,并在 `LectotypeWindow.xaml.cs` 中添加了多个事件处理方法。

在 `MainWindow.xaml.cs` 中修改了 `Dispatcher` 的调用方式。在 `DesignPluginEntry.cs` 中添加了 `EPLAN.Harness.AppCore` 的引用,并设置了窗口的所有者。在 `Sinvo.EplanHpD.Plugin.csproj` 中添加了 `EPLAN.Harness.AppCore` 的引用。
This commit is contained in:
lihanbo 2024-11-19 12:11:29 +08:00
parent 04045b01e3
commit ed490f4315
11 changed files with 273 additions and 29 deletions

View File

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2DBCD22A-650D-4797-9908-9C4D5D6665FE}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<RootNamespace>Sinvo.EplanHpD.Plugin.WPFUI</RootNamespace>
<AssemblyName>Sinvo.EplanHpD.Plugin.WPFUI</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
@ -56,7 +56,7 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
<StartupObject>Sinvo.EplanHpD.Plugin.WPFUI.TestWindow</StartupObject>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
@ -134,9 +134,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\UICommand.cs" />
<Compile Include="LectotypeWindow.xaml.cs">
<DependentUpon>LectotypeWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Models\CheckedModel.cs" />
<Compile Include="Models\ConfigItemModel.cs" />
<Compile Include="Models\ExcelModel.cs" />
@ -154,6 +151,7 @@
<DependentUpon>TestWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Utils\ApplicationExt.cs" />
<Compile Include="Utils\BaseAppExt.cs" />
<Compile Include="Utils\CheckedModelExt.cs" />
<Compile Include="Utils\Consts.cs" />
<Compile Include="Utils\DataGridType.cs" />
@ -170,17 +168,14 @@
<Compile Include="ViewModel\LectotypeViewModel.cs" />
<Compile Include="ViewModel\MainViewModel.Check.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Page Include="LectotypeWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="MainWindow.xaml.cs">
<Compile Include="View\CableLectotypeWindow.xaml.cs">
<DependentUpon>CableLectotypeWindow.xaml</DependentUpon>
</Compile>
<Compile Include="View\LectotypeWindow.xaml.cs">
<DependentUpon>LectotypeWindow.xaml</DependentUpon>
</Compile>
<Compile Include="View\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="TestWindow.xaml">
<SubType>Designer</SubType>
@ -190,6 +185,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="View\CableLectotypeWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="View\LectotypeWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
@ -239,5 +246,8 @@
<Version>8.0.6</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Common\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,5 +1,7 @@
using EPLAN.Harness.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using Sinvo.EplanHpD.Plugin.WPFUI.View;
using System;
using System.Linq;
using System.Windows;
@ -34,5 +36,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
testDataGrid.ItemsSource = wires;
}
[STAThread]
public static void Main()
{
var window = new CableLectotypeWindow();
window.ShowDialog();
}
}
}

View File

@ -3,4 +3,7 @@
<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>

View File

@ -0,0 +1,144 @@
<Window
x:Class="Sinvo.EplanHpD.Plugin.WPFUI.View.CableLectotypeWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="CableLectotypeWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Sinvo.EplanHpD.Plugin.WPFUI;component/Themes/Theme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<hc:Card
Grid.Row="0"
Grid.Column="0"
Effect="{DynamicResource EffectShadow2}">
<hc:SimpleStackPanel Orientation="Vertical">
<hc:SimpleStackPanel Orientation="Horizontal">
<hc:TextBox
Width="140"
Height="30"
Margin="5,0,0,0"
hc:TitleElement.Title="电机型号"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
<hc:TextBox
Width="140"
Height="30"
Margin="5,0,0,0"
hc:TitleElement.Title="电机功率"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel Orientation="Horizontal">
<hc:TextBox
Width="140"
Height="30"
Margin="5,0,0,0"
hc:TitleElement.Title="电机型号"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
<hc:TextBox
Width="140"
Height="30"
Margin="5,0,0,0"
hc:TitleElement.Title="电机功率"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel Orientation="Vertical">
<hc:TextBox
Width="240"
Height="30"
Margin="5,0,0,0"
HorizontalAlignment="Left"
hc:TitleElement.Title="电机型号"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
<hc:TextBox
Width="240"
Height="30"
Margin="5,0,0,0"
HorizontalAlignment="Left"
hc:TitleElement.Title="电机功率"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel Orientation="Vertical">
<hc:TextBox
Width="240"
Height="30"
Margin="5,0,0,0"
HorizontalAlignment="Left"
hc:TitleElement.Title="电机型号"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
<hc:TextBox
Width="240"
Height="30"
Margin="5,0,0,0"
HorizontalAlignment="Left"
hc:TitleElement.Title="电机型号"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel Orientation="Horizontal">
<hc:TextBox
Width="140"
Height="30"
Margin="5,0,0,0"
hc:TitleElement.Title="电机型号"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
<hc:TextBox
Width="140"
Height="30"
Margin="5,0,0,0"
hc:TitleElement.Title="电机功率"
hc:TitleElement.TitlePlacement="Left"
hc:TitleElement.VerticalAlignment="Center"
IsReadOnly="True" />
</hc:SimpleStackPanel>
</hc:SimpleStackPanel>
</hc:Card>
<hc:SimpleStackPanel
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2">
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Text="Hello World!" />
</hc:SimpleStackPanel>
<hc:Card Grid.Row="0" Grid.Column="1">
<ListView />
</hc:Card>
</Grid>
</Window>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
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.Shapes;
namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{
/// <summary>
/// CableLectotypeWindow.xaml 的交互逻辑
/// </summary>
public partial class CableLectotypeWindow : Window
{
public CableLectotypeWindow()
{
InitializeComponent();
}
}
}

View File

@ -15,6 +15,7 @@
d:DataContext="{d:DesignInstance Type=viewmodel:LectotypeViewModel}"
Closed="Window_Closed"
Loaded="Window_Loaded"
Topmost="False"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Window.Resources>
@ -150,6 +151,12 @@
Click="ExportExcelBtn_Click"
Content="导出下单表"
Style="{StaticResource ButtonPrimary}" />
<Button
x:Name="EnableSelectSetBtn"
Margin="5"
Click="EnableSelectSetBtn_Click"
Content="启用选择监听"
Style="{StaticResource ButtonPrimary}" />
</hc:SimpleStackPanel>
</hc:Card>
<TabControl Grid.Row="1" FontSize="14">
@ -403,7 +410,14 @@
x:Name="MotorDataGrid"
AutoGenerateColumns="False"
IsReadOnly="False"
ItemsSource="{Binding Motors}">
ItemsSource="{Binding Motors}"
RowHeight="NaN">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Click="MotorDataGridToMotorSourceMenuItem_Click" Header="在3D中查看转至电机" />
<MenuItem Click="MotorDataGridToCableLectotype_Click" Header="根据此电机开始选择线材" />
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Resources>
<Style BasedOn="{StaticResource DataGridCellStyle}" TargetType="DataGridCell">
<Setter Property="Height" Value="Auto" />
@ -448,8 +462,6 @@
</DataGrid>
</TabItem>
</TabControl>
<Grid
Grid.Row="0"
Grid.RowSpan="2"

View File

@ -4,6 +4,7 @@ using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using Sinvo.EplanHpD.Plugin.WPFUI.View;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System;
using System.Diagnostics;
@ -36,6 +37,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
//DrawPDFHelper.CacheAllPdfToMemory();
MotorExcelHelper.Instance.ReadDataToStream();
LoadData();
}
catch (System.Exception ex)
{
@ -311,20 +313,51 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
var selectItem = LettotypeListView.SelectedItem;
if (selectItem is LectotypeLineModel model)
{
var motorModelStr = model.Motor?.MotorModelStr;
var motorModelPartId = model.Motor?.OccPartId;
var cableName = model.IsComplexLine ? model.CableName.Split('/')[1] : model.CableName;
if (string.IsNullOrEmpty(motorModelStr))
if (string.IsNullOrEmpty(motorModelPartId))
{
FlexMessageBox.ShowText(FlexMessageBox.Type.INFO, "未获取到电机名称");
}
else
{
ViewModel.ToMotorSource(motorModelStr, cableName);
ViewModel.ToMotorSource(motorModelPartId, cableName);
}
//}
}
}
private void EnableSelectSetBtn_Click(object sender, RoutedEventArgs e)
{
}
private void MotorDataGridToMotorSourceMenuItem_Click(object sender, RoutedEventArgs e)
{
var selectItem = MotorDataGrid.SelectedItem;
if (selectItem is MotorModel model)
{
var motorModelPartId = model.OccPartId;
//var cableName = model.IsComplexLine ? model.CableName.Split('/')[1] : model.CableName;
if (string.IsNullOrEmpty(motorModelPartId))
{
FlexMessageBox.ShowText(FlexMessageBox.Type.INFO, "未获取到电机名称");
}
else
{
ViewModel.ToMotorSource(motorModelPartId, null);
}
//}
}
}
private void MotorDataGridToCableLectotype_Click(object sender, RoutedEventArgs e)
{
new CableLectotypeWindow().Show();
}
}
}

View File

@ -74,7 +74,6 @@
ContentTemplate="{StaticResource LoadingMask}" />
<Grid Grid.Row="0">
<StackPanel Orientation="Horizontal">
<hc:Card
MinWidth="200"
Margin="8"

View File

@ -147,11 +147,11 @@ public partial class MainWindow : System.Windows.Window
{
Growl.Register("Message", GrowlParent);
LoadingMask.Visibility = Visibility.Visible;
this.Dispatcher.BeginInvoke(async delegate ()
{
ExcelHelper.CheckAndGetCache(true);
await LoadDataAsync(datas, reportColumns);
});
await this.Dispatcher.BeginInvoke(async delegate ()
{
ExcelHelper.CheckAndGetCache(true);
await LoadDataAsync(datas, reportColumns);
});
}
catch (System.Exception ex)
{

View File

@ -1,5 +1,6 @@
using EPLAN.Harness.API;
using EPLAN.Harness.API.Plugins.Core;
using EPLAN.Harness.AppCore;
using Sinvo.EplanHpD.Plugin.WPFUI;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using System;
@ -45,8 +46,6 @@ namespace Sinvo.EplanHpD.Plugin
public string ToolbarText => "伺服电机线缆抓取";
public string ToolbarTooltip => "伺服电机线缆抓取";
public HpDModule Module => HpDModule.WorkSpace;
public void Execute(HpdApi api)
@ -54,6 +53,9 @@ namespace Sinvo.EplanHpD.Plugin
var doc = api.CurrentProject.GetActiveDocument();
var window = new LectotypeWindow(doc.ID);
ElementHost.EnableModelessKeyboardInterop(window);
var mainApp = BaseApp.ActiveApplication;
var helper = new System.Windows.Interop.WindowInteropHelper(window);
helper.Owner = mainApp.Handle;
window.Show();
}

View File

@ -77,6 +77,10 @@
<Reference Include="EPLAN.Harness.API.Plugins.Core">
<HintPath>RefDLL\EPLAN.Harness.API.Plugins.Core.dll</HintPath>
</Reference>
<Reference Include="EPLAN.Harness.AppCore, Version=2.9.2.903, Culture=neutral, PublicKeyToken=57aaa27e22f7b107, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>RefDLL\EPLAN.Harness.AppCore.dll</HintPath>
</Reference>
<Reference Include="EPLAN.Harness.Common, Version=2.9.2.903, Culture=neutral, PublicKeyToken=57aaa27e22f7b107" />
<Reference Include="EPLAN.Harness.Core, Version=2.9.2.903, Culture=neutral, PublicKeyToken=57aaa27e22f7b107, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>