Exemple #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();
        }
Exemple #2
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();
        }