Click here to Skip to main content
15,893,663 members
Articles / Programming Languages / C#

Grandiose Projects 3. Compatibility with Simulink

Rate me:
Please Sign up or sign in to vote.
4.27/5 (11 votes)
8 Feb 2010CPOL23 min read 47.8K   5.9K   38  
Import of Simulink files
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using CommonService;

namespace DiagramUI
{
    /// <summary>
    /// Performer of container UI
    /// </summary>
    static public class ContainerPerformerUI
    {
        /// <summary>
        /// Initialization of containers tools
        /// </summary>
        /// <param name="baseDirectory">Base directory</param>
        /// <param name="tools">Tools</param>
        /// <param name="tabControl">Tab control</param>
        /// <param name="resources">Resources</param>
        static public void InitContainers(string baseDirectory, ToolsDiagram tools, TabControl tabControl,
            Dictionary<string, object>[] resources)
        {
            string cont = baseDirectory;
            if (cont[cont.Length - 1] != Path.DirectorySeparatorChar)
            {
                cont = cont + Path.DirectorySeparatorChar;
            }
            cont = cont + "Containers" +
                Path.DirectorySeparatorChar + "Containers.xml";
            if (!File.Exists(cont))
            {
                return;
            }
            XmlDocument doc = new XmlDocument();
            doc.Load(cont);
            XmlNodeList contPages = doc.GetElementsByTagName("Page");
          //  int k = 0;
            LightDictionary<string, ButtonWrapper[]> dict = new LightDictionary<string, ButtonWrapper[]>();
            foreach (XmlElement page in contPages)
            {
                //int np = 0;
                XmlNodeList list = page.GetElementsByTagName("Aggregate");
                List<ButtonWrapper> buttons = new List<ButtonWrapper>();
                foreach (XmlElement el in list)
                {
                    string ico = AppDomain.CurrentDomain.BaseDirectory + el.Attributes["icon"].Value;
                    Image image = Image.FromFile(ico);
                    //ObjectContainers.ImageList.Images.Add(Image.FromFile(ico));
                    string name = el.Attributes["name"].Value;
                    string hint = el.Attributes["hint"].Value;
                    bool isArrow = el.Attributes["arrow"].Value.Equals("true");
                    ButtonWrapper button = null;
                    if (isArrow)
                    {
                        button = new ButtonWrapper(typeof(LibraryArrowWrapper), name, hint, image, null, true, true);
                    }
                    else
                    {
                        bool b = true;
                        if (el.Attributes["wrapper"] != null)
                        {
                            if (el.GetAttribute("wrapper").Equals("true"))
                            {
                                button = new ButtonWrapper(typeof(LibraryObjectWrapper), name, hint, image, null, true, false);
                                b = false;
                            }
                        }
                        if (b)
                        {
                            button = new ButtonWrapper(typeof(ObjectContainer), name, hint, image, null, true, false);
                        }
                    }
                    buttons.Add(button);
                }
                XmlAttribute an = page.Attributes["pageName"];
                dict.Add(new string[] { an.Value }, new ButtonWrapper[][] { buttons.ToArray() });
                //  TabPage tp = new TabPage(an.Value);
                // tp.ToolTipText = page.Attributes["pageHint"].Value;
                //  tabControl.Controls.Add(tp);
                // tp.Controls.Add(ObjectContainers);
            }
            ButtonWrapper.Add(dict, tabControl, tools, new Size(25, 25), resources, false);
        }
    }
}

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