144 lines
7.1 KiB
C#
144 lines
7.1 KiB
C#
using Autodesk.Revit.UI;
|
||
using RookieStation.CommonTools.ExecuteCmd;
|
||
using RookieStation.CommonTools.View;
|
||
using RookieStation.Finishes.ExecuteCmd;
|
||
using RookieStation.ParcelAreaModule.ExecuteCmd;
|
||
using RookieStation.ProjectConfig.ExecuteCmd;
|
||
using RookieStation.MailingAreaModule.ExecuteCmd;
|
||
using RookieStation.Statistics.ExecuteCmd;
|
||
using RookieStation.Utils;
|
||
using System;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Windows;
|
||
using System.Windows.Interop;
|
||
using System.Windows.Media.Imaging;
|
||
|
||
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 CommonTools = "通用工具";
|
||
|
||
//获取Ribbon类所在的通用类库目录
|
||
private static string AddInPath = typeof(RsApp).Assembly.Location;
|
||
|
||
//获取AddInPath的目录
|
||
private static string DirRequestAssembly = Path.GetDirectoryName(AddInPath);
|
||
|
||
private static string ViewPlanCmdEnabled = typeof(EnableCmdInViewPlan).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);
|
||
|
||
CreatePushButton<CmdProjectSettings>(projectPanel, "项目设置", Properties.Resources.cainiao, null);
|
||
//前台布置
|
||
RibbonPanel receptionAreaPanel = application.CreateRibbonPanel(TabName, ReceptionPanelName);
|
||
|
||
CreatePushButton<CmdPlaceReceptionArea>(receptionAreaPanel, "前台布置", Properties.Resources.Reception, ViewPlanCmdEnabled);
|
||
|
||
CreatePushButton<CmdPlaceReceptionArea>(receptionAreaPanel, "标识挤出", Properties.Resources.LogoExtrusion, ViewPlanCmdEnabled);
|
||
|
||
//出入口布置
|
||
RibbonPanel packAreaPanel = application.CreateRibbonPanel(TabName, EntranceAndExitGatePanelName);
|
||
CreatePushButton<CmdPlaceEntranceGate>(packAreaPanel, "入口布置", Properties.Resources.EntranceGate, ViewPlanCmdEnabled);
|
||
CreatePushButton<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];
|
||
//寄件区布置
|
||
CreatePushButton<CmdPlaceShelves>(packAreaPanel, "货架布置", Properties.Resources.Shelf, ViewPlanCmdEnabled);
|
||
|
||
CreatePushButton<CmdArrangeShelfCards>(packAreaPanel, "货架端牌", Properties.Resources.ShelfCard, ViewPlanCmdEnabled);
|
||
CreatePushButton<CmdPlaceLamps>(packAreaPanel, "灯具布置", Properties.Resources.Lamp, ViewPlanCmdEnabled);
|
||
|
||
//饰面,完成面
|
||
RibbonPanel finishesPanel = application.CreateRibbonPanel(TabName, FinishesPanelName);
|
||
CreatePushButton<CmdPlaceFloorFinishes>(finishesPanel, "板饰面", Properties.Resources.FloorFinishes, ViewPlanCmdEnabled);
|
||
CreatePushButton<CmdPlaceWallFinishes>(finishesPanel, "墙饰面", Properties.Resources.WallFinishes, ViewPlanCmdEnabled);
|
||
|
||
//统计面板
|
||
RibbonPanel statisticsPanel = application.CreateRibbonPanel(TabName, StatisticsPanelName);
|
||
CreatePushButton<CmdExportWorkSchedule>(statisticsPanel, "工程量导出", Properties.Resources.WorkSchedule, null);
|
||
|
||
//通用面板
|
||
RibbonPanel commonToolsPanel = application.CreateRibbonPanel(TabName, CommonTools);
|
||
CreatePushButton<CmdUseFamilyPane>(commonToolsPanel, "族库浏览", Properties.Resources.FamilyLib, 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="className">控制可用性</param>
|
||
public void CreatePushButton<T>(RibbonPanel panel, string btnContent, Bitmap bitmap, string className)
|
||
{
|
||
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 (className != null)
|
||
{
|
||
placeShelvesBtn.AvailabilityClassName = className;
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|
||
} |