using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;

namespace uBIM_EarthTools
{
    class Ribbon : Autodesk.Revit.UI.IExternalApplication
    {
        static string AddInPath = typeof(Ribbon).Assembly.Location;
        public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
        {
            CreateRibbonSamplePanel(application);
            return Result.Succeeded;
        }

        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }

        private void CreateRibbonSamplePanel(UIControlledApplication application)
        {
            application.CreateRibbonTab("uBIM三维地质");
            RibbonPanel sPanel = application.CreateRibbonPanel("uBIM三维地质", "uBIM三维地质");
            PushButtonData ToggleBackground_ButtonData = new PushButtonData("数据导出", "数据导出", AddInPath, "uBIM_EarthTools.DwgDataExport");
            ToggleBackground_ButtonData.Image = Icon(Properties.Resources.contract);
            ToggleBackground_ButtonData.LargeImage = Icon(Properties.Resources.contract);
            sPanel.AddItem(ToggleBackground_ButtonData);

            PushButtonData ReLoadLink_ButtonData = new PushButtonData("模型生成", "模型生成", AddInPath, "uBIM_EarthTools.GeologyModel");
            ReLoadLink_ButtonData.Image = Icon(Properties.Resources.pyramid);
            ReLoadLink_ButtonData.LargeImage = Icon(Properties.Resources.pyramid);
            sPanel.AddItem(ReLoadLink_ButtonData);
            
        }

        private BitmapSource Icon(System.Drawing.Bitmap bitmap)
        {
            BitmapSource bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    bitmap.GetHbitmap(),
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());
            return bitSrc;
        }
    }
}
