| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- 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<Line> 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<Line>();
- }
- public override DrawingToolType ToolType()
- {
- return DrawingToolType.GannBox;
- }
- public override IDrawingTool Clone()
- {
- return new DrawingGannBox
- {
- mColor = Colors.Yellow
- };
- }
- protected override List<FrameworkElement> 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<FrameworkElement> RltLineList = new List<FrameworkElement>();
- 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<ControlPair> GetPropertyEditors()
- {
- List<ControlPair> list = new List<ControlPair>();
- 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<Line>.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<object> 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;
- }
- }
- }
|