You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

408 lines
17 KiB
C#

// <copyright file="DrawerWellGroup.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using GeoSigma.SigmaDrawerStyle;
using GeoSigmaDrawLib;
using SigmaDrawerStyle;
namespace SigmaDrawerElement
{
/// <summary>
/// The drawer well group.
/// </summary>
[XmlRoot("WellGroup")]
public class DrawerWellGroup : DrawerPoint, INotifyPropertyChanged
{
[XmlElement("HowToViewPoint")]
[Category("井组"), DisplayName("井点样式"), Browsable(false)]
public DrawerPointStyle WellPointStyle { get; set; }
/// <summary>
/// Gets or sets 井支.
/// </summary>
[Category("井组"), DisplayName("井支")]
public List<WellBranch> WellBranches { get; set; } = new List<WellBranch>();
/// <summary>
/// Gets or sets 参数.
/// </summary>
[Category("井组"), DisplayName("参数")]
public WellGroupParameter Parameter { get; set; } = new WellGroupParameter();
/// <summary>
/// Initializes a new instance of the <see cref="DrawerWellGroup"/> class.
/// </summary>
public DrawerWellGroup()
{
ElementType = DrawElementType.ELEMENT_WELL_GROUP;
}
public bool CreateHorizionWells()
{
WellBranches.Clear();
string strWellName = this.Name;
double dDistanceRight = Parameter.BranchDistanceRight;
double dDistanceLeft = Parameter.BranchDistanceLeft;
double dBranchAngle = Parameter.BranchAngle;
double dBranchSpace = Parameter.BranchSpace;
double dBranchLength = Parameter.BranchLength;
int nBranchCount = Parameter.BranchCountRight;
List<WellBranch> lstBranchRigh = this.CreateBranchs(dDistanceRight, dBranchSpace, dBranchLength, nBranchCount, true);
WellBranches.AddRange(lstBranchRigh);
nBranchCount = Parameter.BranchCountLeft;
if (Parameter.BranchCountLeft > 0)
{
List<WellBranch> lstBranchLeft = this.CreateBranchs(dDistanceLeft, dBranchSpace, dBranchLength, nBranchCount, false);
WellBranches.AddRange(lstBranchLeft);
}
if (this.Parameter.BranchAngle != 0)
{
double dAngle = this.Parameter.BranchAngle * Math.PI / 180.0;
int nCount = WellBranches.Count;
for (int i = 0; i < nCount; i++)
{
WellBranch branchOld = WellBranches[i];
DrawerPoint ptRotate = RotatePoint(branchOld.PointStart.X, branchOld.PointStart.Y
, 0, 0, dAngle);
branchOld.PointStart.X = ptRotate.X;
branchOld.PointStart.Y = ptRotate.Y;
ptRotate = RotatePoint(branchOld.PointEnd.X, branchOld.PointEnd.Y
, 0, 0, dAngle);
branchOld.PointEnd.X = ptRotate.X;
branchOld.PointEnd.Y = ptRotate.Y;
}
}
Offset(this.Parameter.WellPoint.X, this.Parameter.WellPoint.Y);
//Z = this.Parameter.WellPoint.Z;
//// 设置井点样式
//DrawerPointStyle ptstyleWell = new DrawerPointStyle();
//ptstyleWell.AlignHorizion = (int)TextStyleFlags.alignCenterH;
//ptstyleWell.AlignVertical = (int)TextStyleFlags.alignTop;
//ptstyleWell.Offset = new PropertyPoint(0, Parameter.SymbolSize * 0.5);
//PropertySize txtSize = default(PropertySize);
//txtSize.Width = Parameter.FontHeight * 0.4;
//txtSize.Height = Parameter.FontHeight;
//txtSize.FixScale = true;
//SizeF sizeSymbol = new SizeF((float)Parameter.SymbolSize, (float)Parameter.SymbolSize);
//ptstyleWell.TextSize = txtSize;
//ptstyleWell.SymbolSize = sizeSymbol;
//ptstyleWell.SymbolName = Parameter.SymbolWell.SymbolName;
//WellPointStyle = ptstyleWell;
//// 设置井支入靶点和出靶点样式
//int nBranchAllCount = wellGroup.WellBranches.Count;
//for (int i = 0; i < nBranchAllCount; i++)
//{
// WellBranch branch = wellGroup.WellBranches[i];
// branch.PointStyles = new List<DrawerPointStyle>();
// DrawerPointStyle ptStart = ptstyleWell.Clone();
// ptStart.Name = "start";
// ptStart.SymbolName = Parameter.SymbolStart.SymbolName;
// ptStart.SymbolSize = new SizeF((float)(sizeSymbol.Width * 0.5), (float)(sizeSymbol.Height * 0.5));
// //ptStart.TextSize = txtSize;
// //ptStart.SymbolSize = sizeSymbol;
// branch.PointStyles.Add(ptStart);
// DrawerPointStyle ptEnd = ptstyleWell.Clone();
// ptEnd.Name = "end";
// ptEnd.SymbolName = Parameter.SymbolEnd.SymbolName;
// ptEnd.SymbolSize = new SizeF((float)(sizeSymbol.Width * 0.5), (float)(sizeSymbol.Height * 0.5));
// // ptEnd.TextSize = txtSize;
// // ptEnd.SymbolSize = sizeSymbol;
// branch.PointStyles.Add(ptEnd);
// branch.PointStart.Name = $"{strWellName}-{i + 1}A";
// branch.PointEnd.Name = $"{strWellName}-{i + 1}B";
// branch.LineStyles = new List<DrawerCurveStyle>();
// DrawerCurveStyle drawerCurveStyleOffset = new DrawerCurveStyle();
// drawerCurveStyleOffset.Name = "offset";
// CurveProperty curvePropertyOffset = new CurveProperty();
// curvePropertyOffset.Width = Parameter.OffsetLineWidth;
// curvePropertyOffset.LineColor = Parameter.OffsetColor;
// drawerCurveStyleOffset.Properties.Add(curvePropertyOffset);
// branch.LineStyles.Add(drawerCurveStyleOffset);
// DrawerCurveStyle drawerCurveStyleHori = new DrawerCurveStyle();
// drawerCurveStyleHori.Name = "horizon";
// CurveProperty curvePropertyHori = new CurveProperty();
// curvePropertyHori.Width = Parameter.HorizonLineWidth;
// curvePropertyHori.LineColor = Parameter.HorizonColor;
// drawerCurveStyleHori.Properties.Add(curvePropertyHori);
// branch.LineStyles.Add(drawerCurveStyleHori);
//}
//DrawerElementProperty element = new DrawerElementProperty();
//element.Element = wellGroup;
//element.ElementType = wellGroup.ElementType;
//string strElementData = DrawerElementHelp.Serialize(element);
//drawer.Geo.AddWellGroupSetData(strElementData);
return true;
}
/// <summary>
/// 获得井组的数据范围
/// </summary>
/// <returns>范围</returns>
public RectangleD CaculateDataRange()
{
double dXMin = this.X;
double dYMin = this.Y;
double dXMax = this.X;
double dYMax = this.Y;
foreach (var branch in WellBranches)
{
dXMin = Math.Min(dXMin, branch.PointEnd.X);
dXMin = Math.Min(dXMin, branch.PointStart.X);
dYMin = Math.Min(dYMin, branch.PointEnd.Y);
dYMin = Math.Min(dYMin, branch.PointStart.Y);
dXMax = Math.Max(dXMax, branch.PointEnd.X);
dXMax = Math.Max(dXMax, branch.PointStart.X);
dYMax = Math.Max(dYMax, branch.PointEnd.Y);
dYMax = Math.Max(dYMax, branch.PointStart.Y);
}
return new RectangleD(dXMin, dYMin, dXMax - dXMin, dYMax - dYMin);
}
/// <summary>
/// 计算旋转后的坐标
/// </summary>
/// <param name="sourceX"></param>
/// <param name="sourceY"></param>
/// <param name="centerX"></param>
/// <param name="centerY"></param>
/// <param name="angle"></param>
/// <returns></returns>
private DrawerPoint RotatePoint(double sourceX, double sourceY, double ox, double oy, double angle)
{
double rotatedX = ox + (sourceX - ox) * Math.Cos(angle) - (sourceY - oy) * Math.Sin(angle);
double rotatedY = oy + (sourceX - ox) * Math.Sin(angle) + (sourceY - oy) * Math.Cos(angle);
return new DrawerPoint(string.Empty, rotatedX, rotatedY, 0, 0);
}
/// <summary>
/// 生成右侧的井支
/// </summary>
/// <param name="dDistance">靶前偏移</param>
/// <param name="dBranchSpace">井间距</param>
/// <param name="dBranchLength">水平段长度</param>
/// <param name="nBranchCount">井支数量</param>
/// <param name="isRight">是否为右侧</param>
private List<WellBranch> CreateBranchs(double dDistance, double dBranchSpace, double dBranchLength, int nBranchCount, bool isRight)
{
List<WellBranch> branchs = new List<WellBranch>();
double dHeight = Parameter.BranchSpace * (nBranchCount - 1);
// 先按井支角度为0计算
// 中心角
//double dAngleCenter = 0;
int nHalfCount = (int)Math.Ceiling(nBranchCount * 0.5);
for (int i = 0; i < nHalfCount; i++)
{
double dHeightOne = dHeight - (dBranchSpace * i * 2);
//dAngleCenter = Math.Acos(((dDistance * dDistance) + (dDistance * dDistance) - (dHeightOne * dHeightOne)) / (2 * dDistance * dDistance));
//dAngleCenter *= 0.5;
double dPtStartX = dDistance; // (dDistance * Math.Cos(dAngleCenter));
double dPtStartY = dHeightOne * 0.5; // (dDistance * Math.Sin(dAngleCenter));
double dPtEndX = dPtStartX + dBranchLength;
double dPtEndY = dPtStartY;
WellBranch wellBranch = new WellBranch();
wellBranch.PointStart = new DrawerPoint(string.Empty, dPtStartX, dPtStartY, -1E101, 0);
wellBranch.PointEnd = new DrawerPoint(string.Empty, dPtEndX, dPtEndY, -1E101, 0);
// 旋转
if (isRight == false)
{
wellBranch.PointStart.X = -wellBranch.PointStart.X;
wellBranch.PointEnd.X = -wellBranch.PointEnd.X;
}
branchs.Add(wellBranch);
}
List<WellBranch> lstDown = new List<WellBranch>();
for (int i = nHalfCount; i < nBranchCount; i++)
{
WellBranch wellBranch = new WellBranch();
DrawerPoint ptOldStart = branchs[i - nHalfCount].PointStart;
DrawerPoint ptOldEnd = branchs[i - nHalfCount].PointEnd;
wellBranch.PointStart = new DrawerPoint(string.Empty, ptOldStart.X, -ptOldStart.Y, -1E101, 0);
wellBranch.PointEnd = new DrawerPoint(string.Empty, ptOldEnd.X, -ptOldEnd.Y, -1E101, 0);
lstDown.Add(wellBranch);
//branchs.Insert(branchs.Count - 2, wellBranch);
}
lstDown.Reverse();
branchs.AddRange(lstDown);
return branchs;
}
/// <summary>
/// 坐标偏移
/// </summary>
/// <param name="dX">x偏移</param>
/// <param name="dY">y偏移</param>
public new void Offset(double dX, double dY)
{
base.Offset(dX, dY);
if (this.Parameter != null)
{
this.Parameter.WellPoint.Offset(dX, dY);
}
for (int i = 0; i < this.WellBranches.Count; i++)
{
this.WellBranches[i].PointEnd.Offset(dX, dY);
this.WellBranches[i].PointStart.Offset(dX, dY);
}
}
}
/// <summary>
/// The 井组参数.
/// </summary>
[TypeConverter(typeof(PropertySorter))]
public class WellGroupParameter : INotifyPropertyChanged
{
public WellGroupParameter() { }
private DrawerPoint wellPoint = new DrawerPoint();
//[RefreshProperties(RefreshProperties.All)]
[XmlIgnore]
[Category("\t\t水平井参数"), DisplayName("\t井点"), Browsable(true)]
[TypeConverter(typeof(ExpandableObjectConverter))]
public DrawerPoint WellPoint
{
get
{
return wellPoint;
}
set
{
if (!wellPoint.Equals(value))
{
wellPoint = value;
OnPropertyChanged(nameof(WellPoint));
}
}
}
[XmlAttribute]
[Category("\t\t水平井参数"), DisplayName("井支角度"), Browsable(true), PropertyOrder(1)]
public double BranchAngle { get; set; } = 0; // 井支角度
private int branchCountRight = 3;
[XmlAttribute]
[Category("\t\t水平井参数"), DisplayName("右侧井支数"), Browsable(true), PropertyOrder(2)]
public int BranchCountRight
{
get
{
return branchCountRight;
}
set
{
if (branchCountRight != value)
{
branchCountRight = value;
OnPropertyChanged(nameof(BranchCountRight));
}
}
}
[XmlAttribute]
[Category("\t\t水平井参数"), DisplayName("右侧垂直靶前距"), Browsable(true), PropertyOrder(3)]
public double BranchDistanceRight { get; set; } = 500; // 垂直靶前距
private int branchCountLeft = 3;
[XmlAttribute]
[Category("\t\t水平井参数"), DisplayName("左侧井支数"), Browsable(true), PropertyOrder(4)]
public int BranchCountLeft
{
get
{
return branchCountLeft;
}
set
{
if (branchCountLeft != value)
{
branchCountLeft = value;
OnPropertyChanged(nameof(BranchCountLeft));
}
}
}
[XmlAttribute]
[Category("\t\t水平井参数"), DisplayName("左侧垂直靶前距"), Browsable(true), PropertyOrder(5)]
public double BranchDistanceLeft { get; set; } = 500; // 垂直靶前距
[XmlAttribute]
[Category("\t\t水平井参数"), DisplayName("水平井段长度"), Browsable(true), PropertyOrder(6)]
public double BranchLength { get; set; } = 1800; // 水平井段长度
[XmlAttribute]
[Category("\t\t水平井参数"), DisplayName("井支间距"), Browsable(true), PropertyOrder(7)]
public double BranchSpace { get; set; } = 300; // 井间距
public WellGroupParameter Clone()
{
WellGroupParameter other = new WellGroupParameter();
other.BranchCountRight = this.BranchCountRight;
other.BranchCountLeft = this.BranchCountLeft;
other.BranchAngle = this.BranchAngle;
other.BranchDistanceLeft = this.BranchDistanceLeft;
other.BranchDistanceRight = this.BranchDistanceRight;
other.BranchLength = this.BranchLength;
other.BranchSpace = this.BranchSpace;
DrawerPoint pt = new DrawerPoint();
pt.X = this.WellPoint.X;
pt.Y = this.WellPoint.Y;
pt.Z = this.WellPoint.Z;
if (this.WellPoint.Name != null)
{
pt.Name = this.WellPoint.Name.Clone().ToString();
}
if (this.WellPoint.Layer != null)
{
pt.Layer = this.WellPoint.Layer.Clone().ToString();
}
other.WellPoint = pt;
return other;
}
public event PropertyChangedEventHandler PropertyChanged;
public virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// 井支
/// </summary>
public class WellBranch
{
public WellBranch() { }
/// <summary>
/// 入靶点
/// </summary>
public DrawerPoint PointStart { get; set; }
/// <summary>
/// 出靶点
/// </summary>
public DrawerPoint PointEnd { get; set; }
[XmlElement(Type = typeof(DrawerCurveStyle), ElementName = "HowToViewCurve")]
public List<DrawerCurveStyle> LineStyles { get; set; }
[XmlElement(Type = typeof(DrawerPointStyle), ElementName = "HowToViewPoint")]
public List<DrawerPointStyle> PointStyles { get; set; }
//public DrawerCurveStyle OffsetLineStyle { get; set; }
//public DrawerCurveStyle HorizonLineStyle { get; set; }
}
}