using Microsoft.VisualBasic.CompilerServices; using MuchInfo.Chart.Data; using MuchInfo.Chart.Data.EnumTypes; using MuchInfo.Chart.Infrastructure.Helpers; using MuchInfo.Chart.Infrastructure.Utilities; using MuchInfo.Chart.WPF.Controls.Drawing; using MuchInfo.Chart.WPF.Controls.Editors; using MuchInfo.Chart.WPF.Helpers; using MuchInfo.Chart.WPF.Primitives.Interfaces; using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; using System.Xml.Linq; using NPOI.SS.Formula.Functions; namespace MuchInfo.Chart.WPF.Primitives.Drawing { public class DrawingGannBox : Drawing2PointBase { private Color CurColor; private List CurLines; private ExtendableLine CurExtendableLine; public Color CenterColor { get { return this.CurColor; } set { bool flag = !value.Equals(this.CurColor); if (flag) { this.CurColor = value; this.ColorChanged(); this.PropertyChanged(); } } } public DrawingGannBox() { this.CurColor = Colors.Yellow; this.CurLines = new List(); } public override DrawingToolType ToolType() { return DrawingToolType.GannBox; } public override IDrawingTool Clone() { return new DrawingGannBox { mColor = Colors.Yellow }; } protected override List GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect) { //初始化 ExtendableLine if (this.CurExtendableLine == null) { this.CurExtendableLine = new ExtendableLine(this, owner); this.CurExtendableLine.Stroke = new SolidColorBrush(this.CurColor); this.CurExtendableLine.StrokeThickness = 1.4; DoubleCollection doubleCollection = new DoubleCollection(); doubleCollection.Add(10.0); doubleCollection.Add(10.0); this.CurExtendableLine.SetMainStrokeDash(doubleCollection); this.CurExtendableLine.ExtensionStroke = this.CurExtendableLine.Stroke; } //初始化颜色 if (!ColorHelper.ColorIsContrasting(this.CurColor, owner.ChartBackgroundColor)) { this.CurColor = ColorHelper.InverseColor(this.CurColor); } this.CurLines.Clear(); List RltLineList = new List(); for (int i = 0; i < 17; i++) { var LineTmp = new Line() { Stroke = new SolidColorBrush(this.mColor), StrokeThickness = 1.4, }; this.CurLines.Add(LineTmp); RltLineList.Add(LineTmp); } this.MoveDrawingToNewLocations(aRect); RltLineList.Add(this.CurExtendableLine); return RltLineList; } public override string RootName { get { return "DrawGannBox"; } } public override string MenuDescription() { return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_GannBox); } public override string Abbreviation() { return "Gann"; } public override string Description() { return this.MenuDescription(); } public override List GetPropertyEditors() { List list = new List(); ControlPair controlPair = new ControlPair(); TextBlock textBlock = new TextBlock(); textBlock.Text = ("Fann Color"); controlPair.ControlLeft = textBlock; ColorOpacityEditor controlRight = new ColorOpacityEditor(this, "Color", "", ""); controlPair.ControlRight = controlRight; list.Add(controlPair); controlPair = new ControlPair(); textBlock = new TextBlock(); textBlock.Text = ("Center Line Color"); controlPair.ControlLeft = textBlock; controlRight = new ColorOpacityEditor(this, "CenterColor", "", ""); controlPair.ControlRight = controlRight; list.Add(controlPair); return list; } protected override void ColorChanged() { this.CurExtendableLine.Stroke = new SolidColorBrush(this.CurColor); try { List.Enumerator enumerator = this.CurLines.GetEnumerator(); while (enumerator.MoveNext()) { Line current = enumerator.Current; current.Stroke = (new SolidColorBrush(this.mColor)); this.CurExtendableLine.ExtensionStroke = this.CurExtendableLine.Stroke; } } finally { } } protected override void MoveDrawingToNewLocations(Rect aRect) { //TODO:调整ExtendableLine主线位置 this.CurExtendableLine.SetPosition(this.mDrawP1, this.mDrawP2, this.mDrawP1.X > this.mDrawP2.X, this.mDrawP1.X < this.mDrawP2.X, aRect); if (this.mDrawP1.X != this.mDrawP2.X && this.mDrawP1.Y != this.mDrawP2.Y) { Point P1 = new Point(this.mDrawP1.X, this.mDrawP1.Y); Point P2 = new Point(this.mDrawP2.X, this.mDrawP2.Y); var absX = P1.X > P2.X ? P1.X - P2.X : P2.X - P1.X; var absY = P1.Y > P2.Y ? P1.Y - P2.Y : P2.Y - P1.Y; var minX = P1.X > P2.X ? P2.X : P1.X; var minY = P1.Y > P2.Y ? P2.Y : P1.Y; var maxX = P1.X > P2.X ? P1.X : P2.X; var maxY = P1.Y > P2.Y ? P1.Y : P2.Y; //TODO:添加 横线、纵线 var multiple = 0.25; for (int i = 0; i < 5; i++) { //横线 var TmpHY = i * multiple * absY + minY; this.CurLines[i].X1 = minX; this.CurLines[i].Y1 = TmpHY; this.CurLines[i].X2 = maxX; this.CurLines[i].Y2 = TmpHY; //纵线 var TmpVX = i * multiple * absX + minX; this.CurLines[i + 5].X1 = TmpVX; this.CurLines[i + 5].Y1 = minY; this.CurLines[i + 5].X2 = TmpVX; this.CurLines[i + 5].Y2 = maxY; //网格交叉线 if (i > 0 && i < 4) { Point A = new Point(); Point B = new Point(); Point TmpPointH = new Point(); Point TmpPointV = new Point(); if (P1.X < P2.X && P1.Y < P2.Y) { var TmpPointHTmp = new Point(maxX, TmpHY); double slope = GeometryHelper.LineSlope(ref P1, ref TmpPointHTmp); TmpPointH = new Point(GeometryHelper.XFromLine(TmpPointHTmp, slope, aRect.Height), aRect.Height); var TmpPointVTmp = new Point(TmpVX, maxY); slope = GeometryHelper.LineSlope(ref P1, ref TmpPointVTmp); TmpPointV = new Point(aRect.Width, GeometryHelper.YFromLine(TmpPointVTmp, slope, aRect.Width)); } else if (P1.X < P2.X && P1.Y > P2.Y) { var TmpPointHTmp = new Point(maxX, TmpHY); double slope = GeometryHelper.LineSlope(ref P1, ref TmpPointHTmp); TmpPointH = new Point(aRect.Width, GeometryHelper.YFromLine(TmpPointHTmp, slope, aRect.Width)); var TmpPointVTmp = new Point(TmpVX, minY); slope = GeometryHelper.LineSlope(ref P1, ref TmpPointVTmp); TmpPointV = new Point(GeometryHelper.XFromLine(TmpPointVTmp, slope, aRect.Top), aRect.Top); } else if (P1.X > P2.X && P1.Y < P2.Y) { var TmpPointHTmp = new Point(minX, TmpHY); double slope = GeometryHelper.LineSlope(ref P1, ref TmpPointHTmp); TmpPointH = new Point(aRect.Left, GeometryHelper.YFromLine(TmpPointHTmp, slope, aRect.Left)); var TmpPointVTmp = new Point(TmpVX, maxY); slope = GeometryHelper.LineSlope(ref P1, ref TmpPointVTmp); TmpPointV = new Point(GeometryHelper.XFromLine(TmpPointVTmp, slope, aRect.Bottom), aRect.Bottom); } else if (P1.X > P2.X && P1.Y > P2.Y) { var TmpPointHTmp = new Point(minX, TmpHY); double slope = GeometryHelper.LineSlope(ref P1, ref TmpPointHTmp); TmpPointH = new Point(aRect.Left, GeometryHelper.YFromLine(TmpPointHTmp, slope, aRect.Left)); var TmpPointVTmp = new Point(TmpVX, minY); slope = GeometryHelper.LineSlope(ref P1, ref TmpPointVTmp); TmpPointV = new Point(GeometryHelper.XFromLine(TmpPointVTmp, slope, aRect.Top), aRect.Top); } A = P1; B = TmpPointH; Point startPoint = new Point(); Point endPoint = new Point(); PointOfLineAtRectangleCalculator(ref startPoint, ref endPoint, A, B, aRect); this.CurLines[i + 10].X1 = startPoint.X; this.CurLines[i + 10].Y1 = startPoint.Y; this.CurLines[i + 10].X2 = endPoint.X; this.CurLines[i + 10].Y2 = endPoint.Y; B = TmpPointV; PointOfLineAtRectangleCalculator(ref startPoint, ref endPoint, A, B, aRect); this.CurLines[i + 13].X1 = startPoint.X; this.CurLines[i + 13].Y1 = startPoint.Y; this.CurLines[i + 13].X2 = endPoint.X; this.CurLines[i + 13].Y2 = endPoint.Y; } } } } protected override void AddFromXml(XElement xml) { bool flag = xml.Attribute("CClr") != null; if (flag) { this.CurColor = ColorHelper.ColorFromString(xml.Attribute("CClr").Value); } } protected override void AddToXml(XElement xml, List args) { xml.Add(new XAttribute("CClr", this.CurColor.ToString())); } protected override void AddFromInfo(DrawingToolInfo info) { base.AddFromInfo(info); try { XElement xElement = XElement.Parse(info.XML); bool flag = xElement.Name == "Root"; if (flag) { bool flag2 = xElement.Attribute("Color1") != null; if (flag2) { this.CurColor = ColorHelper.ColorFromInt(int.Parse(xElement.Attribute("Color1").Value)); } } } catch (Exception expr_A1) { ProjectData.SetProjectError(expr_A1); ProjectData.ClearProjectError(); } } protected override void AddToInfo(DrawingToolInfo info) { base.AddToInfo(info); XElement xElement = new XElement("Root"); xElement.Add(new XAttribute("Color1", ColorHelper.ColorToInt(this.CurColor))); info.XML = xElement.ToString(); } public override ImageSource Icon() { ImageSource result; try { result = ImageHelper.GetImage("FibFan.png"); } catch (Exception expr_3A) { ProjectData.SetProjectError(expr_3A); result = null; ProjectData.ClearProjectError(); } return result; } protected override bool CanExtendLeft() { return false; } protected override bool CanExtendRight() { return false; } } }