123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- /* ==============================================================================
- * 功能描述:加载Menu下的配置文件,转化为TszTabData
- * 创 建 者:Garrett
- * 创建日期:2018/9/17 17:56:32
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Others;
- using SAGA.RevitUtils;
- namespace SAGA.RevitMenu.Configuration
- {
- /// <summary>
- /// MenuData
- /// </summary>
- class XmlMenuData
- {
- /// <summary>
- /// 根据选择的项目 确定加载的菜单 建筑 结构 水暖电
- /// </summary>
- /// <param name="strRevitVersion"></param>
- /// <param name="blnRevit"></param>
- /// <returns></returns>
- public static TszTabData[] GetConfigTabs(string strRevitVersion, out bool blnRevit)
- {
- blnRevit = false;
- List<string> listFea = new List<string>();
- FileInfo[] files = new DirectoryInfo(Path.Combine(AppBaseInfo.AppRunPath, "Menu")).GetFiles("*.xml");
- if (files.Length == 0)
- {
- MessageShowBase.Infomation(@"菜单加载异常,请查看安装目录DLL\OperateLogs下的操作日志。");
- return null;
- }
- Dictionary<int, string> dictionary = new Dictionary<int, string>();
- #region 读取所有的文件,对所有的模块进行排序
- foreach (FileInfo info3 in files)
- {
- try
- {
- FileInfo info4 = info3;
- XmlDocument document = new XmlDocument();
- document.Load(info4.FullName);
- XmlElement xelem = document.DocumentElement;
- if (xelem == null) continue;
- int key = xelem.SelectSingleNode("App").SelectSingleNode("AppIndex").InnerText.Trim().ToInt();
- if (!dictionary.ContainsKey(key))
- {
- dictionary.Add(key, info4.FullName);
- }
- }
- catch (Exception exception)
- {
- MessageShow.Show(exception, false, "");
- }
- }
- #endregion
- List<TszTabData> list2 = new List<TszTabData>();
- List<int> pushButtonList = dictionary.Keys.ToList<int>();
- pushButtonList.Sort();
- foreach (int num2 in pushButtonList)
- {
- TszTabData[] collection = GetConfigTabs(strRevitVersion, listFea, dictionary[num2]);
- if ((collection != null) && (collection.Length > 0))
- {
- list2.AddRange(collection);
- }
- }
- return list2.ToArray();
- }
- /// <summary>
- /// 从菜单配置文件中读取数据,转化为为TszTabData
- /// Tab-Panels-Buttons
- /// </summary>
- /// <param name="strRevitVersion"></param>
- /// <param name="listFea"></param>
- /// <param name="fileName"></param>
- /// <returns></returns>
- public static TszTabData[] GetConfigTabs(string strRevitVersion, List<string> listFea, string fileName)
- {
- try
- {
- string str = Path.Combine(AppBaseInfo.AppRunPath, "RibbonImage");
- XmlDocument document = new XmlDocument();
- document.Load(fileName);
- XmlElement documentElement = document.DocumentElement;
- List<TszPanelData> list = new List<TszPanelData>();
- #region 获取所有的命令
- foreach (XmlNode node in documentElement.SelectNodes("Panel"))
- {
- string strPanelName = node.Attributes["PanelName"].Value.Trim();
- bool boolGroupFlag = bool.Parse(node.Attributes["GroupFlag"].Value.Trim());
- string str3 = node.Attributes["GroupImage"].Value.Trim();
- string strBtnsTyle = node.Attributes["ButtonStyles"].Value.Trim();
- string str5 = "Normal";
- string strRevitVer = node.Attributes["RevitVer"].Value.Trim();
- RevitVer revitVer = GetRevitVer(strRevitVer);
- ButtonStyles buttonStyle = GetButtonStyle(strBtnsTyle);
- StackStyles stackStyle = GetStackStyle(str5);
- if (str3.Length <= 0)
- {
- str3 = Path.Combine(str, "LargeImage.png");
- }
- else
- {
- str3 = Path.Combine(str, str3);
- }
- TszPanelData penelData = new TszPanelData(strPanelName, boolGroupFlag, str3, buttonStyle);
- #region 命令是否可见
- XmlAttribute attribute = node.Attributes["Visible"];
- if (attribute != null)
- {
- penelData.Visible = attribute.Value.Trim().ToBool();
- }
- #endregion
- XmlNodeList pushButtonList = node.SelectNodes("Button");
- List<TszButtonData> list4 = new List<TszButtonData>();
- foreach (XmlNode node2 in pushButtonList)
- {
- ButtonStyles styles3 = buttonStyle;
- StackStyles styles4 = stackStyle;
- RevitVer ver2 = revitVer;
- XmlAttribute attribute3 = node2.Attributes["ButtonStyles"];
- if (attribute3 != null)
- {
- styles3 = GetButtonStyle(attribute3.Value.Trim());
- }
- XmlAttribute attribute4 = node2.Attributes["StackStyles"];
- if (attribute4 != null)
- {
- styles4 = GetStackStyle(attribute4.Value.Trim());
- }
- XmlAttribute attribute5 = node2.Attributes["RevitVer"];
- if (attribute5 != null)
- {
- ver2 = GetRevitVer(attribute5.Value.Trim());
- }
- #region 调试的命令不添加
- var debugAttri = node2.Attributes["IsDebug"];
- if (debugAttri != null)
- {
- if (debugAttri.Value.ToBool())
- continue;
- }
- #endregion
- string menuTab = node2.SelectSingleNode("MenuTab").InnerText.Trim();
- string[] strArray = node2.SelectSingleNode("Modules").InnerText.Trim().Split(new char[] { ',' });
- TszButtonData data2 = null;
- if (node2.ChildNodes.Count > 6)
- {
- string strButtonName = node2.SelectSingleNode("ButtonName").InnerText.Trim();
- string strButtonText = node2.SelectSingleNode("ButtonText").InnerText.Trim();
- string str14 = node2.SelectSingleNode("ImageName").InnerText.Trim();
- str14 = Path.Combine(str, str14);
- string path = node2.SelectSingleNode("DllName").InnerText.Trim();
- //..\OutputDll\SpacePlugin.dll
- string strAssemblyName = Path.Combine(AppBaseInfo.AppRunPath, Path.GetFileName(path));
- string addStr = @"..\";
- if (path.Contains(addStr))
- {
- path = path.Replace(addStr, "");
- strAssemblyName = Path.Combine(AppBaseInfo.AppRunPath, path);
- }
- string strClassName = node2.SelectSingleNode("ClassName").InnerText.Trim();
- string str18 = node2.SelectSingleNode("ToolTip").InnerText.Trim();
- string str19 = node2.SelectSingleNode("LongDescription").InnerText.Trim();
- data2 = new TszButtonData(penelData, menuTab, strButtonName, strButtonText, str14,
- strAssemblyName, strClassName)
- {
- ToolTip = str18,
- LongDescription = str19
- };
- }
- else if (node2.ChildNodes.Count > 3)
- {
- string str20 = node2.SelectSingleNode("ButtonText").InnerText.Trim();
- string str21 = node2.SelectSingleNode("ImageName").InnerText.Trim();
- string str23 = node2.SelectSingleNode("ToolTip").InnerText.Trim();
- str21 = Path.Combine(str, str21);
- data2 = new TszButtonData(menuTab)
- {
- TszPanelData = penelData,
- ToolTip = str23,
- ButtonText = str20,
- ImageName = str21
- };
- }
- else
- {
- data2 = new TszButtonData(menuTab);
- }
- XmlAttribute btnVisibleAttri = node2.Attributes["Visible"];
- if (btnVisibleAttri != null)
- {
- data2.Visible = btnVisibleAttri.Value.Trim().ToBool();
- }
- data2.Styles = styles3;
- data2.StackStyle = styles4;
- data2.UseVersion = ver2;
- list4.Add(data2);
- }
- if (list4.Any())
- {
- penelData.Buttons.AddRange(list4);
- list.Add(penelData);
- }
- }
- #endregion
- List<TszTabData> list6 = new List<TszTabData>();
- #region 对命令进行重新分组
- XmlNodeList list5 = documentElement.SelectNodes("Tab");
- foreach (XmlNode node3 in list5)
- {
- string strTabName = node3.Attributes["TabName"].Value.Trim();
- string str25 = node3.SelectSingleNode("MenuTab").InnerText.Trim();
- string[] strArray2 = node3.SelectSingleNode("Modules").InnerText.Trim().Split(new char[] { ',' });
- List<TszPanelData> list7 = new List<TszPanelData>();
- foreach (TszPanelData data5 in list)
- {
- TszButtonData[] collection = data5.FilterButtons(str25);
- if ((collection != null) && (collection.Length > 0))
- {
- TszPanelData data6 =
- new TszPanelData(data5.PanelName, data5.GroupFlag, data5.GroupImage, data5.Styles)
- {
- Visible = data5.Visible
- };
- data6.Buttons.AddRange(collection);
- list7.Add(data6);
- }
- }
- TszTabData item = new TszTabData(strTabName)
- {
- TabText = str25,
- Modules = strArray2
- };
- if (list7.Any())
- {
- item.Panels.AddRange(list7);
- list6.Add(item);
- }
- }
- #endregion
- return list6.ToArray();
- }
- catch (Exception exception)
- {
- MessageShow.Show(exception, false, "");
- return null;
- }
- }
- /// <summary>
- /// 根据配置文件设置 获取Botton样式
- /// </summary>
- /// <param name="strBtnsTyle"></param>
- /// <returns></returns>
- public static ButtonStyles GetButtonStyle(string strBtnsTyle)
- {
- if (strBtnsTyle == null)
- return ButtonStyles.Pushdown;
- string str = strBtnsTyle.ToLower();
- if (str == "separator")
- {
- return ButtonStyles.Separator;
- }
- if (str == "large")
- {
- return ButtonStyles.Large;
- }
- if (str == "pushdown")
- {
- return ButtonStyles.Pushdown;
- }
- if (str == "stacked")
- {
- return ButtonStyles.Stacked;
- }
- if (str != "stackedbox")
- {
- return ButtonStyles.StackedBox;
- }
- return ButtonStyles.Pushdown;
- }
- /// <summary>
- /// 获取有哪些版本的命令可用 R14,R15,R16,R17,R18
- /// </summary>
- /// <param name="strRevitVer"></param>
- /// <returns></returns>
- public static RevitVer GetRevitVer(string strRevitVer)
- {
- RevitVer unkonw = RevitVer.Unkonw;
- if (strRevitVer.ToUpper().IndexOf("R14", StringComparison.Ordinal) > -1)
- {
- unkonw |= RevitVer.R14;
- }
- if (strRevitVer.ToUpper().IndexOf("R15", StringComparison.Ordinal) > -1)
- {
- unkonw |= RevitVer.R15;
- }
- if (strRevitVer.ToUpper().IndexOf("R16", StringComparison.Ordinal) > -1)
- {
- unkonw |= RevitVer.R16;
- }
- if (strRevitVer.ToUpper().IndexOf("R17", StringComparison.Ordinal) > -1)
- {
- unkonw |= RevitVer.R17;
- }
- return unkonw;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="strBtnsTyle"></param>
- /// <returns></returns>
- public static StackStyles GetStackStyle(string strBtnsTyle)
- {
- StackStyles normal = StackStyles.Normal;
- if (strBtnsTyle == null) return normal;
- string str = strBtnsTyle.ToLower();
- if (str == "pulldown")
- {
- normal = StackStyles.Pulldown;
- }
- if (str == "normal")
- {
- normal = StackStyles.Normal;
- }
- return normal;
- }
- }
- }
|