Conditioner.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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;
  17. public void SetDockPanelConditioner(DockPanel dp)
  18. {
  19. m_DockPanel = dp;
  20. }
  21. private MapControl m_MapControl;
  22. public void SetMapControl(MapControl mapControl)
  23. {
  24. m_MapControl = mapControl;
  25. }
  26. private MapEx m_MapEx;
  27. public void SetMapEx(MapEx mapEx)
  28. {
  29. m_MapEx = mapEx;
  30. }
  31. public static Conditioner Instance
  32. {
  33. get
  34. {
  35. if (m_Instance == null)
  36. {
  37. m_Instance = new Conditioner();
  38. }
  39. return m_Instance;
  40. }
  41. }
  42. 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. {
  75. Sunny.UI.UIMessageTip.ShowError("请先打开管线工作空间", 5000);
  76. return;
  77. }
  78. var conditionFullName = "WWPipeLine.MapTools.Conditions." + type + ",WWPipeLine.MapTools";
  79. var cond = Type.GetType(conditionFullName);
  80. if (cond == null)
  81. {
  82. Sunny.UI.UIMessageTip.ShowError(conditionFullName + "is Null。没有对当前按钮做相应的操作。", 3000);
  83. return;
  84. }
  85. var openedControl = OpenMapEx(cond);
  86. if (openedControl != null)
  87. {
  88. openedControl.Focus();
  89. return;
  90. }
  91. ConditionPanel cp = (ConditionPanel)Activator.CreateInstance(cond);
  92. cp.BaseConditions.Add("IMessageInterface", this.m_MessageInterface);
  93. cp.BaseConditions.Add("DockPanelConditionPanel", this.m_DockPanel);
  94. cp.BaseConditions.Add("MapControlConditionPanel", this.m_MapControl);
  95. //cp.CreateResultWindow();
  96. //当点击功能菜单的RibbonButton按钮时,禁止创建结果窗体ResultWindow,为了后续的传值
  97. //只有当点击条件窗体ConditionForm的OK按键的时候,才创建结果窗体ResultWindow
  98. string formText;
  99. if (string.IsNullOrEmpty(cp.ConditionPanelName))
  100. {
  101. formText = "条件输入";
  102. }
  103. else
  104. {
  105. formText = cp.ConditionPanelName;
  106. }
  107. foreach (Form form in Application.OpenForms)
  108. {
  109. if (form is ConditionForm && form.Text == formText)
  110. {
  111. form.Close();
  112. break;
  113. }
  114. }
  115. if (cp is BasicToolBar)
  116. {
  117. m_MapEx.AddToolBar(cp as BasicToolBar);
  118. return;
  119. }
  120. else
  121. {
  122. m_MapEx.RemoveAllToolBar();
  123. }
  124. ConditionForm cf = new ConditionForm(cp)
  125. {
  126. Text = formText,
  127. DockPanel = this.m_DockPanel,
  128. MessageInterface = this.m_MessageInterface
  129. };
  130. if (cp.ShowModal())
  131. {
  132. cf.ShowDialog(System.Windows.Forms.Application.OpenForms[0]);
  133. }
  134. else
  135. {
  136. cf.Show();
  137. }
  138. }
  139. }
  140. }