Exemplo n.º 1
0
        protected override void EndEditingInternal(bool pathJustCreated)
        {
            PathGeometry pathGeometry1 = PathGeometryUtilities.Copy(this.PathGeometry, false);
            bool         isAnimated    = this.IsAnimated;

            if (!isAnimated && this.ViewModel.AnimationEditor.IsKeyFraming)
            {
                System.Windows.Media.Geometry geometry1 = (System.Windows.Media.Geometry) this.editingElement.GetComputedValueAsWpf(Base2DElement.ClipProperty);
                PathGeometry geometry2 = new PathGeometry();
                if (geometry1 != null)
                {
                    geometry2.AddGeometry(geometry1);
                }
                PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(geometry2);
                SceneNode sceneNode = this.editingElement.ViewModel.CreateSceneNode(this.editingElement.ViewModel.DefaultView.ConvertFromWpfValue((object)geometry2));
                sceneNode.SetLocalValueAsWpf(DesignTimeProperties.IsAnimatedProperty, (object)true);
                this.editingElement.SetValueAsSceneNode(Base2DElement.ClipProperty, sceneNode);
                this.editingElement.ViewModel.Document.OnUpdatedEditTransaction();
            }
            if (this.EditingElement.IsAttached && (this.ViewModel.AnimationEditor.IsKeyFraming || isAnimated))
            {
                new PathDiff(this.EditingElement, Base2DElement.ClipProperty, this.PathDiffChangeList).SetPathUsingMinimalDiff(pathGeometry1);
            }
            else
            {
                PathGeometry pathGeometry2 = PathGeometryUtilities.RemoveMapping(pathGeometry1, true);
                this.EditingElement.SetValueAsWpf(Base2DElement.ClipProperty, (object)pathGeometry2);
            }
        }
Exemplo n.º 2
0
 public static void AdjustPathForAnimations(PathElement pathElement, SceneEditTransaction editTransaction)
 {
     using (pathElement.ViewModel.ForceBaseValue())
     {
         System.Windows.Media.Geometry geometry1 = (System.Windows.Media.Geometry)pathElement.GetLocalOrDefaultValueAsWpf(PathElement.DataProperty);
         PathGeometry pathGeometry = new PathGeometry();
         pathGeometry.AddGeometry(geometry1);
         Rect bounds = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry.Bounds, pathElement, false);
         PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
         Rect            maxAnimatedExtent   = PathCommandHelper.FindMaxAnimatedExtent((SceneElement)pathElement, bounds, propertyReference);
         double          num1             = Math.Min(0.0, maxAnimatedExtent.Left);
         double          num2             = Math.Min(0.0, maxAnimatedExtent.Top);
         Vector          vector           = new Vector(-num1, -num2);
         ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true);
         editTransaction.Update();
         Rect childRect = designerForChild.GetChildRect((BaseFrameworkElement)pathElement);
         childRect.X     += num1;
         childRect.Y     += num2;
         childRect.Width  = Math.Max(maxAnimatedExtent.Width, childRect.Width);
         childRect.Height = Math.Max(maxAnimatedExtent.Height, childRect.Height);
         designerForChild.SetChildRect((BaseFrameworkElement)pathElement, childRect);
         Transform    transform = (Transform) new TranslateTransform(vector.X, vector.Y);
         PathGeometry geometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry, transform);
         if (!pathElement.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
         {
             PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(geometry2);
         }
         pathElement.PathGeometry = geometry2;
         PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform);
         pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)(Stretch)(pathElement.HasVertexAnimations ? 0 : 1));
     }
 }
Exemplo n.º 3
0
        public bool EnsureSingleSegmentsInPathGeometry()
        {
            PathGeometry pathGeometry = this.PathGeometry;
            bool         flag         = PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(pathGeometry);

            this.PathGeometry = pathGeometry;
            return(flag);
        }
Exemplo n.º 4
0
 protected void EnsureOnlySingleSegments()
 {
     if (!PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(this.PathGeometry))
     {
         return;
     }
     this.AddCriticalEdit();
 }
Exemplo n.º 5
0
 public override void PostDeleteAction()
 {
     if (!PathGeometryUtilities.IsEmpty(this.PathGeometry))
     {
         return;
     }
     this.ViewModel.AnimationEditor.DeleteMotionPath((SceneNode)this.EditingElement);
 }
