修改命名空间
This commit is contained in:
149
ShrlAlgoToolkit.RevitCore/Assists/UIAssist.cs
Normal file
149
ShrlAlgoToolkit.RevitCore/Assists/UIAssist.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
|
||||
|
||||
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
using adWin = Autodesk.Windows;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitCore.Assists
|
||||
{
|
||||
public class UIAssist
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建ToggleButton
|
||||
/// </summary>
|
||||
/// <param name="showText"></param>
|
||||
/// <param name="largeImage"></param>
|
||||
/// <param name="toolTip"></param>
|
||||
/// <returns></returns>
|
||||
public static adWin.RibbonToggleButton NewAwToggleButton(string showText, Bitmap largeImage, string toolTip = null)
|
||||
{
|
||||
return new adWin.RibbonToggleButton()
|
||||
{
|
||||
LargeImage = ToBitmapSource(largeImage),
|
||||
Size = adWin.RibbonItemSize.Large,
|
||||
ToolTip = toolTip ?? showText,
|
||||
ShowText = true,
|
||||
Id = $"ID_{showText}",
|
||||
Name = $"Tog_{showText}",
|
||||
Text = showText,
|
||||
IsCheckable = true,
|
||||
Orientation = System.Windows.Controls.Orientation.Vertical,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// 位图转像素集
|
||||
/// </summary>
|
||||
/// <param name="bitmap"></param>
|
||||
/// <returns></returns>
|
||||
private static BitmapSource ToBitmapSource(Bitmap bitmap)
|
||||
{
|
||||
return bitmap == null
|
||||
? null
|
||||
: Imaging.CreateBitmapSourceFromHBitmap(
|
||||
bitmap.GetHbitmap(),
|
||||
IntPtr.Zero,
|
||||
Int32Rect.Empty,
|
||||
BitmapSizeOptions.FromEmptyOptions());
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建按钮
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="showText"></param>
|
||||
/// <param name="largeImage"></param>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="command">RelayCommand</param>
|
||||
/// <param name="parameter">命令的参数</param>
|
||||
/// <param name="toolTip"></param>
|
||||
/// <returns></returns>
|
||||
public static adWin.RibbonButton NewAwButton(string showText, Bitmap largeImage, Bitmap image, ICommand command, object parameter, string toolTip = default)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Image = ToBitmapSource(image),
|
||||
LargeImage = ToBitmapSource(largeImage),
|
||||
Size = adWin.RibbonItemSize.Standard,
|
||||
ShowText = true,
|
||||
Id = $"ID_{showText}",
|
||||
Name = $"Btn_{showText}",
|
||||
ToolTip = toolTip ?? showText,
|
||||
Text = showText,
|
||||
IsCheckable = true,
|
||||
CommandHandler = command,
|
||||
CommandParameter = parameter,
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
}
|
||||
private static readonly string AddInPath = Assembly.GetExecutingAssembly().Location;
|
||||
|
||||
#region 静态方法
|
||||
/// <summary>
|
||||
/// 新建命令按钮
|
||||
/// </summary>
|
||||
/// <typeparam name="Command"></typeparam>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="largeImage"></param>
|
||||
/// <param name="toolTip"></param>
|
||||
/// <param name="longDescription"></param>
|
||||
/// <returns></returns>
|
||||
public static PushButtonData NewPushButtonData<Command>(
|
||||
string text,
|
||||
Bitmap largeImage = null,
|
||||
Bitmap image = null,
|
||||
string toolTip = null,
|
||||
string longDescription = null
|
||||
)
|
||||
where Command : class, IExternalCommand
|
||||
{
|
||||
return new(typeof(Command).FullName, text, AddInPath, typeof(Command).FullName)
|
||||
{
|
||||
LargeImage = ToBitmapSource(largeImage),
|
||||
Image = ToBitmapSource(image),
|
||||
ToolTip = toolTip ?? text,
|
||||
LongDescription = longDescription
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新建可控的命令按钮
|
||||
/// </summary>
|
||||
/// <typeparam name="Command"></typeparam>
|
||||
/// <typeparam name="Availablility"></typeparam>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="bitmap"></param>
|
||||
/// <param name="largeBitmap"></param>
|
||||
/// <param name="toolTip"></param>
|
||||
/// <param name="longDescription"></param>
|
||||
/// <returns></returns>
|
||||
public static PushButtonData NewButtonData<Command, Availablility>(
|
||||
string text,
|
||||
Bitmap largeBitmap = null,
|
||||
Bitmap bitmap = null,
|
||||
string toolTip = null,
|
||||
string longDescription = null
|
||||
)
|
||||
where Command : class, IExternalCommand
|
||||
where Availablility : class, IExternalCommandAvailability
|
||||
{
|
||||
return new(typeof(Command).FullName, text, AddInPath, typeof(Command).FullName)
|
||||
{
|
||||
LargeImage = ToBitmapSource(largeBitmap),
|
||||
Image = ToBitmapSource(bitmap),
|
||||
ToolTip = toolTip ?? text,
|
||||
LongDescription = longDescription,
|
||||
AvailabilityClassName = typeof(Availablility).FullName
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user