| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616 |
- 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;
- /// <summary>
- /// TheYVal
- /// </summary>
- protected float P1Val;
- protected double P1XPercent;
- protected double P1YPercent;
- protected DrawingSelectionArea SelectionArea;
- public Chart Chart { get; set; }
- private IDrawingToolSpec _drawingToolSpec;
- /// <summary>
- /// PlotOnAllSymbols
- /// </summary>
- 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<ControlPair> AdditionalEditors()
- {
- List<ControlPair> 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<FrameworkElement> 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<FrameworkElement>();
- flag = this.IsTooSmallToShow(owner, aScale);
- List<FrameworkElement> 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<ControlPair> GetPropertyEditors()
- {
- var list = new List<ControlPair>
- {
- new ControlPair
- {
- ControlLeft =
- new TextBlock {Text = LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_Color)},
- ControlRight = new ColorOpacityEditor(this, "Color", "", "")
- }
- };
- List<ControlPair> 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<object> 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<object> args)
- {
- }
- protected abstract void ColorChanged();
- protected abstract List<FrameworkElement> 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<object> { "SAVEDEF" };
- return this.ToXml(list).ToString();
- }
- #endregion Protected Methods
- /// <summary>
- /// Gets the size of the chart font.
- /// </summary>
- /// <returns>System.Double.</returns>
- public double GetChartFontSize()
- {
- return (Chart == null) ? 12f : this.Chart.ChartFontSize;
- }
- #endregion Methods
- }
- }
|