Exemplo n.º 6
0
        private System.Windows.Media.Geometry GetTransformedClippingGeometry(SceneElement clipper, Transform transform)
        {
            RectangleElement rectangleElement = clipper as RectangleElement;

            if (rectangleElement == null || !this.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.PrefersRectangularClippingPath))
            {
                PathGeometry pathGeometry = PathGeometryUtilities.TransformGeometry(this.ApplyCurrentClippingToGeometry((System.Windows.Media.Geometry)PathConversionHelper.ConvertToPathGeometry(clipper), clipper), transform);
                if (pathGeometry.Bounds == Rect.Empty)
                {
                    pathGeometry = new PathGeometry();
                }
                return((System.Windows.Media.Geometry)pathGeometry);
            }
            RectangleGeometry rectangleGeometry = rectangleElement.ViewModel.DefaultView.GetRenderedGeometryAsWpf((SceneElement)rectangleElement) as RectangleGeometry;

            if (rectangleGeometry == null)
            {
                return((System.Windows.Media.Geometry) new RectangleGeometry());
            }
            CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition(transform.Value);
            Matrix matrix = new Matrix();

            matrix.Scale(canonicalDecomposition.ScaleX, canonicalDecomposition.ScaleY);
            matrix.Translate(canonicalDecomposition.TranslationX, canonicalDecomposition.TranslationY);
            Rect rect = rectangleGeometry.Rect;

            rect.Transform(matrix);
            rectangleGeometry.Rect = RoundingHelper.RoundRect(rect);
            CanonicalTransform canonicalTransform = new CanonicalTransform();
            bool flag = false;

            canonicalTransform.CenterX = canonicalDecomposition.TranslationX;
            canonicalTransform.CenterY = canonicalDecomposition.TranslationY;
            if (canonicalDecomposition.RotationAngle != 0.0)
            {
                canonicalTransform.RotationAngle = canonicalDecomposition.RotationAngle;
                flag = true;
            }
            if (canonicalDecomposition.SkewX != 0.0 || canonicalDecomposition.SkewY != 0.0)
            {
                canonicalTransform.SkewX = RoundingHelper.RoundLength(canonicalDecomposition.SkewX);
                canonicalTransform.SkewY = RoundingHelper.RoundLength(canonicalDecomposition.SkewY);
                flag = true;
            }
            if (flag)
            {
                rectangleGeometry.Transform = (Transform)canonicalTransform.TransformGroup;
            }
            if ((double)rectangleElement.GetComputedValue(RectangleElement.RadiusXProperty) != 0.0 || (double)rectangleElement.GetComputedValue(RectangleElement.RadiusYProperty) != 0.0)
            {
                rectangleGeometry.ClearValue(RectangleGeometry.RadiusXProperty);
                rectangleGeometry.ClearValue(RectangleGeometry.RadiusYProperty);
                this.SceneView.ShowBubble(StringTable.ClippingRectanglePropertiesLostWarning, MessageBubbleType.Warning);
            }
            return((System.Windows.Media.Geometry)rectangleGeometry);
        }
Exemplo n.º 7
0
        private void NormalizePathGeometry()
        {
            PathGeometry pathGeometry   = this.PathGeometry;
            Rect         extent         = PathCommandHelper.InflateRectByStrokeWidth(PathGeometryUtilities.TightExtent(pathGeometry, Matrix.Identity), this, false);
            Rect         computedBounds = this.GetComputedBounds((Base2DElement)this);
            Transform    transform      = ScenePathEditorTarget.NormalizePathGeometry(pathGeometry, extent, computedBounds);

            this.PathGeometry = pathGeometry;
            PathCommandHelper.TransformPointKeyframes((SceneElement)this, new PropertyReference((ReferenceStep)this.ProjectContext.ResolveProperty(PathElement.DataProperty)), transform);
        }
Exemplo n.º 8
0
        public void SimplifyPathData(ref System.Windows.Media.Geometry geometry)
        {
            PathGeometry geometry1 = geometry as PathGeometry;

            BooleanCommand.CleanUpPathGeometry(ref geometry1);
            PathGeometry geometry2 = PathConversionHelper.RemoveDegeneratePoints((System.Windows.Media.Geometry)geometry1);

            PathGeometryUtilities.CollapseSingleSegmentsToPolySegments(geometry2);
            PathCommandHelper.GrokPathPointPrecision(geometry2, 3);
            geometry = (System.Windows.Media.Geometry)geometry2;
        }
Exemplo n.º 9
0
 public override void PostDeleteAction()
 {
     if (PathGeometryUtilities.IsEmpty(this.PathGeometry))
     {
         this.RemovePath();
     }
     else
     {
         this.EndEditing(false);
     }
 }
Exemplo n.º 10
0
        public override Rect GetComputedTightBounds(Base2DElement context)
        {
            PathGeometry renderedGeometry = this.RenderedGeometry;

            if (renderedGeometry == null)
            {
                return(Rect.Empty);
            }
            Matrix transformToElement = this.GetComputedTransformToElement((SceneElement)context);

            return(PathGeometryUtilities.TightExtent(renderedGeometry, transformToElement));
        }
Exemplo n.º 11
0
 public override void Execute()
 {
     using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
     {
         SceneElement clipper;
         SceneElement elementToBeClipped;
         this.GetClipperAndElementToBeClipped(this.SceneViewModel.ElementSelectionSet, out clipper, out elementToBeClipped);
         if (elementToBeClipped == null)
         {
             SceneElement root = this.SceneViewModel.ActiveEditingContainer as SceneElement;
             if (root != null)
             {
                 elementToBeClipped = (SceneElement)PathTargetDialog.ChooseClippingPathTarget(root, clipper);
             }
         }
         if (elementToBeClipped == null)
         {
             return;
         }
         using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeClippingPath, false))
         {
             using (this.SceneViewModel.ForceBaseValue())
             {
                 this.SceneViewModel.ElementSelectionSet.Clear();
                 Transform geometryTransform = this.GetGeometryTransform(clipper, elementToBeClipped);
                 System.Windows.Media.Geometry targetGeometry = this.GetTransformedClippingGeometry(clipper, geometryTransform);
                 if (!this.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.PrefersRectangularClippingPath))
                 {
                     targetGeometry = this.ApplyCurrentClippingToGeometry(targetGeometry, elementToBeClipped);
                 }
                 if (!this.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                 {
                     PathGeometry original = targetGeometry as PathGeometry;
                     if (original != null)
                     {
                         PathGeometry geometry = PathGeometryUtilities.RemoveMapping(original, true);
                         PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(geometry);
                         targetGeometry = (System.Windows.Media.Geometry)geometry;
                     }
                 }
                 elementToBeClipped.SetValueAsWpf(Base2DElement.ClipProperty, (object)targetGeometry);
                 ReferenceStep singleStep1 = (ReferenceStep)this.SceneViewModel.ProjectContext.ResolveProperty(PathElement.DataProperty);
                 ReferenceStep singleStep2 = (ReferenceStep)this.SceneViewModel.ProjectContext.ResolveProperty(Base2DElement.ClipProperty);
                 PathCommandHelper.MoveVertexAnimations(clipper, new PropertyReference(singleStep1), elementToBeClipped, new PropertyReference(singleStep2), geometryTransform);
                 this.SceneViewModel.DeleteElementTree(clipper);
                 this.SceneViewModel.ElementSelectionSet.SetSelection(elementToBeClipped);
             }
             editTransaction.Commit();
         }
     }
 }
