Exemple #1
0
 public Form1()
 {
     InitializeComponent();
     actorStripSelected                  = false;
     lineStripSelected                   = false;
     ellipseStripSelected                = false;
     Elements                            = new UseCaseDiagramDocument();
     firstPointDragStart                 = Point.Empty;
     dragStart                           = Point.Empty;
     resizeDragStart                     = Point.Empty;
     currentShape                        = null;
     FillColor                           = Color.YellowGreen;
     BorderColor                         = Color.CadetBlue;
     TextColor                           = Color.DarkOliveGreen;
     toolStripbtnFillColor.BackColor     = FillColor;
     toolStripbtnBorderColor.BackColor   = BorderColor;
     toolStripbtnTextColor.BackColor     = TextColor;
     startPointSelectRectangle           = Point.Empty;
     selectRectangle                     = Rectangle.Empty;
     previousCtrlDown                    = false;
     lastClickedShape                    = null;
     toolStripHover                      = Color.LightGray;
     toolStripNotHover                   = Color.WhiteSmoke;
     toolStripMobile.BackColor           = toolStripNotHover;
     copyList                            = new List <IDrawable>();
     toolStripbtnFillColor.ToolTipText   = "Fill Color";
     toolStripbtnBorderColor.ToolTipText = "Border Color";
     toolStripbtnTextColor.ToolTipText   = "Text Color";
     undoElements                        = new UseCaseDiagramDocument();
     undoDone                            = true;
     redoDone                            = true;
 }
Exemple #2
0
        public UseCaseDiagramDocument(UseCaseDiagramDocument obj)
        {
            List <IDrawable> elem = new List <IDrawable>();

            foreach (IDrawable o in obj.Elements)
            {
                if (o is UMLElipse)
                {
                    UMLElipse elipse    = o as UMLElipse;
                    UMLElipse newObject = new UMLElipse(elipse);
                    elem.Add(newObject);
                }
                else if (o is Line)
                {
                    Line line      = o as Line;
                    Line newObject = new Line(line);
                    elem.Add(newObject);
                }
                else if (o is Actor)
                {
                    Actor actor     = o as Actor;
                    Actor newObject = new Actor(actor);
                    elem.Add(newObject);
                }
            }
            Elements = elem;
        }
