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
|
//{
|
// 无,
|
// 新增节点,
|
// 新建水库,
|
// 新建水池,
|
// 新建水表,
|
// 新增喷头,
|
// 新增管线,
|
|
// 新建阀门,
|
|
// 新建重复器,
|
// 新建水泵,
|
// 设置底图范围,
|
|
//}
|
}
|