Exemplo n.º 1
0
        public void AddShape(MouseButtonEventArgs e)
        {
            string UMLFields  = "-First field : int\n-Second Field : String";
            string UMLMethods = "+First method()\n+Second method()";
            Point  p          = e.MouseDevice.GetPosition(e.Source as IInputElement);
            IShape shape      = null;

            switch (SelectedFigure)
            {
            case 0:
                shape = new BasicShapeViewModel(new BasicShape(EBasicShape.Ellipse, p.X, p.Y, 50, 50, SelectedColor, CreateShapeID()));
                break;

            case 1:
                shape = new UMLClassViewModel(new UMLClass(p.X, p.Y, 300, 200, "New Shape", SelectedColor, CreateShapeID(), UMLFields, UMLMethods));
                break;

            case 2:
                shape = new BasicShapeViewModel(new BasicShape(EBasicShape.Rectangle, p.X, p.Y, 50, 50, SelectedColor, CreateShapeID()));
                break;

            default:
                Console.WriteLine("Figure selection error");
                break;
            }
            if (shape != null)
            {
                new ShapeAddCommand(Shapes, shape).Execute();
            }
            Tool = ETool.Default;
        }
Exemplo n.º 2
0
        private void loading(List <ModelBase> loadedModelsList)
        {
            IList <ILine>  linesAdd  = new List <ILine>();
            IList <IShape> shapesAdd = new List <IShape>();

            foreach (var loadedModel in loadedModelsList)
            {
                if (loadedModel is UMLClass)
                {
                    var actualUMLClass = loadedModel as UMLClass;
                    var storedColor    = Color.FromRgb(actualUMLClass.ColorR, actualUMLClass.ColorG, actualUMLClass.ColorB);

                    IShape actualViewModel = new UMLClassViewModel(new UMLClass(actualUMLClass.X + _loadingOffSet, actualUMLClass.Y + _loadingOffSet, actualUMLClass.Width, actualUMLClass.Height,
                                                                                actualUMLClass.Name, storedColor, actualUMLClass.ID, actualUMLClass.UMLFields, actualUMLClass.UMLMethods));

                    shapesAdd.Add(actualViewModel);
                }
                else if (loadedModel is BasicShape)
                {
                    var actualBasicShape = loadedModel as BasicShape;
                    var storedColor      = Color.FromRgb(actualBasicShape.ColorR, actualBasicShape.ColorG, actualBasicShape.ColorB);


                    IShape actualViewModel = new BasicShapeViewModel(new BasicShape(actualBasicShape.Type, actualBasicShape.X + _loadingOffSet, actualBasicShape.Y + _loadingOffSet,
                                                                                    actualBasicShape.Width, actualBasicShape.Height, storedColor, actualBasicShape.ID));
                    shapesAdd.Add(actualViewModel);
                }
                else if (loadedModel is Line)
                {
                    var    actualLine = loadedModel as Line;
                    string fromID     = actualLine.StoreFromId;
                    string toID       = actualLine.StoreToId;
                    IPoint cpFrom     = null;
                    IPoint cpTo       = null;

                    foreach (var viewModel in shapesAdd)
                    {
                        var actualViewModel = viewModel as IShape;

                        if (actualViewModel.ID == fromID)
                        {
                            cpFrom = actualViewModel.ConnectionPoints.ElementAt(0);
                        }

                        if (actualViewModel.ID == toID)
                        {
                            cpTo = actualViewModel.ConnectionPoints.ElementAt(0);
                        }
                    }

                    if (cpFrom != null || cpTo != null)
                    {
                        linesAdd.Add(new LineViewModel(new Line(actualLine.Type, cpFrom, cpTo)));
                    }
                }
            }

            new MultiUndoRedoCommand(new List <UndoRedoCommand>()
            {
                new ShapeAddCommand(Shapes, shapesAdd),
                new LineAddCommand(Lines, linesAdd)
            }).Execute();
        }