Пример #1
0
        public AutomatonMaker(bool nondeterministic)
        {
            createdAutomatonCore = new AutomatonCore(nondeterministic);

            InitializeComponent();

            this.DoubleClick += delegate(object sender, EventArgs e)
            {
                MouseEventArgs     me = e as MouseEventArgs;
                AutomatonNodeMaker b  = new AutomatonNodeMaker(this, false);
                b.Location  = new Point(me.Location.X - 25, me.Location.Y - 25);
                b.Size      = new Size(50, 50);
                b.FlatStyle = FlatStyle.Popup;
                b.Parent    = this;
                this.Controls.Add(b);
                createdAutomatonCore.nodes.Add(b.createdAutomatonNodeCore);
            };
            System.Windows.Forms.Timer refreshTimer = new System.Windows.Forms.Timer();
            refreshTimer.Interval = (int)Math.Round(1000.0f / 30.0f);
            refreshTimer.Tick    += delegate
            {
                this.Refresh();
                this.Invalidate();
            };
            refreshTimer.Start();
        }
Пример #2
0
        //Used to remove nodes from both the screen and the core
        public void removeNode(AutomatonNodeMaker node)
        {
            //Remove itself from its parents and childs
            node.createdAutomatonNodeCore.parents.ForEach(parent => parent.automatonNode.children.RemoveAll(n => n.automatonNode == node.createdAutomatonNodeCore));
            node.createdAutomatonNodeCore.children.ForEach(child => child.automatonNode.parents.RemoveAll(n => n.automatonNode == node.createdAutomatonNodeCore));

            createdAutomatonCore.nodes.Remove(node.createdAutomatonNodeCore);
            Controls.Remove(node);
        }
Пример #3
0
        //Draws the automaton in progress of being made
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;
            base.OnPaint(e);

            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            using (Font f = new Font(this.Font.SystemFontName, 20, FontStyle.Bold))
            {
                using (Pen a = new Pen(Color.Teal, 5))
                {
                    a.EndCap = LineCap.ArrowAnchor;

                    foreach (object obj in Controls)
                    {
                        AutomatonNodeMaker n1 = obj as AutomatonNodeMaker;

                        if (n1 == null)
                        {
                            continue;
                        }

                        //End
                        using (Pen p = new Pen(n1 == selectedAutomatonNodeMaker ? (transitionCreator ? Color.Pink : Color.Blue) : Color.Red, 4))
                        {
                            e.Graphics.DrawEllipse(p, n1.Location.X + 2, n1.Location.Y + 2, n1.Size.Width - 4, n1.Size.Height - 4);
                            if (n1.createdAutomatonNodeCore.isEndNode)
                            {
                                e.Graphics.DrawEllipse(p, n1.Location.X + 2 + 6, n1.Location.Y + 2 + 6, n1.Size.Width - 4 - 12, n1.Size.Height - 4 - 12);
                            }
                        }

                        //Start
                        if (n1.createdAutomatonNodeCore.isBeginNode)
                        {
                            e.Graphics.DrawCurve(a, new Point[] { new Point(n1.Location.X + (n1.Size.Width / 2) - 100, n1.Location.Y + (n1.Size.Height / 2)),
                                                                  new Point(n1.Location.X + (n1.Size.Width / 2), n1.Location.Y + (n1.Size.Height / 2)) });
                        }

                        //Transition
                        foreach (AutomatonTransition transition in n1.createdAutomatonNodeCore.children)
                        {
                            foreach (object obj2 in Controls)
                            {
                                AutomatonNodeMaker n2 = obj2 as AutomatonNodeMaker;

                                if (n2 == null)
                                {
                                    continue;
                                }

                                if (transition.automatonNode == n2.createdAutomatonNodeCore)
                                {
                                    string txt = "";
                                    for (int i = 0; i < transition.acceptedSymbols.Count; i++)
                                    {
                                        txt += transition.acceptedSymbols[i];
                                        if ((i + 1) < transition.acceptedSymbols.Count)
                                        {
                                            txt += ",";
                                        }
                                    }

                                    if (n1.createdAutomatonNodeCore == n2.createdAutomatonNodeCore)
                                    {
                                        e.Graphics.DrawCurve(a, new Point[] { new Point(n1.Location.X, n1.Location.Y + (n1.Size.Height / 2)),
                                                                              new Point(n1.Location.X, n1.Location.Y - (n1.Size.Height / 2)),
                                                                              new Point(n1.Location.X + n1.Width, n1.Location.Y - (n1.Size.Height / 2)),
                                                                              new Point(n1.Location.X + n1.Width, n1.Location.Y + (n1.Size.Height / 2)) });

                                        e.Graphics.DrawString(txt, f, Brushes.Black, new Point(n1.Location.X + (n1.Width / 2), n1.Location.Y - (n1.Size.Height / 4)), stringFormat);
                                    }
                                    else
                                    {
                                        e.Graphics.DrawCurve(a, new Point[] { new Point(n1.Location.X + (n1.Size.Width / 2), n1.Location.Y + (n1.Size.Height / 2)),
                                                                              new Point(n2.Location.X + (n2.Size.Width / 2), n2.Location.Y + (n2.Size.Height / 2)) });

                                        e.Graphics.DrawString(txt, f, Brushes.Black, new Point(
                                                                  (n1.Location.X + (n1.Size.Width / 2)) - (((n1.Location.X + (n1.Size.Width / 2) - (n2.Location.X + (n2.Size.Width / 2))) / 2)),
                                                                  (n1.Location.Y + (n1.Size.Height / 2)) - (((n1.Location.Y + (n1.Size.Height / 2) - (n2.Location.Y + (n2.Size.Height / 2))) / 2))),
                                                              stringFormat);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
 public StateNameInputBox(AutomatonNodeMaker automatonNodeMaker)
 {
     this.automatonNodeMaker = automatonNodeMaker;
     InitializeComponent();
 }