ButtonAttribute.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ButtonAttribute
  3. * 作者:xulisong
  4. * 创建时间: 2019/7/25 11:30:56
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace FWindSoft.Revit.Menu
  14. {
  15. [AttributeUsage(AttributeTargets.Class)]
  16. public class ButtonAttribute:Attribute
  17. {
  18. public ButtonAttribute()
  19. {
  20. //此处获取到的程序集为mscorlib,不太合适
  21. //var assemblyName= Assembly.GetCallingAssembly().GetName().Name;
  22. this.TabName = "自定义";
  23. this.PanelName = "自定义";
  24. }
  25. /// <summary>
  26. /// 菜单顺序
  27. /// </summary>
  28. public int Index { get; set; }
  29. private string m_TabName;
  30. private string m_TabText;
  31. /// <summary>
  32. /// tab名称
  33. /// </summary>
  34. public string TabName
  35. {
  36. get { return GetResult(m_TabName, m_TabText); }
  37. set
  38. {
  39. m_TabName = value;
  40. }
  41. }
  42. /// <summary>
  43. /// tab显示
  44. /// </summary>
  45. public string TabText
  46. {
  47. get { return GetResult(m_TabText, m_TabName); }
  48. set
  49. {
  50. m_TabText = value;
  51. }
  52. }
  53. private string m_PanelName;
  54. private string m_PanelText;
  55. /// <summary>
  56. /// panel名称
  57. /// </summary>
  58. public string PanelName
  59. {
  60. get { return GetResult(m_PanelName, m_PanelText); }
  61. set
  62. {
  63. m_PanelName = value;
  64. }
  65. }
  66. /// <summary>
  67. /// panel显示
  68. /// </summary>
  69. public string PanelText
  70. {
  71. get { return GetResult(m_PanelText, m_PanelName); }
  72. set
  73. {
  74. m_PanelText = value;
  75. }
  76. }
  77. private string m_ButtonName;
  78. private string m_ButtonText;
  79. /// <summary>
  80. /// button名称
  81. /// </summary>
  82. public string ButtonName
  83. {
  84. get { return GetResult(m_ButtonName, m_ButtonText); }
  85. set
  86. {
  87. m_ButtonName = value;
  88. }
  89. }
  90. /// <summary>
  91. /// button显示
  92. /// </summary>
  93. public string ButtonText
  94. {
  95. get { return GetResult(m_ButtonText, m_ButtonName); }
  96. set
  97. {
  98. m_ButtonText = value;
  99. }
  100. }
  101. public string ImageName { get; set; }
  102. public string Description { get; set; }
  103. public string LongDescription { get; set; }
  104. public RevitButtonStyle ButtonStyle { get; set; }
  105. public string GroupName { get; set; }
  106. public bool IsStack { get; set; }
  107. private T GetResult<T>(T useResult, T spareResult) where T : class
  108. {
  109. return useResult ?? spareResult;
  110. }
  111. /// <summary>
  112. /// 生成tab
  113. /// </summary>
  114. /// <returns></returns>
  115. public RevitTab GetTab()
  116. {
  117. RevitTab tab = new RevitTab();
  118. tab.Text = this.TabText;
  119. tab.Name = this.TabName;
  120. return tab;
  121. }
  122. /// <summary>
  123. /// 生成Panel
  124. /// </summary>
  125. /// <returns></returns>
  126. public RevitPanel GetPanel()
  127. {
  128. RevitPanel panel = new RevitPanel();
  129. panel.Text = this.PanelText;
  130. panel.Name = this.PanelName;
  131. panel.TabName = this.TabName;
  132. return panel;
  133. }
  134. /// <summary>
  135. /// 生成Button
  136. /// </summary>
  137. /// <returns></returns>
  138. public RevitButton GetButton()
  139. {
  140. RevitButton button = new RevitButton();
  141. button.Text = this.ButtonText;
  142. button.Name = this.ButtonName;
  143. button.PanelName = this.PanelName;
  144. button.IsStack = this.IsStack;
  145. button.GroupName = this.GroupName;
  146. button.ButtonStyle = this.ButtonStyle;
  147. button.Description = this.Description;
  148. button.LongDescription = this.LongDescription;
  149. button.ImageName = this.ImageName;
  150. return button;
  151. }
  152. }
  153. }