コード例 #1
0
        public void DiagramAdd2AndRetriveNew()
        {
            Diagram test = new Diagram("test.sql");

            didactic_palm_tree.UIModel.IComponent testComponent = new TestComponent(0, 0);
            test.Add(testComponent);

            didactic_palm_tree.UIModel.IComponent testComponent2 = new TestComponent(1, 1);
            test.Add(testComponent2);
            Assert.AreEqual(test.GetComponent(new Point(1, 1)), testComponent2);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: denismaster/seal-old
 private void PasteFigure()
 {
     if (CopiedFigure != null)
     {
         Diagram.Add(CopiedFigure);
     }
 }
コード例 #3
0
        public void DiagramAdd()
        {
            Diagram test = new Diagram("test.sql");

            didactic_palm_tree.UIModel.IComponent testComponent = new TestComponent(0, 0);
            test.Add(testComponent);
        }
コード例 #4
0
ファイル: AddController.cs プロジェクト: denismaster/seal-old
 public override void MouseUpAction(System.Windows.Forms.MouseEventArgs e)
 {
     if (geometry != null)
     {
         figure.Location = location;
         Diagram.Add(figure);
         geometry = default(T);
         figure   = null;
     }
 }
コード例 #5
0
        public void DiagramAddSaveAndRetrive()
        {
            Diagram test = Diagram.CreateNew("test.sql");

            didactic_palm_tree.UIModel.IComponent testComponent = new TestComponent(0, 0);
            test.Add(testComponent);
            test.Save();
            Diagram test2 = Diagram.Load("test.sql");

            Assert.AreEqual(test2.GetComponent(new Point(0, 0)), testComponent);
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: denismaster/seal-old
        private void toolStripButton22_Click(object sender, EventArgs e)
        {
            Random rng = new Random();
            var    ofd = new OpenFileDialog();

            ofd.Multiselect = true;
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (var filename in ofd.FileNames)
                {
                    var location = new Location(rng.Next(200), rng.Next(200));
                    var image    = new Seal.Figures.ImageFigure
                                       (new Seal.Images.BitmapImageProvider(this.seal2DCanvas1.RenderTarget).Get(filename));
                    image.Location = location;
                    Diagram.Add(image);
                }
            }
        }
コード例 #7
0
ファイル: AddController.cs プロジェクト: denismaster/seal-old
        public override void MouseUpAction(System.Windows.Forms.MouseEventArgs e)
        {
            var p      = new SharpDX.Point(e.X, e.Y);
            var figure = Diagram.Get(p) as ILineEndable;

            if (figure != null)
            {
                line = new Line(from, figure);
            }
            else
            {
                line = new Line(from, to);
            }
            Diagram.Add(line);
            from = null;
            to   = null;
            line = null;
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: zkhan93/xsddiagram
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            bool streamToOutput = !string.IsNullOrEmpty(Options.OutputFile) || Options.OutputOnStdOut;

            if (Options.NoGUI || Options.RequestHelp || streamToOutput)
            {
                //if(!Options.IsRunningOnMono)
                //{
                //    if (GetConsoleWindow() == IntPtr.Zero)
                //        ; // AllocConsole();
                //}

                if (Options.RequestHelp || string.IsNullOrEmpty(Options.InputFile) || !streamToOutput ||
                    Options.RootElements.Count == 0 || Options.ExpandLevel < 0 || Options.Zoom < 10.0 || Options.Zoom > 1000.0)
                {
                    string version = typeof(Program).Assembly.GetName().Version.ToString();
                    Log(usage, version, Path.GetFileName(Environment.GetCommandLineArgs()[0]));

                    return;
                }

                Log("Loading the file: {0}\n", Options.InputFile);

                Schema schema = new Schema();
                schema.RequestCredential += delegate(string url, string realm, int attemptCount, out string username, out string password)
                {
                    username = password = "";
                    if (!string.IsNullOrEmpty(Options.Username))
                    {
                        if (attemptCount > 1)
                        {
                            return(false);
                        }
                        username = Options.Username;
                        password = Options.Password;
                        return(true);
                    }
                    return(false);
                };

                schema.LoadSchema(Options.InputFile);

                if (schema.LoadError.Count > 0)
                {
                    LogError("There are errors while loading:\n");
                    foreach (var error in schema.LoadError)
                    {
                        LogError(error);
                    }
                    LogError("\r\n");
                }

                Diagram diagram = new Diagram();
                diagram.ShowDocumentation = Options.ShowDocumentation;
                diagram.ElementsByName    = schema.ElementsByName;
                diagram.Scale             = Options.Zoom / 100.0f;

                foreach (var rootElement in Options.RootElements)
                {
                    string elementName      = rootElement;
                    string elementNamespace = null;
                    if (!string.IsNullOrEmpty(elementName))
                    {
                        var pos = rootElement.IndexOf("@");
                        if (pos != -1)
                        {
                            elementName      = rootElement.Substring(0, pos);
                            elementNamespace = rootElement.Substring(pos + 1);
                        }
                    }

                    foreach (var element in schema.Elements)
                    {
                        if ((elementNamespace != null && elementNamespace == element.NameSpace && element.Name == elementName) ||
                            (elementNamespace == null && element.Name == elementName))
                        {
                            Log("Adding '{0}' element to the diagram...\n", rootElement);
                            diagram.Add(element.Tag, element.NameSpace);
                        }
                    }
                }
                Form     form     = new Form();
                Graphics graphics = form.CreateGraphics();
                graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                for (int i = 0; i < Options.ExpandLevel; i++)
                {
                    Log("Expanding to level {0}...\n", i + 1);
                    diagram.ExpandOneLevel();
                }
                diagram.Layout(graphics);
                Log("Saving image...\n");
                try
                {
                    bool result = false;

                    DiagramExporter exporter = new DiagramExporter(diagram);
                    IDictionary <string, object> specificRendererParameters = new Dictionary <string, object>()
                    {
                        { "TextOutputFields", Options.TextOutputFields },
                        { "DisplayAttributes", Options.DisplayAttributes },
                        { "Schema", schema }
                        //For future parameters, {}
                    };
                    if (Options.OutputOnStdOut)
                    {
                        Stream stream = Console.OpenStandardOutput();
                        result = exporter.Export(stream, "." + Options.OutputOnStdOutExtension.ToLower(), graphics, new DiagramAlertHandler(ByPassSaveAlert), specificRendererParameters);
                        stream.Flush();
                    }
                    else
                    {
                        result = exporter.Export(Options.OutputFile, graphics, new DiagramAlertHandler(SaveAlert), specificRendererParameters);
                    }

                    if (result)
                    {
                        Log("The diagram is now saved in the file: {0}\n", Options.OutputFile);
                    }
                    else
                    {
                        Log("ERROR: The diagram has not been saved!\n");
                    }
                }
                catch (Exception ex)
                {
                    Log("ERROR: The diagram has not been saved. {0}\n", ex.Message);
                }

                graphics.Dispose();
                form.Dispose();
            }
            else
            {
                if (Options.RequestHelp)
                {
                    string version = typeof(Program).Assembly.GetName().Version.ToString();
                    MessageBox.Show(string.Format(usage, version, Environment.GetCommandLineArgs()[0]));
                }

                Application.ThreadException += HandleThreadException;
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
        }
コード例 #9
0
ファイル: DiagramTest.cs プロジェクト: jdpillon/LadderIno
        public void FileSave()
        {
            //|     x1          y2      x2     y1   |
            //|--+--[ ]--[OSR]--[/]--+--[/]----( )--|
            //|  |  y1               |              |
            //|  +--[ ]--------------+              |
            //|                                     |
            //|     x2          y1      x1     y2   |
            //|--+--[ ]--[OSR]--[/]--+--[/]----( )--|
            //|  |  y2               |              |
            //|  +--[ ]--------------+              |
            //|                                     |
            //|                                     |
            //|--[ ]------------------------+--( )--|
            //|                             |       |
            //|                             +--( )--|
            //|                             |       |
            //|                             +--( )--|
            //|                                     |
            //|                                     |
            //|--+--[ ]--+-+--[ ]--+-----------( )--|
            //|  |       | |       |                |
            //|  +--[ ]--+ +--[ ]--+                |

            Diagram TestDiagram = new Diagram();

            #region Declare Components
            Rung Rung1 = new Rung();
            Rung Rung2 = new Rung();
            Rung Rung3 = new Rung();
            Rung Rung4 = new Rung();

            var Y1 = new Coil();
            Y1.Name = "1";

            var Y2 = new Coil();
            Y2.Name = "2";

            var X1 = new Contact();
            X1.Name = "1";

            var X1I = new Contact();
            X1I.Name       = "1";
            X1I.IsInverted = true;

            var X2 = new Contact();
            X2.Name = "2";

            var X2I = new Contact();
            X2I.Name       = "2";
            X2I.IsInverted = true;

            var Y1C = new Contact();
            Y1C.Name = "1";
            Y1C.Type = Contact.ContactType.OutputPin;

            var Y1CI = new Contact();
            Y1CI.Name       = "1";
            Y1CI.Type       = Contact.ContactType.OutputPin;
            Y1CI.IsInverted = true;

            var Y2C = new Contact();
            Y2C.Name = "2";
            Y2C.Type = Contact.ContactType.OutputPin;

            var Y2CI = new Contact();
            Y2CI.Name       = "2";
            Y2CI.Type       = Contact.ContactType.OutputPin;
            Y2CI.IsInverted = true;

            var X3 = new Contact();
            X3.Name = "3";
            var X4 = new Contact();
            X4.Name = "4";
            #endregion Declare Components

            #region Build Circuit
            Rung1.Add(Y1);
            Rung1.InsertBefore(X2I, Y1);
            Rung1.Add(X1);
            Rung1.InsertUnder(Y1C, X1);
            Rung1.InsertAfter(Y2CI, X1);
            Rung1.InsertBefore(new OSR(), Y2CI);

            TestDiagram.Add(Rung1);

            Rung2.Add(Y2);
            Rung2.InsertBefore(X1I, Y2);
            Rung2.Add(X2);
            Rung2.InsertUnder(Y2C, X2);
            Rung2.InsertAfter(Y1CI, X2);
            Rung2.InsertBefore(new OSR(), Y1CI);

            TestDiagram.InsertUnder(Rung2, Rung1);

            Rung3.Add(new Coil());
            Rung3.Add(new Coil());
            Rung3.Add(new Coil());
            Rung3.Add(new Contact());
            TestDiagram.InsertUnder(Rung3, Rung2);

            ELF elf = new ELF();
            elf.Name = "test";
            elf.Code = "int a = 10;";
            Rung4.Add(elf);
            Rung4.Add(X3);
            Rung4.InsertAfter(X4, X3);
            Rung4.InsertUnder(new Contact(), X3);
            Rung4.InsertUnder(new Contact(), X4);
            TestDiagram.InsertUnder(Rung4, Rung3);

            #endregion Build Circuit

            LDFile.DiagramWriter.SaveDiagram(TestDiagram, "test.xml");
        }
コード例 #10
0
ファイル: DiagramTest.cs プロジェクト: jdpillon/LadderIno
        public void BasicTest()
        {
            //|     x1          y2      x2     y1   |
            //|--+--[ ]--[OSR]--[/]--+--[/]----( )--|
            //|  |  y1               |              |
            //|  +--[ ]--------------+              |
            //|                                     |
            //|     x2          y1      x1     y2   |
            //|--+--[ ]--[OSR]--[/]--+--[/]----( )--|
            //|  |  y2               |              |
            //|  +--[ ]--------------+              |

            Diagram TestDiagram = new Diagram();

            TestDiagram.MasterRelay = true;

            #region Declare Components
            Rung Rung1 = new Rung();
            Rung Rung2 = new Rung();

            var Y1 = new Coil();
            Y1.Name = "1";

            var Y2 = new Coil();
            Y2.Name = "2";

            var X1 = new Contact();
            X1.Name = "1";

            var X1I = new Contact();
            X1I.Name       = "1";
            X1I.IsInverted = true;

            var X2 = new Contact();
            X2.Name = "2";

            var X2I = new Contact();
            X2I.Name       = "2";
            X2I.IsInverted = true;

            var Y1C = new Contact();
            Y1C.Name = "1";
            Y1C.Type = Contact.ContactType.OutputPin;

            var Y1CI = new Contact();
            Y1CI.Name       = "1";
            Y1CI.Type       = Contact.ContactType.OutputPin;
            Y1CI.IsInverted = true;

            var Y2C = new Contact();
            Y2C.Name = "2";
            Y2C.Type = Contact.ContactType.OutputPin;

            var Y2CI = new Contact();
            Y2CI.Name       = "2";
            Y2CI.Type       = Contact.ContactType.OutputPin;
            Y2CI.IsInverted = true;

            #endregion Declare Components

            #region Build Circuit
            Rung1.Add(Y1);
            Rung1.InsertBefore(X2I, Y1);
            Rung1.Add(X1);
            Rung1.InsertUnder(Y1C, X1);
            Rung1.InsertAfter(Y2CI, X1);
            Rung1.InsertBefore(new OSR(), Y2CI);

            TestDiagram.Add(Rung1);

            Rung2.Add(Y2);
            Rung2.InsertBefore(X1I, Y2);
            Rung2.Add(X2);
            Rung2.InsertUnder(Y2C, X2);
            Rung2.InsertAfter(Y1CI, X2);
            Rung2.InsertBefore(new OSR(), Y1CI);

            TestDiagram.InsertUnder(Rung2, Rung1);

            #endregion Build Circuit

            Trace.WriteLine("");

            #region Cycle 1
            Trace.WriteLine("Cycle 1", "Unit Test");
            Trace.Indent();
            TestDiagram.Execute();
            Assert.IsFalse(X1.InternalState, "X1 Fail");
            Assert.IsFalse(X2.InternalState, "X2 Fail");
            Assert.IsFalse(X1I.InternalState, "X1I Fail");
            Assert.IsFalse(X2I.InternalState, "X2I Fail");
            Assert.IsFalse(Y1.InternalState, "Y1 Fail");
            Assert.IsFalse(Y2.InternalState, "Y2 Fail");
            Assert.IsFalse(Y1C.InternalState, "Y1C Fail");
            Assert.IsFalse(Y2C.InternalState, "Y2C Fail");
            Assert.IsFalse(Y1CI.InternalState, "Y1CI Fail");
            Assert.IsFalse(Y2CI.InternalState, "Y2CI Fail");
            Trace.Unindent();
            #endregion Cycle 1

            #region Cycle 2
            Trace.WriteLine("Cycle 2", "Unit Test");
            Trace.Indent();
            X1.IsClosed = true;
            TestDiagram.Execute();
            Assert.IsTrue(X1.InternalState, "X1 Fail");
            Assert.IsFalse(X2.InternalState, "X2 Fail");
            Assert.IsFalse(X1I.InternalState, "X1I Fail");
            Assert.IsTrue(X2I.InternalState, "X2I Fail");
            Assert.IsTrue(Y1.InternalState, "Y1 Fail");
            Assert.IsFalse(Y2.InternalState, "Y2 Fail");
            Assert.IsFalse(Y1C.InternalState, "Y1C Fail");
            Assert.IsFalse(Y2C.InternalState, "Y2C Fail");
            Assert.IsFalse(Y1CI.InternalState, "Y1CI Fail");
            Assert.IsTrue(Y2CI.InternalState, "Y2CI Fail");
            Trace.Unindent();
            #endregion Cycle 2

            #region Cycle 3
            Trace.WriteLine("Cycle 3", "Unit Test");
            Trace.Indent();
            X1.IsClosed = false;
            TestDiagram.Execute();
            Assert.IsFalse(X1.InternalState, "X1 Fail");
            Assert.IsFalse(X2.InternalState, "X2 Fail");
            Assert.IsFalse(X1I.InternalState, "X1I Fail");
            Assert.IsTrue(X2I.InternalState, "X2I Fail");
            Assert.IsTrue(Y1.InternalState, "Y1 Fail");
            Assert.IsFalse(Y2.InternalState, "Y2 Fail");
            Assert.IsTrue(Y1C.InternalState, "Y1C Fail");
            Assert.IsFalse(Y2C.InternalState, "Y2C Fail");
            Assert.IsFalse(Y1CI.InternalState, "Y1CI Fail");
            Assert.IsFalse(Y2CI.InternalState, "Y2CI Fail");
            Trace.Unindent();
            #endregion Cycle 3

            #region Cycle 4
            Trace.WriteLine("Cycle 4", "Unit Test");
            Trace.Indent();
            X2.IsClosed = true;
            TestDiagram.Execute();
            Assert.IsFalse(X1.InternalState, "X1 Fail");
            Assert.IsTrue(X2.InternalState, "X2 Fail");
            Assert.IsTrue(X1I.InternalState, "X1I Fail");
            Assert.IsFalse(X2I.InternalState, "X2I Fail");
            Assert.IsFalse(Y1.InternalState, "Y1 Fail");
            Assert.IsTrue(Y2.InternalState, "Y2 Fail");
            Assert.IsTrue(Y1C.InternalState, "Y1C Fail");
            Assert.IsFalse(Y2C.InternalState, "Y2C Fail");
            Assert.IsTrue(Y1CI.InternalState, "Y1CI Fail");
            Assert.IsFalse(Y2CI.InternalState, "Y2CI Fail");
            Trace.Unindent();
            #endregion Cycle 4

            #region Cycle 5
            Trace.WriteLine("Cycle 5", "Unit Test");
            Trace.Indent();
            X2.IsClosed = false;
            TestDiagram.Execute();
            Assert.IsFalse(X1.InternalState, "X1 Fail");
            Assert.IsFalse(X2.InternalState, "X2 Fail");
            Assert.IsTrue(X1I.InternalState, "X1I Fail");
            Assert.IsFalse(X2I.InternalState, "X2I Fail");
            Assert.IsFalse(Y1.InternalState, "Y1 Fail");
            Assert.IsTrue(Y2.InternalState, "Y2 Fail");
            Assert.IsFalse(Y1C.InternalState, "Y1C Fail");
            Assert.IsTrue(Y2C.InternalState, "Y2C Fail");
            Assert.IsFalse(Y1CI.InternalState, "Y1CI Fail");
            Assert.IsFalse(Y2CI.InternalState, "Y2CI Fail");
            Trace.Unindent();
            #endregion Cycle 5

            #region Cycle 6
            Trace.WriteLine("Cycle 6", "Unit Test");
            Trace.Indent();
            X1.IsClosed = true;
            TestDiagram.Execute();
            Assert.IsTrue(X1.InternalState, "X1 Fail");
            Assert.IsFalse(X2.InternalState, "X2 Fail");
            Assert.IsFalse(X1I.InternalState, "X1I Fail");
            Assert.IsFalse(X2I.InternalState, "X2I Fail");
            Assert.IsFalse(Y1.InternalState, "Y1 Fail");
            Assert.IsFalse(Y2.InternalState, "Y2 Fail");
            Assert.IsFalse(Y1C.InternalState, "Y1C Fail");
            Assert.IsTrue(Y2C.InternalState, "Y2C Fail");
            Assert.IsFalse(Y1CI.InternalState, "Y1CI Fail");
            Assert.IsFalse(Y2CI.InternalState, "Y2CI Fail");
            Trace.Unindent();
            #endregion Cycle 6

            #region Cycle 7
            Trace.WriteLine("Cycle 7", "Unit Test");
            Trace.Indent();
            X1.IsClosed = false;
            TestDiagram.Execute();
            Assert.IsFalse(X1.InternalState, "X1 Fail");
            Assert.IsFalse(X2.InternalState, "X2 Fail");
            Assert.IsFalse(X1I.InternalState, "X1I Fail");
            Assert.IsFalse(X2I.InternalState, "X2I Fail");
            Assert.IsFalse(Y1.InternalState, "Y1 Fail");
            Assert.IsFalse(Y2.InternalState, "Y2 Fail");
            Assert.IsFalse(Y1C.InternalState, "Y1C Fail");
            Assert.IsFalse(Y2C.InternalState, "Y2C Fail");
            Assert.IsFalse(Y1CI.InternalState, "Y1CI Fail");
            Assert.IsFalse(Y2CI.InternalState, "Y2CI Fail");
            Trace.Unindent();
            #endregion Cycle 7
        }
コード例 #11
0
ファイル: RungsReader.cs プロジェクト: jdpillon/LadderIno
        /// <summary>
        /// Read rungs from node list
        /// </summary>
        /// <param name="diagram"></param>
        /// <param name="rungs"></param>
        internal static void ReadRungs(XmlNodeList rungs, Diagram diagram)
        {
            foreach (XmlNode xRung in rungs)
            {
                Trace.WriteLine("Rung Started");
                Trace.Indent();

                Rung rung = new Rung();
                rung.Comment = xRung.Attributes["Comment"].Value;
                List <ComponentBase>  components = new List <ComponentBase>();
                List <List <string> > dRung      = new List <List <string> >();//Decomposed stringRung

                #region Decompose Loop
                Trace.WriteLine("Starting decomposition", "Rung");
                Trace.Indent();

                string       sRung      = xRung.InnerXml; //Rung as string
                Stack <bool> SerialMode = new Stack <bool>();
                SerialMode.Push(true);

                dRung.Add(new List <string>());

                //Decompose loop
                for (int pos = 0, CurrLevel = 0; pos < sRung.Length; pos++)
                {
                    if (sRung[pos] == '<')
                    {
                        if (sRung.Substring(pos + 1, 6) == "Serial")
                        {
                            dRung[CurrLevel].Add("SS" + ((CurrLevel + 2 > dRung.Count) ? 0 : dRung[CurrLevel + 1].Count));
                            pos += 7;
                            SerialMode.Push(true);

                            CurrLevel++;
                            if (CurrLevel + 1 > dRung.Count)
                            {
                                dRung.Add(new List <string>());
                            }
                        }
                        else if (sRung.Substring(pos + 1, 8) == "Parallel")
                        {
                            dRung[CurrLevel].Add("SP" + ((CurrLevel + 2 > dRung.Count) ? 0 : dRung[CurrLevel + 1].Count));
                            pos += 9;
                            SerialMode.Push(false);

                            CurrLevel++;
                            if (CurrLevel + 1 > dRung.Count)
                            {
                                dRung.Add(new List <string>());
                            }
                        }
                        else if (sRung[pos + 1] == '/')
                        {
                            int lenght = 0;
                            while (sRung[pos + lenght] != '>')
                            {
                                lenght++;
                            }
                            dRung[CurrLevel].Add((sRung.Substring(pos, lenght + 1).Contains('S')) ? "ES" : "EP");
                            pos += lenght;
                            SerialMode.Pop();

                            CurrLevel--;
                        }
                        else
                        {
                            int lenght = 0;
                            while (sRung[pos + lenght] != '/' && sRung[pos + lenght + 1] != '>')
                            {
                                lenght++;
                            }

                            components.Add(CreateComponent(sRung.Substring(pos, ++lenght + 1)));
                            dRung[CurrLevel].Add(((components.Count == 1) ? "I" : "N") + ((SerialMode.Peek()) ? "S" : "P") + (components.Count - 1).ToString());
                            pos += lenght;
                        }
                    }
                }

                dRung[0].Add("ES");

                Trace.WriteLine("Decomposition ended, rung deepness " + dRung.Count.ToString() + " levels", "Rung");
                Trace.Unindent();
                #endregion Decompose Loop

                if (xRung.Attributes["Count"].Value.ToInt() != components.Count)
                {
                    throw new Exception("Corrupted File. Wrong number of components in a rung");
                }

                #region Rebuild Loop
                Trace.WriteLine("Starting Rung Rebuild", "Rebuild");
                Trace.Indent();

                int lastComponent = 0;
                rung.Add(components[0]);

                for (int level = 0; level < dRung.Count; level++)
                {
                    for (int pos = 0; pos < dRung[level].Count; pos++)
                    {
                        switch (dRung[level][pos][0])
                        {
                            #region Hit Sub-Circuit
                        case 'S':
                            int m = pos;
                            while (dRung[level][m][0] != 'E')
                            {
                                m++;
                            }

                            if (m > pos + 1)
                            {
                                int slA = level, //Selected level A
                                    spA = pos;   //Selected Position A

                                while (dRung[slA][spA][0] == 'S')
                                {
                                    spA = dRung[slA][spA].Substring(2).ToInt();
                                    slA++;
                                }

                                int slB = level,      //Selected level B
                                    spB = pos + 1;    //Selected Position B

                                while (dRung[slB][spB][0] == 'S')
                                {
                                    spB = dRung[slB][spB].Substring(2).ToInt();
                                    slB++;
                                }

                                Trace.WriteLine("Component pair -> " + dRung[slA][spA].Substring(2) + " | " + dRung[slB][spB].Substring(2), "Rebuild");

                                //if (dRung[slA][spA][0] == 'N')
                                //{
                                //    if (dRung[level][m][1] == 'S') rung.InsertAfter(components[dRung[slA][spA].Substring(2).ToInt()], components[lastComponent]);
                                //    else rung.InsertUnder(components[dRung[slA][spA].Substring(2).ToInt()], components[lastComponent]);
                                //    dRung[slA][spA] = dRung[slA][spA].Replace("N", "I");
                                //    Trace.WriteLine("Component A inserted ", "Rebuild");
                                //}

                                lastComponent = dRung[slA][spA].Substring(2).ToInt();

                                if (dRung[slB][spB][0] == 'N')
                                {
                                    if (dRung[level][m][1] == 'S')
                                    {
                                        rung.InsertAfter(components[dRung[slB][spB].Substring(2).ToInt()], components[lastComponent]);
                                    }
                                    else
                                    {
                                        rung.InsertUnder(components[dRung[slB][spB].Substring(2).ToInt()], components[lastComponent]);
                                    }
                                    dRung[slB][spB] = dRung[slB][spB].Replace("N", "I");
                                    Trace.WriteLine("Component " + dRung[slB][spB].Substring(2) + " inserted ", "Rebuild");
                                }

                                lastComponent = dRung[slB][spB].Substring(2).ToInt();
                            }
                            else
                            {
                                int sl = level, //Selected level
                                    sp = pos;   //Selected Position

                                while (dRung[sl][sp][0] == 'S')
                                {
                                    sp = dRung[sl][sp].Substring(2).ToInt();
                                    sl++;
                                }

                                if (dRung[sl][sp][0] == 'N')
                                {
                                    if (dRung[level][m][1] == 'S')
                                    {
                                        rung.InsertAfter(components[dRung[sl][sp].Substring(2).ToInt()], components[lastComponent]);
                                    }
                                    else
                                    {
                                        rung.InsertUnder(components[dRung[sl][sp].Substring(2).ToInt()], components[lastComponent]);
                                    }
                                    dRung[sl][sp] = dRung[sl][sp].Replace("N", "I");
                                    Trace.WriteLine("Component " + dRung[sl][sp].Substring(2) + " inserted ", "Rebuild");
                                }
                            }
                            break;
                            #endregion Hit Sub-Circuit

                            #region Hit End of Sub-Circuit
                        case 'E':     //End Sub-Circuit
                            Trace.WriteLine("End sub-circuit", "Rebuild");
                            break;
                            #endregion Hit End of Sub-Circuit

                            #region Hit Not Inserted Component
                        case 'N':     //New component
                            if (dRung[level][pos][1] == 'S')
                            {
                                rung.InsertAfter(components[dRung[level][pos].Substring(2).ToInt()], components[lastComponent]);
                            }
                            else
                            {
                                rung.InsertUnder(components[dRung[level][pos].Substring(2).ToInt()], components[lastComponent]);
                            }

                            dRung[level][pos] = dRung[level][pos].Replace("N", "I");

                            lastComponent = dRung[level][pos].Substring(2).ToInt();

                            Trace.WriteLine("Component " + dRung[level][pos].Substring(2) + " inserted", "Rebuild");
                            break;
                            #endregion Hit Not Inserted Component

                            #region Hit Inserted Component
                        case 'I':     //Inserted Component
                            lastComponent = dRung[level][pos].Substring(2).ToInt();
                            Trace.WriteLine("Last component index -> " + lastComponent, "Rebuild");
                            break;
                            #endregion Hit Inserted Component
                        }
                    }
                }

                Trace.Unindent();
                Trace.WriteLine("Rung Rebuild Ended");
                #endregion Rebuild Loop

                diagram.Add(rung);
                Trace.Unindent();
                Trace.WriteLine("Rung Ended");
            }
        }
コード例 #12
0
ファイル: CompilerTest.cs プロジェクト: jdpillon/LadderIno
        public void Compile()
        {
            //|     x1          y2      x2     y1   |
            //|--+--[ ]--[OSR]--[/]--+--[/]----( )--|
            //|  |  y1               |              |
            //|  +--[ ]--------------+              |
            //|                                     |
            //|     x2          y1      x1     y2   |
            //|--+--[ ]--[OSR]--[/]--+--[/]----( )--|
            //|  |  y2               |              |
            //|  +--[ ]--------------+              |

            Diagram TestDiagram = new Diagram();

            TestDiagram.MasterRelay = true;

            #region Declare Components
            Rung Rung1 = new Rung();
            Rung Rung2 = new Rung();

            var Y1 = new Coil();
            Y1.Name = "1";

            var Y2 = new Coil();
            Y2.Name = "2";

            var X1 = new Contact();
            X1.Name = "1";

            var X1I = new Contact();
            X1I.Name       = "1";
            X1I.IsInverted = true;

            var X2 = new Contact();
            X2.Name = "2";

            var X2I = new Contact();
            X2I.Name       = "2";
            X2I.IsInverted = true;

            var Y1C = new Contact();
            Y1C.Name = "1";
            Y1C.Type = Contact.ContactType.OutputPin;

            var Y1CI = new Contact();
            Y1CI.Name       = "1";
            Y1CI.Type       = Contact.ContactType.OutputPin;
            Y1CI.IsInverted = true;

            var Y2C = new Contact();
            Y2C.Name = "2";
            Y2C.Type = Contact.ContactType.OutputPin;

            var Y2CI = new Contact();
            Y2CI.Name       = "2";
            Y2CI.Type       = Contact.ContactType.OutputPin;
            Y2CI.IsInverted = true;

            #endregion Declare Components

            #region Build Circuit
            Rung1.Add(Y1);
            Rung1.InsertBefore(X2I, Y1);
            Rung1.Add(X1);
            Rung1.InsertUnder(Y1C, X1);
            Rung1.InsertAfter(Y2CI, X1);
            Rung1.InsertBefore(new OSR(), Y2CI);

            TestDiagram.Add(Rung1);

            Rung2.Add(Y2);
            //ELF elf = new ELF();
            //elf.Name = "test";
            //elf.Code = "int a = 10;";
            //Rung2.Add(elf);
            Rung2.InsertBefore(X1I, Y2);
            Rung2.Add(X2);
            Rung2.InsertUnder(Y2C, X2);
            Rung2.InsertAfter(Y1CI, X2);
            Rung2.InsertBefore(new OSR(), Y1CI);

            TestDiagram.InsertUnder(Rung2, Rung1);

            #endregion Build Circuit

            TestDiagram.RefreshPins();
            TestDiagram.Pins[0].Pin = "3";
            TestDiagram.Pins[1].Pin = "9";
            TestDiagram.Pins[2].Pin = "8";
            TestDiagram.Pins[3].Pin = "4";

            Console.WriteLine();
            Console.Write(Compiler.DiagramCompiler.CompileDiagram(TestDiagram));
        }