using MuchInfo.Chart.Data; using MuchInfo.Chart.Data.EnumTypes; using MuchInfo.Chart.Infrastructure.Controls; using MuchInfo.Chart.Infrastructure.Helpers; using MuchInfo.Chart.Infrastructure.Utilities; 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.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Xml.Linq; namespace MuchInfo.Chart.WPF.Primitives.Drawing { public abstract class Drawing1PointBase : IDrawingTool { #region Fields protected object mAnchorByPercent; protected Color mColor; protected Rect mLastRect; protected ScaleLayer mLastScale; protected double mLastX1; protected double mLastY1; protected bool mSaveByPercent; protected DateTime P1Date; /// /// TheYVal /// protected float P1Val; protected double P1XPercent; protected double P1YPercent; protected DrawingSelectionArea SelectionArea; public Chart Chart { get; set; } private IDrawingToolSpec _drawingToolSpec; /// /// PlotOnAllSymbols /// private bool _plotOnAllSymbols; private double _lastX1; private double _lastY1; #endregion Fields #region Constructors protected Drawing1PointBase() { this.P1XPercent = 0.0; this.P1YPercent = 0.0; this.mSaveByPercent = false; this.mColor = Colors.Red; this._plotOnAllSymbols = false; } #endregion Constructors #region Properties #region Public Properties public Color Color { get { return this.mColor; } set { bool flag = !this.mColor.Equals(value); if (flag) { this.mColor = value; this.ColorChanged(); //this.PropertyChanged(); } } } public IDrawingToolSpec OwnerSpec { get { return this._drawingToolSpec; } set { this._drawingToolSpec = value; } } public bool PlotOnAllSymbols { get { return this._plotOnAllSymbols; } set { bool flag = value != this._plotOnAllSymbols; if (flag) { this._plotOnAllSymbols = value; this.PropertyChanged(); } } } public abstract string RootName { get; } public bool SaveByPercent { get { return this.mSaveByPercent; } set { bool flag = value != this.mSaveByPercent; if (flag) { this.mSaveByPercent = value; //this.PropertyChanged(); } } } public float YValue { get { return this.P1Val; } set { bool flag = this.P1Val != value; if (flag) { this.P1Val = value; IDateScaler dateScaler = this.Chart.DateScaler; this.mLastX1 = (double)dateScaler.XforDate(this.P1Date); this.mLastY1 = (double)this.mLastScale.GetRightValueScaler().ScaledY(this.P1Val, this.mLastRect); this.P1YPercent = (this.mLastY1 - this.mLastRect.Left) / this.mLastRect.Height; this.MoveDrawingToNewLocations(this.mLastRect); this.PropertyChanged(); } } } #endregion Public Properties #region Internal Properties internal float TheYVal { get { return this.P1Val; } set { this.P1Val = value; } } #endregion Internal Properties #endregion Properties #region Indexers public Point this[int aIndex] { get { bool flag = aIndex == 0; Point result = new Point(); if (flag) { Point point = new Point(this.mLastX1, this.mLastY1); result = point; } return result; } set { //加上左边纵坐标位移 var offset = this.Chart.GetChartPanelOffset(); DateTime p1Date = this.Chart.DateScaler.OriginalDateFromX((float)value.X + (float)offset); float p1Val = this.mLastScale.GetRightValueScaler().ValueFromPercent((float)(1.0 - value.Y / this.mLastRect.Height)); bool flag = aIndex == 0; if (flag) { this.P1Date = p1Date; this.P1Val = p1Val; this.mLastX1 = value.X; this.mLastY1 = value.Y; this.P1XPercent = (value.X + offset - this.mLastRect.Top) / this.mLastRect.Width; this.P1YPercent = (value.Y - this.mLastRect.Left) / this.mLastRect.Height; this.MoveDrawingToNewLocations(this.mLastRect); } } } #endregion Indexers #region Methods #region Public Methods public abstract string Abbreviation(); public virtual List AdditionalEditors() { List result = null; return result; } public DateTime aP1Date() { return this.P1Date; } public float aP1Val() { return this.P1Val; } public float aP1XPercent() { return (float)this.P1XPercent; } public float aP1YPercent() { return (float)this.P1YPercent; } public abstract bool CanPlotOnAllSymbols(); public abstract bool CanSaveByPercent(); public abstract IDrawingTool Clone(); public void Delete() { bool flag = this._drawingToolSpec != null; if (flag) { this._drawingToolSpec.DeleteTool(); } } public abstract string Description(); public void FromInfo(DrawingToolInfo info) { bool flag = info.P1Date.HasValue; if (flag) { this.P1Date = info.P1Date.Value; } flag = info.P1Val.HasValue; if (flag) { this.P1Val = info.P1Val.Value; } flag = info.Color1.HasValue; if (flag) { this.mColor = ColorHelper.ColorFromInt(info.Color1.Value); } flag = this.mSaveByPercent; //if (flag) //{ // IL_8B: flag = (info.P2Val.HasValue && info.P3Val.HasValue); if (flag) { this.mSaveByPercent = true; this.P1XPercent = (double)info.P2Val.Value; this.P1YPercent = (double)info.P3Val.Value; } else { this.mSaveByPercent = false; } this._plotOnAllSymbols = info.DrawOnAllSymbols; this.AddFromInfo(info); return; //} //goto IL_8B; } public void FromXml(XElement node) { var flag = node.Attribute("D1") != null; if (flag) { this.P1Date = new DateTime(long.Parse(node.Attribute("D1").Value)); } flag = (node.Attribute("V1") != null); if (flag) { this.P1Val = XMLHelp.ParseSingle(node.Attribute("V1").Value); } flag = (node.Attribute("Clr") != null); if (flag) { this.mColor = ColorHelper.ColorFromString(node.Attribute("Clr").Value); } flag = (node.Attribute("ALS") != null); if (flag) { this._plotOnAllSymbols = bool.Parse(node.Attribute("ALS").Value); } this.AddFromXml(node); } public void GetDrawingInfo(DrawingToolInfo info) { info.P1Date = this.P1Date; info.P1Val = this.P1Val; info.Color1 = ColorHelper.ColorToInt(this.mColor); info.DrawOnAllSymbols = this._plotOnAllSymbols; bool flag = this.mSaveByPercent; if (flag) { info.P2Val = (float)this.P1XPercent; info.P3Val = (float)this.P1YPercent; } else { info.P2Val = default(float?); info.P3Val = default(float?); } this.AddToInfo(info); } public List GetPlots(Chart owner, ScaleLayer aScale, Rect aRect, bool DrawHandles) { this.Chart = owner; this.mLastScale = aScale; this.mLastRect = aRect; bool flag = !ColorHelper.ColorIsContrasting(this.mColor, ColorHelper.GetBrushColor(owner.ChartBackground)); if (flag) { this.mColor = ColorHelper.InverseColor(this.mColor); } var list = new List(); flag = this.IsTooSmallToShow(owner, aScale); List result; if (flag) { result = list; } else { IDateScaler dateScaler = owner.DateScaler; flag = !this.mSaveByPercent; if (flag) { this.mLastX1 = (double)dateScaler.XforDate(this.P1Date); this.mLastY1 = (double)aScale.GetRightValueScaler().ScaledY(this.P1Val, aRect); this.P1XPercent = (this.mLastX1 - this.mLastRect.Top) / this.mLastRect.Width; this.P1YPercent = (this.mLastY1 - this.mLastRect.Left) / this.mLastRect.Height; } else { this.mLastX1 = aRect.Left + aRect.Width * this.P1XPercent; this.mLastY1 = aRect.Top + aRect.Height * this.P1YPercent; DateTime p1Date = this.Chart.DateScaler.DateFromX((float)this.mLastX1); float p1Val = this.mLastScale.GetRightValueScaler().ValueFromPercent((float)(1.0 - this.mLastY1 / this.mLastRect.Height)); this.P1Date = p1Date; this.P1Val = p1Val; } bool arg_1E8_0; if (this.mLastX1 <= 30000.0 && this.mLastX1 >= -30000.0) { if (this.mLastY1 <= 30000.0) { if (this.mLastY1 >= -30000.0) { arg_1E8_0 = false; goto IL_1E8; } } } arg_1E8_0 = true; IL_1E8: flag = arg_1E8_0; if (flag) { result = list; } else { flag = (this.SelectionArea == null); if (flag) { this.SelectionArea = new DrawingSelectionArea(this, owner); } list.AddRange(this.GetDrawingPlots(owner, aScale, aRect)); flag = (DrawHandles && this.ShowDragHandle()); if (flag) { list.AddRange(this.SelectionArea.GetControls()); } result = list; } } return result; } public virtual List GetPropertyEditors() { var list = new List { new ControlPair { ControlLeft = new TextBlock {Text = LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_Color)}, ControlRight = new ColorOpacityEditor(this, "Color", "", "") } }; List list2 = this.AdditionalEditors(); bool flag = list2 != null; if (flag) { list.AddRange(list2); } //flag = this.CanPlotOnAllSymbols(); //if (flag) //{ // list.Add(new ControlPair // { // ControlRight = new BooleanEditor(this, "PlotOnAllSymbols", "Draw on all Symbols") // }); //} flag = this.CanSaveByPercent(); if (flag) { list.Add(new ControlPair() { ControlLeft = new BooleanEditor(this, "SaveByPercent", LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_SaveByPercent)) }); } return list; } public abstract ImageSource Icon(); public void InitDone(MouseEventArgs e) { } public void InitPoint(DateTime aDate, float aVal, ScaleLayer aScale, Rect aRect, Point p) { this.mLastRect = aRect; this.mLastScale = aScale; this.P1Date = aDate; this.P1Val = aVal; this.P1XPercent = (p.X - this.mLastRect.Top) / this.mLastRect.Width; this.P1YPercent = (p.Y - this.mLastRect.Left) / this.mLastRect.Height; } public bool IsTooSmallToShow(Chart owner, ScaleLayer aScale, DrawingToolInfo Info) { return false; } public bool IsTooSmallToShow(Chart owner, ScaleLayer aScale) { return false; } public abstract string MenuDescription(); public void MovePlot(Point initialPosition, Point currentPosition) { double num = currentPosition.X - initialPosition.X; double num2 = currentPosition.Y - initialPosition.Y; var value = new Point(this._lastX1 + num, this._lastY1 + num2); value.X = Math.Max(0, value.X); value.Y = Math.Max(0, value.Y); this[0] = value; } public void MovePlot(Point initialPosition, Point currentPosition, Point maxPoint) { double num = currentPosition.X - initialPosition.X; double num2 = currentPosition.Y - initialPosition.Y; var value = new Point(this._lastX1 + num, this._lastY1 + num2); value.X = Math.Max(0, value.X); value.X = Math.Min(maxPoint.X, value.X); value.Y = Math.Max(0, value.Y); value.Y = Math.Min(maxPoint.Y, value.Y); this[0] = value; } public void MoveSecondPoint(DateTime aDate, float aVal, Point p) { this.P1Date = aDate; this.P1Val = aVal; this.P1XPercent = (p.X - this.mLastRect.Top) / this.mLastRect.Width; this.P1YPercent = (p.Y - this.mLastRect.Left) / this.mLastRect.Height; } public void PrepareToMove() { this._lastX1 = this.mLastX1; this._lastY1 = this.mLastY1; } public void PropertyChanged() { bool flag = this._drawingToolSpec != null; if (flag) { this._drawingToolSpec.ToolChanged(this); } } public void ShowEditor(MouseEventArgs mouseargs) { bool flag = this.Chart == null; if (!flag) { var drawingToolEditor = new DrawingToolEditor(this); drawingToolEditor.Show(mouseargs); } } public abstract DrawingToolType ToolType(); public XElement ToXml(List args) { var xElement = new XElement(this.RootName); var flag = args == null || !args.Contains("SAVEDEF"); if (flag) { xElement.Add(new XAttribute("D1", this.P1Date.Ticks.ToString())); xElement.Add(new XAttribute("V1", XMLHelp.NumToString(this.P1Val))); } xElement.Add(new XAttribute("Clr", this.mColor.ToString())); xElement.Add(new XAttribute("ALS", this._plotOnAllSymbols.ToString())); this.AddToXml(xElement, args); return xElement; } #endregion Public Methods #region Protected Methods protected virtual void AddFromInfo(DrawingToolInfo info) { } protected virtual void AddFromXml(XElement xml) { } protected virtual void AddToInfo(DrawingToolInfo info) { } protected virtual void AddToXml(XElement xml, List args) { } protected abstract void ColorChanged(); protected abstract List GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect); protected abstract void MoveDrawingToNewLocations(Rect aRect); protected virtual bool ShowDragHandle() { return true; } public string GetXmlForDefault() { var list = new List { "SAVEDEF" }; return this.ToXml(list).ToString(); } #endregion Protected Methods /// /// Gets the size of the chart font. /// /// System.Double. public double GetChartFontSize() { return (Chart == null) ? 12f : this.Chart.ChartFontSize; } #endregion Methods } }