Files
RookieStation/RookieStation/RsApp.cs
2021-11-23 16:37:19 +08:00

280 lines
16 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Autodesk.Revit.UI;
using RookieStation.CommonTools.ExecuteCmd;
using RookieStation.CommonTools.Views;
using RookieStation.Finishes.ExecuteCmds;
using RookieStation.ParcelAreaModule.ExecuteCmds;
using RookieStation.ProjectConfig.ExecuteCmds;
using RookieStation.MailingAreaModule.ExecuteCmds;
using RookieStation.Statistics.ExecuteCmds;
using RookieStation.Utils;
using System;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using RookieStation.Drawing.ExecuteCmds;
using System.Reflection;
namespace RookieStation.RibbonMenu
{
internal class RsApp : IExternalApplication
{
private const string TabName = "菜鸟驿站工具";
private const string ProjectSettingsPanelName = "项目设置";
private const string ReceptionPanelName = "前台布置";
private const string EntranceAndExitGatePanelName = "取件区";
private const string FinishesPanelName = "饰面";
private const string StatisticsPanelName = "统计";
private const string DrawingPanelName = "出图";
private const string CommonTools = "通用工具";
///// <summary>
///// 帮助文档
///// </summary>
///// <param name="helpFile"></param>
///// <returns></returns>
//private static ContextualHelp CreateContextualHelp(string helpFile)
//{
// FileInfo dllFileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location);
// string helpFilePath = Path.Combine(dllFileInfo.Directory.Parent.FullName, "help.htm");
// FileInfo helpFileInfo = new FileInfo(helpFilePath);
// if (helpFileInfo.Exists)
// {
// return new ContextualHelp(ContextualHelpType.Url, helpFilePath);
// }
// else
// {
// string dirPath = dllFileInfo.Directory.FullName;
// //Get the english documentation
// string HelpName = helpFile;
// string HelpPath = Path.Combine(dirPath, HelpName);
// //if the help file does not exist, extract it in the HelpDirectory
// //Extract the english documentation
// Tools.ExtractRessource("AlignTag.Resources.AlignHelp.chm", HelpPath);
// return new ContextualHelp(ContextualHelpType.ChmFile, HelpPath);
// }
//}
//获取Ribbon类所在的通用类库目录
private static readonly string AddInPath = typeof(RsApp).Assembly.Location;
//获取AddInPath的目录
private static readonly string DirRequestAssembly = Path.GetDirectoryName(AddInPath);
private static readonly string ViewPlanCmdEnabled = typeof(EnableCmdInViewPlan).ToString();
private static readonly string DrawingSheetCmdEnabled = typeof(EnableCmdInViewSheet).ToString();
private static readonly string ViewSectionCmdEnabled = typeof(EnableCmdInViewSection).ToString();
private static readonly string NotView3dCmdEnabled = typeof(EnableCmdNotInView3D).ToString();
private BitmapSource ConvertFromBitmap(System.Drawing.Bitmap bitmap)
{
return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
Result IExternalApplication.OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
Result IExternalApplication.OnStartup(UIControlledApplication application)
{
try
{
application.CreateRibbonTab(TabName);
//UserPanel.AddItem(_loginPBData);
//".\\*.*"中的“.”表示通用类库文件所在的目录Debug“..”表示的是上级的目录bin“..”\\..,引号表示再上一级目录
//ContextualHelp contextualHelp = new ContextualHelp(ContextualHelpType.Url, "https://www.baidu.com");
//_loginPBData.SetContextualHelp(contextualHelp);
//项目设置
RibbonPanel projectPanel = application.CreateRibbonPanel(TabName, ProjectSettingsPanelName);
NewPushButtonData<CmdProjectSettings>(projectPanel, "项目设置", Properties.Resources.cainiao, null);
//前台布置
RibbonPanel receptionAreaPanel = application.CreateRibbonPanel(TabName, ReceptionPanelName);
NewPushButtonData<CmdPlaceReceptionArea>(receptionAreaPanel, "前台布置", Properties.Resources.Reception, ViewPlanCmdEnabled);
NewPushButtonData<CmdLogoExtrusion>(receptionAreaPanel, "标识挤出", Properties.Resources.LogoExtrusion, ViewPlanCmdEnabled);
//出入口布置
RibbonPanel packAreaPanel = application.CreateRibbonPanel(TabName, EntranceAndExitGatePanelName);
NewPushButtonData<CmdPlaceEntranceGate>(packAreaPanel, "入口布置", Properties.Resources.EntranceGate, ViewPlanCmdEnabled);
NewPushButtonData<CmdPlaceExitGate>(packAreaPanel, "出口布置", Properties.Resources.ExitGate, ViewPlanCmdEnabled);
//PushButtonData exitGateLayoutPBD = new PushButtonData("出口布置", "出口收检台", AddInPath, typeof(CmdPlaceExitGate).FullName)
//{
// LargeImage = ConvertFromBitmap(Properties.Resources.ExitGate),
// Image = ConvertFromBitmap(Properties.Resources.ExitGate)
//};
////var gateBtn = (PushButton)gatePanel.AddItem(exportGateLayoutPBD);
////IList<RibbonItem> gateItemsStacked = packAreaPanel.AddStackedItems(entrancegateLayoutPBD, exitGateLayoutPBD);
////var entranceBtn = (PushButton)gateItemsStacked[0];
////var exitBtn = (PushButton)gateItemsStacked[1];
//寄件区布置
NewPushButtonData<CmdPlaceShelves>(packAreaPanel, "货架布置", Properties.Resources.Shelf, ViewPlanCmdEnabled);
NewPushButtonData<CmdArrangeShelfCards>(packAreaPanel, "货架端牌", Properties.Resources.ShelfCard, ViewPlanCmdEnabled);
NewPushButtonData<CmdPlaceLamps>(packAreaPanel, "灯具布置", Properties.Resources.Lamp, ViewPlanCmdEnabled);
//饰面,完成面
RibbonPanel finishesPanel = application.CreateRibbonPanel(TabName, FinishesPanelName);
NewPushButtonData<CmdPlaceFloorFinishes>(finishesPanel, "板饰面", Properties.Resources.FloorFinishes, ViewPlanCmdEnabled);
NewPushButtonData<CmdPlaceWallFinishes>(finishesPanel, "墙饰面", Properties.Resources.WallFinishes, ViewPlanCmdEnabled);
//统计面板
RibbonPanel statisticsPanel = application.CreateRibbonPanel(TabName, StatisticsPanelName);
NewPushButtonData<CmdExportBudgetInventory>(statisticsPanel, "工程量导出", Properties.Resources.WorkSchedule, null);
//出图面板
RibbonPanel drawingPanel = application.CreateRibbonPanel(TabName, DrawingPanelName);
NewPushButtonData<CreateMainMaterialsTable>(drawingPanel, "主材表", Properties.Resources.MainMaterials, DrawingSheetCmdEnabled);
SplitButtonData legendSplitButtonData = new SplitButtonData("创建图例", "创建图例");
var lspb = drawingPanel.AddItem(legendSplitButtonData) as SplitButton;
PushButtonData planeGraphButtonData = new PushButtonData("平面图例", "平面图例", AddInPath, typeof(CreatePlaneGraphLegend).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.PlaneLegend),
Image = ConvertFromBitmap(Properties.Resources.PlaneLegend),
ToolTip = "在菜鸟驿站平面布置图中创建图例。",
AvailabilityClassName = DrawingSheetCmdEnabled
};
PushButtonData furnitureButtonData = new PushButtonData("家具图例", "家具图例", AddInPath, typeof(CreateFurnitureLegend).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.FurnitureLegend),
Image = ConvertFromBitmap(Properties.Resources.FurnitureLegend),
ToolTip = "在家具尺寸图中创建家具图例。",
AvailabilityClassName = DrawingSheetCmdEnabled
};
PushButtonData wallButtonData = new PushButtonData("墙体图例", "墙体图例", AddInPath, typeof(CreateWallLegend).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.WallLegend),
Image = ConvertFromBitmap(Properties.Resources.WallLegend),
ToolTip = "在墙体定位图中创建墙体图例。",
AvailabilityClassName = DrawingSheetCmdEnabled
};
PushButtonData floorButtonData = new PushButtonData("地面图例", "地面图例", AddInPath, typeof(CreateGroundPavingLegend).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.GroundLegend),
Image = ConvertFromBitmap(Properties.Resources.GroundLegend),
ToolTip = "在地面铺贴图中创建地面铺贴图例。",
AvailabilityClassName = DrawingSheetCmdEnabled
};
PushButtonData lightButtonData = new PushButtonData("灯具图例", "灯具图例", AddInPath, typeof(CreateLightLegend).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.LightLegend),
Image = ConvertFromBitmap(Properties.Resources.LightLegend),
ToolTip = "在灯具定位图中创建灯具图例。",
AvailabilityClassName = DrawingSheetCmdEnabled
};
PushButtonData socketButtonData = new PushButtonData("插座图例", "插座图例", AddInPath, typeof(CreateSocketLegend).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.SocketLegend),
Image = ConvertFromBitmap(Properties.Resources.SocketLegend),
ToolTip = "在强弱电点位图中创建插座图例。",
AvailabilityClassName = DrawingSheetCmdEnabled
};
PushButtonData switchButtonData = new PushButtonData("开关图例", "开关图例", AddInPath, typeof(CreateSwitchLegend).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.SwitchLegend),
Image = ConvertFromBitmap(Properties.Resources.SwitchLegend),
ToolTip = "在开关控制图中创建开关图例。",
AvailabilityClassName = DrawingSheetCmdEnabled
};
lspb.AddPushButton(planeGraphButtonData);
lspb.AddPushButton(furnitureButtonData);
lspb.AddPushButton(wallButtonData);
lspb.AddPushButton(floorButtonData);
lspb.AddPushButton(lightButtonData);
lspb.AddPushButton(socketButtonData);
lspb.AddPushButton(switchButtonData);
SplitButtonData tagSplitButtonData = new SplitButtonData("标记整理", "标记整理");
var tspb = drawingPanel.AddItem(tagSplitButtonData) as SplitButton;
//PulldownButtonData tagPullButtonData = new PulldownButtonData("标记整理", "标记整理");
//var tpbb = drawingPanel.AddItem(tagPullButtonData) as PulldownButton;
//var ManualAlignPBD = NewPushButtonData<ManualAlign>(drawingPanel, "手动", Properties.Resources.ArrangeTags, null);
PushButtonData ManualAlignPBD = new PushButtonData("手动", "手动", AddInPath, typeof(ManualAlignTags).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.ManualArrangeTags),
Image = ConvertFromBitmap(Properties.Resources.ManualArrangeTags),
ToolTip = "对当前视图的标记进行手动整理。",
AvailabilityClassName = NotView3dCmdEnabled
};
//var autoAlignPBD = NewPushButtonData<AutoAlign>(drawingPanel, "自动", Properties.Resources.ArrangeTags, null);
PushButtonData autoAlignPBD = new PushButtonData("自动", "自动", AddInPath, typeof(AutoAlignTags).FullName)
{
LargeImage = ConvertFromBitmap(Properties.Resources.AutoArrangeTags),
Image = ConvertFromBitmap(Properties.Resources.AutoArrangeTags),
ToolTip = "对当前视图的所有标记进行分组自动整理。",
AvailabilityClassName = NotView3dCmdEnabled
};
tspb.AddPushButton(ManualAlignPBD);
tspb.AddPushButton(autoAlignPBD);
NewPushButtonData<CreateViewPlanAnnotation>(drawingPanel, "平面标注", Properties.Resources.ViewPlanDim, ViewPlanCmdEnabled);
NewPushButtonData<CreateViewSectionAnnotation>(drawingPanel, "立面标注", Properties.Resources.ViewSectionDim, ViewSectionCmdEnabled);
NewPushButtonData<CreateWires>(drawingPanel, "创建导线", Properties.Resources.Wire, ViewPlanCmdEnabled);
var UnifyViewportPBD = NewPushButtonData<UnifyViewportOnViewSheet>(drawingPanel, "统一视口", Properties.Resources.UnifyViewport, ViewPlanCmdEnabled);
UnifyViewportPBD.ToolTip = "请选择一个合适的楼层平面,以该楼层平面视口范围作为图纸视口范围";
NewPushButtonData<BatchExportDwg>(drawingPanel, "批量导出DWG", Properties.Resources.ExportDWG, null);
//通用面板
RibbonPanel commonToolsPanel = application.CreateRibbonPanel(TabName, CommonTools);
//CreatePushButton<CmdEncryptFamily>(commonToolsPanel, "加密族", Properties.Resources.Encrypt, null);
//CreatePushButton<CmdDecryptFamily>(commonToolsPanel, "解密族", Properties.Resources.Decrypt, null);
NewPushButtonData<UseFamilyPane>(commonToolsPanel, "族库浏览", Properties.Resources.FamilyLib, null);
NewPushButtonData<ChangeBackgroundColor>(commonToolsPanel, "切换背景色", Properties.Resources.Background, null);
RegisterDockPane(application);
return Result.Succeeded;
}
catch (Exception ex)
{
Log.WriteLog(ex.Message);
return Result.Failed;
}
}
/// <summary>
///创建按钮
/// </summary>
/// <typeparam name="T">命令类</typeparam>
/// <param name="panel">面板</param>
/// <param name="btnContent">按钮名</param>
/// <param name="bitmap">按钮图片</param>
/// <param name="availabilityClassName">控制可用性</param>
public PushButtonData NewPushButtonData<T>(RibbonPanel panel, string btnContent, Bitmap bitmap, string availabilityClassName)
{
string AddInPath = typeof(T).Assembly.Location;
PushButtonData btnData = new PushButtonData(btnContent, btnContent, AddInPath, typeof(T).FullName)
{
LargeImage = ConvertFromBitmap(bitmap),
Image = ConvertFromBitmap(bitmap),
};
var placeShelvesBtn = (PushButton)panel.AddItem(btnData);
if (availabilityClassName != null)
{
placeShelvesBtn.AvailabilityClassName = availabilityClassName;
}
return btnData;
}
private void RegisterDockPane(UIControlledApplication application)
{
Guid guid = new Guid("{028001AD-0588-4A9C-AA03-D7E472D85050}");
DockablePaneId id = new DockablePaneId(guid);
WpfFamilyDockablePane pane = new WpfFamilyDockablePane();
application.RegisterDockablePane(id, "族库", pane as IDockablePaneProvider);
}
}
}