160 lines
4.6 KiB
C#
160 lines
4.6 KiB
C#
|
|
using Laservall.Solidworks.Extension;
|
|
using Laservall.Solidworks.Pane;
|
|
using Laservall.Solidworks.Server;
|
|
using Laservall.Solidworks.Windows;
|
|
using Laservall.Solidworks.Windows.ViewModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Resources;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
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.Commands.Attributes;
|
|
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
|
|
{
|
|
[Title("Laservall")]
|
|
[Description("Laservall 工具")]
|
|
public enum LaservallCommands_e
|
|
{
|
|
[Title("生成BOM")]
|
|
[Description("生成物料清单")]
|
|
GenerateBOM
|
|
}
|
|
|
|
[System.Runtime.InteropServices.ComVisible(true)]
|
|
public class AddinEntry : Xarial.XCad.SolidWorks.SwAddInEx
|
|
{
|
|
private IXTaskPane<PartPropPaneUserControl> m_TaskPane;
|
|
|
|
private static readonly bool UseWpfBomWindow = false;
|
|
|
|
private static ItemsPropWindow _bomWindow;
|
|
private static BomHttpServer _bomServer;
|
|
private static StaThreadMarshaller _marshaller;
|
|
|
|
public override void OnConnect()
|
|
{
|
|
AppDomainDllLoader.SetLaoder();
|
|
WPFApplicationExt.InitApplication();
|
|
|
|
_marshaller = new StaThreadMarshaller(System.Windows.Application.Current.Dispatcher);
|
|
|
|
SWUtils.SwApp = this.Application.Sw;
|
|
|
|
this.CommandManager.AddCommandGroup<LaservallCommands_e>().CommandClick += OnCommandClick;
|
|
|
|
var cmdTaskPane = this.CreateTaskPane<PartPropPaneUserControl>(new TaskPaneSpec
|
|
{
|
|
Title = "Laservall 自定义属性卡",
|
|
Tooltip = "Laservall 自定义属性卡"
|
|
});
|
|
cmdTaskPane.Control.pane = cmdTaskPane;
|
|
|
|
m_TaskPane = cmdTaskPane;
|
|
|
|
this.Application.Documents.DocumentActivated += OnDocumentActivated;
|
|
|
|
if (this.Application.Documents.Active != null)
|
|
{
|
|
SubscribeToSelectionEvents(this.Application.Documents.Active);
|
|
}
|
|
|
|
this.CreateTaskPane<FeaturesUserControl>(new TaskPaneSpec
|
|
{
|
|
Title = "Laservall Features",
|
|
Tooltip = "Laservall Features"
|
|
});
|
|
}
|
|
|
|
private void OnCommandClick(LaservallCommands_e cmd)
|
|
{
|
|
switch (cmd)
|
|
{
|
|
case LaservallCommands_e.GenerateBOM:
|
|
if (UseWpfBomWindow)
|
|
OpenBomWindowWpf();
|
|
else
|
|
OpenBomInBrowser();
|
|
break;
|
|
}
|
|
}
|
|
|
|
internal static void OpenBomInBrowser()
|
|
{
|
|
if (_bomServer != null && _bomServer.IsRunning)
|
|
{
|
|
_bomServer.OpenInBrowser();
|
|
return;
|
|
}
|
|
|
|
_bomServer?.Dispose();
|
|
_bomServer = new BomHttpServer(new SolidWorksBomDataProvider(_marshaller));
|
|
_bomServer.Start();
|
|
_bomServer.OpenInBrowser();
|
|
}
|
|
|
|
internal static void OpenBomWindowWpf()
|
|
{
|
|
if (_bomWindow != null)
|
|
{
|
|
try
|
|
{
|
|
_bomWindow.Activate();
|
|
return;
|
|
}
|
|
catch
|
|
{
|
|
_bomWindow = null;
|
|
}
|
|
}
|
|
|
|
_bomWindow = new ItemsPropWindow();
|
|
_bomWindow.DataContext = new ItemsViewModel();
|
|
_bomWindow.Closed += (s, args) => _bomWindow = null;
|
|
_bomWindow.Show();
|
|
}
|
|
|
|
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.ViewModel.OnSelectionChanged(doc, selObject);
|
|
}
|
|
|
|
public override void OnDisconnect()
|
|
{
|
|
_bomServer?.Dispose();
|
|
_bomServer = null;
|
|
|
|
base.OnDisconnect();
|
|
}
|
|
|
|
private void OnTaskPaneButtonClick(TaskPaneButtonSpec spec)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|