Пример #1
0
        private static DiagramMemberElement GetTypeElement(Shape shape)
        {
            if (shape is UmlClass)
            {
                var endClass = shape as UmlClass;
                return (endClass.DataSource as UmlClassData).Owner;
            }

            if (shape is UmlInterface)
            {
                var endClass = shape as UmlInterface;
                return (endClass.DataSource as UmlInterfaceData).Owner;
            }

            if (shape is UmlEnum)
            {
                var endClass = shape as UmlEnum;
                return (endClass.DataSource as UmlEnumData).Owner;
            }

            if (shape is UmlComment)
            {
                var endComment = shape as UmlComment;
                return (endComment.DataSource as UmlCommentData).Owner;
            }

            return null;
        }
Пример #2
0
        private void EndDrawAssociation(Shape start, Shape end)
        {
            if (start == null || end == null)
                return;


            DiagramMemberElement startElement = GetTypeElement(start);
            DiagramMemberElement endElement = GetTypeElement(end);


            var association = new DiagramRelationElement();
            association.Start = startElement;
            association.End = endElement;

            DiagramNode.AddChild(association);
        }
Пример #3
0
        private void MainCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            EndInput();
            var x = (int) ((e.X - MainCanvas.AutoScrollPosition.X)/Zoom);
            var y = (int) ((e.Y - MainCanvas.AutoScrollPosition.Y)/Zoom);

            if (EditMode == EditMode.BeginDrawRelation)
            {
                mouseDownPoint = new Point(e.X, e.Y);
                EditMode = EditMode.DrawRelation;
                relationStart = null;

                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            relationStart = bitem.Target as Shape;
                        }
                    }
                }
            }
            else if (EditMode == EditMode.Normal)
            {
                mouseDownPoint = new Point(e.X, e.Y);
                mouseDownAutoscrollPoint = new Point(-MainCanvas.AutoScrollPosition.X, -MainCanvas.AutoScrollPosition.Y);

                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            currentBoundingItem = bitem;
                            var shape = (Shape) bitem.Target;
                            currentShape = shape;
                            var args = new ShapeMouseEventArgs
                                       {
                                           BoundingItem = bitem,
                                           X = x,
                                           Y = y,
                                           Button = e.Button,
                                           Sender = this,
                                           GridSize = GridSize,
                                           SnapToGrid = SnapToGrid
                                       };
                            shape.OnMouseDown(args);
                            if (args.Redraw)
                                Refresh();
                        }

                        return;
                    }
                }
                isPanning = true;
            }
        }
Пример #4
0
        private void MainCanvas_MouseUp(object sender, MouseEventArgs e)
        {
            var x = (int) ((e.X - MainCanvas.AutoScrollPosition.X)/Zoom);
            var y = (int) ((e.Y - MainCanvas.AutoScrollPosition.Y)/Zoom);

            if (EditMode == EditMode.DrawRelation)
            {
                relationEnd = null;


                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            relationEnd = bitem.Target as Shape;
                        }
                    }
                }

                endDrawRelation(relationStart, relationEnd);

                //end drawing
                EditMode = EditMode.Normal;
                MainCanvas.Refresh();
            }
            else if (EditMode == EditMode.Normal)
            {
                Cursor = Cursors.Default;
                currentBoundingItem = null;
                isPanning = false;
                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            var shape = (Shape) bitem.Target;
                            var args = new ShapeMouseEventArgs
                                       {
                                           BoundingItem = bitem,
                                           X = x,
                                           Y = y,
                                           Button = e.Button,
                                           Sender = this,
                                           GridSize = GridSize,
                                           SnapToGrid = SnapToGrid
                                       };
                            shape.OnMouseUp(args);
                            if (args.Redraw)
                                Refresh();
                        }

                        return;
                    }
                }
            }
        }
