Conditioner.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 (ComsStatic.MapControl.Map.Layers.Count == 0) { Sunny.UI.UIMessageTip.ShowError("请先打开工作空间"); return; }
  74. var conditionFullName = "WWPipeLine.MapTools.Conditions." + type + ",WWPipeLine.MapTools";
  75. var cond = Type.GetType(conditionFullName);
  76. if (cond == null) { Sunny.UI.UIMessageTip.ShowError("没有对当前按钮做相应的操作。"); return; }
  77. //"CreateCondition " + conditionFullName + "is Null。
  78. var openedControl = OpenMapEx(cond);
  79. if (openedControl != null)
  80. {
  81. openedControl.Focus(); return;
  82. }
  83. ConditionPanel cp = (ConditionPanel)Activator.CreateInstance(cond);
  84. //cp.BaseConditions.Add("IMessageInterface", this.m_MessageInterface);
  85. //cp.BaseConditions.Add("DockPanelConditionPanel", this.m_DockPanel);
  86. //cp.BaseConditions.Add("MapControlConditionPanel", this.m_MapControl);
  87. //cp.CreateResultWindow();
  88. //当点击功能菜单的RibbonButton按钮时,禁止创建结果窗体ResultWindow,为了后续的传值
  89. //只有当点击条件窗体ConditionForm的OK按键的时候,才创建结果窗体ResultWindow
  90. string formText;
  91. if (string.IsNullOrEmpty(cp.ConditionPanelName))
  92. {
  93. formText = "条件输入";
  94. }
  95. else
  96. {
  97. formText = cp.ConditionPanelName;
  98. }
  99. foreach (Form form in Application.OpenForms)
  100. {
  101. if (form is ConditionForm && form.Text == formText)
  102. {
  103. form.Close(); break;
  104. }
  105. }
  106. m_MapEx.RemoveAllToolBar();
  107. if (cp is BasicToolBar)
  108. {
  109. m_MapEx.AddToolBar(cp as BasicToolBar); return;
  110. }
  111. ConditionForm cf = new ConditionForm(cp)
  112. {
  113. Text = formText,
  114. //DockPanel = this.m_DockPanel,
  115. //MessageInterface = this.m_MessageInterface
  116. };
  117. if (cp.ShowModal())
  118. {
  119. cf.ShowDialog(Application.OpenForms[0]); return;
  120. }
  121. cf.Show();
  122. }
  123. }
  124. }