using Microsoft.VisualBasic.CompilerServices; using MuchInfo.Chart.Data.Interfaces; using MuchInfo.Chart.Data.Models; using MuchInfo.Chart.Infrastructure.Utilities; using MuchInfo.Chart.WPF.Controls.Indicator; using MuchInfo.Chart.WPF.Helpers; using MuchInfo.Chart.WPF.Primitives.Interfaces; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Linq; namespace MuchInfo.Chart.WPF.Primitives { public abstract class PlotBase : IToolTipControlProvider { #region Fields protected Chart mChart; protected string mPendingSourceUID; protected ScaleLayer mScale; private IndicatorModel _indicatorModel; /// /// 指标编辑器转换后绘图数据 /// public IndicatorModel Indicator { get { return _indicatorModel; } set { _indicatorModel = value; } } /// /// mSource /// // private ILineDataSet _outPutSource; private double _plotOpacity; private string _savedAsName; #endregion Fields #region Constructors protected PlotBase() { this.mPendingSourceUID = ""; this._plotOpacity = 1.0; } protected PlotBase(IndicatorModel indicatorModel, Chart parentchart) : this() { this.mChart = parentchart; // _outPutSource = new ChartDataSet(indicatorModel.CalculateDataPoints); this._indicatorModel = indicatorModel; } #endregion Constructors #region Properties #region Public Properties public double PlotOpacity { get { return this._plotOpacity; } set { bool flag = value != this._plotOpacity; if (flag) { this._plotOpacity = value; flag = (this.mChart != null); if (flag) { this.mChart.Refresh(); } } } } public string SavedAsName { get { return this._savedAsName; } set { this._savedAsName = value; } } public ScaleLayer ScaleLayer { get { return this.mScale; } set { this.mScale = value; } } #endregion Public Properties #region Protected Properties ///// ///// 数据源 ///// //protected virtual ILineDataSet mSource //{ // get // { // return this._outPutSource; // } // set // { // var dataChangedEventHandler = new LineDataSetDataChangedEventHandler(this.OnDataChanged); // bool flag = this._outPutSource != null; // if (flag) // { // this._outPutSource.DataChanged -= (dataChangedEventHandler); // } // this._outPutSource = value; // flag = (this._outPutSource != null); // if (flag) // { // this._outPutSource.DataChanged += (dataChangedEventHandler); // } // } //} //public ILineDataSet OutputSource //{ // get { return _outPutSource; } // // set { _outPutSource = value; } //} public IndicatorModel OutputSource { get { return Indicator; } // set { _outPutSource = value; } } #endregion Protected Properties #endregion Properties #region Methods #region Public Methods public TimeSpan CurrentTimeFrame() { bool flag = this.mChart != null; TimeSpan currentTimeFrame = TimeSpan.Zero; if (flag) { currentTimeFrame = this.mChart.CurrentTimeFrame; } return currentTimeFrame; } public Chart GetChart() { return this.mChart; } public object GetControl() { return new IndicatorHierarchyDisplay(this); } public List GetElements(Chart owner, ScaleLayer aScale, IDateScaler dateScale, IValueScaler valScale, Rect aRect) { //bool flag = this.PlotBase_1655.Count == 0; List list; list = this.BuildPlot(owner, aScale, dateScale, valScale, aRect); //if (flag) //{ // list = this.PlotBase_5028(owner, aScale, dateScale, ValScale, aRect); //} //else //{ // list = new List(); // try // { // List.Enumerator enumerator = this.PlotBase_1655.GetEnumerator(); // while (enumerator.MoveNext()) // { // IPlotAddition current = enumerator.Current; // list.AddRange(current.GetPlots(owner, this, aScale, dateScale, ValScale, aRect)); // } // } // finally // { // //List.Enumerator enumerator; // //enumerator.Dispose(); // } // list.AddRange(this.PlotBase_5028(owner, aScale, dateScale, ValScale, aRect)); //} if (list != null) { foreach (var current in list) { current.Opacity = this._plotOpacity; } } return list; } public abstract void InitAsNew(); public abstract void ReInstanceSources(); public void RemovedFromChart() { this.DeleteData(); this.mChart = null; this.mScale = null; // this.mLegendBtn = null; } //public void RemovePlotAddition(IPlotAddition aAdd) //{ // this.PlotBase_1655.Remove(aAdd); // bool flag = this.mChart != null; // if (flag) // { // this.mChart.Invalidate(); // } //} //public void ScanConditionCreated(baseCondition mCondition, Color aColor) //{ // IMQLScanHost currentIndicatorScanHost = MQLMain.CurrentIndicatorScanHost; // bool flag = currentIndicatorScanHost != null; // if (flag) // { // currentIndicatorScanHost.NewIndicatorScanCreated(mCondition, aColor); // } //} //public List SiblingPlots() //{ // List list = new List(); // bool flag = this.mScale != null; // if (flag) // { // try // { // List.Enumerator enumerator = this.mScale.AllPlots().GetEnumerator(); // while (enumerator.MoveNext()) // { // PlotBase current = enumerator.Current; // bool flag2 = current != this; // if (flag2) // { // list.Add(current); // } // } // } // finally // { // //List.Enumerator enumerator; // //enumerator.Dispose(); // } // } // return list; //} public abstract void SourceDataChange(object change); #endregion Public Methods #region Internal Methods /// /// 创建图表 /// internal abstract List BuildPlot(Chart owner, ScaleLayer aScale, IDateScaler dateScale, IValueScaler valScale, Rect aRect); /// /// /// internal abstract void Calculate(); internal void Delete() { this.DeleteData(); var webChart = this.mChart; bool flag = this.mScale != null; if (flag) { this.mScale.RemoveFromChartPane(this); } flag = (webChart != null); if (flag) { webChart.Refresh(); } //this.ClearPlotAdditions(); } /// /// ָ 显示在顶部的标题,弹出框的标题 /// /// internal string Description() { string result = ""; return result; } internal abstract Color GetColor(); /// /// 添加显示到面板中指标数据 /// /// 日期 /// /// /// internal abstract List GetControlPairs(DateTime aDate, bool isDarkBackground, bool isForex); /// /// Gets the control pairs. /// /// A date. /// if set to true [is dark background]. /// The digites. /// List{ControlPair}. internal abstract List GetControlPairs(DateTime aDate, bool isDarkBackground, int digites); internal abstract Color GetPlotColor(); internal void SetDataSource(List sources) { bool flag = Operators.CompareString(this.mPendingSourceUID, "", false) == 0; if (!flag) { try { List.Enumerator enumerator = sources.GetEnumerator(); while (enumerator.MoveNext()) { ILineDataSet current = enumerator.Current; flag = true;// (Operators.CompareString(current.UID(), this.mPendingSourceUID, false) == 0); if (flag) { // this.mSource = current; break; } } } finally { //List.Enumerator enumerator; //enumerator.Dispose(); } } } internal abstract void ShowPlotEdit(FrameworkElement relativeTo); /// /// 添加指标 /// //internal abstract void AddIndicators(); #endregion Internal Methods #region Protected Methods protected void AddToXML(XElement xml, List args) { //bool flag = this.PlotBase_1655.Count > 0; //if (flag) //{ // XElement xElement = new XElement("PLOTADDITIONS"); // try // { // List.Enumerator enumerator = this.PlotBase_1655.GetEnumerator(); // while (enumerator.MoveNext()) // { // IPlotAddition current = enumerator.Current; // xElement.Add(current.ToXML(args)); // } // } // finally // { // //List.Enumerator enumerator; // //enumerator.Dispose(); // } // xml.Add(xElement); //} var flag = (Operators.CompareString(this._savedAsName, "", false) != 0); if (flag) { xml.Add(new XAttribute("SavedName", this._savedAsName)); } xml.Add(new XAttribute("Opacity", this._plotOpacity.ToString())); } protected abstract void DeleteData(); #endregion Protected Methods #region Private Methods private void AddRemoveIndicators(MouseButtonEventArgs e) { //bool flag = this.mChart != null && this.mChart.AllowAddRemoveIndicators; //if (flag) //{ // PopUpMenu popUpMenu = new PopUpMenu(); // popUpMenu.AddItem("Edit", ImageMan.GetImage("PropertiesHS.png"), new EventHandler(this.PlotBase_5065)); // flag = (this is LinePlot && !(this.Calculation() is calcPivotPoints) && !(this.Calculation() is calcIchimoku)); // if (flag) // { // popUpMenu.AddItem("Add Indicator", ImageMan.GetImage("add2.png"), new EventHandler(this.PlotBase_5071)); // } // flag = (this == this.mChart.GetPricePlot()); // if (flag) // { // popUpMenu.AddItem("Comparisons", ImageMan.GetImage("line-chart.png"), new EventHandler(this.PlotBase_5070)); // } // flag = (this.Calculation().DefaultAddMode == eIndicatorAddMode.eRegular); // if (flag) // { // popUpMenu.AddItem("Edit Plot Guides", ImageMan.GetImage("Ruler.png"), new EventHandler(this.PlotBase_5066)); // } // popUpMenu.AddSeperator(); // flag = (FSCServices.ServiceLevelAllowed(FSCServices.enumAlmostFSCServiceLevels.eMassiveScansAndSorts) && this is LinePlot && this.mCalculation != null && MQLSocketMan.IndicatorKeyAllowed(this.mCalculation.RootName())); // if (flag) // { // popUpMenu.AddItem("Scan", ImageMan.GetImage("flash.png"), new EventHandler(this.PlotBase_5078)); // popUpMenu.AddItem("Add Column", ImageMan.GetImage("AddColumn.png"), new EventHandler(this.PlotBase_5079)); // popUpMenu.AddSeperator(); // } // flag = (this.ScaleLayer != null && this.ScaleLayer.ScaleLayer_5525() != null && this.ScaleLayer.ScaleLayer_5525() is ValueScalerArithmetic); // bool flag2; // if (flag) // { // ValueScalerArithmetic valueScalerArithmetic = (ValueScalerArithmetic)this.ScaleLayer.ScaleLayer_5525(); // flag = (this.DataSource() is _125 && this.Calculation() is calcPriceHistory); // if (flag) // { // flag2 = (valueScalerArithmetic.ScaleMode == ValueScalerArithmetic.enumScaleMethod.eArithmetic); // if (flag2) // { // popUpMenu.AddItem("Arithmetic", ImageMan.GetImage("MenuCheck.png"), null); // popUpMenu.AddItem("Log", null, new EventHandler(this.PlotBase_5069)); // } // else // { // popUpMenu.AddItem("Arithmetic", null, new EventHandler(this.PlotBase_5068)); // popUpMenu.AddItem("Log", ImageMan.GetImage("MenuCheck.png"), null); // } // popUpMenu.AddItem("More Scaling...", null, new EventHandler(this.PlotBase_5067)); // } // else // { // popUpMenu.AddItem("Scaling...", null, new EventHandler(this.PlotBase_5067)); // } // } // flag2 = (this != this.mChart.GetPricePlot()); // if (flag2) // { // popUpMenu.AddSeperator(); // popUpMenu.AddItem("Save", ImageMan.GetImage("Save24.png"), new EventHandler(this.PlotBase_5072)); // popUpMenu.AddSeperator(); // popUpMenu.AddItem("Remove", ImageMan.GetImage("DeleteHS.png"), new EventHandler(this.PlotBase_5073)); // } // PopUpMenu arg_3BB_0 = popUpMenu; // Point offset = new Point(-3.0, -5.0); // arg_3BB_0.Show(e, offset); //} } private void OnDataChanged(object change) { bool flag = change is PlotDeletingDataChange; if (flag) { this.Delete(); } else { this.SourceDataChange(RuntimeHelpers.GetObjectValue(change)); } } //private void PlotBase_5066(object sender, EventArgs e) //{ // PlotGuideLineEditor plotGuideLineEditor = new PlotGuideLineEditor(); // plotGuideLineEditor.Show(this); //} //private void PlotBase_5067(object sender, EventArgs e) //{ // bool flag = e is MouseEventArgs; // if (flag) // { // ValueScaleEditor valueScaleEditor = new ValueScaleEditor(this.ScaleLayer); // valueScaleEditor.Show((MouseEventArgs)e); // } //} //private void PlotBase_5068(object sender, EventArgs e) //{ // bool flag = this.ScaleLayer != null && this.ScaleLayer.ScaleLayer_5525() is ValueScalerArithmetic; // if (flag) // { // ((ValueScalerArithmetic)this.ScaleLayer.ScaleLayer_5525()).ScaleMode = ValueScalerArithmetic.enumScaleMethod.eArithmetic; // } //} //private void PlotBase_5069(object sender, EventArgs e) //{ // bool flag = this.ScaleLayer != null && this.ScaleLayer.ScaleLayer_5525() is ValueScalerArithmetic; // if (flag) // { // ((ValueScalerArithmetic)this.ScaleLayer.ScaleLayer_5525()).ScaleMode = ValueScalerArithmetic.enumScaleMethod.eLog; // } //} //private void PlotBase_5070(object sender, EventArgs e) //{ // bool flag = e is MouseEventArgs; // if (flag) // { // WebChartEditor webChartEditor = new WebChartEditor(this.mChart, WebChartEditor.DialogStyle.eCompare); // webChartEditor.DoWhiteBackground(); // webChartEditor.Show((MouseEventArgs)e); // } //} //private void PlotBase_5071(object sender, EventArgs e) //{ // bool flag = e is MouseEventArgs; // if (flag) // { // AddIndicatorDialog addIndicatorDialog = new AddIndicatorDialog(); // addIndicatorDialog.Show(this.mChart, this, (MouseEventArgs)e); // } //} //private void PlotBase_5072(object sender, EventArgs e) //{ // SaveIndicatorDialog saveIndicatorDialog = new SaveIndicatorDialog(); // saveIndicatorDialog.ShowDialog((MouseEventArgs)e, this); //} private void OnDelete(object sender, EventArgs e) { this.Delete(); } private void RefreshChart() { this.Calculate(); bool flag = this.mChart != null; if (flag) { this.mChart.Refresh(); } } private void ShowPlotEdit(object sender, EventArgs e) { // this.ShowPlotEdit(this.mLegendBtn); } #endregion Private Methods #endregion Methods #region Nested Types private class PlotBase_260 { #region Fields public List PlotBase_260_1661; public List PlotBase_260_1662; #endregion Fields #region Constructors public PlotBase_260() { this.PlotBase_260_1661 = new List(); this.PlotBase_260_1662 = new List(); } #endregion Constructors #region Other //public void PlotBase_260_5092() //{ // dlgTestMQL dlgTestMQL = new dlgTestMQL(); // dlgTestMQL.Show(this.PlotBase_260_1663, this.PlotBase_260_1664, this.PlotBase_260_1661, this.PlotBase_260_1662); //} #endregion Other } #endregion Nested Types #region Other //public abstract XElement ToXML(List args); #endregion Other } }