Exemplo n.º 1
0
        void DrawCircle(XElement element, Graphics graphics)
        {
            int[] pos = SimulinkXmlParser.GetPosition(element);
            Pen   pen = di.GetPen(element);

            graphics.DrawEllipse(GetPen(element), pos[0], pos[1], pos[2] - pos[0], pos[3] - pos[1]);
        }
Exemplo n.º 2
0
        void ProcessBrunch(Path path, int[] begin, XElement element)
        {
            int[] x = new int[begin.Length];
            Array.Copy(begin, x, x.Length);
            int[]   y  = new int[] { 0, 0 };//x[0], x[1]};
            int[][] pp = SimulinkXmlParser.GetPoints(element);
            path.Add(y);
            if (pp != null)
            {
                foreach (int[] p in pp)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        y[i] += p[i];
                    }
                    path.Add(y);
                }
            }
            string b  = element.GetAttributeLocal(SimulinkXmlParser.SourceTarget[1]);
            string pb = element.GetAttributeLocal(SimulinkXmlParser.SourceTargetPorts[1]);

            if (b.Length > 0)
            {
                PortIO ff = GetConnectionPort(b, pb, true);
                path.Out = ff;
            }
        }
Exemplo n.º 3
0
        void DrawTriangle(XElement element, Graphics graphics)
        {
            int[] pos = SimulinkXmlParser.GetPosition(element);
            Pen   pen = di.GetPen(element);

            Point[] p = new Point[] { new Point(pos[0], pos[1]), new Point(pos[0], pos[3]), new Point(pos[2], (pos[1] + pos[3]) / 2) };
            graphics.DrawPolygon(pen, p);
        }
Exemplo n.º 4
0
        string GetShowName(XElement element)
        {
            string sn = element.GetAttributeLocal(ShowName);

            if (sn.ToLower().Contains(off))
            {
                return(null);
            }
            return(SimulinkXmlParser.GetName(element));
        }
Exemplo n.º 5
0
        int[] GetPort(XElement element, string port, bool input)
        {
            string blockType = SimulinkXmlParser.GetBlockType(element);
            string icon      = element.GetAttributeLocal("IconShape");

            if (blockType.Equals("Sum") & icon.Equals("round"))
            {
                return(GetSumPort(element, port, input));
            }
            return(GetDefaultPort(element, port, input));
        }
