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(); } } }
public static PathElement ConvertToPath(BaseFrameworkElement element) { SceneViewModel viewModel = element.ViewModel; PathGeometry pathGeometry = PathConversionHelper.ConvertToPathGeometry((SceneElement)element); PathElement pathElement = (PathElement)viewModel.CreateSceneNode(PlatformTypes.Path); ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)element, true); Rect childRect = designerForChild.GetChildRect(element); Transform transform1 = Transform.Identity; if (element.IsSet(Base2DElement.RenderTransformProperty) == PropertyState.Set) { transform1 = (Transform)element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty); } Point point1 = new Point(0.5, 0.5); if (element.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Set) { point1 = (Point)element.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty); } bool flag = false; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitConvertToPath, true)) { using (viewModel.ForceBaseValue()) { pathElement.PathGeometry = pathGeometry; pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill); Brush textForeground = PathCommandHelper.GetTextForeground(element); if (textForeground != null) { flag = true; pathElement.SetValueAsWpf(ShapeElement.FillProperty, (object)textForeground); } viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)element); Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)element); ISceneNodeCollection <SceneNode> collectionForChild = element.Parent.GetCollectionForChild((SceneNode)element); int index = collectionForChild.IndexOf((SceneNode)element); collectionForChild[index] = (SceneNode)pathElement; if (flag) { List <IPropertyId> list = new List <IPropertyId>(); foreach (KeyValuePair <IPropertyId, SceneNode> keyValuePair in properties) { IPropertyId key = keyValuePair.Key; DependencyPropertyReferenceStep propertyReferenceStep = key as DependencyPropertyReferenceStep; if (propertyReferenceStep != null && !propertyReferenceStep.IsAttachable && (propertyReferenceStep.MemberType != MemberType.DesignTimeProperty && !PlatformTypeHelper.GetDeclaringType((IMember)propertyReferenceStep).IsAssignableFrom(typeof(Path)))) { list.Add(key); } } foreach (IPropertyId key in list) { properties.Remove(key); } } SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties); } if (ProjectNeutralTypes.PrimitiveShape.IsAssignableFrom((ITypeId)element.Type)) { using (viewModel.ForceBaseValue()) { Rect bounds = pathGeometry.Bounds; double halfStrokeWidth = PathCommandHelper.GetHalfStrokeWidth(pathElement); bounds.Inflate(halfStrokeWidth / 2.0, halfStrokeWidth / 2.0); if (transform1 != Transform.Identity && bounds.Size != childRect.Size) { Point point2 = (Point)pathElement.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty); Point point3 = new Point(point2.X * childRect.Width, point2.Y * childRect.Height); Point point4 = new Point((point3.X - bounds.X) / bounds.Width, (point3.Y - bounds.Y) / bounds.Height); pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point4); } bounds.Offset(childRect.Left, childRect.Top); editTransaction.Update(); designerForChild.SetChildRect((BaseFrameworkElement)pathElement, bounds); } } if (flag && !pathGeometry.IsEmpty()) { using (viewModel.ForceBaseValue()) { Rect bounds = pathGeometry.Bounds; bounds.Offset(childRect.Left, childRect.Top); Point point2 = new Point(bounds.Left + point1.X * bounds.Width, bounds.Top + point1.Y * bounds.Height); Point point3 = new Point(childRect.Left + childRect.Width * point1.X, childRect.Top + childRect.Height * point1.Y); Point point4 = new TransformGroup() { Children = { (Transform) new TranslateTransform(-point3.X, -point3.Y), transform1, (Transform) new TranslateTransform(point3.X, point3.Y) } }.Transform(point2); Transform transform2 = (Transform) new CanonicalTransform(transform1) { TranslationX = 0.0, TranslationY = 0.0 }.TransformGroup; Rect rect = new Rect(point4.X - bounds.Width * point1.X, point4.Y - bounds.Height * point1.Y, bounds.Width, bounds.Height); pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point1); editTransaction.Update(); designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect); pathElement.RenderTransform = transform2; } } editTransaction.Commit(); } return(pathElement); }
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); }