Exemplo n.º 12
0
        private void ReleaseClippingPath(SceneElement sceneElement, SceneEditTransaction editTransaction)
        {
            if (sceneElement.IsSet(Base2DElement.ClipProperty) != PropertyState.Set)
            {
                return;
            }
            SceneNode sceneNode = (SceneNode)sceneElement;

            for (SceneNode parent = sceneElement.Parent; parent != null; parent = parent.Parent)
            {
                PanelElement panelElement = parent as PanelElement;
                if (panelElement != null)
                {
                    MatrixTransform matrixTransform        = new MatrixTransform(sceneElement.GetComputedTransformToElement((SceneElement)panelElement));
                    PathGeometry    pathGeometry1          = new PathGeometry();
                    System.Windows.Media.Geometry geometry = (System.Windows.Media.Geometry)sceneElement.GetLocalOrDefaultValueAsWpf(Base2DElement.ClipProperty);
                    if (geometry != null)
                    {
                        pathGeometry1 = PathGeometryUtilities.TransformGeometry(geometry, (Transform)matrixTransform);
                    }
                    PathElement pathElement = (PathElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Path);
                    using (pathElement.ViewModel.ForceBaseValue())
                    {
                        this.DesignerContext.AmbientPropertyManager.ApplyAmbientProperties((SceneNode)pathElement);
                        pathElement.SetValueAsWpf(ShapeElement.StrokeProperty, (object)Brushes.Black);
                        pathElement.ClearValue(ShapeElement.FillProperty);
                        pathElement.ClearValue(ShapeElement.StrokeThicknessProperty);
                        panelElement.Children.Insert(panelElement.Children.IndexOf(sceneNode) + 1, (SceneNode)pathElement);
                        ReferenceStep singleStep1 = (ReferenceStep)pathElement.ProjectContext.ResolveProperty(Base2DElement.ClipProperty);
                        ReferenceStep singleStep2 = (ReferenceStep)pathElement.ProjectContext.ResolveProperty(PathElement.DataProperty);
                        PathCommandHelper.MoveVertexAnimations(sceneElement, new PropertyReference(singleStep1), (SceneElement)pathElement, new PropertyReference(singleStep2), (Transform)matrixTransform);
                        Rect bounds            = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry1.Bounds, pathElement, false);
                        Rect maxAnimatedExtent = PathCommandHelper.FindMaxAnimatedExtent((SceneElement)pathElement, bounds, new PropertyReference(singleStep2));
                        editTransaction.Update();
                        Vector vector = new Vector(-maxAnimatedExtent.Left, -maxAnimatedExtent.Top);
                        panelElement.LayoutDesigner.SetChildRect((BaseFrameworkElement)pathElement, maxAnimatedExtent);
                        Transform    transform     = (Transform) new TranslateTransform(vector.X, vector.Y);
                        PathGeometry pathGeometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry1, transform);
                        pathElement.PathGeometry = pathGeometry2;
                        PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, new PropertyReference(singleStep2), transform);
                        pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)(Stretch)(pathElement.HasVertexAnimations ? 0 : 1));
                        break;
                    }
                }
                else
                {
                    sceneNode = parent;
                }
            }
        }
        public override void Execute()
        {
            AnimationEditor      animationEditor  = this.SceneViewModel.AnimationEditor;
            SceneElement         pathTarget       = this.GetPathTarget(this.SceneViewModel.ElementSelectionSet);
            BaseFrameworkElement frameworkElement = (BaseFrameworkElement)this.GetAnimationTarget(this.SceneViewModel.ElementSelectionSet);

            if (frameworkElement == null)
            {
                SceneElement root = this.SceneViewModel.ActiveEditingContainer as SceneElement;
                if (root != null)
                {
                    frameworkElement = PathTargetDialog.ChooseMotionPathTarget(root, pathTarget);
                }
            }
            if (frameworkElement == null)
            {
                return;
            }
            PathGeometry geometry = PathConversionHelper.ConvertToPathGeometry(pathTarget);

            if (PathGeometryUtilities.TotalSegmentCount(geometry) == 0)
            {
                this.DesignerContext.MessageDisplayService.ShowError(StringTable.ConvertToMotionPathNoSegmentsMessage);
            }
            else
            {
                using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.ConvertToMotionPathUndo, false))
                {
                    StoryboardTimelineSceneNode targetTimeline = this.GetTargetTimeline();
                    if (targetTimeline == null)
                    {
                        this.SceneViewModel.AnimationEditor.CreateNewTimeline(TriggerCreateBehavior.Default);
                    }
                    else if (targetTimeline != this.SceneViewModel.ActiveStoryboardTimeline)
                    {
                        this.SceneViewModel.SetActiveStoryboardTimeline(targetTimeline.StoryboardContainer, targetTimeline, (TriggerBaseNode)null);
                    }
                    this.SceneViewModel.ElementSelectionSet.Clear();
                    Point        elementCoordinates = frameworkElement.RenderTransformOriginInElementCoordinates;
                    Matrix       matrix             = new TranslateTransform(-elementCoordinates.X, -elementCoordinates.Y).Value;
                    Transform    transform          = (Transform) new MatrixTransform(pathTarget.GetComputedTransformToElement((SceneElement)frameworkElement) * frameworkElement.GetEffectiveRenderTransform(false) * matrix);
                    PathGeometry path          = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)geometry, transform);
                    double       animationTime = animationEditor.AnimationTime;
                    animationEditor.SetMotionPath((SceneElement)frameworkElement, path, new double?(animationTime), new double?(animationTime + 2.0));
                    this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)frameworkElement);
                    editTransaction.Commit();
                }
            }
        }
