Example #1
0
        void AddBlock(XElement element)
        {
            string name = SimulinkXmlParser.GetName(element);
            string type = element.GetAttribute(SimulinkXmlParser.BlockType);

            lBlocks.Add(name);
            if (type.Equals(SimulinkXmlParser.SubSystem))
            {
                //     XElement[] children = SimulinkXmlParser.GetChildren(element);
                //        foreach (XElement child in children)
                //        {
                //              if (child.Name.Equals(SimulinkXmlParser.SystemStr))
                //              {
                SimulinkSubsystem system = new SimulinkSubsystem(element, this, null);
                listBlocks.Add(system);
                systems[system.Name] = system;
                esystems[system]     = system.Name;
                //                 return;
                //              }
                //          }
                return;
            }
            Block block = new Block(element, this);

            blocks[name]   = block;
            eblocks[block] = name;
            listBlocks.Add(block);
        }
Example #2
0
 static void SetInterop(List <Arrow> inter)
 {
     foreach (Arrow ar in inter)
     {
         Block[]     bl = new Block[] { ar.SourceBlock, ar.TargetBlock };
         BlockPort[] bp = new BlockPort[] { ar.Source, ar.Target };
         for (int i = 0; i < bl.Length; i++)
         {
             bool  inp = (i == 0);
             Block c   = bl[i];
             if (c is SimulinkSubsystem)
             {
                 SimulinkSubsystem ss = c as SimulinkSubsystem;
                 Block             br = GetIOBlock(ss, (1 - i), bp[i].Port + "");
                 if (br == null)
                 {
                     continue;
                 }
                 if (inp)
                 {
                     ar.TargetBlock           = br;
                     br.Input[ar.Target.Port] = ar;
                 }
                 else
                 {
                     ar.SourceBlock            = br;
                     br.Output[ar.Source.Port] = ar;
                 }
             }
         }
     }
 }
Example #3
0
        Block GetBlock(string name)
        {
            if (blocks.ContainsKey(name))
            {
                return(blocks[name]);
            }
            SimulinkSubsystem r = Root;

            return(GetBlock(r, name));
        }
Example #4
0
        /// <summary>
        /// Replaces block id by expression
        /// </summary>
        /// <param name="b">The block</param>
        /// <param name="expr">The expression</param>
        /// <returns>Replacement result</returns>
        public static string Replace(Block b, string expr)
        {
            SimulinkSubsystem system = b.Parent;
            string            pre    = system.constPreffix;
            string            so     = expr + "";

            foreach (string s in system.systemConst.Keys)
            {
                so = so.Replace(s, pre + s);
            }
            return(so);
        }
Example #5
0
 void GetAllBlocks(List <Block> l)
 {
     foreach (Block b in listBlocks)
     {
         if (b is SimulinkSubsystem)
         {
             SimulinkSubsystem ss = b as SimulinkSubsystem;
             ss.GetAllBlocks(l);
             continue;
         }
         l.Add(b);
     }
 }
Example #6
0
 static Block GetIOBlock(SimulinkSubsystem system, int num, string port)
 {
     foreach (Block bl in system.blocks.Values)
     {
         if (!bl.Type.Equals(SimulinkXmlParser.IOPorts[num]))
         {
             continue;
         }
         IAttribute a = bl;
         if (a[SimulinkXmlParser.Port].Equals(port))
         {
             return(bl);
         }
     }
     return(null);
 }
Example #7
0
 static SimulinkSubsystem GetSystem(SimulinkSubsystem system, string name)
 {
     if (system.systems.ContainsKey(name))
     {
         return(system.systems[name]);
     }
     foreach (SimulinkSubsystem sy in system.systems.Values)
     {
         SimulinkSubsystem b = GetSystem(sy, name);
         if (b != null)
         {
             return(b);
         }
     }
     return(null);
 }
Example #8
0
        /* public SimulinkSystem(SimulinkSubsystem system, SimulinkStateflow stateflow)
         * {
         *   this.system = system;
         *   this.stateflow = stateflow;
         * }*/

        /// <summary>
        /// Constructor from Xml document
        /// </summary>
        /// <param name="doc">The document</param>
        public SimulinkSystem(XElement doc)
        {
            XElement e = null;

            foreach (XElement p in doc.GetElementsByTagName("Model"))
            {
                e = p;
                break;
            }
            system = new SimulinkSubsystem(
                e,
                null, new BlockCodeCreator());
            IEnumerable <XElement> nl = doc.GetElementsByTagName("Stateflow");

            foreach (XElement p in nl)
            {
                stateflow = new SimulinkStateflow(p);
                break;
            }
        }
Example #9
0
        static Block GetBlock(SimulinkSubsystem system, string name)
        {
            SimulinkSubsystem sys = GetSystem(system, name);

            if (sys != null)
            {
                return(sys);
            }
            if (system.blocks.ContainsKey(name))
            {
                return(system.blocks[name]);
            }
            foreach (SimulinkSubsystem sy in system.systems.Values)
            {
                Block b = GetBlock(sy, name);
                if (b != null)
                {
                    return(b);
                }
            }
            return(null);

            /*char[] sep = "\\\n".ToCharArray();
             * string[] s = name.Split(sep);
             * /*SimulinkSystem system = this;
             * Dictionary<string, SimulinkSystem> d = null;
             * for (int i = 0; i < s.Length - 1; i++)
             * {
             *  d = system.systems;
             *  string key = s[i];
             *  if (d.ContainsKey(key))
             *  {
             *      system = d[key];
             *  }
             * }
             * if (system.blocks.ContainsKey(s[s.Length - 1]))
             * {
             *  return system.blocks[s[s.Length - 1]];
             * }
             * return null;*/
        }
Example #10
0
        /// <summary>
        /// Constructor from element
        /// </summary>
        /// <param name="element">The element</param>
        /// <param name="system">Parent system</param>
        /// <param name="creator">Creation interface</param>
        public SimulinkSubsystem(XElement element, SimulinkSubsystem system,
                                 IBlockCodeCreator creator)
            : base(element, system)
        {
            XElement e = null;

            XElement[] children = StaticExtensionXmlParserLibrary.GetChildren(element);
            foreach (XElement child in children)
            {
                if (child.Name.Equals(SimulinkXmlParser.SystemStr))
                {
                    e = child;
                }
            }
            Create(e);
            if (system == null)
            {
                SetArrows(creator);
            }
            CreateConst();
        }
Example #11
0
 /// <summary>
 /// Constructor from Xml element
 /// </summary>
 /// <param name="element">The element</param>
 /// <param name="system">Parent system</param>
 public SimulinkSubsystem(XElement element, SimulinkSubsystem system)
     : this(element, system, null)
 {
 }
Example #12
0
        SimulinkSubsystem GetSystem(string name)
        {
            SimulinkSubsystem r = Root;

            return(GetSystem(r, name));
        }