using Newtonsoft.Json.Linq;
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.Media;
using Txgy.Microseismic.BaseLib.Models;
using System.Runtime.CompilerServices;
namespace Txgy.EWS.Client.Models
{
public class CadLayerModel
{
///
/// 层名称
///
public string name { get; set; }
[JsonProperty(PropertyName = "linecolor")]
///
/// 层线颜色字符串
///
public string linecolorStr { get; set; }
[JsonIgnore]
///
/// 线颜色
///
public Color lineColor { get; set; }
///
/// 层线宽度
///
public double linewidth { get; set; }
///
/// 线是否闭合
///
public bool lineClose { get; set; }
///
/// 层高度
///
public int layerHeight { get; set; }
///
/// 是否显示
///
public bool isShow { get; set; }
///
/// 文字大小
///
public double fontSize { get; set; }
///
/// 是否填充
///
public bool isFill { get; set; }
public CadLayerModel()
{
}
public CadLayerModel(string name,Color lineColor,double lineWidth,bool isClose,int layerHeight)
{
}
public void SetColor()
{
string[] sts = linecolorStr.Split(',');
bool noError=true;
byte[] data = new byte[sts.Length];
if (!byte.TryParse(sts[0], out data[0])) noError = false;
if (!byte.TryParse(sts[1], out data[1])) noError = false;
if (!byte.TryParse(sts[2], out data[2])) noError = false;
lineColor = noError ? Color.FromRgb(data[0], data[1], data[2]) : Colors.Black;
}
public static List ReadDwgTxtConfig(string configPath)
{
List lds = new List();
//string filePath = AppDomain.CurrentDomain.BaseDirectory +
// System.Configuration.ConfigurationManager.AppSettings["DwgSettings"].ToString();
string[] rows, cols;
using (StreamReader sr = new StreamReader(configPath))
{
rows = sr.ReadToEnd().Trim().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
}
for (int i = 1; i < rows.Length; i++)
{
cols = rows[i].Trim('\r').Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
string name = cols[0];
string[] ci = cols[1].Split(',');
Color color = Color.FromRgb(byte.Parse(ci[0]), byte.Parse(ci[1]), byte.Parse(ci[2]));
double lineW = double.Parse(cols[2]);
bool closeLine = true;
if (cols[3] == "0")
{
closeLine = false;
}
int layerHeight = int.Parse(cols[4]);
lds.Add(new CadLayerModel(name, color, lineW, closeLine, layerHeight));
}
return lds;
}
public static List CreateFromJson(string jsonFile)
{
List cadLayerModels = new List();
StreamReader streamReader = new StreamReader(jsonFile);
string jsonRoot = streamReader.ReadToEnd(); //读全部json
//jsonRoot.Dump();
JArray jA = JArray.Parse(jsonRoot);
foreach (var element in jA)
{
CadLayerModel la = JsonConvert.DeserializeObject(element.ToString());
cadLayerModels.Add(la);
}
return cadLayerModels;
}
}
}