Example #1
0
        private void CreateUseCase(String name, Point mouse)
        {
            int width  = useCaseBaseWidth;
            int height = useCaseBaseHeight;

            if (name != "")
            {
                // Get size of name when drawn
                SizeF nameBounds = pictureBoxGraphics.MeasureString(name, Font);

                // Update width
                width = Math.Max(width, (int)nameBounds.Width + 15 * 2);
            }

            // Create use case
            UseCase useCase = new UseCase(useCaseBaseWidth, mouse.X, mouse.Y, width, height, name);

            // Draw actor and set as selected
            useCase.Draw(pictureBoxGraphics, Font, true);
            selectedIndex = useCases.Count;
            selectedType  = typeof(UseCase);

            // Add actor to list
            useCases.Add(useCase);

            // Open properties window
            useCasePropertiesForm = new UseCasePropertiesForm(useCase);
            useCasePropertiesForm.Show();
        }
Example #2
0
        public Form1()
        {
            InitializeComponent();

            selectedIndex                        = -1;
            selectedType                         = null;
            actors                               = new List <Actor>();
            useCases                             = new List <UseCase>();
            lines                                = new List <Line>();
            lineSelectionActor                   = null;
            lineSelectionUseCase                 = null;
            useCasePropertiesForm                = null;
            pictureBoxGraphics                   = useCaseDiagramPictureBox.CreateGraphics();
            pictureBoxGraphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            pictureBoxGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        }
Example #3
0
        private void UpdateUseCasePropertiesForm()
        {
            if (useCasePropertiesForm != null && selectedIndex != -1)
            {
                // Update usecase
                useCases[selectedIndex].name        = useCasePropertiesForm.nameTextBox.Text;
                useCases[selectedIndex].summary     = useCasePropertiesForm.summaryTextBox.Text;
                useCases[selectedIndex].assumption  = useCasePropertiesForm.assumptionTextBox.Text;
                useCases[selectedIndex].description = useCasePropertiesForm.descriptionTextBox.Text;
                useCases[selectedIndex].exception   = useCasePropertiesForm.exceptionTextBox.Text;
                useCases[selectedIndex].result      = useCasePropertiesForm.resultTextBox.Text;

                // Close dialog
                useCasePropertiesForm.Close();
                useCasePropertiesForm = null;
            }
        }
Example #4
0
        private void removeButton_Click(object sender, EventArgs e)
        {
            if (selectedIndex >= 0)
            {
                if (selectedType == typeof(Actor))
                {
                    // Check if connected to line
                    Line[] ls = GetConnectedLine(actors[selectedIndex]);

                    // Delete line and actor and actor in connected user case]
                    for (int i = 0; i < ls.Length; i++)
                    {
                        ls[i].useCase.actors.Remove(actors[selectedIndex]);

                        lines.Remove(ls[i]);
                    }
                    actors.RemoveAt(selectedIndex);
                }
                else if (selectedType == typeof(UseCase))
                {
                    // Check if connected to line
                    Line[] ls = GetConnectedLine(useCases[selectedIndex]);

                    // Delete line and actor
                    for (int i = 0; i < ls.Length; i++)
                    {
                        lines.Remove(ls[i]);
                    }

                    useCasePropertiesForm.Close();
                    useCasePropertiesForm = null;
                    useCases.RemoveAt(selectedIndex);
                }
                else if (selectedType == typeof(Line))
                {
                    // Remove actor from connected usecase
                    lines[selectedIndex].useCase.removeActor(lines[selectedIndex].actor);
                    lines.RemoveAt(selectedIndex);
                }
            }
            selectedIndex = -1;
            selectedType  = null;
            Redraw();
        }
