146 lines
5.1 KiB
C#
146 lines
5.1 KiB
C#
![]() |
using System;
|
|||
|
using System.Linq;
|
|||
|
using System.Windows.Forms;
|
|||
|
using Bricscad.Ribbon;
|
|||
|
using Bricscad.Windows;
|
|||
|
using CAD.Extend;
|
|||
|
using CAD.Extend.ViewModels;
|
|||
|
using CAD.Extend.Views;
|
|||
|
using Prism.Container.DryIoc;
|
|||
|
using Prism.Dialogs;
|
|||
|
using Prism.Ioc;
|
|||
|
using SWS.CAD.Base;
|
|||
|
using Teigha.Runtime;
|
|||
|
using Telerik.Windows.Controls;
|
|||
|
using Unity;
|
|||
|
using Application = Bricscad.ApplicationServices.Application;
|
|||
|
|
|||
|
[assembly: CommandClass(typeof(Commands))]
|
|||
|
[assembly: ExtensionApplication(typeof(Commands))]
|
|||
|
namespace CAD.Extend
|
|||
|
{
|
|||
|
public partial class Commands : IExtensionApplication
|
|||
|
{
|
|||
|
|
|||
|
public void Initialize()
|
|||
|
{
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
|||
|
if (RibbonServices.RibbonPaletteSet == null)
|
|||
|
RibbonServices.CreateRibbonPaletteSet();
|
|||
|
|
|||
|
Register();
|
|||
|
|
|||
|
AddTab();
|
|||
|
}
|
|||
|
catch (System.Exception e)
|
|||
|
{
|
|||
|
Application.ShowAlertDialog(" An exception occurred in Initialize():\n" + e.ToString());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void Register()
|
|||
|
{
|
|||
|
|
|||
|
GlobalObject._prismContainer = new DryIocContainerExtension();
|
|||
|
GlobalObject._prismContainer.Register<IDialogService, DialogService>();
|
|||
|
GlobalObject._prismContainer.Register<IDialogWindow, CustomDialogWindow>();
|
|||
|
GlobalObject._prismContainer.RegisterDialog<DialogConvertBaseMap, DialogConvertBaseMapViewModel>();
|
|||
|
}
|
|||
|
|
|||
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
// 记录异常信息到日志文件,这里简单打印到控制台
|
|||
|
System.Exception ex = e.ExceptionObject as System.Exception;
|
|||
|
Console.WriteLine($"发生未处理的异常: {ex.Message}");
|
|||
|
Console.WriteLine($"异常堆栈跟踪: {ex.StackTrace}");
|
|||
|
|
|||
|
// 关闭所有打开的对话框窗口
|
|||
|
|
|||
|
|
|||
|
// 提示用户发生了错误
|
|||
|
MessageBox.Show("发生错误,请检查日志文件以获取更多信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
catch (System.Exception innerEx)
|
|||
|
{
|
|||
|
// 如果在处理异常时又发生了异常,简单打印信息
|
|||
|
Console.WriteLine($"处理异常时发生错误: {innerEx.Message}");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Terminate()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
void AddTab()
|
|||
|
{
|
|||
|
RibbonControl rbnCtrl = ComponentManager.Ribbon; //整个上面都是ribbon,比如莫工做的电气系统,就是ribbon中的一个tab
|
|||
|
|
|||
|
if (rbnCtrl == null) return;
|
|||
|
#region create Ribbon tab
|
|||
|
RibbonTab tab1 = new RibbonTab();
|
|||
|
tab1.Title = "扩展功能";
|
|||
|
tab1.Id = "扩展功能";
|
|||
|
rbnCtrl.Tabs.Add(tab1);//一个就行了
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Ribbon 图层管理
|
|||
|
RibbonPanelSource dataSource = new RibbonPanelSource();
|
|||
|
dataSource.Title = "图层操作";
|
|||
|
dataSource.Id = "图层操作";
|
|||
|
RibbonPanel dataPanel = new RibbonPanel();
|
|||
|
dataPanel.Source = dataSource;
|
|||
|
tab1.Panels.Add(dataPanel);
|
|||
|
|
|||
|
//垂直排列按钮panel
|
|||
|
RibbonRowPanel ribbonRowPanel = new RibbonRowPanel();
|
|||
|
|
|||
|
#region buttons 一键转底图
|
|||
|
RibbonButton btnSinalManage = new RibbonButton();
|
|||
|
btnSinalManage.ToolTip = "一键转底图";
|
|||
|
btnSinalManage.Text = "一键转底图";
|
|||
|
btnSinalManage.ButtonStyle = RibbonButtonStyle.SmallWithText;
|
|||
|
btnSinalManage.CommandHandler = new DelegateCommand(x =>
|
|||
|
{
|
|||
|
var listObjectId=General.GetSelectedObjectId();
|
|||
|
if (listObjectId==null||!listObjectId.Any())
|
|||
|
{
|
|||
|
MessageBox.Show("请先选择图元!");
|
|||
|
return;
|
|||
|
}
|
|||
|
//打开窗体
|
|||
|
Prism.Dialogs.DialogParameters para = new Prism.Dialogs.DialogParameters();
|
|||
|
para.Add(GlobalObject.dialogPar.info.ToString(), listObjectId);
|
|||
|
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
|
|||
|
_dialogService.ShowDialog(nameof(DialogConvertBaseMap), para, (RES) =>
|
|||
|
{
|
|||
|
if (RES.Result == ButtonResult.Yes)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
else if (RES.Result == ButtonResult.No)
|
|||
|
{ }
|
|||
|
});
|
|||
|
});
|
|||
|
btnSinalManage.Image = GlobalObject.ImageSourceFromEmbeddedResourceStream(@"CAD.Extend.Images.pic1.png");
|
|||
|
btnSinalManage.Id = "一键转底图";
|
|||
|
ribbonRowPanel.Items.Add(btnSinalManage);
|
|||
|
ribbonRowPanel.Items.Add(new RibbonRowBreak());//换行,这样可以使按钮多行排列
|
|||
|
#endregion
|
|||
|
dataSource.Items.Add(ribbonRowPanel);
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|