예제 #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);
        }
예제 #2
0
        public void MakeVisible(AnnotationSceneNode annotation, IEnumerable <SceneElement> targets)
        {
            Artboard artboard = this.designerContext.ActiveView.Artboard;

            artboard.AnnotationLayer.UpdateLayout();
            targets = Enumerable.Where <SceneElement>(targets, (Func <SceneElement, bool>)(element =>
            {
                if (element != null)
                {
                    return(element != element.ViewModel.RootNode);
                }
                return(false);
            }));
            Rect rect1 = Rect.Empty;

            foreach (SceneElement sceneElement in targets)
            {
                rect1 = Rect.Union(rect1, artboard.GetElementBounds(sceneElement));
            }
            Size             size   = new Size(250.0, 200.0);
            AnnotationVisual visual = annotation.Visual;

            if (visual != null)
            {
                size = visual.RenderSize;
            }
            Rect   rect2      = new Rect(annotation.Position, size);
            Size   renderSize = artboard.RenderSize;
            double zoom       = artboard.Zoom;
            Rect   rect2_1    = rect2;

            rect2_1.Width  /= zoom;
            rect2_1.Height /= zoom;
            Rect rect3 = Rect.Union(rect1, rect2_1);

            if (rect3.IsEmpty || artboard.ArtboardBounds.Contains(rect3))
            {
                return;
            }
            if (rect3.Width < artboard.ArtboardBounds.Width && rect3.Height < artboard.ArtboardBounds.Height)
            {
                Rect artboardBounds = artboard.ArtboardBounds;
                if (rect3.X < artboard.ArtboardBounds.X)
                {
                    artboardBounds.X = rect3.X;
                }
                else if (artboard.ArtboardBounds.Right < rect3.Right)
                {
                    artboardBounds.X -= artboard.ArtboardBounds.Right - rect3.Right;
                }
                if (rect3.Y < artboard.ArtboardBounds.Y)
                {
                    artboardBounds.Y = rect3.Y;
                }
                else if (artboard.ArtboardBounds.Bottom < rect3.Bottom)
                {
                    artboardBounds.Y -= artboard.ArtboardBounds.Bottom - rect3.Bottom;
                }
                artboard.ZoomToFitRectangle(artboardBounds);
            }
            else
            {
                double num     = Math.Max(0.01, Math.Min((renderSize.Width - rect2.Width) / rect1.Width, (renderSize.Height - rect2.Height) / rect1.Height));
                Rect   rect2_2 = rect2;
                rect2_2.Width  /= num;
                rect2_2.Height /= num;
                Rect rectangle = Rect.Union(rect1, rect2_2);
                artboard.ZoomToFitRectangle(rectangle);
            }
        }