qinjie
2023-12-02 c2fa168aff53d879f72412c94baa7be4998dae5e
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
using Hydro.MapView;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Hydro.MapView.MapViewEnum;
 
namespace Hydro.MapView.Common
{
 
    public static class Global
    {
 
        //public static TemplateList TemplateList;
 
 
        public static List<MapObjectRecord> mapObjectRecords = new List<MapObjectRecord>();
        public static int RecordIndex = 0;
        public static List<string> curveStrings = new List<string>() { "流量扬程曲线", "流量功率曲线", "流量效率曲线" };
        public static void ClearFileReadOnly(string filePath)
        {
            if (File.Exists(filePath))
            {
                // 获取当前文件属性
                FileAttributes attributes = File.GetAttributes(filePath);
 
                // 如果文件被设置为只读,则移除只读属性
                if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    attributes &= ~FileAttributes.ReadOnly; // 移除只读标志
 
                    // 设置新的文件属性
                    File.SetAttributes(filePath, attributes);
 
 
                }
 
            }
        }
    }
    public static class PointFExtansion
    {
        public static Point ToPoint(this PointF p)
        {
            return new Point((int)p.X, (int)p.Y);
        }
    }
    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 static class GlobalExtension
    {
        public static Type GetObjType(this MapObjectType type)
        {
            switch (type)
            {
                case MapObjectType.全部: return null;
                case MapObjectType.节点: return typeof(JunctionViewModel);
                case MapObjectType.水库: return typeof(ReservoirViewModel);
                case MapObjectType.水池: return typeof(TankViewModel);
                case MapObjectType.喷头: return typeof(NozzleViewModel);
                case MapObjectType.管线: return typeof(PipeViewModel);
                case MapObjectType.阀门: return typeof(ValveViewModel);
                case MapObjectType.重复器: return typeof(RepeaterViewModel);
                case MapObjectType.水泵: return typeof(PumpViewModel);
                case MapObjectType.阀门点: return typeof(ValveNodeViewModel);
                case MapObjectType.水泵点: return typeof(PumpNodeViewModel);
                default: return null;
            }
 
        }
        public static bool isNodeType(this MapObjectType type)
        {
            switch (type)
            {
                case MapObjectType.全部: return true;
                case MapObjectType.节点: return true;
                case MapObjectType.水库: return true;
                case MapObjectType.水池: return true;
                case MapObjectType.喷头: return true;
                case MapObjectType.阀门点: return true;
                case MapObjectType.水泵点: return true;
 
 
 
                default: return false;
            }
 
        }
 
    }
    public class MapObjectRecord
    {
        public IBaseViewModel mapObject { get; set; }
        public string ValueName { get; set; }
 
        public dynamic Value { get; set; }
 
    }
 
 
    //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 NodeViewModel junction;
    //    public ReservoirViewModel reservoir;
    //    public TankViewModel tank;
    //    public MeterViewModel meter;
    //    public NozzleViewModel nozzle;
    //    public LinkViewModel pipe;
    //    public ValveViewModel valve;
    //    public RepeaterViewModel repeater;
    //    public PumpViewModel pump;
    //    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<MapObjectType, string> PreName = new Dictionary<MapObjectType, string>()
    //    {
    //        {MapObjectType.节点,"J" },
    //        {MapObjectType.水库,"R" },
    //        {MapObjectType.水池,"T" },
    //        {MapObjectType.水表,"M" },
    //        {MapObjectType.喷头,"N" },
    //        {MapObjectType.管线,"P" },
    //        {MapObjectType.阀门,"V" },
    //        {MapObjectType.重复器,"Rp" },
    //        {MapObjectType.水泵,"Pump" },
    //        {MapObjectType.阀门点,"Vn" },
    //    };
    //    public static string GetPreString(IBaseViewModel obj)
    //    {
    //        return PreName[obj.Type];
    //    }
    //}
 
    //public enum MouseState
    //{
    //    无,
    //    新增节点,
    //    新建水库,
    //    新建水池,
    //    新建水表,
    //    新增喷头,
    //    新增管线,
 
    //    新建阀门,
 
    //    新建重复器,
    //    新建水泵,
    //    设置底图范围,
 
    //}
}