using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using CategoryTheory;
using BaseTypes.Interfaces;
using BaseTypes;
using DiagramUI;
using DiagramUI.Labels;
using DataPerformer.Interfaces;
namespace DataPerformer
{
/// <summary>
/// Table of three parameters
/// This table uses linear interpolation
/// </summary>
[Serializable()]
public class Table3D : DataPerformer.Basic.Table3D, ICategoryObject, IDataConsumer, IMeasurements, IObjectOperation,
IPowered, IPostSetArrow
{
#region Fields
/// <summary>
/// Change input event
/// </summary>
private event Action onChangeInput = () => { };
/// <summary>
/// Associated object
/// </summary>
private object obj;
/// <summary>
/// Output measurements
/// </summary>
private IMeasure[] output = null;
/// <summary>
/// Arguments
/// </summary>
private string[] arguments;
/// <summary>
/// Input measurements
/// </summary>
private IMeasure[] input = new IMeasure[2];
/// <summary>
/// The x, y - arguments
/// </summary>
private readonly string[] xy = new string[] { "x", "y" };
/// <summary>
/// Measurements
/// </summary>
private List<IMeasurements> measurements = new List<IMeasurements>();
/// <summary>
/// The "is updated" sign
/// </summary>
private bool isUpdated;
/// <summary>
/// The "has derivation" sign
/// </summary>
private bool hasDerivation = true;
private const double type = 0;
private readonly object[] types = new object[] { new ArrayReturnType((double)0, new int[] { 2 }, false) };
#endregion
#region Ctor
/// <summary>
/// Default constructor
/// </summary>
public Table3D()
{
}
/// <summary>
/// Deserilaization constructor
/// </summary>
/// <param name="info">Serialization Info</param>
/// <param name="context">Streaming Context</param>
protected Table3D(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Func<object> fn = () => { return this; };
output = new IMeasure[]{ new Measure(this, fn, "Function")};
/*arguments = (string[])info.GetValue("Arguments", typeof(string[]));
Double a = 0;
output[0] = new MeasureDerivation(a, new Func<object>(GetFunction), new Measure(GetDerivation, "Der_Value"), "Value");
Func<object> fn = () => { return this; };
output[1] = new Measure(this, fn, "Function");
try
{
throwsOutOfRangeException =
info.GetBoolean("ThrowsOutOfRangeException");
}
catch (Exception ex)
{
ex.ShowError(10);
}*/
}
#endregion
#region ICategoryObject Members
ICategory ICategoryObject.Category
{
get { return null; }
}
ICategoryArrow ICategoryObject.Id
{
get { return null; }
}
#endregion
#region IAssociatedObject Members
object IAssociatedObject.Object
{
get
{
return obj;
}
set
{
obj = value;
}
}
#endregion
#region IDataConsumer Members
void IDataConsumer.Add(IMeasurements measurements)
{
this.measurements.Add(measurements);
}
void IDataConsumer.Remove(IMeasurements measurements)
{
this.measurements.Remove(measurements);
}
void IDataConsumer.UpdateChildrenData()
{
measurements.UpdateChildrenData();
}
int IDataConsumer.Count
{
get { return measurements.Count; }
}
IMeasurements IDataConsumer.this[int n]
{
get { return measurements[n]; }
}
void IDataConsumer.Reset()
{
this.FullReset();
}
event Action IDataConsumer.OnChangeInput
{
add { onChangeInput += value; }
remove { onChangeInput -= value; }
}
#endregion
#region IMeasurements Members
int IMeasurements.Count
{
get { return 1; }
}
IMeasure IMeasurements.this[int n]
{
get { return output[n]; }
}
void IMeasurements.UpdateMeasurements()
{
/*
if (input[0] == null)
{
return;
}
if (isUpdated)
{
return;
}
try
{
IDataConsumer c = this;
c.UpdateChildrenData();
Calculate((double)input[0].Parameter(), (double)input[1].Parameter());
if (hasDerivation)
{
for (int i = 0; i < 2; i++)
{
IDerivation der = input[i] as IDerivation;
result[1] += dx[i] * (double)der.Derivation.Parameter();
}
}
isUpdated = true;
}
catch (Exception e)
{
e.ShowError(10);
this.Throw(e);
}*/
}
bool IMeasurements.IsUpdated
{
get
{
return isUpdated;
}
set
{
isUpdated = value;
}
}
#endregion
#region IObjectOperation Members
object[] IObjectOperation.InputTypes
{
get { return types; }
}
object IObjectOperation.this[object[] x]
{
get
{
object[] o = x[0] as object[];
return Calculate((double)o[0], (double)o[1], (double)o[2]);
}
}
object IObjectOperation.ReturnType
{
get { return type; }
}
bool IPowered.IsPowered
{
get { return false; }
}
#endregion
#region IPostSetArrow Members
void IPostSetArrow.PostSetArrow()
{
try
{
AcceptArguments();
}
catch (Exception ex)
{
ex.ShowError(10);
}
}
#endregion
#region Specific Members
/// <summary>
/// Comments
/// </summary>
public ICollection Comments
{
get
{
return PureDesktopPeer.Deserialize(comments) as ICollection;
}
set
{
comments = PureDesktopPeer.Serialize(value);
}
}
/// <summary>
/// Arguments
/// </summary>
public string[] Arguments
{
get
{
return arguments;
}
}
/// <summary>
/// Pre initialization
/// </summary>
protected override void PreInit()
{
arguments = new string[] { "", "" };
}
/// <summary>
/// Accepts arguments
/// </summary>
private void AcceptArguments()
{
foreach (IMeasurements measurements in this.measurements)
{
IAssociatedObject cont = measurements as IAssociatedObject;
INamedComponent c = cont.Object as INamedComponent;
string name = c.Name;
for (int i = 0; i < measurements.Count; i++)
{
IMeasure measure = measurements[i];
string p = name + "." + measure.Name;
for (int j = 0; j < 2; j++)
{
if (arguments[j].Equals(p))
{
input[j] = measure;
break;
}
}
}
}
for (int i = 0; i < 2; i++)
{
if (arguments[i].Equals("Time"))
{
input[i] = DataPerformer.StaticExtensionDataPerformerBase.Factory.TimeProvider.TimeMeasure;
}
}
hasDerivation = true;
for (int i = 0; i < input.Length; i++)
{
IDerivation der = input[i] as IDerivation;
if (der == null)
{
hasDerivation = false;
break;
}
}
}
#endregion
}
}