예제 #1
0
        /// <summary>
        /// Выбрать фигуры, находящиеся в прямоугольнике выборки
        /// </summary>
        private void SelectFiguresInRect()
        {
            if (_presenter.GetFigures() == null)
            {
                _selectionRect = new Rectangle();
                return;
            }

            var selectedFigures = new Dictionary <int, BaseFigure>();

            foreach (var figure in _presenter.GetFigures())
            {
                var points     = figure.Value.Points.GetPoints();
                var figureRect = GetRect(points);
                if (_selectionRect.IntersectsWith(figureRect))
                {
                    selectedFigures.Add(figure.Key, figure.Value);
                }
            }
            if (selectedFigures.Count == 0)
            {
                _isSelectionEmpty = true;
            }
            else
            {
                SelectedFigures.Clear();
                SelectedFigures = selectedFigures;
            }
            _selectionRect = new Rectangle();
        }
예제 #2
0
        public void GetFromClipboard()
        {
            IDataObject      dataObj        = Clipboard.GetDataObject();
            List <My_Figure> pasted_figures = new List <My_Figure>();

            if (dataObj.GetDataPresent(typeof(byte[])))
            {
                byte[] data = dataObj.GetData(typeof(byte[])) as byte[];
                pasted_figures = My_Picture.Deserialize(data);
                if (pasted_figures == null)
                {
                    return;
                }
            }
            foreach (My_Figure figure in pasted_figures)
            {
                figure.Core = this;
                picture.FigureList.Add(figure);
                SelectedFigures.Add(figure);
                if (figure is My_Port)
                {
                    (figure as My_Port).TextLabel.Core = this;
                }
            }

            AddToHistory();
            form.Invalidate();
        }
예제 #3
0
 public void UnselectAll()
 {
     SelectedFigures.Clear();
     SelectedFigure = null;
     foreach (My_Figure fig in picture.FigureList)
     {
         fig.selected = false;
     }
 }
예제 #4
0
        public void CreateNewPort(My_Port.PortType type, bool Inverse)
        {
            My_Port p = new My_Port(this, type, Inverse);

            UnselectAll();
            SelectedFigure = p;
            SelectedFigures.Add(p);
            picture.FigureList.Add(p);
            Lock = true;
        }
예제 #5
0
        public void CreateNewRectangle()
        {
            My_Rectangle rectangle = new My_Rectangle(this);

            UnselectAll();
            SelectedFigure = rectangle;
            SelectedFigures.Add(rectangle);
            picture.FigureList.Add(rectangle);
            Lock = true;
        }
예제 #6
0
        public void CreateNewArc()
        {
            My_Arc arc = new My_Arc(this);

            UnselectAll();
            SelectedFigure = arc;
            SelectedFigures.Add(arc);
            picture.FigureList.Add(arc);
            Lock = true;
        }
예제 #7
0
        public void CreateNewPolyline()
        {
            My_Polyline polyline = new My_Polyline(this);

            UnselectAll();
            SelectedFigure = polyline;
            SelectedFigures.Add(polyline);
            picture.FigureList.Add(polyline);
            Lock = true;
        }
예제 #8
0
        public void CreateNewText()
        {
            My_Text text = new My_Text(this);

            UnselectAll();
            SelectedFigure = text;
            SelectedFigures.Add(text);
            picture.FigureList.Add(text);
            Lock = true;
        }
예제 #9
0
        public void CreateNewPath()
        {
            My_Path path = new My_Path(this);

            UnselectAll();
            SelectedFigure = path;
            SelectedFigures.Add(path);
            picture.FigureList.Add(path);
            Lock = true;
        }
예제 #10
0
        public void CreateNewCurve()
        {
            My_Curve curve = new My_Curve(this);

            UnselectAll();
            SelectedFigure = curve;
            SelectedFigures.Add(curve);
            picture.FigureList.Add(curve);
            Lock = true;
        }
예제 #11
0
        public void CreateNewSplineBezier()
        {
            My_SplineBezier spline = new My_SplineBezier(this);

            UnselectAll();
            SelectedFigure = spline;
            SelectedFigures.Add(spline);
            picture.FigureList.Add(spline);
            Lock = true;
        }
예제 #12
0
        public void CreateNewPolygon()
        {
            My_Polygon polygon = new My_Polygon(this);

            UnselectAll();
            SelectedFigure = polygon;
            SelectedFigures.Add(polygon);
            picture.FigureList.Add(polygon);
            Lock = true;
        }
