private void DeSerializeXMLToObject(string filepath)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(SaveLoadCollection));

            using (StreamReader wr = new StreamReader(filepath))
            {
                SaveLoadCollection Load = (SaveLoadCollection)serializer.Deserialize(wr);
                classCollection.Clear();
                arrowCollection.Clear();
                ClassIndex = Load.tempDiagrams.Count + 1;
                foreach (Diagram tempDiagram in Load.tempDiagrams)
                {
                    classCollection.Add(new ClassViewModel(tempDiagram));
                }
                foreach (ArrowViewModel arrow in Load.tempArrows)
                {
                    ClassViewModel DiagramA = null;
                    ClassViewModel DiagramB = null;
                    foreach (ClassViewModel diagram in classCollection)
                    {
                        if (arrow.DiagramA.Id == diagram.Id)
                        {
                            DiagramA = diagram;
                        }
                        else if (arrow.DiagramB.Id == diagram.Id)
                        {
                            DiagramB = diagram;
                        }
                    }
                    ArrowViewModel tempArrow = new ArrowViewModel(DiagramA, DiagramB, arrow.arrow);
                    undoRedoController.AddAndExecute(new AddArrowCommand(arrowCollection, tempArrow));
                }
                undoRedoController.Reset();
            }
        }
Beispiel #2
0
 public ArrowViewModel(ClassViewModel nVMEndA, ClassViewModel nVMEndB, EArrows type)
 {
     arrow    = new Arrow();
     DiagramA = nVMEndA;
     DiagramB = nVMEndB;
     Type     = arrowTypeConverter(type);
     initArrow();
     newPath();
 }
Beispiel #3
0
 public ArrowViewModel(ClassViewModel diagramA, ClassViewModel diagramB, Arrow arrow)
 {
     this.arrow = arrow;
     DiagramA   = diagramA;
     DiagramB   = diagramB;
     Type       = arrowTypeConverter(this.arrow.Type);
     initArrow();
     newPath();
 }
        public void MouseMoveDiagram(MouseEventArgs e)
        {
            if (Mouse.Captured != null)
            {
                movingClass = (FrameworkElement)e.MouseDevice.Target;

                if (movingClass is TextBox)
                {
                    return;
                }

                if (relativeMousePositionX == -1 && relativeMousePositionY == -1)
                {
                    relativeMousePositionX = (int)Mouse.GetPosition(movingClass).X;
                    relativeMousePositionY = (int)Mouse.GetPosition(movingClass).Y;
                }

                ClassViewModel movingDiagram = (ClassViewModel)movingClass.DataContext;

                canvas = FindParent <Canvas>(movingClass);
                Point mousePosition = Mouse.GetPosition(canvas);
                if (moveArrowPoint == default(Point))
                {
                    moveArrowPoint = mousePosition;
                }
                if ((int)mousePosition.X - relativeMousePositionX >= 0)
                {
                    movingDiagram.X = (int)mousePosition.X - relativeMousePositionX;
                }
                else
                {
                    movingDiagram.X = 0;
                }

                if ((int)mousePosition.Y - relativeMousePositionY >= 0)
                {
                    movingDiagram.Y = (int)mousePosition.Y - relativeMousePositionY;
                }
                else
                {
                    movingDiagram.Y = 0;
                }

                for (int i = 0; i < arrowCollection.Count; i++)
                {
                    if (movingDiagram == arrowCollection[i].DiagramA || movingDiagram == arrowCollection[i].DiagramB)
                    {
                        arrowCollection[i].newPath();
                    }
                }
            }
        }
        public void MouseUpDiagram(MouseEventArgs e)
        {
            FrameworkElement movingClass = (FrameworkElement)e.MouseDevice.Target;

            FocusedClass = (ClassViewModel)movingClass.DataContext;

            if (isAddingArrow)
            {
                if (startArrow == null)
                {
                    startArrow = FocusedClass;
                }
                else if (startArrow != FocusedClass)
                {
                    undoRedoController.AddAndExecute(new AddArrowCommand(arrowCollection, new ArrowViewModel(startArrow, FocusedClass, type)));
                    isAddingArrow = false;
                    startArrow    = null;
                    type          = EArrows.NORMAL;
                }
            }
            else
            {
                if (oldMousePositionPoint == e.GetPosition(FindParent <Canvas>((FrameworkElement)e.MouseDevice.Target)))
                {
                    e.MouseDevice.Target.ReleaseMouseCapture();
                    return;
                }

                ClassViewModel movingDiagram = (ClassViewModel)movingClass.DataContext;
                canvas = FindParent <Canvas>(movingClass);
                Point mousePosition = Mouse.GetPosition(canvas);

                int X, Y, oldX, oldY;
                if ((int)mousePosition.X - relativeMousePositionX >= 0)
                {
                    X = (int)mousePosition.X - relativeMousePositionX;
                }
                else
                {
                    X = 0;
                }
                if ((int)mousePosition.Y - relativeMousePositionY >= 0)
                {
                    Y = (int)mousePosition.Y - relativeMousePositionY;
                }
                else
                {
                    Y = 0;
                }

                if ((int)moveArrowPoint.X - relativeMousePositionX >= 0)
                {
                    oldX = (int)moveArrowPoint.X - relativeMousePositionX;
                }
                else
                {
                    oldX = 0;
                }
                if ((int)moveArrowPoint.Y - relativeMousePositionY >= 0)
                {
                    oldY = (int)moveArrowPoint.Y - relativeMousePositionY;
                }
                else
                {
                    oldY = 0;
                }

                undoRedoController.AddAndExecute(new MoveDiagramCommand(movingDiagram, X, Y, oldX, oldY, arrowCollection));
                moveArrowPoint         = new Point();
                relativeMousePositionX = -1;
                relativeMousePositionY = -1;
                e.MouseDevice.Target.ReleaseMouseCapture();
            }
        }