FlyLayout.cs 7.02 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace MultiLayout
{
    /// <summary>
    /// 
    /// </summary>
    public class FlyLayout : INotifyPropertyChanged
    {
        public List<GageTabItem> GageTabItems { get; set; }


        private int dynareawidth = 250;
        /// <summary>
        /// 动态区宽度
        /// </summary>
        public int DynAreaWidth
        {
            get
            {
                return dynareawidth;
            }
            set
            {
                if (value < 100)
                    value = 100;
                if (dynareawidth != value)
                {
                    dynareawidth = value;
                }
            }
        }

        /// <summary>
        /// 动态区显示
        /// </summary>
        public bool IsDynAreaVisible { get; set; } = true;

        /// <summary>
        /// 隐藏 logo
        /// </summary>
        public bool IsLogoHidden { get; set; }


        #region 上一次界面状态

        public System.Drawing.Rectangle Rect { get; set; } = new System.Drawing.Rectangle(0, 0, 1024, 768);
        public WindowState WindowState { get; set; } = WindowState.Maximized;
        #endregion

        /// <summary>
        /// 基本路径,全部参数都应该放在这个文件夹内
        /// </summary>
        public const string BasePath = "layout";
        /// <summary>
        /// 
        /// </summary>
        public FlyLayout()
        {
        }

        /// <summary>
        /// 加载
        /// </summary>
        public void Load()
        {
            string path = System.IO.Path.Combine(BasePath, "graphcustom.json");
            if (!File.Exists(path))
                return;
            try
            {
                string json = File.ReadAllText(path);

                Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
            }
            catch 
            {

            }

            if (GageTabItems == null)
                GageTabItems = new List<GageTabItem>();
            foreach (var gageTabItem in GageTabItems)
            {
                if (gageTabItem.Components == null)
                {
                    gageTabItem.Components = new List<FlyComponent>();
                }

                if (gageTabItem.DynAreaItems == null) 
                {
                    gageTabItem.DynAreaItems = new List<int>();
                }

                if (gageTabItem.MenuItems == null)
                {
                    gageTabItem.MenuItems = new List<int>();
                }

                if (gageTabItem.Items == null)
                {
                    gageTabItem.Items = new List<GraphTabItem>();
                }

                foreach (var item in gageTabItem.Items) 
                {
                    if (item.Graphs == null)
                    {
                        item.Graphs = new List<GraphComponent>();
                    }
                }
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            try
            {
                if (!System.IO.Directory.Exists(BasePath))
                    System.IO.Directory.CreateDirectory(BasePath);

                string path = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustom.json");

                string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
                File.WriteAllText(path, json);
            }
            catch 
            {
            
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
    }
    
    /// <summary>
    /// 控件基类
    /// </summary>
    public class FlyComponent : INotifyPropertyChanged
    {
        /// <summary>
        /// 全局唯一ID
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// 模块的类名全称
        /// </summary>
        public string Module { get; set; }

        /// <summary>
        /// 容器名称
        /// </summary>
        public string ServiceContainerName { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public override string ToString()
        {
            return Module;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class GraphComponent : INotifyPropertyChanged
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int ID { get; set; }
        public System.Drawing.Rectangle Rect { get; set; } = new System.Drawing.Rectangle(0, 0, 1, 1);

        public event PropertyChangedEventHandler PropertyChanged;
    }

    /// <summary>
    /// 图表区 tabitem
    /// </summary>
    public class GraphTabItem:INotifyPropertyChanged
    {

        /// <summary>
        /// 图表
        /// </summary>
        public List<GraphComponent> Graphs { get; set; } = new List<GraphComponent>();
        /// <summary>
        /// 列数量
        /// </summary>
        public int ColumnCount { get; set; } = 1;
        /// <summary>
        /// 行数量
        /// </summary>
        public int RowCount { get; set; } = 3;
        /// <summary>
        /// 每行定义, 当为auto时,为true
        /// </summary>
        public List<bool> RowDefinitions { get; set; } = new List<bool>();
        /// <summary>
        /// 每列定义, 当为auto时,为true
        /// </summary>
        public List<bool> ColumnDefinitions { get; set; } = new List<bool>();

        /// <summary>
        /// 标题
        /// </summary>
        public string Header { get; set; } = "Test";

        public event PropertyChangedEventHandler PropertyChanged;
    }

    /// <summary>
    /// 设备页面
    /// </summary>
    public class GageTabItem:INotifyPropertyChanged
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 容器名称
        /// </summary>
        public string ServiceContainerName { get; set; }
        /// <summary>
        /// 设置目录 图标
        /// </summary>
        public List<int> MenuItems { get; set; } = new List<int>();
        /// <summary>
        /// 动态区 控件组
        /// </summary>
        public List<int> DynAreaItems { get; set; } = new List<int>();
        /// <summary>
        /// 图表区,tabitem
        /// </summary>
        public List<GraphTabItem> Items { get; set; } = new List<GraphTabItem>();

        /// <summary>
        /// 根据配置 最后生成的 TabControl
        /// </summary>
        [JsonIgnore]
        public TabControl TabControl;
        /// <summary>
        /// 全部组件
        /// </summary>
        public List<FlyComponent> Components { get; set; } = new List<FlyComponent>();

        public event PropertyChangedEventHandler PropertyChanged;
    }
}