예제 #13
0
        public void CreateNewLine()
        {
            My_Line line = new My_Line(this);

            UnselectAll();
            SelectedFigure = line;
            SelectedFigures.Add(line);
            picture.FigureList.Add(line);
            Lock = true;
        }
예제 #14
0
        public void CreateNewEllipse()
        {
            My_Ellipse ellipse = new My_Ellipse(this);

            UnselectAll();
            SelectedFigure = ellipse;
            SelectedFigures.Add(ellipse);
            picture.FigureList.Add(ellipse);
            Lock = true;
        }
예제 #15
0
 public void SelectAll()
 {
     SelectedFigures.Clear();
     SelectedFigure = null;
     foreach (My_Figure fig in picture.FigureList)
     {
         SelectedFigures.Add(fig);
         fig.selected = true;
     }
 }
예제 #16
0
        public void CreateNewPie()
        {
            My_Pie pie = new My_Pie(this);

            UnselectAll();
            SelectedFigure = pie;
            SelectedFigures.Add(pie);
            picture.FigureList.Add(pie);
            Lock = true;
        }
예제 #17
0
        public void CreateNewImage(string filename)
        {
            Bitmap   bitmap = Bitmap.FromFile(filename) as Bitmap;
            My_Image img    = new My_Image(this, bitmap);

            UnselectAll();
            SelectedFigure = img;
            SelectedFigures.Add(img);
            picture.FigureList.Add(img);
            Lock = true;
        }
예제 #18
0
        public void MoveByKey(Keys key)
        {
            Step tmpStep = new Step(DefaultStep);

            if (SelectedFigures.Count == 0)
            {
                SelectedFigures.AddRange(Figures);
            }

            switch (key)
            {
            case Keys.Left:
                tmpStep = SetStep(tmpStep, 1, 0);
                break;

            case Keys.Right:
                tmpStep = SetStep(tmpStep, -1, 0);
                break;

            case Keys.Up:
                tmpStep = SetStep(tmpStep, 0, 1);
                break;

            case Keys.Down:
                tmpStep = SetStep(tmpStep, 0, -1);
                break;
            }

            foreach (IFigure figure in SelectedFigures)
            {
                if (figure is AbstractArrow arrow)
                {
                    WriteLogs(arrow, false);
                    for (int i = 0; i < arrow.Points.Count; i++)
                    {
                        Point point = new Point(arrow.Points[i].X - tmpStep.X, arrow.Points[i].Y - tmpStep.Y);
                        arrow.Points[i] = point;
                    }
                    WriteLogs(arrow, true);
                }
                if (figure is AbstractBox box)
                {
                    WriteLogs(box, false);
                    for (int i = 0; i < box.Points.Count; i++)
                    {
                        Point point = new Point(box.Points[i].X - tmpStep.X, box.Points[i].Y - tmpStep.Y);
                        box.Points[i] = point;
                    }
                    WriteLogs(box, true);
                }
            }
            UpdPicture();
        }
예제 #19
0
 public void LoadTmpFigure()
 {
     SelectedFigures.Clear();
     foreach (IFigure figure in TmpFigures)
     {
         WriteLogs(null, false);
         var copyFigure = Activator.CreateInstance(Type.GetType(figure.GetType().FullName), figure);
         WriteLogs((IFigure)copyFigure, true);
         SelectedFigures.Add((IFigure)copyFigure);
     }
     Figures.AddRange(SelectedFigures);
     UpdPicture();
 }
예제 #20
0
        public void SwapTypeArrow()
        {
            string[] typeArrow = new string[5]
            {
                "Project_UML.Core.Arrows.AggregationArrow",
                "Project_UML.Core.Arrows.AssociationArrow",
                "Project_UML.Core.Arrows.CompositionArrow",
                "Project_UML.Core.Arrows.ImplementationArrow",
                "Project_UML.Core.Arrows.InheritanceArrow"
            };
            IFigure newFigure = null;

            TempFig = new List <IFigure>();
            foreach (IFigure figure in SelectedFigures)
            {
                if (figure is AbstractArrow arrow)
                {
                    WriteLogs(arrow, false);

                    for (int i = 0; i < typeArrow.Length; i++)
                    {
                        if (typeArrow[i] == arrow.GetType().FullName)
                        {
                            int tmp = i + 1;
                            if (tmp == 5)
                            {
                                tmp = 1;
                            }
                            var newArrow = Activator.CreateInstance(Type.GetType(typeArrow[tmp]), (IFigure)arrow);
                            newFigure = (AbstractArrow)newArrow;
                            break;
                        }
                    }
                    WriteLogs(newFigure, true);
                    TempFig.Add(newFigure);
                    Figures.Remove(arrow);
                    Figures.Add(newFigure);
                }
                else
                {
                    TempFig.Add(figure);
                }
            }
            SelectedFigures.Clear();
            SelectedFigures.AddRange(TempFig);
            UpdPicture();
        }
