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