EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.WPFUI/View/LayoutHelperWindow.xaml.cs

102 lines
3.1 KiB
C#

using EPLAN.Harness.API;
using EPLAN.Harness.Core.Controls;
using EPLAN.Harness.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using HandyControl.Controls;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
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>
/// LayoutHelperWindow.xaml 的交互逻辑
/// </summary>
public partial class LayoutHelperWindow
{
private FlexDesigner _currentFlexDesigner;
private LayoutHelperViewModel viewModel;
public LayoutHelperWindow(List<string> motorIds)
{
InitializeComponent();
viewModel = new LayoutHelperViewModel(_currentFlexDesigner, motorIds);
this.DataContext = viewModel;
}
private void OnInit()
{
GetCurrentDoc();
_currentFlexDesigner.SelectSet.SelectionChanged += SelectSet_SelectionChanged;
GetMotorCables();
}
private void GetMotorCables()
{
viewModel.GetMotorCables();
}
private void SelectSet_SelectionChanged(object sender, EventArgs e)
{
viewModel.OnSelectChange(sender);
}
public void GetCurrentDoc()
{
try
{
HpdApi api = HpdApi.GetInstance();
var currentDocId = api.CurrentProject.GetActiveDocument()?.ID;
var designer = SelfControler<FlexBaseOrganizer>.FindInstance(currentDocId) as FlexDesigner;
if (designer != null)
{
_currentFlexDesigner = designer;
viewModel._currentFlexDesigner = designer;
}
else
{
FlexMessageBox.Warning("未找到当前打开的工作区,请先打开工作区");
}
}
catch (Exception ex)
{
FlexMessageBox.Error(ex.Message);
}
}
private void GlowWindow_Loaded(object sender, RoutedEventArgs e)
{
Growl.Register("LayoutMessage", GrowlParent);
OnInit();
}
private void PrevBtn_Click(object sender, RoutedEventArgs e)
{
viewModel.ToPrevLine();
}
private void NextBtn_Click(object sender, RoutedEventArgs e)
{
viewModel.ToNextLine();
}
private void AxisNoAndLineBtn_Click(object sender, RoutedEventArgs e)
{
if(viewModel != null && viewModel.SelectedLine != null)
{
var text = $"{viewModel.SelectedLine.AxisNo}-{viewModel.SelectedLine.CurrentLine}";
Clipboard.SetDataObject(text);
}
}
}
}