Exemple #1
0
        private Dictionary <KeyValuePair <SceneElement, IPropertyId>, SceneElementCollection> SortSelectionByParentAndZOrder(ICollection <SceneElement> selection)
        {
            Dictionary <KeyValuePair <SceneElement, IPropertyId>, SceneElementCollection> dictionary = new Dictionary <KeyValuePair <SceneElement, IPropertyId>, SceneElementCollection>();

            foreach (SceneElement sceneElement in (IEnumerable <SceneElement>)selection)
            {
                SceneElement parentElement = sceneElement.ParentElement;
                IPropertyId  propertyId    = (IPropertyId)parentElement.GetPropertyForChild((SceneNode)sceneElement);
                KeyValuePair <SceneElement, IPropertyId> key = new KeyValuePair <SceneElement, IPropertyId>(parentElement, propertyId);
                SceneElementCollection elementCollection;
                if (!dictionary.TryGetValue(key, out elementCollection))
                {
                    elementCollection = new SceneElementCollection();
                    dictionary.Add(key, elementCollection);
                }
                elementCollection.Add(sceneElement);
            }
            if (this.requiresSortedList)
            {
                ZOrderComparer <SceneElement> zorderComparer = new ZOrderComparer <SceneElement>(this.SceneViewModel.RootNode);
                foreach (KeyValuePair <KeyValuePair <SceneElement, IPropertyId>, SceneElementCollection> keyValuePair in dictionary)
                {
                    keyValuePair.Value.Sort((IComparer <SceneElement>)zorderComparer);
                }
            }
            return(dictionary);
        }
        public static void Cleanup(SceneNode sceneNode)
        {
            SceneElement element = sceneNode as SceneElement;

            if (element != null)
            {
                sceneNode.ViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
                sceneNode.ViewModel.RemoveElement((SceneNode)element);
            }
            else
            {
                if (sceneNode == null || !sceneNode.ShouldClearAnimation)
                {
                    return;
                }
                SceneElement sceneElement = sceneNode.Parent as SceneElement;
                if (sceneElement == null)
                {
                    return;
                }
                IPropertyId       propertyId = (IPropertyId)sceneElement.GetPropertyForChild(sceneNode);
                PropertyReference property   = new PropertyReference((ReferenceStep)sceneElement.ProjectContext.ResolveProperty(propertyId));
                sceneNode.ViewModel.AnimationEditor.DeleteAllAnimationsInPropertySubtree((SceneNode)sceneElement, property);
            }
        }
Exemple #3
0
        public static void OnChildAddedHelper(SceneElement itemsControl, SceneNode child)
        {
            IProperty propertyForChild = itemsControl.GetPropertyForChild(child);

            if (propertyForChild == null || !ItemsControlElement.ItemsProperty.Equals((object)propertyForChild))
            {
                return;
            }
            ItemsControlElement.UpdateItemsSourceOnItemsChanged(itemsControl);
        }