Exemplo n.º 14
0
            public void Update(double scaleX, double scaleY)
            {
                double num = 2.0 * this.halfStrokeThickness;

                if (this.initialSize.Width > num)
                {
                    scaleX = (this.initialSize.Width * scaleX - num) / (this.initialSize.Width - num);
                }
                if (this.initialSize.Height > num)
                {
                    scaleY = (this.initialSize.Height * scaleY - num) / (this.initialSize.Height - num);
                }
                this.transform = (Transform) new ScaleTransform(scaleX, scaleY, this.halfStrokeThickness, this.halfStrokeThickness);
                this.pathElement.PathGeometry = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry) this.initialGeometry, this.transform);
            }
Exemplo n.º 15
0
 public void EndEditing(bool pathJustCreated)
 {
     if (!this.isCurrentlyEditing)
     {
         return;
     }
     if (this.ShouldCollapseSegments() && PathGeometryUtilities.CollapseSingleSegmentsToPolySegments(this.PathGeometry))
     {
         this.AddCriticalEdit();
     }
     this.isCurrentlyEditing  = false;
     this.ignoreFirstInserted = true;
     this.EditingElement.ViewModel.Document.AddUndoUnit((IUndoUnit) new PathEditorTarget.PathEditorTargetUndoUnit((BaseFrameworkElement)this.EditingElement, this.PathEditMode, true));
     this.EndEditingInternal(pathJustCreated);
     this.EditingElement.ViewModel.Document.AddUndoUnit((IUndoUnit) new PathEditorTarget.PathEditorTargetUndoUnit((BaseFrameworkElement)this.EditingElement, this.PathEditMode, false));
 }
Exemplo n.º 16
0
        public void SetPathUsingMinimalDiff(PathGeometry path)
        {
            PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(path);
            PathGeometry pathGeometry = this.targetElement.GetComputedValueAsWpf((IPropertyId)this.pathProperty) as PathGeometry;

            if (pathGeometry != null && path != null)
            {
                PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(pathGeometry);
                if (this.changeList.Changes.Count == 0 && this.DoesStructureMatch(path, pathGeometry))
                {
                    this.SetPathGeometryUsingMinimalDiff(path, pathGeometry);
                }
                else
                {
                    this.SetPathUsingMapping(path);
                }
            }
            else
            {
                this.targetElement.SetValueAsWpf((IPropertyId)this.pathProperty, (object)path);
            }
        }
Exemplo n.º 17
0
        public static PathGeometry ConvertToPathGeometry(SceneElement element)
        {
            PathGeometry[] pathGeometryArray = PathConversionHelper.ConvertToPathGeometries(element);
            if (pathGeometryArray.Length == 0)
            {
                return(new PathGeometry());
            }
            if (pathGeometryArray.Length > 1)
            {
                for (int index = 1; index < pathGeometryArray.Length; ++index)
                {
                    pathGeometryArray[0].AddGeometry((System.Windows.Media.Geometry)pathGeometryArray[index]);
                }
            }
            PathGeometry pathGeometry = pathGeometryArray[0];

            if (pathGeometry != null && Enumerable.Any <PathFigure>((IEnumerable <PathFigure>)pathGeometry.Figures, (Func <PathFigure, bool>)(figure => Enumerable.Any <PathSegment>((IEnumerable <PathSegment>)figure.Segments, (Func <PathSegment, bool>)(segment => segment is ArcSegment)))))
            {
                pathGeometry = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry, (Transform) new TranslateTransform(1.0, 0.0)), (Transform) new TranslateTransform(-1.0, 0.0));
            }
            return(pathGeometry);
        }
Exemplo n.º 18
0
        public override void UpdateCachedPath()
        {
            PathGeometry original = (PathGeometry)null;

            if (this.pathElement.IsAttached)
            {
                original = this.ViewModel.AnimationEditor.ActiveStoryboardTimeline == null ? this.pathElement.PathGeometry : PathGeometryUtilities.GetPathGeometryFromGeometry(this.pathElement.GetComputedValueAsWpf(PathElement.DataProperty) as System.Windows.Media.Geometry);
            }
            if (original != null)
            {
                this.PathGeometry = PathGeometryUtilities.Copy(original, false);
                if (!this.IsCurrentlyEditing)
                {
                    return;
                }
                this.EnsureOnlySingleSegments();
            }
            else
            {
                this.PathGeometry = new PathGeometry();
            }
        }
Exemplo n.º 19
0
 public static void CleanUpPathGeometry(ref PathGeometry geometry)
 {
     if (geometry == null)
     {
         return;
     }
     if (geometry.Figures.Count == 0)
     {
         geometry = (PathGeometry)null;
     }
     else
     {
         geometry = PathGeometryUtilities.Copy(geometry, false);
         foreach (PathFigure pathFigure in geometry.Figures)
         {
             foreach (PathSegment pathSegment in pathFigure.Segments)
             {
                 pathSegment.ClearValue(PathSegment.IsStrokedProperty);
                 pathSegment.ClearValue(PathSegment.IsSmoothJoinProperty);
             }
         }
     }
 }
