using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using IniParser; using UtfUnknown; namespace Construction.BatchCreateMap { public class GridCreateParameter: GridCreateParameterBase { private double curveSpace = 5; private int lableSpace = 5; /// /// Gets or sets the automatic. /// /// The automatic. [Category("\t文件")] [DisplayName("自动打开")] [Browsable(false)] public int Auto { get; set; } = 0; /// /// Gets or sets the contour. /// /// The contour. [Category("\t文件")] [DisplayName("等值线")] [Browsable(false)] public string Contour { get; set; } /// /// Gets or sets the faultage. /// [Category("\t文件")] [DisplayName("断层")] [ReadOnly(true)] [Browsable(true)] //[Editor( // "DQ.Construction.NewLook.Editor.EditorDropdownFault, Construction", // typeof(System.Drawing.Design.UITypeEditor))] //[TypeConverter(typeof(ParameterUtil.Converter.FilePathConverter))] public string Faultage { get; set; } ///// ///// Gets or sets the faultage type. ///// //[Category("\t文件")] //[DisplayName("\t断层类型")] ////[Editor(Config.NameSpace + "EditorDropdownFaultType, KEPlatform", //// typeof(System.Drawing.Design.UITypeEditor))] ////[TypeConverter(typeof(EnumTypeConverter))] //public string FaultageType { get; set; } /// /// Gets or sets the file path. /// /// The file path. [Category("\t文件")] [DisplayName("参数文件")] [Browsable(false)] public string FilePath { get; set; } /// /// Gets or sets the input. /// /// The input. [Category("\t文件")] [DisplayName("散点")] [Browsable(true)] [ReadOnly(true)] public string Input { get; set; } /// /// Gets or sets the outline. /// /// The outline. [Category("\t文件")] [DisplayName("\t\t边界")] [Browsable(true)] //[Editor("DQ.Construction.NewLook.Editor.EditorDropdownBorder, Construction", // typeof(System.Drawing.Design.UITypeEditor))] //[TypeConverter(typeof(ParameterUtil.Converter.FilePathConverter))] [ReadOnly(true)] public string Outline { get; set; } /// /// Gets or sets 编辑类型. /// /// /// 0,数据边界,1层位边界,2,工区边界 /// //[Category("\t文件")] //[DisplayName("\t\t\t边界类型")] ////[Editor(Config.NameSpace + "EditorDropdownBorderType, KEPlatform", //// typeof(System.Drawing.Design.UITypeEditor))] ////[TypeConverter(typeof(EnumTypeConverter))] //public string OutlineType { get; set; } /// /// Gets or sets the output. /// /// The output. [Category("\t文件")] [DisplayName("结果")] [Browsable(false)] public string Output { get; set; } /// /// 曲线间隔 /// [Category("等值线")] [DisplayName("\t等值线步长")] public double CurveSpace { get { return this.curveSpace; } set { this.curveSpace = value; } } /// /// 标注间隔 /// [Category("等值线")] [DisplayName("标注间隔")] public int LableSpace { get { return this.lableSpace; } set { this.lableSpace = value; } } /// /// 等值线 /// [Category("等值线")] [DisplayName("控制输出范围")] [ReadOnly(false)] public ConverLableType IsLableOutType { get; set; } = ConverLableType.否; /// /// 等值线 /// [Category("等值线")] [DisplayName("最小值")] [ReadOnly(true)] public double LableOutMinValue { get; set; } = 0; /// /// 等值线 /// [Category("等值线")] [DisplayName("最大值")] [ReadOnly(true)] public double LableOutMaxValue { get; set; } = 0; /// /// 收敛参数 /// [Category("收敛参数")] [DisplayName("是否收敛处理")] [ReadOnly(false)] public ConverType IsConverType { get; set; } = ConverType.否; /// /// 收敛参数 /// [Category("收敛参数")] [DisplayName("收敛半径")] [ReadOnly(false)] public double ConvergentRadius { get; set; } = 10; /// /// 收敛参数 /// [Category("收敛参数")] [DisplayName("收敛临界值")] [ReadOnly(false)] public double ConvergentFillValue { get; set; } = 0; /// /// 网格化算法 /// [Category("计算参数")] [DisplayName("网格化\t\t算法")] //[TypeConverter(typeof(EnumTypeConverter))] public ModelCreateType CreateType { get; set; } = ModelCreateType.XY; /// /// 边界参数 /// [Category("边界参数")] [DisplayName("\t是否计算边界Z值")] [ReadOnly(false)] public ConverType IsOutLineZ { get; set; } = ConverType.否; /// /// 边界参数 /// [Category("边界参数")] [DisplayName("边界Z值")] [ReadOnly(false)] public double OutLineZ { get; set; } /// /// 计算参数 /// [Category("计算参数")] [DisplayName("网格化输出控制")] [ReadOnly(false)] public ConverGridType IsModelOutType { get; set; } = ConverGridType.否; /// /// 计算参数 /// [Category("计算参数")] [DisplayName("最小值")] [ReadOnly(true)] public double ModelOutMinValue { get; set; } = 0; /// /// 计算参数 /// [Category("计算参数")] [DisplayName("最大值")] [ReadOnly(true)] public double ModelOutMaxValue { get; set; } = 0; /// /// Gets or sets the file path. /// /// The file path. [Category("其它数据")] [DisplayName("是否生成井斜")] public ConverType IsAddSlantWell { get; set; } = ConverType.是; /// /// Gets or sets 深度类型. /// /// The file path. [Category("其它数据")] [DisplayName("深度类型")] [Browsable(false)] [ReadOnly(true)] public int DepthType { get; set; } /// /// 相对路径 /// [Browsable(false)] public string DataRootPath { get; set; } public GridCreateParameter() { } public GridCreateParameter(GridCreateParameter other) { if(other == null) { return; } this.Input = other.Input; this.Outline = other.Outline; this.Faultage = other.Faultage; this.Output = other.Output; this.Contour = other.Contour; this.Smooth = other.Smooth; this.Times = other.Times; this.XMin = other.XMin; this.YMin = other.YMin; this.XMax = other.XMax; this.YMax = other.YMax; this.ZMin = other.ZMin; this.ZMax = other.ZMax; this.Auto = other.Auto; this.CurveSpace = other.CurveSpace; this.LableSpace = other.LableSpace; //paraOther.M = this.M; //paraOther.N = this.N; this.XStep = other.XStep; this.YStep = other.YStep; this.FilePath = other.FilePath; this.CreateType = other.CreateType; //this.OutlineType = other.OutlineType; //this.FaultageType = other.FaultageType; //paraOther.AddOtherData = this.AddOtherData; //// Type type = this.OtherData.GetType(); //if (this.OtherData != null) //{ // paraOther.OtherData = ObjectClone.CloneFrom(this.OtherData); //} this.DataRootPath = other.DataRootPath; this.IsModelOutType = other.IsModelOutType; this.ModelOutMaxValue = other.ModelOutMaxValue; this.ModelOutMinValue = other.ModelOutMinValue; this.IsLableOutType = other.IsLableOutType; this.LableOutMaxValue = other.LableOutMaxValue; this.LableOutMinValue = other.LableOutMinValue; this.DepthType = other.DepthType; this.IsConverType = other.IsConverType; this.ConvergentFillValue = other.ConvergentFillValue; this.ConvergentRadius = other.ConvergentRadius; this.IsAddSlantWell = other.IsAddSlantWell; this.IsOutLineZ = other.IsOutLineZ; this.OutLineZ = other.OutLineZ; } /// /// Initializes a new instance of the class. /// /// The file path. public GridCreateParameter(string filePath) { this.FilePath = filePath; } /// /// Clones 一个新对象. /// public virtual GridCreateParameter Clone() { return new GridCreateParameter(this); } /// /// Reads the data. /// /// true if XXXX, false otherwise. public virtual bool ReadData() { string strFilePath = this.FilePath; if (!this.FilePath.StartsWith(this.DataRootPath)) { strFilePath = Path.Combine(this.DataRootPath, this.FilePath); } if (!File.Exists(strFilePath)) { return false; } // 自动检测编码 Encoding encoding = Encoding.Default; var dector = CharsetDetector.DetectFromFile(strFilePath); if (dector.Detected != null && dector.Detected.HasBOM == true && dector.Detected.Encoding != null) { encoding = dector.Detected.Encoding; } string strFileData = File.ReadAllText(strFilePath, encoding); var parser = new IniDataParser(); IniData parsedData = parser.Parse(strFileData); this.Input = parsedData["pages"]["input"];// INIHelper.Read("pages", "input", string.Empty, strFilePath); this.Output = parsedData["pages"]["output"]; // INIHelper.Read("pages", "output", string.Empty, strFilePath); this.Faultage = parsedData["pages"]["faultage"]; // INIHelper.Read("pages", "faultage", string.Empty, strFilePath); this.Outline = parsedData["pages"]["outline"]; // INIHelper.Read("pages", "outline", string.Empty, strFilePath); this.Contour = parsedData["pages"]["contour"]; // INIHelper.Read("pages", "contour", string.Empty, strFilePath); string strSmooth = parsedData["pages"]["smooth"]; // INIHelper.Read("pages", "smooth", string.Empty, strFilePath); if (strSmooth.Length > 0) { this.Smooth = Convert.ToInt32(strSmooth); } string strM = parsedData["pages"]["m"]; // INIHelper.Read("pages", "m", string.Empty, strFilePath); if (strM.Length > 0) { this.M = Convert.ToInt32(strM); } string strN = parsedData["pages"]["n"]; // INIHelper.Read("pages", "n", string.Empty, strFilePath); if (strN.Length > 0) { this.N = Convert.ToInt32(strN); } string strTimes = parsedData["pages"]["times"]; // INIHelper.Read("pages", "times", string.Empty, strFilePath); if (strTimes.Length > 0) { this.Times = Convert.ToInt32(strTimes); } string strXmin = parsedData["pages"]["xmin"]; // INIHelper.Read("pages", "xmin", string.Empty, strFilePath); if (strXmin.Length > 0) { try { this.XMin = Convert.ToDouble(strXmin); } catch { this.XMin = double.NaN; } } string strYmin = parsedData["pages"]["ymin"]; // INIHelper.Read("pages", "ymin", string.Empty, strFilePath); if (strYmin.Length > 0) { try { this.YMin = Convert.ToDouble(strYmin); } catch { this.YMin = double.NaN; } } string strXmax = parsedData["pages"]["xmax"]; //INIHelper.Read("pages", "xmax", string.Empty, strFilePath); if (strXmax.Length > 0) { try { this.XMax = Convert.ToDouble(strXmax); } catch { this.XMax = double.NaN; } } string strYmax = parsedData["pages"]["ymax"]; //INIHelper.Read("pages", "ymax", string.Empty, strFilePath); if (strYmax.Length > 0) { try { this.YMax = Convert.ToDouble(strYmax); } catch { this.YMax = double.NaN; } } string strZMin = parsedData["pages"]["zmin"]; // INIHelper.Read("pages", "zmin", string.Empty, strFilePath); if (!string.IsNullOrEmpty(strZMin)) { try { this.ZMin = Convert.ToDouble(strZMin); } catch { this.ZMin = double.NaN; } } string strZMax = parsedData["pages"]["zmax"]; // INIHelper.Read("pages", "zmax", string.Empty, strFilePath); if (!string.IsNullOrEmpty(strZMax)) { try { this.ZMax = Convert.ToDouble(strZMax); } catch { this.ZMax = double.NaN; } } string strAuto = parsedData["pages"]["auto"];// INIHelper.Read("pages", "auto", string.Empty, strFilePath); if (strAuto.Length > 0) { this.Auto = Convert.ToInt32(strAuto); } string strCurveSpace = parsedData["curve"]["curveSpace"]; // INIHelper.Read("curve", "curveSpace", "5", strFilePath); if (strCurveSpace.Length > 0) { if (double.TryParse(strCurveSpace, out this.curveSpace) == false) { this.curveSpace = double.NaN; } } else { curveSpace = 5; } string strLableSpace = parsedData["curve"]["lableSpace"];// INIHelper.Read("curve", "lableSpace", "5", strFilePath); if (strLableSpace.Length > 0) { this.lableSpace = Convert.ToInt32(strLableSpace); } else { this.lableSpace = 5; } string strCreateType = parsedData["other"]["createType"]; // INIHelper.Read("other", "createType", "0", strFilePath); if (strCreateType.Length > 0) { this.CreateType = (ModelCreateType)Convert.ToInt32(strCreateType); } else { this.CreateType = 0; } //string strOutLineType = INIHelper.Read("other", "outlineType", "0", strFilePath); //if (strOutLineType.Length > 0) //{ // this.OutlineType = (EnumOutlineType)Convert.ToInt32(strOutLineType); //} //string strFaultageType = INIHelper.Read("other", "faultageType", "0", strFilePath); //if (strFaultageType.Length > 0) //{ // this.FaultageType = (EnumFaultType)Convert.ToInt32(strFaultageType); //} string strAddSlantWell = parsedData["other"]["IsAddSlantWell"]; if (string.IsNullOrEmpty(strAddSlantWell)) { strAddSlantWell = "是"; } this.IsAddSlantWell = GetVauleByType(strAddSlantWell);//INIHelper.Read("other", "IsAddSlantWell", "是", strFilePath)); string strTmp = parsedData["other"]["DepthType"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.DepthType = GetVauleByType(strTmp); strTmp = parsedData["curve"]["outType"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "否"; } this.IsLableOutType = GetVauleByType(strTmp);// INIHelper.Read("curve", "outType", "否", strFilePath)); strTmp = parsedData["curve"]["outMinValue"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.LableOutMinValue = GetVauleByType(strTmp); //INIHelper.Read("curve", "outMinValue", "0", strFilePath)); strTmp = parsedData["curve"]["outMaxValue"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.LableOutMaxValue = GetVauleByType(strTmp);// INIHelper.Read("curve", "outMaxValue", "0", strFilePath)); strTmp = parsedData["model"]["outType"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "否"; } this.IsModelOutType = GetVauleByType(strTmp);// INIHelper.Read("model", "outType", "否", strFilePath)); strTmp = parsedData["model"]["outMinValue"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.ModelOutMinValue = GetVauleByType(strTmp);// INIHelper.Read("model", "outMinValue", "0", strFilePath)); strTmp = parsedData["model"]["outMaxValue"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.ModelOutMaxValue = GetVauleByType(strTmp); // INIHelper.Read("model", "outMaxValue", "0", strFilePath)); strTmp = parsedData["conver"]["converType"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "否"; } this.IsConverType = GetVauleByType(strTmp); // INIHelper.Read("conver", "converType", "否", strFilePath)); strTmp = parsedData["conver"]["convergentRadius"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.ConvergentRadius = GetVauleByType(strTmp);// INIHelper.Read("conver", "convergentRadius", "0", strFilePath)); strTmp = parsedData["conver"]["convergentFillValue"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.ConvergentFillValue = GetVauleByType(strTmp);// INIHelper.Read("conver", "convergentFillValue", "0", strFilePath)); strTmp = parsedData["curve"]["IsOutLineZ"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "否"; } this.IsOutLineZ = GetVauleByType(strTmp); // INIHelper.Read("curve", "IsOutLineZ", "否", strFilePath)); strTmp = parsedData["curve"]["OutLineZ"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "0"; } this.OutLineZ = GetVauleByType(strTmp); // INIHelper.Read("curve", "OutLineZ", "0", strFilePath)); strTmp = parsedData["other"]["IsAddSlantWell"]; if (string.IsNullOrEmpty(strTmp)) { strTmp = "1"; } this.IsAddSlantWell = (ConverType)Convert.ToInt32(strTmp); //string strSlantWell = INIHelper.Read("other", "IsAddSlantWell", "1", strFilePath); //if (strSlantWell.Length > 0) //{ // this.IsAddSlantWell = (ConverType)Convert.ToInt32(strSlantWell); //} //string strFileName = Path.GetFileNameWithoutExtension(strFilePath); //string strDir = Path.GetDirectoryName(strFilePath); //string strFileMerge = Path.Combine(strDir, $"{strFileName}.merge"); //if (File.Exists(strFileMerge)) //{ // MergeTemplate template = null; // try // { // using (XmlReader reader = XmlReader.Create(strFileMerge)) // { // XmlSerializer formatter = new XmlSerializer(typeof(MergeTemplate)); // template = formatter.Deserialize(reader) as MergeTemplate; // } // this.OtherData = template; // } // catch // { // template = null; // } //} return true; } /// /// 返回转换后值 /// /// /// /// private T GetVauleByType(string input) { input = input.Trim(); object obj = default(T); if (typeof(T) == typeof(double)) { if (string.IsNullOrEmpty(input)) { obj = 0; } else { obj = Convert.ToDouble(input); } } else if(typeof(T) == typeof(int)) { if (string.IsNullOrEmpty(input)) { obj = 0; } else { obj = Convert.ToInt32(input); } } else if (typeof(T) == typeof(ConverType)) { if (input.Equals("是")) { obj = ConverType.是; } else { obj = ConverType.否; } } else if (typeof(T) == typeof(ConverLableType)) { if (input.Equals("是")) { obj = ConverLableType.是; } else if (input.Equals("与网格同步")) { obj = ConverLableType.与网格同步; } else { obj = ConverLableType.否; } } else if (typeof(T) == typeof(ConverGridType)) { if (input.Equals("抹平")) { obj = ConverGridType.抹平; } else if (input.Equals("剔除")) { obj = ConverGridType.剔除; } else { obj = ConverGridType.否; } } return (T)obj; } /// /// Writes the data. /// /// true if XXXX, false otherwise. public virtual bool WriteData() { string strFilePath = this.FilePath; if (string.IsNullOrEmpty(strFilePath)) { return false; } if (!this.FilePath.StartsWith(this.DataRootPath)) { strFilePath = Path.Combine(this.DataRootPath, this.FilePath); this.FilePath = strFilePath; var folder = Directory.GetParent(this.FilePath).FullName; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } using (StreamWriter sw = new StreamWriter(strFilePath, false, Encoding.Default)) { string strContent = $@"[pages] input={this.Input} output={this.Output} faultage={this.Faultage} outline={this.Outline} contour={this.Contour} smooth={ this.Smooth} m={this.M} n={this.N} times={this.Times} xmin={this.XMin} ymin={this.YMin} xmax={this.XMax} ymax={this.YMax} auto={this.Auto} zmin={this.ZMin} zmax={this.ZMax} [curve] curveSpace={this.CurveSpace} lableSpace={this.LableSpace} outType ={ this.IsLableOutType} outMinValue ={ this.LableOutMinValue} outMaxValue ={ this.LableOutMaxValue} IsOutLineZ ={ this.IsOutLineZ} OutLineZ ={ this.OutLineZ} [model] outType ={ this.IsModelOutType} outMinValue ={ this.ModelOutMinValue} outMaxValue ={ this.ModelOutMaxValue} [other] createType={(int)this.CreateType} IsAddSlantWell={(int)this.IsAddSlantWell} [conver] converType={this.IsConverType} convergentFillValue ={this.ConvergentFillValue} convergentRadius ={this.ConvergentRadius}"; sw.Write(strContent); } //outlineType={(int)this.OutlineType} //faultageType={(int)this.FaultageType} //WriteTemplate(); return true; } //public bool WriteTemplate() //{ // string strFilePath = this.FilePath; // string strFileName = Path.GetFileNameWithoutExtension(strFilePath); // string strDir = Path.GetDirectoryName(strFilePath); // string strFileMerge = Path.Combine(strDir, $"{strFileName}.merge"); // XmlWriterSettings settings = new XmlWriterSettings(); // settings.Indent = true; // settings.IndentChars = " "; // settings.NewLineChars = "\r\n"; // settings.Encoding = Encoding.Default; // try // { // MemoryStream mem = new MemoryStream(); // using (XmlWriter writer = XmlWriter.Create(mem, settings)) // { // // 去除默认命名空间xmlns:xsd和xmlns:xsi // XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); // ns.Add(string.Empty, string.Empty); // XmlSerializer formatter = new XmlSerializer(typeof(MergeTemplate)); // formatter.Serialize(writer, OtherData, ns); // } // string strData = Encoding.Default.GetString(mem.ToArray()); // File.WriteAllText(strFileMerge, strData, Encoding.Default); // } // catch (Exception ex) // { // Trace.WriteLine(ex.Message); // } // return true; //} } /// /// 边界类型 /// public enum EnumOutlineType { 无 = 0, 层位边界, 工区边界 } /// /// /// public enum EnumFaultType { 无 = 0, 层位断层, } /// /// /// public enum ConverType { 否 = 0, 是 } /// /// /// public enum ConverLableType { 否 = 0, 是, 与网格同步 } /// /// /// public enum ConverGridType { 否 = 0, 剔除 = 1, 抹平 = 2, 抹平固定值 = 3, } public enum ModelCreateType { [Description("最小张力")] XY = 0, [Description("反距离加权")] IDM = 1, [Description("自然临近")] NatureNeighbor = 2, [Description("最小曲率")] Curvature = 3, [Description("快速网格化")] QuikGrid = 4, [Description("样条插值法")] GmtSplineGrid = 5, } }