200 lines
7.1 KiB
C#
200 lines
7.1 KiB
C#
using EPLAN.Harness.Actuator.Commands.Designer;
|
||
using EPLAN.Harness.API;
|
||
using EPLAN.Harness.AppCore.Controls;
|
||
using EPLAN.Harness.Core;
|
||
using EPLAN.Harness.Core.Commands;
|
||
using EPLAN.Harness.Core.Common;
|
||
using EPLAN.Harness.Core.Controls;
|
||
using EPLAN.Harness.Core.UIFactory;
|
||
using EPLAN.Harness.Primitives.ActionControls;
|
||
using EPLAN.Harness.ProjectCore;
|
||
using EPLAN.Harness.ProjectCore.Occurrences;
|
||
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
|
||
using HandyControl.Controls;
|
||
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
|
||
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}";
|
||
SetToClipboard(text);
|
||
}
|
||
}
|
||
|
||
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
|
||
{
|
||
if (sender is System.Windows.Controls.TextBox box)
|
||
{
|
||
SetToClipboard(box.Text);
|
||
box.SelectAll();
|
||
}
|
||
}
|
||
private void SetToClipboard(string text)
|
||
{
|
||
try
|
||
{
|
||
Clipboard.SetDataObject(text);
|
||
Growl.SuccessGlobal("复制成功!");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
FlexMessageBox.Error(ex.Message);
|
||
}
|
||
}
|
||
protected CmdRunEnv _cmdEnvironment = CmdRunEnv.Designer;
|
||
private void InsertCableBtn_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if(sender is Button btn)
|
||
{
|
||
if(!string.IsNullOrEmpty(btn.Tag?.ToString() ?? ""))
|
||
{
|
||
string cableModelNo = btn.Tag?.ToString();
|
||
SetToClipboard(cableModelNo);
|
||
|
||
var Commander = new CommandInvoker();
|
||
|
||
//this._organizer as FlexDesigner,
|
||
//this._bookmarks.ItemList,
|
||
//this.GetConectWireFrm(),
|
||
//this.GetForkedCableControl(OccCablesSubpartGraph.SIDE.Left),
|
||
//this._cmdEnvironment
|
||
var cmdD3DPlaceCableForkedAH = new CmdD3DPlaceCableForkedAH(
|
||
_currentFlexDesigner,
|
||
new EPLAN.Harness.Core.Common.BookmarkList(),
|
||
GetConectWireFrm(),
|
||
this.GetForkedCableControl(OccCablesSubpartGraph.SIDE.Left),
|
||
_cmdEnvironment);
|
||
Commander.ExecuteCommand(cmdD3DPlaceCableForkedAH);
|
||
|
||
}
|
||
}
|
||
}
|
||
private CmdD3DPlaceCableBase.IfrmConnectWires GetConectWireFrm()
|
||
{
|
||
return _currentFlexDesigner.CurrentView.UserControlFactory_Create<CmdD3DPlaceCableBase.IfrmConnectWires>(UIObject.frm_Designer_ConnectCableWires, Array.Empty<object>());
|
||
}
|
||
private CmdD3DPlaceCableForked.IForkedCableControl GetForkedCableControl(OccCablesSubpartGraph.SIDE side)
|
||
{
|
||
return _currentFlexDesigner.CurrentView.UserControlFactory_Create<CmdD3DPlaceCableForked.IForkedCableControl>(UIObject.ctrl_Designer_ForkedPathPlace, new object[] { side });
|
||
}
|
||
|
||
private void ToMotorBtn_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
ToMotorSource(viewModel.Motor.OccPartId);
|
||
}
|
||
public void ToMotorSource(string motorId)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(LectotypeManager.CURRENT_DOC_ID)) return;
|
||
// 获取当前使用的设计器的实例
|
||
var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == LectotypeManager.CURRENT_DOC_ID);
|
||
// 使用设计器根据EPLAN内部的部件ID,获取部件实例
|
||
var part = doc.GetOccurrenceByID(motorId);
|
||
//var cable = doc.GetOccurrenceByName(cableName, typeof(OccCableForked));
|
||
if (part != null)
|
||
{
|
||
doc.SelectSet.Clear();
|
||
// 根据EPLAN内部的部件ID,获取部件实例
|
||
//var oriOcc = SelfControler<BaseOccurrence>.FindInstance(part.ID);
|
||
part.SetVisibility(true, null);
|
||
doc.SelectSet.Add(part);
|
||
doc.FitToSelectSet();
|
||
doc.SelectSet.OnSelectionChanged();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
FlexMessageBox.Error(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|