Exemplo n.º 20
0
        public override void UpdateCachedPath()
        {
            PathAnimationSceneNode pathAnimation = this.GetPathAnimation();

            this.PathGeometry = pathAnimation == null || pathAnimation.Path == null ? new PathGeometry() : PathGeometryUtilities.Copy(pathAnimation.Path, true);
        }
Exemplo n.º 21
0
        private void SetPathUsingMapping(PathGeometry path)
        {
            SceneViewModel viewModel = this.targetElement.ViewModel;

            using (viewModel.AnimationProxyManager != null ? viewModel.AnimationProxyManager.ExpandAllProxiesInActiveContainer() : (IDisposable)null)
            {
                foreach (PathAction action in this.changeList.Changes)
                {
                    System.Windows.Media.Geometry geometry = this.targetElement.GetLocalOrDefaultValueAsWpf((IPropertyId)this.pathProperty) as System.Windows.Media.Geometry;
                    if (geometry == null && this.targetElement.IsValueExpression((IPropertyId)this.pathProperty))
                    {
                        geometry = this.targetElement.ViewModel.DefaultView.ConvertToWpfValue(this.targetElement.ViewModel.CreateInstance(this.targetElement.GetLocalValueAsSceneNode((IPropertyId)this.pathProperty).DocumentNodePath)) as System.Windows.Media.Geometry;
                        if (geometry == null)
                        {
                            geometry = this.targetElement.GetComputedValueAsWpf((IPropertyId)this.pathProperty) as System.Windows.Media.Geometry;
                            if (geometry == null)
                            {
                                return;
                            }
                        }
                    }
                    PathGeometry oldGeometry = new PathGeometry();
                    oldGeometry.AddGeometry(geometry.Clone());
                    PathGeometry pathGeometry = new PathGeometry();
                    pathGeometry.AddGeometry(geometry);
                    PathFigureEditor   pathFigureEditor   = new PathFigureEditor(pathGeometry.Figures[action.Figure]);
                    PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(pathGeometry);
                    switch (action.Action)
                    {
                    case PathActionType.InsertPoint:
                        pathFigureEditor.SubdivideSegment(action.PointIndex, action.Parameter);
                        break;

                    case PathActionType.DeletePoint:
                        pathFigureEditor.RemovePoint(action.PointIndex);
                        break;

                    case PathActionType.DeleteSegment:
                        if (action.Segment == 0 && pathFigureEditor.PathFigure.Segments.Count > 1)
                        {
                            pathFigureEditor.RemoveFirstSegment();
                            break;
                        }
                        pathFigureEditor.RemoveLastSegment();
                        break;

                    case PathActionType.PromoteSegment:
                        pathFigureEditor.PromoteSegment(action.PointIndex);
                        break;

                    case PathActionType.Rotate:
                        pathFigureEditor.Rotate();
                        break;

                    case PathActionType.Open:
                        pathFigureEditor.Open(action.PointIndex);
                        break;

                    case PathActionType.Split:
                        pathFigureEditor.Split(action.PointIndex);
                        break;

                    case PathActionType.SplitAndAdd:
                        pathGeometryEditor.SplitFigure(action.Figure, action.PointIndex);
                        break;

                    case PathActionType.RemoveFigure:
                        pathGeometryEditor.RemoveFigure(action.Figure);
                        break;

                    case PathActionType.AppendSegment:
                        PathAppendLineAction appendLineAction;
                        if ((appendLineAction = action as PathAppendLineAction) != null)
                        {
                            Point point = appendLineAction.Point;
                            if (action.Figure < path.Figures.Count && action.Segment < path.Figures[action.Figure].Segments.Count)
                            {
                                LineSegment lineSegment = path.Figures[action.Figure].Segments[action.Segment] as LineSegment;
                                if (lineSegment != null)
                                {
                                    point = lineSegment.Point;
                                }
                            }
                            pathFigureEditor.LineTo(point);
                            break;
                        }
                        PathAppendQuadraticBezierAction quadraticBezierAction;
                        if ((quadraticBezierAction = action as PathAppendQuadraticBezierAction) != null)
                        {
                            Point point1 = quadraticBezierAction.Point1;
                            Point point2 = quadraticBezierAction.Point2;
                            if (action.Figure < path.Figures.Count && action.Segment < path.Figures[action.Figure].Segments.Count)
                            {
                                QuadraticBezierSegment quadraticBezierSegment = path.Figures[action.Figure].Segments[action.Segment] as QuadraticBezierSegment;
                                if (quadraticBezierSegment != null)
                                {
                                    point1 = quadraticBezierSegment.Point1;
                                    point2 = quadraticBezierSegment.Point2;
                                }
                            }
                            pathFigureEditor.QuadraticCurveTo(point1, point2);
                            break;
                        }
                        PathAppendBezierAction appendBezierAction;
                        if ((appendBezierAction = action as PathAppendBezierAction) != null)
                        {
                            Point point1 = appendBezierAction.Point1;
                            Point point2 = appendBezierAction.Point2;
                            Point point3 = appendBezierAction.Point3;
                            if (action.Figure < path.Figures.Count && action.Segment < path.Figures[action.Figure].Segments.Count)
                            {
                                BezierSegment bezierSegment = path.Figures[action.Figure].Segments[action.Segment] as BezierSegment;
                                if (bezierSegment != null)
                                {
                                    point1 = bezierSegment.Point1;
                                    point2 = bezierSegment.Point2;
                                    point3 = bezierSegment.Point3;
                                }
                            }
                            pathFigureEditor.CubicCurveTo(point1, point2, point3);
                            break;
                        }
                        break;

                    case PathActionType.Close:
                        pathFigureEditor.CloseWithLineSegment();
                        break;

                    case PathActionType.Join:
                        pathGeometryEditor.JoinFigure(action.Figure, action.PointIndex);
                        break;

                    case PathActionType.Reverse:
                        pathFigureEditor.Reverse();
                        break;
                    }
                    this.targetElement.SetLocalValueAsWpf((IPropertyId)this.pathProperty, (object)pathGeometry);
                    this.ApplyAnimationChanges(oldGeometry, pathGeometry, action);
                    if (action.Action == PathActionType.PromoteSegment && action.Segment < pathGeometry.Figures[action.Figure].Segments.Count)
                    {
                        this.targetElement.ViewModel.Document.OnUpdatedEditTransaction();
                        this.SetKeyframesForSegment(path, action.Figure, action.Segment);
                    }
                }
                this.RemoveInvalidAnimations(PathGeometryUtilities.GetPathGeometryFromGeometry((System.Windows.Media.Geometry) this.targetElement.GetLocalOrDefaultValueAsWpf((IPropertyId)this.pathProperty)));
            }
        }
