private DocumentCompositeNode GenerateDataTemplateIfNeeded(SceneNode targetNode, ITypeId dataTemplateType) { if (this.DragModel.RelativeDropSchemaPath.IsProperty) { return((DocumentCompositeNode)null); } IList <DataSchemaNodePath> relativeSchemaPaths = this.GetRelativeSchemaPaths(); if (relativeSchemaPaths.Count == 0) { return((DocumentCompositeNode)null); } DocumentCompositeNode dataTemplateNode = (DocumentCompositeNode)null; using (SceneEditTransaction editTransaction = this.DragModel.Document.CreateEditTransaction(StringTable.UndoUnitCreateTemplate)) { DataSchemaNode node = this.DragModel.RelativeDropSchemaPath.Node; DataSchemaNode dataSchemaNode = node.CollectionItem ?? node; string str = ((dataSchemaNode.Type != (Type)null ? dataSchemaNode.Type.Name : dataSchemaNode.PathName) + "Template").TrimStart('@', '/'); if (!SceneNodeIDHelper.IsCSharpID(str)) { str = "DataTemplate"; } dataTemplateNode = DataViewFactory.CreateDataTemplateResource(targetNode, ItemsControlElement.ItemTemplateProperty, str, relativeSchemaPaths, DataViewCategory.DataTemplate, dataTemplateType); editTransaction.Update(); this.ApplyActiveUserThemeStyleToDataTemplate(dataTemplateNode); editTransaction.Commit(); } return(dataTemplateNode); }
public ImportManagerContext(string fileName, SceneViewModel sceneViewModel, IProject project, bool supportProjectRollbackOnCancel) { this.FileName = fileName; if (sceneViewModel != null) { this.sceneViewModel = sceneViewModel; this.sceneNodeIDHelper = new SceneNodeIDHelper(this.sceneViewModel, this.sceneViewModel.RootNode); } this.Project = project; this.supportProjectRollbackOnCancel = supportProjectRollbackOnCancel; }
private string GetCandidateName(SceneElement element) { if (element == null) { return(string.Empty); } SceneNode root = element.StoryboardContainer as SceneNode ?? this.view.ViewModel.RootNode; SceneNodeIDHelper sceneNodeIdHelper = new SceneNodeIDHelper(element.ViewModel, root); string namePrefix = SceneNodeIDHelper.DefaultNamePrefixForType((ITypeId)element.Type); return(sceneNodeIdHelper.GetValidElementID((SceneNode)element, namePrefix)); }
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 string GetUniqueName(string name) { string str = this.mode != DataSourceDialogMode.LiveXmlData ? this.SampleData.GetUniqueSampleDataSetName(name) : SceneNodeIDHelper.ToCSharpID(name); if (string.IsNullOrEmpty(str)) { str = this.mode != DataSourceDialogMode.LiveXmlData ? this.SampleData.GetUniqueSampleDataSetName(this.initialDataSourceName) : SceneNodeIDHelper.ToCSharpID(this.initialDataSourceName); } return(str); }
private static SceneElement PasteElement(SceneViewModel viewModel, SceneElement element, List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater, ISceneInsertionPoint insertionPoint) { SceneNodeIDHelper sceneNodeIdHelper = new SceneNodeIDHelper(viewModel, (SceneNode)insertionPoint.SceneNode.StoryboardContainer); SceneElement element1 = (SceneElement)null; using (viewModel.ForceBaseValue()) { PasteCommand.StripStoryboardsAndTriggers(element); PasteCommand.StripExtraNamespaces(element); BaseFrameworkElement frameworkElement = element as BaseFrameworkElement; if (frameworkElement != null || element is DataGridColumnNode) { if (!(insertionPoint.SceneElement is Viewport3DElement) && !(insertionPoint.SceneElement is Base3DElement)) { if (insertionPoint.CanInsert((ITypeId)element.Type)) { if (!PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)insertionPoint.SceneElement.Type) && (!PlatformTypes.UserControl.Equals((object)insertionPoint.SceneElement.Type) || insertionPoint.SceneElement.DocumentNode.DocumentRoot.RootNode != insertionPoint.SceneElement.DocumentNode)) { if (element.Name != null) { string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)element, element.Name); sceneNodeIdHelper.SetLocalName((SceneNode)element, validCopiedElementId); } sceneNodeIdHelper.FixNameConflicts((SceneNode)element); } if (viewModel.DesignerContext.PrototypingService != null) { viewModel.DesignerContext.PrototypingService.ProcessElementBeforeInsertion(insertionPoint, element); } insertionPoint.Insert((SceneNode)element); if (element.GetLocalValue(DesignTimeProperties.LayoutRectProperty) != null && frameworkElement != null) { elementsToTranslateLater.Add(new PasteCommand.DelayedElementTranslationInfo(frameworkElement)); } element1 = element; } } else if (element.TargetType == typeof(Image)) { GeometryModel3DElement geometryModel3Delement = GeometryCreationHelper3D.ConvertImageTo3D(viewModel, frameworkElement, element.Name); IChildContainer3D childContainer3D = insertionPoint.SceneElement as IChildContainer3D; if (childContainer3D != null) { childContainer3D.AddChild(viewModel, (Base3DElement)geometryModel3Delement); element1 = (SceneElement)geometryModel3Delement; } } } else { Base3DElement child; if ((child = element as Base3DElement) != null) { if (child.Name != null) { string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)child, child.Name); sceneNodeIdHelper.SetLocalName((SceneNode)child, validCopiedElementId); } DependencyPropertyReferenceStep propertyReferenceStep = insertionPoint.Property as DependencyPropertyReferenceStep; if (propertyReferenceStep != null && propertyReferenceStep.DependencyProperty == ModelVisual3D.ContentProperty) { Model3DElement model3Delement = BaseElement3DCoercionHelper.CoerceToModel3D(viewModel, (SceneElement)child); if (model3Delement != null) { insertionPoint.Insert((SceneNode)model3Delement); element1 = (SceneElement)model3Delement; } } else { IChildContainer3D childContainer3D = insertionPoint.SceneElement as IChildContainer3D; if (childContainer3D != null) { element1 = childContainer3D.AddChild(viewModel, child); } } } } if (element1 != null) { if (!(viewModel.ActiveEditingContainer is FrameworkTemplateElement)) { PasteCommand.StripTemplateBindings(element1); } } } return(element1); }
public static GeometryModel3DElement ConvertImageTo3D(SceneViewModel viewModel, BaseFrameworkElement imageElement, string newName, out ImageBrushNode imageBrush) { imageBrush = (ImageBrushNode)viewModel.CreateSceneNode(typeof(ImageBrush)); string uri = ((ImageElement)imageElement).Uri; SceneNode valueAsSceneNode = imageElement.GetLocalValueAsSceneNode(ImageElement.SourceProperty); if (valueAsSceneNode != null) { imageBrush.ImageSource = viewModel.GetSceneNode(valueAsSceneNode.DocumentNode.Clone(viewModel.Document.DocumentContext)); } double num = 1.0; double imageWidth = 1.0; double imageHeight = 1.0; double width = 1.0; double height = 1.0; Stretch stretch = Stretch.Fill; ImageSource imageSource; if (imageElement.Visual != null) { Rect computedTightBounds = imageElement.GetComputedTightBounds(); num = computedTightBounds.Width / computedTightBounds.Height; imageWidth = computedTightBounds.Width; imageHeight = computedTightBounds.Height; imageSource = imageElement.GetComputedValue(ImageElement.SourceProperty) as ImageSource; stretch = (Stretch)imageElement.GetComputedValue(ImageElement.StretchProperty); } else { imageSource = imageElement.GetLocalOrDefaultValue(ImageElement.SourceProperty) as ImageSource; object localOrDefaultValue = imageElement.GetLocalOrDefaultValue(ImageElement.StretchProperty); if (localOrDefaultValue is Stretch) { stretch = (Stretch)localOrDefaultValue; } } if (imageSource != null) { width = imageSource.Width; height = imageSource.Height; } imageBrush.SetValue(TileBrushNode.StretchProperty, (object)stretch); if (stretch == Stretch.None) { double x = 0.0; double y = 0.0; if (imageWidth > width) { x = (imageWidth - width) / 2.0; } if (imageHeight > height) { y = (imageHeight - height) / 2.0; } imageBrush.SetValue(TileBrushNode.ViewportUnitsProperty, (object)BrushMappingMode.Absolute); imageBrush.SetValue(TileBrushNode.ViewportProperty, (object)new Rect(x, y, width, height)); } GeometryModel3D geometryModel3D = new GeometryModel3D(); geometryModel3D.Geometry = (Geometry3D)GeometryCreationHelper3D.CreateSubdividedQuad(9, 20.0 * num, 20.0, imageWidth, imageHeight); GeometryModel3DElement geometryModel3Delement = (GeometryModel3DElement)viewModel.CreateSceneNode((object)geometryModel3D); geometryModel3Delement.Name = SceneNodeIDHelper.ToCSharpID(newName); geometryModel3Delement.DesignTimeBounds = geometryModel3D.Bounds; DiffuseMaterialNode diffuseMaterialNode = (DiffuseMaterialNode)viewModel.CreateSceneNode(typeof(DiffuseMaterial)); diffuseMaterialNode.Brush = (SceneNode)imageBrush; geometryModel3Delement.Material = (MaterialNode)diffuseMaterialNode; BitmapImageNode bitmapImageNode = imageBrush.ImageSource as BitmapImageNode; if (bitmapImageNode != null && uri != null) { bitmapImageNode.SetValue(BitmapImageNode.UriSourceProperty, (object)new Uri(uri, UriKind.RelativeOrAbsolute)); } return(geometryModel3Delement); }