Exemplo n.º 1
0
        internal AnnotationSceneNode CreateAnnotation(IEnumerable <SceneElement> targets)
        {
            Artboard            artboard             = this.sceneViewModel.DefaultView.Artboard;
            SceneElement        sceneElement         = Enumerable.First <SceneElement>(targets);
            int                 num                  = Enumerable.Count <SceneElement>(targets);
            bool                treatTopLeftAsCenter = num > 1 || sceneElement.Equals((object)sceneElement.ViewModel.RootNode);
            AnnotationSceneNode annotation;

            using (SceneEditTransaction editTransaction = sceneElement.ViewModel.CreateEditTransaction(StringTable.AddAnnotationUndoUnit))
            {
                annotation = AnnotationManagerSceneNode.CreateAnnotation((SceneNode)sceneElement);
                foreach (SceneElement element in Enumerable.Skip <SceneElement>(targets, 1))
                {
                    AnnotationUtils.AddAnnotationReference(element, annotation);
                }
                Point point1;
                if (treatTopLeftAsCenter)
                {
                    Rect rect = Rect.Empty;
                    if (num > 1 || !sceneElement.Equals((object)annotation.ViewModel.RootNode))
                    {
                        rect = artboard.GetElementListBounds(targets);
                    }
                    if (rect.IsEmpty)
                    {
                        rect = artboard.ArtboardBounds;
                    }
                    point1 = new Point(rect.Left + rect.Width / 2.0, rect.Top + rect.Height / 2.0);
                }
                else
                {
                    point1 = artboard.GetElementBounds(sceneElement).TopRight;
                }
                Point point2 = RoundingHelper.RoundPosition(point1);
                annotation.Left = point2.X;
                annotation.Top  = point2.Y;
                string authorName = this.AnnotationService.DesignerContext.AnnotationsOptionsModel.AuthorName;
                if (!string.IsNullOrEmpty(authorName))
                {
                    annotation.Author = authorName;
                }
                string authorInitials = this.AnnotationService.DesignerContext.AnnotationsOptionsModel.AuthorInitials;
                if (!string.IsNullOrEmpty(authorInitials))
                {
                    annotation.AuthorInitials = authorInitials;
                }
                AnnotationUtils.SetSerialNumber(annotation);
                editTransaction.Commit();
            }
            this.CreateAnnotationVisual(annotation).Initialize(treatTopLeftAsCenter);
            return(annotation);
        }