private static SceneElement ChangeLayoutType(SceneElement sourceElement, ITypeId layoutType, ref SceneElement elementContainingChildren) { IDocumentRoot documentRoot = sourceElement.DocumentNode.DocumentRoot; IDocumentContext documentContext = documentRoot.DocumentContext; SceneViewModel viewModel = sourceElement.ViewModel; Size size = Size.Empty; BaseFrameworkElement frameworkElement = sourceElement as BaseFrameworkElement; if (frameworkElement != null) { size = frameworkElement.GetComputedTightBounds().Size; } using (viewModel.ForceBaseValue()) { SceneElement sceneElement = (SceneElement)viewModel.CreateSceneNode(layoutType); using (viewModel.DisableUpdateChildrenOnAddAndRemove()) { using (viewModel.DisableDrawIntoState()) { viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)sourceElement); Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)sourceElement); Dictionary <IPropertyId, List <SceneNode> > storedChildren = ChangeLayoutTypeCommand.StoreChildren(sourceElement); if (sourceElement.DocumentNode == documentRoot.RootNode) { documentRoot.RootNode = sceneElement.DocumentNode; sceneElement.DocumentNode.NameScope = new DocumentNodeNameScope(); } else { ISceneNodeCollection <SceneNode> collectionContainer = sourceElement.GetCollectionContainer(); int index = collectionContainer.IndexOf((SceneNode)sourceElement); sourceElement.Remove(); collectionContainer.Insert(index, (SceneNode)sceneElement); } SceneElementHelper.ApplyProperties((SceneNode)sceneElement, properties); elementContainingChildren = ChangeLayoutTypeCommand.ApplyChildren(sceneElement, storedChildren, size); } } if (sceneElement is GridElement || sceneElement is CanvasElement) { ILayoutDesigner designerForChild = sceneElement.ViewModel.GetLayoutDesignerForChild(sceneElement, true); if ((designerForChild.GetWidthConstraintMode((BaseFrameworkElement)sceneElement) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike) { sceneElement.SetValue(BaseFrameworkElement.WidthProperty, (object)size.Width); } if ((designerForChild.GetHeightConstraintMode((BaseFrameworkElement)sceneElement) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike) { sceneElement.SetValue(BaseFrameworkElement.HeightProperty, (object)size.Height); } } return(sceneElement); } }
public override void Execute(object arg) { DesignerContext designerContext = this.DesignerContext; SceneViewModel activeSceneViewModel = designerContext.ActiveSceneViewModel; ITypeId type = this.Type; if (type is ProjectNeutralTypeId) { bool flag = activeSceneViewModel.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)this.DesignerContext.ActiveSceneViewModel.ProjectContext, type); if (!flag && this.IsDragDropContainer) { IMessageDisplayService messageDisplayService = activeSceneViewModel.DesignerContext.MessageDisplayService; flag = ToolkitHelper.EnsureSilverlightToolkitTypeAvailable((ITypeResolver)activeSceneViewModel.ProjectContext, type, messageDisplayService, StringTable.SilverlightToolkitDragDropNotInstalled, StringTable.SilverlightToolkitDragDropIncorrectVersion); } if (!flag) { return; } } using (SceneEditTransaction editTransaction = designerContext.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitGroupIntoLayoutType, new object[1] { (object)this.Type.Name }))) { List <SceneElement> list1 = new List <SceneElement>(); List <SceneNode> elements = new List <SceneNode>(); list1.AddRange((IEnumerable <SceneElement>)designerContext.SelectionManager.ElementSelectionSet.Selection); GroupIntoLayoutTypeCommand.OrientationHelper orientationHelper = new GroupIntoLayoutTypeCommand.OrientationHelper(); list1.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(this.SceneViewModel.RootNode)); List <LayoutCacheRecord> list2 = new List <LayoutCacheRecord>(list1.Count); Rect empty = Rect.Empty; for (int index = 0; index < list1.Count; ++index) { list2.Add((LayoutCacheRecord)null); BaseFrameworkElement element = list1[index] as BaseFrameworkElement; if (element != null) { ILayoutDesigner designerForChild = element.ViewModel.GetLayoutDesignerForChild((SceneElement)element, true); Rect roundedUpChildRect = LayoutRoundingHelper.GetRoundedUpChildRect(designerForChild, element); empty.Union(roundedUpChildRect); orientationHelper.AddChildRect((SceneNode)element, roundedUpChildRect); LayoutCacheRecord layoutCacheRecord = designerForChild.CacheLayout(element); list2[index] = layoutCacheRecord; elements.Add((SceneNode)element); } } Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null; using (this.SceneViewModel.ForceBaseValue()) { using (this.SceneViewModel.DisableDrawIntoState()) { SceneElement sceneElement1 = (SceneElement)null; SceneElement sceneElement2 = (SceneElement)activeSceneViewModel.CreateSceneNode(type); Orientation? nullable = orientationHelper.ApplyOrientation(sceneElement2); if (nullable.HasValue) { orientationHelper.SortElements(elements, nullable.Value); } int num; if (list1.Count == 1 && list1[0] is BaseFrameworkElement) { int?fixedCapacity = sceneElement2.DefaultContent.FixedCapacity; num = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false); } else { num = 0; } bool flag = num != 0; if (sceneElement2 != null) { activeSceneViewModel.GetLayoutDesignerForParent(sceneElement2, true); } foreach (SceneElement sceneElement3 in list1) { if (sceneElement3 != null) { BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement; ILayoutDesigner layoutDesigner = frameworkElement == null ? (ILayoutDesigner)null : sceneElement3.ViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true); if (flag) { properties = SceneElementHelper.StoreProperties((SceneNode)sceneElement3, layoutDesigner.GetLayoutProperties(), true); } if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == sceneElement3) { sceneElement1 = sceneElement3; } } } if (list1.Count == 1) { VisualStateManagerSceneNode.MoveStates(list1[0], sceneElement2); } using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { SceneElement primarySelection = designerContext.SelectionManager.ElementSelectionSet.PrimarySelection; designerContext.SelectionManager.ElementSelectionSet.Clear(); Dictionary <IPropertyId, List <SceneNode> > storedChildren = new Dictionary <IPropertyId, List <SceneNode> >(); storedChildren.Add((IPropertyId)sceneElement2.DefaultContentProperty, elements); ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer(); foreach (SceneElement sceneElement3 in list1) { if (sceneElement3 != primarySelection) { sceneElement3.Remove(); } } int index1 = collectionContainer.IndexOf((SceneNode)primarySelection); primarySelection.Remove(); collectionContainer.Insert(index1, (SceneNode)sceneElement2); ChangeLayoutTypeCommand.ApplyChildren(sceneElement2, storedChildren, empty.Size); if (flag) { SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)list1[0], (SceneNode)sceneElement2, properties); SceneElementHelper.ApplyProperties((SceneNode)sceneElement2, properties); } else { ILayoutDesigner designerForChild = sceneElement2.ViewModel.GetLayoutDesignerForChild(sceneElement2, true); if (sceneElement2.IsViewObjectValid) { LayoutOverrides layoutOverrides = LayoutOverrides.None; LayoutOverrides overridesToIgnore = LayoutOverrides.None; if (nullable.HasValue && nullable.Value == Orientation.Horizontal) { layoutOverrides |= LayoutOverrides.Width; } else { overridesToIgnore |= LayoutOverrides.Width; } if (nullable.HasValue && nullable.Value == Orientation.Vertical) { layoutOverrides |= LayoutOverrides.Height; } else { overridesToIgnore |= LayoutOverrides.Height; } designerForChild.SetChildRect((BaseFrameworkElement)sceneElement2, empty, layoutOverrides, overridesToIgnore, LayoutOverrides.None); } } editTransaction.Update(); if (sceneElement2.IsViewObjectValid) { this.SceneViewModel.DefaultView.UpdateLayout(); SceneElement parentElement = primarySelection.ParentElement; ILayoutDesigner designerForParent = activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true); for (int index2 = 0; index2 < list1.Count; ++index2) { SceneElement sceneElement3 = list1[index2]; BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement; if (frameworkElement != null) { LayoutCacheRecord layoutCacheRecord = list2[index2]; Rect rect = LayoutRoundingHelper.RoundUpLayoutRect(frameworkElement, layoutCacheRecord.Rect); rect.Location = (Point)(rect.Location - empty.Location); designerForParent.ClearUnusedLayoutProperties(frameworkElement); designerForParent.SetChildRect(frameworkElement, rect, flag ? LayoutOverrides.None : layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None); if (this.IsDragDropContainer) { sceneElement3.SetValue(Base2DElement.AllowDropProperty, (object)true); } } } } if (sceneElement1 != null) { this.SceneViewModel.SetLockedInsertionPoint(sceneElement1); } } designerContext.SelectionManager.ElementSelectionSet.SetSelection(sceneElement2); editTransaction.Commit(); } } } }
private SceneElement GroupElements() { ReadOnlyCollection <SceneElement> selection = this.SceneViewModel.ElementSelectionSet.Selection; if (selection[0] is BaseFrameworkElement) { return((SceneElement)null); } if (!(selection[0] is Base3DElement)) { return((SceneElement)null); } SceneElement primarySelection = this.SceneViewModel.ElementSelectionSet.PrimarySelection; this.SceneViewModel.ElementSelectionSet.Clear(); List <SceneElement> list = new List <SceneElement>((IEnumerable <SceneElement>)selection); Base3DElement base3Delement1 = (Base3DElement)null; int num = int.MaxValue; Viewport3DElement viewport = ((Base3DElement)list[0]).Viewport; foreach (Base3DElement base3Delement2 in list) { if (base3Delement2.Viewport == viewport) { int depthFromViewport3D = base3Delement2.DepthFromViewport3D; if (depthFromViewport3D < num) { base3Delement1 = base3Delement2; num = depthFromViewport3D; } } } SceneElement parentElement = base3Delement1.ParentElement; Matrix3D matrix3D = Matrix3D.Identity; if (parentElement is Base3DElement) { matrix3D = ((Base3DElement)parentElement).GetComputedTransformFromViewport3DToElement(); matrix3D.Invert(); } Base3DElement parent = (Base3DElement)null; if (list[0] is Model3DElement) { Model3DGroup model3Dgroup = new Model3DGroup(); Model3DCollection model3Dcollection = new Model3DCollection(); model3Dgroup.Children = model3Dcollection; parent = (Base3DElement)this.SceneViewModel.CreateSceneNode((object)model3Dgroup); } else if (list[0] is Visual3DElement) { parent = (Base3DElement)this.SceneViewModel.CreateSceneNode((object)new ModelVisual3D()); } SceneNodeIDHelper sceneNodeIdHelper = new SceneNodeIDHelper(this.SceneViewModel, (SceneNode)this.SceneViewModel.ActiveSceneInsertionPoint.SceneElement.StoryboardContainer); string validElementId = sceneNodeIdHelper.GetValidElementID((SceneNode)parent, "group3D"); sceneNodeIdHelper.SetLocalName((SceneNode)parent, validElementId); using (this.SceneViewModel.ForceBaseValue()) { Matrix3D[] matrix3DArray = new Matrix3D[list.Count]; for (int index = 0; index < list.Count; ++index) { matrix3DArray[index] = ((Base3DElement)list[index]).GetComputedTransformFromViewport3DToElement(); } foreach (Base3DElement base3Delement2 in list) { if (base3Delement2 != primarySelection) { base3Delement2.Remove(); } } int insertAt = primarySelection.GetCollectionContainer().IndexOf((SceneNode)primarySelection); primarySelection.Remove(); if (parentElement is Viewport3DElement) { GroupCommandHelpers.InsertElement(parentElement, (SceneNode)parent, insertAt); } else { GroupCommandHelpers.InsertElement(this.SceneViewModel, (Base3DElement)parentElement, (SceneNode)parent, new int?(insertAt)); } for (int index = 0; index < list.Count; ++index) { GroupCommandHelpers.InsertElement(this.SceneViewModel, parent, (SceneNode)list[index], new int?()); ((Base3DElement)list[index]).Transform = (Transform3D) new CanonicalTransform3D(matrix3DArray[index] * matrix3D); } } return((SceneElement)parent); }
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(); } }