Click here to Skip to main content
15,886,258 members
Articles / Programming Languages / C#

Integration: Mechanics + Hydraulics + Navigation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (46 votes)
3 Feb 2011CPOL21 min read 61.6K   6.1K   88  
Sample of integration of branches of engineering.
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 DataPerformer.Helpers.DataPerformerCollectionStateTransformer)
                {
                    return new DataPerformerUI.Forms.FormDataPerformerCollectionStateTransformer(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 DataPerformer.Helpers.KalmanFilter)
                {
                    return new DataPerformerUI.Forms.FormKalmanFilter(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

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions