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(); } } }
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(); } } }
private void OnSelectElement(object o, EventArgs e) { SceneNodeProperty editingProperty = this.ElementPicker.EditingProperty; if (editingProperty == null) { return; } SceneElement root = editingProperty.SceneNodeObjectSet.ViewModel.ActiveEditingContainer as SceneElement; if (root == null) { return; } this.ElementPicker.ChangeElementName(PathTargetDialog.ChooseElementForBehavior(root, this.TypeConstraint)); }