Пример #5
0
        private void MainCanvas_MouseUp(object sender, MouseEventArgs e)
        {
            var x = (int) ((e.X - MainCanvas.AutoScrollPosition.X)/Zoom);
            var y = (int) ((e.Y - MainCanvas.AutoScrollPosition.Y)/Zoom);

            if (EditMode == EditMode.DrawRelation)
            {
                relationEnd = null;

                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            relationEnd = bbox.Target as Shape;
                        }
                    }
                }

                endDrawRelation(relationStart, relationEnd);

                //end drawing
                EditMode = EditMode.Normal;
                MainCanvas.Refresh();
            }
            else if (EditMode == EditMode.Normal)
            {
                Cursor = Cursors.Default;
                currentBoundingBox = null;
                isPanning = false;
                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            var shape = (Shape) bbox.Target;
                            var args = new ShapeMouseEventArgs();
                            args.BoundingBox = bbox;
                            args.X = x;
                            args.Y = y;
                            args.Button = e.Button;
                            args.Sender = this;
                            args.GridSize = GridSize;
                            args.SnapToGrid = SnapToGrid;
                            shape.OnMouseUp(args);
                            if (args.Redraw)
                                Refresh();
                        }

                        return;
                    }
                }
            }
        }
Пример #6
0
        private void MainCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            EndInput();
            var x = (int) ((e.X - MainCanvas.AutoScrollPosition.X)/Zoom);
            var y = (int) ((e.Y - MainCanvas.AutoScrollPosition.Y)/Zoom);

            if (EditMode == EditMode.BeginDrawRelation)
            {
                mouseDownPoint = new Point(e.X, e.Y);
                EditMode = EditMode.DrawRelation;
                relationStart = null;

                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            relationStart = bbox.Target as Shape;
                        }
                    }
                }
            }
            else if (EditMode == EditMode.Normal)
            {
                mouseDownPoint = new Point(e.X, e.Y);
                mouseDownAutoscrollPoint = new Point(-MainCanvas.AutoScrollPosition.X, -MainCanvas.AutoScrollPosition.Y);

                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            currentBoundingBox = bbox;
                            var shape = (Shape) bbox.Target;
                            currentShape = shape;
                            var args = new ShapeMouseEventArgs();
                            args.BoundingBox = bbox;
                            args.X = x;
                            args.Y = y;
                            args.Button = e.Button;
                            args.Sender = this;
                            args.GridSize = GridSize;
                            args.SnapToGrid = SnapToGrid;
                            shape.OnMouseDown(args);
                            if (args.Redraw)
                                Refresh();
                        }

                        return;
                    }
                }
                isPanning = true;
            }
        }
Пример #7
0
        private void EndDrawInheritance(Shape start, Shape end)
        {
            if (start == null || end == null)
                return;

            if (start is UmlClass)
            {
                var startClass = start as UmlClass;
                var startElement = (startClass.DataSource as UmlClassData).Owner.Type as ClassElement;

                if (end is UmlClass)
                {
                    ApplyBaseClassToClass(end, startElement);
                }

                if (end is UmlInterface)
                {
                    ApplyInterfaceToClass(end, startElement);
                }
            }
        }
Пример #8
0
        private static void ApplyInterfaceToClass(Shape end, ClassElement startElement)
        {
            var endInterface = end as UmlInterface;
            var endElement = (endInterface.DataSource as UmlInterfaceData).Owner.Type as InterfaceElement;

            bool exists = false;

            foreach (ImplementationElement existingImpl in startElement.GetChildren<ImplementationElement>())
            {
                if (existingImpl.InterfaceName == endElement.Name)
                {
                    exists = true;
                    break;
                }
            }

            if (!exists)
            {
                var implementation = new ImplementationElement();
                implementation.InterfaceName = endElement.Name;
                startElement.AddChild(implementation);
            }
        }
Пример #9
0
        private static void ApplyBaseClassToClass(Shape end, ClassElement startElement)
        {
            var endClass = end as UmlClass;
            var endElement = (endClass.DataSource as UmlClassData).Owner.Type as ClassElement;

            startElement.Inherits = endElement.Name;
        }