예제 #21
0
 /// <summary>
 /// Обработки отпускания мышки
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (_isDraggingSelectionRect)
         {
             //Выборка закончилась
             _isDraggingSelectionRect = false;
             SelectFiguresInRect();
             _isFigurePicked = true;
             if (_isSelectionEmpty)
             {
                 _isFigurePicked = false;
                 SelectedFigures.Clear();
                 _selectedFigure   = null;
                 _isSelectionEmpty = false;
             }
         }
         if (_isMouseDown)
         {
             if (!IsItMoving(_originalMouseDownPoint, e.Location))
             {
                 if (IsPointOnFigure(e.Location))
                 {
                     SelectedFigures.Clear();
                     _selectedFigure = _presenter.GetFigures()
                                       [GetFigurePointOn(e.Location)];
                     int index = GetFigurePointOn(e.Location);
                     SelectedFigures.Add(index, _presenter.GetFigures()[index]);
                     _isFigurePicked = true;
                 }
                 else
                 {
                     SelectedFigures.Clear();
                     _selectedFigure = null;
                     _isFigurePicked = false;
                 }
             }
             _isMouseDown = false;
         }
     }
     Canvas.Refresh();
 }
예제 #22
0
 public PreparationData LoadData(Form menu)
 {
     if (_coreUML.MyPath == "")
     {
         MessageBox.Show("Последнее сохранение не определено, повторите попытку, после создания нового сохранения");
         _data = null;
     }
     else
     {
         SelectedFigures.Clear();
         Figures.Clear();
         _deserializer = new Deserialize();
         _data         = _deserializer.DeserializationDictionary();
         if (_data != null)
         {
             Loading(menu);
         }
     }
     return(_data);
 }
예제 #23
0
        //Мышка нажата
        /// <summary>
        /// Обработчик события нажатия мышки
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (_isFigurePicked &&
                    SelectedFigures != null)
                {
                    if (IsPointOnFigure(e.Location))
                    {
                        if ((SelectedFigures != null) &&
                            SelectedFigures.ContainsKey(GetFigurePointOn(e.Location)))
                        {
                            _selectedFigure = _presenter.GetFigures()
                                              [GetFigurePointOn(e.Location)];

                            //Сохраняем предыдущее состояние
                            BeforeState?.Clear();

                            foreach (var figure in SelectedFigures)
                            {
                                if (!_presenter.GetFigures().Contains(figure))
                                {
                                    continue;
                                }
                                var index = figure.Key;
                                BeforeState?.Add(index, FigureFactory.CreateCopy(figure.Value));
                            }

                            MouseMoveDelegate -= MouseMoveSelecting;
                            MouseMoveDelegate += MouseMoveFigure;
                            MouseUpDelegate   += MouseUpFigure;

                            _offsetX = _selectedFigure.Points.GetPoints()[0].X - e.X;
                            _offsetY = _selectedFigure.Points.GetPoints()[0].Y - e.Y;
                        }
                    }
                    else if (IsPointOnMarker(e.Location, out _pickedPoint))
                    {
                        MouseMoveDelegate -= MouseMoveSelecting;
                        MouseMoveDelegate += MouseMoveMarker;
                        MouseUpDelegate   += MouseUpMarker;

                        BeforePointState?.Clear();

                        foreach (var figure in _presenter.GetFigures())
                        {
                            if (figure.Key != _pickedFigureIndex)
                            {
                                continue;
                            }
                            _oldFigureIndex = figure.Key;
                            BeforePointState?.Add(_oldFigureIndex,
                                                  FigureFactory.CreateCopy(figure.Value));
                        }

                        _offsetX = _pickedPoint.X - e.X;
                        _offsetY = _pickedPoint.Y - e.Y;
                    }
                    else
                    {
                        _isMouseDown = true;
                    }
                }
                else
                {
                    _isMouseDown = true;
                }
                _originalMouseDownPoint = e.Location;
            }
        }
예제 #24
0
 /// <summary>
 /// Очистить выборку фигур
 /// </summary>
 public void ClearSelectedFigures()
 {
     SelectedFigures.Clear();
     _selectedFigure = null;
 }