using SuperMap.Mapping; using SuperMap.UI; using System; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; using WWPipeLine.MapBasic; using WWPipeLine.MapBasic.Conditions; namespace WWPipeLine.MapTools { /// /// 调节器 /// public class Conditioner { private static Conditioner m_Instance; //private DockPanel m_DockPanel = ComsStatic.DockPanel; //private DockPanel m_DockPanel; //public void SetDockPanelConditioner(DockPanel dp) //{ // m_DockPanel = dp; //} //private MapControl m_MapControl = ComsStatic.MapControl; //private MapControl m_MapControl; //public void SetMapControl(MapControl mapControl) //{ // m_MapControl = mapControl; //} private MapEx m_MapEx; public void SetMapEx(MapEx mapEx) { m_MapEx = mapEx; } public static Conditioner Instance { get { if (m_Instance == null) { m_Instance = new Conditioner(); } return m_Instance; } } //private IMessageInterface m_MessageInterface = ComsStatic.MessageInterface; //private IMessageInterface m_MessageInterface; //public IMessageInterface MessageInterface { get => m_MessageInterface; set => m_MessageInterface = value; } /// /// 检查该类型的窗体,是否已经处在打开状态 /// /// /// private Control OpenMapEx(Type type) { var fs = Application.OpenForms; foreach (Form form in fs) { if (form.GetType() == type) { return form; } var cs = form.Controls.Find(type.Name, true); if (cs != null && cs.Length > 0) return cs[0]; } foreach (Control c in this.m_MapEx.Controls) { if (c.GetType() == type) { return c; } } return null; } public void CreateCondition(string type) { if (ComsStatic.MapControl.Map.Layers.Count == 0) { Sunny.UI.UIMessageTip.ShowError("请先打开工作空间"); return; } var conditionFullName = "WWPipeLine.MapTools.Conditions." + type + ",WWPipeLine.MapTools"; var cond = Type.GetType(conditionFullName); if (cond == null) { Sunny.UI.UIMessageTip.ShowError("没有对当前按钮做相应的操作。"); return; } //"CreateCondition " + conditionFullName + "is Null。 var openedControl = OpenMapEx(cond); if (openedControl != null) { openedControl.Focus(); return; } ConditionPanel cp = (ConditionPanel)Activator.CreateInstance(cond); //cp.BaseConditions.Add("IMessageInterface", this.m_MessageInterface); //cp.BaseConditions.Add("DockPanelConditionPanel", this.m_DockPanel); //cp.BaseConditions.Add("MapControlConditionPanel", this.m_MapControl); //cp.CreateResultWindow(); //当点击功能菜单的RibbonButton按钮时,禁止创建结果窗体ResultWindow,为了后续的传值 //只有当点击条件窗体ConditionForm的OK按键的时候,才创建结果窗体ResultWindow string formText; if (string.IsNullOrEmpty(cp.ConditionPanelName)) { formText = "条件输入"; } else { formText = cp.ConditionPanelName; } foreach (Form form in Application.OpenForms) { if (form is ConditionForm && form.Text == formText) { form.Close(); break; } } m_MapEx.RemoveAllToolBar(); if (cp is BasicToolBar) { m_MapEx.AddToolBar(cp as BasicToolBar); return; } ConditionForm cf = new ConditionForm(cp) { Text = formText, //DockPanel = this.m_DockPanel, //MessageInterface = this.m_MessageInterface }; if (cp.ShowModal()) { cf.ShowDialog(Application.OpenForms[0]); return; } cf.Show(); } } }