示例#1
0
 private void AddTransition()
 {
     if (SelectedFigure != null && SelectedFigure is State)
     {
         Figure tempState = getFigureByPoint(panel1.PointToClient(Control.MousePosition));
         if (tempState != null && tempState is State)
         {
             TransitionNameForm tnf = new TransitionNameForm();
             tnf.ShowDialog();
             if (Program.NewTransitionName != null)
             {
                 foreach(Transition t in findAllTrasitionsFromState((SelectedFigure as State).Name))
                 {
                     if(t.Name == Program.NewTransitionName)
                     {
                         Program.NewTransitionName = null;
                         MessageBox.Show("Данное имя уже используется в другом переходе из состояния начала", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         return;
                     }
                 }
                 TransitionList.Add(new Transition(SelectedFigure as State, tempState as State, Program.NewTransitionName));
                 Program.NewTransitionName = null;
                 if ((SelectedFigure as State).Name == (tempState as State).Name)
                 {
                     TransitionList[TransitionList.Count - 1].InfList.Add(new InfPoint(tempState.X - 20, tempState.Y - 40));
                     TransitionList[TransitionList.Count - 1].InfList.Add(new InfPoint(tempState.X + 20, tempState.Y - 40));
                 }
             }
             SelectedFigure = null;
             tempState = null;
         }
     }
 }
示例#2
0
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (toolStripButton2.Checked)
                    if (SelectedFigure != null)
                    {
                        SelectedFigure.X = e.X;
                        SelectedFigure.Y = e.Y;
                        SelectedFigure = null;
                    }

                if (toolStripButton3.Checked)
                    AddTransition();
            }
            Draw();
        }
示例#3
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            SelectedFigure = null;
            panel1.ContextMenu.MenuItems.Clear();
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (toolStripButton1.Checked)
                    StateList.Add(new State(e.X, e.Y, generateNewStateName()));

                if (toolStripButton2.Checked || toolStripButton3.Checked)
                    SelectedFigure = getFigureByPoint(e.Location);
            }
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                SelectedFigure = getFigureByPoint(e.Location);
                if (SelectedFigure != null)
                {
                    if (SelectedFigure is State)
                        createStateContentMenu();
                    if (SelectedFigure is InfPoint)
                        createInfPointContentMenu();
                }
            }
            Draw();
        }
示例#4
0
        private void markAsStartClick(object sender, System.EventArgs e)
        {
            if (getStartState() != null && getStartState().Name != (SelectedFigure as State).Name)
            {
                MessageBox.Show("Начальное состояние уже выбрано.\nЕсли Вы хотите выбрать другое начальное состояние, сначала снимите отметку с первого", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            foreach(State s in StateList)
                if (s.Name == (SelectedFigure as State).Name)
                {
                    SelectedFigure = null;
                    s.isStartState ^= !s.isFinalState;
                    break;
                }
            Draw();
        }
示例#5
0
 private void markAsFinalClick(object sender, System.EventArgs e)
 {
     foreach (State s in StateList)
         if (s.Name == (SelectedFigure as State).Name)
         {
             SelectedFigure = null;
             s.isFinalState ^= !s.isStartState;
             break;
         }
     Draw();
 }
示例#6
0
        private void deleteClick(object sender, System.EventArgs e)
        {
            if (SelectedFigure is State)
            {
                int name = (SelectedFigure as State).Name;
                DialogResult = MessageBox.Show("Сместить оставшиеся индексы состояний?", "Удаление состояния S" + name, MessageBoxButtons.YesNoCancel);
                if (DialogResult != System.Windows.Forms.DialogResult.Cancel)
                {
                    for (int i = 0; i < StateList.Count; i++)
                        if (StateList[i].Name == (SelectedFigure as State).Name)
                        {
                            SelectedFigure = null;
                            int j = 0;
                            while (j < TransitionList.Count)
                            {
                                for (j = 0; j < TransitionList.Count; j++)
                                {
                                    if (TransitionList[j].Start.Name == StateList[i].Name || TransitionList[j].End.Name == StateList[i].Name)
                                    {
                                        TransitionList.RemoveAt(j);
                                        break;
                                    }
                                }
                            }
                            StateList.RemoveAt(i);
                            break;
                        }
                }
                if (DialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    foreach (State s in StateList)
                        if (s.Name > name)
                            s.Name--;
                }
            }
            if (SelectedFigure is InfPoint)
            {
                foreach (Transition t in TransitionList)
                    for(int i=0; i<t.InfList.Count; i++)
                    {
                        if (SelectedFigure.X == t.InfList[i].X && SelectedFigure.Y == t.InfList[i].Y)
                            t.InfList.RemoveAt(i);
                    }
            }

            Draw();
        }