Exemple #3
0
 public void newDocument()
 {
     if (MessageBox.Show("Дали сакате да отворите нов документ?", "Нов документ?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         Elements = new UseCaseDiagramDocument();
         toolStripMobile.Visible = false;
         Invalidate(true);
     }
 }
Exemple #4
0
 private void cut()
 {
     copy();
     undoElements = new UseCaseDiagramDocument(Elements);
     foreach (IDrawable obj in copyList)
     {
         Elements.Elements.Remove(obj);
     }
     toolStripMobile.Visible = false;
     Invalidate(true);
 }
Exemple #5
0
 public void redo()
 {
     if (!redoDone)
     {
         redoDone                = true;
         undoDone                = false;
         undoElements            = new UseCaseDiagramDocument(Elements);
         Elements                = new UseCaseDiagramDocument(redoElements);
         redoElements            = new UseCaseDiagramDocument();
         toolStripMobile.Visible = false;
         Invalidate(true);
     }
 }
Exemple #6
0
 public void undo()
 {
     if (!undoDone)           //if undo is not done yet
     {
         undoDone                = true;
         redoDone                = false;
         redoElements            = new UseCaseDiagramDocument(Elements); //save the elements for redo, deep copy
         Elements                = new UseCaseDiagramDocument(undoElements);
         undoElements            = new UseCaseDiagramDocument();         //delete the undo elements
         toolStripMobile.Visible = false;
         Invalidate(true);                                               //repaint
     }
 }
Exemple #7
0
        private void open()
        {
            OpenFileDialog op = new OpenFileDialog();

            op.Filter = "DrawU file (*.drawu)|*.drawu";
            op.Title  = "Open a DrawU file";
            if (op.ShowDialog() == DialogResult.OK)
            {
                System.Runtime.Serialization.IFormatter fm = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                fileName = op.FileName;
                FileStream sm = new FileStream(fileName, FileMode.Open);
                Elements = fm.Deserialize(sm) as UseCaseDiagramDocument;
                toolStripMobile.Visible = false;
            }
        }
Exemple #8
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                return;
            }
            UseCaseDiagramDocument docCopy = new UseCaseDiagramDocument(Elements);

            if (selectRectangle != Rectangle.Empty)
            {
                for (int x = selectRectangle.X; x < selectRectangle.X + selectRectangle.Width; x++)
                {
                    if (docCopy.Elements.Count == 0)
                    {
                        break;
                    }
                    for (int y = selectRectangle.Y; y < selectRectangle.Y + selectRectangle.Height; y++)
                    {
                        if (docCopy.Elements.Count == 0)
                        {
                            break;
                        }
                        for (int i = docCopy.Elements.Count - 1; i >= 0; i--)
                        {
                            int index = Elements.Elements.IndexOf(docCopy.Elements[i]);
                            if (index != -1)
                            {
                                Elements.Elements[index].isSelected(new Point(x, y), true);
                                if (Elements.Elements[index].Selected)
                                {
                                    docCopy.Elements.RemoveAt(i);
                                }
                            }
                        }
                    }
                }
            }
            Invalidate(true);
            startPointSelectRectangle = Point.Empty;
            selectRectangle           = Rectangle.Empty;
            dragStart           = Point.Empty;
            resizeDragStart     = Point.Empty;
            firstPointDragStart = Point.Empty;
            this.Cursor         = Cursors.Default;
        }
Exemple #9
0
 private void paste()
 {
     undoElements = new UseCaseDiagramDocument(Elements);
     foreach (IDrawable obj in copyList)
     {
         obj.Selected = true;
         if (obj is UMLElipse || obj is Actor)
         {
             obj.X += 10;
             obj.Y += 10;
         }
         else
         {
             Line l = obj as Line;
             l.X1 += 5;
             l.Y1 += 5;
             l.X2 += 5;
             l.Y2 += 5;
         }
         Elements.Elements.Add(obj);
     }
     copyList = new List <IDrawable>();
     Invalidate(true);
 }
Exemple #10
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control)
            {
                ctrlDown = true;
            }
            else if (e.KeyCode == Keys.Escape)
            {
                unselectShapes();
                unselectToolStrips();
                currentShape = null;
            }
            else if (e.KeyCode == Keys.Left)
            {
                undoElements = new UseCaseDiagramDocument(Elements);
                foreach (IDrawable obj in Elements.Elements)
                {
                    if (obj.Selected)
                    {
                        obj.Move(-10, 0);
                    }
                }
                toolStripMobile.Location = new Point(toolStripMobile.Location.X - 10, toolStripMobile.Location.Y);
            }
            else if (e.KeyCode == Keys.Right)
            {
                undoElements = new UseCaseDiagramDocument(Elements);
                foreach (IDrawable obj in Elements.Elements)
                {
                    if (obj.Selected)
                    {
                        obj.Move(10, 0);
                        EnlargeIfNeeded(obj);
                    }
                }
                toolStripMobile.Location = new Point(toolStripMobile.Location.X + 10, toolStripMobile.Location.Y);
            }
            else if (e.KeyCode == Keys.Up)
            {
                undoElements = new UseCaseDiagramDocument(Elements);
                foreach (IDrawable obj in Elements.Elements)
                {
                    if (obj.Selected)
                    {
                        obj.Move(0, -10);
                    }
                }
                toolStripMobile.Location = new Point(toolStripMobile.Location.X, toolStripMobile.Location.Y - 10);
            }
            else if (e.KeyCode == Keys.Down)
            {
                undoElements = new UseCaseDiagramDocument(Elements);
                foreach (IDrawable obj in Elements.Elements)
                {
                    if (obj.Selected)
                    {
                        obj.Move(0, 10);
                        EnlargeIfNeeded(obj);
                    }
                }
                toolStripMobile.Location = new Point(toolStripMobile.Location.X, toolStripMobile.Location.Y + 10);
            }
            else if (e.KeyCode == Keys.Delete)
            {
                deleteSelected();
            }

            Invalidate(true);
        }