Example #5
0
        private void useCaseDiagramPictureBox_MouseClick(object sender, MouseEventArgs e)
        {
            UpdateUseCasePropertiesForm();
            selectedIndex = -1;
            selectedType  = null;

            // Check if in create mode
            if (createRadioButton.Checked)
            {
                // Check if actor is checked
                if (actorRadioButton.Checked)
                {
                    // Open dialog prompting user for actor name
                    using (NameForm dialog = new NameForm("actor"))
                    {
                        DialogResult result = dialog.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            // Actor creation validated, continue!
                            CreateActor(dialog.actorNameTextBox.Text, e.Location);
                        }
                    }
                }
                else if (useCaseRadioButton.Checked)
                {
                    // Open dialog prompting user for use case name
                    using (NameForm dialog = new NameForm("use case"))
                    {
                        DialogResult result = dialog.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            // Actor creation validated, continue!
                            CreateUseCase(dialog.actorNameTextBox.Text, e.Location);
                        }
                    }
                }
                else if (lineRadioButton.Checked)
                {
                    for (int i = 0; i < actors.Count; i++)
                    {
                        Actor actor = actors[i];

                        // Check if mouse is within bound of actor
                        if (e.Location.X >= actor.x && e.Location.X <= actor.x + actor.width && e.Location.Y >= actor.y && e.Location.Y <= actor.y + actor.height)
                        {
                            // Check if there was already a use case selected (connection made)
                            if (lineSelectionUseCase != null)
                            {
                                lineSelectionActor = actor;
                                CreateLine();
                            }
                            else
                            {
                                // Check if there was previously another actor selected
                                if (lineSelectionActor != null)
                                {
                                    // Redraw that actor, only unselected
                                    lineSelectionActor.Draw(pictureBoxGraphics, Font, false);
                                }

                                // Set selected actor
                                lineSelectionActor = actor;

                                // Redraw selected actor, only selected
                                actor.Draw(pictureBoxGraphics, Font, true);
                                return;
                            }
                        }
                    }
                    for (int i = 0; i < useCases.Count; i++)
                    {
                        UseCase useCase = useCases[i];

                        // Check if mouse is within bound of use case
                        if (e.Location.X >= useCase.x && e.Location.X <= useCase.x + useCase.width && e.Location.Y >= useCase.y && e.Location.Y <= useCase.y + useCase.height)
                        {
                            // Check if there was already an actor selected (connection made)
                            if (lineSelectionActor != null)
                            {
                                lineSelectionUseCase = useCase;
                                CreateLine();
                            }
                            else
                            {
                                // Check if there was previously another use case selected
                                if (lineSelectionUseCase != null)
                                {
                                    // Redraw that use case, only unselected
                                    lineSelectionUseCase.Draw(pictureBoxGraphics, Font, false);
                                }

                                // Set selected use case
                                lineSelectionUseCase = useCase;

                                // Redraw selected use case, only selected
                                useCase.Draw(pictureBoxGraphics, Font, true);
                                return;
                            }
                        }
                    }

                    // Nothing selected, reset selection
                    lineSelectionActor   = null;
                    lineSelectionUseCase = null;
                }
            }
            else // Select mode
            {
                for (int i = 0; i < actors.Count; i++)
                {
                    Actor actor = actors[i];

                    // Check if mouse is within bound of actor
                    if (e.Location.X >= actor.x && e.Location.X <= actor.x + actor.width && e.Location.Y >= actor.y && e.Location.Y <= actor.y + actor.height)
                    {
                        // Redraw selected actor
                        actor.Draw(pictureBoxGraphics, Font, true);
                        selectedIndex = i;
                        selectedType  = typeof(Actor);
                        Redraw();
                        return;
                    }
                }
                for (int i = 0; i < useCases.Count; i++)
                {
                    UseCase useCase = useCases[i];

                    // Check if mouse is within bound of use case
                    if (e.Location.X >= useCase.x && e.Location.X <= useCase.x + useCase.width && e.Location.Y >= useCase.y && e.Location.Y <= useCase.y + useCase.height)
                    {
                        // Redraw selected use case
                        useCase.Draw(pictureBoxGraphics, Font, true);
                        selectedIndex         = i;
                        selectedType          = typeof(UseCase);
                        useCasePropertiesForm = new UseCasePropertiesForm(useCase);
                        useCasePropertiesForm.Show();
                        Redraw();
                        return;
                    }
                }
                for (int i = 0; i < lines.Count; i++)
                {
                    Line line = lines[i];

                    // Check if mouse is within bound of line
                    if (e.Location.X >= line.xSelectionBox && e.Location.X <= line.xSelectionBox + line.widthSelectionBox && e.Location.Y >= line.ySelectionBox && e.Location.Y <= line.ySelectionBox + line.heightSelectionBox)
                    {
                        // Redraw selected line
                        line.Draw(pictureBoxGraphics, Font, true);
                        selectedIndex = i;
                        selectedType  = typeof(Line);
                        Redraw();
                        return;
                    }
                }
            }

            Redraw();
        }