Exemplo n.º 1
0
        public Switch(State from, State to, string input, string output)
        {
            From = from;
            To = to;

            Input = input;
            Output = output;
        }
Exemplo n.º 2
0
        private void State_SigmaStep(State sender, State.SigmaInterruptArgs e)
        {
            ThreadingControlsHelper.SyncInvoke(
                this, () =>
                         {
                             txtInput.SelectionStart = txtInput.TextLength -
                                                       e.RemainingWord.Length;
                             txtInput.SelectionLength = e.RemainingWord.Length;

                             txtOutput.Text = StateStackToString(e.StateStack);
                             txtOutput.AppendText(Environment.NewLine);
                             txtOutput.AppendText(
                                 resMan.GetString("Testresult_Output", currCult) + ": ");
                             txtOutput.AppendText(e.CurrentOutput);

                             suMain.TestState = sender;
                             Application.DoEvents();
                             Thread.Sleep(50);
                         });

            if (cancelTest)
            {
                suMain.TestState = null;
                UpdateButtonStatesTest(false, false);
                Thread.CurrentThread.Abort();
            }
            if (interruptTest)
            {
                UpdateButtonStatesTest(true, true);
                Thread.CurrentThread.Suspend();
            }
        }
Exemplo n.º 3
0
        private void Build()
        {
            if (dgvTable.Rows.Count == 0)
            {
                suMain.States = null;
                return;
            }

            SortedDictionary<string, State> newStates = new SortedDictionary<string, State>(), oldStates = suMain.States;
            Dictionary<int, string> rowToName = new Dictionary<int, string>();

            for (int i = 0; i < dgvTable.Rows.Count - 1; i++)
            {
                string name = dgvTable.Rows[i].Cells[0].Value as string;

                if (string.IsNullOrEmpty(name) || newStates.ContainsKey(name))
                    continue;

                object isStart = dgvTable.Rows[i].Cells[1].Value;
                object isAccepted = dgvTable.Rows[i].Cells[2].Value;
                State state = new State(name, isAccepted == null ? false : (bool)isAccepted, isStart == null ? false : (bool)isStart);

                newStates.Add(state.Name, state);
                rowToName.Add(i, name);

                if (oldStates.ContainsKey(state.Name))
                    newStates[state.Name].Location = oldStates[state.Name].Location;
                else
                    newStates[state.Name].Location = new Point(State.STATE_SIZE + i * State.STATE_SIZE * 4, State.STATE_SIZE * 3);
            }

            for (int i = 0; i < dgvTable.Rows.Count - 1; i++)
            {
                using (DataGridViewRow row = dgvTable.Rows[i])
                {
                    if (!rowToName.ContainsKey(i))
                        continue;

                    string name = rowToName[i];

                    for (int col = 3; col < dgvTable.Columns.Count; col++)
                    {
                        string value = row.Cells[col].Value as string;

                        if (string.IsNullOrEmpty(value))
                            continue;

                        Match m = nondeterministic ? nfaParse.Match(value) : dfaParse.Match(value);

                        if (m!=null)
                        {
                            for (int capture = 0; capture < m.Groups["switch"].Captures.Count; capture++)
                            {
                                string dest = m.Groups["dest"].Captures[capture].Value;

                                if (!newStates.ContainsKey(dest))
                                    continue;

                                string input = dgvTable.Columns[col].HeaderText;
                                string output = m.Groups["output"].Captures[capture].Value;

                                if (!string.IsNullOrEmpty(output))
                                    output = output.TrimStart(new char[] { '/', ' ' });

                                Switch sw = new Switch(newStates[name], newStates[dest], input, output);

                                sw.From.Destinations.Add(sw);
                                sw.To.Sources.Add(sw);
                            }
                        }
                    }
                }
            }

            foreach (State s in newStates.Values)
            {
                if (oldStates.ContainsKey(s.Name))
                {
                    State oldState = oldStates[s.Name];
                    foreach (Switch swOld in oldState.Destinations)
                    {
                        foreach(Switch swNew in s.Destinations)
                            if (swOld.ToName == swNew.ToName)
                            {
                                swNew.C1Offset = swOld.C1Offset;
                                swNew.C1ROffset = swOld.C1ROffset;
                                swNew.C2Offset = swOld.C2Offset;
                                swNew.C2ROffset = swOld.C2ROffset;
                            }
                    }
                }
            }

            suMain.States = newStates;
        }