Exemple #11
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                return;
            }
            if (currentShape != null)
            {
                undoElements = new UseCaseDiagramDocument(Elements);
                undoDone     = false;
                unselectShapes();
                currentShape.Selected = true;
                Elements.Add(currentShape);
                EnlargeIfNeeded(currentShape);
                currentShape = null;
                unselectToolStrips();
            }
            else
            {
                bool Moveflag        = false;
                bool resizeFlag      = false;
                bool lineFirstPoint  = false;
                bool anyShapeClicked = false;
                foreach (IDrawable obj in Elements.Elements)
                {
                    if (obj.IsFirstPointClicked(e.Location) && !ctrlDown)
                    {
                        undoElements        = new UseCaseDiagramDocument(Elements);
                        undoDone            = false;
                        firstPointDragStart = e.Location;
                        lineFirstPoint      = true;
                    }
                    else if (obj.IsResizeSquareClicked(e.Location) && !ctrlDown)
                    {
                        undoElements    = new UseCaseDiagramDocument(Elements);
                        undoDone        = false;
                        resizeDragStart = e.Location;
                        resizeFlag      = true;
                    }
                    else if (obj.Selected && obj.isClicked(e.Location) && !ctrlDown)
                    {
                        undoElements = new UseCaseDiagramDocument(Elements);
                        undoDone     = false;
                        Moveflag     = true;
                    }
                }
                if (!resizeFlag && !lineFirstPoint)
                {
                    if (Moveflag)
                    {
                        undoElements = new UseCaseDiagramDocument(Elements);
                        undoDone     = false;
                        dragStart    = e.Location;
                        this.Cursor  = Cursors.SizeAll;
                    }
                    else
                    {
                        Elements.Selected(e.Location, ctrlDown);
                    }
                }
                if (!ctrlDown && !Moveflag && !resizeFlag)
                {
                    foreach (IDrawable obj in Elements.Elements)
                    {
                        obj.isSelected(e.Location, false);
                        if (obj.Selected)
                        {
                            anyShapeClicked         = true;
                            previouslyShapeSelected = true;
                        }
                    }
                    if (!anyShapeClicked)
                    {
                        startPointSelectRectangle = e.Location;
                    }
                }
            }

            lastClickedShape = null;
            foreach (IDrawable obj in Elements.Elements)
            {
                if (obj.isClicked(e.Location))
                {
                    lastClickedShape = obj;
                }
            }
            if (lastClickedShape != null)
            {
                Point location = new Point(lastClickedShape.X, lastClickedShape.Y - 30);
                location.X -= panel1.HorizontalScroll.Value;
                location.Y -= panel1.VerticalScroll.Value;
                location.X  = Math.Max(location.X, 0);
                toolStripMobile.Location              = location;
                toolStripMobileChangeText.Text        = lastClickedShape.Text;
                toolStripMobilecbBorderWidth.Text     = lastClickedShape.BorderWidth.ToString();
                toolStripMobilebtnBorderColor.Enabled = true;
                toolStripMobilebtnFillColor.Enabled   = true;
                if (lastClickedShape.GetType() == typeof(Actor))
                {
                    toolStripMobilebtnBorderColor.Enabled = false;
                    toolStripMobilebtnFillColor.Enabled   = false;
                }
                else if (lastClickedShape.GetType() == typeof(Line))
                {
                    toolStripMobilebtnFillColor.Enabled = false;
                }
                toolStripMobile.Visible = true;
            }
            else
            {
                toolStripMobile.Visible = false;
            }

            Invalidate(true);
        }