using Autodesk.Revit.UI; using Nice3point.Revit.Toolkit.External; using GeologyToolkit.Properties; using static System.Net.Mime.MediaTypeNames; using System.Drawing; using System.Windows.Interop; using System.Windows.Media.Imaging; using System.Windows; using System; namespace GeologyToolkit; internal class UIRibbon : ExternalApplication { private static readonly string AddInPath = typeof(UIRibbon).Assembly.Location; public static BitmapSource ToBitmapSource(Bitmap bitmap) { if (bitmap == null) { return null; } return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } public override void OnStartup() { //UiApplication.CreateRibbonTab("地质工具"); var ribbonPanel = AddPanel(Application, "地质工具"); //var ribbonPanel = UiApplication.CreateRibbonPanel("地质工具", "地层"); var addPoint = new PushButtonData(typeof(AddPointCmd).FullName, "添加点", AddInPath, typeof(AddPointCmd).FullName) { LargeImage = ToBitmapSource(Resources.AddPoint_32px), Image = ToBitmapSource(Resources.AddPoint_16px), ToolTip = "选择地层表面及其经过钻孔土层,将在地层表面添加钻孔土层底部点", }; var removePoint = new PushButtonData(typeof(RemovePointCmd).FullName, "移除点", AddInPath, typeof(RemovePointCmd).FullName) { LargeImage = ToBitmapSource(Resources.RemovePoint_32px), Image = ToBitmapSource(Resources.RemovePoint_16px), ToolTip = "选择地层表面及其经过底部的钻孔土层,将移除在地层表面的该钻孔土层点", }; var movePoint = new PushButtonData(typeof(MovePointCmd).FullName, "移动点", AddInPath, typeof(MovePointCmd).FullName) { LargeImage = ToBitmapSource(Resources.MovePoint_32px), Image = ToBitmapSource(Resources.MovePoint_16px), ToolTip = "选择地层表面,选择其经过底部的钻孔土层,选择要移动到的土层,移动地层表面点", }; var CreateBorehole = new PushButtonData(typeof(CreateBoreholeCmd).FullName, "创建钻孔", AddInPath, typeof(CreateBoreholeCmd).FullName) { LargeImage = ToBitmapSource(Resources.Borehole_32px), Image = ToBitmapSource(Resources.Borehole_16px), ToolTip = "根据理正导出的mdb数据文件创建钻孔", }; //var createGeology = new PushButtonData(typeof(GenerateGeologyCmd).FullName, "生成地质体", AddInPath, typeof(GenerateGeologyCmd).FullName) //{ // LargeImage = ToBitmapSource(Resources.Geology_32px), // Image = ToBitmapSource(Resources.Geology_16px), // ToolTip = "选择地层表面生成地质体", //}; ribbonPanel.AddItem(CreateBorehole); ribbonPanel.AddItem(addPoint); ribbonPanel.AddItem(removePoint); ribbonPanel.AddItem(movePoint); //ribbonPanel.AddItem(createGeology); } /// /// 使用默认附加模块面板标签页 /// /// /// 面板名称 /// public static RibbonPanel AddPanel(UIControlledApplication application, string panelName) { var ribbonPanel = application.GetRibbonPanels(Tab.AddIns).Find(panel => panel.Name.Equals(panelName)); return ribbonPanel ?? application.CreateRibbonPanel(panelName); } }