Exemple #4
0
        private void SetLightTypeOnSelection(Type lightType)
        {
            if (this.selectedLights.Count == 0 || this.lightType != null && this.lightType.Equals((object)lightType))
            {
                return;
            }
            this.lightType = (object)lightType;
            SceneViewModel           viewModel                     = this.selectedLights[0].ViewModel;
            SceneElementSelectionSet elementSelectionSet           = viewModel.ElementSelectionSet;
            List <KeyValuePair <LightElement, LightElement> > list = new List <KeyValuePair <LightElement, LightElement> >();

            foreach (LightElement key in (IEnumerable <LightElement>)elementSelectionSet.GetFilteredSelection <LightElement>())
            {
                if (!(key.TargetType == lightType))
                {
                    LightElement lightElement = (LightElement)key.ViewModel.CreateSceneNode(lightType);
                    DocumentNode documentNode = (DocumentNode)null;
                    if (typeof(SpotLight).Equals(lightType))
                    {
                        DocumentNodePath valueAsDocumentNode = key.GetLocalValueAsDocumentNode(SpotLightElement.DirectionProperty);
                        documentNode = valueAsDocumentNode != null ? valueAsDocumentNode.Node : (DocumentNode)null;
                    }
                    else if (typeof(DirectionalLight).Equals(lightType))
                    {
                        DocumentNodePath valueAsDocumentNode = key.GetLocalValueAsDocumentNode(DirectionalLightElement.DirectionProperty);
                        documentNode = valueAsDocumentNode != null ? valueAsDocumentNode.Node : (DocumentNode)null;
                    }
                    if (typeof(DirectionalLight).Equals(lightType))
                    {
                        if (documentNode != null)
                        {
                            lightElement.SetValue(DirectionalLightElement.DirectionProperty, (object)documentNode);
                        }
                    }
                    else if (typeof(PointLightBase).IsAssignableFrom(lightType))
                    {
                        if (!typeof(PointLightBase).IsAssignableFrom(key.TargetType))
                        {
                            lightElement.SetValue(LightElement.PositionProperty, (object)new Point3D(0.0, 0.0, 0.0));
                            lightElement.SetValue(LightElement.RangeProperty, (object)10.0);
                            lightElement.SetValue(LightElement.ConstantAttenuationProperty, (object)1.0);
                            lightElement.SetValue(LightElement.LinearAttenuationProperty, (object)0.0);
                            lightElement.SetValue(LightElement.QuadraticAttenuationProperty, (object)0.0);
                        }
                        if (typeof(SpotLight).Equals(lightType))
                        {
                            if (documentNode != null)
                            {
                                lightElement.SetValue(SpotLightElement.DirectionProperty, (object)documentNode);
                            }
                            lightElement.SetValue(SpotLightElement.OuterConeAngleProperty, (object)40.0);
                            lightElement.SetValue(SpotLightElement.InnerConeAngleProperty, (object)30.0);
                        }
                    }
                    list.Add(new KeyValuePair <LightElement, LightElement>(key, lightElement));
                }
            }
            if (list.Count != 0)
            {
                using (SceneEditTransaction editTransaction = viewModel.Document.CreateEditTransaction(StringTable.UndoUnitChangeLightType))
                {
                    foreach (KeyValuePair <LightElement, LightElement> keyValuePair in list)
                    {
                        LightElement key          = keyValuePair.Key;
                        LightElement lightElement = keyValuePair.Value;
                        viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)key);
                        Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)key);
                        elementSelectionSet.RemoveSelection((SceneElement)key);
                        SceneElement parentElement = key.ParentElement;
                        ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)parentElement.GetPropertyForChild((SceneNode)key));
                        int index = collectionForProperty.IndexOf((SceneNode)key);
                        collectionForProperty[index] = (SceneNode)lightElement;
                        SceneElementHelper.ApplyProperties((SceneNode)lightElement, properties);
                        elementSelectionSet.ExtendSelection((SceneElement)lightElement);
                    }
                    editTransaction.Commit();
                }
            }
            this.OnPropertyChanged("IsAmbientLight");
            this.OnPropertyChanged("IsPointLight");
            this.OnPropertyChanged("IsDirectionalLight");
            this.OnPropertyChanged("IsSpotLight");
        }
