Exemplo n.º 1
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.º 2
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 });
        }