Exemplo n.º 6
0
 void DrawRect(XElement element, Graphics graphics)
 {
     try
     {
         int[] pos = SimulinkXmlParser.GetPosition(element);
         Pen   pen = di.GetPen(element);
         graphics.DrawRectangle(GetPen(element), pos[0], pos[1], pos[2] - pos[0], pos[3] - pos[1]);
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 7
0
        void DrawTransferFunc(XElement element, Graphics graphics)
        {
            try
            {
                int[]    pos  = SimulinkXmlParser.GetPosition(element);
                string[] snd  = new string[2];
                SizeF[]  size = new SizeF[2];
                Font     font = GetFont(element);
                float    w    = 0;

                for (int i = 0; i < 2; i++)
                {
                    string[] ss = ParseString(
                        element.GetAttributeLocal(SimulinkXmlParser.Fraction[i]));
                    string str = "";
                    for (int j = 0; j < ss.Length; j++)
                    {
                        if (j > 0)
                        {
                            str += " + ";
                        }
                        str += ss[j];
                        if (j < ss.Length - 1)
                        {
                            str += "s";
                        }
                    }
                    snd[i] = str;
                    SizeF siz = graphics.MeasureString(str, font);
                    if (w < siz.Width)
                    {
                        w = siz.Width;
                    }
                    size[i] = siz;
                }
                int cx  = (pos[0] + pos[2]) / 2;
                int cy  = (pos[1] + pos[3]) / 2;
                int w2  = (int)(w / 2);
                Pen pen = GetPen(element);
                graphics.DrawLine(pen, cx - w2, cy, cx + w2, cy);
                int[] yy    = new int[] { cy - (int)size[0].Height - 1, cy + 1 };
                Brush brush = GetForeBrush(element);
                for (int i = 0; i < 2; i++)
                {
                    float x = (float)cx - size[i].Width / 2;
                    graphics.DrawString(snd[i], font, brush, x, (float)yy[i]);
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 8
0
 int IBlockCodeCreator.GetInternalDimension(Block block)
 {
     if (block.Type.Equals("TransferFcn"))
     {
         int[] k = SimulinkXmlParser.TransformFuncDegree(block.Element);
         return(k[1] - 1);
     }
     if (block.Type.Equals("Integrator"))
     {
         return(1);
     }
     return(0);
 }
Exemplo n.º 9
0
        void ProcessArrow(XElement element)
        {
            List <int[]> pstl = new List <int[]>();

            int[] xx   = null;
            Path  path = null;

            for (int i = 0; i < 2; i++)
            {
                string b = element.GetAttributeLocal(SimulinkXmlParser.SourceTarget[i]);
                string p = element.GetAttributeLocal(SimulinkXmlParser.SourceTargetPorts[i]);
                if (b.Length == 0)
                {
                    break;
                }
                PortIO pio = GetConnectionPort(b, p, i == 1);
                if (i == 0)
                {
                    path           = new Path(pio);
                    paths[element] = path;
                }
                else
                {
                    path.Out = pio;
                }
            }
            int[][] pp = SimulinkXmlParser.GetPoints(element);
            xx = new int[] { 0, 0 };
            if (pp != null)
            {
                //   Array.Copy(pp[0], xx, xx.Length);
                //  path.Add(pp[0]);
                foreach (int[] p in pp)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        xx[i] += p[i];
                    }
                    path.Add(xx);
                }
            }
            XElement[] children = SimulinkXmlParser.GetChildren(element);
            foreach (XElement child in children)
            {
                if (child.Name.Equals("Branch"))
                {
                    Path pn = path.Create();
                    ProcessBrunch(pn, xx, child);
                }
            }
        }
Exemplo n.º 10
0
        void DrawMult(XElement element, Graphics graphics)
        {
            int[]  pos = SimulinkXmlParser.GetPosition(element);
            Pen    pen = di.GetPen(element);
            double dx  = (pos[2] - pos[0]);
            double dy  = (pos[3] - pos[1]);
            //int xl = (int)(dx * Math.Sqrt(0.5));
            int dxl = (int)(dx * Math.Sqrt(2) / 8);
            //int yl = (int)(dy * Math.Sqrt(0.5));
            int dyl = (int)(dy * Math.Sqrt(2) / 8);

            graphics.DrawLine(pen, pos[0] + dxl, pos[1] + dyl, pos[2] - dxl, pos[3] - dyl);
            graphics.DrawLine(pen, pos[0] + dxl, pos[3] - dyl, pos[2] - dxl, pos[1] + dyl);
        }
Exemplo n.º 11
0
 void PrepareArrows(XElement element)
 {
     XElement[] el = SimulinkXmlParser.GetChildren(element);
     foreach (XElement e in el)
     {
         if (e.Name.Equals(SimulinkXmlParser.Block))
         {
             blocks[e.GetAttributeLocal(SimulinkXmlParser.Name)] = e;
         }
     }
     foreach (XElement e in el)
     {
         if (e.Name.Equals(SimulinkXmlParser.Line))
         {
             ProcessArrow(e);
         }
     }
 }
Exemplo n.º 12
0
        private void CreateGraphicsStructure()
        {
            Dictionary <string, GraphicsStructure> d = new Dictionary <string, GraphicsStructure>();
            XElement r = root;

            while (true)
            {
                if (r.Name.Equals("Model"))
                {
                    break;
                }
                XElement p = r.Parent as XElement;
                if (p == null)
                {
                    break;
                }
                r = p;
            }
            XElement[] children = SimulinkXmlParser.GetChildren(r);
            foreach (XElement e in children)
            {
                string tn = e.Name.LocalName;
                if (tn.Contains(Defaults))
                {
                    string            s  = tn.Substring(0, tn.Length - Defaults.Length);
                    GraphicsStructure gs = CreateStucrure(e);
                    d[s] = gs;
                }
            }
            if (d.ContainsKey(SimulinkXmlParser.Line))
            {
                d[SimulinkXmlParser.Branch] = d[SimulinkXmlParser.Line];
            }
            IDrawingInterface         din  = TagNameDrawingInterface.GetInterface(d);
            IList <IDrawingInterface> list = new List <IDrawingInterface>();

            list.Add(din);
            list.Add(this);
            di = new DrawingInterfaceList(list);
        }
Exemplo n.º 13
0
        Action <XElement, Graphics> IDrawing.GetDrawing(XElement element, out bool recursive)
        {
            string en = element.Name.LocalName;

            if (en.Equals(SimulinkXmlParser.Block))
            {
                string bn = SimulinkXmlParser.GetName(element);
                recursive = false;
                string type = SimulinkXmlParser.GetBlockType(element);
                string icon = element.GetAttributeLocal("IconShape");
                if (drawIconBlock.ContainsKey(icon))
                {
                    Dictionary <string, Action <XElement, Graphics> > dd = drawIconBlock[icon];
                    if (dd.ContainsKey(type))
                    {
                        return(dd[type]);
                    }
                }
                if (drawBlock.ContainsKey(type))
                {
                    return(drawBlock[type]);
                }
                else
                {
                    Action <XElement, Graphics> d = DrawRect;
                    d += DrawName;
                    return(d);
                }
            }
            recursive = true;
            if (en.Equals(SimulinkXmlParser.Line) | en.Equals(SimulinkXmlParser.Branch))
            {
                return(DrawLine);
            }
            return(null);
        }
Exemplo n.º 14
0
        int[] GetDefaultPort(XElement element, string port, bool input)
        {
            int[]  p  = GetPosition(element);
            int    n  = 1;
            int    m  = 0;
            string pp = element.GetAttributeLocal("Ports");

            try
            {
                int[] nn = SimulinkXmlParser.ParseInt(pp);
                // n = (input) ? nn[0] : nn[1];
                m = Int32.Parse(port) - 1;
                if (input)
                {
                    int    km = 0;
                    string s  = element.GetAttributeLocal("MaxPort");
                    if (s.Length > 0)
                    {
                        km = Int32.Parse(s);
                    }
                    if (m > km)
                    {
                        km = m;
                    }
                    element.SetAttributeValue("MaxPort", km + "");
                }
                else
                {
                    string s = element.GetAttributeLocal("MaxPort");
                    if (s.Length > 0)
                    {
                        m += 1 + Int32.Parse(s);
                    }
                }
                int kk   = 0;
                int side = 0;
                for (; side < nn.Length; side++)
                {
                    kk += nn[side];
                    if (m <= kk)
                    {
                        break;
                    }
                }
                int   nk       = nn[side];
                bool  vertical = (side == 0 | side == 2);
                float len      = (float)(vertical ? (p[3] - p[1]) : (p[2] - p[0]));
                float kl       = len / (float)nk;
                float pos      = (EPS + (float)m) * kl;
                int   coord    = p[side];
                if (vertical)
                {
                    return(new int[] { coord, p[1] + (int)pos });
                }
                else
                {
                    return(new int[] { p[1] + (int)pos, coord });
                }
            }
            catch (Exception)
            {
            }
            float k = (float)(p[3] - p[1]) / ((float)n /* - 1 + 2 * EPS*/);

            k = (float)p[1] + (EPS + (float)m) * k;
            int mm = (int)k;

            if (!input)
            {
                return(new int[] { p[2], mm });
            }
            return(new int[] { p[0], mm });
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates object from file
        /// </summary>
        /// <param name="filename">Filename</param>
        /// <returns>Created object</returns>
        public static SimulinkDrawing FromFile(string filename)
        {
            XElement doc = SimulinkXmlParser.Create(StaticExtensionXmlParserLibrary.TransformFile(filename));

            return(new SimulinkDrawing(doc));
        }
Exemplo n.º 16
0
 int[] GetPosition(XElement element)
 {
     return(SimulinkXmlParser.GetPosition(element));
 }
Exemplo n.º 17
0
        /// <summary>
        /// Creates element from list of strings
        /// </summary>
        /// <param name="text">List of strings</param>
        /// <returns>Created object</returns>
        public static SimulinkDrawing FromText(IList <string> text)
        {
            XElement doc = SimulinkXmlParser.Create(text);

            return(new SimulinkDrawing(doc));
        }
Exemplo n.º 18
0
 static string[] ParseString(string s)
 {
     return(SimulinkXmlParser.ParseString(s));
 }
Exemplo n.º 19
0
        int[] GetDefaultPort(XElement element, string port, bool input,
                             Dictionary <XElement, Dictionary <bool, Dictionary <string, PortIO> > > dic)
        {
            int[]  ss   = new int[] { 0, 2, 1, 3 };
            string icon = element.GetAttribute("IconShape");

            if (icon.Equals("round"))
            {
                int[] nc = GetCircularPort(element, port, input);
                if (nc != null)
                {
                    return(nc);
                }
            }
            int[] p  = GetPosition(element);
            int   n  = 1;
            int   m  = 0;
            int   dm = 0;
            Dictionary <bool, Dictionary <string, PortIO> > dd = dic[element];
            string pp = element.GetAttribute("Ports");

            try
            {
                int[] nn = SimulinkXmlParser.ParseInt(pp);
                // n = (input) ? nn[0] : nn[1];
                m = Int32.Parse(port) - 1;
                if (!input & nn.Length > 0)
                {
                    m += dd[true].Count;
                }
                int kk   = 0;
                int side = 0;
                for (; side < nn.Length; side++)
                {
                    int kkk = kk;
                    kk += nn[side];
                    if (m < kk)
                    {
                        dm = m - kkk;
                        break;
                    }
                }
                int nk = 1;
                if (nn.Length == 0)
                {
                    side = input ? 0 : 1;
                }
                else
                {
                    nk = nn[side];
                }
                bool  vertical = (side == 0 | side == 1);
                float len      = (float)(vertical ? (p[3] - p[1]) : (p[2] - p[0]));
                float kl       = len / (float)nk;
                float pos      = (EPS + (float)dm) * kl;
                int   coord    = p[ss[side]];
                if (vertical)
                {
                    return(new int[] { coord, p[1] + (int)pos });
                }
                else
                {
                    return(new int[] { p[1] + (int)pos, coord });
                }
            }
            catch (Exception)
            {
            }
            float k = (float)(p[3] - p[1]) / ((float)n /* - 1 + 2 * EPS*/);

            k = (float)p[1] + (EPS + (float)m) * k;
            int mm = (int)k;

            if (!input)
            {
                return(new int[] { p[2], mm });
            }
            return(new int[] { p[0], mm });
        }