Exemple #5
0
        private void SetCameraTypeOnSelection(Type cameraType)
        {
            if (this.selectedCameras.Count == 0 || this.cameraType.Equals((object)cameraType))
            {
                return;
            }
            this.cameraType = (object)cameraType;
            SceneViewModel           viewModel           = this.selectedCameras[0].ViewModel;
            SceneElementSelectionSet elementSelectionSet = viewModel.ElementSelectionSet;

            using (SceneEditTransaction editTransaction = viewModel.Document.CreateEditTransaction(StringTable.UndoUnitChangeCameraType))
            {
                foreach (ProjectionCameraElement projectionCameraElement1 in this.selectedCameras)
                {
                    if (!(projectionCameraElement1.TargetType == cameraType))
                    {
                        ProjectionCameraElement projectionCameraElement2;
                        if (typeof(OrthographicCamera).IsAssignableFrom(cameraType))
                        {
                            projectionCameraElement2 = (ProjectionCameraElement)OrthographicCameraElement.Factory.Instantiate(projectionCameraElement1.ViewModel);
                            projectionCameraElement2.SetValue(OrthographicCameraElement.WidthProperty, (object)10.0);
                        }
                        else if (typeof(PerspectiveCamera).IsAssignableFrom(cameraType))
                        {
                            projectionCameraElement2 = (ProjectionCameraElement)PerspectiveCameraElement.Factory.Instantiate(projectionCameraElement1.ViewModel);
                            projectionCameraElement2.SetValue(PerspectiveCameraElement.FieldOfViewProperty, (object)45.0);
                        }
                        else
                        {
                            continue;
                        }
                        projectionCameraElement1.ViewModel.AnimationEditor.DeleteAllAnimations((SceneNode)projectionCameraElement1);
                        Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)projectionCameraElement1);
                        elementSelectionSet.RemoveSelection((SceneElement)projectionCameraElement1);
                        SceneElement parentElement = projectionCameraElement1.ParentElement;
                        ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)parentElement.GetPropertyForChild((SceneNode)projectionCameraElement1));
                        int index = collectionForProperty.IndexOf((SceneNode)projectionCameraElement1);
                        collectionForProperty[index] = (SceneNode)projectionCameraElement2;
                        SceneElementHelper.ApplyProperties((SceneNode)projectionCameraElement2, properties);
                        elementSelectionSet.ExtendSelection((SceneElement)projectionCameraElement2);
                    }
                }
                editTransaction.Commit();
            }
            this.OnPropertyChanged("IsCameraOrthographic");
            this.OnPropertyChanged("IsCameraPerspective");
        }
 private SceneNode Move(SceneNode node)
 {
     if (node.IsAttached)
     {
         SceneElement      sceneElement      = (SceneElement)node.Parent;
         PropertyReference propertyReference = new PropertyReference((ReferenceStep)sceneElement.GetPropertyForChild(node));
         this.TargetNode.ViewModel.AnimationEditor.DeleteAllAnimations((SceneNode)sceneElement, propertyReference.ToString());
         this.TargetNode.ViewModel.RemoveElement(node);
     }
     return(this.InsertNode(node));
 }
        public override void Execute()
        {
            string               fileName           = "test";
            IProject             activeProject      = this.DesignerContext.ActiveProject;
            TemplateItemHelper   templateItemHelper = new TemplateItemHelper(activeProject, (IList <string>)null, (IServiceProvider)this.DesignerContext.Services);
            IProjectItemTemplate templateItem       = templateItemHelper.FindTemplateItem("UserControl");

            if (templateItem == null)
            {
                this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlTemplateNotFound);
            }
            else
            {
                SceneViewModel      activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel;
                List <SceneElement> elements             = new List <SceneElement>();
                elements.AddRange((IEnumerable <SceneElement>)activeSceneViewModel.ElementSelectionSet.Selection);
                elements.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(activeSceneViewModel.RootNode));
                if (this.ShowUI)
                {
                    string recommendedName = this.GetRecommendedName((IEnumerable <SceneElement>)elements);
                    MakeUserControlDialog userControlDialog = new MakeUserControlDialog(this.DesignerContext, this.DialogTitle, templateItemHelper, recommendedName);
                    bool?nullable = userControlDialog.ShowDialog();
                    if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                    {
                        return;
                    }
                    fileName = userControlDialog.ControlName;
                }
                List <IProjectItem>        itemsToOpen  = (List <IProjectItem>)null;
                IProjectItem               projectItem1 = (IProjectItem)null;
                IEnumerable <IProjectItem> source       = (IEnumerable <IProjectItem>)null;
                try
                {
                    source = templateItemHelper.AddProjectItemsForTemplateItem(templateItem, fileName, this.DesignerContext.ProjectManager.TargetFolderForProject(activeProject), CreationOptions.DoNotAllowOverwrites | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath, out itemsToOpen);
                }
                catch (Exception ex)
                {
                    if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex))
                    {
                        this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ProjectNewFileErrorDialogMessage, new object[2]
                        {
                            (object)fileName,
                            (object)ex.Message
                        }));
                    }
                    else
                    {
                        throw;
                    }
                }
                if (source == null || EnumerableExtensions.CountIsLessThan <IProjectItem>(source, 1))
                {
                    return;
                }
                if (itemsToOpen != null && itemsToOpen.Count > 0)
                {
                    projectItem1 = Enumerable.FirstOrDefault <IProjectItem>((IEnumerable <IProjectItem>)itemsToOpen);
                    projectItem1.OpenDocument(false, true);
                }
                if (projectItem1 != null && projectItem1.IsOpen && projectItem1.DocumentType.CanView)
                {
                    Rect empty = Rect.Empty;
                    for (int index = 0; index < elements.Count; ++index)
                    {
                        BaseFrameworkElement child = elements[index] as BaseFrameworkElement;
                        if (child != null)
                        {
                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                            empty.Union(childRect);
                        }
                    }
                    Rect         rect              = RoundingHelper.RoundRect(empty);
                    SceneElement parentElement     = elements[0].ParentElement;
                    bool         useLayoutRounding = LayoutRoundingHelper.GetUseLayoutRounding(parentElement);
                    DataObject   dataObject        = (DataObject)null;
                    using (activeSceneViewModel.ForceBaseValue())
                    {
                        PastePackage pastePackage = new PastePackage(activeSceneViewModel);
                        pastePackage.CopyStoryboardsReferencingElements = true;
                        pastePackage.AddElements(elements);
                        dataObject = pastePackage.GetPasteDataObject();
                    }
                    SceneView sceneView = projectItem1.OpenView(true) as SceneView;
                    if (sceneView != null)
                    {
                        SceneViewModel     viewModel           = sceneView.ViewModel;
                        ProjectXamlContext projectXamlContext  = ProjectXamlContext.FromProjectContext(viewModel.ViewRoot.ProjectContext);
                        ClassAttributes    rootClassAttributes = viewModel.DocumentRoot.RootClassAttributes;
                        ITypeId            typeId = (ITypeId)null;
                        if (projectXamlContext != null && rootClassAttributes != null)
                        {
                            projectXamlContext.RefreshUnbuiltTypeDescriptions();
                            if (rootClassAttributes != null)
                            {
                                typeId = (ITypeId)projectXamlContext.GetType(projectXamlContext.ProjectAssembly.Name, rootClassAttributes.QualifiedClassName);
                            }
                        }
                        if (typeId != null && this.CheckForCircularReference((IEnumerable <SceneElement>)elements, typeId))
                        {
                            this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlCircularReferenceFound);
                            this.CleanupAfterCancel(projectItem1);
                            return;
                        }
                        using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                        {
                            if (!rect.IsEmpty)
                            {
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignWidthProperty, (object)rect.Width);
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignHeightProperty, (object)rect.Height);
                                if (this.AddToApplicationFlow)
                                {
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.WidthProperty, (object)rect.Width);
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.HeightProperty, (object)rect.Height);
                                }
                            }
                            IProperty property = LayoutRoundingHelper.ResolveUseLayoutRoundingProperty(viewModel.RootNode);
                            if (property != null)
                            {
                                viewModel.RootNode.SetValue((IPropertyId)property, (object)(bool)(useLayoutRounding ? true : false));
                            }
                            ILayoutDesigner         designerForParent = viewModel.GetLayoutDesignerForParent(viewModel.ActiveSceneInsertionPoint.SceneElement, true);
                            bool                    canceledPasteOperation;
                            ICollection <SceneNode> nodes = PasteCommand.PasteData(viewModel, new SafeDataObject((IDataObject)dataObject), viewModel.ActiveSceneInsertionPoint, out canceledPasteOperation);
                            if (canceledPasteOperation)
                            {
                                editTransaction.Cancel();
                                this.CleanupAfterCancel(projectItem1);
                                return;
                            }
                            editTransaction.Update();
                            if (nodes.Count > 0)
                            {
                                viewModel.DefaultView.UpdateLayout();
                                viewModel.SelectNodes(nodes);
                                if (designerForParent != null)
                                {
                                    foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)nodes)
                                    {
                                        BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                        if (child != null && child.IsViewObjectValid)
                                        {
                                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                                            childRect.Location = (Point)(childRect.Location - rect.Location);
                                            designerForParent.SetChildRect(child, childRect);
                                        }
                                    }
                                }
                            }
                            editTransaction.Commit();
                        }
                        if (this.AddToApplicationFlow && this.DesignerContext.PrototypingService != null)
                        {
                            this.DesignerContext.PrototypingService.PromoteToCompositionScreen(projectItem1);
                        }
                        if (typeId != null)
                        {
                            using (activeSceneViewModel.ForceBaseValue())
                            {
                                using (activeSceneViewModel.DisableDrawIntoState())
                                {
                                    using (SceneEditTransaction editTransaction = activeSceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                                    {
                                        using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove())
                                        {
                                            SceneElement primarySelection = activeSceneViewModel.ElementSelectionSet.PrimarySelection;
                                            IProperty    propertyForChild = parentElement.GetPropertyForChild((SceneNode)primarySelection);
                                            PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(parentElement, propertyForChild);
                                            SceneNode sceneNode = (SceneNode)null;
                                            if (sceneInsertionPoint.CanInsert(typeId))
                                            {
                                                foreach (SceneElement element in elements)
                                                {
                                                    if (element != primarySelection)
                                                    {
                                                        activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
                                                        element.Remove();
                                                    }
                                                }
                                                ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)propertyForChild);
                                                int index = collectionForProperty.IndexOf((SceneNode)primarySelection);
                                                activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection);
                                                primarySelection.Remove();
                                                sceneNode = activeSceneViewModel.CreateSceneNode(typeId);
                                                collectionForProperty.Insert(index, sceneNode);
                                                this.DesignerContext.ViewService.ActiveView = (IView)activeSceneViewModel.DefaultView;
                                                editTransaction.Update();
                                                activeSceneViewModel.DefaultView.UpdateLayout();
                                                BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                                if (child != null && child.IsViewObjectValid)
                                                {
                                                    activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true).SetChildRect(child, rect);
                                                }
                                            }
                                            if (this.AddToApplicationFlow)
                                            {
                                                if (sceneNode != null)
                                                {
                                                    sceneNode.SetValue(DesignTimeProperties.IsPrototypingCompositionProperty, (object)true);
                                                }
                                            }
                                        }
                                        editTransaction.Commit();
                                    }
                                }
                            }
                            this.DesignerContext.ViewService.ActiveView = (IView)viewModel.DefaultView;
                        }
                    }
                }
                if (itemsToOpen == null || itemsToOpen.Count <= 1)
                {
                    return;
                }
                foreach (IProjectItem projectItem2 in itemsToOpen)
                {
                    if (projectItem1 != projectItem2)
                    {
                        projectItem2.OpenView(true);
                    }
                }
            }
        }