Exemplo n.º 4
0
 private static void OnSigmaStep(State sender, SigmaInterruptArgs e)
 {
     if (SigmaStep != null)
         SigmaStep(sender, e);
 }
Exemplo n.º 5
0
        private void initControls()
        {
            RichTextBox rtb = new RichTextBox();

            rtb.AppendText("DrawEA\n");
            rtb.SelectAll();
            rtb.SelectionFont = new Font(Font.FontFamily, Font.Size*2, FontStyle.Bold);

            rtb.SelectionLength = 0;
            rtb.SelectionStart = rtb.Text.Length;
            rtb.AppendText("Version " + Application.ProductVersion);
            rtb.SelectionLength = rtb.Text.Length - rtb.SelectionStart;
            rtb.SelectionFont = new Font(Font, FontStyle.Italic);

            rtb.ReadOnly = true;
            rtb.BackColor = Color.White;
            rtb.BorderStyle = BorderStyle.None;
            rtb.Location = new Point(50, 10);
            rtb.Size = new Size(200, 50);

            Controls.Add(rtb);

            Button close = new Button();

            close.Text = "x";
            close.Size = new Size(20, 20);
            close.Location = new Point(275, 5);

            close.Click += delegate { Close(); };

            Controls.Add(close);

            LinkLabel lblMail = new LinkLabel();

            lblMail.Text = "© 2006-2008 Andreas K.";
            lblMail.LinkArea = new LinkArea(12, 10);
            lblMail.LinkBehavior = LinkBehavior.HoverUnderline;
            lblMail.LinkClicked += delegate { System.Diagnostics.Process.Start("mailto:\"Andreas Krohn\"<*****@*****.**>?subject=DrawEA%20Version%20"+Application.ProductVersion); };

            lblMail.AutoSize = true;
            lblMail.Dock = DockStyle.Bottom;

            Controls.Add(lblMail);

            Bitmap bmp = new Bitmap(300, 190);
            Graphics g = Graphics.FromImage(bmp);

            int oldSize = State.STATE_SIZE;
            State.STATE_SIZE = 40;

            State A = new State("A", false, true);
            State B = new State("B", true, false);
            State C = new State("C", false, false);

            A.Destinations.Add(new Switch(A, B, "1", "done"));
            A.Destinations.Add(new Switch(A, C, "0", string.Empty));
            B.Destinations.Add(new Switch(B, B, "0", string.Empty));
            B.Destinations.Add(new Switch(B, B, "1", string.Empty));
            C.Destinations.Add(new Switch(C, A, "1", string.Empty));
            C.Destinations.Add(new Switch(C, C, "0", string.Empty));

            A.Location = new Point(40, 40);
            B.Location = new Point(230, 60);
            C.Location = new Point(160, 140);

            A.CalculateSwitchPoints();
            B.CalculateSwitchPoints();
            C.CalculateSwitchPoints();

            StringFormat sf = new StringFormat {Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center};

            using (Pen borderPen = new Pen(ForeColor, 4f))
            using (Pen switchOutline = new Pen(Color.FromArgb(220, BackColor), 5f))
            using (Pen switchPen = new Pen(ForeColor, 4f)
                                       {
                                           EndCap = LineCap.Custom,
                                           CustomEndCap = new AdjustableArrowCap(3, 3, true)
                                       })
            {
                g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);

                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBilinear;
                g.SmoothingMode = SmoothingMode.HighQuality;

                A.Draw(g, Brushes.White, borderPen, switchPen, Font, sf);
                B.Draw(g, Brushes.White, borderPen, switchPen, Font, sf);
                C.Draw(g, Brushes.White, borderPen, switchPen, Font, sf);
                A.DrawAllSwitches(g, A.CenterPoint(), switchPen, switchOutline, Font, sf, false);
                B.DrawAllSwitches(g, B.CenterPoint(), switchPen, switchOutline, Font, sf, true);
                C.DrawAllSwitches(g, C.CenterPoint(), switchPen, switchOutline, Font, sf, false);
            }

            State.STATE_SIZE = oldSize;

            PictureBox pb = new PictureBox();
            pb.SizeMode = PictureBoxSizeMode.AutoSize;
            pb.Image = bmp;
            pb.Location = new Point(0,60);

            Controls.Add(pb);

            close.Select();
        }