Example #1
0
        void dragHandle_DragCompleted(object sender,
                                      DragCompletedEventArgs e)
        {
            Point actualPos = Mouse.GetPosition(this);

            if (actualPos.X < 0 || actualPos.Y < 0)
            {
                canvas.isUpdatingLink = false;
                visualChildren.Remove(linkPreview);
                InvalidateArrange();
                return;
            }

            CustomStroke newAnchoredStroke = null;
            int          number            = 0;


            foreach (UIElement thumb in canvas.Children)
            {
                if (thumb.GetType() == typeof(StrokeAnchorPointThumb))
                {
                    Point thumbPosition = thumb.TransformToAncestor(canvas).Transform(new Point(0, 0));

                    StrokeAnchorPointThumb cheatThumb = thumb as StrokeAnchorPointThumb;
                    double y = thumbPosition.Y - actualPos.Y;
                    double x = thumbPosition.X - actualPos.X;

                    double distBetweenPoints = (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)));
                    if (distBetweenPoints <= 10)
                    {
                        newAnchoredStroke = cheatThumb.stroke;
                        actualPos         = thumbPosition;
                        number            = cheatThumb.number;
                    }
                }
            }


            if (newAnchoredStroke != null)
            {
                //anchoredShapeStroke
                if (linkStrokeAnchor == 0)           //from is changing
                {
                    if (anchoredShapeStroke != null) // there is a to
                    {
                        if (anchoredShapeStroke.isProccessStroke())
                        {
                            if (anchoredShapeStroke is ActorStroke)
                            {
                                ShowMessage("No shape can point to a role");
                            }
                            else if (anchoredShapeStroke is ActivityStroke)
                            {
                                if (newAnchoredStroke.GetType() != typeof(ActorStroke) &&
                                    newAnchoredStroke.GetType() != typeof(ArtifactStroke))
                                {
                                    ShowMessage("Only roles or artifacts can point to an activity.");
                                }
                            }
                            else if (anchoredShapeStroke is ArtifactStroke)
                            {
                                ShowMessage("A link cannot point to a role");
                            }
                        }
                        else if (anchoredShapeStroke is ClassStroke && linkStroke.isLinkAggCompHeritage())
                        {
                            if (!(newAnchoredStroke is ClassStroke))
                            {
                                ShowMessage("Aggregation, composition and heritage links must be between two classes.");
                            }
                        }
                        else if (newAnchoredStroke.isProccessStroke())
                        {
                            ShowMessage("Roles, artifacts and activities must be linked between themselves.");
                        }
                    }
                    else // there is no to
                    {
                        noNewStrokeLinkedToProcessOrClassCheck(newAnchoredStroke);
                    }
                }
                else // to is changing
                {
                    CustomStroke fromStroke = anchoredShapeStroke;
                    if (fromStroke != null) // there is a from
                    {
                        if (fromStroke is ActorStroke)
                        {
                            if (!(newAnchoredStroke is ActivityStroke))
                            {
                                ShowMessage("A role can only be linked to an activity.");
                            }
                        }
                        else if (fromStroke is ArtifactStroke)
                        {
                            if (!(newAnchoredStroke is ActivityStroke))
                            {
                                ShowMessage("An artifact can only be linked to an activity.");
                            }
                        }
                        else if (fromStroke is ActivityStroke)
                        {
                            if (!(newAnchoredStroke is ArtifactStroke))
                            {
                                ShowMessage("An activity can only be linked to an artifact.");
                            }
                        }
                        else if (newAnchoredStroke != null && newAnchoredStroke.isProccessStroke())
                        {
                            ShowMessage("Roles, artifacts and activities must be linked between themselves.");
                        }
                        else if (fromStroke is ClassStroke && linkStroke.isLinkAggCompHeritage())
                        {
                            if (!(newAnchoredStroke is ClassStroke))
                            {
                                ShowMessage("Aggregation, composition and heritage links must be between two classes.");
                            }
                        }
                    }
                    else // there is no from
                    {
                        noNewStrokeLinkedToProcessOrClassCheck(newAnchoredStroke);
                    }
                }
            }
            else // no newAnchoredStroke
            {
                if (anchoredShapeStroke != null && anchoredShapeStroke.isProccessStroke())
                {
                    ShowMessage("Roles, artifacts and activities cannot be linked to nothing.");
                }

                if (anchoredShapeStroke != null && anchoredShapeStroke is ClassStroke && linkStroke.isLinkAggCompHeritage())
                {
                    ShowMessage("Aggregation, composition and heritage links must be between two classes.");
                }

                //if (linkStrokeAnchor == 0) //from is changing to nothing. No from
                //{
                //}
                //else //to is changing to nothing. Not to.
                //{

                //}
            }
            // voir fonction du anchorPointAdorner

            if (!hasFailed)
            {
                canvas.updateLink(linkStrokeAnchor, linkStroke, newAnchoredStroke as ShapeStroke, number, actualPos);
            }
            else
            {
                StrokeCollection selectedStrokes = new StrokeCollection {
                    canvas.GetSelectedStrokes()
                };
                canvas.Select(new StrokeCollection {
                });
                canvas.Select(selectedStrokes);
            }


            //TODO eliminate preview
            visualChildren.Remove(linkPreview);

            InvalidateArrange();
        }