Exemplo n.º 22
0
        private HashSet <SceneElement> PathPartDelete(SceneEditTransaction editTransaction)
        {
            HashSet <SceneElement> hashSet          = new HashSet <SceneElement>();
            PathPartSelectionSet   partSelectionSet = this.SceneViewModel.PathPartSelectionSet;
            Dictionary <PathEditMode, List <PathEditorTarget> > dictionary = new Dictionary <PathEditMode, List <PathEditorTarget> >();

            dictionary[PathEditMode.ClippingPath] = new List <PathEditorTarget>();
            dictionary[PathEditMode.ScenePath]    = new List <PathEditorTarget>();
            dictionary[PathEditMode.MotionPath]   = new List <PathEditorTarget>();
            Tool activeTool = this.SceneViewModel.DesignerContext.ToolManager.ActiveTool;

            if (activeTool != null)
            {
                foreach (PathPart pathPart in partSelectionSet.Selection)
                {
                    BaseFrameworkElement frameworkElement = pathPart.SceneElement as BaseFrameworkElement;
                    if (frameworkElement != null)
                    {
                        PathEditorTarget pathEditorTarget = activeTool.GetPathEditorTarget((Base2DElement)frameworkElement, pathPart.PathEditMode);
                        if (pathEditorTarget != null && !dictionary[pathPart.PathEditMode].Contains(pathEditorTarget))
                        {
                            dictionary[pathPart.PathEditMode].Add(pathEditorTarget);
                            hashSet.Add((SceneElement)frameworkElement);
                        }
                    }
                }
            }
            List <PathEditorTarget> list1 = new List <PathEditorTarget>();
            List <PathEditorTarget> list2 = new List <PathEditorTarget>();

            foreach (KeyValuePair <PathEditMode, List <PathEditorTarget> > keyValuePair in dictionary)
            {
                foreach (PathEditorTarget pathEditorTarget in keyValuePair.Value)
                {
                    pathEditorTarget.BeginEditing();
                    int count1 = pathEditorTarget.PathGeometry.Figures.Count;
                    ICollection <PathPart> selectionByElement = partSelectionSet.GetSelectionByElement((SceneElement)pathEditorTarget.EditingElement, keyValuePair.Key);
                    new DeleteCommand.SelectedComponentsRemover(pathEditorTarget).Execute(selectionByElement);
                    pathEditorTarget.EndEditing(false);
                    pathEditorTarget.PostDeleteAction();
                    if (keyValuePair.Key == PathEditMode.ScenePath)
                    {
                        if (!PathGeometryUtilities.IsEmpty(pathEditorTarget.PathGeometry))
                        {
                            PathElement pathElement = (PathElement)pathEditorTarget.EditingElement;
                            int         count2      = pathElement.PathGeometry.Figures.Count;
                            if (count1 == 1 && count2 > 1)
                            {
                                ISceneNodeCollection <SceneNode> collectionContainer = pathElement.GetCollectionContainer();
                                if (!collectionContainer.FixedCapacity.HasValue || collectionContainer.FixedCapacity.Value >= collectionContainer.Count - 1 + count2)
                                {
                                    list2.Add(pathEditorTarget);
                                }
                            }
                        }
                        else
                        {
                            list1.Add(pathEditorTarget);
                        }
                    }
                    pathEditorTarget.AddCriticalEdit();
                }
            }
            List <SceneElement> list3 = new List <SceneElement>();

            foreach (PathEditorTarget pathEditorTarget in list2)
            {
                PathElement pathElement1 = (PathElement)pathEditorTarget.EditingElement;
                using (this.SceneView.AdornerLayer.SuspendUpdates())
                {
                    this.SceneView.UpdateLayout();
                    foreach (PathElement pathElement2 in PathCommandHelper.ReleaseCompoundPaths(pathElement1, editTransaction))
                    {
                        list3.Add((SceneElement)pathElement2);
                    }
                }
            }
            foreach (PathEditorTarget pathEditorTarget in list1)
            {
                pathEditorTarget.RemovePath();
            }
            partSelectionSet.Clear();
            this.SceneViewModel.ElementSelectionSet.ExtendSelection((ICollection <SceneElement>)list3);
            foreach (SceneElement sceneElement in list3)
            {
                hashSet.Add(sceneElement);
            }
            return(hashSet);
        }
