private static bool IsElementToPathConversionNecessary(SceneElement element) { if (PathConversionHelper.CanConvert(element)) { return(!PlatformTypes.Shape.IsAssignableFrom((ITypeId)element.Type)); } return(false); }
private bool CanBeClipper(SceneElement element) { if (this.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.PrefersRectangularClippingPath)) { return(element is RectangleElement); } return(PathConversionHelper.CanConvert(element)); }
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; }
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 SceneElement GetAnimationTarget(SceneElementSelectionSet selection) { SceneElement sceneElement = (SceneElement)null; if (selection.Count == 2) { SceneElement primarySelection = selection.PrimarySelection; SceneElement element = selection.Selection[0] == primarySelection ? selection.Selection[1] : selection.Selection[0]; if (PathConversionHelper.CanConvert(element)) { sceneElement = primarySelection; } else if (PathConversionHelper.CanConvert(primarySelection)) { sceneElement = element; } } return(sceneElement); }
public override void Execute() { using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeCompoundPath)) { SceneElementSelectionSet elementSelectionSet = this.SceneViewModel.ElementSelectionSet; List <PathElement> otherElements = new List <PathElement>(); foreach (SceneElement element in elementSelectionSet.Selection) { PathElement pathElement = element as PathElement; if (pathElement != null) { otherElements.Add(pathElement); } else if (PathConversionHelper.CanConvert(element)) { otherElements.Add(PathCommandHelper.ConvertToPath((BaseFrameworkElement)element)); } } editTransaction.Update(); this.DesignerContext.ActiveView.UpdateLayout(); otherElements.Sort((IComparer <PathElement>) new ZOrderComparer <PathElement>(this.SceneViewModel.RootNode)); elementSelectionSet.Clear(); PathElement mainElement = otherElements[0]; BaseFrameworkElement frameworkElement = (BaseFrameworkElement)otherElements[otherElements.Count - 1]; ISceneNodeCollection <SceneNode> collectionForChild = frameworkElement.ParentElement.GetCollectionForChild((SceneNode)frameworkElement); int num = collectionForChild.IndexOf((SceneNode)frameworkElement); SceneNode sceneNode = num + 1 < collectionForChild.Count ? collectionForChild[num + 1] : (SceneNode)null; otherElements.RemoveAt(0); PathCommandHelper.MakeCompoundPath(mainElement, otherElements, editTransaction); mainElement.Remove(); if (sceneNode == null) { collectionForChild.Add((SceneNode)mainElement); } else { collectionForChild.Insert(collectionForChild.IndexOf(sceneNode), (SceneNode)mainElement); } elementSelectionSet.SetSelection((SceneElement)mainElement); 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); }
public static ContextMenu CreateContextMenu(ISelectionSet <SceneElement> selection, SceneViewModel viewModel, bool isOnArtboard) { viewModel.DesignerContext.CommandBarService.CommandBars.Remove("Designer_SceneContextMenu"); ICommandBar commandBar = viewModel.DesignerContext.CommandBarService.CommandBars.AddContextMenu("Designer_SceneContextMenu"); commandBar.Items.AddButton("Edit_Cut", StringTable.ElementContextMenuCut); commandBar.Items.AddButton("Edit_Copy", StringTable.ElementContextMenuCopy); commandBar.Items.AddButton("Edit_Paste", StringTable.ElementContextMenuPaste); commandBar.Items.AddButton("Edit_Delete", StringTable.ElementContextMenuDelete); ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); ContextMenuHelper.AddExtensibleMenuItems(commandBar, viewModel, selection.PrimarySelection != null ? selection.PrimarySelection.TargetType : (Type)null); if (new CopyToResourceCommand(viewModel).IsEnabled) { commandBar.Items.AddButton("Edit_MakeTileBrush_CopyToResource", StringTable.ElementContextMenuCopyToResource); } if (new MoveToResourceCommand(viewModel).IsEnabled) { commandBar.Items.AddButton("Edit_MakeTileBrush_MoveToResource", StringTable.ElementContextMenuMoveToResource); } bool flag1 = false; bool flag2 = false; bool flag3 = true; foreach (SceneElement element in selection.Selection) { if (!flag1 && PathConversionHelper.CanConvert(element)) { flag1 = true; flag2 = true; } if (!flag2 && element.IsSet(Base2DElement.ClipProperty) == PropertyState.Set) { flag1 = true; } if (flag3 && !PlatformTypes.UIElement.IsAssignableFrom((ITypeId)element.Type)) { flag3 = false; } } if (flag3) { ICommandBarMenu commandBarMenu1 = commandBar.Items.AddMenu("Order", StringTable.ElementContextMenuOrder); commandBarMenu1.Items.AddButton("Edit_Order_BringToFront", StringTable.ElementContextMenuOrderBringToFront); commandBarMenu1.Items.AddButton("Edit_Order_BringForward", StringTable.ElementContextMenuOrderBringForward); commandBarMenu1.Items.AddButton("Edit_Order_SendBackward", StringTable.ElementContextMenuOrderSendBackward); commandBarMenu1.Items.AddButton("Edit_Order_SendToBack", StringTable.ElementContextMenuOrderSendToBack); ICommandBarMenu commandBarMenu2 = commandBar.Items.AddMenu("Align", StringTable.ElementContextMenuAlign); commandBarMenu2.Items.AddButton("Edit_Align_AlignLeft", StringTable.ElementContextMenuAlignLeft); commandBarMenu2.Items.AddButton("Edit_Align_AlignCenter", StringTable.ElementContextMenuAlignCenter); commandBarMenu2.Items.AddButton("Edit_Align_AlignRight", StringTable.ElementContextMenuAlignRight); commandBarMenu2.Items.AddSeparator(); commandBarMenu2.Items.AddButton("Edit_Align_AlignTop", StringTable.ElementContextMenuAlignTop); commandBarMenu2.Items.AddButton("Edit_Align_AlignMiddle", StringTable.ElementContextMenuAlignMiddle); commandBarMenu2.Items.AddButton("Edit_Align_AlignBottom", StringTable.ElementContextMenuAlignBottom); ICommandBarMenu commandBarMenu3 = commandBar.Items.AddMenu("AutoSize", StringTable.ElementContextMenuAutoSize); commandBarMenu3.Items.AddCheckBox("Edit_AutoSize_Horizontal", StringTable.ElementContextMenuAutoSizeWidth); commandBarMenu3.Items.AddCheckBox("Edit_AutoSize_Vertical", StringTable.ElementContextMenuAutoSizeHeight); commandBarMenu3.Items.AddCheckBox("Edit_AutoSize_Both", StringTable.ElementContextMenuAutoSizeBoth); commandBarMenu3.Items.AddButton("Edit_AutoSize_Fill", StringTable.ElementContextMenuAutoSizeFill); } if (flag3) { ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); commandBar.Items.AddButton("Edit_Group", StringTable.ElementContextMenuGroup); commandBar.Items.AddDynamicMenu("Edit_GroupInto", StringTable.GroupIntoCommandName); commandBar.Items.AddButton("Edit_Ungroup", StringTable.ElementContextMenuUngroup); } if (ChangeLayoutTypeFlyoutCommand.ShouldShowChangeLayoutTypeMenu(selection)) { commandBar.Items.AddDynamicMenu("Edit_ChangeLayoutTypes", StringTable.ChangeLayoutTypeCommandName); } if (new ToggleLockInsertionPointCommand(viewModel).IsEnabled) { commandBar.Items.AddCheckBox("Edit_LockInsertionPoint", StringTable.SelectionContextMenuLockInsertionPoint); } if (isOnArtboard) { commandBar.Items.AddDynamicMenu("Edit_SetCurrentSelection", StringTable.ElementContextMenuSetCurrentSelection); } ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); if (flag2) { ICommandBarMenu menu = commandBar.Items.AddMenu("Combine", StringTable.ElementContextMenuToolsMenuCombine); menu.Items.AddButton("Tools_Combine_Unite", StringTable.ElementContextMenuToolsMenuUnite); menu.Items.AddButton("Tools_Combine_Divide", StringTable.ElementContextMenuToolsMenuDivide); menu.Items.AddButton("Tools_Combine_Intersect", StringTable.ElementContextMenuToolsMenuIntersect); menu.Items.AddButton("Tools_Combine_Subtract", StringTable.ElementContextMenuToolsMenuSubtract); menu.Items.AddButton("Tools_Combine_ExcludeOverlap", StringTable.ElementContextMenuToolsMenuExcludeOverlap); if (ContextMenuHelper.IsSubmenuDisabled(menu)) { commandBar.Items.Remove((ICommandBarItem)menu); } } if (flag1) { ICommandBarMenu menu = commandBar.Items.AddMenu("Path", StringTable.ElementContextMenuObjectMenuPath); menu.Items.AddButton("Edit_ConvertToPath", StringTable.ElementContextMenuObjectMenuConvertToPath); menu.Items.AddButton("Edit_ConvertToMotionPath", StringTable.ElementContextMenuObjectMenuConvertToMotionPath); menu.Items.AddButton("Edit_MakeLayoutPath", StringTable.ElementContextMenuObjectMenuMakeLayoutPath); menu.Items.AddButton("Edit_MakeClippingPath", StringTable.ElementContextMenuObjectMenuMakeClippingPath); menu.Items.AddButton("Edit_RemoveClippingPath", StringTable.ElementContextMenuObjectMenuRemoveClippingPath); menu.Items.AddButton("Edit_MakeCompoundPath", StringTable.ElementContextMenuObjectMenuMakeCompoundPath); menu.Items.AddButton("Edit_ReleaseCompoundPath", StringTable.ElementContextMenuObjectMenuReleaseCompoundPath); if (ContextMenuHelper.IsSubmenuDisabled(menu)) { commandBar.Items.Remove((ICommandBarItem)menu); } } ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); if (selection.Count == 1) { SceneElement primarySelection = selection.PrimarySelection; int count = commandBar.Items.Count; primarySelection.AddCustomContextMenuCommands(commandBar); if (count == commandBar.Items.Count) { commandBar.Items.RemoveAt(count - 1); } if (primarySelection.DocumentNode != null) { if (TextEditProxyFactory.IsEditableElement(primarySelection)) { commandBar.Items.AddButton("Edit_EditText", StringTable.ElementContextMenuEditText); } if (flag3) { ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); commandBar.Items.AddButton("Edit_MakeButton", StringTable.MakeControlCommandName); if (viewModel.PartsModel.IsEnabled && selection.Count == 1) { if (viewModel.PartsModel.GetPartStatus((SceneNode)selection.PrimarySelection) != PartStatus.Assigned) { Type targetElementType = ((FrameworkTemplateElement)viewModel.ActiveEditingContainer).TargetElementType; commandBar.Items.AddDynamicMenu("Edit_MakePart", string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.MakeIntoPartMenuEnabled, new object[1] { (object)targetElementType.Name })); } else { commandBar.Items.AddButton("Edit_MakePart", StringTable.MakeIntoPartMenuDisabled); } commandBar.Items.AddButton("Edit_ClearPart", StringTable.ClearPartAssignmentCommandName); } commandBar.Items.AddButton("Edit_MakeUserControl", StringTable.MakeUserControlCommandName); commandBar.Items.AddButton("Edit_MakeCompositionScreen", StringTable.MakeCompositionScreenCommandName); if (primarySelection.DocumentNode.Type.XamlSourcePath != null) { commandBar.Items.AddButton("Edit_EditControl", StringTable.ElementContextMenuEditControl); } } } ITypeId type = (ITypeId)primarySelection.Type; StyleNode styleNode = primarySelection as StyleNode; if (styleNode != null) { type = (ITypeId)styleNode.StyleTargetTypeId; } if (PlatformTypes.Control.IsAssignableFrom(type) || PlatformTypes.Page.IsAssignableFrom(type)) { ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); ICommandBarMenu commandBarMenu = commandBar.Items.AddMenu("Template", StringTable.ElementContextMenuEditTemplateMenuName); commandBarMenu.Items.AddButton("Edit_Template_EditExisting", StringTable.EditExistingTemplateCommandName); commandBarMenu.Items.AddButton("Edit_Template_EditCopy", StringTable.EditClonedStyleCommandName); commandBarMenu.Items.AddButton("Edit_Template_EditNew", StringTable.EditEmptyStyleCommandName); commandBarMenu.Items.AddSeparator(); commandBarMenu.Items.AddDynamicMenu("Edit_Template_LocalResource", StringTable.ElementContextMenuEditLocalResource); commandBar.Items.AddDynamicMenu("Edit_EditTemplates", StringTable.ElementContextMenuEditTemplates); } else if (PlatformTypes.FrameworkElement.IsAssignableFrom(type)) { ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); ICommandBarMenu commandBarMenu = commandBar.Items.AddMenu("Style", StringTable.ElementContextMenuEditStyleMenuName); commandBarMenu.Items.AddButton("Edit_Style_EditExisting", StringTable.ElementContextMenuEditExistingStyle); commandBarMenu.Items.AddButton("Edit_Style_EditCopy", StringTable.ElementContextMenuEditCopyStyle); commandBarMenu.Items.AddButton("Edit_Style_EditNew", StringTable.ElementContextMenuEditNewStyle); commandBarMenu.Items.AddSeparator(); commandBarMenu.Items.AddDynamicMenu("Edit_Style_LocalResource", StringTable.ElementContextMenuEditLocalResource); } } else if (flag3) { ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); commandBar.Items.AddButton("Edit_MakeUserControl", StringTable.MakeUserControlCommandName); commandBar.Items.AddButton("Edit_MakeCompositionScreen", StringTable.MakeCompositionScreenCommandName); } if (viewModel.DefaultView.ViewMode == ViewMode.Design) { ContextMenuHelper.AddSeparatorHelper.AddSeparator(commandBar); commandBar.Items.AddButton("View_GoToXaml", StringTable.ViewXamlCommandName); } IPrototypingService prototypingService = viewModel.DesignerContext.PrototypingService; if (prototypingService != null) { prototypingService.AddElementContextMenuItems(commandBar, (IEnumerable <SceneElement>)selection.Selection, viewModel, isOnArtboard); } ContextMenu contextMenu = (ContextMenu)commandBar; contextMenu.MinWidth = 200.0; ContextMenuHelper.AddSeparatorHelper.RemoveLastSeparatorIfNeeded(commandBar); return(contextMenu); }
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(); } }