using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using CategoryTheory;
using DiagramUI;
using DiagramUI.Labels;
using Diagram.UI.Factory;
using Diagram.UI.Interfaces.Labels;
using Diagram.UI.Interfaces;
using DiagramUI.Interfaces;
using DataPerformer;
using DataPerformerUI;
namespace BasicEngineeringUIFactory
{
/// <summary>
/// Minimal factory
/// </summary>
public class MinimalFactory : EmptyUIFactory
{
#region Fields
internal static readonly MinimalFactory Object = new MinimalFactory();
private IToolsDiagram tools;
/// <summary>
/// Button of library
/// </summary>
protected PaletteButton libraryButton;
#endregion
#region Ctor
private MinimalFactory()
{
}
#endregion
#region IUIFactory Members
/// <summary>
/// Object creation
/// </summary>
/// <param name="button">Corresponding button</param>
/// <returns>The object</returns>
public override ICategoryObject CreateObject(IPaletteButton button)
{
if (button.ReflectionType.Equals(typeof(DataPerformer.DataConsumer)))
{
return new DataConsumer(0);
}
return null;
}
/// <summary>
/// Creates property editor from desktop component
/// </summary>
/// <param name="comp">The component</param>
/// <returns>The property editor</returns>
public override object CreateForm(INamedComponent comp)
{
// Checks whether component is an arrow
if (comp is IArrowLabel)
{
IArrowLabel lab = comp as IArrowLabel;
ICategoryArrow arrow = lab.Arrow;
/*if (arrow is Motion6D.MechanicalAggregateLink)
{
return new MotionUI.FormAggregateLink(lab);
}*/
}
// The component is an object
if (comp is IObjectLabel)
{
IObjectLabel lab = comp as IObjectLabel;
// The object of component
ICategoryObject obj = lab.Object;
Form form = ToolsDiagram.CreateEditorForm(obj);
if (form != null)
{
return form;
}
// Creation of iterator property editor
if (obj is Regression.IteratorGLM)
{
return new FormIterateGLM(lab);
}
// Creation of VectorFormulaConsumer property editor
if (obj is VectorFormulaConsumer)
{
return new DataPerformerUI.Forms.FormVectorConsumer(lab);
}
if (obj is MatrixAssembly)
{
return new DataPerformerUI.FormMatrixAssembly(lab);
}
if (obj is VectorAssembly)
{
return new FormVectorAssembly(lab);
}
if (obj is ArrayDisassembly)
{
return new FormArrayDisassembly(lab);
}
if (obj is ArrayTransformer)
{
return new DataPerformerUI.Forms.FormArrayTransformer(lab);
}
if (obj is DataPerformer.ObjectTransformer)
{
return new FormObjectTransformer(lab);
}
if (obj is Chart.Objects.DrawSeries)
{
return new DataPerformerUI.FormPointCollection(lab);
}
/*if (obj is DataTableSelection.DataTableSeries)
{
// return new FormSeriesTable(lab);
}*/
if (obj is DataPerformer.Series)
{
//return new FormSeries(lab);
}
/* if (obj is FunctionAccumulator)
{
return new FormFuncAccumulator(lab);
}*/
if (obj is Regression.CombinedSelection)
{
return new FormCombinedSelection(lab);
}
/* if (obj is DataConsumer)
{
DataConsumer consumer = obj as DataConsumer;
if (consumer.GetType().Equals(typeof(DataConsumer)))
{
return new DataPerformerUI.Forms.FormGraph((consumer, lab);
}
}*/
if (obj is FormulaFilterIterator)
{
return new DataPerformerUI.FormIteratorFilter(lab);
}
if (obj is DifferentialEquationSolver)
{
return new DataPerformerUI.Forms.FormDiffEquation(lab);
}
if (obj is Recursive)
{
return new DataPerformerUI.Forms.FormRecursive(lab);
}
if (obj is Regression.XmlSelectionCollection)
{
return new DataPerformerUI.FormXmlSelection(lab);
}
if (obj is Regression.AliasRegression)
{
return new DataPerformerUI.Forms.FormAliasRegression(lab);
}
}
return null;
}
public override IObjectLabelUI CreateObjectLabel(IPaletteButton button)
{
return CreateObjectLabel(button.ReflectionType, button.Kind, button.ButtonImage as System.Drawing.Image);
}
public override IToolsDiagram Tools
{
set { tools = value; }
}
public override void CheckOrder(IDesktop desktop)
{
Control desk = desktop as Control;
foreach (Control c in desk.Controls)
{
if (!(c is ArrowLabel))
{
continue;
}
ArrowLabel l = c as ArrowLabel;
ICategoryArrow a = l.Arrow;
if (!(a is DataLink))
{
continue;
}
if (l.Source.Root.Ord < l.Target.Root.Ord)
{
a.Throw(new Exception(DataLink.SetProviderBefore));
}
}
}
public override IObjectLabelUI CreateLabel(ICategoryObject obj)
{
if (obj is IProperties)
{
IProperties p = obj as IProperties;
object pr = p.Properties;
if (pr != null)
{
if (pr is IObjectLabelUI)
{
return pr as IObjectLabelUI;
}
}
}
Type t = obj.GetType();
if (t.Equals(typeof(DiagramUI.ObjectsCollection)))
{
DiagramUI.ObjectsCollection coll = obj as DiagramUI.ObjectsCollection;
if (coll.Type.Equals(typeof(Regression.AliasRegression)))
{
return UserControlLabel.CreateLabel(new DataPerformerUI.Labels.FisherLabel(), null, false);
}
}
return CreateObjectLabel(t, "", null);
}
public override IArrowLabelUI CreateLabel(ICategoryArrow arr)
{
return null;
}
#endregion
#region Members
/// <summary>
/// Button of library
/// </summary>
internal PaletteButton LibraryButton
{
set
{
libraryButton = value;
}
}
private IObjectLabelUI CreateObjectLabel(Type t, string kind, System.Drawing.Image image)
{
if (t == null)
{
return null;
}
if (t.GetInterface(typeof(DataPerformer.Interfaces.INamedCoordinates).FullName) != null)
{
return DataPerformerUI.Labels.NamedlSeriesLabel.Create(t);
}
if (t.Equals(typeof(DataConsumer)))
{
return UserControlBaseLabel.Create(typeof(DataPerformerUI.Labels.GraphLabel), false);
}
if (t.Equals(typeof(Series)))
{
return UserControlLabel.CreateLabel(new DataPerformerUI.Labels.SeriesLabel(), image, false);
}
/*if (t.Equals(typeof(SeriesVectorData)))
{
return UserControlLabel.CreateLabel(new DataPerformerUI.Labels.SeriesVectorLabel(), image, false);
}*/
if (t.Equals(typeof(Chart.Objects.DrawSeries)))
{
return UserControlLabel.CreateLabel(new DataPerformerUI.Labels.DrawSeriesLabel(), image, false);
}
if (t.Equals(typeof(DataPerformer.Table2D)))
{
return UserControlLabel.CreateLabel(new DataPerformerUI.Labels.Table2DLabel(), image, false);
}
if (t.Equals(typeof(DataPerformer.Advanced.DynamicFunction)))
{
return UserControlBaseLabel.Create(typeof(DataPerformerUI.Labels.DelayAccumulatorLabel), true);
}
if (t.Equals(typeof(DataPerformer.FunctionAccumulator)))
{
return UserControlBaseLabel.Create(typeof(DataPerformerUI.Labels.FuncAccumulatorLabel), true);
}
if (t.Equals(typeof(DataPerformer.Advanced.Accumulators.AccumulatorSeriesArgument)))
{
return UserControlBaseLabel.Create(typeof(DataPerformerUI.Labels.AccumulatorSeriesArgumentLabel), true);
}
if (t.Equals(typeof(DiagramUI.ObjectsCollection)))
{
if (kind.Equals("Regression.AliasRegression,AliasRegression"))
{
return UserControlLabel.CreateLabel(new DataPerformerUI.Labels.FisherLabel(), image, false);
}
}
return null;
}
#endregion
}
}