Exemplo n.º 23
0
        protected override void EndEditingInternal(bool pathJustCreated)
        {
            Matrix identity = Matrix.Identity;

            if (!pathJustCreated)
            {
                Transform geometryTransform = this.pathElement.GeometryTransform;
                if (geometryTransform != null)
                {
                    identity = geometryTransform.Value;
                }
            }
            Rect extent1 = PathGeometryUtilities.TightExtent(this.PathGeometry, identity);
            Rect extent2 = extent1;
            bool flag1   = false;

            if (this.ViewModel.AnimationEditor.IsKeyFraming)
            {
                if ((Stretch)this.pathElement.GetLocalOrDefaultValueAsWpf(ShapeElement.StretchProperty) != Stretch.None)
                {
                    flag1 = true;
                    if (!pathJustCreated)
                    {
                        extent1 = PathGeometryUtilities.TightExtent(this.pathElement.PathGeometry, Matrix.Identity);
                    }
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                        {
                            this.pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.None);
                            this.ViewModel.Document.OnUpdatedEditTransaction();
                        }
                    }
                }
                if (this.pathElement.EnsureSingleSegmentsInPathGeometry())
                {
                    this.ViewModel.Document.OnUpdatedEditTransaction();
                }
            }
            Rect         extent3        = PathCommandHelper.InflateRectByStrokeWidth(extent1, this.pathElement, pathJustCreated);
            Rect         rect1          = PathCommandHelper.InflateRectByStrokeWidth(extent2, this.pathElement, pathJustCreated);
            Rect         computedBounds = this.pathElement.GetComputedBounds((Base2DElement)this.pathElement);
            PathGeometry pathGeometry1  = this.PathGeometry;

            if (flag1 && !pathJustCreated)
            {
                ScenePathEditorTarget.NormalizePathGeometry(pathGeometry1, extent3, computedBounds);
            }
            if (flag1)
            {
                this.OnMatrixChanged();
            }
            Vector    vector1     = new Vector(extent3.Left, extent3.Top);
            Transform transform   = (Transform)null;
            Point     centerPoint = new Point();
            bool      flag2       = (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated;

            if (flag2 && !computedBounds.Contains(rect1))
            {
                ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, true);
                Rect            childRect        = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement);
                double          x       = Math.Min(0.0, rect1.Left);
                double          y       = Math.Min(0.0, rect1.Top);
                Vector          vector2 = new Vector(x, y);
                centerPoint = this.pathElement.RenderTransformOrigin;
                transform   = this.pathElement.RenderTransform;
                if (transform != null && !transform.Value.IsIdentity)
                {
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                            this.UpdateCenterPoint(new Point(0.0, 0.0));
                    }
                    vector2 *= transform.Value;
                }
                double num1 = Math.Max(0.0, rect1.Right - computedBounds.Right);
                double num2 = Math.Max(0.0, rect1.Bottom - computedBounds.Bottom);
                childRect.X      += vector2.X;
                childRect.Y      += vector2.Y;
                childRect.Width  += -x + num1;
                childRect.Height += -y + num2;
                using (this.ViewModel.ForceBaseValue())
                {
                    using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                        designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, childRect);
                }
                if (x != 0.0 || y != 0.0)
                {
                    this.AdjustKeyframes(new Vector(x, y));
                    ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, new Vector(x, y), 1.0, 1.0);
                    PathGeometry pathGeometry2 = this.pathElement.PathGeometry;
                    ScenePathEditorTarget.UpdateAllPoints(pathGeometry2, new Vector(x, y), 1.0, 1.0);
                    this.pathElement.PathGeometry = pathGeometry2;
                }
                this.ViewModel.Document.OnUpdatedEditTransaction();
                if (transform != null && !transform.Value.IsIdentity)
                {
                    using (this.ViewModel.ForceBaseValue())
                    {
                        using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                            this.UpdateCenterPoint(centerPoint);
                    }
                }
            }
            if (!flag2 && (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None)
            {
                ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, vector1, 1.0, 1.0);
            }
            if (!flag2)
            {
                using (this.ViewModel.ForceBaseValue())
                {
                    using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                    {
                        centerPoint = this.pathElement.RenderTransformOrigin;
                        transform   = this.pathElement.RenderTransform;
                        if (!extent3.IsEmpty)
                        {
                            if (transform != null && !transform.Value.IsIdentity)
                            {
                                this.UpdateCenterPoint(new Point(0.0, 0.0));
                                vector1 *= transform.Value;
                            }
                            ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, false);
                            Rect            rect2            = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement);
                            if (pathJustCreated)
                            {
                                rect2 = new Rect(0.0, 0.0, 0.0, 0.0);
                            }
                            double width  = extent3.Width;
                            double height = extent3.Height;
                            rect2.Offset(vector1);
                            rect2.Width  = width;
                            rect2.Height = height;
                            designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, rect2);
                        }
                    }
                }
            }
            if (this.pathElement.IsAttached && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated)
            {
                new PathDiff((Base2DElement)this.pathElement, PathElement.DataProperty, this.PathDiffChangeList).SetPathUsingMinimalDiff(pathGeometry1);
            }
            else
            {
                this.pathElement.PathGeometry = pathGeometry1;
            }
            if (flag2)
            {
                return;
            }
            using (this.ViewModel.ForceBaseValue())
            {
                using (this.ViewModel.AnimationEditor.DeferKeyFraming())
                {
                    if (extent3.IsEmpty)
                    {
                        return;
                    }
                    this.ViewModel.Document.OnUpdatedEditTransaction();
                    if (transform == null || transform.Value.IsIdentity)
                    {
                        return;
                    }
                    this.UpdateCenterPoint(centerPoint);
                }
            }
        }
