cloudflight
2023-12-20 ac3e88e5dc69c74c80045a86abe38caae81d0101
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace CloudWaterNetwork
{
 
    public static class Global
    {
        public static PropertyForm PropertyForm;
        public static MapViewer map;
        public static Templates Templates;
 
 
        public static List<MapObjectRecord> mapObjectRecords = new List<MapObjectRecord>();
        public static int RecordIndex=0;
    }
 
    public class MapOption
    {
        public float Link_multiply { get; set; } = 0.6667f;
        public float junction_multiply { get; set; } = 1f;
        public bool _ShowValve { get; set; } = true;
        public bool _ShowJunction { get; set; } = true;
    }
    //public class AutoBuildParams
    //{
    //    public int MaxLevel;
    //    public int FloorHeigh;
    //}
    public enum MapObjectType
    {
        ALL,
        Junction,
        Reservoir,
        Tank,
        Pipe,
        Valve,
        Repeater,
        
    }
    public static class GlobalExtension
    {
        public static Type GetObjType(this MapObjectType type)
        {
            switch (type)
            {
                case MapObjectType.ALL: return null;
                case MapObjectType.Junction:return typeof(Junction);
                case MapObjectType.Reservoir: return typeof(Reservoir);
                case MapObjectType.Tank: return typeof(Tank);
                case MapObjectType.Pipe: return typeof(Pipe);          
                case MapObjectType.Valve: return typeof(Valve);
                case MapObjectType.Repeater: return typeof(Repeater);
 
                default: return null;
            }
 
        }
       
    }
    public class MapObjectRecord
    {
        public MapObject mapObject { get; set; }
        public string ValueName { get; set; }
 
        public dynamic Value { get; set; }
 
    }
    public class Parts
    {
        List<string> _parts = null;
 
        public int Length
        {
            get
            {
                if (_parts != null)
                    return _parts.Count;
                else
                    return -1;
            }
        }
 
        public int Count
        {
            get
            {
                if (_parts != null)
                    return _parts.Count;
                else
                    return -1;
            }
        }
        public Parts(string[] strings)
        {
            _parts = strings.ToList();
        }
        public string this[int index]
        {
            get
            {
                if (_parts != null && _parts.Count > index)
                    return _parts[index];
                else
                    return null;
            }
            set
            {
                _parts[index] = value;
            }
        }
    }
 
    public class message
    {
        public static bool show(string caption, string content, MessageBoxButtons boxButtons = MessageBoxButtons.OKCancel)
        {
            var result = MessageBox.Show(content, caption, boxButtons, MessageBoxIcon.Information);
            if (result == DialogResult.OK || result == DialogResult.Yes)
                return true;
            else
                return false;
        }
    }
    public class Default
    {
        static string _filePath =Path.Combine( Directory.GetCurrentDirectory() ,@"default.ini");
        //public static string JunctionPre = "J";
        //public static string ReservoirPre = "R";
        //public static string TankPre = "T";
        //public static string PipePre = "P";
        //public static string ValvePre = "V";
        //public static string MeterPre = "M";
        //public static string RepeaterPre = "Repeater";
        public Node junction;
        public Reservoir reservoir;
        public Tank tank;
        public Meter meter;
        public Link pipe;
        public Valve valve;
        public Repeater repeater;
        public static Default GetfaultINI()
        {
            StreamReader sr = new StreamReader(_filePath);
            string json = sr.ReadToEnd();
            sr.Close();
            return JsonConvert.DeserializeObject<Default>(json);
 
        }
        public void SaveFile()
        {
            StreamWriter sw = new StreamWriter(_filePath);
            sw.WriteLine(JsonConvert.SerializeObject(this));
            sw.Close();
        }
 
        public static Dictionary<string, string> PreName = new Dictionary<string, string>()
        {
            {"Junction","J" },
            {"Reservoir","R" },
            {"Tank","T" },
            {"Meter","M" },
            {"Pipe","P" },
            {"Valve","V" },
            {"Repeater","Rp" },
        };
        public static  string GetPreString(MapObject obj)
        {
            return PreName[obj.GetTypeString()];
        }
    }
 
    public enum MouseState
    {
        无,
        新增节点,
        新建水库,
        新建水池,
        新增管线,
        新建阀门,
        新建水表,
        新建重复器,
 
 
    }
}