Conditioner.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using SuperMap.Mapping;
  2. using SuperMap.UI;
  3. using System;
  4. using System.Windows.Forms;
  5. using WeifenLuo.WinFormsUI.Docking;
  6. using WWPipeLine.MapBasic;
  7. using WWPipeLine.MapBasic.Conditions;
  8. namespace WWPipeLine.MapTools
  9. {
  10. /// <summary>
  11. /// 调节器
  12. /// </summary>
  13. public class Conditioner
  14. {
  15. private static Conditioner m_Instance;
  16. //private DockPanel m_DockPanel = ComsStatic.DockPanel;
  17. //private DockPanel m_DockPanel;
  18. //public void SetDockPanelConditioner(DockPanel dp)
  19. //{
  20. // m_DockPanel = dp;
  21. //}
  22. //private MapControl m_MapControl = ComsStatic.MapControl;
  23. //private MapControl m_MapControl;
  24. //public void SetMapControl(MapControl mapControl)
  25. //{
  26. // m_MapControl = mapControl;
  27. //}
  28. private MapEx m_MapEx;
  29. public void SetMapEx(MapEx mapEx)
  30. {
  31. m_MapEx = mapEx;
  32. }
  33. public static Conditioner Instance
  34. {
  35. get
  36. {
  37. if (m_Instance == null) { m_Instance = new Conditioner(); }
  38. return m_Instance;
  39. }
  40. }
  41. private IMessageInterface m_MessageInterface = ComsStatic.MessageInterface;
  42. //private IMessageInterface m_MessageInterface;
  43. //public IMessageInterface MessageInterface { get => m_MessageInterface; set => m_MessageInterface = value; }
  44. /// <summary>
  45. /// 检查该类型的窗体,是否已经处在打开状态
  46. /// </summary>
  47. /// <param name="type"></param>
  48. /// <returns></returns>
  49. private Control OpenMapEx(Type type)
  50. {
  51. var fs = Application.OpenForms;
  52. foreach (Form form in fs)
  53. {
  54. if (form.GetType() == type)
  55. {
  56. return form;
  57. }
  58. var cs = form.Controls.Find(type.Name, true);
  59. if (cs != null && cs.Length > 0)
  60. return cs[0];
  61. }
  62. foreach (Control c in this.m_MapEx.Controls)
  63. {
  64. if (c.GetType() == type)
  65. {
  66. return c;
  67. }
  68. }
  69. return null;
  70. }
  71. public void CreateCondition(string type)
  72. {
  73. //if (m_MapControl.Map.Layers.Count == 0)
  74. if (ComsStatic.MapControl.Map.Layers.Count == 0)
  75. {
  76. Sunny.UI.UIMessageTip.ShowError("请先打开管线工作空间"); return;
  77. }
  78. var conditionFullName = "WWPipeLine.MapTools.Conditions." + type + ",WWPipeLine.MapTools";
  79. var cond = Type.GetType(conditionFullName);
  80. if (cond == null)
  81. {
  82. string msg = "CreateCondition " + conditionFullName + "is Null。没有对当前按钮做相应的操作。";
  83. Commons.LogHelper.Error(msg); Sunny.UI.UIMessageTip.ShowError(msg); return;
  84. }
  85. var openedControl = OpenMapEx(cond);
  86. if (openedControl != null)
  87. {
  88. openedControl.Focus(); return;
  89. }
  90. ConditionPanel cp = (ConditionPanel)Activator.CreateInstance(cond);
  91. //cp.BaseConditions.Add("IMessageInterface", this.m_MessageInterface);
  92. //cp.BaseConditions.Add("DockPanelConditionPanel", this.m_DockPanel);
  93. //cp.BaseConditions.Add("MapControlConditionPanel", this.m_MapControl);
  94. //cp.CreateResultWindow();
  95. //当点击功能菜单的RibbonButton按钮时,禁止创建结果窗体ResultWindow,为了后续的传值
  96. //只有当点击条件窗体ConditionForm的OK按键的时候,才创建结果窗体ResultWindow
  97. string formText;
  98. if (string.IsNullOrEmpty(cp.ConditionPanelName))
  99. {
  100. formText = "条件输入";
  101. }
  102. else
  103. {
  104. formText = cp.ConditionPanelName;
  105. }
  106. foreach (Form form in Application.OpenForms)
  107. {
  108. if (form is ConditionForm && (form.Text == formText || form.Width == 0 || form.Height == 0))
  109. {
  110. form.Close(); break;
  111. }
  112. }
  113. m_MapEx.RemoveAllToolBar();
  114. if (cp is BasicToolBar)
  115. {
  116. m_MapEx.AddToolBar(cp as BasicToolBar); return;
  117. }
  118. ConditionForm cf = new ConditionForm(cp)
  119. {
  120. Text = formText,
  121. //DockPanel = this.m_DockPanel,
  122. //MessageInterface = this.m_MessageInterface
  123. };
  124. if (cp.ShowModal())
  125. {
  126. cf.ShowDialog(Application.OpenForms[0]);
  127. }
  128. else
  129. {
  130. cf.Show();
  131. }
  132. }
  133. }
  134. }