/*-------------------------------------------------------------------------
* 功能描述:ButtonAttribute
* 作者:xulisong
* 创建时间: 2019/7/25 11:30:56
* 版本号:v1.0
* -------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace FWindSoft.Revit.Menu
{
[AttributeUsage(AttributeTargets.Class)]
public class ButtonAttribute:Attribute
{
public ButtonAttribute()
{
//此处获取到的程序集为mscorlib,不太合适
//var assemblyName= Assembly.GetCallingAssembly().GetName().Name;
this.TabName = "自定义";
this.PanelName = "自定义";
}
///
/// 菜单顺序
///
public int Index { get; set; }
private string m_TabName;
private string m_TabText;
///
/// tab名称
///
public string TabName
{
get { return GetResult(m_TabName, m_TabText); }
set
{
m_TabName = value;
}
}
///
/// tab显示
///
public string TabText
{
get { return GetResult(m_TabText, m_TabName); }
set
{
m_TabText = value;
}
}
private string m_PanelName;
private string m_PanelText;
///
/// panel名称
///
public string PanelName
{
get { return GetResult(m_PanelName, m_PanelText); }
set
{
m_PanelName = value;
}
}
///
/// panel显示
///
public string PanelText
{
get { return GetResult(m_PanelText, m_PanelName); }
set
{
m_PanelText = value;
}
}
private string m_ButtonName;
private string m_ButtonText;
///
/// button名称
///
public string ButtonName
{
get { return GetResult(m_ButtonName, m_ButtonText); }
set
{
m_ButtonName = value;
}
}
///
/// button显示
///
public string ButtonText
{
get { return GetResult(m_ButtonText, m_ButtonName); }
set
{
m_ButtonText = value;
}
}
public string ImageName { get; set; }
public string Description { get; set; }
public string LongDescription { get; set; }
public RevitButtonStyle ButtonStyle { get; set; }
public string GroupName { get; set; }
public bool IsStack { get; set; }
private T GetResult(T useResult, T spareResult) where T : class
{
return useResult ?? spareResult;
}
///
/// 生成tab
///
///
public RevitTab GetTab()
{
RevitTab tab = new RevitTab();
tab.Text = this.TabText;
tab.Name = this.TabName;
return tab;
}
///
/// 生成Panel
///
///
public RevitPanel GetPanel()
{
RevitPanel panel = new RevitPanel();
panel.Text = this.PanelText;
panel.Name = this.PanelName;
panel.TabName = this.TabName;
return panel;
}
///
/// 生成Button
///
///
public RevitButton GetButton()
{
RevitButton button = new RevitButton();
button.Text = this.ButtonText;
button.Name = this.ButtonName;
button.PanelName = this.PanelName;
button.IsStack = this.IsStack;
button.GroupName = this.GroupName;
button.ButtonStyle = this.ButtonStyle;
button.Description = this.Description;
button.LongDescription = this.LongDescription;
button.ImageName = this.ImageName;
return button;
}
}
}