Exemplo n.º 24
0
 public override void Execute()
 {
     using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.undoDescription))
     {
         this.ConvertSelectedElementsToPathIfNecessary();
         editTransaction.Update();
         this.SceneViewModel.DefaultView.UpdateLayout();
         SceneElementSelectionSet      elementSelectionSet   = this.SceneViewModel.ElementSelectionSet;
         SceneElement                  primarySelection      = elementSelectionSet.PrimarySelection;
         System.Windows.Media.Geometry renderedGeometryAsWpf = this.SceneView.GetRenderedGeometryAsWpf(primarySelection);
         if (renderedGeometryAsWpf == null)
         {
             return;
         }
         this.Initialize(renderedGeometryAsWpf);
         SceneElementCollection elementCollection = new SceneElementCollection();
         foreach (SceneElement shapeElement in elementSelectionSet.Selection)
         {
             if (shapeElement != primarySelection)
             {
                 elementCollection.Add(shapeElement);
                 System.Windows.Media.Geometry secondaryGeometry = this.SceneView.GetRenderedGeometryAsWpf(shapeElement);
                 if (secondaryGeometry == null)
                 {
                     return;
                 }
                 Matrix transformToElement = shapeElement.GetComputedTransformToElement(primarySelection);
                 if (!transformToElement.IsIdentity)
                 {
                     MatrixTransform matrixTransform = new MatrixTransform(transformToElement);
                     matrixTransform.Freeze();
                     GeometryGroup geometryGroup = new GeometryGroup();
                     geometryGroup.Children.Add(secondaryGeometry);
                     geometryGroup.Transform = (Transform)matrixTransform;
                     secondaryGeometry       = (System.Windows.Media.Geometry)geometryGroup;
                 }
                 this.Combine(secondaryGeometry);
             }
         }
         PathGeometry result = this.GetResult();
         BooleanCommand.CleanUpPathGeometry(ref result);
         PathGeometry pathGeometry = PathConversionHelper.RemoveDegeneratePoints((System.Windows.Media.Geometry)result);
         elementSelectionSet.Clear();
         PathGeometryUtilities.CollapseSingleSegmentsToPolySegments(pathGeometry);
         PathElement pathElement = (PathElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Path);
         Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null;
         using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
         {
             this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection);
             properties = SceneElementHelper.StoreProperties((SceneNode)primarySelection);
             ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer();
             int index = collectionContainer.IndexOf((SceneNode)primarySelection);
             collectionContainer[index] = (SceneNode)pathElement;
         }
         foreach (SceneElement element in elementCollection)
         {
             this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
             element.Remove();
         }
         using (this.SceneViewModel.ForceBaseValue())
         {
             if (properties != null)
             {
                 SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties);
             }
             pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill);
             PathCommandHelper.ReplacePathGeometry(pathElement, pathGeometry, editTransaction);
         }
         elementSelectionSet.SetSelection((SceneElement)pathElement);
         editTransaction.Commit();
     }
 }
Exemplo n.º 25
0
        public static Transform ReplacePathGeometry(PathElement pathElement, PathGeometry pathGeometry, SceneEditTransaction editTransaction)
        {
            Transform transform1 = Transform.Identity;

            using (pathElement.ViewModel.ForceBaseValue())
            {
                if (pathGeometry == null)
                {
                    pathElement.ClearLocalValue(PathElement.DataProperty);
                }
                else
                {
                    editTransaction.Update();
                    ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true);
                    Rect            childRect        = designerForChild.GetChildRect((BaseFrameworkElement)pathElement);
                    Path            path             = pathElement.Path;
                    Transform       transform2       = path == null ? (Transform)null : path.RenderTransform;
                    Point           point1           = path == null ? new Point(0.0, 0.0) : path.RenderTransformOrigin;
                    double          num           = path == null || path.Stroke == null ? 0.0 : path.StrokeThickness;
                    Rect            bounds        = pathGeometry.Bounds;
                    PathGeometry    pathGeometry1 = new PathGeometry();
                    pathGeometry1.AddGeometry((System.Windows.Media.Geometry)pathGeometry);
                    Rect   rect1   = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry1.Bounds, pathElement, false);
                    Vector vector1 = new Vector(-rect1.Left, -rect1.Top);
                    transform1 = (Transform) new TranslateTransform(vector1.X, vector1.Y);
                    PathGeometry pathGeometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry1, transform1);
                    pathElement.PathGeometry = pathGeometry2;
                    PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
                    PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform1);
                    if (!bounds.IsEmpty)
                    {
                        bounds.Inflate(num / 2.0, num / 2.0);
                        Rect rect2 = new Rect(childRect.Left + bounds.Left, childRect.Top + bounds.Top, bounds.Width, bounds.Height);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect2);
                        if (pathElement.IsSet(Base2DElement.RenderTransformOriginProperty) != PropertyState.Set)
                        {
                            if (transform2 != null)
                            {
                                if (transform2.Value.IsIdentity)
                                {
                                    goto label_15;
                                }
                            }
                            else
                            {
                                goto label_15;
                            }
                        }
                        Vector vector2 = childRect.TopLeft + new Vector(point1.X * childRect.Width, point1.Y * childRect.Height) - rect2.TopLeft;
                        Point  point2  = new Point(0.0, 0.0);
                        if (rect2.Width != 0.0)
                        {
                            point2.X = vector2.X / rect2.Width;
                        }
                        if (rect2.Height != 0.0)
                        {
                            point2.Y = vector2.Y / rect2.Height;
                        }
                        pathElement.RenderTransformOrigin = point2;
                    }
                }
            }
label_15:
            return(transform1);
        }
Exemplo n.º 26
0
 protected override void EndEditingInternal(bool pathJustCreated)
 {
     this.ViewModel.AnimationEditor.SetMotionPath((SceneElement)this.editingElement, PathGeometryUtilities.Copy(this.PathGeometry, true), new double?(), new double?());
 }